@libp2p/utils 6.5.8-757577dd2 → 6.5.8-95909c3df
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/get-thin-waist-addresses.browser.d.ts +6 -4
- package/dist/src/get-thin-waist-addresses.browser.d.ts.map +1 -1
- package/dist/src/get-thin-waist-addresses.browser.js +9 -4
- package/dist/src/get-thin-waist-addresses.browser.js.map +1 -1
- package/dist/src/get-thin-waist-addresses.d.ts +3 -3
- package/dist/src/get-thin-waist-addresses.d.ts.map +1 -1
- package/dist/src/get-thin-waist-addresses.js +11 -4
- package/dist/src/get-thin-waist-addresses.js.map +1 -1
- package/dist/src/link-local-ip.d.ts.map +1 -1
- package/dist/src/link-local-ip.js +4 -5
- package/dist/src/link-local-ip.js.map +1 -1
- package/package.json +5 -5
- package/src/get-thin-waist-addresses.browser.ts +12 -5
- package/src/get-thin-waist-addresses.ts +15 -5
- package/src/link-local-ip.ts +4 -6
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
2
2
|
/**
|
|
3
|
-
* Get all thin waist addresses that match the
|
|
4
|
-
*
|
|
3
|
+
* Get all thin waist addresses on the current host that match the family of the
|
|
4
|
+
* passed multiaddr and optionally override the port.
|
|
5
|
+
*
|
|
6
|
+
* Wildcard IP4/6 addresses will be expanded into all available interfaces.
|
|
5
7
|
*/
|
|
6
|
-
export declare function getThinWaistAddresses(ma
|
|
8
|
+
export declare function getThinWaistAddresses(ma?: Multiaddr, port?: number): Multiaddr[];
|
|
7
9
|
//# sourceMappingURL=get-thin-waist-addresses.browser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-thin-waist-addresses.browser.d.ts","sourceRoot":"","sources":["../../src/get-thin-waist-addresses.browser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-thin-waist-addresses.browser.d.ts","sourceRoot":"","sources":["../../src/get-thin-waist-addresses.browser.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAE,EAAE,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,EAAE,CAUjF"}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { multiaddr } from '@multiformats/multiaddr';
|
|
2
2
|
/**
|
|
3
|
-
* Get all thin waist addresses that match the
|
|
4
|
-
*
|
|
3
|
+
* Get all thin waist addresses on the current host that match the family of the
|
|
4
|
+
* passed multiaddr and optionally override the port.
|
|
5
|
+
*
|
|
6
|
+
* Wildcard IP4/6 addresses will be expanded into all available interfaces.
|
|
5
7
|
*/
|
|
6
|
-
export function getThinWaistAddresses(ma) {
|
|
8
|
+
export function getThinWaistAddresses(ma, port) {
|
|
9
|
+
if (ma == null) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
7
12
|
const options = ma.toOptions();
|
|
8
13
|
return [
|
|
9
|
-
multiaddr(`/ip${options.family}/${options.host}/${options.transport}/${options.port}`)
|
|
14
|
+
multiaddr(`/ip${options.family}/${options.host}/${options.transport}/${port ?? options.port}`)
|
|
10
15
|
];
|
|
11
16
|
}
|
|
12
17
|
//# sourceMappingURL=get-thin-waist-addresses.browser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-thin-waist-addresses.browser.js","sourceRoot":"","sources":["../../src/get-thin-waist-addresses.browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"get-thin-waist-addresses.browser.js","sourceRoot":"","sources":["../../src/get-thin-waist-addresses.browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAGnD;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAE,EAAc,EAAE,IAAa;IAClE,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC;QACf,OAAO,EAAE,CAAA;IACX,CAAC;IAED,MAAM,OAAO,GAAG,EAAE,CAAC,SAAS,EAAE,CAAA;IAE9B,OAAO;QACL,SAAS,CAAC,MAAM,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,SAAS,IAAI,IAAI,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;KAC/F,CAAA;AACH,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
2
2
|
/**
|
|
3
3
|
* Get all thin waist addresses on the current host that match the family of the
|
|
4
|
-
* passed multiaddr.
|
|
4
|
+
* passed multiaddr and optionally override the port.
|
|
5
5
|
*
|
|
6
6
|
* Wildcard IP4/6 addresses will be expanded into all available interfaces.
|
|
7
7
|
*/
|
|
8
|
-
export declare function getThinWaistAddresses(ma
|
|
8
|
+
export declare function getThinWaistAddresses(ma?: Multiaddr, port?: number): Multiaddr[];
|
|
9
9
|
//# sourceMappingURL=get-thin-waist-addresses.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-thin-waist-addresses.d.ts","sourceRoot":"","sources":["../../src/get-thin-waist-addresses.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-thin-waist-addresses.d.ts","sourceRoot":"","sources":["../../src/get-thin-waist-addresses.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AA6BxD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAE,EAAE,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,EAAE,CAoBjF"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import os from 'node:os';
|
|
2
2
|
import { multiaddr } from '@multiformats/multiaddr';
|
|
3
|
+
import { isLinkLocalIp } from './link-local-ip.js';
|
|
3
4
|
const FAMILIES = { 4: 'IPv4', 6: 'IPv6' };
|
|
4
5
|
function isWildcard(ip) {
|
|
5
6
|
return ['0.0.0.0', '::'].includes(ip);
|
|
@@ -10,6 +11,9 @@ function getNetworkAddrs(family) {
|
|
|
10
11
|
for (const [, netAddrs] of Object.entries(networks)) {
|
|
11
12
|
if (netAddrs != null) {
|
|
12
13
|
for (const netAddr of netAddrs) {
|
|
14
|
+
if (isLinkLocalIp(netAddr.address)) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
13
17
|
if (netAddr.family === FAMILIES[family]) {
|
|
14
18
|
addresses.push(netAddr.address);
|
|
15
19
|
}
|
|
@@ -20,21 +24,24 @@ function getNetworkAddrs(family) {
|
|
|
20
24
|
}
|
|
21
25
|
/**
|
|
22
26
|
* Get all thin waist addresses on the current host that match the family of the
|
|
23
|
-
* passed multiaddr.
|
|
27
|
+
* passed multiaddr and optionally override the port.
|
|
24
28
|
*
|
|
25
29
|
* Wildcard IP4/6 addresses will be expanded into all available interfaces.
|
|
26
30
|
*/
|
|
27
|
-
export function getThinWaistAddresses(ma) {
|
|
31
|
+
export function getThinWaistAddresses(ma, port) {
|
|
32
|
+
if (ma == null) {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
28
35
|
const options = ma.toOptions();
|
|
29
36
|
if (isWildcard(options.host)) {
|
|
30
37
|
const addrs = [];
|
|
31
38
|
for (const host of getNetworkAddrs(options.family)) {
|
|
32
|
-
addrs.push(multiaddr(`/ip${options.family}/${host}/${options.transport}/${options.port}`));
|
|
39
|
+
addrs.push(multiaddr(`/ip${options.family}/${host}/${options.transport}/${port ?? options.port}`));
|
|
33
40
|
}
|
|
34
41
|
return addrs;
|
|
35
42
|
}
|
|
36
43
|
return [
|
|
37
|
-
multiaddr(`/ip${options.family}/${options.host}/${options.transport}/${options.port}`)
|
|
44
|
+
multiaddr(`/ip${options.family}/${options.host}/${options.transport}/${port ?? options.port}`)
|
|
38
45
|
];
|
|
39
46
|
}
|
|
40
47
|
//# sourceMappingURL=get-thin-waist-addresses.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-thin-waist-addresses.js","sourceRoot":"","sources":["../../src/get-thin-waist-addresses.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"get-thin-waist-addresses.js","sourceRoot":"","sources":["../../src/get-thin-waist-addresses.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAGlD,MAAM,QAAQ,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAA;AAEzC,SAAS,UAAU,CAAE,EAAU;IAC7B,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;AACvC,CAAC;AAED,SAAS,eAAe,CAAE,MAAa;IACrC,MAAM,SAAS,GAAa,EAAE,CAAA;IAC9B,MAAM,QAAQ,GAAG,EAAE,CAAC,iBAAiB,EAAE,CAAA;IAEvC,KAAK,MAAM,CAAC,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QACpD,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;YACrB,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;gBAC/B,IAAI,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;oBACnC,SAAQ;gBACV,CAAC;gBAED,IAAI,OAAO,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;oBACxC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;gBACjC,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAA;AAClB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAE,EAAc,EAAE,IAAa;IAClE,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC;QACf,OAAO,EAAE,CAAA;IACX,CAAC;IAED,MAAM,OAAO,GAAG,EAAE,CAAC,SAAS,EAAE,CAAA;IAE9B,IAAI,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7B,MAAM,KAAK,GAAG,EAAE,CAAA;QAEhB,KAAK,MAAM,IAAI,IAAI,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YACnD,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,OAAO,CAAC,MAAM,IAAI,IAAI,IAAI,OAAO,CAAC,SAAS,IAAI,IAAI,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;QACpG,CAAC;QAED,OAAO,KAAK,CAAA;IACd,CAAC;IAED,OAAO;QACL,SAAS,CAAC,MAAM,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,SAAS,IAAI,IAAI,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;KAC/F,CAAA;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link-local-ip.d.ts","sourceRoot":"","sources":["../../src/link-local-ip.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"link-local-ip.d.ts","sourceRoot":"","sources":["../../src/link-local-ip.ts"],"names":[],"mappings":"AAAA,wBAAgB,aAAa,CAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAUlD"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { isIPv4, isIPv6 } from '@chainsafe/is-ip';
|
|
2
1
|
export function isLinkLocalIp(ip) {
|
|
3
|
-
if (
|
|
4
|
-
return
|
|
2
|
+
if (ip.startsWith('169.254.')) {
|
|
3
|
+
return true;
|
|
5
4
|
}
|
|
6
|
-
if (
|
|
7
|
-
return
|
|
5
|
+
if (ip.toLowerCase().startsWith('fe80')) {
|
|
6
|
+
return true;
|
|
8
7
|
}
|
|
9
8
|
return false;
|
|
10
9
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link-local-ip.js","sourceRoot":"","sources":["../../src/link-local-ip.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"link-local-ip.js","sourceRoot":"","sources":["../../src/link-local-ip.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,aAAa,CAAE,EAAU;IACvC,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9B,OAAO,IAAI,CAAA;IACb,CAAC;IAED,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QACxC,OAAO,IAAI,CAAA;IACb,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/utils",
|
|
3
|
-
"version": "6.5.8-
|
|
3
|
+
"version": "6.5.8-95909c3df",
|
|
4
4
|
"description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/utils#readme",
|
|
@@ -194,9 +194,9 @@
|
|
|
194
194
|
"dependencies": {
|
|
195
195
|
"@chainsafe/is-ip": "^2.0.2",
|
|
196
196
|
"@chainsafe/netmask": "^2.0.0",
|
|
197
|
-
"@libp2p/crypto": "5.0.15-
|
|
198
|
-
"@libp2p/interface": "2.7.0-
|
|
199
|
-
"@libp2p/logger": "5.1.13-
|
|
197
|
+
"@libp2p/crypto": "5.0.15-95909c3df",
|
|
198
|
+
"@libp2p/interface": "2.7.0-95909c3df",
|
|
199
|
+
"@libp2p/logger": "5.1.13-95909c3df",
|
|
200
200
|
"@multiformats/multiaddr": "^12.3.3",
|
|
201
201
|
"@sindresorhus/fnv1a": "^3.1.0",
|
|
202
202
|
"any-signal": "^4.1.1",
|
|
@@ -215,7 +215,7 @@
|
|
|
215
215
|
"uint8arrays": "^5.1.0"
|
|
216
216
|
},
|
|
217
217
|
"devDependencies": {
|
|
218
|
-
"@libp2p/peer-id": "5.1.0-
|
|
218
|
+
"@libp2p/peer-id": "5.1.0-95909c3df",
|
|
219
219
|
"@types/netmask": "^2.0.5",
|
|
220
220
|
"aegir": "^45.1.1",
|
|
221
221
|
"benchmark": "^2.1.4",
|
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
import { multiaddr
|
|
1
|
+
import { multiaddr } from '@multiformats/multiaddr'
|
|
2
|
+
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
|
-
* Get all thin waist addresses that match the
|
|
5
|
-
*
|
|
5
|
+
* Get all thin waist addresses on the current host that match the family of the
|
|
6
|
+
* passed multiaddr and optionally override the port.
|
|
7
|
+
*
|
|
8
|
+
* Wildcard IP4/6 addresses will be expanded into all available interfaces.
|
|
6
9
|
*/
|
|
7
|
-
export function getThinWaistAddresses (ma
|
|
10
|
+
export function getThinWaistAddresses (ma?: Multiaddr, port?: number): Multiaddr[] {
|
|
11
|
+
if (ma == null) {
|
|
12
|
+
return []
|
|
13
|
+
}
|
|
14
|
+
|
|
8
15
|
const options = ma.toOptions()
|
|
9
16
|
|
|
10
17
|
return [
|
|
11
|
-
multiaddr(`/ip${options.family}/${options.host}/${options.transport}/${options.port}`)
|
|
18
|
+
multiaddr(`/ip${options.family}/${options.host}/${options.transport}/${port ?? options.port}`)
|
|
12
19
|
]
|
|
13
20
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import os from 'node:os'
|
|
2
|
-
import { multiaddr
|
|
2
|
+
import { multiaddr } from '@multiformats/multiaddr'
|
|
3
|
+
import { isLinkLocalIp } from './link-local-ip.js'
|
|
4
|
+
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
3
5
|
|
|
4
6
|
const FAMILIES = { 4: 'IPv4', 6: 'IPv6' }
|
|
5
7
|
|
|
@@ -14,6 +16,10 @@ function getNetworkAddrs (family: 4 | 6): string[] {
|
|
|
14
16
|
for (const [, netAddrs] of Object.entries(networks)) {
|
|
15
17
|
if (netAddrs != null) {
|
|
16
18
|
for (const netAddr of netAddrs) {
|
|
19
|
+
if (isLinkLocalIp(netAddr.address)) {
|
|
20
|
+
continue
|
|
21
|
+
}
|
|
22
|
+
|
|
17
23
|
if (netAddr.family === FAMILIES[family]) {
|
|
18
24
|
addresses.push(netAddr.address)
|
|
19
25
|
}
|
|
@@ -26,24 +32,28 @@ function getNetworkAddrs (family: 4 | 6): string[] {
|
|
|
26
32
|
|
|
27
33
|
/**
|
|
28
34
|
* Get all thin waist addresses on the current host that match the family of the
|
|
29
|
-
* passed multiaddr.
|
|
35
|
+
* passed multiaddr and optionally override the port.
|
|
30
36
|
*
|
|
31
37
|
* Wildcard IP4/6 addresses will be expanded into all available interfaces.
|
|
32
38
|
*/
|
|
33
|
-
export function getThinWaistAddresses (ma
|
|
39
|
+
export function getThinWaistAddresses (ma?: Multiaddr, port?: number): Multiaddr[] {
|
|
40
|
+
if (ma == null) {
|
|
41
|
+
return []
|
|
42
|
+
}
|
|
43
|
+
|
|
34
44
|
const options = ma.toOptions()
|
|
35
45
|
|
|
36
46
|
if (isWildcard(options.host)) {
|
|
37
47
|
const addrs = []
|
|
38
48
|
|
|
39
49
|
for (const host of getNetworkAddrs(options.family)) {
|
|
40
|
-
addrs.push(multiaddr(`/ip${options.family}/${host}/${options.transport}/${options.port}`))
|
|
50
|
+
addrs.push(multiaddr(`/ip${options.family}/${host}/${options.transport}/${port ?? options.port}`))
|
|
41
51
|
}
|
|
42
52
|
|
|
43
53
|
return addrs
|
|
44
54
|
}
|
|
45
55
|
|
|
46
56
|
return [
|
|
47
|
-
multiaddr(`/ip${options.family}/${options.host}/${options.transport}/${options.port}`)
|
|
57
|
+
multiaddr(`/ip${options.family}/${options.host}/${options.transport}/${port ?? options.port}`)
|
|
48
58
|
]
|
|
49
59
|
}
|
package/src/link-local-ip.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { isIPv4, isIPv6 } from '@chainsafe/is-ip'
|
|
2
|
-
|
|
3
1
|
export function isLinkLocalIp (ip: string): boolean {
|
|
4
|
-
if (
|
|
5
|
-
return
|
|
2
|
+
if (ip.startsWith('169.254.')) {
|
|
3
|
+
return true
|
|
6
4
|
}
|
|
7
5
|
|
|
8
|
-
if (
|
|
9
|
-
return
|
|
6
|
+
if (ip.toLowerCase().startsWith('fe80')) {
|
|
7
|
+
return true
|
|
10
8
|
}
|
|
11
9
|
|
|
12
10
|
return false
|