-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR adopts the changes introduced in grpc/grpc-swift#2158, requiring client transports to provide a `ClientContext` alongside the stream.
- Loading branch information
Showing
12 changed files
with
218 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
Sources/GRPCNIOTransportCore/Internal/Channel+AddressInfo.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright 2025, gRPC Authors All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
internal import NIOCore | ||
|
||
extension NIOAsyncChannel { | ||
var remoteAddressInfo: String { | ||
guard let remote = self.channel.remoteAddress else { | ||
return "<unknown>" | ||
} | ||
|
||
switch remote { | ||
case .v4(let address): | ||
// '!' is safe, v4 always has a port. | ||
return "ipv4:\(address.host):\(remote.port!)" | ||
|
||
case .v6(let address): | ||
// '!' is safe, v6 always has a port. | ||
return "ipv6:[\(address.host)]:\(remote.port!)" | ||
|
||
case .unixDomainSocket: | ||
// '!' is safe, UDS always has a path. | ||
if remote.pathname!.isEmpty { | ||
guard let local = self.channel.localAddress else { | ||
return "unix:<unknown>" | ||
} | ||
|
||
switch local { | ||
case .unixDomainSocket: | ||
// '!' is safe, UDS always has a path. | ||
return "unix:\(local.pathname!)" | ||
|
||
case .v4, .v6: | ||
// Remote address is UDS but local isn't. This shouldn't ever happen. | ||
return "unix:<unknown>" | ||
} | ||
} else { | ||
// '!' is safe, UDS always has a path. | ||
return "unix:\(remote.pathname!)" | ||
} | ||
} | ||
} | ||
|
||
var localAddressInfo: String { | ||
guard let local = self.channel.localAddress else { | ||
return "<unknown>" | ||
} | ||
|
||
switch local { | ||
case .v4(let address): | ||
// '!' is safe, v4 always has a port. | ||
return "ipv4:\(address.host):\(local.port!)" | ||
|
||
case .v6(let address): | ||
// '!' is safe, v6 always has a port. | ||
return "ipv6:[\(address.host)]:\(local.port!)" | ||
|
||
case .unixDomainSocket: | ||
// '!' is safe, UDS always has a path. | ||
if local.pathname!.isEmpty { | ||
guard let remote = self.channel.remoteAddress else { | ||
return "unix:<unknown>" | ||
} | ||
|
||
switch remote { | ||
case .unixDomainSocket: | ||
// '!' is safe, UDS always has a path. | ||
return "unix:\(remote.pathname!)" | ||
|
||
case .v4, .v6: | ||
// Remote address is UDS but local isn't. This shouldn't ever happen. | ||
return "unix:<unknown>" | ||
} | ||
} else { | ||
// '!' is safe, UDS always has a path. | ||
return "unix:\(local.pathname!)" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.