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>
impl<X> Mixnet<X>
sourcepub fn session_status(&self) -> SessionStatus
pub fn session_status(&self) -> SessionStatus
Returns the current session index and phase.
sourcepub fn set_session_status(&mut self, session_status: SessionStatus)
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
.
sourcepub fn maybe_set_mixnodes(
&mut self,
rel_session_index: RelSessionIndex,
mixnodes: &mut dyn FnMut() -> Result<Vec<Mixnode<X>>, MixnodesErr>,
)
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:
- Checking for connectivity (they are passed to
NetworkStatus::is_connected
). - Sending packets (they are put in
AddressedPacket::peer_id
).
sourcepub fn next_kx_public(&mut self) -> &KxPublic
pub fn next_kx_public(&mut self) -> &KxPublic
Returns the key-exchange public key for the next session.
sourcepub fn reserved_peers(&self) -> impl Iterator<Item = &Mixnode<X>>
pub fn reserved_peers(&self) -> impl Iterator<Item = &Mixnode<X>>
Returns the mixnodes we should try to maintain connections to.
sourcepub fn handle_packet(&mut self, packet: &Packet) -> Option<Message>
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.
sourcepub fn next_forward_packet_deadline(&self) -> Option<Instant>
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.
sourcepub fn pop_next_forward_packet(&mut self) -> Option<AddressedPacket>
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.
Returns the delay after which pop_next_authored_packet
should be called. None
means an infinite delay.
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).
sourcepub 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>
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.
sourcepub fn post_reply(
&mut self,
surbs: &mut Vec<Surb>,
session_index: SessionIndex,
message_id: &MessageId,
data: Scattered<'_, u8>,
) -> Result<(), PostErr>
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.
sourcepub fn take_events(&mut self) -> Events
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> 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
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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