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

Add a request-response NetworkBehaviour helper #1562

Closed
tomaka opened this issue Apr 30, 2020 · 1 comment
Closed

Add a request-response NetworkBehaviour helper #1562

tomaka opened this issue Apr 30, 2020 · 1 comment
Assignees

Comments

@tomaka
Copy link
Member

tomaka commented Apr 30, 2020

Writing a simple "request-response" protocol (where each request opens a new substream) is way too complicated at the moment, despite the OneShotHandler.

Instead, in my opinion there should be some sort of helper structs.

Here is an API sketch:

impl<T: OutboundUpgrade> Request<T> {
    pub fn new(protocol: T) -> Self { ... }
    pub fn start_request(&mut self, destination: &PeerId) -> Result<..., ...>;
    pub fn in_progress(&self) -> impl Iterator<Item = InProgress> { ... }
}
impl<T: OutboundUpgrade> NetworkBehaviour for Request<T> { ... }

impl<T: InboundUpgrade> Respond<T> {
    pub fn pending(&self) -> impl Iterator<Item = Pending> { ... }
}
impl<T: InboundUpgrade> NetworkBehaviour for Respond<T> { ... }

/// `Pending` borrows an entry within the `Respond`
impl<'a> Pending<'a> {
    pub fn source(&self) -> &PeerId { ... }
    pub fn request(&self) -> &... { ... }
    pub fn respond(self, response: ...) { ... }
}

Thanks to this, it would be possible to write just an implementation of OutboundUpgrade and InboundUpgrade.

This could also be combined with libp2p_core::upgrade::from_fn to create protocols in one line of code, provided Rust gets existential types.

Related: #1530

@tomaka tomaka changed the title Add a RequestResponse NetworkBehaviour Add a request-response NetworkBehaviour helper Apr 30, 2020
@romanb romanb self-assigned this May 7, 2020
@romanb
Copy link
Contributor

romanb commented Jul 1, 2020

libp2p-request-response has been released. Further work along the line of bugs and improvements are probably better tracked in new tickets.

@romanb romanb closed this as completed Jul 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants