Skip to main content

DHTServer

Struct DHTServer 

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

Cloneable BEP-5 server handle and primary crate entry point.

Implementations§

Source§

impl DHTServer

Source

pub async fn new(options: DHTOptions) -> Result<Self>

Validates options, binds configured UDP sockets and constructs bounded pipelines.

Background Metadata scheduling begins during construction. Active crawling and UDP receive loops begin when Self::start is awaited.

Source

pub fn on_metadata_fetch<F, Fut>(&self, callback: F)
where F: Fn(String) -> Fut + Send + Sync + 'static, Fut: Future<Output = bool> + Send + 'static,

Registers the asynchronous admission gate invoked before the first real Peer attempt.

Returning false rejects the job without downloading Metadata and without emitting a MetadataFetchCompletion. If no gate is registered, jobs are admitted.

Source

pub fn on_torrent<F>(&self, callback: F)
where F: Fn(TorrentInfo) + Send + Sync + 'static,

Registers a torrent callback whose return is implicitly treated as accepted delivery.

Registering a new torrent callback replaces the previous one.

Source

pub fn on_torrent_with_ack<F>(&self, callback: F)
where F: Fn(TorrentInfo) -> bool + Send + Sync + 'static,

Registers a torrent callback that acknowledges application delivery.

Returning true produces crate::MetadataFetchCompletionStatus::Accepted. Returning false produces crate::MetadataFetchCompletionStatus::DeliveryRejected: the Metadata download was valid, but the application did not accept it. A callback panic is caught and treated as rejected delivery. Registering this callback replaces any previous torrent callback.

Source

pub fn on_metadata_fetch_complete<F>(&self, callback: F)
where F: Fn(MetadataFetchCompletion) + Send + Sync + 'static,

Registers a callback invoked exactly once when an admitted Metadata job terminates.

Gate rejection does not emit a completion. attempts counts real Peer network attempts; failure-cache skips are excluded. Registering a new callback replaces the previous one.

Source

pub fn filter<F>(&self, filter: F)
where F: Fn(&str) -> bool + Send + Sync + 'static,

Registers an early synchronous InfoHash filter for valid announce_peer queries.

Returning false prevents the Hash from entering the bounded ingress queue. Registering a new filter replaces the previous one.

Source

pub fn set_filter<F>(&self, filter: F)
where F: Fn(&str) -> bool + Send + Sync + 'static,

Alias for Self::filter.

Source

pub fn on_error<F>(&self, callback: F)
where F: Fn(DHTError) + Send + Sync + 'static,

Registers a runtime error callback, replacing any previous callback.

Initialization and start errors are still returned through Result.

Source

pub fn get_node_pool_size(&self) -> usize

Returns the current strict FIFO crawl-pool size.

Source

pub fn runtime_stats(&self) -> DhtRuntimeStats

Returns a cheap cloneable handle to transport-neutral atomic runtime statistics.

Source

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

Starts crawl and UDP background tasks, then waits until Self::shutdown is called.

A shut-down server cannot be restarted. Construct a new DHTServer for another run.

Source

pub fn shutdown(&self)

Cancels UDP, crawl and Metadata tasks. This method is safe to call more than once.

Trait Implementations§

Source§

impl Clone for DHTServer

Source§

fn clone(&self) -> DHTServer

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

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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