Skip to content

Commit

Permalink
chore(p2p-rrs): wip
Browse files Browse the repository at this point in the history
  • Loading branch information
CHr15F0x committed Nov 3, 2023
1 parent 5bbb233 commit d5f164c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
6 changes: 5 additions & 1 deletion crates/p2p-rrs/src/handler/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
use crate::codec::Codec;
use crate::RequestId;

use futures::{channel::oneshot, future::BoxFuture, prelude::*};
use futures::{
channel::{mpsc, oneshot},
future::BoxFuture,
prelude::*,
};
use libp2p::core::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo};
use libp2p::swarm::Stream;
use smallvec::SmallVec;
Expand Down
28 changes: 27 additions & 1 deletion crates/p2p-rrs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ mod handler;
pub use codec::Codec;

use crate::handler::protocol::RequestProtocol;
use futures::channel::oneshot;
use futures::channel::{mpsc, oneshot};
use handler::Handler;
use libp2p::core::{ConnectedPoint, Endpoint, Multiaddr};
use libp2p::identity::PeerId;
Expand Down Expand Up @@ -103,6 +103,31 @@ pub enum Message<TRequest, TResponse, TChannelResponse = TResponse> {
/// The events emitted by a request-response [`Behaviour`].
#[derive(Debug)]
pub enum Event<TRequest, TResponse, TChannelResponse = TResponse> {
/// An incoming request from another peer.
InboundRequest {
/// The peer who sent the request.
peer: PeerId,
/// The ID of the request.
request_id: RequestId,
/// The request message.
request: TRequest,
/// The channel through which we are expected to send responses.
///
/// TODO handle the channel related errors
channel: mpsc::Sender<TChannelResponse>,
},
/// Outbound request to another peer was accepted and we can now await responses.
OutboundRequestAccepted {
/// The peer who received our request.
peer: PeerId,
/// The ID of the outbound request.
request_id: RequestId,
/// The channel through which we can receive the responses.
///
/// TODO handle the channel related errors
channel: mpsc::Receiver<TResponse>,
},
/// TODO remove
/// An incoming message (request or response).
Message {
/// The peer who sent the message.
Expand All @@ -128,6 +153,7 @@ pub enum Event<TRequest, TResponse, TChannelResponse = TResponse> {
/// The error that occurred.
error: InboundFailure,
},
/// TODO remove
/// A response to an inbound request has been sent.
///
/// When this event is received, the response has been flushed on
Expand Down

0 comments on commit d5f164c

Please sign in to comment.