Skip to content

Commit

Permalink
Add ProtocolsHandler trait (#573)
Browse files Browse the repository at this point in the history
* Add ProtocolsHandler trait

* Reexport symbols

* Add a note about shutting down

* Add map_protocol

* Add a NodeHandlerWrapperBuilder

* Update core/src/nodes/protocols_handler.rs

Co-Authored-By: tomaka <[email protected]>

* Fix compilation
  • Loading branch information
tomaka authored Nov 1, 2018
1 parent 4627f21 commit c730b4b
Show file tree
Hide file tree
Showing 5 changed files with 697 additions and 2 deletions.
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ rw-stream-sink = { path = "../misc/rw-stream-sink" }
smallvec = "0.6"
tokio-executor = "0.1.4"
tokio-io = "0.1"
tokio-timer = "0.2"
void = "1"

[dev-dependencies]
Expand Down
3 changes: 1 addition & 2 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ extern crate rw_stream_sink;
extern crate smallvec;
extern crate tokio_executor;
extern crate tokio_io;
extern crate tokio_timer;
extern crate void;

#[cfg(test)]
Expand All @@ -193,8 +194,6 @@ extern crate tokio;
#[cfg(test)]
extern crate tokio_codec;
#[cfg(test)]
extern crate tokio_timer;
#[cfg(test)]
#[macro_use]
extern crate assert_matches;
#[cfg(test)]
Expand Down
11 changes: 11 additions & 0 deletions core/src/nodes/handled_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ pub trait NodeHandler {
/// Sends a new substream to the handler.
///
/// The handler is responsible for upgrading the substream to whatever protocol it wants.
///
/// # Panic
///
/// Implementations are allowed to panic in the case of dialing if the `user_data` in
/// `endpoint` doesn't correspond to what was returned earlier when polling, or is used
/// multiple times.
fn inject_substream(&mut self, substream: Self::Substream, endpoint: NodeHandlerEndpoint<Self::OutboundOpenInfo>);

/// Indicates to the handler that the inbound part of the muxer has been closed, and that
Expand All @@ -49,6 +55,11 @@ pub trait NodeHandler {

/// Indicates to the handler that an outbound substream failed to open because the outbound
/// part of the muxer has been closed.
///
/// # Panic
///
/// Implementations are allowed to panic if `user_data` doesn't correspond to what was returned
/// earlier when polling, or is used multiple times.
fn inject_outbound_closed(&mut self, user_data: Self::OutboundOpenInfo);

/// Injects an event coming from the outside into the handler.
Expand Down
2 changes: 2 additions & 0 deletions core/src/nodes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ pub mod handled_node;
pub mod handled_node_tasks;
pub mod listeners;
pub mod node;
pub mod protocols_handler;
pub mod raw_swarm;

pub use self::node::Substream;
pub use self::handled_node::{NodeHandlerEvent, NodeHandlerEndpoint};
pub use self::protocols_handler::{ProtocolsHandler, ProtocolsHandlerEvent};
pub use self::raw_swarm::{ConnectedPoint, Peer, RawSwarm, RawSwarmEvent};
Loading

0 comments on commit c730b4b

Please sign in to comment.