Skip to content

transport/manager: Add ability to accept/reject incoming connections before negotiation  #186

@lexnv

Description

@lexnv

Refactor the transport manager and every transport to allow the transport manager to accept or reject incoming connections.

Currently, each transport is responsible for polling the underlying socket and all incoming connections are immediately accepted and negotiated:

fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
while let Poll::Ready(event) = self.listener.poll_next_unpin(cx) {
match event {
None | Some(Err(_)) => return Poll::Ready(None),
Some(Ok((connection, address))) => {
self.on_inbound_connection(connection, address);
}
}
}

self.pending_connections.push(Box::pin(async move {
TcpConnection::accept_connection(
connection,
connection_id,
keypair,
address,
yamux_config,
max_read_ahead_factor,
max_write_buffer_size,
connection_open_timeout,
substream_open_timeout,
)
.await
.map_err(|error| (connection_id, error))

It would be beneficial in terms of resources to move the accept/reject responsibility to the transport manager for inbound connections (similar how we handle outbound ones). We can reject the connection immediately rather than negotiating it to simply reject later.

One option would be to extend the TransportEvent::ConnectionOpened to support an Endpoint instead of a connection + address. Then we can emit this event from each transport to the transport manager. Then, the transport manager can check the limits and handle the negotiation. This may also require a refactor to the peer state logic.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions