n0-computer / quic-rpc

A streaming rpc system based on quic
Other
99 stars 15 forks source link

How to obtain remote ip? #91

Open mzdk100 opened 3 months ago

mzdk100 commented 3 months ago

How to determine which remote host (Remote IP Address) a request comes from?

rklaehn commented 2 months ago

It is currently not possible to do this in general. The connection could be non ip-based, like for example in-memory.

For a network-based connection like a quinn connection you could add this, but so far we have not seen a need to do so.

mzdk100 commented 2 months ago

Can we implement a similar interface function 'get_remote_addr()' on RpcChannel? If it is an in memory connection, calling this function can be an undefined behavior. Because I need to track the IP address requested by the user.

matheus23 commented 2 months ago

I think it should be possible to write your own struct, let's say MyServerEndpoint, that stores a QuinnServerEndpoint and implements the ServerEndpoint trait. This way you can intercept quinn's Incoming values from its accept function, and you thus get access to its remote_address.

This doesn't help you get the IP address information to the RPC service interfaces, but it's good enough for e.g. IP address allow-listing.

mzdk100 commented 2 months ago

Do you have any specific examples?

matheus23 commented 2 months ago

You could take a look at the QuinnServerEndpoint implementation for ServerEndpoint. Otherwise to get a feeling for ServerEndpoint, you can look at the source code for the memory-based implementations, too. I don't have a specific example for you're asking for right now :/