pub struct Listener<C: Codec<ByteBuffer> + Default + Clone> {
key_pair: KeyPair,
task_group: TaskGroup,
connection_slots: Arc<ConnectionSlots>,
conn_queue: Option<Arc<ConnQueue>>,
monitor: Arc<Monitor>,
handshake_timeout: Duration,
access_control: Arc<dyn AccessControl>,
_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 the
kademlia lookup-plane (KadNetMsgCodec).
Fields§
§key_pair: KeyPair§task_group: TaskGroup§connection_slots: Arc<ConnectionSlots>§conn_queue: Option<Arc<ConnQueue>>§monitor: Arc<Monitor>§handshake_timeout: Duration§access_control: Arc<dyn AccessControl>§_codec: PhantomData<C>Implementations§
Source§impl<C> Listener<C>
impl<C> Listener<C>
Sourcepub fn new(
key_pair: &KeyPair,
connection_slots: Arc<ConnectionSlots>,
monitor: Arc<Monitor>,
handshake_timeout: u64,
access_control: Arc<dyn AccessControl>,
ex: Executor,
) -> Arc<Self> ⓘ
pub fn new( key_pair: &KeyPair, connection_slots: Arc<ConnectionSlots>, monitor: Arc<Monitor>, handshake_timeout: u64, access_control: Arc<dyn AccessControl>, ex: Executor, ) -> Arc<Self> ⓘ
Create a new Listener (no auto-queue; use start_with_callback).
handshake_timeout is in seconds.
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>
Create a listener for TCP/TLS.
Source§impl Listener<PeerNetMsgCodec>
impl Listener<PeerNetMsgCodec>
Sourcepub fn new_with_queue(
key_pair: &KeyPair,
connection_slots: Arc<ConnectionSlots>,
conn_queue: Arc<ConnQueue>,
monitor: Arc<Monitor>,
handshake_timeout: u64,
access_control: Arc<dyn AccessControl>,
ex: Executor,
) -> Arc<Self> ⓘ
pub fn new_with_queue( key_pair: &KeyPair, connection_slots: Arc<ConnectionSlots>, conn_queue: Arc<ConnQueue>, monitor: Arc<Monitor>, handshake_timeout: u64, access_control: Arc<dyn AccessControl>, ex: Executor, ) -> Arc<Self> ⓘ
Create a new Listener with a ConnQueue (auto-queue mode).
handshake_timeout is in seconds.
Sourcepub async fn start(self: &Arc<Self>, endpoint: Endpoint) -> Result<Endpoint>
pub async fn start(self: &Arc<Self>, endpoint: Endpoint) -> Result<Endpoint>
Start listening (auto-queue mode). Returns the resolved endpoint.
Sourceasync fn listen_loop(self: Arc<Self>, listener: Arc<StreamListener>)
async fn listen_loop(self: Arc<Self>, listener: Arc<StreamListener>)
Accept loop (auto-queue mode).
Sourceasync fn listen_loop_quic(self: Arc<Self>, quic_endpoint: QuicEndpoint)
async fn listen_loop_quic(self: Arc<Self>, quic_endpoint: QuicEndpoint)
QUIC accept loop.