Skip to main content

DhtHandle

Struct DhtHandle 

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

A cloneable handle to the DHT actor.

Implementations§

Source§

impl DhtHandle

Source

pub async fn start(config: DhtConfig) -> Result<(Self, Receiver<IpAddr>)>

Start the DHT actor and return a handle plus an IP consensus channel.

The consensus channel fires when the BEP 42 ExternalIpVoter reaches agreement on our external IP address.

§Errors

Returns an error if the UDP socket cannot be bound.

Source

pub async fn update_external_ip( &self, ip: IpAddr, source: IpVoteSource, ) -> Result<()>

Notify the DHT of our external IP (from NAT/tracker discovery).

§Errors

Returns Error::Shutdown if the actor has stopped.

Source

pub async fn get_peers( &self, info_hash: Id20, ) -> Result<UnboundedReceiver<Vec<SocketAddr>>>

Discover peers for an info_hash.

Returns a channel that receives batches of peers as they are found. The channel closes when the search is exhausted.

§Errors

Returns Error::Shutdown if the actor has stopped.

Source

pub async fn announce(&self, info_hash: Id20, port: u16) -> Result<()>

Announce that we have peers for an info_hash on the given port.

§Errors

Returns Error::Shutdown if the actor has stopped.

Source

pub async fn stats(&self) -> Result<DhtStats>

Get current DHT statistics.

§Errors

Returns Error::Shutdown if the actor has stopped.

Source

pub async fn node_count(&self) -> Result<usize>

Get the number of nodes currently in the routing table (M171 D4).

Thin accessor over DhtStats::routing_table_size used by the qBt v2 transferInfo.dht_nodes field and the DHT pseudo-tracker’s num_peers column. Returns Ok(0) when the routing table is empty — including immediately after startup, before bootstrap has populated any buckets.

§Errors

Returns Error::Shutdown if the actor has stopped.

Source

pub async fn shutdown(&self) -> Result<()>

Shut down the DHT actor (fire-and-forget).

Returns once the shutdown command has been queued. The actor will persist the routing table (dht_state.json) before terminating, but this method does NOT wait for that. For runtime DHT-restart paths that need to be sure the state is on disk before starting a new actor, use Self::shutdown_and_wait.

§Errors

Returns Error::Shutdown if the command channel has already closed.

Source

pub async fn shutdown_and_wait(&self) -> Result<()>

M173 Lane B (B7): shut down the DHT actor and wait for it to fully drain — including persisting the routing table to dht_state.json.

Returns Ok(()) once the actor has saved its state and terminated. Used by the apply_settings DHT-restart phase so the new DHT actor (started with the same state_dir) can load the pre-restart state.

§Errors

Returns Error::Shutdown if the actor exits before sending its reply (typically because it had already shut down for another reason).

Source

pub async fn save_routing_table(&self) -> Result<()>

M173 Lane B (B7): synchronously persist the routing table.

Returns Ok(()) once dht_state.json has been written and renamed atomically. Distinct from Self::shutdown_and_wait in that the actor continues running afterwards — used by callers that want to checkpoint state without restarting DHT.

§Errors

Returns Error::Shutdown if the actor channel has closed. May return an underlying I/O error wrapped in Error::Shutdown if the persist itself failed (the actor returns the error verbatim, but the channel-closed case is indistinguishable from the I/O case at the API boundary).

Source

pub async fn put_immutable(&self, value: Vec<u8>) -> Result<Id20>

Store an immutable item in the DHT (BEP 44).

Returns the SHA-1 target hash that can be used to retrieve the item. The value must be valid bencoded data, max 1000 bytes.

§Errors

Returns Error::Shutdown if the actor has stopped, or a BEP 44 validation error if the value exceeds size limits.

Source

pub async fn get_immutable(&self, target: Id20) -> Result<Option<Vec<u8>>>

Retrieve an immutable item from the DHT (BEP 44).

Returns the raw bencoded value if found, None if not.

§Errors

Returns Error::Shutdown if the actor has stopped.

Source

pub async fn put_mutable( &self, keypair_bytes: [u8; 32], value: Vec<u8>, seq: i64, salt: Vec<u8>, ) -> Result<Id20>

Store a mutable item in the DHT (BEP 44).

  • keypair_bytes: 32-byte ed25519 seed (secret key)
  • value: bencoded data, max 1000 bytes
  • seq: sequence number (must be higher than any previously stored)
  • salt: optional salt for sub-key isolation (max 64 bytes)

Returns the target hash.

§Errors

Returns Error::Shutdown if the actor has stopped, or a BEP 44 validation error if value or salt exceeds size limits.

Source

pub async fn sample_infohashes( &self, target: Id20, ) -> Result<SampleInfohashesResult>

Query a DHT node for a random sample of info hashes (BEP 51).

Routes toward target to find the responding node. Returns sampled hashes, the interval before re-querying, and closer nodes for traversal.

§Errors

Returns Error::Shutdown if the actor has stopped.

Source

pub async fn get_mutable( &self, public_key: [u8; 32], salt: Vec<u8>, ) -> Result<Option<(Vec<u8>, i64)>>

Retrieve a mutable item from the DHT (BEP 44).

Returns (value, seq) if found, None if not.

§Errors

Returns Error::Shutdown if the actor has stopped.

Source

pub async fn get_routing_nodes(&self) -> Vec<(Id20, SocketAddr)>

Return all nodes currently in the DHT routing table.

Trait Implementations§

Source§

impl Clone for DhtHandle

Source§

fn clone(&self) -> DhtHandle

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DhtHandle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more