Struct aether_lib::link::Link
source · [−]Expand description
Represents a single reliable Link
to another peer
Fields
private_id: Id
Identity of the user that created this identity
peer_id: PublicId
Public Identity of the other peer
Implementations
sourceimpl Link
impl Link
sourcepub fn new(
id: Id,
socket: UdpSocket,
peer_addr: SocketAddr,
peer_id: PublicId,
send_seq: u32,
recv_seq: u32,
config: Config
) -> Result<Link, AetherError>
pub fn new(
id: Id,
socket: UdpSocket,
peer_addr: SocketAddr,
peer_id: PublicId,
send_seq: u32,
recv_seq: u32,
config: Config
) -> Result<Link, AetherError>
Creates a new Link
to another peer
Arguments
id
-Id
of the user that is creating this linksocket
- UDP socket used to communicate with the other peerpeer_addr
- Address of the other peerpeer_id
- Public Id of the other peersend_seq
- Sending Sequence number that the Link needs to be initialised withrecv_seq
- Receiving Sequence number that the Link needs to be initialised withconfig
- Configuration for Aether
pub fn enable_encryption(&mut self) -> Result<(), AetherError>
pub fn is_encrypted(&self) -> bool
sourcepub fn get_addr(&self) -> SocketAddr
pub fn get_addr(&self) -> SocketAddr
Get the SocketAddr
of the peer
sourcepub fn send_packet(&self, packet: Packet) -> Result<(), AetherError>
pub fn send_packet(&self, packet: Packet) -> Result<(), AetherError>
sourcepub fn set_read_timout(&mut self, timeout: Duration)
pub fn set_read_timout(&mut self, timeout: Duration)
sourcepub fn recv_timeout(&self, timeout: Duration) -> Result<Vec<u8>, AetherError>
pub fn recv_timeout(&self, timeout: Duration) -> Result<Vec<u8>, AetherError>
Receive bytes from the other peer or return an error if the timeout is reached
Arguments
timeout
- Timeout to wait for receiving packets
Returns
Vec<u8>
- Buffer containing the received bytes
Errors
AetherError::RecvTimeout
- Timeout reached before receiving any bytesAetherError::LinkStopped
-Link
stopped before receiving any bytes
Other general errors might occur (refer to AetherError
)
sourcepub fn recv(&self) -> Result<Vec<u8>, AetherError>
pub fn recv(&self) -> Result<Vec<u8>, AetherError>
Receive bytes from the other peer
Returns
Vec<u8>
- Buffer containing the received bytes
Errors
AetherError::LinkStopped
-Link
stopped before receiving any bytesAetherError::LinkTimeout
-Link
timed out before receiving any bytes
Other general errors might occur (refer to AetherError
)
sourcepub fn get_receiver(&self) -> Result<Receiver<Packet>, AetherError>
pub fn get_receiver(&self) -> Result<Receiver<Packet>, AetherError>
Returns a [Receiver
] to receive packets from the output queue
sourcepub fn is_empty(&self) -> Result<bool, AetherError>
pub fn is_empty(&self) -> Result<bool, AetherError>
Returns true if no more packets needs to be sent Checks if both primary queue and batch queue are empty
sourcepub fn wait_empty(&self) -> Result<(), AetherError>
pub fn wait_empty(&self) -> Result<(), AetherError>
Waits and blocks the current thread until the Link
is empty
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Link
impl Send for Link
impl Sync for Link
impl Unpin for Link
impl !UnwindSafe for Link
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more