Struct DHT

Source
pub struct DHT { /* private fields */ }
Expand description

This struct is the heart of the library - contains data structure and business logic to run a DHT node.

Implementations§

Source§

impl DHT

Source

pub fn get_id(&self) -> Id

Returns the current Id used by the DHT.

Source

pub fn get_info_hashes( &self, newer_than: Option<Instant>, ) -> Vec<(Id, Vec<PeerInfo>)>

Returns a full dump of all the info hashes and peers in storage. Peers that haven’t announced since the provided newer_than can be optionally filtered.

Source

pub fn get_nodes(&self) -> Vec<NodeWrapper>

Returns information about all currently-verified DHT nodes that we’re “connected” with.

Source

pub fn get_settings(&self) -> DHTSettings

Return a copy of the settings used by the DHT

Source

pub fn new( shutdown: ShutdownReceiver, id: Option<Id>, socket_addr: SocketAddr, ip4_source: Box<dyn IPV4AddrSource + Send>, buckets: Box<dyn NodeStorage + Send>, settings: DHTSettings, ) -> Result<DHT, RustyDHTError>

Creates a new DHT.

§Arguments
  • shutdown - the DHT passes this to any sub-tasks that it spawns, and uses it to know when to stop its event own event loop.
  • id - an optional initial Id for the DHT. The DHT may change its Id if at some point its not valid for the external IPv4 address (as reported by ip4_source).
  • listen_port - the port that the DHT should bind its UDP socket on.
  • ip4_source - Some type that implements IPV4AddrSource. This object will be used by the DHT to keep up to date on its IPv4 address.
  • buckets - A function that takes an Id and returns a struct implementing NodeStorage. The NodeStorage-implementing type will be used to keep the nodes (or routing table) of the DHT.
  • routers - Array of string slices with hostname:port of DHT routers. These help us get bootstrapped onto the network.
  • settings - DHTSettings struct containing settings that DHT will use.
Source

pub async fn run_event_loop(&self) -> Result<(), RustyDHTError>

Runs the main event loop of the DHT.

It will only return if there’s an error or if the DHT’s ShutdownReceiver is signalled to stop the DHT.

Source

pub async fn send_request( &self, req: Message, dest: SocketAddr, dest_id: Option<Id>, timeout: Option<Duration>, ) -> Result<Message, RustyDHTError>

Sends a Message, awaits and returns a response.

Note that req must be a request message (not a response or error message), as this method awaits a reply. DHT automatically handles sending responses for incoming requests.

§Arguments
  • req - the message that should be sent
  • dest - the IP/port of the intended recipient
  • dest_id - the Id of the DHT node listening at dest, if known. Otherwise, None can be provided.
  • timeout - An optional timeout. If supplied, this function will return a RustyDHTError::TimeoutError if dest does not reply to the message within the allotted time.
Source

pub fn subscribe(&self) -> Receiver<DHTEvent>

Subscribe to DHTEvent notifications from the DHT.

When you’re sick of receiving events from the DHT, just drop the receiver.

Auto Trait Implementations§

§

impl Freeze for DHT

§

impl !RefUnwindSafe for DHT

§

impl Send for DHT

§

impl Sync for DHT

§

impl Unpin for DHT

§

impl !UnwindSafe for DHT

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V