Struct State
pub struct State {
pub shared_heads: Vec<ChangeHash>,
pub last_sent_heads: Vec<ChangeHash>,
pub their_heads: Option<Vec<ChangeHash>>,
pub their_need: Option<Vec<ChangeHash>>,
pub their_have: Option<Vec<Have>>,
pub sent_hashes: BTreeSet<ChangeHash>,
pub in_flight: bool,
pub have_responded: bool,
pub their_capabilities: Option<Vec<Capability>>,
pub read_only: bool,
pub peer_read_only: bool,
pub needs_reset: bool,
}Expand description
The state of synchronisation with a peer.
This should be persisted using Self::encode() when you know you will be interacting with the
same peer in multiple sessions. Self::encode() only encodes state which should be reused
across connections.
Fields§
The hashes which we know both peers have
last_sent_heads: Vec<ChangeHash>The heads we last sent
their_heads: Option<Vec<ChangeHash>>The heads we last received from them
their_need: Option<Vec<ChangeHash>>Any specific changes they last said they needed
their_have: Option<Vec<Have>>The bloom filters summarising what they said they have
sent_hashes: BTreeSet<ChangeHash>The hashes we have sent in this session
in_flight: bool[SyncDoc::generate_sync_message()] should return None if there are no new changes
to send. In particular, if there are changes in flight which the other end has not yet
acknowledged we do not wish to generate duplicate sync messages. This field tracks whether
the changes we expect to send to the peer based on this sync state have been sent or not. If
Self::in_flight is false then [SyncDoc::generate_sync_message()] will return a new
message (provided there are in fact changes to send). If it is true then we don’t. This
flag is cleared in [SyncDoc::receive_sync_message()].
have_responded: boolWhether we have ever responded to the other end. This is used to ensure that we always send at least on sync message to the other end, even if we have no changes to send, which is necessary because we want the other end to know what our heads are.
their_capabilities: Option<Vec<Capability>>The persistent capabilities the other side has advertised (e.g. message
format support). Derived from super::MessageFlagss on incoming messages.
read_only: boolIf true, incoming changes from the peer will not be applied to the document. The peer will still receive our changes. This is useful for publish-only peers.
peer_read_only: boolWhether the remote peer is in read-only mode, as advertised by the
super::MessageFlags::READ_ONLY flag on their most recent message.
needs_reset: boolIf true, the next generated sync message will include a
super::MessageFlags::SYNC_RESET flag, signaling the remote peer to
clear its sent_hashes. Set by Self::set_read_only() when switching
from read-only to read-write.
Implementations§
§impl State
impl State
pub fn new() -> State
pub fn new_read_only() -> State
pub fn new_read_only() -> State
Create a new read-only sync state.
In read-only mode, incoming changes from the peer are not applied to the document, but our changes are still sent to the peer.
pub fn encode(&self) -> Vec<u8> ⓘ
pub fn decode(input: &[u8]) -> Result<State, DecodeError>
pub fn set_read_only(&mut self, read_only: bool)
pub fn set_read_only(&mut self, read_only: bool)
Set the read-only mode of this sync state.
When switching from read-only to read-write, the sync state is reset to trigger a fresh sync exchange with the remote peer. This ensures the remote peer resends any changes that were previously ignored.
When switching from read-write to read-only, only the flag is changed.
pub fn is_peer_read_only(&self) -> bool
pub fn is_peer_read_only(&self) -> bool
Returns true if the remote peer has advertised that it is in read-only mode. A read-only peer will not apply incoming changes, so there is no point sending them.
Trait Implementations§
impl Eq for State
impl StructuralPartialEq for State
Auto Trait Implementations§
impl Freeze for State
impl RefUnwindSafe for State
impl Send for State
impl Sync for State
impl Unpin for State
impl UnsafeUnpin for State
impl UnwindSafe for State
Blanket Implementations§
§impl<T> AnyEq for T
impl<T> AnyEq for T
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> 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 more