Skip to content
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

swarm/src/protocols_handler: Make ProtocolsHandlerEvent depend on `ProtocolsHandler only #2389

Closed
mxinden opened this issue Dec 16, 2021 · 3 comments
Labels
difficulty:moderate getting-started Issues that can be tackled if you don't know the internals of libp2p very well help wanted

Comments

@mxinden
Copy link
Member

mxinden commented Dec 16, 2021

Today ProtocolsHandlerEvent depends on 4 trait parameters.

/// Event produced by a handler.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum ProtocolsHandlerEvent<TConnectionUpgrade, TOutboundOpenInfo, TCustom, TErr> {
/// Request a new outbound substream to be opened with the remote.
OutboundSubstreamRequest {
/// The protocol(s) to apply on the substream.
protocol: SubstreamProtocol<TConnectionUpgrade, TOutboundOpenInfo>,
},
/// Close the connection for the given reason.
Close(TErr),
/// Other event.
Custom(TCustom),

I think it is worth exploring simplifications, e.g. having ProtocolsHandlerEvent depend on a ProtocolsHandler implementation only:

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum ProtocolsHandlerEvent<THandler: ProtocolsHandler> {
    /// Request a new outbound substream to be opened with the remote.
    OutboundSubstreamRequest {
        /// The protocol(s) to apply on the substream.
        protocol: SubstreamProtocol<THandler::OutboundProtocol, THandler::OutboundOpenInfo>,
    },

    /// Close the connection for the given reason.
    Close(THandler::Errror),

    /// Other event.
    Custom(THandler::OutEvent),
}

Note that this might clash with the various ProtocolsHandlerEvent::map_xxx methods, as they assume being able to map individual trait parameters.

Proposed by @elenaf9 in #2059 (comment).

@mxinden mxinden added difficulty:moderate help wanted getting-started Issues that can be tackled if you don't know the internals of libp2p very well labels Dec 16, 2021
@drHuangMHT
Copy link
Contributor

Update: ProtocolHandler has been renamed to ConnectionHandler.
Just attempted to do this but the compiler denied an inobvious equality: associated types of ToggleConnectionHandler<TInner> and associated types of TInner. This is expected, because the wrapper and inner are different after all. But this makes it impossible to remove all generic parameters of ConnectionHandlerEvent without removing ToggleConnectionHandler.

@thomaseizinger
Copy link
Contributor

Three of these trait parameters will go away eventually through other refactorings:

@thomaseizinger
Copy link
Contributor

Closing this as a result.

@thomaseizinger thomaseizinger closed this as not planned Won't fix, can't repro, duplicate, stale Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty:moderate getting-started Issues that can be tackled if you don't know the internals of libp2p very well help wanted
Projects
None yet
Development

No branches or pull requests

3 participants