libp2p 0.46.12-e8123d3f → 0.46.12-e9099d40
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/index.min.js +30 -27
- package/dist/src/address-manager/utils.d.ts +3 -0
- package/dist/src/address-manager/utils.d.ts.map +1 -1
- package/dist/src/address-manager/utils.js +10 -0
- package/dist/src/address-manager/utils.js.map +1 -1
- package/dist/src/autonat/index.d.ts.map +1 -1
- package/dist/src/autonat/index.js +15 -6
- package/dist/src/autonat/index.js.map +1 -1
- package/dist/src/circuit-relay/constants.d.ts +4 -0
- package/dist/src/circuit-relay/constants.d.ts.map +1 -1
- package/dist/src/circuit-relay/constants.js +4 -0
- package/dist/src/circuit-relay/constants.js.map +1 -1
- package/dist/src/circuit-relay/server/index.d.ts.map +1 -1
- package/dist/src/circuit-relay/server/index.js +20 -8
- package/dist/src/circuit-relay/server/index.js.map +1 -1
- package/dist/src/circuit-relay/server/reservation-store.d.ts.map +1 -1
- package/dist/src/circuit-relay/server/reservation-store.js +15 -6
- package/dist/src/circuit-relay/server/reservation-store.js.map +1 -1
- package/dist/src/circuit-relay/transport/index.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/index.js +13 -11
- package/dist/src/circuit-relay/transport/index.js.map +1 -1
- package/dist/src/{config.d.ts → config/config.d.ts} +1 -1
- package/dist/src/config/config.d.ts.map +1 -0
- package/dist/src/config/config.js +35 -0
- package/dist/src/config/config.js.map +1 -0
- package/dist/src/config/helpers.d.ts +2 -0
- package/dist/src/config/helpers.d.ts.map +1 -0
- package/dist/src/config/helpers.js +13 -0
- package/dist/src/config/helpers.js.map +1 -0
- package/dist/src/connection-manager/utils.d.ts +3 -0
- package/dist/src/connection-manager/utils.d.ts.map +1 -1
- package/dist/src/connection-manager/utils.js +21 -0
- package/dist/src/connection-manager/utils.js.map +1 -1
- package/dist/src/dcutr/dcutr.d.ts.map +1 -1
- package/dist/src/dcutr/dcutr.js +13 -12
- package/dist/src/dcutr/dcutr.js.map +1 -1
- package/dist/src/fetch/constants.d.ts +3 -0
- package/dist/src/fetch/constants.d.ts.map +1 -1
- package/dist/src/fetch/constants.js +3 -0
- package/dist/src/fetch/constants.js.map +1 -1
- package/dist/src/fetch/index.d.ts.map +1 -1
- package/dist/src/fetch/index.js +19 -9
- package/dist/src/fetch/index.js.map +1 -1
- package/dist/src/identify/consts.d.ts +11 -1
- package/dist/src/identify/consts.d.ts.map +1 -1
- package/dist/src/identify/consts.js +10 -0
- package/dist/src/identify/consts.js.map +1 -1
- package/dist/src/identify/identify.d.ts +1 -0
- package/dist/src/identify/identify.d.ts.map +1 -1
- package/dist/src/identify/identify.js +31 -31
- package/dist/src/identify/identify.js.map +1 -1
- package/dist/src/identify/index.d.ts.map +1 -1
- package/dist/src/identify/index.js.map +1 -1
- package/dist/src/libp2p.js +1 -1
- package/dist/src/libp2p.js.map +1 -1
- package/dist/src/ping/index.d.ts.map +1 -1
- package/dist/src/ping/index.js +13 -5
- package/dist/src/ping/index.js.map +1 -1
- package/dist/src/upnp-nat/index.d.ts +1 -1
- package/dist/src/upnp-nat/index.d.ts.map +1 -1
- package/dist/src/upnp-nat/index.js +16 -6
- package/dist/src/upnp-nat/index.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +23 -22
- package/src/address-manager/utils.ts +14 -0
- package/src/autonat/index.ts +16 -6
- package/src/circuit-relay/constants.ts +5 -0
- package/src/circuit-relay/server/index.ts +24 -8
- package/src/circuit-relay/server/reservation-store.ts +16 -6
- package/src/circuit-relay/transport/index.ts +16 -14
- package/src/config/config.ts +44 -0
- package/src/config/helpers.ts +12 -0
- package/src/connection-manager/utils.ts +23 -0
- package/src/dcutr/dcutr.ts +14 -13
- package/src/fetch/constants.ts +4 -0
- package/src/fetch/index.ts +21 -10
- package/src/identify/consts.ts +13 -0
- package/src/identify/identify.ts +42 -33
- package/src/identify/index.ts +1 -4
- package/src/libp2p.ts +1 -1
- package/src/ping/index.ts +15 -5
- package/src/upnp-nat/index.ts +20 -8
- package/src/version.ts +1 -1
- package/dist/src/config.d.ts.map +0 -1
- package/dist/src/config.js +0 -34
- package/dist/src/config.js.map +0 -1
- package/src/config.ts +0 -41
|
@@ -2,6 +2,10 @@ import { setMaxListeners } from 'events'
|
|
|
2
2
|
import { logger } from '@libp2p/logger'
|
|
3
3
|
import { type AbortOptions, multiaddr, type Multiaddr } from '@multiformats/multiaddr'
|
|
4
4
|
import { type ClearableSignal, anySignal } from 'any-signal'
|
|
5
|
+
import { type ObjectSchema, array, number, object, string } from 'yup'
|
|
6
|
+
import { validateMultiaddr } from '../config/helpers.js'
|
|
7
|
+
import { AUTO_DIAL_CONCURRENCY, AUTO_DIAL_INTERVAL, AUTO_DIAL_PRIORITY, DIAL_TIMEOUT, INBOUND_CONNECTION_THRESHOLD, INBOUND_UPGRADE_TIMEOUT, MAX_CONNECTIONS, MAX_INCOMING_PENDING_CONNECTIONS, MAX_PARALLEL_DIALS, MAX_PARALLEL_DIALS_PER_PEER, MAX_PEER_ADDRS_TO_DIAL, MIN_CONNECTIONS } from './constants.js'
|
|
8
|
+
import type { ConnectionManagerInit } from '.'
|
|
5
9
|
|
|
6
10
|
const log = logger('libp2p:connection-manager:utils')
|
|
7
11
|
|
|
@@ -73,3 +77,22 @@ export function combineSignals (...signals: Array<AbortSignal | undefined>): Cle
|
|
|
73
77
|
|
|
74
78
|
return signal
|
|
75
79
|
}
|
|
80
|
+
|
|
81
|
+
export const validateConnectionManagerConfig = (opts: ConnectionManagerInit): ObjectSchema<Record<string, unknown>> => {
|
|
82
|
+
return object({
|
|
83
|
+
maxConnections: number().min(opts?.minConnections ?? MIN_CONNECTIONS, `maxConnections must be greater than the min connections limit: ${opts?.minConnections}`).integer().default(MAX_CONNECTIONS),
|
|
84
|
+
minConnections: number().min(0).integer().max(opts?.maxConnections ?? MAX_CONNECTIONS, `minConnections must be less than the max connections limit: ${opts?.maxConnections}`).default(MIN_CONNECTIONS),
|
|
85
|
+
autoDialInterval: number().min(0).integer().default(AUTO_DIAL_INTERVAL),
|
|
86
|
+
autoDialConcurrency: number().min(0).integer().default(AUTO_DIAL_CONCURRENCY),
|
|
87
|
+
autoDialPriority: number().min(0).integer().default(AUTO_DIAL_PRIORITY),
|
|
88
|
+
maxParallelDials: number().min(0).integer().default(MAX_PARALLEL_DIALS),
|
|
89
|
+
maxParallelDialsPerPeer: number().max(opts?.autoDialConcurrency ?? AUTO_DIAL_CONCURRENCY, `maxParallelDialsPerPeer must be less than the min auto dial conccurency limit: ${opts?.autoDialConcurrency}`).default(MAX_PARALLEL_DIALS_PER_PEER),
|
|
90
|
+
maxPeerAddrsToDialed: number().min(0).integer().default(MAX_PEER_ADDRS_TO_DIAL),
|
|
91
|
+
dialTimeout: number().min(0).integer().default(DIAL_TIMEOUT),
|
|
92
|
+
inboundUpgradeTimeout: number().integer().default(INBOUND_UPGRADE_TIMEOUT),
|
|
93
|
+
allow: array().of(string()).test('is multiaddr', validateMultiaddr).optional(),
|
|
94
|
+
deny: array().of(string()).test('is multiaddr', validateMultiaddr).optional(),
|
|
95
|
+
inboundConnectionThreshold: number().max(opts?.maxConnections ?? MAX_CONNECTIONS, `inboundConnectionThreshold must be less than the max connections limit: ${opts?.inboundConnectionThreshold}`).integer().default(INBOUND_CONNECTION_THRESHOLD),
|
|
96
|
+
maxIncomingPendingConnections: number().integer().max(opts?.maxConnections ?? MAX_CONNECTIONS, `maxIncomingPendingConnections must be less than the max connections limit: ${opts?.maxIncomingPendingConnections}`).default(MAX_INCOMING_PENDING_CONNECTIONS)
|
|
97
|
+
})
|
|
98
|
+
}
|
package/src/dcutr/dcutr.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { Circuit, IP, DNS } from '@multiformats/multiaddr-matcher'
|
|
|
5
5
|
import delay from 'delay'
|
|
6
6
|
import { pbStream } from 'it-protobuf-stream'
|
|
7
7
|
import isPrivate from 'private-ip'
|
|
8
|
+
import { number, object } from 'yup'
|
|
8
9
|
import { codes } from '../errors.js'
|
|
9
10
|
import { HolePunch } from './pb/message.js'
|
|
10
11
|
import { multicodec } from './index.js'
|
|
@@ -24,15 +25,6 @@ const MAX_DCUTR_MESSAGE_SIZE = 1024 * 4
|
|
|
24
25
|
// ensure the dial has a high priority to jump to the head of the dial queue
|
|
25
26
|
const DCUTR_DIAL_PRIORITY = 100
|
|
26
27
|
|
|
27
|
-
const defaultValues = {
|
|
28
|
-
// https://github.com/libp2p/go-libp2p/blob/8d2e54e1637041d5cf4fac1e531287560bd1f4ac/p2p/protocol/holepunch/holepuncher.go#L27
|
|
29
|
-
timeout: 5000,
|
|
30
|
-
// https://github.com/libp2p/go-libp2p/blob/8d2e54e1637041d5cf4fac1e531287560bd1f4ac/p2p/protocol/holepunch/holepuncher.go#L28
|
|
31
|
-
retries: 3,
|
|
32
|
-
maxInboundStreams: 1,
|
|
33
|
-
maxOutboundStreams: 1
|
|
34
|
-
}
|
|
35
|
-
|
|
36
28
|
export class DefaultDCUtRService implements Startable {
|
|
37
29
|
private started: boolean
|
|
38
30
|
private readonly timeout: number
|
|
@@ -54,10 +46,19 @@ export class DefaultDCUtRService implements Startable {
|
|
|
54
46
|
this.connectionManager = components.connectionManager
|
|
55
47
|
this.transportManager = components.transportManager
|
|
56
48
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
49
|
+
const validatedConfig = object({
|
|
50
|
+
// https://github.com/libp2p/go-libp2p/blob/8d2e54e1637041d5cf4fac1e531287560bd1f4ac/p2p/protocol/holepunch/holepuncher.go#L27
|
|
51
|
+
timeout: number().integer().default(5000).min(1),
|
|
52
|
+
// https://github.com/libp2p/go-libp2p/blob/8d2e54e1637041d5cf4fac1e531287560bd1f4ac/p2p/protocol/holepunch/holepuncher.go#L28
|
|
53
|
+
retries: number().integer().default(3).min(1),
|
|
54
|
+
maxInboundStreams: number().integer().default(1).min(1),
|
|
55
|
+
maxOutboundStreams: number().integer().default(1).min(1)
|
|
56
|
+
}).validateSync(init)
|
|
57
|
+
|
|
58
|
+
this.timeout = validatedConfig.timeout
|
|
59
|
+
this.retries = validatedConfig.retries
|
|
60
|
+
this.maxInboundStreams = validatedConfig.maxInboundStreams
|
|
61
|
+
this.maxOutboundStreams = validatedConfig.maxOutboundStreams
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
isStarted (): boolean {
|
package/src/fetch/constants.ts
CHANGED
package/src/fetch/index.ts
CHANGED
|
@@ -6,8 +6,9 @@ import * as lp from 'it-length-prefixed'
|
|
|
6
6
|
import { pipe } from 'it-pipe'
|
|
7
7
|
import { fromString as uint8arrayFromString } from 'uint8arrays/from-string'
|
|
8
8
|
import { toString as uint8arrayToString } from 'uint8arrays/to-string'
|
|
9
|
+
import { number, object, string } from 'yup'
|
|
9
10
|
import { codes } from '../errors.js'
|
|
10
|
-
import { PROTOCOL_NAME, PROTOCOL_VERSION } from './constants.js'
|
|
11
|
+
import { MAX_INBOUND_STREAMS, MAX_OUTBOUND_STREAMS, PROTOCOL_NAME, PROTOCOL_VERSION, TIMEOUT } from './constants.js'
|
|
11
12
|
import { FetchRequest, FetchResponse } from './pb/proto.js'
|
|
12
13
|
import type { AbortOptions } from '@libp2p/interface'
|
|
13
14
|
import type { Stream } from '@libp2p/interface/connection'
|
|
@@ -18,8 +19,6 @@ import type { IncomingStreamData, Registrar } from '@libp2p/interface-internal/r
|
|
|
18
19
|
|
|
19
20
|
const log = logger('libp2p:fetch')
|
|
20
21
|
|
|
21
|
-
const DEFAULT_TIMEOUT = 10000
|
|
22
|
-
|
|
23
22
|
export interface FetchServiceInit {
|
|
24
23
|
protocolPrefix?: string
|
|
25
24
|
maxInboundStreams?: number
|
|
@@ -94,15 +93,27 @@ class DefaultFetchService implements Startable, FetchService {
|
|
|
94
93
|
private readonly components: FetchServiceComponents
|
|
95
94
|
private readonly lookupFunctions: Map<string, LookupFunction>
|
|
96
95
|
private started: boolean
|
|
97
|
-
private readonly
|
|
96
|
+
private readonly timeout: number
|
|
97
|
+
private readonly maxInboundStreams: number
|
|
98
|
+
private readonly maxOutboundStreams: number
|
|
98
99
|
|
|
99
100
|
constructor (components: FetchServiceComponents, init: FetchServiceInit) {
|
|
101
|
+
const validatedConfig = object({
|
|
102
|
+
protocolPrefix: string().default('libp2p'),
|
|
103
|
+
timeout: number().integer().default(TIMEOUT),
|
|
104
|
+
maxInboundStreams: number().integer().min(0).default(MAX_INBOUND_STREAMS),
|
|
105
|
+
maxOutboundStreams: number().integer().min(0).default(MAX_OUTBOUND_STREAMS)
|
|
106
|
+
}).validateSync(init)
|
|
107
|
+
|
|
100
108
|
this.started = false
|
|
101
109
|
this.components = components
|
|
102
|
-
this.protocol = `/${
|
|
110
|
+
this.protocol = `/${validatedConfig.protocolPrefix}/${PROTOCOL_NAME}/${PROTOCOL_VERSION}`
|
|
111
|
+
this.timeout = validatedConfig.timeout
|
|
112
|
+
this.maxInboundStreams = validatedConfig.maxInboundStreams
|
|
113
|
+
this.maxOutboundStreams = validatedConfig.maxOutboundStreams
|
|
114
|
+
|
|
103
115
|
this.lookupFunctions = new Map() // Maps key prefix to value lookup function
|
|
104
116
|
this.handleMessage = this.handleMessage.bind(this)
|
|
105
|
-
this.init = init
|
|
106
117
|
}
|
|
107
118
|
|
|
108
119
|
async start (): Promise<void> {
|
|
@@ -115,8 +126,8 @@ class DefaultFetchService implements Startable, FetchService {
|
|
|
115
126
|
log.error(err)
|
|
116
127
|
})
|
|
117
128
|
}, {
|
|
118
|
-
maxInboundStreams: this.
|
|
119
|
-
maxOutboundStreams: this.
|
|
129
|
+
maxInboundStreams: this.maxInboundStreams,
|
|
130
|
+
maxOutboundStreams: this.maxOutboundStreams
|
|
120
131
|
})
|
|
121
132
|
this.started = true
|
|
122
133
|
}
|
|
@@ -143,8 +154,8 @@ class DefaultFetchService implements Startable, FetchService {
|
|
|
143
154
|
|
|
144
155
|
// create a timeout if no abort signal passed
|
|
145
156
|
if (signal == null) {
|
|
146
|
-
log('using default timeout of %d ms', this.
|
|
147
|
-
signal = AbortSignal.timeout(this.
|
|
157
|
+
log('using default timeout of %d ms', this.timeout)
|
|
158
|
+
signal = AbortSignal.timeout(this.timeout)
|
|
148
159
|
|
|
149
160
|
try {
|
|
150
161
|
// fails on node < 15.4
|
package/src/identify/consts.ts
CHANGED
|
@@ -5,8 +5,21 @@ export const AGENT_VERSION = `js-libp2p/${version}`
|
|
|
5
5
|
export const MULTICODEC_IDENTIFY = '/ipfs/id/1.0.0' // deprecated
|
|
6
6
|
export const MULTICODEC_IDENTIFY_PUSH = '/ipfs/id/push/1.0.0' // deprecated
|
|
7
7
|
|
|
8
|
+
export const PROTOCOL_PREFIX = 'ipfs'
|
|
9
|
+
export const MAX_IDENTIFY_MESSAGE_SIZE = 1024 * 8 // https://github.com/libp2p/go-libp2p/blob/8d2e54e1637041d5cf4fac1e531287560bd1f4ac/p2p/protocol/identify/id.go#L52
|
|
10
|
+
export const MAX_INBOUND_STREAMS = 1
|
|
11
|
+
export const MAX_OUTBOUND_STREAMS = 1
|
|
12
|
+
export const MAX_PUSH_INCOMING_STREAMS = 1
|
|
13
|
+
export const MAX_PUSH_OUTGOING_STREAMS = 1
|
|
14
|
+
export const MAX_OBSERVED_ADDRESSES = 10
|
|
15
|
+
|
|
16
|
+
export const RUN_ON_TRANSIENT_CONNECTION = true
|
|
17
|
+
export const RUN_ON_CONNECTION_OPEN = true
|
|
18
|
+
|
|
8
19
|
export const IDENTIFY_PROTOCOL_VERSION = '0.1.0'
|
|
9
20
|
export const MULTICODEC_IDENTIFY_PROTOCOL_NAME = 'id'
|
|
10
21
|
export const MULTICODEC_IDENTIFY_PUSH_PROTOCOL_NAME = 'id/push'
|
|
11
22
|
export const MULTICODEC_IDENTIFY_PROTOCOL_VERSION = '1.0.0'
|
|
12
23
|
export const MULTICODEC_IDENTIFY_PUSH_PROTOCOL_VERSION = '1.0.0'
|
|
24
|
+
|
|
25
|
+
export const TIMEOUT = 60000
|
package/src/identify/identify.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { pbStream } from 'it-protobuf-stream'
|
|
|
8
8
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
9
9
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
10
10
|
import { isNode, isBrowser, isWebWorker, isElectronMain, isElectronRenderer, isReactNative } from 'wherearewe'
|
|
11
|
+
import { boolean, number, object, string } from 'yup'
|
|
11
12
|
import { codes } from '../errors.js'
|
|
12
13
|
import {
|
|
13
14
|
AGENT_VERSION,
|
|
@@ -15,7 +16,17 @@ import {
|
|
|
15
16
|
MULTICODEC_IDENTIFY_PROTOCOL_NAME,
|
|
16
17
|
MULTICODEC_IDENTIFY_PUSH_PROTOCOL_NAME,
|
|
17
18
|
MULTICODEC_IDENTIFY_PROTOCOL_VERSION,
|
|
18
|
-
MULTICODEC_IDENTIFY_PUSH_PROTOCOL_VERSION
|
|
19
|
+
MULTICODEC_IDENTIFY_PUSH_PROTOCOL_VERSION,
|
|
20
|
+
MAX_INBOUND_STREAMS,
|
|
21
|
+
MAX_OUTBOUND_STREAMS,
|
|
22
|
+
MAX_IDENTIFY_MESSAGE_SIZE,
|
|
23
|
+
TIMEOUT,
|
|
24
|
+
RUN_ON_CONNECTION_OPEN,
|
|
25
|
+
PROTOCOL_PREFIX,
|
|
26
|
+
RUN_ON_TRANSIENT_CONNECTION,
|
|
27
|
+
MAX_PUSH_INCOMING_STREAMS,
|
|
28
|
+
MAX_PUSH_OUTGOING_STREAMS,
|
|
29
|
+
MAX_OBSERVED_ADDRESSES
|
|
19
30
|
} from './consts.js'
|
|
20
31
|
import { Identify } from './pb/message.js'
|
|
21
32
|
import type { IdentifyService, IdentifyServiceComponents, IdentifyServiceInit } from './index.js'
|
|
@@ -31,24 +42,6 @@ import type { IncomingStreamData, Registrar } from '@libp2p/interface-internal/r
|
|
|
31
42
|
|
|
32
43
|
const log = logger('libp2p:identify')
|
|
33
44
|
|
|
34
|
-
// https://github.com/libp2p/go-libp2p/blob/8d2e54e1637041d5cf4fac1e531287560bd1f4ac/p2p/protocol/identify/id.go#L52
|
|
35
|
-
const MAX_IDENTIFY_MESSAGE_SIZE = 1024 * 8
|
|
36
|
-
|
|
37
|
-
const defaultValues = {
|
|
38
|
-
protocolPrefix: 'ipfs',
|
|
39
|
-
agentVersion: AGENT_VERSION,
|
|
40
|
-
// https://github.com/libp2p/go-libp2p/blob/8d2e54e1637041d5cf4fac1e531287560bd1f4ac/p2p/protocol/identify/id.go#L48
|
|
41
|
-
timeout: 60000,
|
|
42
|
-
maxInboundStreams: 1,
|
|
43
|
-
maxOutboundStreams: 1,
|
|
44
|
-
maxPushIncomingStreams: 1,
|
|
45
|
-
maxPushOutgoingStreams: 1,
|
|
46
|
-
maxObservedAddresses: 10,
|
|
47
|
-
maxIdentifyMessageSize: 8192,
|
|
48
|
-
runOnConnectionOpen: true,
|
|
49
|
-
runOnTransientConnection: true
|
|
50
|
-
}
|
|
51
|
-
|
|
52
45
|
export class DefaultIdentifyService implements Startable, IdentifyService {
|
|
53
46
|
private readonly identifyProtocolStr: string
|
|
54
47
|
private readonly identifyPushProtocolStr: string
|
|
@@ -72,8 +65,23 @@ export class DefaultIdentifyService implements Startable, IdentifyService {
|
|
|
72
65
|
private readonly maxObservedAddresses: number
|
|
73
66
|
private readonly events: EventEmitter<Libp2pEvents>
|
|
74
67
|
private readonly runOnTransientConnection: boolean
|
|
68
|
+
private readonly runOnConnectionOpen: boolean
|
|
75
69
|
|
|
76
70
|
constructor (components: IdentifyServiceComponents, init: IdentifyServiceInit) {
|
|
71
|
+
const validatedConfig = object({
|
|
72
|
+
protocolPrefix: string().default(PROTOCOL_PREFIX),
|
|
73
|
+
agentVersion: string().default(AGENT_VERSION),
|
|
74
|
+
timeout: number().integer().default(TIMEOUT),
|
|
75
|
+
maxIdentifyMessageSize: number().integer().min(0).default(MAX_IDENTIFY_MESSAGE_SIZE),
|
|
76
|
+
maxInboundStreams: number().integer().min(0).default(MAX_INBOUND_STREAMS),
|
|
77
|
+
maxPushIncomingStreams: number().integer().min(0).default(MAX_PUSH_INCOMING_STREAMS),
|
|
78
|
+
maxPushOutgoingStreams: number().integer().min(0).default(MAX_PUSH_OUTGOING_STREAMS),
|
|
79
|
+
maxOutboundStreams: number().integer().min(0).default(MAX_OUTBOUND_STREAMS),
|
|
80
|
+
maxObservedAddresses: number().integer().min(0).default(MAX_OBSERVED_ADDRESSES),
|
|
81
|
+
runOnConnectionOpen: boolean().default(RUN_ON_CONNECTION_OPEN),
|
|
82
|
+
runOnTransientConnection: boolean().default(RUN_ON_TRANSIENT_CONNECTION)
|
|
83
|
+
}).validateSync(init)
|
|
84
|
+
|
|
77
85
|
this.started = false
|
|
78
86
|
this.peerId = components.peerId
|
|
79
87
|
this.peerStore = components.peerStore
|
|
@@ -82,24 +90,25 @@ export class DefaultIdentifyService implements Startable, IdentifyService {
|
|
|
82
90
|
this.connectionManager = components.connectionManager
|
|
83
91
|
this.events = components.events
|
|
84
92
|
|
|
85
|
-
this.identifyProtocolStr = `/${
|
|
86
|
-
this.identifyPushProtocolStr = `/${
|
|
87
|
-
this.timeout =
|
|
88
|
-
this.maxInboundStreams =
|
|
89
|
-
this.maxOutboundStreams =
|
|
90
|
-
this.maxPushIncomingStreams =
|
|
91
|
-
this.maxPushOutgoingStreams =
|
|
92
|
-
this.maxIdentifyMessageSize =
|
|
93
|
-
this.maxObservedAddresses =
|
|
94
|
-
this.runOnTransientConnection =
|
|
93
|
+
this.identifyProtocolStr = `/${validatedConfig.protocolPrefix}/${MULTICODEC_IDENTIFY_PROTOCOL_NAME}/${MULTICODEC_IDENTIFY_PROTOCOL_VERSION}`
|
|
94
|
+
this.identifyPushProtocolStr = `/${validatedConfig.protocolPrefix}/${MULTICODEC_IDENTIFY_PUSH_PROTOCOL_NAME}/${MULTICODEC_IDENTIFY_PUSH_PROTOCOL_VERSION}`
|
|
95
|
+
this.timeout = validatedConfig.timeout
|
|
96
|
+
this.maxInboundStreams = validatedConfig.maxInboundStreams
|
|
97
|
+
this.maxOutboundStreams = validatedConfig.maxOutboundStreams
|
|
98
|
+
this.maxPushIncomingStreams = validatedConfig.maxPushIncomingStreams
|
|
99
|
+
this.maxPushOutgoingStreams = validatedConfig.maxPushOutgoingStreams
|
|
100
|
+
this.maxIdentifyMessageSize = validatedConfig.maxIdentifyMessageSize
|
|
101
|
+
this.maxObservedAddresses = validatedConfig.maxObservedAddresses
|
|
102
|
+
this.runOnTransientConnection = validatedConfig.runOnTransientConnection
|
|
103
|
+
this.runOnConnectionOpen = validatedConfig.runOnConnectionOpen
|
|
95
104
|
|
|
96
105
|
// Store self host metadata
|
|
97
106
|
this.host = {
|
|
98
|
-
protocolVersion: `${
|
|
99
|
-
agentVersion:
|
|
107
|
+
protocolVersion: `${validatedConfig.protocolPrefix}/${IDENTIFY_PROTOCOL_VERSION}`,
|
|
108
|
+
agentVersion: validatedConfig.agentVersion
|
|
100
109
|
}
|
|
101
110
|
|
|
102
|
-
if (
|
|
111
|
+
if (this.runOnConnectionOpen) {
|
|
103
112
|
// When a new connection happens, trigger identify
|
|
104
113
|
components.events.addEventListener('connection:open', (evt) => {
|
|
105
114
|
const connection = evt.detail
|
|
@@ -313,7 +322,7 @@ export class DefaultIdentifyService implements Startable, IdentifyService {
|
|
|
313
322
|
log('our observed address is %a', cleanObservedAddr)
|
|
314
323
|
|
|
315
324
|
if (cleanObservedAddr != null &&
|
|
316
|
-
this.addressManager.getObservedAddrs().length < (this.maxObservedAddresses
|
|
325
|
+
this.addressManager.getObservedAddrs().length < (this.maxObservedAddresses)) {
|
|
317
326
|
log('storing our observed address %a', cleanObservedAddr)
|
|
318
327
|
this.addressManager.addObservedAddr(cleanObservedAddr)
|
|
319
328
|
}
|
package/src/identify/index.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
MULTICODEC_IDENTIFY,
|
|
3
|
-
MULTICODEC_IDENTIFY_PUSH
|
|
4
|
-
} from './consts.js'
|
|
1
|
+
import { MULTICODEC_IDENTIFY, MULTICODEC_IDENTIFY_PUSH } from './consts.js'
|
|
5
2
|
import { DefaultIdentifyService } from './identify.js'
|
|
6
3
|
import { Identify } from './pb/message.js'
|
|
7
4
|
import type { AbortOptions, IdentifyResult, Libp2pEvents } from '@libp2p/interface'
|
package/src/libp2p.ts
CHANGED
|
@@ -18,8 +18,8 @@ import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
|
|
|
18
18
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
19
19
|
import { DefaultAddressManager } from './address-manager/index.js'
|
|
20
20
|
import { defaultComponents } from './components.js'
|
|
21
|
+
import { validateConfig } from './config/config.js'
|
|
21
22
|
import { connectionGater } from './config/connection-gater.js'
|
|
22
|
-
import { validateConfig } from './config.js'
|
|
23
23
|
import { DefaultConnectionManager } from './connection-manager/index.js'
|
|
24
24
|
import { CompoundContentRouting } from './content-routing/index.js'
|
|
25
25
|
import { codes } from './errors.js'
|
package/src/ping/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { logger } from '@libp2p/logger'
|
|
|
4
4
|
import first from 'it-first'
|
|
5
5
|
import { pipe } from 'it-pipe'
|
|
6
6
|
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
|
|
7
|
+
import { boolean, number, object, string } from 'yup'
|
|
7
8
|
import { codes } from '../errors.js'
|
|
8
9
|
import { PROTOCOL_PREFIX, PROTOCOL_NAME, PING_LENGTH, PROTOCOL_VERSION, TIMEOUT, MAX_INBOUND_STREAMS, MAX_OUTBOUND_STREAMS } from './constants.js'
|
|
9
10
|
import type { AbortOptions } from '@libp2p/interface'
|
|
@@ -49,11 +50,20 @@ class DefaultPingService implements Startable, PingService {
|
|
|
49
50
|
constructor (components: PingServiceComponents, init: PingServiceInit) {
|
|
50
51
|
this.components = components
|
|
51
52
|
this.started = false
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
|
|
54
|
+
const validatedConfig = object({
|
|
55
|
+
protocolPrefix: string().default(PROTOCOL_PREFIX),
|
|
56
|
+
timeout: number().integer().default(TIMEOUT),
|
|
57
|
+
maxInboundStreams: number().integer().min(0).default(MAX_INBOUND_STREAMS),
|
|
58
|
+
maxOutboundStreams: number().integer().min(0).default(MAX_OUTBOUND_STREAMS),
|
|
59
|
+
runOnTransientConnection: boolean().default(true)
|
|
60
|
+
}).validateSync(init)
|
|
61
|
+
|
|
62
|
+
this.protocol = `/${validatedConfig.protocolPrefix}/${PROTOCOL_NAME}/${PROTOCOL_VERSION}`
|
|
63
|
+
this.timeout = validatedConfig.timeout
|
|
64
|
+
this.maxInboundStreams = validatedConfig.maxInboundStreams
|
|
65
|
+
this.maxOutboundStreams = validatedConfig.maxOutboundStreams
|
|
66
|
+
this.runOnTransientConnection = validatedConfig.runOnTransientConnection
|
|
57
67
|
}
|
|
58
68
|
|
|
59
69
|
async start (): Promise<void> {
|
package/src/upnp-nat/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { isLoopback } from '@libp2p/utils/multiaddr/is-loopback'
|
|
|
5
5
|
import { fromNodeAddress } from '@multiformats/multiaddr'
|
|
6
6
|
import isPrivateIp from 'private-ip'
|
|
7
7
|
import { isBrowser } from 'wherearewe'
|
|
8
|
+
import { boolean, number, object, string } from 'yup'
|
|
8
9
|
import { codes } from '../errors.js'
|
|
9
10
|
import * as pkg from '../version.js'
|
|
10
11
|
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
@@ -70,21 +71,32 @@ class UPnPNAT implements Startable {
|
|
|
70
71
|
private readonly localAddress?: string
|
|
71
72
|
private readonly description: string
|
|
72
73
|
private readonly ttl: number
|
|
73
|
-
private readonly keepAlive
|
|
74
|
+
private readonly keepAlive?: boolean
|
|
74
75
|
private readonly gateway?: string
|
|
75
76
|
private started: boolean
|
|
76
77
|
private client?: NatAPI
|
|
77
78
|
|
|
78
79
|
constructor (components: UPnPNATComponents, init: UPnPNATInit) {
|
|
79
80
|
this.components = components
|
|
80
|
-
|
|
81
81
|
this.started = false
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
82
|
+
|
|
83
|
+
const validIPRegex = /^(?:(?:^|\.)(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])){4}$/
|
|
84
|
+
|
|
85
|
+
const validatedConfig = object({
|
|
86
|
+
externalAddress: string().matches(validIPRegex, 'Invalid IP address'),
|
|
87
|
+
localAddress: string().matches(validIPRegex, 'Invalid IP address'),
|
|
88
|
+
description: string().default(`${pkg.name}@${pkg.version} ${this.components.peerId.toString()}`),
|
|
89
|
+
ttl: number().integer().default(DEFAULT_TTL),
|
|
90
|
+
keepAlive: boolean().default(true),
|
|
91
|
+
gateway: string().optional()
|
|
92
|
+
}).validateSync(init)
|
|
93
|
+
|
|
94
|
+
this.externalAddress = validatedConfig.externalAddress
|
|
95
|
+
this.localAddress = validatedConfig.localAddress
|
|
96
|
+
this.description = validatedConfig.description
|
|
97
|
+
this.ttl = validatedConfig.ttl
|
|
98
|
+
this.keepAlive = validatedConfig.keepAlive
|
|
99
|
+
this.gateway = validatedConfig.gateway
|
|
88
100
|
|
|
89
101
|
if (this.ttl < DEFAULT_TTL) {
|
|
90
102
|
throw new CodeError(`NatManager ttl should be at least ${DEFAULT_TTL} seconds`, codes.ERR_INVALID_PARAMETERS)
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version = '0.46.12-
|
|
1
|
+
export const version = '0.46.12-e9099d40'
|
|
2
2
|
export const name = 'libp2p'
|
package/dist/src/config.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAqBrE,wBAAgB,cAAc,CAAE,CAAC,SAAS,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAG,IAAI,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAYrI"}
|
package/dist/src/config.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { CodeError } from '@libp2p/interface/errors';
|
|
2
|
-
import { FaultTolerance } from '@libp2p/interface/transport';
|
|
3
|
-
import { defaultAddressSort } from '@libp2p/utils/address-sort';
|
|
4
|
-
import { dnsaddrResolver } from '@multiformats/multiaddr/resolvers';
|
|
5
|
-
import mergeOptions from 'merge-options';
|
|
6
|
-
import { codes, messages } from './errors.js';
|
|
7
|
-
const DefaultConfig = {
|
|
8
|
-
addresses: {
|
|
9
|
-
listen: [],
|
|
10
|
-
announce: [],
|
|
11
|
-
noAnnounce: [],
|
|
12
|
-
announceFilter: (multiaddrs) => multiaddrs
|
|
13
|
-
},
|
|
14
|
-
connectionManager: {
|
|
15
|
-
resolvers: {
|
|
16
|
-
dnsaddr: dnsaddrResolver
|
|
17
|
-
},
|
|
18
|
-
addressSorter: defaultAddressSort
|
|
19
|
-
},
|
|
20
|
-
transportManager: {
|
|
21
|
-
faultTolerance: FaultTolerance.FATAL_ALL
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
export function validateConfig(opts) {
|
|
25
|
-
const resultingOptions = mergeOptions(DefaultConfig, opts);
|
|
26
|
-
if (resultingOptions.transports == null || resultingOptions.transports.length < 1) {
|
|
27
|
-
throw new CodeError(messages.ERR_TRANSPORTS_REQUIRED, codes.ERR_TRANSPORTS_REQUIRED);
|
|
28
|
-
}
|
|
29
|
-
if (resultingOptions.connectionProtector === null && globalThis.process?.env?.LIBP2P_FORCE_PNET != null) { // eslint-disable-line no-undef
|
|
30
|
-
throw new CodeError(messages.ERR_PROTECTOR_REQUIRED, codes.ERR_PROTECTOR_REQUIRED);
|
|
31
|
-
}
|
|
32
|
-
return resultingOptions;
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=config.js.map
|
package/dist/src/config.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,YAAY,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAK7C,MAAM,aAAa,GAAwB;IACzC,SAAS,EAAE;QACT,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE,EAAE;QACZ,UAAU,EAAE,EAAE;QACd,cAAc,EAAE,CAAC,UAAuB,EAAE,EAAE,CAAC,UAAU;KACxD;IACD,iBAAiB,EAAE;QACjB,SAAS,EAAE;YACT,OAAO,EAAE,eAAe;SACzB;QACD,aAAa,EAAE,kBAAkB;KAClC;IACD,gBAAgB,EAAE;QAChB,cAAc,EAAE,cAAc,CAAC,SAAS;KACzC;CACF,CAAA;AAED,MAAM,UAAU,cAAc,CAAmD,IAAqC;IACpH,MAAM,gBAAgB,GAAkB,YAAY,CAAC,aAAa,EAAE,IAAI,CAAC,CAAA;IAEzE,IAAI,gBAAgB,CAAC,UAAU,IAAI,IAAI,IAAI,gBAAgB,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE;QACjF,MAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,uBAAuB,EAAE,KAAK,CAAC,uBAAuB,CAAC,CAAA;KACrF;IAED,IAAI,gBAAgB,CAAC,mBAAmB,KAAK,IAAI,IAAI,UAAU,CAAC,OAAO,EAAE,GAAG,EAAE,iBAAiB,IAAI,IAAI,EAAE,EAAE,+BAA+B;QACxI,MAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,sBAAsB,EAAE,KAAK,CAAC,sBAAsB,CAAC,CAAA;KACnF;IAED,OAAO,gBAAgB,CAAA;AACzB,CAAC"}
|
package/src/config.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { CodeError } from '@libp2p/interface/errors'
|
|
2
|
-
import { FaultTolerance } from '@libp2p/interface/transport'
|
|
3
|
-
import { defaultAddressSort } from '@libp2p/utils/address-sort'
|
|
4
|
-
import { dnsaddrResolver } from '@multiformats/multiaddr/resolvers'
|
|
5
|
-
import mergeOptions from 'merge-options'
|
|
6
|
-
import { codes, messages } from './errors.js'
|
|
7
|
-
import type { Libp2pInit } from './index.js'
|
|
8
|
-
import type { ServiceMap, RecursivePartial } from '@libp2p/interface'
|
|
9
|
-
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
10
|
-
|
|
11
|
-
const DefaultConfig: Partial<Libp2pInit> = {
|
|
12
|
-
addresses: {
|
|
13
|
-
listen: [],
|
|
14
|
-
announce: [],
|
|
15
|
-
noAnnounce: [],
|
|
16
|
-
announceFilter: (multiaddrs: Multiaddr[]) => multiaddrs
|
|
17
|
-
},
|
|
18
|
-
connectionManager: {
|
|
19
|
-
resolvers: {
|
|
20
|
-
dnsaddr: dnsaddrResolver
|
|
21
|
-
},
|
|
22
|
-
addressSorter: defaultAddressSort
|
|
23
|
-
},
|
|
24
|
-
transportManager: {
|
|
25
|
-
faultTolerance: FaultTolerance.FATAL_ALL
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function validateConfig <T extends ServiceMap = Record<string, unknown>> (opts: RecursivePartial<Libp2pInit<T>>): Libp2pInit<T> {
|
|
30
|
-
const resultingOptions: Libp2pInit<T> = mergeOptions(DefaultConfig, opts)
|
|
31
|
-
|
|
32
|
-
if (resultingOptions.transports == null || resultingOptions.transports.length < 1) {
|
|
33
|
-
throw new CodeError(messages.ERR_TRANSPORTS_REQUIRED, codes.ERR_TRANSPORTS_REQUIRED)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (resultingOptions.connectionProtector === null && globalThis.process?.env?.LIBP2P_FORCE_PNET != null) { // eslint-disable-line no-undef
|
|
37
|
-
throw new CodeError(messages.ERR_PROTECTOR_REQUIRED, codes.ERR_PROTECTOR_REQUIRED)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return resultingOptions
|
|
41
|
-
}
|