Add a send_request function to NetworkService (#8008)

* Add a `send_request` to `NetworkService`.

This function delivers responses via a provided sender and also allows
for sending requests to currently not connected peers.

* Document caveats of send_request better.

* Fix compilation in certain cases.

* Update docs + introduce IfDisconnected enum

for more readable function calls.

* Doc fix.

* Rename send_request to detached_request.

* Whitespace fix - arrrgh

* Update client/network/src/service.rs

spaces/tabs

Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>

* Update client/network/src/request_responses.rs

Documentation fix

Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>

* Update client/network/src/service.rs

Typo.

Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>

* Update client/network/src/service.rs

Better docs.

Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>

* Update client/network/src/service.rs

Typo.

Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>

* Update client/network/src/service.rs

Doc improvements.

Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>

* Remove error in logs on dialing a peer.

This is now valid behaviour.

* Rename detached_request to start_request.

As suggested by @romanb.

* Fix merged master.

* Fix too long lines.

Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
This commit is contained in:
Robert Klotzner
2021-02-02 20:52:12 +01:00
committed by GitHub
parent 73386a4215
commit 3628998d3c
3 changed files with 85 additions and 23 deletions
+19 -6
View File
@@ -45,6 +45,7 @@ use std::{
pub use crate::request_responses::{
ResponseFailure, InboundFailure, RequestFailure, OutboundFailure, RequestId,
IfDisconnected
};
/// General behaviour of the network. Combines all protocols together.
@@ -248,8 +249,9 @@ impl<B: BlockT, H: ExHashT> Behaviour<B, H> {
protocol: &str,
request: Vec<u8>,
pending_response: oneshot::Sender<Result<Vec<u8>, RequestFailure>>,
connect: IfDisconnected,
) {
self.request_responses.send_request(target, protocol, request, pending_response)
self.request_responses.send_request(target, protocol, request, pending_response, connect)
}
/// Returns a shared reference to the user protocol.
@@ -317,7 +319,7 @@ Behaviour<B, H> {
}
self.request_responses.send_request(
&target, &self.block_request_protocol_name, buf, pending_response,
&target, &self.block_request_protocol_name, buf, pending_response, IfDisconnected::ImmediateError,
);
},
CustomMessageOutcome::NotificationStreamOpened { remote, protocol, roles, notifications_sink } => {
@@ -454,11 +456,22 @@ impl<B: BlockT, H: ExHashT> Behaviour<B, H> {
_: &mut impl PollParameters,
) -> Poll<NetworkBehaviourAction<TEv, BehaviourOut<B>>> {
use light_client_requests::sender::OutEvent;
while let Poll::Ready(Some(event)) = self.light_client_request_sender.poll_next_unpin(cx) {
while let Poll::Ready(Some(event)) =
self.light_client_request_sender.poll_next_unpin(cx)
{
match event {
OutEvent::SendRequest { target, request, pending_response, protocol_name } => {
self.request_responses.send_request(&target, &protocol_name, request, pending_response)
}
OutEvent::SendRequest {
target,
request,
pending_response,
protocol_name,
} => self.request_responses.send_request(
&target,
&protocol_name,
request,
pending_response,
IfDisconnected::ImmediateError,
),
}
}