GithubHelp home page GithubHelp logo

Comments (4)

LucioFranco avatar LucioFranco commented on July 30, 2024

Thanks for opening this detailed issue! So I am really cautious about introducing something like a PeerAddr to request since it's designed intentionally to not expose any details about the transport/encodings.

For the client, I believe the channel can expose who it's connected too but this also might not make sense if you're load balancing.

For the server, hyper itself provides a way to get nonexclusive access to the IO type which then can provide the remote address. Via this, we could probably provide some middleware to extract this and attach it to the metadata of every inbound request. What do you think about that? This would require that we somehow serialize the peer address into some form of bytes but I think this might provide the most flexible solution.

from tonic.

domodwyer avatar domodwyer commented on July 30, 2024

Hi @LucioFranco

I actually took a peek at using an interceptor to populate the metadata exactly as you suggest, but currently it has the http layer Request only so went looking elsewhere - I think it would be a good way of opting into the functionality (it's safe to say it's not needed by everyone) and feels quite natural.

I must admit I have only been considering the server side of this until now - I've not used the client yet, so can't really suggest anything meaningful.

Dom

from tonic.

LucioFranco avatar LucioFranco commented on July 30, 2024

Right so this gets a bit funky ill try to explain a bit here:

So in tower, we use two types of Service's for servers. We use an outter MakeService that creates some inner service for each connection, that inner service then gets dispatched aka called for each inbound request. The outter MakeService contains a target. You can see some of this here https://github.com/hyperium/tonic/blob/master/tonic/src/transport/server.rs#L384 and you will notice that the type T is actually ignored here. In fact this with hyper turns out to be the IO type given by a & reference. So this is a bit lower level then what I'd like do to with interceptors but this is totally possible. So if you wrap your generated MakeService from codegen like I do here you can extract and then inject. Let me know if that makes sense :)

from tonic.

domodwyer avatar domodwyer commented on July 30, 2024

Great - makes perfect sense.

I'll take a look some time in the next week, thanks for the pointers!

from tonic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.