Struct dht::service::Service [] [src]

pub struct Service<TNodeTable, TData> where TNodeTable: GenericNodeTable, TData: Send + Sync + Clone {
    // some fields omitted
}

Protocol agnostic DHT service.

Its type parameters are TNodeTable - the node table implementation (see e.g. KNodeTable) and TData - stored data type.

The service starts a network listening loop in a separate thread.

Methods

impl<TNodeTable, TData> Service<TNodeTable, TData> where TNodeTable: GenericNodeTable, TData: Send + Sync + Clone
[src]

fn new(node_table: TNodeTable) -> Service<TNodeTable, TData>

Create a service with a random ID.

fn new_with_id(node_table: TNodeTable, node_id: BigUint) -> Service<TNodeTable, TData>

Create a service with a given ID.

fn node_table(&self) -> RwLockReadGuard<TNodeTable>

Get an immutable reference to the node table.

fn node_table_mut(&mut self) -> RwLockWriteGuard<TNodeTable>

Get a mutable reference to the node table.

fn node_id(&self) -> &BigUint

Get the current node ID.

fn stored_data(&self) -> RwLockReadGuard<HashMap<BigUint, TData>>

Get an immutable reference to the data.

fn stored_data_mut(&mut self) -> RwLockWriteGuard<HashMap<BigUint, TData>>

Get an immutable reference to the data.

fn clean_needed(&self) -> bool

Check if some buckets are full already.

fn clean_up<TCheck>(&mut self, check: TCheck) where TCheck: FnMut(&Node) -> bool

Try to clean up the table by checking the oldest records.

Should be called periodically, especially when clean_needed is true.