-
Notifications
You must be signed in to change notification settings - Fork 950
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
Add an example that documents how to build an "escape hatch" NetworkBehaviour
that just hands out streams
#4457
Comments
NetworkBehaviour
that just hands out streamsNetworkBehaviour
that just hands out streams
I would love to give this a shot. Can I get assigned to this if possible? |
Side-note: Such an oppinonated behaviour could also be useful for low-level testing of protocols because we can plug the real implementation in on one end and use this behaviour on the other end where we get direct access to the stream. |
I'm sorry, I haven't been able to put in the hours into investigating this, and I don't foresee being able to in the next few weeks. Unasigning myself for now. If still open, I will pick this up later |
No worries at all, thanks for being proactive :) |
id like to pick this up |
That would be great actually! Coincidentally, I just bumped this to the top of my priority list this morning and was about to assign myself 😄 I think it is something that will really benefit our users. Since I wrote the above description, I slightly changed my mind on what the API should be after talking to @mxinden. Instead of taking a impl IncomingStreams {
pub async fn next(&mut self) -> (PeerId, Stream);
pub fn poll_next(&mut self) -> Poll<(PeerId, Stream)>;
}
impl Behaviour {
pub fn new(protocol: StreamProtocol) -> (Self, Control, IncomingStreams);
} The advantage of the above API is that it supports backpressure and if users want, they can always implement their own loop where they take a handler and call it with every stream. With this in mind, the goal of the example should be:
Let me know if this makes sense and whether you need any more guidance :) |
For a while now, `rust-libp2p` provided the `request-response` abstraction which makes it easy for users to build request-response based protocols without having to implement a `NetworkBehaviour` themselves. This PR introduces an alpha version of `libp2p-stream`: a `NetworkBehaviour` that directly gives access to negotiated streams. In addition to complementing `request-response`, `libp2p-stream` also diverges in its design from the remaining modules by offering a clonable `Control` that provides `async` functions. Resolves: #4457. Pull-Request: #5027.
This is now released! https://github.com/libp2p/rust-libp2p/releases/tag/libp2p-stream-v0.1.0-alpha |
For a while now, `rust-libp2p` provided the `request-response` abstraction which makes it easy for users to build request-response based protocols without having to implement a `NetworkBehaviour` themselves. This PR introduces an alpha version of `libp2p-stream`: a `NetworkBehaviour` that directly gives access to negotiated streams. In addition to complementing `request-response`, `libp2p-stream` also diverges in its design from the remaining modules by offering a clonable `Control` that provides `async` functions. Resolves: libp2p#4457. Pull-Request: libp2p#5027.
For a while now, `rust-libp2p` provided the `request-response` abstraction which makes it easy for users to build request-response based protocols without having to implement a `NetworkBehaviour` themselves. This PR introduces an alpha version of `libp2p-stream`: a `NetworkBehaviour` that directly gives access to negotiated streams. In addition to complementing `request-response`, `libp2p-stream` also diverges in its design from the remaining modules by offering a clonable `Control` that provides `async` functions. Resolves: libp2p#4457. Pull-Request: libp2p#5027.
Simply getting access to a stream without having to implement
NetworkBehaviour
has been discussed a lot. Mostly in #2657 and other linked issues.This issue documents an example that we would like to add to the repository which users can copy and modify to their needs. Perhaps we can eventually grow something useful out of that :)
The example should:
The above is essentially the
ping
protocol but implemented "outside" ofrust-libp2p
, i.e. not as a module. This should serve as a good-enough starting point for users that want to implement something custom.The library component of the example should contain a
NetworkBehaviour
with roughly the following API:A couple of design notes:
Fn
because it is simple. If state needs to be shared across inbound streams, it is better to just implement aConnectionHandler
as it will come out much cleaner.Control
object allows creation of streams without interacting withSwarm
. The assumption is that most users that want this kind of functionality don't want to interact with theSwarm
through an event loop.Control
object with more messages.The text was updated successfully, but these errors were encountered: