pub struct Peer {
id: Id,
tx: Option<Sender<Message>>,
terminated: Arc<AtomicBool>,
read_thread: Option<JoinHandle<()>>,
write_thread: Option<JoinHandle<()>>,
}
Expand description
Peer connection
Fields§
§id: Id
§tx: Option<Sender<Message>>
§terminated: Arc<AtomicBool>
§read_thread: Option<JoinHandle<()>>
§write_thread: Option<JoinHandle<()>>
Implementations§
source§impl Peer
impl Peer
sourcepub fn listen(listener: &TcpListener, server_tx: &Sender<Event>)
pub fn listen(listener: &TcpListener, server_tx: &Sender<Event>)
Blocking incoming peer connection accept loop
sourcepub fn connect(
config: &Arc<Config>,
peer: &Peer,
server_tx: &Sender<Event>,
) -> Result<JoinSuccess, HandshakeError>
pub fn connect( config: &Arc<Config>, peer: &Peer, server_tx: &Sender<Event>, ) -> Result<JoinSuccess, HandshakeError>
Initiate peer connection
sourcepub fn new(
stream: TcpStream,
id: Id,
server_tx: Sender<Event>,
heartbeat_timeout: Duration,
) -> Self
pub fn new( stream: TcpStream, id: Id, server_tx: Sender<Event>, heartbeat_timeout: Duration, ) -> Self
Start peer IO threads
pub fn start_handshake( stream: TcpStream, config: &Arc<Config>, expected_id: Id, server_tx: Sender<Event>, ) -> Result<JoinSuccess, HandshakeError>
pub fn send_message(&self, message: Message)
fn read_thread_fn( stream: &mut TcpStream, peer_id: Id, server_tx: &Sender<Event>, terminated: &Arc<AtomicBool>, )
fn write_thread_fn( stream: &mut TcpStream, peer_id: Id, rx: &Receiver<Message>, timeout: Duration, )
Trait Implementations§
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> 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