Difficulties to configure requiredInterfaceType for GRPCChannel
jbgosselin opened this issue · 2 comments
What are you trying to achieve?
Hi grpc-swift team, I would like to be able to force a GRPC connection/call to happen on the cellular network only.
My best shot so far was to create a NWConnection
with NWParameters.requiredInterfaceType
. But I can't find a way to either configure this with grpc-swift or being able to pass a NIO's Channel
to the library.
I see there is some wrappers around generating the NIO Channel here https://swiftinit.org/docs/grpc-swift/grpc/clientbootstrapprotocol, but it seems that I cannot call withExistingNWConnection
on it https://swiftpackageindex.com/apple/swift-nio-transport-services/1.21.0/documentation/niotransportservices/niotsconnectionbootstrap/withexistingnwconnection(_:)
Do you have some advice if this is currently possible, if so how to achieve this ?
Otherwise, what would be the course of action to add the possibility to force the interface used ?
What have you tried so far?
Here is a code snippet to create a NIO Channel with such connection.
import Network
import NIOTransportServices
import GRPC
func fooBar() async throws {
guard let url = URL(string: "https://www.google.com") else {
return
}
let endpoint = NWEndpoint.url(url)
let parameters = NWParameters(tls: nil, tcp: Network.NWProtocolTCP.Options())
parameters.requiredInterfaceType = .cellular
let connection = NWConnection(to: endpoint, using: parameters)
let eventLoopGroup = NIOTSEventLoopGroup()
let channel = try await NIOTSConnectionBootstrap.init(group: eventLoopGroup).withExistingNWConnection(connection).get()
}
Thanks in advance !
This isn't currently possible, but it is something we should be able to add. It's somewhat related to #1913 which also requires more API for creating connections with NWConnections/NWListeners.
Thanks a lot for the fast answer !
Yes this looks similar than the mentioned issue.
We are looking forward this addition in the future 🙌
Just for understanding the change, would it be adding a ConnectionTarget
that would receive a NWConnection
?