Added async request-reply for Tari p2p services#670
Merged
CjS77 merged 3 commits intodevelopmentfrom Aug 15, 2019
Merged
Conversation
db0ef23 to
14819c6
Compare
This PR contains the building blocks for async p2p services. It consists of the following modules: - `builder`: contains the `MakeServicePair` trait which should be implemented by a service builder and the `StackBuilder` struct which is responsible for building the service and making service _handles_ available to all the other services. Handles are any object which is able to control a service in some way. Most commonly the handle will be a `transport::Requester<MyServiceRequest>`. - `handles`: struct for collecting named handles for services. The `StackBuilder` uses this to make all handles available to services. - `transport`: This allows messages to be reliably send/received to/from services. A `Requester`/`Responder` pair is created using the `transport::channel` function which takes an impl of `tower_service::Service` as it's first parameter. A `Requester` implements `tower_service::Service` and is used to send requests which return a Future which resolves to a response. The `Requester` uses a `oneshot` channel allow responses to be sent back. A `Responder` receives a `(request, oneshot::Sender)` tuple, calls the given tower service with that request and sends the result on the `oneshot::Sender`. The `Responder` handles many requests simultaneously.
14819c6 to
16bb512
Compare
neonknight64
previously approved these changes
Aug 15, 2019
Contributor
neonknight64
left a comment
There was a problem hiding this comment.
With my limited futures knowledge, it looks good.
CjS77
added a commit
that referenced
this pull request
Aug 15, 2019
This PR contains the building blocks for async p2p services. It consists of the following modules: * builder: contains the MakeServicePair trait which should be implemented by a service builder and the StackBuilder struct which is responsible for building the service and making service handles available to all the other services. Handles are any object which is able to control a service in some way. Most commonly the handle will be a transport::Requester<MyServiceRequest>. * handles: struct for collecting named handles for services. The StackBuilder uses this to make all handles available to services. * transport: This allows messages to be reliably send/received to/from services. A Requester/Responder pair is created using the transport::channel function which takes an impl of tower_service::Service as it's first parameter. A Requester implements tower_service::Service and is used to send requests which return a Future which resolves to a response. The Requester uses a oneshot channel allow responses to be sent back. A Responder receives a (request, oneshot::Sender) tuple, calls the given tower service with that request and sends the result on the oneshot::Sender. The Responder handles many requests simultaneously. Notes: This PR adds the rust feature #![feature(existential_type)] to reduce the need to box futures in many cases - more info here: rust-lang/rfcs#2071 TODO: Hook up pub/sub messages from the comms layer. (Ref #644)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR contains the building blocks for async p2p services.
It consists of the following modules:
builder: contains theMakeServicePairtrait which should be implemented by a service builder and theStackBuilderstruct which is responsible for building the service and making service handles available to all the other services. Handles are any object which is able to control a service in some way. Most commonly the handle will be atransport::Requester<MyServiceRequest>.handles: struct for collecting named handles for services. TheStackBuilderuses this to make all handles available to services.transport: This allows messages to be reliably send/received to/from services. ARequester/Responderpair is created using thetransport::channelfunction which takes an impl oftower_service::Serviceas it's first parameter. ARequesterimplementstower_service::Serviceand is used to send requests which return a Futurewhich resolves to a response. The
Requesteruses aoneshotchannel allow responses to be sent back. AResponderreceives a(request, oneshot::Sender)tuple, calls the given tower service with that request and sends the result on theoneshot::Sender. TheResponderhandles many requests simultaneously.Notes:
#![feature(existential_type)]to reduce the need to box futures in many cases - more info here: Named existentials and impl Trait variable declarations rust-lang/rfcs#2071TODO:
Motivation and Context
Ref #654
Epic #621
How Has This Been Tested?
Relevant unit tests
Types of changes
Checklist:
developmentbranchcargo-fmt --allbefore pushing