pub struct DhtHandler { /* private fields */ }Expand description
Serves cdn/dht/v1. Owns the routing table + the per-request rate
limiter; accept() is reentrant — many concurrent streams from
different peers all share the same Arc<DhtHandler>.
Routing-table updates take a short Mutex — the table is touched once
per request to refresh the requester’s recency and once again to
produce the closer_nodes snapshot. We use std::sync::Mutex rather
than tokio::sync::Mutex since the critical section is microseconds
long (no awaits) and the lock would just add scheduler overhead.
Implementations§
Source§impl DhtHandler
impl DhtHandler
Sourcepub const ALPN: &'static [u8] = ALPN_DHT
pub const ALPN: &'static [u8] = ALPN_DHT
The ALPN this handler answers on: cdn/dht/v1, the content-discovery
protocol (ADR 022).
Sourcepub fn new(
self_id: PublicKey,
rate_limiter: Arc<DhtRateLimiter>,
dispatch_limiter: Arc<ConnectionLimiter>,
metrics: Arc<Metrics>,
staker_set: Arc<dyn StakerSet>,
records: Arc<Mutex<RecordStore>>,
) -> Self
pub fn new( self_id: PublicKey, rate_limiter: Arc<DhtRateLimiter>, dispatch_limiter: Arc<ConnectionLimiter>, metrics: Arc<Metrics>, staker_set: Arc<dyn StakerSet>, records: Arc<Mutex<RecordStore>>, ) -> Self
Construct a handler. The routing table is empty at construction; the
runtime’s DHT bootstrap fills it from the on-chain staker set, and the
handler additionally updates the table from every incoming
request’s authenticated NodeId once it knows the peer is
rate-limit admitted.
Sourcepub const fn with_routing(
self_id: PublicKey,
routing: Arc<Mutex<RoutingTable>>,
rate_limiter: Arc<DhtRateLimiter>,
dispatch_limiter: Arc<ConnectionLimiter>,
metrics: Arc<Metrics>,
staker_set: Arc<dyn StakerSet>,
records: Arc<Mutex<RecordStore>>,
) -> Self
pub const fn with_routing( self_id: PublicKey, routing: Arc<Mutex<RoutingTable>>, rate_limiter: Arc<DhtRateLimiter>, dispatch_limiter: Arc<ConnectionLimiter>, metrics: Arc<Metrics>, staker_set: Arc<dyn StakerSet>, records: Arc<Mutex<RecordStore>>, ) -> Self
Construct with a pre-built routing table. Used by tests and by the bootstrap path that wants to seed the table before the handler goes live.
Sourcepub fn routing_table(&self) -> Arc<Mutex<RoutingTable>> ⓘ
pub fn routing_table(&self) -> Arc<Mutex<RoutingTable>> ⓘ
Shared handle to the routing table — exposed so the runtime’s bootstrap
and bucket-refresh tasks drive the same table without re-allocating the
Arc<Mutex<RoutingTable>> from outside.
Trait Implementations§
Source§impl Debug for DhtHandler
impl Debug for DhtHandler
Source§impl ProtocolHandler for DhtHandler
impl ProtocolHandler for DhtHandler
Source§async fn accept(&self, connection: Connection) -> Result<(), AcceptError>
async fn accept(&self, connection: Connection) -> Result<(), AcceptError>
Source§fn on_accepting(
&self,
accepting: Accepting,
) -> impl Future<Output = Result<Connection, AcceptError>> + Send
fn on_accepting( &self, accepting: Accepting, ) -> impl Future<Output = Result<Connection, AcceptError>> + Send
Accepting state. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for DhtHandler
impl !UnwindSafe for DhtHandler
impl Freeze for DhtHandler
impl Send for DhtHandler
impl Sync for DhtHandler
impl Unpin for DhtHandler
impl UnsafeUnpin for DhtHandler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<P> DynProtocolHandler for Pwhere
P: ProtocolHandler,
impl<P> DynProtocolHandler for Pwhere
P: ProtocolHandler,
Source§fn accept(
&self,
connection: Connection,
) -> Pin<Box<dyn Future<Output = Result<(), AcceptError>> + Send + '_>>
fn accept( &self, connection: Connection, ) -> Pin<Box<dyn Future<Output = Result<(), AcceptError>> + Send + '_>>
Source§fn on_accepting(
&self,
accepting: Accepting,
) -> Pin<Box<dyn Future<Output = Result<Connection, AcceptError>> + Send + '_>>
fn on_accepting( &self, accepting: Accepting, ) -> Pin<Box<dyn Future<Output = Result<Connection, AcceptError>> + Send + '_>>
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request