Skip to main content

MessageCache

Struct MessageCache 

Source
pub struct MessageCache {
    full_cache: VecDeque<Box<[u8]>>,
    pub last_seen: LastSeen,
}
Expand description

Message signature cache for a player

Fields§

§full_cache: VecDeque<Box<[u8]>>

Max 128 cached message signatures. Most recent FIRST. Server should (when possible) reference indexes in this (recipient’s) cache instead of sending full signatures in last seen. Must be 1:1 with client’s signature cache.

§last_seen: LastSeen

Max 20 last seen messages by the sender. Most Recent LAST

Implementations§

Source§

impl MessageCache

Source

pub fn new() -> Self

Creates a new message cache

Source

pub fn unpack_acknowledged( &self, _offset: i32, acknowledged: [u8; 3], ) -> Option<LastSeen>

Reconstructs the LastSeen from a BitSet acknowledgment.

The offset indicates how many old messages to skip (not used for unpacking, but used by the validator), and the acknowledged BitSet indicates which of the last 20 messages were seen.

Returns None if the cache doesn’t contain the required messages.

Note: The offset is primarily used by the LastSeenMessagesValidator to advance the tracking window. For unpacking acknowledged messages, we just need to look at which bits are set in the acknowledged bitset and retrieve those signatures from the cache at the corresponding indices.

Source

pub fn cache_signatures(&mut self, signatures: &[Box<[u8]>])

Cache signatures from senders that the recipient hasn’t seen yet. Not used for caching seen messages. Only for non-indexed signatures from senders.

Source

pub fn add_seen_signature(&mut self, signature: &[u8])

Adds a seen signature to last_seen and full_cache.

Source

pub fn push( &mut self, last_seen_signatures: &LastSeen, current_signature: Option<&[u8; 256]>, )

Pushes signatures into the cache using vanilla’s algorithm. This should be called AFTER sending a chat packet to a recipient.

The signatures are pushed in order: all lastSeen signatures first, then the current message signature. This matches vanilla’s MessageSignatureCache.push(SignedMessageBody, MessageSignature) behavior.

§Panics

Panics if the deque is empty while attempting to pop (should never happen as we check !deque.is_empty()).

Source

pub fn index_previous_messages( &self, sender_last_seen: &LastSeen, ) -> Box<[PreviousMessageEntry]>

Convert the sender’s last_seen signatures to IDs if the recipient has them in their cache. Otherwise, the full signature is sent. (ID:0 indicates full signature is being sent)

Trait Implementations§

Source§

impl Debug for MessageCache

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for MessageCache

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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.

§

impl<T> Instrument for T

§

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

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

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

Source§

fn into_shared(self) -> Arc<Mutex<RawMutex, Self>>

Wraps this value in an Arc<SyncMutex<>>
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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