Comparing version 2.5.2 to 2.6.0
@@ -120,3 +120,12 @@ import type { ComponentLogger, Libp2pEvents, TypedEventTarget, PeerId, PeerStore } from '@libp2p/interface'; | ||
removePublicAddressMapping(internalIp: string, internalPort: number, externalIp: string, externalPort?: number, protocol?: 'tcp' | 'udp'): void; | ||
/** | ||
* Where an external service (router, gateway, etc) is forwarding traffic to | ||
* us, attempt to add an IP mapping for the external address - this will | ||
* include the observed mapping in the address list where we also have a DNS | ||
* mapping for the external IP. | ||
* | ||
* Returns true if we added a new mapping | ||
*/ | ||
private maybeUpgradeToIPMapping; | ||
} | ||
//# sourceMappingURL=index.d.ts.map |
@@ -6,3 +6,5 @@ /* eslint-disable complexity */ | ||
import { createScalableCuckooFilter } from '@libp2p/utils/filters'; | ||
import { isPrivateIp } from '@libp2p/utils/private-ip'; | ||
import { multiaddr } from '@multiformats/multiaddr'; | ||
import { QUICV1, TCP, WebSockets, WebSocketsSecure } from '@multiformats/multiaddr-matcher'; | ||
import { DNSMappings } from './dns-mappings.js'; | ||
@@ -150,14 +152,33 @@ import { IPMappings } from './ip-mappings.js'; | ||
let startingConfidence = true; | ||
if (options?.type === 'observed' || this.observed.has(addr)) { | ||
startingConfidence = this.observed.confirm(addr, options?.ttl ?? this.addressVerificationTTL); | ||
} | ||
if (options?.type === 'transport' || this.transportAddresses.has(addr)) { | ||
startingConfidence = this.transportAddresses.confirm(addr, options?.ttl ?? this.addressVerificationTTL); | ||
const transportStartingConfidence = this.transportAddresses.confirm(addr, options?.ttl ?? this.addressVerificationTTL); | ||
if (!transportStartingConfidence && startingConfidence) { | ||
startingConfidence = false; | ||
} | ||
} | ||
if (options?.type === 'dns-mapping' || this.dnsMappings.has(addr)) { | ||
startingConfidence = this.dnsMappings.confirm(addr, options?.ttl ?? this.addressVerificationTTL); | ||
const dnsMapingStartingConfidence = this.dnsMappings.confirm(addr, options?.ttl ?? this.addressVerificationTTL); | ||
if (!dnsMapingStartingConfidence && startingConfidence) { | ||
startingConfidence = false; | ||
} | ||
} | ||
if (options?.type === 'ip-mapping' || this.ipMappings.has(addr)) { | ||
startingConfidence = this.ipMappings.confirm(addr, options?.ttl ?? this.addressVerificationTTL); | ||
const ipMapingStartingConfidence = this.ipMappings.confirm(addr, options?.ttl ?? this.addressVerificationTTL); | ||
if (!ipMapingStartingConfidence && startingConfidence) { | ||
startingConfidence = false; | ||
} | ||
} | ||
if (options?.type === 'observed' || this.observed.has(addr)) { | ||
// try to match up observed address with local transport listener | ||
if (this.maybeUpgradeToIPMapping(addr)) { | ||
this.ipMappings.confirm(addr, options?.ttl ?? this.addressVerificationTTL); | ||
startingConfidence = false; | ||
} | ||
else { | ||
const observedStartingConfidence = this.observed.confirm(addr, options?.ttl ?? this.addressVerificationTTL); | ||
if (!observedStartingConfidence && startingConfidence) { | ||
startingConfidence = false; | ||
} | ||
} | ||
} | ||
// only trigger the 'self:peer:update' event if our confidence in an address has changed | ||
@@ -172,12 +193,24 @@ if (!startingConfidence) { | ||
if (this.observed.has(addr)) { | ||
startingConfidence = this.observed.remove(addr); | ||
const observedStartingConfidence = this.observed.remove(addr); | ||
if (!observedStartingConfidence && startingConfidence) { | ||
startingConfidence = false; | ||
} | ||
} | ||
if (this.transportAddresses.has(addr)) { | ||
startingConfidence = this.transportAddresses.unconfirm(addr, options?.ttl ?? this.addressVerificationRetry); | ||
const transportStartingConfidence = this.transportAddresses.unconfirm(addr, options?.ttl ?? this.addressVerificationRetry); | ||
if (!transportStartingConfidence && startingConfidence) { | ||
startingConfidence = false; | ||
} | ||
} | ||
if (this.dnsMappings.has(addr)) { | ||
startingConfidence = this.dnsMappings.unconfirm(addr, options?.ttl ?? this.addressVerificationRetry); | ||
const dnsMapingStartingConfidence = this.dnsMappings.unconfirm(addr, options?.ttl ?? this.addressVerificationRetry); | ||
if (!dnsMapingStartingConfidence && startingConfidence) { | ||
startingConfidence = false; | ||
} | ||
} | ||
if (this.ipMappings.has(addr)) { | ||
startingConfidence = this.ipMappings.unconfirm(addr, options?.ttl ?? this.addressVerificationRetry); | ||
const ipMapingStartingConfidence = this.ipMappings.unconfirm(addr, options?.ttl ?? this.addressVerificationRetry); | ||
if (!ipMapingStartingConfidence && startingConfidence) { | ||
startingConfidence = false; | ||
} | ||
} | ||
@@ -266,3 +299,61 @@ // only trigger the 'self:peer:update' event if our confidence in an address has changed | ||
} | ||
/** | ||
* Where an external service (router, gateway, etc) is forwarding traffic to | ||
* us, attempt to add an IP mapping for the external address - this will | ||
* include the observed mapping in the address list where we also have a DNS | ||
* mapping for the external IP. | ||
* | ||
* Returns true if we added a new mapping | ||
*/ | ||
maybeUpgradeToIPMapping(ma) { | ||
// this address is already mapped | ||
if (this.ipMappings.has(ma)) { | ||
return false; | ||
} | ||
const maOptions = ma.toOptions(); | ||
// only public IPv4 addresses | ||
if (maOptions.family === 6 || maOptions.host === '127.0.0.1' || isPrivateIp(maOptions.host) === true) { | ||
return false; | ||
} | ||
const listeners = this.components.transportManager.getListeners(); | ||
const transportMatchers = [ | ||
(ma) => WebSockets.exactMatch(ma) || WebSocketsSecure.exactMatch(ma), | ||
(ma) => TCP.exactMatch(ma), | ||
(ma) => QUICV1.exactMatch(ma) | ||
]; | ||
for (const matcher of transportMatchers) { | ||
// is the incoming address the same type as the matcher | ||
if (!matcher(ma)) { | ||
continue; | ||
} | ||
// get the listeners for this transport | ||
const transportListeners = listeners.filter(listener => { | ||
return listener.getAddrs().filter(ma => { | ||
// only IPv4 addresses of the matcher type | ||
return ma.toOptions().family === 4 && matcher(ma); | ||
}).length > 0; | ||
}); | ||
// because the NAT mapping could be forwarding different external ports to | ||
// internal ones, we can only be sure enough to add a mapping if there is | ||
// a single listener | ||
if (transportListeners.length !== 1) { | ||
continue; | ||
} | ||
// we have one listener which listens on one port so whatever the external | ||
// NAT port mapping is, it should be for this listener | ||
const linkLocalAddr = transportListeners[0].getAddrs().filter(ma => { | ||
return ma.toOptions().host !== '127.0.0.1'; | ||
}).pop(); | ||
if (linkLocalAddr == null) { | ||
continue; | ||
} | ||
const linkLocalOptions = linkLocalAddr.toOptions(); | ||
// upgrade observed address to IP mapping | ||
this.observed.remove(ma); | ||
this.ipMappings.add(linkLocalOptions.host, linkLocalOptions.port, maOptions.host, maOptions.port, maOptions.transport); | ||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -44,3 +44,3 @@ /** | ||
*/ | ||
nodeInfo?: NodeInfo; | ||
nodeInfo?: Partial<NodeInfo>; | ||
/** | ||
@@ -47,0 +47,0 @@ * Addresses for transport listening and to advertise to the network |
@@ -5,4 +5,3 @@ import { TypedEventEmitter } from '@libp2p/interface'; | ||
import type { Libp2p as Libp2pInterface, Libp2pInit } from './index.js'; | ||
import type { PeerRouting, ContentRouting, Libp2pEvents, PendingDial, ServiceMap, AbortOptions, ComponentLogger, Connection, NewStreamOptions, Stream, Metrics, PeerId, PeerStore, Topology, Libp2pStatus, IsDialableOptions, DialOptions, PublicKey, Ed25519PeerId, Secp256k1PeerId, RSAPublicKey, RSAPeerId, URLPeerId, Ed25519PublicKey, Secp256k1PublicKey } from '@libp2p/interface'; | ||
import type { StreamHandler, StreamHandlerOptions } from '@libp2p/interface-internal'; | ||
import type { PeerRouting, ContentRouting, Libp2pEvents, PendingDial, ServiceMap, AbortOptions, ComponentLogger, Connection, NewStreamOptions, Stream, Metrics, PeerId, PeerStore, Topology, Libp2pStatus, IsDialableOptions, DialOptions, PublicKey, Ed25519PeerId, Secp256k1PeerId, RSAPublicKey, RSAPeerId, URLPeerId, Ed25519PublicKey, Secp256k1PublicKey, StreamHandler, StreamHandlerOptions } from '@libp2p/interface'; | ||
export declare class Libp2p<T extends ServiceMap = ServiceMap> extends TypedEventEmitter<Libp2pEvents> implements Libp2pInterface<T> { | ||
@@ -9,0 +8,0 @@ #private; |
@@ -19,5 +19,6 @@ import { publicKeyFromProtobuf } from '@libp2p/crypto/keys'; | ||
import { RandomWalk } from './random-walk.js'; | ||
import { DefaultRegistrar } from './registrar.js'; | ||
import { Registrar } from './registrar.js'; | ||
import { DefaultTransportManager } from './transport-manager.js'; | ||
import { DefaultUpgrader } from './upgrader.js'; | ||
import { userAgent } from './user-agent.js'; | ||
import * as pkg from './version.js'; | ||
@@ -54,2 +55,4 @@ export class Libp2p extends TypedEventEmitter { | ||
this.services = {}; | ||
const nodeInfoName = init.nodeInfo?.name ?? pkg.name; | ||
const nodeInfoVersion = init.nodeInfo?.version ?? pkg.name; | ||
// @ts-expect-error defaultComponents is missing component types added later | ||
@@ -59,5 +62,6 @@ const components = this.components = defaultComponents({ | ||
privateKey: init.privateKey, | ||
nodeInfo: init.nodeInfo ?? { | ||
name: pkg.name, | ||
version: pkg.version | ||
nodeInfo: { | ||
name: nodeInfoName, | ||
version: nodeInfoVersion, | ||
userAgent: init.nodeInfo?.userAgent ?? userAgent(nodeInfoName, nodeInfoVersion) | ||
}, | ||
@@ -108,3 +112,3 @@ logger: this.logger, | ||
// Create the Registrar | ||
this.configureComponent('registrar', new DefaultRegistrar(this.components)); | ||
this.configureComponent('registrar', new Registrar(this.components)); | ||
// Addresses {listen, announce, noAnnounce} | ||
@@ -111,0 +115,0 @@ this.configureComponent('addressManager', new AddressManager(this.components, init.addresses)); |
@@ -1,3 +0,3 @@ | ||
import type { IdentifyResult, Libp2pEvents, PeerUpdate, TypedEventTarget, PeerId, PeerStore, Topology } from '@libp2p/interface'; | ||
import type { StreamHandlerOptions, StreamHandlerRecord, Registrar, StreamHandler } from '@libp2p/interface-internal'; | ||
import type { IdentifyResult, Libp2pEvents, PeerUpdate, TypedEventTarget, PeerId, PeerStore, Topology, StreamHandlerRecord, StreamHandlerOptions } from '@libp2p/interface'; | ||
import type { Registrar as RegistrarInterface, StreamHandler } from '@libp2p/interface-internal'; | ||
import type { ComponentLogger } from '@libp2p/logger'; | ||
@@ -15,3 +15,3 @@ export declare const DEFAULT_MAX_INBOUND_STREAMS = 32; | ||
*/ | ||
export declare class DefaultRegistrar implements Registrar { | ||
export declare class Registrar implements RegistrarInterface { | ||
private readonly log; | ||
@@ -18,0 +18,0 @@ private readonly topologies; |
@@ -9,3 +9,3 @@ import { InvalidParametersError } from '@libp2p/interface'; | ||
*/ | ||
export class DefaultRegistrar { | ||
export class Registrar { | ||
log; | ||
@@ -53,3 +53,3 @@ topologies; | ||
async handle(protocol, handler, opts) { | ||
if (this.handlers.has(protocol)) { | ||
if (this.handlers.has(protocol) && opts?.force !== true) { | ||
throw new errorsJs.DuplicateProtocolHandlerError(`Handler already registered for protocol ${protocol}`); | ||
@@ -56,0 +56,0 @@ } |
@@ -1,3 +0,3 @@ | ||
export declare const version = "2.5.2"; | ||
export declare const version = "2.6.0"; | ||
export declare const name = "js-libp2p"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -1,3 +0,3 @@ | ||
export const version = '2.5.2'; | ||
export const version = '2.6.0'; | ||
export const name = 'js-libp2p'; | ||
//# sourceMappingURL=version.js.map |
@@ -15,2 +15,4 @@ { | ||
".:createLibp2p": "https://libp2p.github.io/js-libp2p/functions/libp2p.index.createLibp2p.html", | ||
"userAgent": "https://libp2p.github.io/js-libp2p/functions/libp2p.user_agent.userAgent.html", | ||
"./user-agent:userAgent": "https://libp2p.github.io/js-libp2p/functions/libp2p.user_agent.userAgent.html", | ||
"name": "https://libp2p.github.io/js-libp2p/variables/libp2p.version.name.html", | ||
@@ -17,0 +19,0 @@ "./version:name": "https://libp2p.github.io/js-libp2p/variables/libp2p.version.name.html", |
{ | ||
"name": "libp2p", | ||
"version": "2.5.2", | ||
"version": "2.6.0", | ||
"description": "JavaScript implementation of libp2p, a modular peer to peer network stack", | ||
@@ -55,2 +55,6 @@ "license": "Apache-2.0 OR MIT", | ||
}, | ||
"./user-agent": { | ||
"types": "./dist/src/user-agent.d.ts", | ||
"import": "./dist/src/user-agent.js" | ||
}, | ||
"./version": { | ||
@@ -91,13 +95,13 @@ "types": "./dist/src/version.d.ts", | ||
"@chainsafe/netmask": "^2.0.0", | ||
"@libp2p/crypto": "^5.0.10", | ||
"@libp2p/interface": "^2.4.1", | ||
"@libp2p/interface-internal": "^2.2.4", | ||
"@libp2p/logger": "^5.1.7", | ||
"@libp2p/multistream-select": "^6.0.12", | ||
"@libp2p/peer-collections": "^6.0.16", | ||
"@libp2p/peer-id": "^5.0.11", | ||
"@libp2p/peer-store": "^11.0.16", | ||
"@libp2p/utils": "^6.5.0", | ||
"@libp2p/crypto": "^5.0.11", | ||
"@libp2p/interface": "^2.5.0", | ||
"@libp2p/interface-internal": "^2.3.0", | ||
"@libp2p/logger": "^5.1.8", | ||
"@libp2p/multistream-select": "^6.0.13", | ||
"@libp2p/peer-collections": "^6.0.17", | ||
"@libp2p/peer-id": "^5.0.12", | ||
"@libp2p/peer-store": "^11.0.17", | ||
"@libp2p/utils": "^6.5.1", | ||
"@multiformats/dns": "^1.0.6", | ||
"@multiformats/multiaddr": "^12.3.3", | ||
"@multiformats/multiaddr": "^12.3.5", | ||
"@multiformats/multiaddr-matcher": "^1.6.0", | ||
@@ -133,13 +137,16 @@ "any-signal": "^4.1.1", | ||
"sinon-ts": "^2.0.0", | ||
"uint8arraylist": "^2.4.8" | ||
"uint8arraylist": "^2.4.8", | ||
"wherearewe": "^2.0.1" | ||
}, | ||
"browser": { | ||
"./dist/src/connection-manager/constants.js": "./dist/src/connection-manager/constants.browser.js", | ||
"./dist/src/config/connection-gater.js": "./dist/src/config/connection-gater.browser.js" | ||
"./dist/src/config/connection-gater.js": "./dist/src/config/connection-gater.browser.js", | ||
"./dist/src/user-agent.js": "./dist/src/user-agent.browser.js" | ||
}, | ||
"react-native": { | ||
"./dist/src/connection-manager/constants.js": "./dist/src/connection-manager/constants.browser.js", | ||
"./dist/src/config/connection-gater.js": "./dist/src/config/connection-gater.browser.js" | ||
"./dist/src/config/connection-gater.js": "./dist/src/config/connection-gater.browser.js", | ||
"./dist/src/user-agent.js": "./dist/src/user-agent.react-native.js" | ||
}, | ||
"sideEffects": false | ||
} |
@@ -6,3 +6,5 @@ /* eslint-disable complexity */ | ||
import { createScalableCuckooFilter } from '@libp2p/utils/filters' | ||
import { isPrivateIp } from '@libp2p/utils/private-ip' | ||
import { multiaddr } from '@multiformats/multiaddr' | ||
import { QUICV1, TCP, WebSockets, WebSocketsSecure } from '@multiformats/multiaddr-matcher' | ||
import { DNSMappings } from './dns-mappings.js' | ||
@@ -253,18 +255,40 @@ import { IPMappings } from './ip-mappings.js' | ||
if (options?.type === 'observed' || this.observed.has(addr)) { | ||
startingConfidence = this.observed.confirm(addr, options?.ttl ?? this.addressVerificationTTL) | ||
} | ||
if (options?.type === 'transport' || this.transportAddresses.has(addr)) { | ||
const transportStartingConfidence = this.transportAddresses.confirm(addr, options?.ttl ?? this.addressVerificationTTL) | ||
if (options?.type === 'transport' || this.transportAddresses.has(addr)) { | ||
startingConfidence = this.transportAddresses.confirm(addr, options?.ttl ?? this.addressVerificationTTL) | ||
if (!transportStartingConfidence && startingConfidence) { | ||
startingConfidence = false | ||
} | ||
} | ||
if (options?.type === 'dns-mapping' || this.dnsMappings.has(addr)) { | ||
startingConfidence = this.dnsMappings.confirm(addr, options?.ttl ?? this.addressVerificationTTL) | ||
const dnsMapingStartingConfidence = this.dnsMappings.confirm(addr, options?.ttl ?? this.addressVerificationTTL) | ||
if (!dnsMapingStartingConfidence && startingConfidence) { | ||
startingConfidence = false | ||
} | ||
} | ||
if (options?.type === 'ip-mapping' || this.ipMappings.has(addr)) { | ||
startingConfidence = this.ipMappings.confirm(addr, options?.ttl ?? this.addressVerificationTTL) | ||
const ipMapingStartingConfidence = this.ipMappings.confirm(addr, options?.ttl ?? this.addressVerificationTTL) | ||
if (!ipMapingStartingConfidence && startingConfidence) { | ||
startingConfidence = false | ||
} | ||
} | ||
if (options?.type === 'observed' || this.observed.has(addr)) { | ||
// try to match up observed address with local transport listener | ||
if (this.maybeUpgradeToIPMapping(addr)) { | ||
this.ipMappings.confirm(addr, options?.ttl ?? this.addressVerificationTTL) | ||
startingConfidence = false | ||
} else { | ||
const observedStartingConfidence = this.observed.confirm(addr, options?.ttl ?? this.addressVerificationTTL) | ||
if (!observedStartingConfidence && startingConfidence) { | ||
startingConfidence = false | ||
} | ||
} | ||
} | ||
// only trigger the 'self:peer:update' event if our confidence in an address has changed | ||
@@ -282,15 +306,31 @@ if (!startingConfidence) { | ||
if (this.observed.has(addr)) { | ||
startingConfidence = this.observed.remove(addr) | ||
const observedStartingConfidence = this.observed.remove(addr) | ||
if (!observedStartingConfidence && startingConfidence) { | ||
startingConfidence = false | ||
} | ||
} | ||
if (this.transportAddresses.has(addr)) { | ||
startingConfidence = this.transportAddresses.unconfirm(addr, options?.ttl ?? this.addressVerificationRetry) | ||
const transportStartingConfidence = this.transportAddresses.unconfirm(addr, options?.ttl ?? this.addressVerificationRetry) | ||
if (!transportStartingConfidence && startingConfidence) { | ||
startingConfidence = false | ||
} | ||
} | ||
if (this.dnsMappings.has(addr)) { | ||
startingConfidence = this.dnsMappings.unconfirm(addr, options?.ttl ?? this.addressVerificationRetry) | ||
const dnsMapingStartingConfidence = this.dnsMappings.unconfirm(addr, options?.ttl ?? this.addressVerificationRetry) | ||
if (!dnsMapingStartingConfidence && startingConfidence) { | ||
startingConfidence = false | ||
} | ||
} | ||
if (this.ipMappings.has(addr)) { | ||
startingConfidence = this.ipMappings.unconfirm(addr, options?.ttl ?? this.addressVerificationRetry) | ||
const ipMapingStartingConfidence = this.ipMappings.unconfirm(addr, options?.ttl ?? this.addressVerificationRetry) | ||
if (!ipMapingStartingConfidence && startingConfidence) { | ||
startingConfidence = false | ||
} | ||
} | ||
@@ -416,2 +456,80 @@ | ||
} | ||
/** | ||
* Where an external service (router, gateway, etc) is forwarding traffic to | ||
* us, attempt to add an IP mapping for the external address - this will | ||
* include the observed mapping in the address list where we also have a DNS | ||
* mapping for the external IP. | ||
* | ||
* Returns true if we added a new mapping | ||
*/ | ||
private maybeUpgradeToIPMapping (ma: Multiaddr): boolean { | ||
// this address is already mapped | ||
if (this.ipMappings.has(ma)) { | ||
return false | ||
} | ||
const maOptions = ma.toOptions() | ||
// only public IPv4 addresses | ||
if (maOptions.family === 6 || maOptions.host === '127.0.0.1' || isPrivateIp(maOptions.host) === true) { | ||
return false | ||
} | ||
const listeners = this.components.transportManager.getListeners() | ||
const transportMatchers: Array<(ma: Multiaddr) => boolean> = [ | ||
(ma: Multiaddr) => WebSockets.exactMatch(ma) || WebSocketsSecure.exactMatch(ma), | ||
(ma: Multiaddr) => TCP.exactMatch(ma), | ||
(ma: Multiaddr) => QUICV1.exactMatch(ma) | ||
] | ||
for (const matcher of transportMatchers) { | ||
// is the incoming address the same type as the matcher | ||
if (!matcher(ma)) { | ||
continue | ||
} | ||
// get the listeners for this transport | ||
const transportListeners = listeners.filter(listener => { | ||
return listener.getAddrs().filter(ma => { | ||
// only IPv4 addresses of the matcher type | ||
return ma.toOptions().family === 4 && matcher(ma) | ||
}).length > 0 | ||
}) | ||
// because the NAT mapping could be forwarding different external ports to | ||
// internal ones, we can only be sure enough to add a mapping if there is | ||
// a single listener | ||
if (transportListeners.length !== 1) { | ||
continue | ||
} | ||
// we have one listener which listens on one port so whatever the external | ||
// NAT port mapping is, it should be for this listener | ||
const linkLocalAddr = transportListeners[0].getAddrs().filter(ma => { | ||
return ma.toOptions().host !== '127.0.0.1' | ||
}).pop() | ||
if (linkLocalAddr == null) { | ||
continue | ||
} | ||
const linkLocalOptions = linkLocalAddr.toOptions() | ||
// upgrade observed address to IP mapping | ||
this.observed.remove(ma) | ||
this.ipMappings.add( | ||
linkLocalOptions.host, | ||
linkLocalOptions.port, | ||
maOptions.host, | ||
maOptions.port, | ||
maOptions.transport | ||
) | ||
return true | ||
} | ||
return false | ||
} | ||
} |
@@ -53,3 +53,3 @@ /** | ||
*/ | ||
nodeInfo?: NodeInfo | ||
nodeInfo?: Partial<NodeInfo> | ||
@@ -56,0 +56,0 @@ /** |
@@ -19,10 +19,10 @@ import { publicKeyFromProtobuf } from '@libp2p/crypto/keys' | ||
import { RandomWalk } from './random-walk.js' | ||
import { DefaultRegistrar } from './registrar.js' | ||
import { Registrar } from './registrar.js' | ||
import { DefaultTransportManager } from './transport-manager.js' | ||
import { DefaultUpgrader } from './upgrader.js' | ||
import { userAgent } from './user-agent.js' | ||
import * as pkg from './version.js' | ||
import type { Components } from './components.js' | ||
import type { Libp2p as Libp2pInterface, Libp2pInit } from './index.js' | ||
import type { PeerRouting, ContentRouting, Libp2pEvents, PendingDial, ServiceMap, AbortOptions, ComponentLogger, Logger, Connection, NewStreamOptions, Stream, Metrics, PeerId, PeerInfo, PeerStore, Topology, Libp2pStatus, IsDialableOptions, DialOptions, PublicKey, Ed25519PeerId, Secp256k1PeerId, RSAPublicKey, RSAPeerId, URLPeerId, Ed25519PublicKey, Secp256k1PublicKey } from '@libp2p/interface' | ||
import type { StreamHandler, StreamHandlerOptions } from '@libp2p/interface-internal' | ||
import type { PeerRouting, ContentRouting, Libp2pEvents, PendingDial, ServiceMap, AbortOptions, ComponentLogger, Logger, Connection, NewStreamOptions, Stream, Metrics, PeerId, PeerInfo, PeerStore, Topology, Libp2pStatus, IsDialableOptions, DialOptions, PublicKey, Ed25519PeerId, Secp256k1PeerId, RSAPublicKey, RSAPeerId, URLPeerId, Ed25519PublicKey, Secp256k1PublicKey, StreamHandler, StreamHandlerOptions } from '@libp2p/interface' | ||
@@ -68,2 +68,6 @@ export class Libp2p<T extends ServiceMap = ServiceMap> extends TypedEventEmitter<Libp2pEvents> implements Libp2pInterface<T> { | ||
this.services = {} | ||
const nodeInfoName = init.nodeInfo?.name ?? pkg.name | ||
const nodeInfoVersion = init.nodeInfo?.version ?? pkg.name | ||
// @ts-expect-error defaultComponents is missing component types added later | ||
@@ -73,5 +77,6 @@ const components = this.components = defaultComponents({ | ||
privateKey: init.privateKey, | ||
nodeInfo: init.nodeInfo ?? { | ||
name: pkg.name, | ||
version: pkg.version | ||
nodeInfo: { | ||
name: nodeInfoName, | ||
version: nodeInfoVersion, | ||
userAgent: init.nodeInfo?.userAgent ?? userAgent(nodeInfoName, nodeInfoVersion) | ||
}, | ||
@@ -132,3 +137,3 @@ logger: this.logger, | ||
// Create the Registrar | ||
this.configureComponent('registrar', new DefaultRegistrar(this.components)) | ||
this.configureComponent('registrar', new Registrar(this.components)) | ||
@@ -135,0 +140,0 @@ // Addresses {listen, announce, noAnnounce} |
import { InvalidParametersError } from '@libp2p/interface' | ||
import merge from 'merge-options' | ||
import * as errorsJs from './errors.js' | ||
import type { IdentifyResult, Libp2pEvents, Logger, PeerUpdate, TypedEventTarget, PeerId, PeerStore, Topology } from '@libp2p/interface' | ||
import type { StreamHandlerOptions, StreamHandlerRecord, Registrar, StreamHandler } from '@libp2p/interface-internal' | ||
import type { IdentifyResult, Libp2pEvents, Logger, PeerUpdate, TypedEventTarget, PeerId, PeerStore, Topology, StreamHandlerRecord, StreamHandlerOptions } from '@libp2p/interface' | ||
import type { Registrar as RegistrarInterface, StreamHandler } from '@libp2p/interface-internal' | ||
import type { ComponentLogger } from '@libp2p/logger' | ||
@@ -21,3 +21,3 @@ | ||
*/ | ||
export class DefaultRegistrar implements Registrar { | ||
export class Registrar implements RegistrarInterface { | ||
private readonly log: Logger | ||
@@ -77,3 +77,3 @@ private readonly topologies: Map<string, Map<string, Topology>> | ||
async handle (protocol: string, handler: StreamHandler, opts?: StreamHandlerOptions): Promise<void> { | ||
if (this.handlers.has(protocol)) { | ||
if (this.handlers.has(protocol) && opts?.force !== true) { | ||
throw new errorsJs.DuplicateProtocolHandlerError(`Handler already registered for protocol ${protocol}`) | ||
@@ -80,0 +80,0 @@ } |
@@ -1,2 +0,2 @@ | ||
export const version = '2.5.2' | ||
export const version = '2.6.0' | ||
export const name = 'js-libp2p' |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
992453
174
12375
15
Updated@libp2p/crypto@^5.0.11
Updated@libp2p/interface@^2.5.0
Updated@libp2p/logger@^5.1.8
Updated@libp2p/peer-id@^5.0.12
Updated@libp2p/peer-store@^11.0.17
Updated@libp2p/utils@^6.5.1