Skip to content

fix: pass service map to non-service components #3070

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 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions packages/libp2p/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,45 +92,45 @@ export interface Libp2pInit<T extends ServiceMap = ServiceMap> {
/**
* Transports are low-level communication channels
*/
transports?: Array<(components: Components) => Transport>
transports?: Array<(components: Components & T) => Transport>

/**
* Stream muxers allow the creation of many data streams over a single
* connection.
*/
streamMuxers?: Array<(components: Components) => StreamMuxerFactory>
streamMuxers?: Array<(components: Components & T) => StreamMuxerFactory>

/**
* Connection encrypters ensure that data sent over connections cannot be
* eavesdropped on, and that the remote peer possesses the private key that
* corresponds to the public key that it's Peer ID is derived from.
*/
connectionEncrypters?: Array<(components: Components) => ConnectionEncrypter>
connectionEncrypters?: Array<(components: Components & T) => ConnectionEncrypter>

/**
* Peer discovery mechanisms allow finding peers on the network
*/
peerDiscovery?: Array<(components: Components) => PeerDiscovery>
peerDiscovery?: Array<(components: Components & T) => PeerDiscovery>

/**
* Peer routers provide implementations for peer routing queries
*/
peerRouters?: Array<(components: Components) => PeerRouting>
peerRouters?: Array<(components: Components & T) => PeerRouting>

/**
* Content routers provide implementations for content routing queries
*/
contentRouters?: Array<(components: Components) => ContentRouting>
contentRouters?: Array<(components: Components & T) => ContentRouting>

/**
* A Metrics implementation can be supplied to collect metrics on this node
*/
metrics?(components: Components): Metrics
metrics?(components: Components & T): Metrics

/**
* A ConnectionProtector can be used to create a secure overlay on top of the network using pre-shared keys
*/
connectionProtector?(components: Components): ConnectionProtector
connectionProtector?(components: Components & T): ConnectionProtector

/**
* Arbitrary libp2p modules
Expand Down
1 change: 1 addition & 0 deletions packages/libp2p/src/libp2p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export class Libp2p<T extends ServiceMap = ServiceMap> extends TypedEventEmitter

// Set up connection protector if configured
if (init.connectionProtector != null) {
// @ts-expect-error defaultComponents is missing service component types added later
this.configureComponent('connectionProtector', init.connectionProtector(components))
}

Expand Down
Loading