-
Notifications
You must be signed in to change notification settings - Fork 33
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
RFC: Handshaker Redesign #48
Comments
Currently have some example code illustrating the above RFC, will upload soon. |
Minimal example is up: https://github.com/GGist/bip-rs/tree/rfc_handshaker_example Ping @astro |
As a second thought, I think leaving off |
Final Comment Period, will close as accepted in two days. May change the naming of some of the items in the trait. Particularly, a more descriptive and specific name than A concrete Also, keep in mind that this metadata is what we will eventually use to send back information from DHT |
Problem
The
bip
ecosystem is meant to contain a modular set of crates that expose functionality and services to clients wishing to leverage BitTorrent infrastructure in their applications. We want to be able to provide flexibility for a client so that they can painlessly integrate either a single crate or many crates from our ecosystem into their application. In the case of a single crate, that crate should provide a usable interface to clients; in the case of many crates, those crates should provide a unified interface to clients.Because of this, we cannot afford to export a per crate asynchronous or synchronous interface for clients to use as that would force a specific architecture on our clients for the purposes of tieing our API into their application.
Goal
Provide a generic interface that clients can use to accept callbacks from every peer discovery service that our ecosystem offers. This callback interface should accept at the bare minimum:
Proposal
My proposal is to modify the current
Handshaker
to adhere to the following interface:Handshaker
implementations would typically accept some channel that anEnvelope
can be sent over and make sure that the result they yield in response to aconnect
can be convertible to anEnvelope
type. Similarly, when a client goes to use theHandshaker
in a peer discovery service, the metadata returned from that service must also be convertible to anEnvelope
.As an example, lets see how we would integrate a
BTHandshaker
, as well as one or more peer discovery services in with amio
event loop. A concreteBTHandshaker
would accept amio
channel that can sendEnvelope
types. TheBTHandshaker
impl would assert that the user has provided aFrom
implementation for creating anEnvelope
from aTcpStream
. The client then goes over to aTrackerClient
and tries to create one using ourBTHandshaker
as the genericHandshaker
. TheTrackerClient
impl would assert that the user has provided aFrom
implementation for creating anEnvelope
fromSomeMetadata
. Similarly, for every peer discovery service the client uses, this would be enforced for the service specific metadata.For services which receive no metadata, a generic
Handshaker
would be accepted and no constraint would be put on the containedEnvelope
.With this example, we can see how a
mio
event loop is now integrated with a number of peer discovery services and can accept both metadata as well as connections over a single channel.Positives
From
impls for the initialBTHandshaker
as well as the services it usesHandshaker
makes _little_ assumptions about the underlying transportHandshaker
Negatives
Handshaker
is manipulated in a peer discovery service's own thread, synchronous programming requires a bit more effortBTHandshaker
requires user's to wrap types such asmio
'sSender
The text was updated successfully, but these errors were encountered: