BundleSocket

Struct BundleSocket 

Source
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

Source

pub fn new(addr: SocketAddrV4) -> Result<Self>

Create a new socket bound to the given address.

Source

pub fn addr(&self) -> SocketAddrV4

Get the bind address of this socket.

Source

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.

Source

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.

Source

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().

Source

pub fn send_auto_ack(&mut self)

Send all auto packet acknowledgments.

Source

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

Source§

fn clone(&self) -> BundleSocket

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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