pub struct Listener<C: Codec<ByteBuffer> + Default + Clone> {
builtin: BuiltinTransports,
task_group: TaskGroup,
connection_slots: Semaphore,
conn_queue: Option<AsyncQueueRef<Incoming>>,
monitor: MonitorRef,
handshake_timeout: Duration,
access_control: AccessControlRef,
transport: Option<TransportRef>,
_codec: PhantomData<C>,
}Expand description
Creates inbound connections with other peers. Generic over the
codec applied to the framed accepted streams so the same accept
machinery serves the peer data-plane (PeerNetMsgCodec) and a
discovery’s own messages.
Fields§
§builtin: BuiltinTransportsListens on the endpoints transport does not support.
task_group: TaskGroup§connection_slots: Semaphore§conn_queue: Option<AsyncQueueRef<Incoming>>Hands accepted connections to the PeerPool. Only on the Node’s own listener.
monitor: MonitorRef§handshake_timeout: Duration§access_control: AccessControlRef§transport: Option<TransportRef>Listens on the endpoints it supports instead of the built-in transports.
_codec: PhantomData<C>Implementations§
Source§impl<C> Listener<C>
impl<C> Listener<C>
Sourcepub fn new(ctx: &DiscoveryContext, slots: usize) -> ListenerRef<C>
pub fn new(ctx: &DiscoveryContext, slots: usize) -> ListenerRef<C>
Create a Listener for a discovery’s own connections (no
auto-queue; use start_with_callback). The key pair, monitor,
executor and the handshake timeout, access control, transport and
QUIC runtime of the node’s config come from ctx.
Sourcefn build(
key_pair: &KeyPair,
config: &Config,
slots: usize,
conn_queue: Option<AsyncQueueRef<Incoming>>,
monitor: MonitorRef,
ex: Executor,
) -> ListenerRef<C>
fn build( key_pair: &KeyPair, config: &Config, slots: usize, conn_queue: Option<AsyncQueueRef<Incoming>>, monitor: MonitorRef, ex: Executor, ) -> ListenerRef<C>
Builds a Listener. conn_queue is set only on the Node’s own.
Sourcepub async fn start_with_callback<Fut>(
self: &Arc<Self>,
endpoint: Endpoint,
callback: impl FnOnce(FramedConn<C>) -> Fut + Clone + Send + 'static,
) -> Result<Endpoint>
pub async fn start_with_callback<Fut>( self: &Arc<Self>, endpoint: Endpoint, callback: impl FnOnce(FramedConn<C>) -> Fut + Clone + Send + 'static, ) -> Result<Endpoint>
Start with a user-provided callback for each connection.
pub async fn shutdown(&self)
Sourceasync fn upgrade(
&self,
listener: &StreamListener,
stream: Box<dyn ByteStream>,
) -> Result<(FramedConn<C>, Option<PeerID>)>
async fn upgrade( &self, listener: &StreamListener, stream: Box<dyn ByteStream>, ) -> Result<(FramedConn<C>, Option<PeerID>)>
Runs the handshake and frames the stream. Called off the accept loop. Also returns the peer id proved by the TLS client cert.
Sourceasync fn listen_loop_callback<Fut>(
self: Arc<Self>,
listener: Arc<StreamListener>,
callback: impl FnOnce(FramedConn<C>) -> Fut + Clone + Send + 'static,
)
async fn listen_loop_callback<Fut>( self: Arc<Self>, listener: Arc<StreamListener>, callback: impl FnOnce(FramedConn<C>) -> Fut + Clone + Send + 'static, )
Accept loop (callback mode).
Sourceasync fn listen(&self, endpoint: &Endpoint) -> Result<StreamListener>
async fn listen(&self, endpoint: &Endpoint) -> Result<StreamListener>
Listen with the user transport if it supports endpoint, else
with the built-in TCP or TLS.
Source§impl Listener<PeerNetMsgCodec>
impl Listener<PeerNetMsgCodec>
Sourcepub(crate) fn new_with_queue(
key_pair: &KeyPair,
config: &Config,
conn_queue: AsyncQueueRef<Incoming>,
monitor: MonitorRef,
ex: Executor,
) -> ListenerRef<PeerNetMsgCodec>
pub(crate) fn new_with_queue( key_pair: &KeyPair, config: &Config, conn_queue: AsyncQueueRef<Incoming>, monitor: MonitorRef, ex: Executor, ) -> ListenerRef<PeerNetMsgCodec>
Create a new Listener that hands its connections to the PeerPool.
Sourcepub(crate) async fn start(
self: &ListenerRef<PeerNetMsgCodec>,
endpoint: Endpoint,
) -> Result<Endpoint>
pub(crate) async fn start( self: &ListenerRef<PeerNetMsgCodec>, endpoint: Endpoint, ) -> Result<Endpoint>
Start listening (auto-queue mode). Returns the resolved endpoint.
Sourcefn conn_queue(&self) -> AsyncQueueRef<Incoming>
fn conn_queue(&self) -> AsyncQueueRef<Incoming>
The queue to the PeerPool. Set on every listener that runs the auto-queue paths.
Sourceasync fn listen_loop(
self: ListenerRef<PeerNetMsgCodec>,
listener: Arc<StreamListener>,
)
async fn listen_loop( self: ListenerRef<PeerNetMsgCodec>, listener: Arc<StreamListener>, )
Accept loop (auto-queue mode).
Sourceasync fn queue_inbound(
&self,
listener: &StreamListener,
stream: Box<dyn ByteStream>,
slot: SemaphoreGuard,
conn_queue: &AsyncQueueRef<Incoming>,
) -> Result<()>
async fn queue_inbound( &self, listener: &StreamListener, stream: Box<dyn ByteStream>, slot: SemaphoreGuard, conn_queue: &AsyncQueueRef<Incoming>, ) -> Result<()>
Upgrades an accepted stream and hands it to the PeerPool.
Sourceasync fn start_quic(
self: &ListenerRef<PeerNetMsgCodec>,
endpoint: Endpoint,
) -> Result<Endpoint>
async fn start_quic( self: &ListenerRef<PeerNetMsgCodec>, endpoint: Endpoint, ) -> Result<Endpoint>
QUIC listener.
Sourceasync fn listen_loop_quic(
self: ListenerRef<PeerNetMsgCodec>,
quic_endpoint: QuicEndpoint,
)
async fn listen_loop_quic( self: ListenerRef<PeerNetMsgCodec>, quic_endpoint: QuicEndpoint, )
QUIC accept loop.
Sourceasync fn queue_inbound_quic(
&self,
incoming: QuicIncoming,
slot: SemaphoreGuard,
conn_queue: &AsyncQueueRef<Incoming>,
) -> Result<()>
async fn queue_inbound_quic( &self, incoming: QuicIncoming, slot: SemaphoreGuard, conn_queue: &AsyncQueueRef<Incoming>, ) -> Result<()>
Runs the QUIC handshake, waits for the peer’s first stream and hands the connection to the PeerPool.