Comparing version
import type { ConnectionGater } from '@libp2p/interface'; | ||
/** | ||
* Returns a connection gater that disallows dialling private addresses by | ||
* default. Browsers are severely limited in their resource usage so don't | ||
* waste time trying to dial undiallable addresses. | ||
* Returns a connection gater that disallows dialling private addresses or | ||
* insecure websockets by default. | ||
* | ||
* Browsers are severely limited in their resource usage so don't waste time | ||
* trying to dial undiallable addresses, and they also print verbose error | ||
* messages when making connections over insecure transports which causes | ||
* confusion. | ||
*/ | ||
export declare function connectionGater(gater?: ConnectionGater): ConnectionGater; | ||
//# sourceMappingURL=connection-gater.browser.d.ts.map |
import { isPrivateIp } from '@libp2p/utils/private-ip'; | ||
import { WebSockets } from '@multiformats/multiaddr-matcher'; | ||
const CODEC_IP4 = 0x04; | ||
const CODEC_IP6 = 0x29; | ||
/** | ||
* Returns a connection gater that disallows dialling private addresses by | ||
* default. Browsers are severely limited in their resource usage so don't | ||
* waste time trying to dial undiallable addresses. | ||
* Returns a connection gater that disallows dialling private addresses or | ||
* insecure websockets by default. | ||
* | ||
* Browsers are severely limited in their resource usage so don't waste time | ||
* trying to dial undiallable addresses, and they also print verbose error | ||
* messages when making connections over insecure transports which causes | ||
* confusion. | ||
*/ | ||
@@ -11,4 +18,9 @@ export function connectionGater(gater = {}) { | ||
denyDialMultiaddr: async (multiaddr) => { | ||
// do not connect to insecure websockets by default | ||
if (WebSockets.matches(multiaddr)) { | ||
return false; | ||
} | ||
const tuples = multiaddr.stringTuples(); | ||
if (tuples[0][0] === 4 || tuples[0][0] === 41) { | ||
// do not connect to private addresses by default | ||
if (tuples[0][0] === CODEC_IP4 || tuples[0][0] === CODEC_IP6) { | ||
return Boolean(isPrivateIp(`${tuples[0][1]}`)); | ||
@@ -15,0 +27,0 @@ } |
import { PeerMap } from '@libp2p/peer-collections'; | ||
import { PriorityQueue, type PriorityQueueJobOptions } from '@libp2p/utils/priority-queue'; | ||
import { type Multiaddr, type Resolver } from '@multiformats/multiaddr'; | ||
import { PriorityQueue } from '@libp2p/utils/priority-queue'; | ||
import type { AddressSorter, ComponentLogger, Connection, ConnectionGater, Metrics, PeerId, PeerStore, PeerRouting, IsDialableOptions, OpenConnectionProgressEvents } from '@libp2p/interface'; | ||
import type { OpenConnectionOptions, TransportManager } from '@libp2p/interface-internal'; | ||
import type { PriorityQueueJobOptions } from '@libp2p/utils/priority-queue'; | ||
import type { DNS } from '@multiformats/dns'; | ||
import type { Multiaddr, Resolver } from '@multiformats/multiaddr'; | ||
import type { ProgressOptions } from 'progress-events'; | ||
@@ -64,3 +65,2 @@ export interface PendingDialTarget { | ||
dial(peerIdOrMultiaddr: PeerId | Multiaddr | Multiaddr[], options?: OpenConnectionOptions): Promise<Connection>; | ||
private createDialAbortController; | ||
private calculateMultiaddrs; | ||
@@ -67,0 +67,0 @@ isDialable(multiaddr: Multiaddr | Multiaddr[], options?: IsDialableOptions): Promise<boolean>; |
@@ -141,3 +141,7 @@ /* eslint-disable max-depth */ | ||
// we may be about to resolve a dns addr which can time out | ||
const signal = this.createDialAbortController(options?.signal); | ||
const signal = anySignal([ | ||
this.shutDownController.signal, | ||
options.signal | ||
]); | ||
setMaxListeners(Infinity, signal); | ||
let addrsToDial; | ||
@@ -226,17 +230,6 @@ try { | ||
multiaddrs: new Set(multiaddrs.map(ma => ma.toString())), | ||
signal: options.signal, | ||
signal: options.signal ?? AbortSignal.timeout(this.dialTimeout), | ||
onProgress: options.onProgress | ||
}); | ||
} | ||
createDialAbortController(userSignal) { | ||
// let any signal abort the dial | ||
const signal = anySignal([ | ||
AbortSignal.timeout(this.dialTimeout), | ||
this.shutDownController.signal, | ||
userSignal | ||
]); | ||
// This emitter gets listened to a lot | ||
setMaxListeners(Infinity, signal); | ||
return signal; | ||
} | ||
// eslint-disable-next-line complexity | ||
@@ -243,0 +236,0 @@ async calculateMultiaddrs(peerId, multiaddrs = new Set(), options = {}) { |
@@ -171,2 +171,3 @@ import { PeerMap } from '@libp2p/peer-collections'; | ||
stop(): Promise<void>; | ||
getMaxConnections(): number; | ||
onConnect(evt: CustomEvent<Connection>): void; | ||
@@ -173,0 +174,0 @@ /** |
@@ -198,2 +198,5 @@ import { ConnectionClosedError, InvalidMultiaddrError, InvalidParametersError, InvalidPeerIdError, NotStartedError, start, stop } from '@libp2p/interface'; | ||
} | ||
getMaxConnections() { | ||
return this.maxConnections; | ||
} | ||
onConnect(evt) { | ||
@@ -200,0 +203,0 @@ void this._onConnect(evt).catch(err => { |
@@ -16,3 +16,3 @@ /** | ||
*/ | ||
import type { AddressManagerInit, AddressFilter } from './address-manager.js'; | ||
import type { AddressManagerInit, AddressFilter } from './address-manager/index.js'; | ||
import type { Components } from './components.js'; | ||
@@ -19,0 +19,0 @@ import type { ConnectionManagerInit } from './connection-manager/index.js'; |
@@ -11,3 +11,3 @@ import { publicKeyFromProtobuf } from '@libp2p/crypto/keys'; | ||
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'; | ||
import { AddressManager } from './address-manager.js'; | ||
import { AddressManager } from './address-manager/index.js'; | ||
import { checkServiceDependencies, defaultComponents } from './components.js'; | ||
@@ -14,0 +14,0 @@ import { connectionGater } from './config/connection-gater.js'; |
@@ -1,3 +0,3 @@ | ||
export declare const version = "2.3.1-0862522fe"; | ||
export declare const name = "libp2p"; | ||
export declare const version = "2.3.1-2625cc323"; | ||
export declare const name = "js-libp2p"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -1,3 +0,3 @@ | ||
export const version = '2.3.1-0862522fe'; | ||
export const name = 'libp2p'; | ||
export const version = '2.3.1-2625cc323'; | ||
export const name = 'js-libp2p'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "libp2p", | ||
"version": "2.3.1-0862522fe", | ||
"version": "2.3.1-2625cc323", | ||
"description": "JavaScript implementation of libp2p, a modular peer to peer network stack", | ||
@@ -88,31 +88,32 @@ "license": "Apache-2.0 OR MIT", | ||
"dependencies": { | ||
"@libp2p/crypto": "5.0.7-0862522fe", | ||
"@libp2p/interface": "2.2.1-0862522fe", | ||
"@libp2p/interface-internal": "2.1.1-0862522fe", | ||
"@libp2p/logger": "5.1.4-0862522fe", | ||
"@libp2p/multistream-select": "6.0.9-0862522fe", | ||
"@libp2p/peer-collections": "6.0.12-0862522fe", | ||
"@libp2p/peer-id": "5.0.8-0862522fe", | ||
"@libp2p/peer-store": "11.0.12-0862522fe", | ||
"@libp2p/utils": "6.2.1-0862522fe", | ||
"@chainsafe/is-ip": "^2.0.2", | ||
"@libp2p/crypto": "5.0.7-2625cc323", | ||
"@libp2p/interface": "2.2.1-2625cc323", | ||
"@libp2p/interface-internal": "2.1.1-2625cc323", | ||
"@libp2p/logger": "5.1.4-2625cc323", | ||
"@libp2p/multistream-select": "6.0.9-2625cc323", | ||
"@libp2p/peer-collections": "6.0.12-2625cc323", | ||
"@libp2p/peer-id": "5.0.8-2625cc323", | ||
"@libp2p/peer-store": "11.0.12-2625cc323", | ||
"@libp2p/utils": "6.2.1-2625cc323", | ||
"@multiformats/dns": "^1.0.6", | ||
"@multiformats/multiaddr": "^12.2.3", | ||
"@multiformats/multiaddr-matcher": "^1.2.1", | ||
"@multiformats/multiaddr": "^12.3.3", | ||
"@multiformats/multiaddr-matcher": "^1.6.0", | ||
"any-signal": "^4.1.1", | ||
"datastore-core": "^10.0.0", | ||
"interface-datastore": "^8.3.0", | ||
"it-byte-stream": "^1.0.12", | ||
"datastore-core": "^10.0.2", | ||
"interface-datastore": "^8.3.1", | ||
"it-byte-stream": "^1.1.0", | ||
"it-merge": "^3.0.5", | ||
"it-parallel": "^3.0.7", | ||
"it-parallel": "^3.0.8", | ||
"merge-options": "^3.0.4", | ||
"multiformats": "^13.1.0", | ||
"multiformats": "^13.3.1", | ||
"p-defer": "^4.0.1", | ||
"p-retry": "^6.2.0", | ||
"progress-events": "^1.0.0", | ||
"p-retry": "^6.2.1", | ||
"progress-events": "^1.0.1", | ||
"race-event": "^1.3.0", | ||
"race-signal": "^1.0.2", | ||
"race-signal": "^1.1.0", | ||
"uint8arrays": "^5.1.0" | ||
}, | ||
"devDependencies": { | ||
"aegir": "^44.0.1", | ||
"aegir": "^45.0.5", | ||
"delay": "^6.0.0", | ||
@@ -122,9 +123,9 @@ "it-all": "^3.0.6", | ||
"it-length-prefixed": "^9.1.0", | ||
"it-map": "^3.1.0", | ||
"it-map": "^3.1.1", | ||
"it-pair": "^2.0.6", | ||
"it-stream-types": "^2.0.1", | ||
"it-take": "^3.0.5", | ||
"it-stream-types": "^2.0.2", | ||
"it-take": "^3.0.6", | ||
"p-event": "^6.0.1", | ||
"p-wait-for": "^5.0.2", | ||
"sinon": "^18.0.0", | ||
"sinon": "^19.0.2", | ||
"sinon-ts": "^2.0.0", | ||
@@ -131,0 +132,0 @@ "uint8arraylist": "^2.4.8" |
@@ -5,28 +5,12 @@ <h1 align="center"> | ||
<h3 align="center">The JavaScript implementation of the libp2p Networking Stack.</h3> | ||
<h3 align="center">The JavaScript implementation of the libp2p Networking Stack</h3> | ||
<p align="center"> | ||
<a href="http://protocol.ai"><img src="https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square" /></a> | ||
<a href="http://libp2p.io/"><img src="https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square" /></a> | ||
<a href="http://webchat.freenode.net/?channels=%23libp2p"><img src="https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square" /></a> | ||
<a href="https://riot.im/app/#/room/#libp2p:matrix.org"><img src="https://img.shields.io/badge/matrix-%23libp2p%3Apermaweb.io-blue.svg?style=flat-square" /> </a> | ||
<a href="https://discord.gg/ipfs"><img src="https://img.shields.io/discord/806902334369824788?color=blueviolet&label=discord&style=flat-square" /></a> | ||
<a href="https://discuss.libp2p.io"><img src="https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg" /></a> | ||
<a href="https://www.npmjs.com/package/libp2p"><img src="https://img.shields.io/npm/dm/libp2p.svg" /></a> | ||
<a href="https://www.jsdelivr.com/package/npm/libp2p"><img src="https://data.jsdelivr.com/v1/package/npm/libp2p/badge"/></a> | ||
</p> | ||
[](http://libp2p.io/) | ||
[](https://www.npmjs.com/package/libp2p) | ||
[](https://discuss.libp2p.io) | ||
[](http://webchat.freenode.net/?channels=%23libp2p) | ||
[](https://discord.com/invite/Ae4TbahHaT) | ||
[](https://codecov.io/gh/libp2p/js-libp2p) | ||
[](https://github.com/libp2p/js-libp2p/actions/workflows/main.yml?query=branch%3Amain) | ||
<p align="center"> | ||
<a href="https://github.com/libp2p/js-libp2p/actions?query=branch%3Amaster+workflow%3Aci+"><img src="https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p/main.yml?branch=main&label=ci&style=flat-square" /></a> | ||
<a href="https://codecov.io/gh/libp2p/js-libp2p"><img src="https://img.shields.io/codecov/c/github/libp2p/js-libp2p/master.svg?style=flat-square"></a> | ||
<br> | ||
<a href="https://github.com/feross/standard"><img src="https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square"></a> | ||
<a href="https://github.com/RichardLitt/standard-readme"><img src="https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square" /></a> | ||
<a href=""><img src="https://img.shields.io/badge/npm-%3E%3D7.0.0-orange.svg?style=flat-square" /></a> | ||
<a href=""><img src="https://img.shields.io/badge/Node.js-%3E%3D15.0.0-orange.svg?style=flat-square" /></a> | ||
<br> | ||
</p> | ||
> JavaScript implementation of libp2p, a modular peer to peer network stack | ||
# About | ||
@@ -33,0 +17,0 @@ |
import { isPrivateIp } from '@libp2p/utils/private-ip' | ||
import { WebSockets } from '@multiformats/multiaddr-matcher' | ||
import type { ConnectionGater } from '@libp2p/interface' | ||
import type { Multiaddr } from '@multiformats/multiaddr' | ||
const CODEC_IP4 = 0x04 | ||
const CODEC_IP6 = 0x29 | ||
/** | ||
* Returns a connection gater that disallows dialling private addresses by | ||
* default. Browsers are severely limited in their resource usage so don't | ||
* waste time trying to dial undiallable addresses. | ||
* Returns a connection gater that disallows dialling private addresses or | ||
* insecure websockets by default. | ||
* | ||
* Browsers are severely limited in their resource usage so don't waste time | ||
* trying to dial undiallable addresses, and they also print verbose error | ||
* messages when making connections over insecure transports which causes | ||
* confusion. | ||
*/ | ||
@@ -14,5 +22,11 @@ export function connectionGater (gater: ConnectionGater = {}): ConnectionGater { | ||
denyDialMultiaddr: async (multiaddr: Multiaddr) => { | ||
// do not connect to insecure websockets by default | ||
if (WebSockets.matches(multiaddr)) { | ||
return false | ||
} | ||
const tuples = multiaddr.stringTuples() | ||
if (tuples[0][0] === 4 || tuples[0][0] === 41) { | ||
// do not connect to private addresses by default | ||
if (tuples[0][0] === CODEC_IP4 || tuples[0][0] === CODEC_IP6) { | ||
return Boolean(isPrivateIp(`${tuples[0][1]}`)) | ||
@@ -19,0 +33,0 @@ } |
/* eslint-disable max-depth */ | ||
import { TimeoutError, DialError, setMaxListeners, AbortError } from '@libp2p/interface' | ||
import { PeerMap } from '@libp2p/peer-collections' | ||
import { PriorityQueue, type PriorityQueueJobOptions } from '@libp2p/utils/priority-queue' | ||
import { type Multiaddr, type Resolver, resolvers, multiaddr } from '@multiformats/multiaddr' | ||
import { PriorityQueue } from '@libp2p/utils/priority-queue' | ||
import { resolvers, multiaddr } from '@multiformats/multiaddr' | ||
import { dnsaddrResolver } from '@multiformats/multiaddr/resolvers' | ||
import { Circuit } from '@multiformats/multiaddr-matcher' | ||
import { type ClearableSignal, anySignal } from 'any-signal' | ||
import { anySignal } from 'any-signal' | ||
import { CustomProgressEvent } from 'progress-events' | ||
@@ -26,3 +26,5 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' | ||
import type { OpenConnectionOptions, TransportManager } from '@libp2p/interface-internal' | ||
import type { PriorityQueueJobOptions } from '@libp2p/utils/priority-queue' | ||
import type { DNS } from '@multiformats/dns' | ||
import type { Multiaddr, Resolver } from '@multiformats/multiaddr' | ||
import type { ProgressOptions } from 'progress-events' | ||
@@ -208,3 +210,8 @@ | ||
// we may be about to resolve a dns addr which can time out | ||
const signal = this.createDialAbortController(options?.signal) | ||
const signal = anySignal([ | ||
this.shutDownController.signal, | ||
options.signal | ||
]) | ||
setMaxListeners(Infinity, signal) | ||
let addrsToDial: Address[] | ||
@@ -304,3 +311,3 @@ | ||
multiaddrs: new Set(multiaddrs.map(ma => ma.toString())), | ||
signal: options.signal, | ||
signal: options.signal ?? AbortSignal.timeout(this.dialTimeout), | ||
onProgress: options.onProgress | ||
@@ -310,16 +317,2 @@ }) | ||
private createDialAbortController (userSignal?: AbortSignal): ClearableSignal { | ||
// let any signal abort the dial | ||
const signal = anySignal([ | ||
AbortSignal.timeout(this.dialTimeout), | ||
this.shutDownController.signal, | ||
userSignal | ||
]) | ||
// This emitter gets listened to a lot | ||
setMaxListeners(Infinity, signal) | ||
return signal | ||
} | ||
// eslint-disable-next-line complexity | ||
@@ -326,0 +319,0 @@ private async calculateMultiaddrs (peerId?: PeerId, multiaddrs: Set<string> = new Set<string>(), options: OpenConnectionOptions = {}): Promise<Address[]> { |
@@ -398,2 +398,6 @@ import { ConnectionClosedError, InvalidMultiaddrError, InvalidParametersError, InvalidPeerIdError, NotStartedError, start, stop } from '@libp2p/interface' | ||
getMaxConnections (): number { | ||
return this.maxConnections | ||
} | ||
onConnect (evt: CustomEvent<Connection>): void { | ||
@@ -400,0 +404,0 @@ void this._onConnect(evt).catch(err => { |
@@ -21,3 +21,3 @@ /** | ||
import { Libp2p as Libp2pClass } from './libp2p.js' | ||
import type { AddressManagerInit, AddressFilter } from './address-manager.js' | ||
import type { AddressManagerInit, AddressFilter } from './address-manager/index.js' | ||
import type { Components } from './components.js' | ||
@@ -24,0 +24,0 @@ import type { ConnectionManagerInit } from './connection-manager/index.js' |
@@ -11,3 +11,3 @@ import { publicKeyFromProtobuf } from '@libp2p/crypto/keys' | ||
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' | ||
import { AddressManager } from './address-manager.js' | ||
import { AddressManager } from './address-manager/index.js' | ||
import { checkServiceDependencies, defaultComponents } from './components.js' | ||
@@ -14,0 +14,0 @@ import { connectionGater } from './config/connection-gater.js' |
@@ -1,2 +0,2 @@ | ||
export const version = '2.3.1-0862522fe' | ||
export const name = 'libp2p' | ||
export const version = '2.3.1-2625cc323' | ||
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
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
963764
9.02%158
13.67%0
-100%100
25%11866
11.26%27
3.85%191
-7.73%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated
Updated
Updated
Updated
Updated
Updated
Updated