Skip to content

manager: Enhance connection lifecycle with custom connection policies #372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: master
Choose a base branch
from

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 <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
@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.

1 participant