Trait DhtHandler

Source
pub trait DhtHandler:
    Send
    + Sync
    + Sized {
    type Value: Clone;
    type Node: DhtNode;

    // Required methods
    fn dht(&self) -> Arc<Dht<Self>>;
    fn node<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Self::Node> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn ping<'life0, 'async_trait>(
        &'life0 self,
        channel: ChannelPtr,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Node>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn on_new_node<'life0, 'life1, 'async_trait>(
        &'life0 self,
        node: &'life1 Self::Node,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn find_nodes<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        node: &'life1 Self::Node,
        key: &'life2 Hash,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Self::Node>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn find_value<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        node: &'life1 Self::Node,
        key: &'life2 Hash,
    ) -> Pin<Box<dyn Future<Output = Result<DhtLookupReply<Self::Node, Self::Value>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn add_value<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        key: &'life1 Hash,
        value: &'life2 Self::Value,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn key_to_string(key: &Hash) -> String;
}
Expand description

Trait for application-specific behaviors over a Dht

Required Associated Types§

Required Methods§

Source

fn dht(&self) -> Arc<Dht<Self>>

The Dht instance

Source

fn node<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Self::Node> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get our own node

Source

fn ping<'life0, 'async_trait>( &'life0 self, channel: ChannelPtr, ) -> Pin<Box<dyn Future<Output = Result<Self::Node>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Send a DHT ping request, which is used to know the node data of a peer (and most importantly, its ID/key in the DHT keyspace)

Source

fn on_new_node<'life0, 'life1, 'async_trait>( &'life0 self, node: &'life1 Self::Node, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Triggered when we find a new node

Source

fn find_nodes<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, node: &'life1 Self::Node, key: &'life2 Hash, ) -> Pin<Box<dyn Future<Output = Result<Vec<Self::Node>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Send FIND NODES request to a peer to get nodes close to key

Source

fn find_value<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, node: &'life1 Self::Node, key: &'life2 Hash, ) -> Pin<Box<dyn Future<Output = Result<DhtLookupReply<Self::Node, Self::Value>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Send FIND VALUE request to a peer to get a value and/or nodes close to key

Source

fn add_value<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, key: &'life1 Hash, value: &'life2 Self::Value, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Add a value to our hash table

Source

fn key_to_string(key: &Hash) -> String

Defines how keys are printed/logged

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§