-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
Provide an option to specify base context for RPC connection #595
Conversation
Signed-off-by: Dzmitry Mikhalapau <[email protected]>
Signed-off-by: Dzmitry Mikhalapau <[email protected]>
@lthibault Hi! Don't know whether it's ok to ping you, but could you review the PR please, if/when you have some free time? :) Thanks in advance! |
hey @homier, yes, totally okay to ping me! Reviewing now :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Firstly, thank you for the contribution! Just a quick question before I approve: have you tested that the behavior is the one you expect when the context is canceled? I'd expect it to close the connection, and judging from the code, that should happen.
Can we add a quick test for this behavior?
P.S.: as a libp2p developer myself, I'm very curious to know what you're building :)
@lthibault Thanks for the review! I'll add a test as soon as possible when I have some free time :) Expect a new ping from me 🙈
Yeah, everything works fine, I'm using my fork with this patch at the moment, works as expected. But anyway, I'll add some tests to ensure that expected behaviour is not broken.
Nothing special, I'm just doing my pet project with p2p file sharing in a form of mobile application at the moment. The code is closed now, though I'm planning to open it when I won't be ashamed of its quality :D |
I'll merge in the meantime, just for the sake of expediency. Just go ahead and add the test in a separate PR when you get a chance. Thanks again for your contribution! |
Rationale
Providing a function to build base context is really useful in situations, when we need to propagate some, let's say, identity data to server handlers. Let's take the following issue as an example:
The problem is that now the only way to do this is to set it in
rpc.Conn
and pass the connection to handlers, but this breaks abstraction between transport layer and application layer.But we could do a simple change to have a context factory, so all the necessary connection information could be set in context, that will be passed to handlers later. And it's similar to how the native
http.Server
interface is built.Real-life example (using libp2p as network stack):