pub struct Peer {
own_id: PeerID,
id: RwLock<Option<PeerID>>,
peer_pool: Weak<PeerPool>,
pub(crate) conn: Arc<Connection>,
stop_chan: (Sender<Result<()>>, Receiver<Result<()>>),
config: Arc<Config>,
task_group: TaskGroup,
}
Fields§
§own_id: PeerID
Own ID
id: RwLock<Option<PeerID>>
Peer’s ID
peer_pool: Weak<PeerPool>
A weak pointer to PeerPool
conn: Arc<Connection>
Holds the peer connection
stop_chan: (Sender<Result<()>>, Receiver<Result<()>>)
This channel is used to send a stop signal to the read loop.
config: Arc<Config>
The Configuration for the P2P network.
task_group: TaskGroup
Managing spawned tasks.
Implementations§
Source§impl Peer
impl Peer
Sourcepub(crate) fn new(
own_id: PeerID,
peer_pool: Weak<PeerPool>,
conn: Arc<Connection>,
config: Arc<Config>,
ex: Executor,
) -> Arc<Peer>
pub(crate) fn new( own_id: PeerID, peer_pool: Weak<PeerPool>, conn: Arc<Connection>, config: Arc<Config>, ex: Executor, ) -> Arc<Peer>
Creates a new peer
Sourcepub async fn send<T: Encode>(&self, proto_id: ProtocolID, msg: T) -> Result<()>
pub async fn send<T: Encode>(&self, proto_id: ProtocolID, msg: T) -> Result<()>
Send a msg to this peer connection using the specified protocol.
Sourcepub async fn recv<P: Protocol>(&self) -> Result<ProtocolEvent>
pub async fn recv<P: Protocol>(&self) -> Result<ProtocolEvent>
Receives a new msg from this peer connection.
Sourcepub async fn broadcast<T: Encode>(&self, proto_id: &ProtocolID, msg: &T)
pub async fn broadcast<T: Encode>(&self, proto_id: &ProtocolID, msg: &T)
Broadcast a message to all connected peers using the specified protocol.
Sourcepub fn remote_endpoint(&self) -> &Endpoint
pub fn remote_endpoint(&self) -> &Endpoint
Returns the remote endpoint for the peer
Sourcepub fn is_inbound(&self) -> bool
pub fn is_inbound(&self) -> bool
Check if the connection is Inbound
Sourcepub fn direction(&self) -> &ConnDirection
pub fn direction(&self) -> &ConnDirection
Returns the direction of the connection, which can be either Inbound
or Outbound
.
pub(crate) async fn init(self: &Arc<Self>) -> Result<()>
Sourceasync fn run_connect_protocols(self: &Arc<Self>)
async fn run_connect_protocols(self: &Arc<Self>)
Run running the Connect Protocols for this peer connection.
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§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more