Peer

Struct Peer 

Source
pub struct Peer {
    pub address: SocketAddr,
    pub is_client: bool,
    /* private fields */
}
Expand description

A struct representing one peer (peer connection. Can be both a client peer or a connected peer)

Fields§

§address: SocketAddr§is_client: bool

Implementations§

Source§

impl Peer

Source

pub fn new(address: SocketAddr, is_client: bool) -> Self

Create a new peer

Source

pub async fn connect( peer: Arc<RwLock<Peer>>, node: Arc<RwLock<Node>>, stream: TcpStream, ) -> JoinHandle<Result<(), PeerError>>

Main connection handler

Source

pub async fn request( peer: Arc<RwLock<Peer>>, message: Message, ) -> Result<Message, PeerError>

Send a request and wait for the response

Source

pub async fn send(peer: Arc<RwLock<Peer>>, message: Message)

Send a message to this peer, without expecting a response

Source

pub async fn send_to_peers(node: Arc<RwLock<Node>>, message: Message)

Send this message to all peers but this one

Auto Trait Implementations§

§

impl Freeze for Peer

§

impl !RefUnwindSafe for Peer

§

impl Send for Peer

§

impl Sync for Peer

§

impl Unpin for Peer

§

impl !UnwindSafe for Peer

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.

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> Same for T

Source§

type Output = T

Should always be Self
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