Struct circuit::Node

source ·
pub struct Node { /* private fields */ }
Expand description

Represents a node on the circuit network.

A node can connect to one or more other nodes, and a stream can be established between any two nodes on the entire connected graph of nodes.

Implementations§

source§

impl Node

source

pub fn new( node_id: &str, protocol: &str, new_peer_sender: Sender<String>, incoming_stream_sender: Sender<(Reader, Writer, String)> ) -> Result<Node>

Establish a new node.

Any time a new peer becomes visible to this node, the peer’s node ID will be sent to new_peer_sender.

Any time a peer wants to establish a stream with this node, a reader and writer for the new stream as well as the peer’s node ID will be sent to incoming_stream_sender.

source

pub fn new_with_router( node_id: &str, protocol: &str, interval: Duration, new_peer_sender: Sender<String>, incoming_stream_sender: Sender<(Reader, Writer, String)> ) -> Result<(Node, impl Future<Output = ()> + Send)>

Establish a new node which will forward streams between its peers. The router process provided must be polled continuously to provide this forwarding.

source

pub async fn connect_to_peer( &self, connection_reader: Reader, connection_writer: Writer, node_id: &str ) -> Result<()>

Establish a stream with another node. Data will be sent to the peer with connection_writer, and received with connection_reader.

Connect to another node.

This establishes the internal state to link this node directly to another one, there by joining it to the circuit network. To actually perform the networking necessary to create such a link, a back end will have to service the streams given to this function via its arguments. To keep the link running, the returned future must also be polled to completion. Depending on configuration, it may complete swiftly or may poll for the entire lifetime of the link.

When we link to another node, we immediately start a “control stream” that performs a handshake and sends routing messages. The reader and writer passed in through control_stream will be used to service this stream. If control_stream is None the first stream emitted from new_stream_receiver will be used.

When the local node needs to create a new stream to the linked node, it will send a reader and writer to new_stream_sender.

When the linked node wants to create a new stream to this node, the back end may send a reader and writer through new_stream_receiver, as well as a oneshot::Sender which will be used to report if the link is established successfully or if an error occurs.

The returned future will continue to poll for the lifetime of the link and return the error that terminated it.

source

pub fn node_id(&self) -> &str

Get the node ID of this node.

Auto Trait Implementations§

§

impl Freeze for Node

§

impl !RefUnwindSafe for Node

§

impl Send for Node

§

impl Sync for Node

§

impl Unpin for Node

§

impl !UnwindSafe for Node

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more