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

Use uds client without TryFrom #608

Open
al8n opened this issue Apr 18, 2021 · 2 comments
Open

Use uds client without TryFrom #608

al8n opened this issue Apr 18, 2021 · 2 comments
Labels
A-tonic C-enhancement Category: New feature or request

Comments

@al8n
Copy link

al8n commented Apr 18, 2021

Is there a way to build a uds channel without use try_from? Is there a way we can directly connect to the socket file? Will Endpoint::try_from panic when the socket address has already been using?

#[cfg(unix)]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // We will ignore this uri because uds do not use it
    // if your connector does use the uri it will be provided
    // as the request to the `MakeConnection`.
    let channel = Endpoint::try_from("http://[::]:50051")?
        .connect_with_connector(service_fn(|_: Uri| {
            let path = "/tmp/tonic/helloworld";

            // Connect to a Uds socket
            UnixStream::connect(path)
        }))
        .await?;

    let mut client = GreeterClient::new(channel);

    let request = tonic::Request::new(HelloRequest {
        name: "Tonic".into(),
    });

    let response = client.say_hello(request).await?;

    println!("RESPONSE={:?}", response);

    Ok(())
}
@davidpdrsn
Copy link
Member

davidpdrsn commented May 1, 2021

Is there a way to build a uds channel without use try_from? Is there a way we can directly connect to the socket file?

Not currently but might be reasonable feature to add.

Will Endpoint::try_from panic when the socket address has already been using?

It will not. It just constructs an http::uri::Uri which does no IO.

@davidpdrsn davidpdrsn added A-tonic C-enhancement Category: New feature or request labels May 1, 2021
@cmcantalupo
Copy link

cmcantalupo commented Jan 24, 2023

Is there a string that can be provided to Endpoint::try_from() that will be guaranteed to fail such that we can be sure that the UDS file is used? Perahaps "" or "/dev/null". In the GEOPM use case, connecting to another endpoint would be a security concern:

https://github.com/geopm/geopm/pull/2779/files#diff-35aec12ebceeffd53bd51330ff6410403decc38fb1c56b898e9e3a6adece0379R164-R168

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tonic C-enhancement Category: New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants