Comparing version 2.7.2 to 2.7.3
@@ -158,4 +158,4 @@ /* eslint-disable complexity */ | ||
if (options?.type === 'dns-mapping' || this.dnsMappings.has(addr)) { | ||
const dnsMapingStartingConfidence = this.dnsMappings.confirm(addr, options?.ttl ?? this.addressVerificationTTL); | ||
if (!dnsMapingStartingConfidence && startingConfidence) { | ||
const dnsMappingStartingConfidence = this.dnsMappings.confirm(addr, options?.ttl ?? this.addressVerificationTTL); | ||
if (!dnsMappingStartingConfidence && startingConfidence) { | ||
startingConfidence = false; | ||
@@ -165,4 +165,4 @@ } | ||
if (options?.type === 'ip-mapping' || this.ipMappings.has(addr)) { | ||
const ipMapingStartingConfidence = this.ipMappings.confirm(addr, options?.ttl ?? this.addressVerificationTTL); | ||
if (!ipMapingStartingConfidence && startingConfidence) { | ||
const ipMappingStartingConfidence = this.ipMappings.confirm(addr, options?.ttl ?? this.addressVerificationTTL); | ||
if (!ipMappingStartingConfidence && startingConfidence) { | ||
startingConfidence = false; | ||
@@ -205,4 +205,4 @@ } | ||
if (this.dnsMappings.has(addr)) { | ||
const dnsMapingStartingConfidence = this.dnsMappings.unconfirm(addr, options?.ttl ?? this.addressVerificationRetry); | ||
if (!dnsMapingStartingConfidence && startingConfidence) { | ||
const dnsMappingStartingConfidence = this.dnsMappings.unconfirm(addr, options?.ttl ?? this.addressVerificationRetry); | ||
if (!dnsMappingStartingConfidence && startingConfidence) { | ||
startingConfidence = false; | ||
@@ -212,4 +212,4 @@ } | ||
if (this.ipMappings.has(addr)) { | ||
const ipMapingStartingConfidence = this.ipMappings.unconfirm(addr, options?.ttl ?? this.addressVerificationRetry); | ||
if (!ipMapingStartingConfidence && startingConfidence) { | ||
const ipMappingStartingConfidence = this.ipMappings.unconfirm(addr, options?.ttl ?? this.addressVerificationRetry); | ||
if (!ipMappingStartingConfidence && startingConfidence) { | ||
startingConfidence = false; | ||
@@ -216,0 +216,0 @@ } |
@@ -7,3 +7,3 @@ import type { ConnectionGater } from '@libp2p/interface'; | ||
* Browsers are severely limited in their resource usage so don't waste time | ||
* trying to dial undiallable addresses, and they also print verbose error | ||
* trying to dial undialable addresses, and they also print verbose error | ||
* messages when making connections over insecure transports which causes | ||
@@ -10,0 +10,0 @@ * confusion. |
@@ -10,3 +10,3 @@ import { isPrivateIp } from '@libp2p/utils/private-ip'; | ||
* Browsers are severely limited in their resource usage so don't waste time | ||
* trying to dial undiallable addresses, and they also print verbose error | ||
* trying to dial undialable addresses, and they also print verbose error | ||
* messages when making connections over insecure transports which causes | ||
@@ -13,0 +13,0 @@ * confusion. |
@@ -12,8 +12,8 @@ import { isLoopback } from '@libp2p/utils/multiaddr/is-loopback'; | ||
export function reliableTransportsFirst(a, b) { | ||
const isATCP = TCP.exactMatch(a.multiaddr); | ||
const isBTCP = TCP.exactMatch(b.multiaddr); | ||
if (isATCP && !isBTCP) { | ||
const isATcp = TCP.exactMatch(a.multiaddr); | ||
const isBTcp = TCP.exactMatch(b.multiaddr); | ||
if (isATcp && !isBTcp) { | ||
return -1; | ||
} | ||
if (!isATCP && isBTCP) { | ||
if (!isATcp && isBTcp) { | ||
return 1; | ||
@@ -20,0 +20,0 @@ } |
/** | ||
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#dialTimeout | ||
*/ | ||
export declare const DIAL_TIMEOUT = 5000; | ||
export declare const DIAL_TIMEOUT = 10000; | ||
/** | ||
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#upgradeTimeout | ||
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#inboundUpgradeTimeout | ||
*/ | ||
export declare const UPGRADE_TIMEOUT = 3000; | ||
export declare const INBOUND_UPGRADE_TIMEOUT = 10000; | ||
/** | ||
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#protocolNegotiationTimeout | ||
*/ | ||
export declare const PROTOCOL_NEGOTIATION_TIMEOUT = 2000; | ||
export declare const PROTOCOL_NEGOTIATION_TIMEOUT = 10000; | ||
/** | ||
@@ -14,0 +14,0 @@ * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxPeerAddrsToDial |
/** | ||
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#dialTimeout | ||
*/ | ||
export const DIAL_TIMEOUT = 5e3; | ||
export const DIAL_TIMEOUT = 10_000; | ||
/** | ||
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#upgradeTimeout | ||
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#inboundUpgradeTimeout | ||
*/ | ||
export const UPGRADE_TIMEOUT = 3e3; | ||
export const INBOUND_UPGRADE_TIMEOUT = 10_000; | ||
/** | ||
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#protocolNegotiationTimeout | ||
*/ | ||
export const PROTOCOL_NEGOTIATION_TIMEOUT = 2e3; | ||
export const PROTOCOL_NEGOTIATION_TIMEOUT = 10_000; | ||
/** | ||
@@ -14,0 +14,0 @@ * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxPeerAddrsToDial |
@@ -149,3 +149,3 @@ /* eslint-disable max-depth */ | ||
// load addresses from address book, resolve and dnsaddrs, filter | ||
// undiallables, add peer IDs, etc | ||
// undialables, add peer IDs, etc | ||
addrsToDial = await this.calculateMultiaddrs(peerId, options?.multiaddrs, { | ||
@@ -348,3 +348,3 @@ ...options, | ||
} | ||
const gatedAdrs = []; | ||
const gatedAddrs = []; | ||
for (const addr of dedupedMultiaddrs) { | ||
@@ -354,5 +354,5 @@ if (this.components.connectionGater.denyDialMultiaddr != null && await this.components.connectionGater.denyDialMultiaddr(addr.multiaddr)) { | ||
} | ||
gatedAdrs.push(addr); | ||
gatedAddrs.push(addr); | ||
} | ||
const sortedGatedAddrs = this.addressSorter == null ? defaultAddressSorter(gatedAdrs) : gatedAdrs.sort(this.addressSorter); | ||
const sortedGatedAddrs = this.addressSorter == null ? defaultAddressSorter(gatedAddrs) : gatedAddrs.sort(this.addressSorter); | ||
// make sure we actually have some addresses to dial | ||
@@ -359,0 +359,0 @@ if (sortedGatedAddrs.length === 0) { |
@@ -46,3 +46,3 @@ import { PeerMap } from '@libp2p/peer-collections'; | ||
* | ||
* @default 5000 | ||
* @default 10_000 | ||
*/ | ||
@@ -54,3 +54,3 @@ dialTimeout?: number; | ||
* | ||
* @default 3000 | ||
* @default 10_000 | ||
*/ | ||
@@ -64,3 +64,3 @@ inboundUpgradeTimeout?: number; | ||
* | ||
* @default 3000 | ||
* @deprecated This is handled by `dialTimeout` | ||
*/ | ||
@@ -78,5 +78,7 @@ outboundUpgradeTimeout?: number; | ||
* | ||
* Does not apply if an abort signal is passed to the `.dial` method. | ||
* Does not apply if an abort signal is passed to the `.dial` or | ||
* `.dialProtocol` method of the `ConnectionManager` or the `openStream` | ||
* method of the `Connection`. | ||
* | ||
* @default 2000 | ||
* @default 10_000 | ||
*/ | ||
@@ -87,3 +89,3 @@ outboundStreamProtocolNegotiationTimeout?: number; | ||
* | ||
* @default 2000 | ||
* @default 10_000 | ||
*/ | ||
@@ -90,0 +92,0 @@ inboundStreamProtocolNegotiationTimeout?: number; |
@@ -32,2 +32,5 @@ export declare enum messages { | ||
} | ||
export declare class NoSupportedAddressesError extends Error { | ||
constructor(message?: string); | ||
} | ||
export declare class ConnectionInterceptedError extends Error { | ||
@@ -34,0 +37,0 @@ constructor(message?: string); |
@@ -60,2 +60,8 @@ export var messages; | ||
} | ||
export class NoSupportedAddressesError extends Error { | ||
constructor(message = 'No supported addresses') { | ||
super(message); | ||
this.name = 'NoSupportedAddressesError'; | ||
} | ||
} | ||
export class ConnectionInterceptedError extends Error { | ||
@@ -62,0 +68,0 @@ constructor(message = 'Connection intercepted') { |
@@ -86,3 +86,3 @@ /** | ||
* Connection encrypters ensure that data sent over connections cannot be | ||
* eavesdropped on, and that the remote peer posesses the private key that | ||
* 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. | ||
@@ -89,0 +89,0 @@ */ |
@@ -21,3 +21,3 @@ import { publicKeyFromProtobuf } from '@libp2p/crypto/keys'; | ||
import { DefaultTransportManager } from './transport-manager.js'; | ||
import { DefaultUpgrader } from './upgrader.js'; | ||
import { Upgrader } from './upgrader.js'; | ||
import { userAgent } from './user-agent.js'; | ||
@@ -96,7 +96,6 @@ import * as pkg from './version.js'; | ||
// Set up the Upgrader | ||
this.components.upgrader = new DefaultUpgrader(this.components, { | ||
this.components.upgrader = new Upgrader(this.components, { | ||
connectionEncrypters: (init.connectionEncrypters ?? []).map((fn, index) => this.configureComponent(`connection-encryption-${index}`, fn(this.components))), | ||
streamMuxers: (init.streamMuxers ?? []).map((fn, index) => this.configureComponent(`stream-muxers-${index}`, fn(this.components))), | ||
inboundUpgradeTimeout: init.connectionManager?.inboundUpgradeTimeout, | ||
outboundUpgradeTimeout: init.connectionManager?.outboundUpgradeTimeout, | ||
inboundStreamProtocolNegotiationTimeout: init.connectionManager?.inboundStreamProtocolNegotiationTimeout ?? init.connectionManager?.protocolNegotiationTimeout, | ||
@@ -103,0 +102,0 @@ outboundStreamProtocolNegotiationTimeout: init.connectionManager?.outboundStreamProtocolNegotiationTimeout ?? init.connectionManager?.protocolNegotiationTimeout |
@@ -101,3 +101,3 @@ import { randomBytes } from '@libp2p/crypto'; | ||
catch (err) { | ||
this.log.error('randomwalk errored', err); | ||
this.log.error('random walk errored', err); | ||
this.safeDispatchEvent('walk:error', { | ||
@@ -111,3 +111,3 @@ detail: err | ||
.catch(err => { | ||
this.log.error('randomwalk errored', err); | ||
this.log.error('random walk errored', err); | ||
}) | ||
@@ -114,0 +114,0 @@ .finally(() => { |
@@ -1,2 +0,2 @@ | ||
import type { Libp2pEvents, AbortOptions, ComponentLogger, MultiaddrConnection, Connection, Stream, ConnectionProtector, ConnectionEncrypter, SecuredConnection, ConnectionGater, TypedEventTarget, Metrics, PeerId, PeerStore, StreamMuxerFactory, Upgrader, UpgraderOptions, ConnectionLimits, SecureConnectionOptions } from '@libp2p/interface'; | ||
import type { Libp2pEvents, AbortOptions, ComponentLogger, MultiaddrConnection, Connection, Stream, ConnectionProtector, ConnectionEncrypter, SecuredConnection, ConnectionGater, TypedEventTarget, Metrics, PeerId, PeerStore, StreamMuxerFactory, Upgrader as UpgraderInterface, UpgraderOptions, ConnectionLimits, SecureConnectionOptions, ClearableSignal } from '@libp2p/interface'; | ||
import type { ConnectionManager, Registrar } from '@libp2p/interface-internal'; | ||
@@ -30,8 +30,2 @@ interface CreateConnectionOptions { | ||
/** | ||
* An amount of ms by which an outbound connection upgrade must complete | ||
* | ||
* @default 3000 | ||
*/ | ||
outboundUpgradeTimeout?: number; | ||
/** | ||
* When a new incoming stream is opened on a multiplexed connection, protocol | ||
@@ -63,3 +57,3 @@ * negotiation on that stream must complete within this many ms | ||
type ConnectionDeniedType = keyof Pick<ConnectionGater, 'denyOutboundConnection' | 'denyInboundEncryptedConnection' | 'denyOutboundEncryptedConnection' | 'denyInboundUpgradedConnection' | 'denyOutboundUpgradedConnection'>; | ||
export declare class DefaultUpgrader implements Upgrader { | ||
export declare class Upgrader implements UpgraderInterface { | ||
private readonly components; | ||
@@ -69,3 +63,2 @@ private readonly connectionEncrypters; | ||
private readonly inboundUpgradeTimeout; | ||
private readonly outboundUpgradeTimeout; | ||
private readonly inboundStreamProtocolNegotiationTimeout; | ||
@@ -79,10 +72,11 @@ private readonly outboundStreamProtocolNegotiationTimeout; | ||
shouldBlockConnection(connectionType: ConnectionDeniedType, remotePeer: PeerId, maConn: MultiaddrConnection): Promise<void>; | ||
createInboundAbortSignal(signal: AbortSignal): ClearableSignal; | ||
/** | ||
* Upgrades an inbound connection | ||
*/ | ||
upgradeInbound(maConn: MultiaddrConnection, opts?: UpgraderOptions): Promise<void>; | ||
upgradeInbound(maConn: MultiaddrConnection, opts: UpgraderOptions): Promise<void>; | ||
/** | ||
* Upgrades an outbound connection | ||
*/ | ||
upgradeOutbound(maConn: MultiaddrConnection, opts?: UpgraderOptions): Promise<Connection>; | ||
upgradeOutbound(maConn: MultiaddrConnection, opts: UpgraderOptions): Promise<Connection>; | ||
private _performUpgrade; | ||
@@ -89,0 +83,0 @@ /** |
import { InvalidMultiaddrError, TooManyInboundProtocolStreamsError, TooManyOutboundProtocolStreamsError, LimitedConnectionError, setMaxListeners, InvalidPeerIdError } from '@libp2p/interface'; | ||
import * as mss from '@libp2p/multistream-select'; | ||
import { peerIdFromString } from '@libp2p/peer-id'; | ||
import { anySignal } from 'any-signal'; | ||
import { CustomProgressEvent } from 'progress-events'; | ||
import { createConnection } from './connection/index.js'; | ||
import { PROTOCOL_NEGOTIATION_TIMEOUT, UPGRADE_TIMEOUT } from './connection-manager/constants.js'; | ||
import { PROTOCOL_NEGOTIATION_TIMEOUT, INBOUND_UPGRADE_TIMEOUT } from './connection-manager/constants.js'; | ||
import { ConnectionDeniedError, ConnectionInterceptedError, EncryptionFailedError, MuxerUnavailableError } from './errors.js'; | ||
@@ -44,3 +45,3 @@ import { DEFAULT_MAX_INBOUND_STREAMS, DEFAULT_MAX_OUTBOUND_STREAMS } from './registrar.js'; | ||
} | ||
export class DefaultUpgrader { | ||
export class Upgrader { | ||
components; | ||
@@ -50,3 +51,2 @@ connectionEncrypters; | ||
inboundUpgradeTimeout; | ||
outboundUpgradeTimeout; | ||
inboundStreamProtocolNegotiationTimeout; | ||
@@ -66,4 +66,3 @@ outboundStreamProtocolNegotiationTimeout; | ||
}); | ||
this.inboundUpgradeTimeout = init.inboundUpgradeTimeout ?? UPGRADE_TIMEOUT; | ||
this.outboundUpgradeTimeout = init.outboundUpgradeTimeout ?? UPGRADE_TIMEOUT; | ||
this.inboundUpgradeTimeout = init.inboundUpgradeTimeout ?? INBOUND_UPGRADE_TIMEOUT; | ||
this.inboundStreamProtocolNegotiationTimeout = init.inboundStreamProtocolNegotiationTimeout ?? PROTOCOL_NEGOTIATION_TIMEOUT; | ||
@@ -88,7 +87,17 @@ this.outboundStreamProtocolNegotiationTimeout = init.outboundStreamProtocolNegotiationTimeout ?? PROTOCOL_NEGOTIATION_TIMEOUT; | ||
} | ||
createInboundAbortSignal(signal) { | ||
const output = anySignal([ | ||
AbortSignal.timeout(this.inboundUpgradeTimeout), | ||
signal | ||
]); | ||
setMaxListeners(Infinity, output); | ||
return output; | ||
} | ||
/** | ||
* Upgrades an inbound connection | ||
*/ | ||
async upgradeInbound(maConn, opts = {}) { | ||
async upgradeInbound(maConn, opts) { | ||
let accepted = false; | ||
// always apply upgrade timeout for incoming upgrades | ||
const signal = this.createInboundAbortSignal(opts.signal); | ||
try { | ||
@@ -103,3 +112,6 @@ this.metrics.dials?.increment({ | ||
await this.shouldBlockConnection('denyInboundConnection', maConn); | ||
await this._performUpgrade(maConn, 'inbound', opts); | ||
await this._performUpgrade(maConn, 'inbound', { | ||
...opts, | ||
signal | ||
}); | ||
} | ||
@@ -113,2 +125,3 @@ catch (err) { | ||
finally { | ||
signal.clear(); | ||
if (accepted) { | ||
@@ -122,3 +135,3 @@ this.components.connectionManager.afterUpgradeInbound(); | ||
*/ | ||
async upgradeOutbound(maConn, opts = {}) { | ||
async upgradeOutbound(maConn, opts) { | ||
try { | ||
@@ -154,8 +167,2 @@ this.metrics.dials?.increment({ | ||
let cryptoProtocol; | ||
if (opts.signal == null) { | ||
maConn.log('no abort signal was passed while trying to upgrade connection, falling back to default timeout'); | ||
const upgradeTimeoutSignal = AbortSignal.timeout(direction === 'inbound' ? this.inboundUpgradeTimeout : this.outboundUpgradeTimeout); | ||
setMaxListeners(Infinity, upgradeTimeoutSignal); | ||
opts.signal = upgradeTimeoutSignal; | ||
} | ||
this.components.metrics?.trackMultiaddrConnection(maConn); | ||
@@ -281,3 +288,3 @@ maConn.log.trace('starting the %s connection upgrade', direction); | ||
// after the handshake the returned stream can have early data so override | ||
// the souce/sink | ||
// the source/sink | ||
muxedStream.source = stream.source; | ||
@@ -299,3 +306,3 @@ muxedStream.sink = stream.sink; | ||
// If a protocol stream has been successfully negotiated and is to be passed to the application, | ||
// the peerstore should ensure that the peer is registered with that protocol | ||
// the peer store should ensure that the peer is registered with that protocol | ||
await this.components.peerStore.merge(remotePeer, { | ||
@@ -347,3 +354,3 @@ protocols: [protocol] | ||
// If a protocol stream has been successfully negotiated and is to be passed to the application, | ||
// the peerstore should ensure that the peer is registered with that protocol | ||
// the peer store should ensure that the peer is registered with that protocol | ||
await this.components.peerStore.merge(remotePeer, { | ||
@@ -353,3 +360,3 @@ protocols: [protocol] | ||
// after the handshake the returned stream can have early data so override | ||
// the souce/sink | ||
// the source/sink | ||
muxedStream.source = stream.source; | ||
@@ -356,0 +363,0 @@ muxedStream.sink = stream.sink; |
@@ -1,3 +0,3 @@ | ||
export declare const version = "2.7.2"; | ||
export declare const version = "2.7.3"; | ||
export declare const name = "js-libp2p"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -1,3 +0,3 @@ | ||
export const version = '2.7.2'; | ||
export const version = '2.7.3'; | ||
export const name = 'js-libp2p'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "libp2p", | ||
"version": "2.7.2", | ||
"version": "2.7.3", | ||
"description": "JavaScript implementation of libp2p, a modular peer to peer network stack", | ||
@@ -95,11 +95,11 @@ "license": "Apache-2.0 OR MIT", | ||
"@chainsafe/netmask": "^2.0.0", | ||
"@libp2p/crypto": "^5.0.12", | ||
"@libp2p/interface": "^2.6.0", | ||
"@libp2p/interface-internal": "^2.3.4", | ||
"@libp2p/logger": "^5.1.9", | ||
"@libp2p/multistream-select": "^6.0.16", | ||
"@libp2p/peer-collections": "^6.0.20", | ||
"@libp2p/peer-id": "^5.0.13", | ||
"@libp2p/peer-store": "^11.0.20", | ||
"@libp2p/utils": "^6.5.4", | ||
"@libp2p/crypto": "^5.0.13", | ||
"@libp2p/interface": "^2.6.1", | ||
"@libp2p/interface-internal": "^2.3.5", | ||
"@libp2p/logger": "^5.1.10", | ||
"@libp2p/multistream-select": "^6.0.17", | ||
"@libp2p/peer-collections": "^6.0.21", | ||
"@libp2p/peer-id": "^5.0.14", | ||
"@libp2p/peer-store": "^11.0.21", | ||
"@libp2p/utils": "^6.5.5", | ||
"@multiformats/dns": "^1.0.6", | ||
@@ -124,3 +124,3 @@ "@multiformats/multiaddr": "^12.3.5", | ||
"devDependencies": { | ||
"aegir": "^45.0.5", | ||
"aegir": "^45.1.1", | ||
"delay": "^6.0.0", | ||
@@ -127,0 +127,0 @@ "it-all": "^3.0.6", |
@@ -30,3 +30,3 @@ <h1 align="center"> | ||
To sum up, libp2p is a "network stack" -- a protocol suite -- that cleanly separates concerns, and enables sophisticated applications to only use the protocols they absolutely need, without giving up interoperability and upgradeability. libp2p grew out of IPFS, but it is built so that lots of people can use it, for lots of different projects. | ||
To sum up, libp2p is a "network stack" -- a protocol suite -- that cleanly separates concerns, and enables sophisticated applications to only use the protocols they absolutely need, without giving up interoperability and upgradability. libp2p grew out of IPFS, but it is built so that lots of people can use it, for lots of different projects. | ||
@@ -73,3 +73,3 @@ # Roadmap | ||
```sh | ||
# run all the unit tsts | ||
# run all the unit tests | ||
> npm test | ||
@@ -147,3 +147,3 @@ | ||
- Go through the modules and **check out existing issues**. This would be especially useful for modules in active development. Some knowledge of IPFS/libp2p may be required, as well as the infrastructure behind it - for instance, you may need to read up on p2p and more complex operations like muxing to be able to help technically. | ||
- **Perform code reviews**. Most of this has been developed by @diasdavid, which means that more eyes will help a) speed the project along b) ensure quality and c) reduce possible future bugs. | ||
- **Perform code reviews**. More eyes will help a) speed the project along b) ensure quality and c) reduce possible future bugs. | ||
- **Add tests**. There can never be enough tests. | ||
@@ -150,0 +150,0 @@ |
@@ -263,5 +263,5 @@ /* eslint-disable complexity */ | ||
if (options?.type === 'dns-mapping' || this.dnsMappings.has(addr)) { | ||
const dnsMapingStartingConfidence = this.dnsMappings.confirm(addr, options?.ttl ?? this.addressVerificationTTL) | ||
const dnsMappingStartingConfidence = this.dnsMappings.confirm(addr, options?.ttl ?? this.addressVerificationTTL) | ||
if (!dnsMapingStartingConfidence && startingConfidence) { | ||
if (!dnsMappingStartingConfidence && startingConfidence) { | ||
startingConfidence = false | ||
@@ -272,5 +272,5 @@ } | ||
if (options?.type === 'ip-mapping' || this.ipMappings.has(addr)) { | ||
const ipMapingStartingConfidence = this.ipMappings.confirm(addr, options?.ttl ?? this.addressVerificationTTL) | ||
const ipMappingStartingConfidence = this.ipMappings.confirm(addr, options?.ttl ?? this.addressVerificationTTL) | ||
if (!ipMapingStartingConfidence && startingConfidence) { | ||
if (!ipMappingStartingConfidence && startingConfidence) { | ||
startingConfidence = false | ||
@@ -322,5 +322,5 @@ } | ||
if (this.dnsMappings.has(addr)) { | ||
const dnsMapingStartingConfidence = this.dnsMappings.unconfirm(addr, options?.ttl ?? this.addressVerificationRetry) | ||
const dnsMappingStartingConfidence = this.dnsMappings.unconfirm(addr, options?.ttl ?? this.addressVerificationRetry) | ||
if (!dnsMapingStartingConfidence && startingConfidence) { | ||
if (!dnsMappingStartingConfidence && startingConfidence) { | ||
startingConfidence = false | ||
@@ -331,5 +331,5 @@ } | ||
if (this.ipMappings.has(addr)) { | ||
const ipMapingStartingConfidence = this.ipMappings.unconfirm(addr, options?.ttl ?? this.addressVerificationRetry) | ||
const ipMappingStartingConfidence = this.ipMappings.unconfirm(addr, options?.ttl ?? this.addressVerificationRetry) | ||
if (!ipMapingStartingConfidence && startingConfidence) { | ||
if (!ipMappingStartingConfidence && startingConfidence) { | ||
startingConfidence = false | ||
@@ -336,0 +336,0 @@ } |
@@ -14,3 +14,3 @@ import { isPrivateIp } from '@libp2p/utils/private-ip' | ||
* Browsers are severely limited in their resource usage so don't waste time | ||
* trying to dial undiallable addresses, and they also print verbose error | ||
* trying to dial undialable addresses, and they also print verbose error | ||
* messages when making connections over insecure transports which causes | ||
@@ -17,0 +17,0 @@ * confusion. |
@@ -14,10 +14,10 @@ import { isLoopback } from '@libp2p/utils/multiaddr/is-loopback' | ||
export function reliableTransportsFirst (a: Address, b: Address): -1 | 0 | 1 { | ||
const isATCP = TCP.exactMatch(a.multiaddr) | ||
const isBTCP = TCP.exactMatch(b.multiaddr) | ||
const isATcp = TCP.exactMatch(a.multiaddr) | ||
const isBTcp = TCP.exactMatch(b.multiaddr) | ||
if (isATCP && !isBTCP) { | ||
if (isATcp && !isBTcp) { | ||
return -1 | ||
} | ||
if (!isATCP && isBTCP) { | ||
if (!isATcp && isBTcp) { | ||
return 1 | ||
@@ -24,0 +24,0 @@ } |
/** | ||
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#dialTimeout | ||
*/ | ||
export const DIAL_TIMEOUT = 5e3 | ||
export const DIAL_TIMEOUT = 10_000 | ||
/** | ||
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#upgradeTimeout | ||
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#inboundUpgradeTimeout | ||
*/ | ||
export const UPGRADE_TIMEOUT = 3e3 | ||
export const INBOUND_UPGRADE_TIMEOUT = 10_000 | ||
@@ -14,3 +14,3 @@ /** | ||
*/ | ||
export const PROTOCOL_NEGOTIATION_TIMEOUT = 2e3 | ||
export const PROTOCOL_NEGOTIATION_TIMEOUT = 10_000 | ||
@@ -17,0 +17,0 @@ /** |
@@ -219,3 +219,3 @@ /* eslint-disable max-depth */ | ||
// load addresses from address book, resolve and dnsaddrs, filter | ||
// undiallables, add peer IDs, etc | ||
// undialables, add peer IDs, etc | ||
addrsToDial = await this.calculateMultiaddrs(peerId, options?.multiaddrs, { | ||
@@ -453,3 +453,3 @@ ...options, | ||
const gatedAdrs: Address[] = [] | ||
const gatedAddrs: Address[] = [] | ||
@@ -461,6 +461,6 @@ for (const addr of dedupedMultiaddrs) { | ||
gatedAdrs.push(addr) | ||
gatedAddrs.push(addr) | ||
} | ||
const sortedGatedAddrs = this.addressSorter == null ? defaultAddressSorter(gatedAdrs) : gatedAdrs.sort(this.addressSorter) | ||
const sortedGatedAddrs = this.addressSorter == null ? defaultAddressSorter(gatedAddrs) : gatedAddrs.sort(this.addressSorter) | ||
@@ -467,0 +467,0 @@ // make sure we actually have some addresses to dial |
@@ -62,3 +62,3 @@ import { ConnectionClosedError, InvalidMultiaddrError, InvalidParametersError, InvalidPeerIdError, NotStartedError, start, stop } from '@libp2p/interface' | ||
* | ||
* @default 5000 | ||
* @default 10_000 | ||
*/ | ||
@@ -71,3 +71,3 @@ dialTimeout?: number | ||
* | ||
* @default 3000 | ||
* @default 10_000 | ||
*/ | ||
@@ -82,3 +82,3 @@ inboundUpgradeTimeout?: number | ||
* | ||
* @default 3000 | ||
* @deprecated This is handled by `dialTimeout` | ||
*/ | ||
@@ -98,5 +98,7 @@ outboundUpgradeTimeout?: number | ||
* | ||
* Does not apply if an abort signal is passed to the `.dial` method. | ||
* Does not apply if an abort signal is passed to the `.dial` or | ||
* `.dialProtocol` method of the `ConnectionManager` or the `openStream` | ||
* method of the `Connection`. | ||
* | ||
* @default 2000 | ||
* @default 10_000 | ||
*/ | ||
@@ -108,3 +110,3 @@ outboundStreamProtocolNegotiationTimeout?: number | ||
* | ||
* @default 2000 | ||
* @default 10_000 | ||
*/ | ||
@@ -111,0 +113,0 @@ inboundStreamProtocolNegotiationTimeout?: number |
@@ -69,2 +69,9 @@ export enum messages { | ||
export class NoSupportedAddressesError extends Error { | ||
constructor (message = 'No supported addresses') { | ||
super(message) | ||
this.name = 'NoSupportedAddressesError' | ||
} | ||
} | ||
export class ConnectionInterceptedError extends Error { | ||
@@ -71,0 +78,0 @@ constructor (message = 'Connection intercepted') { |
@@ -105,3 +105,3 @@ /** | ||
* Connection encrypters ensure that data sent over connections cannot be | ||
* eavesdropped on, and that the remote peer posesses the private key that | ||
* 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. | ||
@@ -108,0 +108,0 @@ */ |
@@ -21,3 +21,3 @@ import { publicKeyFromProtobuf } from '@libp2p/crypto/keys' | ||
import { DefaultTransportManager } from './transport-manager.js' | ||
import { DefaultUpgrader } from './upgrader.js' | ||
import { Upgrader } from './upgrader.js' | ||
import { userAgent } from './user-agent.js' | ||
@@ -117,7 +117,6 @@ import * as pkg from './version.js' | ||
// Set up the Upgrader | ||
this.components.upgrader = new DefaultUpgrader(this.components, { | ||
this.components.upgrader = new Upgrader(this.components, { | ||
connectionEncrypters: (init.connectionEncrypters ?? []).map((fn, index) => this.configureComponent(`connection-encryption-${index}`, fn(this.components))), | ||
streamMuxers: (init.streamMuxers ?? []).map((fn, index) => this.configureComponent(`stream-muxers-${index}`, fn(this.components))), | ||
inboundUpgradeTimeout: init.connectionManager?.inboundUpgradeTimeout, | ||
outboundUpgradeTimeout: init.connectionManager?.outboundUpgradeTimeout, | ||
inboundStreamProtocolNegotiationTimeout: init.connectionManager?.inboundStreamProtocolNegotiationTimeout ?? init.connectionManager?.protocolNegotiationTimeout, | ||
@@ -124,0 +123,0 @@ outboundStreamProtocolNegotiationTimeout: init.connectionManager?.outboundStreamProtocolNegotiationTimeout ?? init.connectionManager?.protocolNegotiationTimeout |
@@ -136,3 +136,3 @@ import { randomBytes } from '@libp2p/crypto' | ||
} catch (err) { | ||
this.log.error('randomwalk errored', err) | ||
this.log.error('random walk errored', err) | ||
@@ -148,3 +148,3 @@ this.safeDispatchEvent('walk:error', { | ||
.catch(err => { | ||
this.log.error('randomwalk errored', err) | ||
this.log.error('random walk errored', err) | ||
}) | ||
@@ -151,0 +151,0 @@ .finally(() => { |
import { InvalidMultiaddrError, TooManyInboundProtocolStreamsError, TooManyOutboundProtocolStreamsError, LimitedConnectionError, setMaxListeners, InvalidPeerIdError } from '@libp2p/interface' | ||
import * as mss from '@libp2p/multistream-select' | ||
import { peerIdFromString } from '@libp2p/peer-id' | ||
import { anySignal } from 'any-signal' | ||
import { CustomProgressEvent } from 'progress-events' | ||
import { createConnection } from './connection/index.js' | ||
import { PROTOCOL_NEGOTIATION_TIMEOUT, UPGRADE_TIMEOUT } from './connection-manager/constants.js' | ||
import { PROTOCOL_NEGOTIATION_TIMEOUT, INBOUND_UPGRADE_TIMEOUT } from './connection-manager/constants.js' | ||
import { ConnectionDeniedError, ConnectionInterceptedError, EncryptionFailedError, MuxerUnavailableError } from './errors.js' | ||
import { DEFAULT_MAX_INBOUND_STREAMS, DEFAULT_MAX_OUTBOUND_STREAMS } from './registrar.js' | ||
import type { Libp2pEvents, AbortOptions, ComponentLogger, MultiaddrConnection, Connection, Stream, ConnectionProtector, NewStreamOptions, ConnectionEncrypter, SecuredConnection, ConnectionGater, TypedEventTarget, Metrics, PeerId, PeerStore, StreamMuxer, StreamMuxerFactory, Upgrader, UpgraderOptions, ConnectionLimits, SecureConnectionOptions, CounterGroup } from '@libp2p/interface' | ||
import type { Libp2pEvents, AbortOptions, ComponentLogger, MultiaddrConnection, Connection, Stream, ConnectionProtector, NewStreamOptions, ConnectionEncrypter, SecuredConnection, ConnectionGater, TypedEventTarget, Metrics, PeerId, PeerStore, StreamMuxer, StreamMuxerFactory, Upgrader as UpgraderInterface, UpgraderOptions, ConnectionLimits, SecureConnectionOptions, CounterGroup, ClearableSignal } from '@libp2p/interface' | ||
import type { ConnectionManager, Registrar } from '@libp2p/interface-internal' | ||
@@ -44,9 +45,2 @@ | ||
/** | ||
* An amount of ms by which an outbound connection upgrade must complete | ||
* | ||
* @default 3000 | ||
*/ | ||
outboundUpgradeTimeout?: number | ||
/** | ||
* When a new incoming stream is opened on a multiplexed connection, protocol | ||
@@ -124,3 +118,3 @@ * negotiation on that stream must complete within this many ms | ||
export class DefaultUpgrader implements Upgrader { | ||
export class Upgrader implements UpgraderInterface { | ||
private readonly components: DefaultUpgraderComponents | ||
@@ -130,3 +124,2 @@ private readonly connectionEncrypters: Map<string, ConnectionEncrypter> | ||
private readonly inboundUpgradeTimeout: number | ||
private readonly outboundUpgradeTimeout: number | ||
private readonly inboundStreamProtocolNegotiationTimeout: number | ||
@@ -154,4 +147,3 @@ private readonly outboundStreamProtocolNegotiationTimeout: number | ||
this.inboundUpgradeTimeout = init.inboundUpgradeTimeout ?? UPGRADE_TIMEOUT | ||
this.outboundUpgradeTimeout = init.outboundUpgradeTimeout ?? UPGRADE_TIMEOUT | ||
this.inboundUpgradeTimeout = init.inboundUpgradeTimeout ?? INBOUND_UPGRADE_TIMEOUT | ||
this.inboundStreamProtocolNegotiationTimeout = init.inboundStreamProtocolNegotiationTimeout ?? PROTOCOL_NEGOTIATION_TIMEOUT | ||
@@ -184,8 +176,21 @@ this.outboundStreamProtocolNegotiationTimeout = init.outboundStreamProtocolNegotiationTimeout ?? PROTOCOL_NEGOTIATION_TIMEOUT | ||
createInboundAbortSignal (signal: AbortSignal): ClearableSignal { | ||
const output = anySignal([ | ||
AbortSignal.timeout(this.inboundUpgradeTimeout), | ||
signal | ||
]) | ||
setMaxListeners(Infinity, output) | ||
return output | ||
} | ||
/** | ||
* Upgrades an inbound connection | ||
*/ | ||
async upgradeInbound (maConn: MultiaddrConnection, opts: UpgraderOptions = {}): Promise<void> { | ||
async upgradeInbound (maConn: MultiaddrConnection, opts: UpgraderOptions): Promise<void> { | ||
let accepted = false | ||
// always apply upgrade timeout for incoming upgrades | ||
const signal = this.createInboundAbortSignal(opts.signal) | ||
try { | ||
@@ -204,3 +209,6 @@ this.metrics.dials?.increment({ | ||
await this._performUpgrade(maConn, 'inbound', opts) | ||
await this._performUpgrade(maConn, 'inbound', { | ||
...opts, | ||
signal | ||
}) | ||
} catch (err) { | ||
@@ -213,2 +221,4 @@ this.metrics.errors?.increment({ | ||
} finally { | ||
signal.clear() | ||
if (accepted) { | ||
@@ -223,3 +233,3 @@ this.components.connectionManager.afterUpgradeInbound() | ||
*/ | ||
async upgradeOutbound (maConn: MultiaddrConnection, opts: UpgraderOptions = {}): Promise<Connection> { | ||
async upgradeOutbound (maConn: MultiaddrConnection, opts: UpgraderOptions): Promise<Connection> { | ||
try { | ||
@@ -262,10 +272,2 @@ this.metrics.dials?.increment({ | ||
if (opts.signal == null) { | ||
maConn.log('no abort signal was passed while trying to upgrade connection, falling back to default timeout') | ||
const upgradeTimeoutSignal = AbortSignal.timeout(direction === 'inbound' ? this.inboundUpgradeTimeout : this.outboundUpgradeTimeout) | ||
setMaxListeners(Infinity, upgradeTimeoutSignal) | ||
opts.signal = upgradeTimeoutSignal | ||
} | ||
this.components.metrics?.trackMultiaddrConnection(maConn) | ||
@@ -425,3 +427,3 @@ | ||
// after the handshake the returned stream can have early data so override | ||
// the souce/sink | ||
// the source/sink | ||
muxedStream.source = stream.source | ||
@@ -447,3 +449,3 @@ muxedStream.sink = stream.sink | ||
// If a protocol stream has been successfully negotiated and is to be passed to the application, | ||
// the peerstore should ensure that the peer is registered with that protocol | ||
// the peer store should ensure that the peer is registered with that protocol | ||
await this.components.peerStore.merge(remotePeer, { | ||
@@ -513,3 +515,3 @@ protocols: [protocol] | ||
// If a protocol stream has been successfully negotiated and is to be passed to the application, | ||
// the peerstore should ensure that the peer is registered with that protocol | ||
// the peer store should ensure that the peer is registered with that protocol | ||
await this.components.peerStore.merge(remotePeer, { | ||
@@ -520,3 +522,3 @@ protocols: [protocol] | ||
// after the handshake the returned stream can have early data so override | ||
// the souce/sink | ||
// the source/sink | ||
muxedStream.source = stream.source | ||
@@ -523,0 +525,0 @@ muxedStream.sink = stream.sink |
@@ -1,2 +0,2 @@ | ||
export const version = '2.7.2' | ||
export const version = '2.7.3' | ||
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
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
998618
12478
Updated@libp2p/crypto@^5.0.13
Updated@libp2p/interface@^2.6.1
Updated@libp2p/logger@^5.1.10
Updated@libp2p/peer-id@^5.0.14
Updated@libp2p/peer-store@^11.0.21
Updated@libp2p/utils@^6.5.5