Struct mixnet::core::Mixnet

source ·
pub struct Mixnet<X> { /* private fields */ }
Expand description

Mixnet core state. X is the type of the extra data stored for each mixnode (Mixnode::extra).

Implementations§

source§

impl<X> Mixnet<X>

source

pub fn new(config: Config) -> Self

Create a new Mixnet.

source

pub fn session_status(&self) -> SessionStatus

Returns the current session index and phase.

source

pub fn set_session_status(&mut self, session_status: SessionStatus)

Sets the current session index and phase. The current and previous mixnodes may need to be provided after calling this; see maybe_set_mixnodes.

source

pub fn maybe_set_mixnodes( &mut self, rel_session_index: RelSessionIndex, mixnodes: &mut dyn FnMut() -> Result<Vec<Mixnode<X>>, MixnodesErr>, )

Sets the mixnodes for the specified session, if they are needed. If mixnodes() returns Err(MixnodesErr::Permanent), the session slot will be disabled, and later calls to maybe_set_mixnodes for the session will return immediately. If mixnodes() returns Err(MixnodesErr::Transient), the session slot will merely remain empty, and later calls to maybe_set_mixnodes may succeed.

The mixnode peer IDs are used for two things:

source

pub fn next_kx_public(&mut self) -> &KxPublic

Returns the key-exchange public key for the next session.

source

pub fn reserved_peers(&self) -> impl Iterator<Item = &Mixnode<X>>

Returns the mixnodes we should try to maintain connections to.

source

pub fn handle_packet(&mut self, packet: &Packet) -> Option<Message>

Handle an incoming packet. If the packet completes a message, the message is returned. Otherwise, None is returned.

source

pub fn next_forward_packet_deadline(&self) -> Option<Instant>

Returns the next instant at which pop_next_forward_packet should be called. None means never.

source

pub fn pop_next_forward_packet(&mut self) -> Option<AddressedPacket>

Pop and return the packet at the head of the forward packet queue. Returns None if the queue is empty.

source

pub fn next_authored_packet_delay(&self) -> Option<Duration>

Returns the delay after which pop_next_authored_packet should be called. None means an infinite delay.

source

pub fn pop_next_authored_packet( &mut self, ns: &dyn NetworkStatus, ) -> Option<AddressedPacket>

Either generate and return a cover packet or pop and return the packet at the head of one of the authored packet queues. May return None if cover packets are disabled, we fail to generate a cover packet, or there are no active sessions (though in the no active sessions case next_authored_packet_delay should return None and so this function should not really be called).

source

pub fn post_request( &mut self, session_index: SessionIndex, destination_index: &mut Option<MixnodeIndex>, message_id: &MessageId, data: Scattered<'_, u8>, num_surbs: usize, ns: &dyn NetworkStatus, ) -> Result<RequestMetrics, PostErr>

Post a request message. If destination_index is None, a destination mixnode is chosen at random and (on success) its index is written back to destination_index. The message is split into fragments and each fragment is sent over a different path to the destination.

source

pub fn post_reply( &mut self, surbs: &mut Vec<Surb>, session_index: SessionIndex, message_id: &MessageId, data: Scattered<'_, u8>, ) -> Result<(), PostErr>

Post a reply message using SURBs. The session index must match the session the SURBs were generated for. SURBs are removed from surbs on use.

source

pub fn take_events(&mut self) -> Events

Clear the event flags. Returns the flags that were cleared.

Auto Trait Implementations§

§

impl<X> Freeze for Mixnet<X>

§

impl<X> RefUnwindSafe for Mixnet<X>
where X: RefUnwindSafe,

§

impl<X> Send for Mixnet<X>
where X: Send,

§

impl<X> Sync for Mixnet<X>
where X: Sync,

§

impl<X> Unpin for Mixnet<X>
where X: Unpin,

§

impl<X> UnwindSafe for Mixnet<X>
where X: UnwindSafe,

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> 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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