Skip to main content

NodeDelegate

Trait NodeDelegate 

Source
pub trait NodeDelegate:
    Send
    + Sync
    + 'static {
    // Provided methods
    fn node_meta(&self, limit: usize) -> impl Future<Output = Meta> + Send { ... }
    fn notify_message(
        &self,
        msg: Cow<'_, [u8]>,
    ) -> impl Future<Output = ()> + Send { ... }
    fn broadcast_messages<F>(
        &self,
        limit: usize,
        encoded_len: F,
    ) -> impl Future<Output = impl Iterator<Item = Bytes> + Send> + Send
       where F: Fn(Bytes) -> (usize, Bytes) + Send + Sync + 'static { ... }
    fn local_state(&self, join: bool) -> impl Future<Output = Bytes> + Send { ... }
    fn merge_remote_state(
        &self,
        buf: &[u8],
        join: bool,
    ) -> impl Future<Output = ()> + Send { ... }
}
Expand description

Used to manage node related events.

Provided Methods§

Source

fn node_meta(&self, limit: usize) -> impl Future<Output = Meta> + Send

Used to retrieve meta-data about the current node when broadcasting an alive message. It’s length is limited to the given byte size. This metadata is available in the NodeState structure.

Source

fn notify_message(&self, msg: Cow<'_, [u8]>) -> impl Future<Output = ()> + Send

Called when a user-data message is received. Care should be taken that this method does not block, since doing so would block the entire UDP packet receive loop. Additionally, the byte slice may be modified after the call returns, so it should be copied if needed

Source

fn broadcast_messages<F>( &self, limit: usize, encoded_len: F, ) -> impl Future<Output = impl Iterator<Item = Bytes> + Send> + Send
where F: Fn(Bytes) -> (usize, Bytes) + Send + Sync + 'static,

Called when user data messages can be broadcast. It can return a list of buffers to send. Each buffer should assume an overhead as provided with a limit on the total byte size allowed. The total byte size of the resulting data to send must not exceed the limit. Care should be taken that this method does not block, since doing so would block the entire UDP packet receive loop.

The encoded_len function accepts a bytes, and will return the same bytes back and the encoded length of the message.

Source

fn local_state(&self, join: bool) -> impl Future<Output = Bytes> + Send

Used for a TCP Push/Pull. This is sent to the remote side in addition to the membership information. Any data can be sent here. See merge_remote_state as well. The join boolean indicates this is for a join instead of a push/pull.

Source

fn merge_remote_state( &self, buf: &[u8], join: bool, ) -> impl Future<Output = ()> + Send

Invoked after a TCP Push/Pull. This is the state received from the remote side and is the result of the remote side’s local_state call. The ‘join’ boolean indicates this is for a join instead of a push/pull.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T: NodeDelegate + ?Sized> NodeDelegate for Arc<T>
where Arc<T>: Send + Sync + 'static,

Source§

fn node_meta(&self, limit: usize) -> impl Future<Output = Meta> + Send

Source§

fn notify_message(&self, msg: Cow<'_, [u8]>) -> impl Future<Output = ()> + Send

Source§

fn broadcast_messages<F>( &self, limit: usize, encoded_len: F, ) -> impl Future<Output = impl Iterator<Item = Bytes> + Send> + Send
where F: Fn(Bytes) -> (usize, Bytes) + Send + Sync + 'static,

Source§

fn local_state(&self, join: bool) -> impl Future<Output = Bytes> + Send

Source§

fn merge_remote_state( &self, buf: &[u8], join: bool, ) -> impl Future<Output = ()> + Send

Source§

impl<T: NodeDelegate + ?Sized> NodeDelegate for Box<T>
where Box<T>: Send + Sync + 'static,

Source§

fn node_meta(&self, limit: usize) -> impl Future<Output = Meta> + Send

Source§

fn notify_message(&self, msg: Cow<'_, [u8]>) -> impl Future<Output = ()> + Send

Source§

fn broadcast_messages<F>( &self, limit: usize, encoded_len: F, ) -> impl Future<Output = impl Iterator<Item = Bytes> + Send> + Send
where F: Fn(Bytes) -> (usize, Bytes) + Send + Sync + 'static,

Source§

fn local_state(&self, join: bool) -> impl Future<Output = Bytes> + Send

Source§

fn merge_remote_state( &self, buf: &[u8], join: bool, ) -> impl Future<Output = ()> + Send

Implementors§

Source§

impl<I, A> NodeDelegate for VoidDelegate<I, A>
where I: Id + Send + Sync + 'static, A: CheapClone + Send + Sync + 'static,

Source§

impl<I, Address, A, C, E, M, N, P> NodeDelegate for CompositeDelegate<I, Address, A, C, E, M, N, P>
where I: Id + Send + Sync + 'static, Address: CheapClone + Send + Sync + 'static, A: AliveDelegate<Id = I, Address = Address>, C: ConflictDelegate<Id = I, Address = Address>, E: EventDelegate<Id = I, Address = Address>, M: MergeDelegate<Id = I, Address = Address>, N: NodeDelegate, P: PingDelegate<Id = I, Address = Address>,