Forráskód Böngészése

Rename a few things (#1856)

Motivation:

"Service config" is the name of a gRPC feature, yet we've named the
corresponding type "ServiceConfiguration". We should follow the gRPC
naming here.

In a similar vein, "keepAlive" should be "keepalive".

Modifications:

- Rename "ServiceConfiguration" to "ServiceConfig"
- Rename "MethodConfiguration" to "MethodConfig"
- Rename various "keepAlive"s to "keepalive"

Result:

Naming is more consistent with gRPC
George Barnett 1 éve
szülő
commit
408a775ac1

+ 49 - 49
Sources/GRPCHTTP2Core/Client/Connection/ClientConnectionHandler.swift

@@ -23,7 +23,7 @@ enum ClientConnectionEvent: Sendable, Hashable {
     /// The server sent a GOAWAY frame to the client.
     case goAway(HTTP2ErrorCode, String)
     /// The keep alive timer fired and subsequently timed out.
-    case keepAliveExpired
+    case keepaliveExpired
     /// The connection became idle.
     case idle
     /// The local peer initiated the close.
@@ -64,14 +64,14 @@ final class ClientConnectionHandler: ChannelInboundHandler, ChannelOutboundHandl
   private var maxIdleTimer: Timer?
 
   /// The amount of time to wait before sending a keep alive ping.
-  private var keepAliveTimer: Timer?
+  private var keepaliveTimer: Timer?
 
   /// The amount of time the client has to reply after sending a keep alive ping. Only used if
-  /// `keepAliveTimer` is set.
-  private var keepAliveTimeoutTimer: Timer
+  /// `keepaliveTimer` is set.
+  private var keepaliveTimeoutTimer: Timer
 
   /// Opaque data sent in keep alive pings.
-  private let keepAlivePingData: HTTP2PingData
+  private let keepalivePingData: HTTP2PingData
 
   /// The current state of the connection.
   private var state: StateMachine
@@ -87,26 +87,26 @@ final class ClientConnectionHandler: ChannelInboundHandler, ChannelOutboundHandl
   /// - Parameters:
   ///   - eventLoop: The `EventLoop` of the `Channel` this handler is placed in.
   ///   - maxIdleTime: The maximum amount time a connection may be idle for before being closed.
-  ///   - keepAliveTime: The amount of time to wait after reading data before sending a keep-alive
+  ///   - keepaliveTime: The amount of time to wait after reading data before sending a keep-alive
   ///       ping.
-  ///   - keepAliveTimeout: The amount of time the client has to reply after the server sends a
+  ///   - keepaliveTimeout: The amount of time the client has to reply after the server sends a
   ///       keep-alive ping to keep the connection open. The connection is closed if no reply
   ///       is received.
-  ///   - keepAliveWithoutCalls: Whether the client sends keep-alive pings when there are no calls
+  ///   - keepaliveWithoutCalls: Whether the client sends keep-alive pings when there are no calls
   ///       in progress.
   init(
     eventLoop: EventLoop,
     maxIdleTime: TimeAmount?,
-    keepAliveTime: TimeAmount?,
-    keepAliveTimeout: TimeAmount?,
-    keepAliveWithoutCalls: Bool
+    keepaliveTime: TimeAmount?,
+    keepaliveTimeout: TimeAmount?,
+    keepaliveWithoutCalls: Bool
   ) {
     self.eventLoop = eventLoop
     self.maxIdleTimer = maxIdleTime.map { Timer(delay: $0) }
-    self.keepAliveTimer = keepAliveTime.map { Timer(delay: $0, repeat: true) }
-    self.keepAliveTimeoutTimer = Timer(delay: keepAliveTimeout ?? .seconds(20))
-    self.keepAlivePingData = HTTP2PingData(withInteger: .random(in: .min ... .max))
-    self.state = StateMachine(allowKeepAliveWithoutCalls: keepAliveWithoutCalls)
+    self.keepaliveTimer = keepaliveTime.map { Timer(delay: $0, repeat: true) }
+    self.keepaliveTimeoutTimer = Timer(delay: keepaliveTimeout ?? .seconds(20))
+    self.keepalivePingData = HTTP2PingData(withInteger: .random(in: .min ... .max))
+    self.state = StateMachine(allowKeepaliveWithoutCalls: keepaliveWithoutCalls)
 
     self.flushPending = false
     self.inReadLoop = false
@@ -117,8 +117,8 @@ final class ClientConnectionHandler: ChannelInboundHandler, ChannelOutboundHandl
   }
 
   func channelActive(context: ChannelHandlerContext) {
-    self.keepAliveTimer?.schedule(on: context.eventLoop) {
-      self.keepAliveTimerFired(context: context)
+    self.keepaliveTimer?.schedule(on: context.eventLoop) {
+      self.keepaliveTimerFired(context: context)
     }
 
     self.maxIdleTimer?.schedule(on: context.eventLoop) {
@@ -133,8 +133,8 @@ final class ClientConnectionHandler: ChannelInboundHandler, ChannelOutboundHandl
     case .succeed(let promise):
       promise.succeed()
     }
-    self.keepAliveTimer?.cancel()
-    self.keepAliveTimeoutTimer.cancel()
+    self.keepaliveTimer?.cancel()
+    self.keepaliveTimeoutTimer.cancel()
   }
 
   func userInboundEventTriggered(context: ChannelHandlerContext, event: Any) {
@@ -146,15 +146,15 @@ final class ClientConnectionHandler: ChannelInboundHandler, ChannelOutboundHandl
 
     case let event as StreamClosedEvent:
       switch self.state.streamClosed(event.streamID) {
-      case .startIdleTimer(let cancelKeepAlive):
+      case .startIdleTimer(let cancelKeepalive):
         // All streams are closed, restart the idle timer, and stop the keep-alive timer (it may
         // not stop if keep-alive is allowed when there are no active calls).
         self.maxIdleTimer?.schedule(on: context.eventLoop) {
           self.maxIdleTimerFired(context: context)
         }
 
-        if cancelKeepAlive {
-          self.keepAliveTimer?.cancel()
+        if cancelKeepalive {
+          self.keepaliveTimer?.cancel()
         }
 
       case .close:
@@ -200,10 +200,10 @@ final class ClientConnectionHandler: ChannelInboundHandler, ChannelOutboundHandl
     case .ping(let data, let ack):
       // Pings are ack'd by the HTTP/2 handler so we only pay attention to acks here, and in
       // particular only those carrying the keep-alive data.
-      if ack, data == self.keepAlivePingData {
-        self.keepAliveTimeoutTimer.cancel()
-        self.keepAliveTimer?.schedule(on: context.eventLoop) {
-          self.keepAliveTimerFired(context: context)
+      if ack, data == self.keepalivePingData {
+        self.keepaliveTimeoutTimer.cancel()
+        self.keepaliveTimer?.schedule(on: context.eventLoop) {
+          self.keepaliveTimerFired(context: context)
         }
       }
 
@@ -258,27 +258,27 @@ extension ClientConnectionHandler {
     }
   }
 
-  private func keepAliveTimerFired(context: ChannelHandlerContext) {
-    guard self.state.sendKeepAlivePing() else { return }
+  private func keepaliveTimerFired(context: ChannelHandlerContext) {
+    guard self.state.sendKeepalivePing() else { return }
 
     // Cancel the keep alive timer when the client sends a ping. The timer is resumed when the ping
     // is acknowledged.
-    self.keepAliveTimer?.cancel()
+    self.keepaliveTimer?.cancel()
 
-    let ping = HTTP2Frame(streamID: .rootStream, payload: .ping(self.keepAlivePingData, ack: false))
+    let ping = HTTP2Frame(streamID: .rootStream, payload: .ping(self.keepalivePingData, ack: false))
     context.write(self.wrapOutboundOut(ping), promise: nil)
     self.maybeFlush(context: context)
 
     // Schedule a timeout on waiting for the response.
-    self.keepAliveTimeoutTimer.schedule(on: context.eventLoop) {
-      self.keepAliveTimeoutExpired(context: context)
+    self.keepaliveTimeoutTimer.schedule(on: context.eventLoop) {
+      self.keepaliveTimeoutExpired(context: context)
     }
   }
 
-  private func keepAliveTimeoutExpired(context: ChannelHandlerContext) {
+  private func keepaliveTimeoutExpired(context: ChannelHandlerContext) {
     guard self.state.beginClosing() else { return }
 
-    context.fireChannelRead(self.wrapInboundOut(.closing(.keepAliveExpired)))
+    context.fireChannelRead(self.wrapInboundOut(.closing(.keepaliveExpired)))
     self.writeAndFlushGoAway(context: context, message: "keepalive_expired")
     context.close(promise: nil)
   }
@@ -321,29 +321,29 @@ extension ClientConnectionHandler {
 
       struct Active {
         var openStreams: Set<HTTP2StreamID>
-        var allowKeepAliveWithoutCalls: Bool
+        var allowKeepaliveWithoutCalls: Bool
 
-        init(allowKeepAliveWithoutCalls: Bool) {
+        init(allowKeepaliveWithoutCalls: Bool) {
           self.openStreams = []
-          self.allowKeepAliveWithoutCalls = allowKeepAliveWithoutCalls
+          self.allowKeepaliveWithoutCalls = allowKeepaliveWithoutCalls
         }
       }
 
       struct Closing {
-        var allowKeepAliveWithoutCalls: Bool
+        var allowKeepaliveWithoutCalls: Bool
         var openStreams: Set<HTTP2StreamID>
         var closePromise: Optional<EventLoopPromise<Void>>
 
         init(from state: Active, closePromise: EventLoopPromise<Void>?) {
           self.openStreams = state.openStreams
-          self.allowKeepAliveWithoutCalls = state.allowKeepAliveWithoutCalls
+          self.allowKeepaliveWithoutCalls = state.allowKeepaliveWithoutCalls
           self.closePromise = closePromise
         }
       }
     }
 
-    init(allowKeepAliveWithoutCalls: Bool) {
-      self.state = .active(State.Active(allowKeepAliveWithoutCalls: allowKeepAliveWithoutCalls))
+    init(allowKeepaliveWithoutCalls: Bool) {
+      self.state = .active(State.Active(allowKeepaliveWithoutCalls: allowKeepaliveWithoutCalls))
     }
 
     /// Record that the stream with the given ID has been opened.
@@ -366,7 +366,7 @@ extension ClientConnectionHandler {
 
     enum OnStreamClosed: Equatable {
       /// Start the idle timer, after which the connection should be closed gracefully.
-      case startIdleTimer(cancelKeepAlive: Bool)
+      case startIdleTimer(cancelKeepalive: Bool)
       /// Close the connection.
       case close
       /// Do nothing.
@@ -382,7 +382,7 @@ extension ClientConnectionHandler {
         let removedID = state.openStreams.remove(id)
         assert(removedID != nil, "Can't close stream \(Int(id)), it wasn't open")
         if state.openStreams.isEmpty {
-          onStreamClosed = .startIdleTimer(cancelKeepAlive: !state.allowKeepAliveWithoutCalls)
+          onStreamClosed = .startIdleTimer(cancelKeepalive: !state.allowKeepaliveWithoutCalls)
         } else {
           onStreamClosed = .none
         }
@@ -402,21 +402,21 @@ extension ClientConnectionHandler {
     }
 
     /// Returns whether a keep alive ping should be sent to the server.
-    mutating func sendKeepAlivePing() -> Bool {
-      let sendKeepAlivePing: Bool
+    mutating func sendKeepalivePing() -> Bool {
+      let sendKeepalivePing: Bool
 
       // Only send a ping if there are open streams or there are no open streams and keep alive
       // is permitted when there are no active calls.
       switch self.state {
       case .active(let state):
-        sendKeepAlivePing = !state.openStreams.isEmpty || state.allowKeepAliveWithoutCalls
+        sendKeepalivePing = !state.openStreams.isEmpty || state.allowKeepaliveWithoutCalls
       case .closing(let state):
-        sendKeepAlivePing = !state.openStreams.isEmpty || state.allowKeepAliveWithoutCalls
+        sendKeepalivePing = !state.openStreams.isEmpty || state.allowKeepaliveWithoutCalls
       case .closed:
-        sendKeepAlivePing = false
+        sendKeepalivePing = false
       }
 
-      return sendKeepAlivePing
+      return sendKeepalivePing
     }
 
     enum OnGracefulShutDown: Equatable {

+ 1 - 1
Sources/GRPCHTTP2Core/Client/Resolver/NameResolver+IPv4.swift

@@ -68,7 +68,7 @@ extension NameResolvers {
 
     public func resolver(for target: Target) -> NameResolver {
       let endpoints = target.addresses.map { Endpoint(addresses: [.ipv4($0)]) }
-      let resolutionResult = NameResolutionResult(endpoints: endpoints, serviceConfiguration: nil)
+      let resolutionResult = NameResolutionResult(endpoints: endpoints, serviceConfig: nil)
       return NameResolver(names: .constant(resolutionResult), updateMode: .pull)
     }
   }

+ 1 - 1
Sources/GRPCHTTP2Core/Client/Resolver/NameResolver+IPv6.swift

@@ -68,7 +68,7 @@ extension NameResolvers {
 
     public func resolver(for target: Target) -> NameResolver {
       let endpoints = target.addresses.map { Endpoint(addresses: [.ipv6($0)]) }
-      let resolutionResult = NameResolutionResult(endpoints: endpoints, serviceConfiguration: nil)
+      let resolutionResult = NameResolutionResult(endpoints: endpoints, serviceConfig: nil)
       return NameResolver(names: .constant(resolutionResult), updateMode: .pull)
     }
   }

+ 1 - 1
Sources/GRPCHTTP2Core/Client/Resolver/NameResolver+UDS.swift

@@ -53,7 +53,7 @@ extension NameResolvers {
 
     public func resolver(for target: Target) -> NameResolver {
       let endpoint = Endpoint(addresses: [.unixDomainSocket(target.address)])
-      let resolutionResult = NameResolutionResult(endpoints: [endpoint], serviceConfiguration: nil)
+      let resolutionResult = NameResolutionResult(endpoints: [endpoint], serviceConfig: nil)
       return NameResolver(names: .constant(resolutionResult), updateMode: .pull)
     }
   }

+ 1 - 1
Sources/GRPCHTTP2Core/Client/Resolver/NameResolver+VSOCK.swift

@@ -57,7 +57,7 @@ extension NameResolvers {
 
     public func resolver(for target: Target) -> NameResolver {
       let endpoint = Endpoint(addresses: [.vsock(target.address)])
-      let resolutionResult = NameResolutionResult(endpoints: [endpoint], serviceConfiguration: nil)
+      let resolutionResult = NameResolutionResult(endpoints: [endpoint], serviceConfig: nil)
       return NameResolver(names: .constant(resolutionResult), updateMode: .pull)
     }
   }

+ 3 - 3
Sources/GRPCHTTP2Core/Client/Resolver/NameResolver.swift

@@ -67,14 +67,14 @@ public struct NameResolutionResult: Hashable, Sendable {
 
   /// The service configuration reported by the resolver, or an error if it couldn't be parsed.
   /// This value may be `nil` if the resolver doesn't support fetching service configuration.
-  public var serviceConfiguration: Result<ServiceConfiguration, RPCError>?
+  public var serviceConfig: Result<ServiceConfig, RPCError>?
 
   public init(
     endpoints: [Endpoint],
-    serviceConfiguration: Result<ServiceConfiguration, RPCError>?
+    serviceConfig: Result<ServiceConfig, RPCError>?
   ) {
     self.endpoints = endpoints
-    self.serviceConfiguration = serviceConfiguration
+    self.serviceConfig = serviceConfig
   }
 }
 

+ 16 - 16
Sources/GRPCHTTP2Core/Server/Connection/ServerConnectionManagementHandler+StateMachine.swift

@@ -33,23 +33,23 @@ extension ServerConnectionManagementHandler {
     /// Create a new state machine.
     ///
     /// - Parameters:
-    ///   - allowKeepAliveWithoutCalls: Whether the client is permitted to send keep alive pings
+    ///   - allowKeepaliveWithoutCalls: Whether the client is permitted to send keep alive pings
     ///       when there are no active calls.
     ///   - minPingReceiveIntervalWithoutCalls: The minimum time interval required between keep
     ///       alive pings when there are no active calls.
     ///   - goAwayPingData: Opaque data sent to the client in a PING frame when the server
     ///       initiates graceful shutdown.
     init(
-      allowKeepAliveWithoutCalls: Bool,
+      allowKeepaliveWithoutCalls: Bool,
       minPingReceiveIntervalWithoutCalls: TimeAmount,
       goAwayPingData: HTTP2PingData = HTTP2PingData(withInteger: .random(in: .min ... .max))
     ) {
-      let keepAlive = KeepAlive(
-        allowWithoutCalls: allowKeepAliveWithoutCalls,
+      let keepalive = Keepalive(
+        allowWithoutCalls: allowKeepaliveWithoutCalls,
         minPingReceiveIntervalWithoutCalls: minPingReceiveIntervalWithoutCalls
       )
 
-      self.state = .active(State.Active(keepAlive: keepAlive))
+      self.state = .active(State.Active(keepalive: keepalive))
       self.goAwayPingData = goAwayPingData
     }
 
@@ -128,7 +128,7 @@ extension ServerConnectionManagementHandler {
 
       switch self.state {
       case .active(var state):
-        let tooManyPings = state.keepAlive.receivedPing(
+        let tooManyPings = state.keepalive.receivedPing(
           atTime: time,
           hasOpenStreams: !state.openStreams.isEmpty
         )
@@ -142,7 +142,7 @@ extension ServerConnectionManagementHandler {
         }
 
       case .closing(var state):
-        let tooManyPings = state.keepAlive.receivedPing(
+        let tooManyPings = state.keepalive.receivedPing(
           atTime: time,
           hasOpenStreams: !state.openStreams.isEmpty
         )
@@ -226,14 +226,14 @@ extension ServerConnectionManagementHandler {
     }
 
     /// Reset the state of keep-alive policing.
-    mutating func resetKeepAliveState() {
+    mutating func resetKeepaliveState() {
       switch self.state {
       case .active(var state):
-        state.keepAlive.reset()
+        state.keepalive.reset()
         self.state = .active(state)
 
       case .closing(var state):
-        state.keepAlive.reset()
+        state.keepalive.reset()
         self.state = .closing(state)
 
       case .closed:
@@ -249,7 +249,7 @@ extension ServerConnectionManagementHandler {
 }
 
 extension ServerConnectionManagementHandler.StateMachine {
-  fileprivate struct KeepAlive {
+  fileprivate struct Keepalive {
     /// Allow the client to send keep alive pings when there are no active calls.
     private let allowWithoutCalls: Bool
 
@@ -328,12 +328,12 @@ extension ServerConnectionManagementHandler.StateMachine {
       /// The ID of the most recently opened stream (zero indicates no streams have been opened yet).
       var lastStreamID: HTTP2StreamID
       /// The state of keep alive.
-      var keepAlive: KeepAlive
+      var keepalive: Keepalive
 
-      init(keepAlive: KeepAlive) {
+      init(keepalive: Keepalive) {
         self.openStreams = []
         self.lastStreamID = .rootStream
-        self.keepAlive = keepAlive
+        self.keepalive = keepalive
       }
     }
 
@@ -345,14 +345,14 @@ extension ServerConnectionManagementHandler.StateMachine {
       /// The ID of the most recently opened stream (zero indicates no streams have been opened yet).
       var lastStreamID: HTTP2StreamID
       /// The state of keep alive.
-      var keepAlive: KeepAlive
+      var keepalive: Keepalive
       /// Whether the second GOAWAY frame has been sent with a lower stream ID.
       var sentSecondGoAway: Bool
 
       init(from state: Active) {
         self.openStreams = state.openStreams
         self.lastStreamID = state.lastStreamID
-        self.keepAlive = state.keepAlive
+        self.keepalive = state.keepalive
         self.sentSecondGoAway = false
       }
     }

+ 28 - 28
Sources/GRPCHTTP2Core/Server/Connection/ServerConnectionManagementHandler.swift

@@ -60,14 +60,14 @@ final class ServerConnectionManagementHandler: ChannelDuplexHandler {
   private var maxGraceTimer: Timer?
 
   /// The amount of time to wait before sending a keep alive ping.
-  private var keepAliveTimer: Timer?
+  private var keepaliveTimer: Timer?
 
   /// The amount of time the client has to reply after sending a keep alive ping. Only used if
-  /// `keepAliveTimer` is set.
-  private var keepAliveTimeoutTimer: Timer
+  /// `keepaliveTimer` is set.
+  private var keepaliveTimeoutTimer: Timer
 
   /// Opaque data sent in keep alive pings.
-  private let keepAlivePingData: HTTP2PingData
+  private let keepalivePingData: HTTP2PingData
 
   /// Whether a flush is pending.
   private var flushPending: Bool
@@ -162,7 +162,7 @@ final class ServerConnectionManagementHandler: ChannelDuplexHandler {
       self.handler.eventLoop.assertInEventLoop()
       if self.handler.frameStats.didWriteHeadersOrData {
         self.handler.frameStats.reset()
-        self.handler.state.resetKeepAliveState()
+        self.handler.state.resetKeepaliveState()
       }
     }
 
@@ -186,12 +186,12 @@ final class ServerConnectionManagementHandler: ChannelDuplexHandler {
   ///   - maxIdleTime: The maximum amount time a connection may be idle for before being closed.
   ///   - maxAge: The maximum amount of time a connection may exist before being gracefully closed.
   ///   - maxGraceTime: The maximum amount of time that the connection has to close gracefully.
-  ///   - keepAliveTime: The amount of time to wait after reading data before sending a keep-alive
+  ///   - keepaliveTime: The amount of time to wait after reading data before sending a keep-alive
   ///       ping.
-  ///   - keepAliveTimeout: The amount of time the client has to reply after the server sends a
+  ///   - keepaliveTimeout: The amount of time the client has to reply after the server sends a
   ///       keep-alive ping to keep the connection open. The connection is closed if no reply
   ///       is received.
-  ///   - allowKeepAliveWithoutCalls: Whether the server allows the client to send keep-alive pings
+  ///   - allowKeepaliveWithoutCalls: Whether the server allows the client to send keep-alive pings
   ///       when there are no calls in progress.
   ///   - minPingIntervalWithoutCalls: The minimum allowed interval the client is allowed to send
   ///       keep-alive pings. Pings more frequent than this interval count as 'strikes' and the
@@ -202,9 +202,9 @@ final class ServerConnectionManagementHandler: ChannelDuplexHandler {
     maxIdleTime: TimeAmount?,
     maxAge: TimeAmount?,
     maxGraceTime: TimeAmount?,
-    keepAliveTime: TimeAmount?,
-    keepAliveTimeout: TimeAmount?,
-    allowKeepAliveWithoutCalls: Bool,
+    keepaliveTime: TimeAmount?,
+    keepaliveTimeout: TimeAmount?,
+    allowKeepaliveWithoutCalls: Bool,
     minPingIntervalWithoutCalls: TimeAmount,
     clock: Clock = .nio
   ) {
@@ -214,16 +214,16 @@ final class ServerConnectionManagementHandler: ChannelDuplexHandler {
     self.maxAgeTimer = maxAge.map { Timer(delay: $0) }
     self.maxGraceTimer = maxGraceTime.map { Timer(delay: $0) }
 
-    self.keepAliveTimer = keepAliveTime.map { Timer(delay: $0) }
+    self.keepaliveTimer = keepaliveTime.map { Timer(delay: $0) }
     // Always create a keep alive timeout timer, it's only used if there is a keep alive timer.
-    self.keepAliveTimeoutTimer = Timer(delay: keepAliveTimeout ?? .seconds(20))
+    self.keepaliveTimeoutTimer = Timer(delay: keepaliveTimeout ?? .seconds(20))
 
     // Generate a random value to be used as keep alive ping data.
     let pingData = UInt64.random(in: .min ... .max)
-    self.keepAlivePingData = HTTP2PingData(withInteger: pingData)
+    self.keepalivePingData = HTTP2PingData(withInteger: pingData)
 
     self.state = StateMachine(
-      allowKeepAliveWithoutCalls: allowKeepAliveWithoutCalls,
+      allowKeepaliveWithoutCalls: allowKeepaliveWithoutCalls,
       minPingReceiveIntervalWithoutCalls: minPingIntervalWithoutCalls,
       goAwayPingData: HTTP2PingData(withInteger: ~pingData)
     )
@@ -247,8 +247,8 @@ final class ServerConnectionManagementHandler: ChannelDuplexHandler {
       self.initiateGracefulShutdown(context: context)
     }
 
-    self.keepAliveTimer?.schedule(on: context.eventLoop) {
-      self.keepAliveTimerFired(context: context)
+    self.keepaliveTimer?.schedule(on: context.eventLoop) {
+      self.keepaliveTimerFired(context: context)
     }
 
     context.fireChannelActive()
@@ -258,8 +258,8 @@ final class ServerConnectionManagementHandler: ChannelDuplexHandler {
     self.maxIdleTimer?.cancel()
     self.maxAgeTimer?.cancel()
     self.maxGraceTimer?.cancel()
-    self.keepAliveTimer?.cancel()
-    self.keepAliveTimeoutTimer.cancel()
+    self.keepaliveTimer?.cancel()
+    self.keepaliveTimeoutTimer.cancel()
     context.fireChannelInactive()
   }
 
@@ -295,8 +295,8 @@ final class ServerConnectionManagementHandler: ChannelDuplexHandler {
     self.inReadLoop = true
 
     // Any read data indicates that the connection is alive so cancel the keep-alive timers.
-    self.keepAliveTimer?.cancel()
-    self.keepAliveTimeoutTimer.cancel()
+    self.keepaliveTimer?.cancel()
+    self.keepaliveTimeoutTimer.cancel()
 
     let frame = self.unwrapInboundIn(data)
     switch frame.payload {
@@ -323,8 +323,8 @@ final class ServerConnectionManagementHandler: ChannelDuplexHandler {
     self.inReadLoop = false
 
     // Done reading: schedule the keep-alive timer.
-    self.keepAliveTimer?.schedule(on: context.eventLoop) {
-      self.keepAliveTimerFired(context: context)
+    self.keepaliveTimer?.schedule(on: context.eventLoop) {
+      self.keepaliveTimerFired(context: context)
     }
 
     context.fireChannelReadComplete()
@@ -350,8 +350,8 @@ extension ServerConnectionManagementHandler {
     // Cancel any timers if initiating shutdown.
     self.maxIdleTimer?.cancel()
     self.maxAgeTimer?.cancel()
-    self.keepAliveTimer?.cancel()
-    self.keepAliveTimeoutTimer.cancel()
+    self.keepaliveTimer?.cancel()
+    self.keepaliveTimeoutTimer.cancel()
 
     switch self.state.startGracefulShutdown() {
     case .sendGoAwayAndPing(let pingData):
@@ -436,13 +436,13 @@ extension ServerConnectionManagementHandler {
     }
   }
 
-  private func keepAliveTimerFired(context: ChannelHandlerContext) {
-    let ping = HTTP2Frame(streamID: .rootStream, payload: .ping(self.keepAlivePingData, ack: false))
+  private func keepaliveTimerFired(context: ChannelHandlerContext) {
+    let ping = HTTP2Frame(streamID: .rootStream, payload: .ping(self.keepalivePingData, ack: false))
     context.write(self.wrapInboundOut(ping), promise: nil)
     self.maybeFlush(context: context)
 
     // Schedule a timeout on waiting for the response.
-    self.keepAliveTimeoutTimer.schedule(on: context.eventLoop) {
+    self.keepaliveTimeoutTimer.schedule(on: context.eventLoop) {
       self.initiateGracefulShutdown(context: context)
     }
   }

+ 21 - 21
Tests/GRPCHTTP2CoreTests/Client/Connection/ClientConnectionHandlerStateMachineTests.swift

@@ -22,9 +22,9 @@ import XCTest
 
 final class ClientConnectionHandlerStateMachineTests: XCTestCase {
   private func makeStateMachine(
-    keepAliveWithoutCalls: Bool = false
+    keepaliveWithoutCalls: Bool = false
   ) -> ClientConnectionHandler.StateMachine {
-    return ClientConnectionHandler.StateMachine(allowKeepAliveWithoutCalls: keepAliveWithoutCalls)
+    return ClientConnectionHandler.StateMachine(allowKeepaliveWithoutCalls: keepaliveWithoutCalls)
   }
 
   func testCloseSomeStreamsWhenActive() {
@@ -32,7 +32,7 @@ final class ClientConnectionHandlerStateMachineTests: XCTestCase {
     state.streamOpened(1)
     state.streamOpened(2)
     XCTAssertEqual(state.streamClosed(2), .none)
-    XCTAssertEqual(state.streamClosed(1), .startIdleTimer(cancelKeepAlive: true))
+    XCTAssertEqual(state.streamClosed(1), .startIdleTimer(cancelKeepalive: true))
   }
 
   func testCloseSomeStreamsWhenClosing() {
@@ -51,45 +51,45 @@ final class ClientConnectionHandlerStateMachineTests: XCTestCase {
     XCTAssertEqual(state.streamClosed(1), .none)
   }
 
-  func testSendKeepAlivePing() {
-    var state = self.makeStateMachine(keepAliveWithoutCalls: false)
+  func testSendKeepalivePing() {
+    var state = self.makeStateMachine(keepaliveWithoutCalls: false)
     // No streams open so ping isn't allowed.
-    XCTAssertFalse(state.sendKeepAlivePing())
+    XCTAssertFalse(state.sendKeepalivePing())
 
     // Stream open, ping allowed.
     state.streamOpened(1)
-    XCTAssertTrue(state.sendKeepAlivePing())
+    XCTAssertTrue(state.sendKeepalivePing())
 
     // No stream, no ping.
-    XCTAssertEqual(state.streamClosed(1), .startIdleTimer(cancelKeepAlive: true))
-    XCTAssertFalse(state.sendKeepAlivePing())
+    XCTAssertEqual(state.streamClosed(1), .startIdleTimer(cancelKeepalive: true))
+    XCTAssertFalse(state.sendKeepalivePing())
   }
 
-  func testSendKeepAlivePingWhenAllowedWithoutCalls() {
-    var state = self.makeStateMachine(keepAliveWithoutCalls: true)
+  func testSendKeepalivePingWhenAllowedWithoutCalls() {
+    var state = self.makeStateMachine(keepaliveWithoutCalls: true)
     // Keep alive is allowed when no streams are open, so pings are allowed.
-    XCTAssertTrue(state.sendKeepAlivePing())
+    XCTAssertTrue(state.sendKeepalivePing())
 
     state.streamOpened(1)
-    XCTAssertTrue(state.sendKeepAlivePing())
+    XCTAssertTrue(state.sendKeepalivePing())
 
-    XCTAssertEqual(state.streamClosed(1), .startIdleTimer(cancelKeepAlive: false))
-    XCTAssertTrue(state.sendKeepAlivePing())
+    XCTAssertEqual(state.streamClosed(1), .startIdleTimer(cancelKeepalive: false))
+    XCTAssertTrue(state.sendKeepalivePing())
   }
 
-  func testSendKeepAlivePingWhenClosing() {
-    var state = self.makeStateMachine(keepAliveWithoutCalls: false)
+  func testSendKeepalivePingWhenClosing() {
+    var state = self.makeStateMachine(keepaliveWithoutCalls: false)
     state.streamOpened(1)
     XCTAssertTrue(state.beginClosing())
 
     // Stream is opened and state is closing, ping is allowed.
-    XCTAssertTrue(state.sendKeepAlivePing())
+    XCTAssertTrue(state.sendKeepalivePing())
   }
 
-  func testSendKeepAlivePingWhenClosed() {
-    var state = self.makeStateMachine(keepAliveWithoutCalls: true)
+  func testSendKeepalivePingWhenClosed() {
+    var state = self.makeStateMachine(keepaliveWithoutCalls: true)
     _ = state.closed()
-    XCTAssertFalse(state.sendKeepAlivePing())
+    XCTAssertFalse(state.sendKeepalivePing())
   }
 
   func testBeginGracefulShutdownWhenStreamsAreOpen() {

+ 13 - 13
Tests/GRPCHTTP2CoreTests/Client/Connection/ClientConnectionHandlerTests.swift

@@ -70,8 +70,8 @@ final class ClientConnectionHandlerTests: XCTestCase {
     try connection.waitUntilClosed()
   }
 
-  func testKeepAliveWithOpenStreams() throws {
-    let connection = try Connection(keepAliveTime: .minutes(1), keepAliveTimeout: .seconds(10))
+  func testKeepaliveWithOpenStreams() throws {
+    let connection = try Connection(keepaliveTime: .minutes(1), keepaliveTimeout: .seconds(10))
     try connection.activate()
 
     // Open a stream so keep-alive starts.
@@ -96,8 +96,8 @@ final class ClientConnectionHandlerTests: XCTestCase {
     XCTAssertNil(try connection.readFrame())
   }
 
-  func testKeepAliveWithNoOpenStreams() throws {
-    let connection = try Connection(keepAliveTime: .minutes(1), allowKeepAliveWithoutCalls: true)
+  func testKeepaliveWithNoOpenStreams() throws {
+    let connection = try Connection(keepaliveTime: .minutes(1), allowKeepaliveWithoutCalls: true)
     try connection.activate()
 
     for _ in 0 ..< 10 {
@@ -114,8 +114,8 @@ final class ClientConnectionHandlerTests: XCTestCase {
     }
   }
 
-  func testKeepAliveWithOpenStreamsTimingOut() throws {
-    let connection = try Connection(keepAliveTime: .minutes(1), keepAliveTimeout: .seconds(10))
+  func testKeepaliveWithOpenStreamsTimingOut() throws {
+    let connection = try Connection(keepaliveTime: .minutes(1), keepaliveTimeout: .seconds(10))
     try connection.activate()
 
     // Open a stream so keep-alive starts.
@@ -135,7 +135,7 @@ final class ClientConnectionHandlerTests: XCTestCase {
     // - be closed
     connection.loop.advanceTime(by: .seconds(10))
 
-    XCTAssertEqual(try connection.readEvent(), .closing(.keepAliveExpired))
+    XCTAssertEqual(try connection.readEvent(), .closing(.keepaliveExpired))
 
     let frame2 = try XCTUnwrap(connection.readFrame())
     XCTAssertEqual(frame2.streamID, .rootStream)
@@ -217,17 +217,17 @@ extension ClientConnectionHandlerTests {
 
     init(
       maxIdleTime: TimeAmount? = nil,
-      keepAliveTime: TimeAmount? = nil,
-      keepAliveTimeout: TimeAmount? = nil,
-      allowKeepAliveWithoutCalls: Bool = false
+      keepaliveTime: TimeAmount? = nil,
+      keepaliveTimeout: TimeAmount? = nil,
+      allowKeepaliveWithoutCalls: Bool = false
     ) throws {
       let loop = EmbeddedEventLoop()
       let handler = ClientConnectionHandler(
         eventLoop: loop,
         maxIdleTime: maxIdleTime,
-        keepAliveTime: keepAliveTime,
-        keepAliveTimeout: keepAliveTimeout,
-        keepAliveWithoutCalls: allowKeepAliveWithoutCalls
+        keepaliveTime: keepaliveTime,
+        keepaliveTimeout: keepaliveTimeout,
+        keepaliveWithoutCalls: allowKeepaliveWithoutCalls
       )
 
       self.channel = EmbeddedChannel(handler: handler, loop: loop)

+ 6 - 6
Tests/GRPCHTTP2CoreTests/Client/Resolver/NameResolverRegistryTests.swift

@@ -178,7 +178,7 @@ final class NameResolverRegistryTests: XCTestCase {
     for _ in 0 ..< 1000 {
       let result = try await XCTUnwrapAsync { try await iterator.next() }
       XCTAssertEqual(result.endpoints, [Endpoint(addresses: [.ipv4(host: "foo", port: 1234)])])
-      XCTAssertNil(result.serviceConfiguration)
+      XCTAssertNil(result.serviceConfig)
     }
   }
 
@@ -199,7 +199,7 @@ final class NameResolverRegistryTests: XCTestCase {
           Endpoint(addresses: [.ipv4(host: "bar", port: 444)]),
         ]
       )
-      XCTAssertNil(result.serviceConfiguration)
+      XCTAssertNil(result.serviceConfig)
     }
   }
 
@@ -214,7 +214,7 @@ final class NameResolverRegistryTests: XCTestCase {
     for _ in 0 ..< 1000 {
       let result = try await XCTUnwrapAsync { try await iterator.next() }
       XCTAssertEqual(result.endpoints, [Endpoint(addresses: [.ipv6(host: "foo", port: 1234)])])
-      XCTAssertNil(result.serviceConfiguration)
+      XCTAssertNil(result.serviceConfig)
     }
   }
 
@@ -235,7 +235,7 @@ final class NameResolverRegistryTests: XCTestCase {
           Endpoint(addresses: [.ipv6(host: "bar", port: 444)]),
         ]
       )
-      XCTAssertNil(result.serviceConfiguration)
+      XCTAssertNil(result.serviceConfig)
     }
   }
 
@@ -250,7 +250,7 @@ final class NameResolverRegistryTests: XCTestCase {
     for _ in 0 ..< 1000 {
       let result = try await XCTUnwrapAsync { try await iterator.next() }
       XCTAssertEqual(result.endpoints, [Endpoint(addresses: [.unixDomainSocket(path: "/foo")])])
-      XCTAssertNil(result.serviceConfiguration)
+      XCTAssertNil(result.serviceConfig)
     }
   }
 
@@ -265,7 +265,7 @@ final class NameResolverRegistryTests: XCTestCase {
     for _ in 0 ..< 1000 {
       let result = try await XCTUnwrapAsync { try await iterator.next() }
       XCTAssertEqual(result.endpoints, [Endpoint(addresses: [.vsock(contextID: .any, port: .any)])])
-      XCTAssertNil(result.serviceConfiguration)
+      XCTAssertNil(result.serviceConfig)
     }
   }
 }

+ 8 - 8
Tests/GRPCHTTP2CoreTests/Server/Connection/ServerConnectionManagementHandler+StateMachineTests.swift

@@ -22,12 +22,12 @@ import XCTest
 
 final class ServerConnectionManagementHandlerStateMachineTests: XCTestCase {
   private func makeStateMachine(
-    allowKeepAliveWithoutCalls: Bool = false,
+    allowKeepaliveWithoutCalls: Bool = false,
     minPingReceiveIntervalWithoutCalls: TimeAmount = .minutes(5),
     goAwayPingData: HTTP2PingData = HTTP2PingData(withInteger: 42)
   ) -> ServerConnectionManagementHandler.StateMachine {
     return .init(
-      allowKeepAliveWithoutCalls: allowKeepAliveWithoutCalls,
+      allowKeepaliveWithoutCalls: allowKeepaliveWithoutCalls,
       minPingReceiveIntervalWithoutCalls: minPingReceiveIntervalWithoutCalls,
       goAwayPingData: goAwayPingData
     )
@@ -193,9 +193,9 @@ final class ServerConnectionManagementHandlerStateMachineTests: XCTestCase {
     XCTAssertEqual(state.receivedPing(atTime: time, data: data), .enhanceYourCalmThenClose(id))
   }
 
-  func testPingStrikesWhenKeepAliveIsNotPermittedWithoutCalls() {
+  func testPingStrikesWhenKeepaliveIsNotPermittedWithoutCalls() {
     let initialState = self.makeStateMachine(
-      allowKeepAliveWithoutCalls: false,
+      allowKeepaliveWithoutCalls: false,
       minPingReceiveIntervalWithoutCalls: .minutes(5)
     )
 
@@ -207,9 +207,9 @@ final class ServerConnectionManagementHandlerStateMachineTests: XCTestCase {
     self.testPingStrikeUsingMinReceiveInterval(state: &state, interval: .hours(2), expectedID: 0)
   }
 
-  func testPingStrikesWhenKeepAliveIsPermittedWithoutCalls() {
+  func testPingStrikesWhenKeepaliveIsPermittedWithoutCalls() {
     var state = self.makeStateMachine(
-      allowKeepAliveWithoutCalls: true,
+      allowKeepaliveWithoutCalls: true,
       minPingReceiveIntervalWithoutCalls: .minutes(5)
     )
 
@@ -218,7 +218,7 @@ final class ServerConnectionManagementHandlerStateMachineTests: XCTestCase {
 
   func testResetPingStrikeState() {
     var state = self.makeStateMachine(
-      allowKeepAliveWithoutCalls: true,
+      allowKeepaliveWithoutCalls: true,
       minPingReceiveIntervalWithoutCalls: .minutes(5)
     )
 
@@ -234,7 +234,7 @@ final class ServerConnectionManagementHandlerStateMachineTests: XCTestCase {
     XCTAssertEqual(state.receivedPing(atTime: time, data: data), .sendAck)
 
     // Reset the ping strike state and test ping strikes as normal.
-    state.resetKeepAliveState()
+    state.resetKeepaliveState()
     self.testPingStrikeUsingMinReceiveInterval(state: &state, interval: .minutes(5), expectedID: 0)
   }
 }

+ 24 - 24
Tests/GRPCHTTP2CoreTests/Server/Connection/ServerConnectionManagementHandlerTests.swift

@@ -128,10 +128,10 @@ final class ServerConnectionManagementHandlerTests: XCTestCase {
     try connection.waitUntilClosed()
   }
 
-  func testKeepAliveOnNewConnection() throws {
+  func testKeepaliveOnNewConnection() throws {
     let connection = try Connection(
-      keepAliveTime: .minutes(5),
-      keepAliveTimeout: .seconds(5)
+      keepaliveTime: .minutes(5),
+      keepaliveTimeout: .seconds(5)
     )
     try connection.activate()
 
@@ -151,10 +151,10 @@ final class ServerConnectionManagementHandlerTests: XCTestCase {
     XCTAssertNil(try connection.readFrame())
   }
 
-  func testKeepAliveStartsAfterReadLoop() throws {
+  func testKeepaliveStartsAfterReadLoop() throws {
     let connection = try Connection(
-      keepAliveTime: .minutes(5),
-      keepAliveTimeout: .seconds(5)
+      keepaliveTime: .minutes(5),
+      keepaliveTimeout: .seconds(5)
     )
     try connection.activate()
 
@@ -179,10 +179,10 @@ final class ServerConnectionManagementHandlerTests: XCTestCase {
     }
   }
 
-  func testKeepAliveOnNewConnectionWithoutResponse() throws {
+  func testKeepaliveOnNewConnectionWithoutResponse() throws {
     let connection = try Connection(
-      keepAliveTime: .minutes(5),
-      keepAliveTimeout: .seconds(5)
+      keepaliveTime: .minutes(5),
+      keepaliveTimeout: .seconds(5)
     )
     try connection.activate()
 
@@ -203,9 +203,9 @@ final class ServerConnectionManagementHandlerTests: XCTestCase {
     try connection.waitUntilClosed()
   }
 
-  func testClientKeepAlivePolicing() throws {
+  func testClientKeepalivePolicing() throws {
     let connection = try Connection(
-      allowKeepAliveWithoutCalls: true,
+      allowKeepaliveWithoutCalls: true,
       minPingIntervalWithoutCalls: .minutes(1)
     )
     try connection.activate()
@@ -235,9 +235,9 @@ final class ServerConnectionManagementHandlerTests: XCTestCase {
     try connection.waitUntilClosed()
   }
 
-  func testClientKeepAliveWithPermissibleIntervals() throws {
+  func testClientKeepaliveWithPermissibleIntervals() throws {
     let connection = try Connection(
-      allowKeepAliveWithoutCalls: true,
+      allowKeepaliveWithoutCalls: true,
       minPingIntervalWithoutCalls: .minutes(1),
       manualClock: true
     )
@@ -257,14 +257,14 @@ final class ServerConnectionManagementHandlerTests: XCTestCase {
     }
   }
 
-  func testClientKeepAliveResetState() throws {
+  func testClientKeepaliveResetState() throws {
     let connection = try Connection(
-      allowKeepAliveWithoutCalls: true,
+      allowKeepaliveWithoutCalls: true,
       minPingIntervalWithoutCalls: .minutes(1)
     )
     try connection.activate()
 
-    func sendThreeKeepAlivePings() throws {
+    func sendThreeKeepalivePings() throws {
       // The first ping is valid, the second and third are strikes.
       for _ in 1 ... 3 {
         try connection.ping(data: HTTP2PingData(), ack: false)
@@ -277,14 +277,14 @@ final class ServerConnectionManagementHandlerTests: XCTestCase {
       }
     }
 
-    try sendThreeKeepAlivePings()
+    try sendThreeKeepalivePings()
 
     // "send" a HEADERS frame and flush to reset keep alive state.
     connection.syncView.wroteHeadersFrame()
     connection.syncView.connectionWillFlush()
 
     // As above, the first ping is valid, the next two are strikes.
-    try sendThreeKeepAlivePings()
+    try sendThreeKeepalivePings()
 
     // The next ping is the third strike and triggers a GOAWAY.
     try connection.ping(data: HTTP2PingData(), ack: false)
@@ -353,9 +353,9 @@ extension ServerConnectionManagementHandlerTests {
       maxIdleTime: TimeAmount? = nil,
       maxAge: TimeAmount? = nil,
       maxGraceTime: TimeAmount? = nil,
-      keepAliveTime: TimeAmount? = nil,
-      keepAliveTimeout: TimeAmount? = nil,
-      allowKeepAliveWithoutCalls: Bool = false,
+      keepaliveTime: TimeAmount? = nil,
+      keepaliveTimeout: TimeAmount? = nil,
+      allowKeepaliveWithoutCalls: Bool = false,
       minPingIntervalWithoutCalls: TimeAmount = .minutes(5),
       manualClock: Bool = false
     ) throws {
@@ -371,9 +371,9 @@ extension ServerConnectionManagementHandlerTests {
         maxIdleTime: maxIdleTime,
         maxAge: maxAge,
         maxGraceTime: maxGraceTime,
-        keepAliveTime: keepAliveTime,
-        keepAliveTimeout: keepAliveTimeout,
-        allowKeepAliveWithoutCalls: allowKeepAliveWithoutCalls,
+        keepaliveTime: keepaliveTime,
+        keepaliveTimeout: keepaliveTimeout,
+        allowKeepaliveWithoutCalls: allowKeepaliveWithoutCalls,
         minPingIntervalWithoutCalls: minPingIntervalWithoutCalls,
         clock: self.clock
       )