Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Difficulties to configure requiredInterfaceType for GRPCChannel #1943

Open
jbgosselin opened this issue Jun 20, 2024 · 2 comments
Open

Difficulties to configure requiredInterfaceType for GRPCChannel #1943

jbgosselin opened this issue Jun 20, 2024 · 2 comments
Labels

Comments

@jbgosselin
Copy link

jbgosselin commented Jun 20, 2024

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 !

@glbrntt
Copy link
Collaborator

glbrntt commented Jun 21, 2024

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.

@jbgosselin
Copy link
Author

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants