pub struct BundleSocket { /* private fields */ }Expand description
A socket providing interface for sending and receiving bundles of elements, backed by an UDP server with support for blowfish channel encryption. This socket is blocking on sends and receives.
It also provides fragmentation support when sending bundles that contains more than one packet, channel blowfish encryption and packet acknowledgment.
This socket handle is actually just a shared pointer to shared data, it can be cloned as needed and used in multiple threads at the same time.
Implementations§
Source§impl BundleSocket
impl BundleSocket
Sourcepub fn new(addr: SocketAddrV4) -> Result<Self>
pub fn new(addr: SocketAddrV4) -> Result<Self>
Create a new socket bound to the given address.
Sourcepub fn addr(&self) -> SocketAddrV4
pub fn addr(&self) -> SocketAddrV4
Get the bind address of this socket.
Sourcepub fn set_channel(&mut self, addr: SocketAddr, blowfish: Arc<Blowfish>)
pub fn set_channel(&mut self, addr: SocketAddr, blowfish: Arc<Blowfish>)
Associate a new channel to the given address with the given blowfish encryption. This blowfish encryption will be used for all transaction to come with this given socket address.
Sourcepub fn send(&mut self, bundle: &mut Bundle, to: SocketAddr) -> Result<usize>
pub fn send(&mut self, bundle: &mut Bundle, to: SocketAddr) -> Result<usize>
Send a bundle to a given address. Note that the bundle is finalized by this method with the internal sequence id.
Note that the net data is guaranteed to be untouched by this function, this includes prefix, flags up to the footer. Bytes beyond this limit might be modified in case of channel encryption.
Sourcepub fn recv(&mut self) -> Result<Option<Bundle>>
pub fn recv(&mut self) -> Result<Option<Bundle>>
Blocking receive of a packet, if a bundle can be constructed it is returned, if
not, none is returned instead. If the packet is rejected for any reason listed
in PacketRejectionError, none is also returned but the packet is internally
queued and can later be retrieve with the error using
Self::take_rejected_packets().
Sourcepub fn send_auto_ack(&mut self)
pub fn send_auto_ack(&mut self)
Send all auto packet acknowledgments.
Sourcepub fn take_rejected_packets(
&mut self,
) -> Vec<(SocketAddr, Box<Packet>, PacketRejectionError)>
pub fn take_rejected_packets( &mut self, ) -> Vec<(SocketAddr, Box<Packet>, PacketRejectionError)>
Take the vector of all rejected packets and the rejection reason.
Trait Implementations§
Source§impl Clone for BundleSocket
impl Clone for BundleSocket
Source§fn clone(&self) -> BundleSocket
fn clone(&self) -> BundleSocket
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more