Skip to content

Commit

Permalink
chore: docs
Browse files Browse the repository at this point in the history
  • Loading branch information
CHr15F0x committed Nov 21, 2023
1 parent d2f83ea commit 1505968
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion crates/p2p_stream/src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub trait Codec {
/// negotiated protocol.
/// __Must return Ok(None) if the stream is closed gracefully,
/// i.e. when there are 0 bytes left to read at the beginning of
/// [`read_response`].__
/// [`Codec::read_response`].__
async fn read_response<T>(
&mut self,
protocol: &Self::Protocol,
Expand Down
8 changes: 3 additions & 5 deletions crates/p2p_stream/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl std::error::Error for OutboundFailure {}
pub enum InboundFailure {
/// The inbound request timed out, either while reading the
/// incoming request or before a response is sent, e.g. if
/// [`InboundRequest::channel::send`] is not called in a
/// `Event::InboundRequest::channel::send` is not called in a
/// timely manner.
Timeout,
/// The connection closed before a response could be send.
Expand Down Expand Up @@ -325,11 +325,9 @@ where
/// connection is established.
///
/// > **Note**: In order for such a dialing attempt to succeed,
/// > the `RequestResonse` protocol must either be embedded
/// > the `RequestResponse` protocol must be embedded
/// > in another `NetworkBehaviour` that provides peer and
/// > address discovery, or known addresses of peers must be
/// > managed via [`Behaviour::add_address`] and
/// > [`Behaviour::remove_address`].
/// > address discovery.
pub fn send_request(&mut self, peer: &PeerId, request: TCodec::Request) -> OutboundRequestId {
let request_id = self.next_outbound_request_id();

Expand Down
24 changes: 12 additions & 12 deletions crates/p2p_stream/tests/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use utils::{
TestSwarm,
};

struct Requestor {
struct Requester {
peer_id: PeerId,
swarm: TestSwarm,
}
Expand All @@ -25,7 +25,7 @@ struct Responder {
}

struct Scenario {
requestor: Requestor,
requester: Requester,
responder: Responder,
}

Expand All @@ -44,7 +44,7 @@ async fn client_request_to_server() -> Scenario {
let (srv_peer_id, srv_swarm, cli_peer_id, cli_swarm) = setup().await;

Scenario {
requestor: Requestor {
requester: Requester {
peer_id: cli_peer_id,
swarm: cli_swarm,
},
Expand All @@ -59,7 +59,7 @@ async fn server_request_to_client() -> Scenario {
let (srv_peer_id, srv_swarm, cli_peer_id, cli_swarm) = setup().await;

Scenario {
requestor: Requestor {
requester: Requester {
peer_id: srv_peer_id,
swarm: srv_swarm,
},
Expand All @@ -85,7 +85,7 @@ async fn sanity(
.try_init();

let Scenario {
mut requestor,
mut requester,
mut responder,
} = scenario.await;

Expand All @@ -97,7 +97,7 @@ async fn sanity(
let (peer, req_id, action, mut resp_tx) =
wait_inbound_request(&mut responder.swarm).await.unwrap();

assert_eq!(peer, requestor.peer_id);
assert_eq!(peer, requester.peer_id);
assert_eq!(action, Action::SanityRequest);

for i in 0..num_responses {
Expand All @@ -114,18 +114,18 @@ async fn sanity(
.await
.unwrap();

assert_eq!(peer, requestor.peer_id);
assert_eq!(peer, requester.peer_id);
assert_eq!(req_id_done, req_id);
};

let requestor_task = async move {
let req_id = requestor
let requester_task = async move {
let req_id = requester
.swarm
.behaviour_mut()
.send_request(&responder.peer_id, Action::SanityRequest);

let (peer, req_id_done, mut resp_rx) =
wait_outbound_request_sent_awaiting_responses(&mut requestor.swarm)
wait_outbound_request_sent_awaiting_responses(&mut requester.swarm)
.await
.unwrap();

Expand All @@ -139,13 +139,13 @@ async fn sanity(
);
}

let (peer, req_id_done) = wait_inbound_response_stream_closed(&mut requestor.swarm)
let (peer, req_id_done) = wait_inbound_response_stream_closed(&mut requester.swarm)
.await
.unwrap();

assert_eq!(peer, responder.peer_id);
assert_eq!(req_id_done, req_id);
};

tokio::join!(responder_task, requestor_task);
tokio::join!(responder_task, requester_task);
}

0 comments on commit 1505968

Please sign in to comment.