Skip to content

Commit 7a2448f

Browse files
committed
PR changes
1 parent dd6a841 commit 7a2448f

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

Sources/NIOHTTP2/GlitchesMonitor.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
package struct GlitchesMonitor {
16-
package static var defaultMaximumGlitches: Int { 200 }
15+
struct GlitchesMonitor {
16+
static var defaultMaximumGlitches: Int { 100 }
1717
private var stateMachine: GlitchesMonitorStateMachine
1818

19-
package init(maximumGlitches: Int = GlitchesMonitor.defaultMaximumGlitches) {
19+
init(maximumGlitches: Int = GlitchesMonitor.defaultMaximumGlitches) {
2020
self.stateMachine = GlitchesMonitorStateMachine(maxGlitches: maximumGlitches)
2121
}
2222

23-
package mutating func processStreamError() throws {
23+
mutating func processStreamError() throws {
2424
switch self.stateMachine.recordEvent() {
2525
case .belowLimit:
2626
()

Sources/NIOHTTP2/HTTP2ChannelHandler.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,17 @@ extension NIOHTTP2Handler {
14451445
public var maximumBufferedControlFrames: Int = 10000
14461446
public var maximumSequentialContinuationFrames: Int = NIOHTTP2Handler.defaultMaximumSequentialContinuationFrames
14471447
public var maximumRecentlyResetStreams: Int = NIOHTTP2Handler.defaultMaximumRecentlyResetFrames
1448+
1449+
/// The maximum number of glitches that are allowed on a connection before it's forcefully closed.
1450+
///
1451+
/// A glitch is defined as some suspicious event on a connection, i.e., similar to a DoS attack.
1452+
/// A running count of the number of glitches occurring on each connection will be kept.
1453+
/// When the number of glitches reaches this threshold, the connection will be closed.
1454+
///
1455+
/// For more information, see the relevant presentation of the 2024 HTTP Workshop:
1456+
/// https://github.com/HTTPWorkshop/workshop2024/blob/main/talks/1.%20Security/glitches.pdf
14481457
public var maximumConnectionGlitches: Int = GlitchesMonitor.defaultMaximumGlitches
1458+
14491459
public init() {}
14501460
}
14511461

Sources/NIOHTTP2/HTTP2Error.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1844,7 +1844,7 @@ public enum NIOHTTP2Errors {
18441844
}
18451845
}
18461846

1847-
/// The remote peer has triggered too many stream errors on this connection.
1847+
/// The remote peer has triggered too many glitches on this connection.
18481848
public struct ExcessiveNumberOfGlitches: NIOHTTP2Error {
18491849
private let file: String
18501850
private let line: UInt

Sources/NIOHTTP2Server/main.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,7 @@ let bootstrap = ServerBootstrap(group: group)
134134
try sync.addHandler(HTTP1TestServer())
135135
try sync.addHandler(ErrorHandler())
136136
}
137-
}.flatMap { _ in
138-
channel.pipeline.addHandler(ErrorHandler())
139-
}
137+
}.map { _ in }
140138
}
141139

142140
// Enable TCP_NODELAY and SO_REUSEADDR for the accepted Channels

Tests/NIOHTTP2Tests/GlitchesMonitorTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
import NIOHTTP2
15+
@testable import NIOHTTP2
1616
import XCTest
1717

1818
class GlitchesMonitorTests: XCTestCase {

0 commit comments

Comments
 (0)