[][src]Struct pea2pea::Node

pub struct Node {
    pub config: NodeConfig,
    pub listening_addr: SocketAddr,
    pub known_peers: KnownPeers,
    // some fields omitted
}

The central object responsible for handling all the connections.

Fields

config: NodeConfig

The node's configuration.

listening_addr: SocketAddr

The node's listening address.

known_peers: KnownPeers

Collects statistics related to the node's connections.

Implementations

impl Node[src]

pub async fn new(config: Option<NodeConfig>) -> Result<Arc<Self>>[src]

Returns a Node wrapped in an Arc.

pub async fn new_multiple(
    count: usize,
    config: Option<NodeConfig>
) -> Result<Vec<Arc<Self>>>
[src]

Returns a vector of Nodes wrapped in Arcs.

pub fn name(&self) -> &str[src]

Returns the name assigned to the node.

pub fn span(&self) -> Span[src]

Returns the tracing Span associated with the node.

pub async fn initiate_connection(
    self: &Arc<Self>,
    addr: SocketAddr
) -> Result<()>
[src]

Connects to the provided SocketAddr.

pub fn disconnect(&self, addr: SocketAddr) -> bool[src]

Disconnects from the provided SocketAddr.

pub async fn send_direct_message(
    &self,
    addr: SocketAddr,
    message: Bytes
) -> Result<()>
[src]

Sends the provided message to the specified, handshaken SocketAddr.

pub async fn send_broadcast(&self, message: Bytes)[src]

Broadcasts the provided message to all handshaken peers.

pub fn handshaken_addrs(&self) -> Vec<SocketAddr>[src]

Returns a list containing addresses of handshaken connections.

pub fn register_sent_message(&self, from: SocketAddr, len: usize)[src]

Updates the peer's statistics upon successful submission of a message.

pub fn register_received_message(&self, from: SocketAddr, len: usize)[src]

Updates the peer's statistics upon successful receipt of a message.

pub fn register_failure(&self, from: SocketAddr)[src]

Updates the peer's statistics upon a failure.

pub fn is_connected(&self, addr: SocketAddr) -> bool[src]

Checks whether the provided address is connected, regardless of its handshake status.

pub fn num_connected(&self) -> usize[src]

Returns the number of active connections, regardless of their handshake status.

pub fn is_handshaking(&self, addr: SocketAddr) -> bool[src]

Checks whether a connection with the given address is currently in the process of handshaking.

pub fn is_handshaken(&self, addr: SocketAddr) -> bool[src]

Checks whether a connection with the given address has been handshaken.

pub fn num_messages_sent(&self) -> usize[src]

Returns the number of all sent messages.

pub fn num_messages_received(&self) -> usize[src]

Returns the number of all received messages.

pub fn update_last_seen(&self, addr: SocketAddr)[src]

Updates the "last seen" timestamp of a connection with the given address.

pub fn mark_as_handshaken(&self, addr: SocketAddr) -> Result<()>[src]

Changes a connection's status from handshaking to handshaken.

pub fn inbound_messages(&self) -> Option<&Sender<(SocketAddr, InboundMessage)>>[src]

Returns a Sender for the channel handling all the incoming messages, if Messaging is enabled.

pub fn set_inbound_messages(&self, sender: Sender<(SocketAddr, InboundMessage)>)[src]

Sets up the Sender for handling all incoming messages, as part of the Messaging protocol.

pub fn set_reading_closure(&self, closure: ReadingClosure)[src]

Sets up the closure responsible for spawning per-connection tasks for handling inbound messages, as part of the Messaging protocol.

pub fn set_handshake_setup(&self, closures: HandshakeSetup)[src]

Sets up the handshake-relevant objects, as part of the Handshaking protocol.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.