Struct Session

Source
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>
where P: Protocol<SP::Verifier>, SP: SessionParameters,

Source

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.

Source

pub fn verifier(&self) -> SP::Verifier

Returns the verifier corresponding to the session’s signer.

Source

pub fn session_id(&self) -> &SessionId

Returns the session ID.

Source

pub fn message_destinations(&self) -> &BTreeSet<SP::Verifier>

Returns the set of message destinations for the current round.

Source

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.

Source

pub fn add_artifact( &self, accum: &mut RoundAccumulator<P, SP>, processed: ProcessedArtifact<SP>, ) -> Result<(), LocalError>

Adds the artifact from make_message to the accumulator.

Source

pub fn round_id(&self) -> RoundId

Returns the ID of the current round.

Source

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

Source

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.

Source

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.

Source

pub fn make_accumulator(&self) -> RoundAccumulator<P, SP>

Makes an accumulator for a new round.

Source

pub fn terminate( self, accum: RoundAccumulator<P, SP>, ) -> Result<SessionReport<P, SP>, LocalError>

Terminates the session, recording the reason as a user decision.

Source

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.

Source

pub fn finalize_round( self, rng: &mut impl CryptoRngCore, accum: RoundAccumulator<P, SP>, ) -> Result<RoundOutcome<P, SP>, LocalError>

Attempts to finalize the current round.

Source

pub fn can_finalize(&self, accum: &RoundAccumulator<P, SP>) -> CanFinalize

Checks if the round can be finalized.

Trait Implementations§

Source§

impl<P: Debug + Protocol<SP::Verifier>, SP: Debug + SessionParameters> Debug for Session<P, SP>
where SP::Signer: Debug, SP::Verifier: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<P, SP> Freeze for Session<P, SP>

§

impl<P, SP> !RefUnwindSafe for Session<P, SP>

§

impl<P, SP> Send for Session<P, SP>

§

impl<P, SP> Sync for Session<P, SP>

§

impl<P, SP> Unpin for Session<P, SP>

§

impl<P, SP> !UnwindSafe for Session<P, SP>

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Behavior for T
where T: 'static + Debug + Send + Sync,