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: LastSeenMax 20 last seen messages by the sender. Most Recent LAST
Implementations§
Source§impl MessageCache
impl MessageCache
Sourcepub fn unpack_acknowledged(
&self,
_offset: i32,
acknowledged: [u8; 3],
) -> Option<LastSeen>
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.
Sourcepub fn cache_signatures(&mut self, signatures: &[Box<[u8]>])
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.
Sourcepub fn add_seen_signature(&mut self, signature: &[u8])
pub fn add_seen_signature(&mut self, signature: &[u8])
Adds a seen signature to last_seen and full_cache.
Sourcepub fn push(
&mut self,
last_seen_signatures: &LastSeen,
current_signature: Option<&[u8; 256]>,
)
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()).
Sourcepub fn index_previous_messages(
&self,
sender_last_seen: &LastSeen,
) -> Box<[PreviousMessageEntry]>
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
impl Debug for MessageCache
Auto Trait Implementations§
impl Freeze for MessageCache
impl RefUnwindSafe for MessageCache
impl Send for MessageCache
impl Sync for MessageCache
impl Unpin for MessageCache
impl UnsafeUnpin for MessageCache
impl UnwindSafe for MessageCache
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
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 moreArc<SyncMutex<>>