New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

libp2p

Package Overview
Dependencies
Maintainers
2
Versions
1093
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libp2p - npm Package Compare versions

Comparing version

to
2.4.0-127abe24b

dist/src/address-manager/dns-mappings.d.ts

10

dist/src/config/connection-gater.browser.d.ts
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 { safelyCloseConnectionIfUnused } from '@libp2p/utils/close';
import { MAX_CONNECTIONS } from './constants.js';
import { multiaddrToIpNet } from './utils.js';
const defaultOptions = {

@@ -20,3 +21,3 @@ maxConnections: MAX_CONNECTIONS,

this.maxConnections = init.maxConnections ?? defaultOptions.maxConnections;
this.allow = init.allow ?? defaultOptions.allow;
this.allow = (init.allow ?? []).map(ma => multiaddrToIpNet(ma));
this.connectionManager = components.connectionManager;

@@ -79,4 +80,4 @@ this.peerStore = components.peerStore;

// check allow list
const connectionInAllowList = this.allow.some((ma) => {
return connection.remoteAddr.toString().startsWith(ma.toString());
const connectionInAllowList = this.allow.some((ipNet) => {
return ipNet.contains(connection.remoteAddr.nodeAddress().address);
});

@@ -83,0 +84,0 @@ // Connections in the allow list should be excluded from pruning

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 @@ /**

@@ -12,2 +12,3 @@ import { ConnectionClosedError, InvalidMultiaddrError, InvalidParametersError, InvalidPeerIdError, NotStartedError, start, stop } from '@libp2p/interface';

import { ReconnectQueue } from './reconnect-queue.js';
import { multiaddrToIpNet } from './utils.js';
export const DEFAULT_DIAL_PRIORITY = 50;

@@ -58,4 +59,4 @@ const defaultOptions = {

// allow/deny lists
this.allow = (init.allow ?? []).map(ma => multiaddr(ma));
this.deny = (init.deny ?? []).map(ma => multiaddr(ma));
this.allow = (init.allow ?? []).map(str => multiaddrToIpNet(str));
this.deny = (init.deny ?? []).map(str => multiaddrToIpNet(str));
this.incomingPendingConnections = 0;

@@ -77,3 +78,3 @@ this.maxIncomingPendingConnections = init.maxIncomingPendingConnections ?? defaultOptions.maxIncomingPendingConnections;

maxConnections: this.maxConnections,
allow: this.allow
allow: init.allow?.map(a => multiaddr(a))
});

@@ -201,2 +202,5 @@ this.dialQueue = new DialQueue(components, {

}
getMaxConnections() {
return this.maxConnections;
}
onConnect(evt) {

@@ -340,3 +344,3 @@ void this._onConnect(evt).catch(err => {

const denyConnection = this.deny.some(ma => {
return maConn.remoteAddr.toString().startsWith(ma.toString());
return ma.contains(maConn.remoteAddr.nodeAddress().address);
});

@@ -348,4 +352,4 @@ if (denyConnection) {

// check allow list
const allowConnection = this.allow.some(ma => {
return maConn.remoteAddr.toString().startsWith(ma.toString());
const allowConnection = this.allow.some(ipNet => {
return ipNet.contains(maConn.remoteAddr.nodeAddress().address);
});

@@ -352,0 +356,0 @@ if (allowConnection) {

@@ -0,3 +1,4 @@

import { type Multiaddr, type ResolveOptions } from '@multiformats/multiaddr';
import type { IpNet } from '@chainsafe/netmask';
import type { LoggerOptions } from '@libp2p/interface';
import type { Multiaddr, ResolveOptions } from '@multiformats/multiaddr';
/**

@@ -7,2 +8,13 @@ * Recursively resolve DNSADDR multiaddrs

export declare function resolveMultiaddrs(ma: Multiaddr, options: ResolveOptions & LoggerOptions): Promise<Multiaddr[]>;
/**
* Converts a multiaddr string or object to an IpNet object.
* If the multiaddr doesn't include /ipcidr, it will encapsulate with the appropriate CIDR:
* - /ipcidr/32 for IPv4
* - /ipcidr/128 for IPv6
*
* @param {string | Multiaddr} ma - The multiaddr string or object to convert.
* @returns {IpNet} The converted IpNet object.
* @throws {Error} Throws an error if the multiaddr is not valid.
*/
export declare function multiaddrToIpNet(ma: string | Multiaddr): IpNet;
//# sourceMappingURL=utils.d.ts.map

@@ -1,2 +0,3 @@

import { resolvers } from '@multiformats/multiaddr';
import { multiaddr, resolvers } from '@multiformats/multiaddr';
import { convertToIpNet } from '@multiformats/multiaddr/convert';
/**

@@ -22,2 +23,33 @@ * Recursively resolve DNSADDR multiaddrs

}
/**
* Converts a multiaddr string or object to an IpNet object.
* If the multiaddr doesn't include /ipcidr, it will encapsulate with the appropriate CIDR:
* - /ipcidr/32 for IPv4
* - /ipcidr/128 for IPv6
*
* @param {string | Multiaddr} ma - The multiaddr string or object to convert.
* @returns {IpNet} The converted IpNet object.
* @throws {Error} Throws an error if the multiaddr is not valid.
*/
export function multiaddrToIpNet(ma) {
try {
let parsedMa;
if (typeof ma === 'string') {
parsedMa = multiaddr(ma);
}
else {
parsedMa = ma;
}
// Check if /ipcidr is already present
if (!parsedMa.protoNames().includes('ipcidr')) {
const isIPv6 = parsedMa.protoNames().includes('ip6');
const cidr = isIPv6 ? '/ipcidr/128' : '/ipcidr/32';
parsedMa = parsedMa.encapsulate(cidr);
}
return convertToIpNet(parsedMa);
}
catch (error) {
throw new Error(`Can't convert to IpNet, Invalid multiaddr format: ${ma}`);
}
}
//# sourceMappingURL=utils.js.map

@@ -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";
export declare const name = "libp2p";
export declare const version = "2.4.0-127abe24b";
export declare const name = "js-libp2p";
//# sourceMappingURL=version.d.ts.map

@@ -1,3 +0,3 @@

export const version = '2.3.1';
export const name = 'libp2p';
export const version = '2.4.0-127abe24b';
export const name = 'js-libp2p';
//# sourceMappingURL=version.js.map
{
"name": "libp2p",
"version": "2.3.1",
"version": "2.4.0-127abe24b",
"description": "JavaScript implementation of libp2p, a modular peer to peer network stack",

@@ -88,31 +88,33 @@ "license": "Apache-2.0 OR MIT",

"dependencies": {
"@libp2p/crypto": "^5.0.7",
"@libp2p/interface": "^2.2.1",
"@libp2p/interface-internal": "^2.1.1",
"@libp2p/logger": "^5.1.4",
"@libp2p/multistream-select": "^6.0.9",
"@libp2p/peer-collections": "^6.0.12",
"@libp2p/peer-id": "^5.0.8",
"@libp2p/peer-store": "^11.0.12",
"@libp2p/utils": "^6.2.1",
"@chainsafe/is-ip": "^2.0.2",
"@chainsafe/netmask": "^2.0.0",
"@libp2p/crypto": "5.0.8-127abe24b",
"@libp2p/interface": "2.3.0-127abe24b",
"@libp2p/interface-internal": "2.2.0-127abe24b",
"@libp2p/logger": "5.1.5-127abe24b",
"@libp2p/multistream-select": "6.0.10-127abe24b",
"@libp2p/peer-collections": "6.0.13-127abe24b",
"@libp2p/peer-id": "5.0.9-127abe24b",
"@libp2p/peer-store": "11.0.13-127abe24b",
"@libp2p/utils": "6.3.0-127abe24b",
"@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 +124,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 +133,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>
[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
[![npm](https://img.shields.io/npm/dm/libp2p.svg?style=flat-square)](https://www.npmjs.com/package/libp2p)
[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
[![Matrix](https://img.shields.io/badge/matrix-%23libp2p--implementers%3Aipfs.io-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
[![Discord](https://img.shields.io/discord/806902334369824788?color=blueviolet&label=discord&style=flat-square)](https://discord.com/invite/Ae4TbahHaT)
[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p)
[![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p/main.yml?branch=main\&style=flat-square)](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 @@ }

import { PeerMap } from '@libp2p/peer-collections'
import { safelyCloseConnectionIfUnused } from '@libp2p/utils/close'
import { MAX_CONNECTIONS } from './constants.js'
import { multiaddrToIpNet } from './utils.js'
import type { IpNet } from '@chainsafe/netmask'
import type { Libp2pEvents, Logger, ComponentLogger, TypedEventTarget, PeerStore, Connection } from '@libp2p/interface'

@@ -32,3 +34,3 @@ import type { ConnectionManager } from '@libp2p/interface-internal'

private readonly peerStore: PeerStore
private readonly allow: Multiaddr[]
private readonly allow: IpNet[]
private readonly events: TypedEventTarget<Libp2pEvents>

@@ -39,3 +41,3 @@ private readonly log: Logger

this.maxConnections = init.maxConnections ?? defaultOptions.maxConnections
this.allow = init.allow ?? defaultOptions.allow
this.allow = (init.allow ?? []).map(ma => multiaddrToIpNet(ma))
this.connectionManager = components.connectionManager

@@ -112,4 +114,4 @@ this.peerStore = components.peerStore

// check allow list
const connectionInAllowList = this.allow.some((ma) => {
return connection.remoteAddr.toString().startsWith(ma.toString())
const connectionInAllowList = this.allow.some((ipNet) => {
return ipNet.contains(connection.remoteAddr.nodeAddress().address)
})

@@ -116,0 +118,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[]> {

@@ -12,2 +12,4 @@ import { ConnectionClosedError, InvalidMultiaddrError, InvalidParametersError, InvalidPeerIdError, NotStartedError, start, stop } from '@libp2p/interface'

import { ReconnectQueue } from './reconnect-queue.js'
import { multiaddrToIpNet } from './utils.js'
import type { IpNet } from '@chainsafe/netmask'
import type { PendingDial, AddressSorter, Libp2pEvents, AbortOptions, ComponentLogger, Logger, Connection, MultiaddrConnection, ConnectionGater, TypedEventTarget, Metrics, PeerId, PeerStore, Startable, PendingDialStatus, PeerRouting, IsDialableOptions } from '@libp2p/interface'

@@ -180,4 +182,4 @@ import type { ConnectionManager, OpenConnectionOptions, TransportManager } from '@libp2p/interface-internal'

private readonly connections: PeerMap<Connection[]>
private readonly allow: Multiaddr[]
private readonly deny: Multiaddr[]
private readonly allow: IpNet[]
private readonly deny: IpNet[]
private readonly maxIncomingPendingConnections: number

@@ -221,4 +223,4 @@ private incomingPendingConnections: number

// allow/deny lists
this.allow = (init.allow ?? []).map(ma => multiaddr(ma))
this.deny = (init.deny ?? []).map(ma => multiaddr(ma))
this.allow = (init.allow ?? []).map(str => multiaddrToIpNet(str))
this.deny = (init.deny ?? []).map(str => multiaddrToIpNet(str))

@@ -243,3 +245,3 @@ this.incomingPendingConnections = 0

maxConnections: this.maxConnections,
allow: this.allow
allow: init.allow?.map(a => multiaddr(a))
})

@@ -402,2 +404,6 @@

getMaxConnections (): number {
return this.maxConnections
}
onConnect (evt: CustomEvent<Connection>): void {

@@ -579,3 +585,3 @@ void this._onConnect(evt).catch(err => {

const denyConnection = this.deny.some(ma => {
return maConn.remoteAddr.toString().startsWith(ma.toString())
return ma.contains(maConn.remoteAddr.nodeAddress().address)
})

@@ -589,4 +595,4 @@

// check allow list
const allowConnection = this.allow.some(ma => {
return maConn.remoteAddr.toString().startsWith(ma.toString())
const allowConnection = this.allow.some(ipNet => {
return ipNet.contains(maConn.remoteAddr.nodeAddress().address)
})

@@ -593,0 +599,0 @@

@@ -1,4 +0,5 @@

import { resolvers } from '@multiformats/multiaddr'
import { multiaddr, resolvers, type Multiaddr, type ResolveOptions } from '@multiformats/multiaddr'
import { convertToIpNet } from '@multiformats/multiaddr/convert'
import type { IpNet } from '@chainsafe/netmask'
import type { LoggerOptions } from '@libp2p/interface'
import type { Multiaddr, ResolveOptions } from '@multiformats/multiaddr'

@@ -31,1 +32,33 @@ /**

}
/**
* Converts a multiaddr string or object to an IpNet object.
* If the multiaddr doesn't include /ipcidr, it will encapsulate with the appropriate CIDR:
* - /ipcidr/32 for IPv4
* - /ipcidr/128 for IPv6
*
* @param {string | Multiaddr} ma - The multiaddr string or object to convert.
* @returns {IpNet} The converted IpNet object.
* @throws {Error} Throws an error if the multiaddr is not valid.
*/
export function multiaddrToIpNet (ma: string | Multiaddr): IpNet {
try {
let parsedMa: Multiaddr
if (typeof ma === 'string') {
parsedMa = multiaddr(ma)
} else {
parsedMa = ma
}
// Check if /ipcidr is already present
if (!parsedMa.protoNames().includes('ipcidr')) {
const isIPv6 = parsedMa.protoNames().includes('ip6')
const cidr = isIPv6 ? '/ipcidr/128' : '/ipcidr/32'
parsedMa = parsedMa.encapsulate(cidr)
}
return convertToIpNet(parsedMa)
} catch (error) {
throw new Error(`Can't convert to IpNet, Invalid multiaddr format: ${ma}`)
}
}

@@ -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'
export const name = 'libp2p'
export const version = '2.4.0-127abe24b'
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

Sorry, the diff of this file is not supported yet