pub struct ConnectionNode { /* private fields */ }
Expand description
Wrapper class for a Node
that lets us create Connection
objects instead of creating raw
streams on the node itself.
Implementations§
Source§impl ConnectionNode
impl ConnectionNode
Sourcepub fn new(
node_id: &str,
protocol: &str,
new_peer_sender: Sender<String>,
) -> Result<(ConnectionNode, impl Stream<Item = Connection> + Send)>
pub fn new( node_id: &str, protocol: &str, new_peer_sender: Sender<String>, ) -> Result<(ConnectionNode, impl Stream<Item = Connection> + Send)>
Create a new ConnectionNode
. We can create a Connection
object for any peer via this
node, and we can then create streams to that peer and have that peer create streams to us.
Unlike with a raw Node
, those streams will be associated with only our connection object,
and the peer will get a connection object that will return to it only the streams we create
from this connection object.
Returns both a ConnectionNode
, and a futures::stream::Stream
of Connection
objects,
which are produced by other nodes connecting to us.
Sourcepub fn new_with_router(
node_id: &str,
protocol: &str,
interval: Duration,
new_peer_sender: Sender<String>,
) -> Result<(ConnectionNode, impl Stream<Item = Connection> + Send)>
pub fn new_with_router( node_id: &str, protocol: &str, interval: Duration, new_peer_sender: Sender<String>, ) -> Result<(ConnectionNode, impl Stream<Item = Connection> + Send)>
Like ConnectionNode::new
but creates a router task as well. See Node::new_with_router
.
Sourcepub async fn connect_to_peer(
&self,
node_id: &str,
connection_reader: Reader,
connection_writer: Writer,
) -> Result<Connection>
pub async fn connect_to_peer( &self, node_id: &str, connection_reader: Reader, connection_writer: Writer, ) -> Result<Connection>
Establish a connection to a peer. The connection_reader
and connection_writer
will be
used to service stream ID 0, which is always created when we start a connection.