Struct Router

Source
pub struct Router<N: Network>(/* private fields */);

Implementations§

Source§

impl<N: Network> Router<N>

Source

pub async fn handshake<'a>( &'a self, peer_addr: SocketAddr, stream: &'a mut TcpStream, peer_side: ConnectionSide, genesis_header: Header<N>, restrictions_id: Field<N>, ) -> Result<(SocketAddr, Framed<&'a mut TcpStream, MessageCodec<N>>)>

Executes the handshake protocol.

Source§

impl<N: Network> Router<N>

Source

pub async fn new( node_ip: SocketAddr, node_type: NodeType, account: Account<N>, trusted_peers: &[SocketAddr], max_peers: u16, rotate_external_peers: bool, allow_external_peers: bool, is_dev: bool, ) -> Result<Self>

Initializes a new Router instance.

Source§

impl<N: Network> Router<N>

Source

pub fn connect(&self, peer_ip: SocketAddr) -> Option<JoinHandle<bool>>

Attempts to connect to the given peer IP.

Source

pub fn disconnect(&self, peer_ip: SocketAddr) -> JoinHandle<bool>

Disconnects from the given peer IP, if the peer is connected.

Source

pub fn local_ip(&self) -> SocketAddr

Returns the IP address of this node.

Source

pub fn is_local_ip(&self, ip: &SocketAddr) -> bool

Returns true if the given IP is this node.

Source

pub fn is_valid_peer_ip(&self, ip: &SocketAddr) -> bool

Returns true if the given IP is not this node, is not a bogon address, and is not unspecified.

Source

pub fn node_type(&self) -> NodeType

Returns the node type.

Source

pub fn private_key(&self) -> &PrivateKey<N>

Returns the account private key of the node.

Source

pub fn view_key(&self) -> &ViewKey<N>

Returns the account view key of the node.

Source

pub fn address(&self) -> Address<N>

Returns the account address of the node.

Source

pub fn is_dev(&self) -> bool

Returns true if the node is in development mode.

Source

pub fn rotate_external_peers(&self) -> bool

Returns true if the node is periodically evicting more external peers.

Source

pub fn allow_external_peers(&self) -> bool

Returns true if the node is engaging in P2P gossip to request more peers.

Source

pub fn resolve_to_listener(&self, peer_addr: &SocketAddr) -> Option<SocketAddr>

Returns the listener IP address from the (ambiguous) peer address.

Source

pub fn resolve_to_ambiguous(&self, peer_ip: &SocketAddr) -> Option<SocketAddr>

Returns the (ambiguous) peer address from the listener IP address.

Source

pub fn is_connected(&self, ip: &SocketAddr) -> bool

Returns true if the node is connected to the given peer IP.

Source

pub fn is_connected_validator(&self, peer_ip: &SocketAddr) -> bool

Returns true if the given peer IP is a connected validator.

Source

pub fn is_connected_prover(&self, peer_ip: &SocketAddr) -> bool

Returns true if the given peer IP is a connected prover.

Source

pub fn is_connected_client(&self, peer_ip: &SocketAddr) -> bool

Returns true if the given peer IP is a connected client.

Source

pub fn is_connecting(&self, ip: &SocketAddr) -> bool

Returns true if the node is currently connecting to the given peer IP.

Source

pub fn is_restricted(&self, ip: &SocketAddr) -> bool

Returns true if the given IP is restricted.

Source

pub fn is_trusted(&self, ip: &SocketAddr) -> bool

Returns true if the given IP is trusted.

Source

pub fn max_connected_peers(&self) -> usize

Returns the maximum number of connected peers.

Source

pub fn number_of_connected_peers(&self) -> usize

Returns the number of connected peers.

Source

pub fn number_of_connected_validators(&self) -> usize

Returns the number of connected validators.

Source

pub fn number_of_connected_provers(&self) -> usize

Returns the number of connected provers.

Source

pub fn number_of_connected_clients(&self) -> usize

Returns the number of connected clients.

Source

pub fn number_of_candidate_peers(&self) -> usize

Returns the number of candidate peers.

Source

pub fn number_of_restricted_peers(&self) -> usize

Returns the number of restricted peers.

Source

pub fn get_connected_peer(&self, ip: &SocketAddr) -> Option<Peer<N>>

Returns the connected peer given the peer IP, if it exists.

Source

pub fn get_connected_peers(&self) -> Vec<Peer<N>>

Returns the connected peers.

Source

pub fn connected_peers(&self) -> Vec<SocketAddr>

Returns the list of connected peers.

Source

pub fn connected_validators(&self) -> Vec<SocketAddr>

Returns the list of connected validators.

Source

pub fn connected_provers(&self) -> Vec<SocketAddr>

Returns the list of connected provers.

Source

pub fn connected_clients(&self) -> Vec<SocketAddr>

Returns the list of connected clients.

Source

pub fn candidate_peers(&self) -> HashSet<SocketAddr>

Returns the list of candidate peers.

Source

pub fn restricted_peers(&self) -> Vec<SocketAddr>

Returns the list of restricted peers.

Source

pub fn trusted_peers(&self) -> &HashSet<SocketAddr>

Returns the list of trusted peers.

Source

pub fn bootstrap_peers(&self) -> Vec<SocketAddr>

Returns the list of bootstrap peers.

Source

pub fn connected_metrics(&self) -> Vec<(SocketAddr, NodeType)>

Returns the list of metrics for the connected peers.

Source

pub fn insert_connected_peer(&self, peer_ip: SocketAddr)

Inserts the given peer into the connected peers.

Source

pub fn insert_candidate_peers(&self, peers: &[SocketAddr])

Inserts the given peer IPs to the set of candidate peers.

This method skips adding any given peers if the combined size exceeds the threshold, as the peer providing this list could be subverting the protocol.

Source

pub fn insert_restricted_peer(&self, peer_ip: SocketAddr)

Inserts the given peer into the restricted peers.

Source

pub fn update_connected_peer<Fn: FnMut(&mut Peer<N>)>( &self, peer_ip: SocketAddr, node_type: NodeType, write_fn: Fn, ) -> Result<()>

Updates the connected peer with the given function.

Source

pub fn update_last_seen_for_connected_peer(&self, peer_ip: SocketAddr)

Source

pub fn remove_connected_peer(&self, peer_ip: SocketAddr)

Removes the connected peer and adds them to the candidate peers.

Source

pub fn remove_candidate_peer(&self, peer_ip: SocketAddr)

Removes the given address from the candidate peers, if it exists.

Source

pub fn spawn<T: Future<Output = ()> + Send + 'static>(&self, future: T)

Spawns a task with the given future; it should only be used for long-running tasks.

Source

pub async fn shut_down(&self)

Shuts down the router.

Trait Implementations§

Source§

impl<N: Clone + Network> Clone for Router<N>

Source§

fn clone(&self) -> Router<N>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<N: Network> Deref for Router<N>

Source§

type Target = Arc<InnerRouter<N>>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<N: Network> P2P for Router<N>

Source§

fn tcp(&self) -> &Tcp

Returns a reference to the TCP instance.

Auto Trait Implementations§

§

impl<N> Freeze for Router<N>

§

impl<N> !RefUnwindSafe for Router<N>

§

impl<N> Send for Router<N>

§

impl<N> Sync for Router<N>

§

impl<N> Unpin for Router<N>

§

impl<N> !UnwindSafe for Router<N>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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>,

Source§

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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T