Skip to content

[switch] Refactor TransportManager to avoid storing listeners directly on the Transport object #430

@dirkmc

Description

@dirkmc

TransportManager stores listeners on the underlying Transport object itself. This causes strange things to happen if, for example, the Transport implementation extends EventEmitter (as it does in peer-base) because EventEmitter has a method called listeners() which gets clobbered.

Currently Switch has an object called transports whose keys are transport names (eg 'tcp') and values are the Transport implementations themselves. I suggest adding a level of indirection such that the values have an object like this:

{
  transport: <Transport implementation>,
  listeners: [<Listener>, <Listener>, ...]
}

The only complicating factor would be if there are libraries that depend on libp2p-switch and reference Switch.transports. As far as I can tell there are no references elsewhere in libp2p.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions