Trait mls_rs::GroupStateStorage
source · pub trait GroupStateStorage: Send + Sync {
type Error: IntoAnyError;
// Required methods
fn state(&self, group_id: &[u8]) -> Result<Option<Vec<u8>>, Self::Error>;
fn epoch(
&self,
group_id: &[u8],
epoch_id: u64,
) -> Result<Option<Vec<u8>>, Self::Error>;
fn write(
&mut self,
state: GroupState,
epoch_inserts: Vec<EpochRecord>,
epoch_updates: Vec<EpochRecord>,
) -> Result<(), Self::Error>;
fn max_epoch_id(&self, group_id: &[u8]) -> Result<Option<u64>, Self::Error>;
}
Expand description
Storage that can persist and reload a group state.
A group state is recorded as a combination of the current state
(represented by the GroupState
trait) and some number of prior
group states (represented by the EpochRecord
trait).
This trait implements reading and writing group data as requested by the protocol
implementation.
§Cleaning up records
Group state will not be purged when the local member is removed from the group. It is up to the implementer of this trait to provide a mechanism to delete records that can be used by an application.
Required Associated Types§
type Error: IntoAnyError
Required Methods§
sourcefn state(&self, group_id: &[u8]) -> Result<Option<Vec<u8>>, Self::Error>
fn state(&self, group_id: &[u8]) -> Result<Option<Vec<u8>>, Self::Error>
Fetch a group state from storage.
sourcefn epoch(
&self,
group_id: &[u8],
epoch_id: u64,
) -> Result<Option<Vec<u8>>, Self::Error>
fn epoch( &self, group_id: &[u8], epoch_id: u64, ) -> Result<Option<Vec<u8>>, Self::Error>
Lazy load cached epoch data from a particular group.
sourcefn write(
&mut self,
state: GroupState,
epoch_inserts: Vec<EpochRecord>,
epoch_updates: Vec<EpochRecord>,
) -> Result<(), Self::Error>
fn write( &mut self, state: GroupState, epoch_inserts: Vec<EpochRecord>, epoch_updates: Vec<EpochRecord>, ) -> Result<(), Self::Error>
Write pending state updates.
The group id that this update belongs to can be retrieved with
GroupState::id
. Prior epoch id values can be retrieved with
EpochRecord::id
.
The protocol implementation handles managing the max size of a prior epoch
cache and the deleting of prior states based on group activity.
The maximum number of prior epochs that will be stored is controlled by the
Preferences::max_epoch_retention
function in mls_rs
.
value. Requested deletes are communicated by the delete_epoch_under
parameter being set to Some
.
§Warning
It is important to consider error recovery when creating an implementation
of this trait. Calls to write
should
optimally be a single atomic transaction in order to avoid partial writes
that may corrupt the group state.
sourcefn max_epoch_id(&self, group_id: &[u8]) -> Result<Option<u64>, Self::Error>
fn max_epoch_id(&self, group_id: &[u8]) -> Result<Option<u64>, Self::Error>
The EpochRecord::id
value that is associated with a stored
prior epoch for a particular group.