-
Notifications
You must be signed in to change notification settings - Fork 219
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
Added async request-reply for Tari p2p services #670
Merged
Merged
Conversation
This file contains 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
sdbondi
force-pushed
the
sb-p2p-async-services
branch
from
August 14, 2019 06:49
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.
sdbondi
force-pushed
the
sb-p2p-async-services
branch
from
August 14, 2019 06:55
14819c6
to
16bb512
Compare
neonknight64
previously approved these changes
Aug 15, 2019
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With my limited futures knowledge, it looks good.
neonknight64
approved these changes
Aug 15, 2019
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
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)
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 theMakeServicePair
trait which should be implemented by a service builder and theStackBuilder
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 atransport::Requester<MyServiceRequest>
.handles
: struct for collecting named handles for services. TheStackBuilder
uses this to make all handles available to services.transport
: This allows messages to be reliably send/received to/from services. ARequester
/Responder
pair is created using thetransport::channel
function which takes an impl oftower_service::Service
as it's first parameter. ARequester
implementstower_service::Service
and is used to send requests which return a Futurewhich resolves to a response. The
Requester
uses aoneshot
channel allow responses to be sent back. AResponder
receives a(request, oneshot::Sender)
tuple, calls the given tower service with that request and sends the result on theoneshot::Sender
. TheResponder
handles 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:
development
branchcargo-fmt --all
before pushing