pub struct Session<P: Protocol<SP::Verifier>, SP: SessionParameters> { /* private fields */ }
Expand description
An object encapsulating the currently active round, transport protocol, and the database of messages and errors from the previous rounds.
Implementations§
Source§impl<P, SP> Session<P, SP>
impl<P, SP> Session<P, SP>
Sourcepub fn new<EP>(
rng: &mut impl CryptoRngCore,
session_id: SessionId,
signer: SP::Signer,
entry_point: EP,
) -> Result<Self, LocalError>where
EP: EntryPoint<SP::Verifier, Protocol = P>,
pub fn new<EP>(
rng: &mut impl CryptoRngCore,
session_id: SessionId,
signer: SP::Signer,
entry_point: EP,
) -> Result<Self, LocalError>where
EP: EntryPoint<SP::Verifier, Protocol = P>,
Initializes a new session.
Sourcepub fn verifier(&self) -> SP::Verifier
pub fn verifier(&self) -> SP::Verifier
Returns the verifier corresponding to the session’s signer.
Sourcepub fn session_id(&self) -> &SessionId
pub fn session_id(&self) -> &SessionId
Returns the session ID.
Sourcepub fn message_destinations(&self) -> &BTreeSet<SP::Verifier>
pub fn message_destinations(&self) -> &BTreeSet<SP::Verifier>
Returns the set of message destinations for the current round.
Sourcepub fn make_message(
&self,
rng: &mut impl CryptoRngCore,
destination: &SP::Verifier,
) -> Result<(Message<SP::Verifier>, ProcessedArtifact<SP>), LocalError>
pub fn make_message( &self, rng: &mut impl CryptoRngCore, destination: &SP::Verifier, ) -> Result<(Message<SP::Verifier>, ProcessedArtifact<SP>), LocalError>
Creates the message to be sent to the given destination.
The destination must be one of those returned by message_destinations
.
Sourcepub fn add_artifact(
&self,
accum: &mut RoundAccumulator<P, SP>,
processed: ProcessedArtifact<SP>,
) -> Result<(), LocalError>
pub fn add_artifact( &self, accum: &mut RoundAccumulator<P, SP>, processed: ProcessedArtifact<SP>, ) -> Result<(), LocalError>
Adds the artifact from make_message
to the accumulator.
Sourcepub fn preprocess_message(
&self,
accum: &mut RoundAccumulator<P, SP>,
from: &SP::Verifier,
message: Message<SP::Verifier>,
) -> Result<PreprocessOutcome<SP::Verifier>, LocalError>
pub fn preprocess_message( &self, accum: &mut RoundAccumulator<P, SP>, from: &SP::Verifier, message: Message<SP::Verifier>, ) -> Result<PreprocessOutcome<SP::Verifier>, LocalError>
Performs some preliminary checks on the message to verify its integrity.
On the happy path, the return values are as follows:
- Ok(Some(…))
if the message passes all checks.
- Ok(None)
if the message passed all checks, but is not for this round. In this case
the preprocessed message is buffered in the “cached” message and applied in the next round.
On the unhappy path, the return values are:
- Ok(None)
when something goes wrong, either because there’s a problem at the
sending side or the message was received in the wrong context (e.g. wrong session, wrong
round etc). In most cases a RemoteError
is added to the RoundAccumulator
.
- Err
means an error while processing the data locally (likely bugs or
deserialization issues).
Sourcepub fn process_message(
&self,
message: VerifiedMessage<SP::Verifier>,
) -> ProcessedMessage<P, SP>
pub fn process_message( &self, message: VerifiedMessage<SP::Verifier>, ) -> ProcessedMessage<P, SP>
Processes a verified message.
This can be called in a spawned task if it is known to take a long time.
Sourcepub fn add_processed_message(
&self,
accum: &mut RoundAccumulator<P, SP>,
processed: ProcessedMessage<P, SP>,
) -> Result<(), LocalError>
pub fn add_processed_message( &self, accum: &mut RoundAccumulator<P, SP>, processed: ProcessedMessage<P, SP>, ) -> Result<(), LocalError>
Adds a result of process_message
to the accumulator.
Sourcepub fn make_accumulator(&self) -> RoundAccumulator<P, SP>
pub fn make_accumulator(&self) -> RoundAccumulator<P, SP>
Makes an accumulator for a new round.
Sourcepub fn terminate(
self,
accum: RoundAccumulator<P, SP>,
) -> Result<SessionReport<P, SP>, LocalError>
pub fn terminate( self, accum: RoundAccumulator<P, SP>, ) -> Result<SessionReport<P, SP>, LocalError>
Terminates the session, recording the reason as a user decision.
Sourcepub fn terminate_due_to_errors(
self,
accum: RoundAccumulator<P, SP>,
) -> Result<SessionReport<P, SP>, LocalError>
pub fn terminate_due_to_errors( self, accum: RoundAccumulator<P, SP>, ) -> Result<SessionReport<P, SP>, LocalError>
Terminates the session, recording the reason as the session being not possible to finalize due to the number of misbehaving nodes.
Will be usually called after receiving CanFinalize::Never
from
can_finalize
.
Sourcepub fn finalize_round(
self,
rng: &mut impl CryptoRngCore,
accum: RoundAccumulator<P, SP>,
) -> Result<RoundOutcome<P, SP>, LocalError>
pub fn finalize_round( self, rng: &mut impl CryptoRngCore, accum: RoundAccumulator<P, SP>, ) -> Result<RoundOutcome<P, SP>, LocalError>
Attempts to finalize the current round.
Sourcepub fn can_finalize(&self, accum: &RoundAccumulator<P, SP>) -> CanFinalize
pub fn can_finalize(&self, accum: &RoundAccumulator<P, SP>) -> CanFinalize
Checks if the round can be finalized.