Skip to content

dependency injection during boot time #130

Closed
@pgte

Description

@pgte

Some libp2p modules require or would benefit from knowing the peerId and other values. It happens that, at the time the declarative options are created, the peerId is not yet known. As an example, libp2p-websocket-star would require the PeerId object to prevent spoofing. It happens that this value is not known before boot.

Here I propose a modules definition form that is backwards compatible and can be summed up to:

If a module is a function, libp2p assumes it is a constructor and executes that function, which should return a the module instance.

This would allow to declare config like this:

{
  modules: {
    transport: [
      wrtcStar // instance,
      ({peerId}) => new WSStar({id: peerId})
    ]
  }
}

Metadata

Metadata

Assignees

Labels

P1High: Likely tackled by core team if no one steps upexp/wizardExtensive knowledge (implications, ramifications) requiredstatus/in-progressIn progress

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions