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})
]
}
}
Some libp2p modules require or would benefit from knowing the
peerIdand 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 thePeerIdobject 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: