Skip to content

Conversation

@lexnv
Copy link
Collaborator

@lexnv lexnv commented Apr 11, 2025

This PR makes the litep2p more generic wrt implementing custom connection limits and policies.

  • the ConnectionMiddleware trait is introduced to offer the ability for developers to implement custom connection policies that hook directly into the connection lifecycle
  • the trait offers the ability to reject connections before or after the negotiation process
  • the ConnectionLimits object is refactored to implement the middleware trait
  • the TransportEvent::PendingInboundConnection is enhanced with the socket address of the remote endpoint

A new middleware trait, named ConnectionMiddleware is introduced:

pub trait ConnectionMiddleware: Send {
   fn outbound_capacity(&mut self, peer: PeerId) -> crate::Result<usize>;

    fn check_inbound(
        &mut self,
        connection_id: ConnectionId,
        address: SocketAddr,
    ) -> crate::Result<()>;

    fn can_accept_connection(&mut self, peer: PeerId, endpoint: &Endpoint) -> crate::Result<()>;

    fn on_connection_established(&mut self, peer: PeerId, endpoint: &Endpoint);

    fn on_connection_closed(&mut self, peer: PeerId, connection_id: ConnectionId);
}

cc @paritytech/networking

lexnv added 22 commits April 10, 2025 16:07
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
@lexnv lexnv added the enhancement New feature or request label Apr 11, 2025
@lexnv lexnv self-assigned this Apr 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants