Struct dht::service::Service
[−]
[src]
pub struct Service<TId, TAddr, TNodeTable, TData> where TId: GenericId,
TNodeTable: GenericNodeTable<TId, TAddr>,
TData: Send + Sync + Clone { /* 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<TId, TAddr, TNodeTable, TData> Service<TId, TAddr, TNodeTable, TData> where TId: GenericId,
TAddr: Send + Sync,
TNodeTable: GenericNodeTable<TId, TAddr>,
TData: Send + Sync + Clone
[src]
TAddr: Send + Sync,
TNodeTable: GenericNodeTable<TId, TAddr>,
TData: Send + Sync + Clone
fn new(node_table: TNodeTable) -> Service<TId, TAddr, TNodeTable, TData>
Create a service with a random ID.
fn new_with_id(node_table: TNodeTable,
node_id: TId)
-> Service<TId, TAddr, TNodeTable, TData>
node_id: TId)
-> Service<TId, TAddr, 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) -> &TId
Get the current node ID.
fn stored_data(&self) -> RwLockReadGuard<HashMap<TId, TData>>
Get an immutable reference to the data.
fn stored_data_mut(&mut self) -> RwLockWriteGuard<HashMap<TId, 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<TId, TAddr>) -> bool
Try to clean up the table by checking the oldest records.
Should be called periodically, especially when clean_needed is true.