@libp2p/circuit-relay-v2 3.2.23 → 3.2.24-0f07e3df5
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 +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/constants.d.ts +0 -4
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +0 -4
- package/dist/src/constants.js.map +1 -1
- package/dist/src/index.d.ts +170 -7
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +12 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/server/index.d.ts +41 -45
- package/dist/src/server/index.d.ts.map +1 -1
- package/dist/src/server/index.js +30 -47
- package/dist/src/server/index.js.map +1 -1
- package/dist/src/server/reservation-store.d.ts +2 -36
- package/dist/src/server/reservation-store.d.ts.map +1 -1
- package/dist/src/server/reservation-store.js.map +1 -1
- package/dist/src/transport/discovery.d.ts +2 -17
- package/dist/src/transport/discovery.d.ts.map +1 -1
- package/dist/src/transport/discovery.js +2 -2
- package/dist/src/transport/discovery.js.map +1 -1
- package/dist/src/transport/index.d.ts +34 -42
- package/dist/src/transport/index.d.ts.map +1 -1
- package/dist/src/transport/index.js +291 -5
- package/dist/src/transport/index.js.map +1 -1
- package/dist/src/transport/reservation-store.d.ts +3 -37
- package/dist/src/transport/reservation-store.d.ts.map +1 -1
- package/dist/src/transport/reservation-store.js +4 -6
- package/dist/src/transport/reservation-store.js.map +1 -1
- package/dist/src/transport/stream-to-conn.d.ts +19 -0
- package/dist/src/transport/stream-to-conn.d.ts.map +1 -0
- package/dist/src/transport/stream-to-conn.js +60 -0
- package/dist/src/transport/stream-to-conn.js.map +1 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +36 -59
- package/dist/src/utils.js.map +1 -1
- package/package.json +19 -24
- package/src/constants.ts +0 -5
- package/src/index.ts +207 -8
- package/src/server/index.ts +35 -100
- package/src/server/reservation-store.ts +2 -42
- package/src/transport/discovery.ts +4 -22
- package/src/transport/index.ts +338 -46
- package/src/transport/reservation-store.ts +8 -46
- package/src/transport/stream-to-conn.ts +91 -0
- package/src/utils.ts +37 -66
- package/dist/src/transport/transport.d.ts +0 -54
- package/dist/src/transport/transport.d.ts.map +0 -1
- package/dist/src/transport/transport.js +0 -314
- package/dist/src/transport/transport.js.map +0 -1
- package/dist/typedoc-urls.json +0 -23
- package/src/transport/transport.ts +0 -378
package/dist/src/constants.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,eAAO,MAAM,
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,eAAO,MAAM,kCAAkC,KAAK,CAAA;AAEpD;;GAEG;AACH,eAAO,MAAM,2BAA2B,QAAkB,CAAA;AAE1D;;GAEG;AACH,eAAO,MAAM,+BAA+B,IAAI,CAAA;AAEhD;;GAEG;AACH,eAAO,MAAM,sCAAsC,OAAO,CAAA;AAE1D;;GAEG;AACH,eAAO,MAAM,oCAAoC,MAAM,CAAA;AAEvD,eAAO,MAAM,gBAAgB,yBAAyB,CAAA;AAEtD,eAAO,MAAM,cAAc,6BAAgC,CAAA;AAC3D,eAAO,MAAM,qBAAqB,oCAAuC,CAAA;AAMzE,eAAO,MAAM,sBAAsB,QAAa,CAAA;AAGhD,eAAO,MAAM,kBAAkB,QAAkB,CAAA;AAEjD;;GAEG;AACH,eAAO,MAAM,kBAAkB,oCAAoC,CAAA;AAEnE;;GAEG;AACH,eAAO,MAAM,mBAAmB,qCAAqC,CAAA;AAErE;;GAEG;AACH,eAAO,MAAM,mBAAmB,QAAc,CAAA;AAE9C;;GAEG;AACH,eAAO,MAAM,yBAAyB,QAAc,CAAA;AAEpD,eAAO,MAAM,eAAe,MAAM,CAAA;AAElC,eAAO,MAAM,6BAA6B,OAAO,CAAA;AACjD,eAAO,MAAM,mCAAmC,QAAQ,CAAA"}
|
package/dist/src/constants.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAE9C,MAAM,MAAM,GAAG,IAAI,CAAA;AACnB,MAAM,MAAM,GAAG,EAAE,GAAG,MAAM,CAAA;AAE1B;;GAEG;AACH,MAAM,CAAC,MAAM,
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAE9C,MAAM,MAAM,GAAG,IAAI,CAAA;AACnB,MAAM,MAAM,GAAG,EAAE,GAAG,MAAM,CAAA;AAE1B;;GAEG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,EAAE,CAAA;AAEpD;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,GAAG,EAAE,GAAG,MAAM,CAAA;AAE1D;;GAEG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAAC,CAAA;AAEhD;;GAEG;AACH,MAAM,CAAC,MAAM,sCAAsC,GAAG,IAAI,CAAA;AAE1D;;GAEG;AACH,MAAM,CAAC,MAAM,oCAAoC,GAAG,GAAG,CAAA;AAEvD,MAAM,CAAC,MAAM,gBAAgB,GAAG,sBAAsB,CAAA;AAEtD,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,UAAU,gBAAgB,CAAA;AAC3D,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,UAAU,uBAAuB,CAAA;AAEzE,+BAA+B;AAC/B,oGAAoG;AAEpG,2CAA2C;AAC3C,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,GAAG,MAAM,CAAA;AAEhD,iCAAiC;AACjC,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;AAEjD;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,iCAAiC,CAAA;AAEnE;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,kCAAkC,CAAA;AAErE;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,GAAG,MAAM,CAAA;AAE9C;;GAEG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,GAAG,MAAM,CAAA;AAEpD,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,CAAA;AAElC,MAAM,CAAC,MAAM,6BAA6B,GAAG,IAAI,CAAA;AACjD,MAAM,CAAC,MAAM,mCAAmC,GAAG,KAAK,CAAA"}
|
package/dist/src/index.d.ts
CHANGED
@@ -40,6 +40,8 @@
|
|
40
40
|
*/
|
41
41
|
import { TypedEventEmitter } from 'main-event';
|
42
42
|
import type { Limit } from './pb/index.js';
|
43
|
+
import type { ComponentLogger, ConnectionGater, Libp2pEvents, Metrics, PeerId, PeerStore, PrivateKey, TopologyFilter, Transport, TypedEventTarget, Upgrader } from '@libp2p/interface';
|
44
|
+
import type { AddressManager, ConnectionManager, RandomWalk, Registrar, TransportManager } from '@libp2p/interface-internal';
|
43
45
|
import type { PeerMap } from '@libp2p/peer-collections';
|
44
46
|
import type { Multiaddr } from '@multiformats/multiaddr';
|
45
47
|
import type { RetimeableAbortSignal } from 'retimeable-signal';
|
@@ -71,12 +73,173 @@ export interface CircuitRelayServiceEvents {
|
|
71
73
|
export interface CircuitRelayService extends TypedEventEmitter<CircuitRelayServiceEvents> {
|
72
74
|
reservations: PeerMap<RelayReservation>;
|
73
75
|
}
|
74
|
-
export { circuitRelayServer } from './server/index.js';
|
75
|
-
export type { CircuitRelayServerInit, CircuitRelayServerComponents } from './server/index.js';
|
76
|
-
export type { ReservationStoreInit as ServerReservationStoreInit } from './server/reservation-store.js';
|
77
|
-
export { circuitRelayTransport } from './transport/index.js';
|
78
|
-
export type { RelayDiscoveryComponents } from './transport/discovery.js';
|
79
|
-
export type { ReservationStoreInit as TransportReservationStoreInit } from './transport/reservation-store.js';
|
80
|
-
export type { CircuitRelayTransportInit, CircuitRelayTransportComponents } from './transport/index.js';
|
81
76
|
export { RELAY_V2_HOP_CODEC, RELAY_V2_STOP_CODEC } from './constants.js';
|
77
|
+
export interface ServerReservationStoreInit {
|
78
|
+
/**
|
79
|
+
* maximum number of reservations allowed
|
80
|
+
*
|
81
|
+
* @default 15
|
82
|
+
*/
|
83
|
+
maxReservations?: number;
|
84
|
+
/**
|
85
|
+
* interval after which stale reservations are cleared
|
86
|
+
*
|
87
|
+
* @default 300000
|
88
|
+
*/
|
89
|
+
reservationClearInterval?: number;
|
90
|
+
/**
|
91
|
+
* apply default relay limits to a new reservation
|
92
|
+
*
|
93
|
+
* @default true
|
94
|
+
*/
|
95
|
+
applyDefaultLimit?: boolean;
|
96
|
+
/**
|
97
|
+
* reservation ttl
|
98
|
+
*
|
99
|
+
* @default 7200000
|
100
|
+
*/
|
101
|
+
reservationTtl?: number;
|
102
|
+
/**
|
103
|
+
* The maximum time a relayed connection can be open for
|
104
|
+
*/
|
105
|
+
defaultDurationLimit?: number;
|
106
|
+
/**
|
107
|
+
* The maximum amount of data allowed to be transferred over a relayed connection
|
108
|
+
*/
|
109
|
+
defaultDataLimit?: bigint;
|
110
|
+
}
|
111
|
+
export interface CircuitRelayServerComponents {
|
112
|
+
registrar: Registrar;
|
113
|
+
peerStore: PeerStore;
|
114
|
+
addressManager: AddressManager;
|
115
|
+
peerId: PeerId;
|
116
|
+
privateKey: PrivateKey;
|
117
|
+
connectionManager: ConnectionManager;
|
118
|
+
connectionGater: ConnectionGater;
|
119
|
+
logger: ComponentLogger;
|
120
|
+
metrics?: Metrics;
|
121
|
+
}
|
122
|
+
export interface CircuitRelayServerInit {
|
123
|
+
/**
|
124
|
+
* Incoming hop requests must complete within this time in ms otherwise
|
125
|
+
* the stream will be reset
|
126
|
+
*
|
127
|
+
* @default 30000
|
128
|
+
*/
|
129
|
+
hopTimeout?: number;
|
130
|
+
/**
|
131
|
+
* Configuration of reservations
|
132
|
+
*/
|
133
|
+
reservations?: ServerReservationStoreInit;
|
134
|
+
/**
|
135
|
+
* The maximum number of simultaneous HOP inbound streams that can be open at once
|
136
|
+
*/
|
137
|
+
maxInboundHopStreams?: number;
|
138
|
+
/**
|
139
|
+
* The maximum number of simultaneous HOP outbound streams that can be open at once
|
140
|
+
*/
|
141
|
+
maxOutboundHopStreams?: number;
|
142
|
+
/**
|
143
|
+
* The maximum number of simultaneous STOP outbound streams that can be open at
|
144
|
+
* once.
|
145
|
+
*
|
146
|
+
* @default 300
|
147
|
+
*/
|
148
|
+
maxOutboundStopStreams?: number;
|
149
|
+
}
|
150
|
+
export declare function circuitRelayServer(init?: CircuitRelayServerInit): (components: CircuitRelayServerComponents) => CircuitRelayService;
|
151
|
+
export interface RelayDiscoveryEvents {
|
152
|
+
'relay:discover': CustomEvent<PeerId>;
|
153
|
+
}
|
154
|
+
export interface TransportReservationStoreComponents {
|
155
|
+
peerId: PeerId;
|
156
|
+
connectionManager: ConnectionManager;
|
157
|
+
peerStore: PeerStore;
|
158
|
+
events: TypedEventTarget<Libp2pEvents>;
|
159
|
+
logger: ComponentLogger;
|
160
|
+
metrics?: Metrics;
|
161
|
+
}
|
162
|
+
export interface TransportReservationStoreInit {
|
163
|
+
/**
|
164
|
+
* Multiple relays may be discovered simultaneously - to prevent listening
|
165
|
+
* on too many relays, this value controls how many to attempt to reserve a
|
166
|
+
* slot on at once. If set to more than one, we may end up listening on
|
167
|
+
* more relays than the `maxReservations` value, but on networks with poor
|
168
|
+
* connectivity the user may wish to attempt to reserve on multiple relays
|
169
|
+
* simultaneously.
|
170
|
+
*
|
171
|
+
* @default 1
|
172
|
+
*/
|
173
|
+
reservationConcurrency?: number;
|
174
|
+
/**
|
175
|
+
* Limit the number of potential relays we will dial
|
176
|
+
*
|
177
|
+
* @default 100
|
178
|
+
*/
|
179
|
+
maxReservationQueueLength?: number;
|
180
|
+
/**
|
181
|
+
* When creating a reservation it must complete within this number of ms
|
182
|
+
*
|
183
|
+
* @default 5000
|
184
|
+
*/
|
185
|
+
reservationCompletionTimeout?: number;
|
186
|
+
}
|
187
|
+
export interface RelayDiscoveryComponents {
|
188
|
+
peerStore: PeerStore;
|
189
|
+
connectionManager: ConnectionManager;
|
190
|
+
transportManager: TransportManager;
|
191
|
+
registrar: Registrar;
|
192
|
+
logger: ComponentLogger;
|
193
|
+
randomWalk: RandomWalk;
|
194
|
+
events: TypedEventTarget<Libp2pEvents>;
|
195
|
+
}
|
196
|
+
export interface RelayDiscoveryInit {
|
197
|
+
filter?: TopologyFilter;
|
198
|
+
}
|
199
|
+
export interface CircuitRelayTransportComponents extends RelayDiscoveryComponents {
|
200
|
+
peerId: PeerId;
|
201
|
+
upgrader: Upgrader;
|
202
|
+
addressManager: AddressManager;
|
203
|
+
connectionGater: ConnectionGater;
|
204
|
+
}
|
205
|
+
/**
|
206
|
+
* RelayConfig configures the circuit v2 relay transport.
|
207
|
+
*/
|
208
|
+
export interface CircuitRelayTransportInit extends TransportReservationStoreInit {
|
209
|
+
/**
|
210
|
+
* An optional filter used to prevent duplicate attempts to reserve relay
|
211
|
+
* slots on the same peer
|
212
|
+
*/
|
213
|
+
discoveryFilter?: TopologyFilter;
|
214
|
+
/**
|
215
|
+
* The maximum number of simultaneous STOP inbound streams that can be open at
|
216
|
+
* once - each inbound relayed connection uses a STOP stream
|
217
|
+
*
|
218
|
+
* @default 300
|
219
|
+
*/
|
220
|
+
maxInboundStopStreams?: number;
|
221
|
+
/**
|
222
|
+
* The maximum number of simultaneous STOP outbound streams that can be open
|
223
|
+
* at once. If this transport is used along with the relay server these
|
224
|
+
* settings should be set to the same value
|
225
|
+
*
|
226
|
+
* @default 300
|
227
|
+
*/
|
228
|
+
maxOutboundStopStreams?: number;
|
229
|
+
/**
|
230
|
+
* Incoming STOP requests (e.g. when a remote peer wants to dial us via a
|
231
|
+
* relay) must finish the initial protocol negotiation within this timeout in
|
232
|
+
* ms
|
233
|
+
*
|
234
|
+
* @deprecated Configure `connectionManager.inboundUpgradeTimeout` instead
|
235
|
+
*/
|
236
|
+
stopTimeout?: number;
|
237
|
+
/**
|
238
|
+
* When creating a reservation it must complete within this number of ms
|
239
|
+
*
|
240
|
+
* @default 10_000
|
241
|
+
*/
|
242
|
+
reservationCompletionTimeout?: number;
|
243
|
+
}
|
244
|
+
export declare function circuitRelayTransport(init?: CircuitRelayTransportInit): (components: CircuitRelayTransportComponents) => Transport;
|
82
245
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAG9C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,EAAE,SAAS,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AACtL,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,UAAU,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAC5H,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AACvD,OAAO,KAAK,EAAE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,eAAe,CAAA;IACvB,UAAU,EAAE,UAAU,CAAA;IACtB,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAA;CACvC;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,cAAc,CAAA;CACxB;AAED,MAAM,WAAW,+BAAgC,SAAQ,wBAAwB;IAC/E,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,QAAQ,CAAA;IAClB,cAAc,EAAE,cAAc,CAAA;IAC9B,eAAe,EAAE,eAAe,CAAA;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,yBAA0B,SAAQ,6BAA6B;IAC9E;;;OAGG;IACH,eAAe,CAAC,EAAE,cAAc,CAAA;IAEhC;;;;;OAKG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAE9B;;;;;;OAMG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAA;IAE/B;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IAEpB;;;;OAIG;IACH,4BAA4B,CAAC,EAAE,MAAM,CAAA;CACtC;AAED,wBAAgB,qBAAqB,CAAE,IAAI,GAAE,yBAA8B,GAAG,CAAC,UAAU,EAAE,+BAA+B,KAAK,SAAS,CAIvI"}
|
package/dist/src/index.js
CHANGED
@@ -39,7 +39,17 @@
|
|
39
39
|
* ```
|
40
40
|
*/
|
41
41
|
import { TypedEventEmitter } from 'main-event';
|
42
|
-
|
43
|
-
|
42
|
+
import { CircuitRelayServer } from './server/index.js';
|
43
|
+
import { CircuitRelayTransport } from "./transport/index.js";
|
44
44
|
export { RELAY_V2_HOP_CODEC, RELAY_V2_STOP_CODEC } from './constants.js';
|
45
|
+
export function circuitRelayServer(init = {}) {
|
46
|
+
return (components) => {
|
47
|
+
return new CircuitRelayServer(components, init);
|
48
|
+
};
|
49
|
+
}
|
50
|
+
export function circuitRelayTransport(init = {}) {
|
51
|
+
return (components) => {
|
52
|
+
return new CircuitRelayTransport(components, init);
|
53
|
+
};
|
54
|
+
}
|
45
55
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AA2C5D,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,gBAAgB,CAAA;AAuFvB,MAAM,UAAU,kBAAkB,CAAE,OAA+B,EAAE;IACnE,OAAO,CAAC,UAAU,EAAE,EAAE;QACpB,OAAO,IAAI,kBAAkB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;IACjD,CAAC,CAAA;AACH,CAAC;AA4GD,MAAM,UAAU,qBAAqB,CAAE,OAAkC,EAAE;IACzE,OAAO,CAAC,UAAU,EAAE,EAAE;QACpB,OAAO,IAAI,qBAAqB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;IACpD,CAAC,CAAA;AACH,CAAC"}
|
@@ -1,37 +1,10 @@
|
|
1
|
+
import { TypedEventEmitter } from 'main-event';
|
1
2
|
import { HopMessage, StopMessage } from '../pb/index.js';
|
2
|
-
import type {
|
3
|
-
import type {
|
4
|
-
import type {
|
5
|
-
import type {
|
6
|
-
import type { ProtobufStream } from '
|
7
|
-
export interface CircuitRelayServerInit {
|
8
|
-
/**
|
9
|
-
* Incoming hop requests must complete within this time in ms otherwise
|
10
|
-
* the stream will be reset
|
11
|
-
*
|
12
|
-
* @default 30000
|
13
|
-
*/
|
14
|
-
hopTimeout?: number;
|
15
|
-
/**
|
16
|
-
* Configuration of reservations
|
17
|
-
*/
|
18
|
-
reservations?: ReservationStoreInit;
|
19
|
-
/**
|
20
|
-
* The maximum number of simultaneous HOP inbound streams that can be open at once
|
21
|
-
*/
|
22
|
-
maxInboundHopStreams?: number;
|
23
|
-
/**
|
24
|
-
* The maximum number of simultaneous HOP outbound streams that can be open at once
|
25
|
-
*/
|
26
|
-
maxOutboundHopStreams?: number;
|
27
|
-
/**
|
28
|
-
* The maximum number of simultaneous STOP outbound streams that can be open at
|
29
|
-
* once.
|
30
|
-
*
|
31
|
-
* @default 300
|
32
|
-
*/
|
33
|
-
maxOutboundStopStreams?: number;
|
34
|
-
}
|
3
|
+
import type { CircuitRelayServerComponents, CircuitRelayServerInit, CircuitRelayService, RelayReservation } from '../index.js';
|
4
|
+
import type { Reservation } from '../pb/index.js';
|
5
|
+
import type { Connection, Stream, PeerId, Startable, AbortOptions } from '@libp2p/interface';
|
6
|
+
import type { PeerMap } from '@libp2p/peer-collections';
|
7
|
+
import type { ProtobufStream } from '@libp2p/utils';
|
35
8
|
export interface HopProtocolOptions {
|
36
9
|
connection: Connection;
|
37
10
|
request: HopMessage;
|
@@ -41,21 +14,44 @@ export interface StopOptions {
|
|
41
14
|
connection: Connection;
|
42
15
|
request: StopMessage;
|
43
16
|
}
|
44
|
-
export interface CircuitRelayServerComponents {
|
45
|
-
registrar: Registrar;
|
46
|
-
peerStore: PeerStore;
|
47
|
-
addressManager: AddressManager;
|
48
|
-
peerId: PeerId;
|
49
|
-
privateKey: PrivateKey;
|
50
|
-
connectionManager: ConnectionManager;
|
51
|
-
connectionGater: ConnectionGater;
|
52
|
-
logger: ComponentLogger;
|
53
|
-
metrics?: Metrics;
|
54
|
-
}
|
55
17
|
export interface RelayServerEvents {
|
56
18
|
'relay:reservation': CustomEvent<RelayReservation>;
|
57
19
|
'relay:advert:success': CustomEvent<unknown>;
|
58
20
|
'relay:advert:error': CustomEvent<Error>;
|
59
21
|
}
|
60
|
-
export declare
|
22
|
+
export declare class CircuitRelayServer extends TypedEventEmitter<RelayServerEvents> implements Startable, CircuitRelayService {
|
23
|
+
private readonly components;
|
24
|
+
private readonly reservationStore;
|
25
|
+
private started;
|
26
|
+
private readonly hopTimeout;
|
27
|
+
private readonly shutdownController;
|
28
|
+
private readonly maxInboundHopStreams?;
|
29
|
+
private readonly maxOutboundHopStreams?;
|
30
|
+
private readonly maxOutboundStopStreams;
|
31
|
+
private readonly log;
|
32
|
+
/**
|
33
|
+
* Creates an instance of Relay
|
34
|
+
*/
|
35
|
+
constructor(components: CircuitRelayServerComponents, init?: CircuitRelayServerInit);
|
36
|
+
readonly [Symbol.toStringTag] = "@libp2p/circuit-relay-v2-server";
|
37
|
+
isStarted(): boolean;
|
38
|
+
/**
|
39
|
+
* Start Relay service
|
40
|
+
*/
|
41
|
+
start(): Promise<void>;
|
42
|
+
/**
|
43
|
+
* Stop Relay service
|
44
|
+
*/
|
45
|
+
stop(): Promise<void>;
|
46
|
+
onHop(stream: Stream, connection: Connection): Promise<void>;
|
47
|
+
handleHopProtocol({ stream, request, connection }: HopProtocolOptions, options: AbortOptions): Promise<void>;
|
48
|
+
handleReserve({ stream, connection }: HopProtocolOptions, options: AbortOptions): Promise<void>;
|
49
|
+
makeReservation(remotePeer: PeerId, expire: bigint): Promise<Reservation>;
|
50
|
+
handleConnect({ stream, request, connection }: HopProtocolOptions, options: AbortOptions): Promise<void>;
|
51
|
+
/**
|
52
|
+
* Send a STOP request to the target peer that the dialing peer wants to contact
|
53
|
+
*/
|
54
|
+
stopHop({ connection, request }: StopOptions, options: AbortOptions): Promise<Stream | undefined>;
|
55
|
+
get reservations(): PeerMap<RelayReservation>;
|
56
|
+
}
|
61
57
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAAmB,MAAM,YAAY,CAAA;AAU/D,OAAO,EAAE,UAAU,EAAU,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAIhE,OAAO,KAAK,EAAE,4BAA4B,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC9H,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,KAAK,EAAU,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACpG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAEnD,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,UAAU,CAAA;IACtB,OAAO,EAAE,UAAU,CAAA;IACnB,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,CAAA;CAC/B;AAED,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,UAAU,CAAA;IACtB,OAAO,EAAE,WAAW,CAAA;CACrB;AAED,MAAM,WAAW,iBAAiB;IAChC,mBAAmB,EAAE,WAAW,CAAC,gBAAgB,CAAC,CAAA;IAClD,sBAAsB,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;IAC5C,oBAAoB,EAAE,WAAW,CAAC,KAAK,CAAC,CAAA;CACzC;AAMD,qBAAa,kBAAmB,SAAQ,iBAAiB,CAAC,iBAAiB,CAAE,YAAW,SAAS,EAAE,mBAAmB;IACpH,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA8B;IACzD,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAkB;IACnD,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,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GAAG,SAAS,CAAC;IAiCxG,IAAI,YAAY,IAAK,OAAO,CAAC,gBAAgB,CAAC,CAE7C;CACF"}
|
package/dist/src/server/index.js
CHANGED
@@ -1,27 +1,21 @@
|
|
1
1
|
import { publicKeyToProtobuf } from '@libp2p/crypto/keys';
|
2
2
|
import { peerIdFromMultihash } from '@libp2p/peer-id';
|
3
3
|
import { RecordEnvelope } from '@libp2p/peer-record';
|
4
|
+
import { pbStream } from '@libp2p/utils';
|
4
5
|
import { multiaddr } from '@multiformats/multiaddr';
|
5
|
-
import {
|
6
|
+
import { Circuit } from '@multiformats/multiaddr-matcher';
|
6
7
|
import { TypedEventEmitter, setMaxListeners } from 'main-event';
|
7
8
|
import * as Digest from 'multiformats/hashes/digest';
|
8
|
-
import {
|
9
|
+
import { DEFAULT_HOP_TIMEOUT, KEEP_ALIVE_SOURCE_TAG, MAX_CONNECTIONS, RELAY_SOURCE_TAG, RELAY_V2_HOP_CODEC, RELAY_V2_STOP_CODEC } from '../constants.js';
|
9
10
|
import { HopMessage, Status, StopMessage } from '../pb/index.js';
|
10
11
|
import { createLimitedRelay } from '../utils.js';
|
11
12
|
import { ReservationStore } from './reservation-store.js';
|
12
13
|
import { ReservationVoucherRecord } from './reservation-voucher.js';
|
13
|
-
const isRelayAddr = (ma) => ma.protoCodes().includes(CIRCUIT_PROTO_CODE);
|
14
14
|
const defaults = {
|
15
15
|
maxOutboundStopStreams: MAX_CONNECTIONS
|
16
16
|
};
|
17
|
-
class CircuitRelayServer extends TypedEventEmitter {
|
18
|
-
|
19
|
-
peerStore;
|
20
|
-
addressManager;
|
21
|
-
peerId;
|
22
|
-
privateKey;
|
23
|
-
connectionManager;
|
24
|
-
connectionGater;
|
17
|
+
export class CircuitRelayServer extends TypedEventEmitter {
|
18
|
+
components;
|
25
19
|
reservationStore;
|
26
20
|
started;
|
27
21
|
hopTimeout;
|
@@ -36,13 +30,7 @@ class CircuitRelayServer extends TypedEventEmitter {
|
|
36
30
|
constructor(components, init = {}) {
|
37
31
|
super();
|
38
32
|
this.log = components.logger.forComponent('libp2p:circuit-relay:server');
|
39
|
-
this.
|
40
|
-
this.peerStore = components.peerStore;
|
41
|
-
this.addressManager = components.addressManager;
|
42
|
-
this.peerId = components.peerId;
|
43
|
-
this.privateKey = components.privateKey;
|
44
|
-
this.connectionManager = components.connectionManager;
|
45
|
-
this.connectionGater = components.connectionGater;
|
33
|
+
this.components = components;
|
46
34
|
this.started = false;
|
47
35
|
this.hopTimeout = init?.hopTimeout ?? DEFAULT_HOP_TIMEOUT;
|
48
36
|
this.maxInboundHopStreams = init.maxInboundHopStreams;
|
@@ -51,6 +39,7 @@ class CircuitRelayServer extends TypedEventEmitter {
|
|
51
39
|
this.reservationStore = new ReservationStore(components, init.reservations);
|
52
40
|
this.shutdownController = new AbortController();
|
53
41
|
setMaxListeners(Infinity, this.shutdownController.signal);
|
42
|
+
this.onHop = this.onHop.bind(this);
|
54
43
|
}
|
55
44
|
[Symbol.toStringTag] = '@libp2p/circuit-relay-v2-server';
|
56
45
|
isStarted() {
|
@@ -63,11 +52,7 @@ class CircuitRelayServer extends TypedEventEmitter {
|
|
63
52
|
if (this.started) {
|
64
53
|
return;
|
65
54
|
}
|
66
|
-
await this.registrar.handle(RELAY_V2_HOP_CODEC,
|
67
|
-
void this.onHop(data).catch(err => {
|
68
|
-
this.log.error(err);
|
69
|
-
});
|
70
|
-
}, {
|
55
|
+
await this.components.registrar.handle(RELAY_V2_HOP_CODEC, this.onHop, {
|
71
56
|
maxInboundStreams: this.maxInboundHopStreams,
|
72
57
|
maxOutboundStreams: this.maxOutboundHopStreams,
|
73
58
|
runOnLimitedConnection: true
|
@@ -80,13 +65,15 @@ class CircuitRelayServer extends TypedEventEmitter {
|
|
80
65
|
async stop() {
|
81
66
|
this.reservationStore.clear();
|
82
67
|
this.shutdownController.abort();
|
83
|
-
await this.registrar.unhandle(RELAY_V2_HOP_CODEC);
|
68
|
+
await this.components.registrar.unhandle(RELAY_V2_HOP_CODEC);
|
84
69
|
this.started = false;
|
85
70
|
}
|
86
|
-
async onHop(
|
71
|
+
async onHop(stream, connection) {
|
87
72
|
this.log('received circuit v2 hop protocol stream from %p', connection.remotePeer);
|
73
|
+
const signal = AbortSignal.timeout(this.hopTimeout);
|
74
|
+
setMaxListeners(Infinity, signal);
|
88
75
|
const options = {
|
89
|
-
signal
|
76
|
+
signal
|
90
77
|
};
|
91
78
|
const pbstr = pbStream(stream);
|
92
79
|
try {
|
@@ -128,12 +115,12 @@ class CircuitRelayServer extends TypedEventEmitter {
|
|
128
115
|
async handleReserve({ stream, connection }, options) {
|
129
116
|
const hopstr = stream.pb(HopMessage);
|
130
117
|
this.log('hop reserve request from %p', connection.remotePeer);
|
131
|
-
if (
|
118
|
+
if (Circuit.exactMatch(connection.remoteAddr)) {
|
132
119
|
this.log.error('relay reservation over circuit connection denied for peer: %p', connection.remotePeer);
|
133
120
|
await hopstr.write({ type: HopMessage.Type.STATUS, status: Status.PERMISSION_DENIED }, options);
|
134
121
|
return;
|
135
122
|
}
|
136
|
-
if ((await this.connectionGater.denyInboundRelayReservation?.(connection.remotePeer)) === true) {
|
123
|
+
if ((await this.components.connectionGater.denyInboundRelayReservation?.(connection.remotePeer)) === true) {
|
137
124
|
this.log.error('reservation for %p denied by connection gater', connection.remotePeer);
|
138
125
|
await hopstr.write({ type: HopMessage.Type.STATUS, status: Status.PERMISSION_DENIED }, options);
|
139
126
|
return;
|
@@ -148,12 +135,12 @@ class CircuitRelayServer extends TypedEventEmitter {
|
|
148
135
|
// result.expire is non-null if `ReservationStore.reserve` returns with status == OK
|
149
136
|
if (result.expire != null) {
|
150
137
|
const ttl = (result.expire * 1000) - Date.now();
|
151
|
-
await this.peerStore.merge(connection.remotePeer, {
|
138
|
+
await this.components.peerStore.merge(connection.remotePeer, {
|
152
139
|
tags: {
|
153
140
|
[RELAY_SOURCE_TAG]: { value: 1, ttl },
|
154
141
|
[KEEP_ALIVE_SOURCE_TAG]: { value: 1, ttl }
|
155
142
|
}
|
156
|
-
});
|
143
|
+
}, options);
|
157
144
|
}
|
158
145
|
await hopstr.write({
|
159
146
|
type: HopMessage.Type.STATUS,
|
@@ -162,17 +149,19 @@ class CircuitRelayServer extends TypedEventEmitter {
|
|
162
149
|
limit: this.reservationStore.get(connection.remotePeer)?.limit
|
163
150
|
}, options);
|
164
151
|
this.log('sent confirmation response to %s', connection.remotePeer);
|
152
|
+
// close writable end of stream
|
153
|
+
await hopstr.unwrap().unwrap().close(options);
|
165
154
|
}
|
166
155
|
catch (err) {
|
167
156
|
this.log.error('failed to send confirmation response to %p - %e', connection.remotePeer, err);
|
168
157
|
this.reservationStore.removeReservation(connection.remotePeer);
|
169
158
|
try {
|
170
|
-
await this.peerStore.merge(connection.remotePeer, {
|
159
|
+
await this.components.peerStore.merge(connection.remotePeer, {
|
171
160
|
tags: {
|
172
161
|
[RELAY_SOURCE_TAG]: undefined,
|
173
162
|
[KEEP_ALIVE_SOURCE_TAG]: undefined
|
174
163
|
}
|
175
|
-
});
|
164
|
+
}, options);
|
176
165
|
}
|
177
166
|
catch (err) {
|
178
167
|
this.log.error('failed to untag relay source peer %p - %e', connection.remotePeer, err);
|
@@ -181,7 +170,7 @@ class CircuitRelayServer extends TypedEventEmitter {
|
|
181
170
|
}
|
182
171
|
async makeReservation(remotePeer, expire) {
|
183
172
|
const addrs = [];
|
184
|
-
for (const relayAddr of this.addressManager.getAddresses()) {
|
173
|
+
for (const relayAddr of this.components.addressManager.getAddresses()) {
|
185
174
|
if (relayAddr.toString().includes('/p2p-circuit')) {
|
186
175
|
continue;
|
187
176
|
}
|
@@ -189,9 +178,9 @@ class CircuitRelayServer extends TypedEventEmitter {
|
|
189
178
|
}
|
190
179
|
const envelope = await RecordEnvelope.seal(new ReservationVoucherRecord({
|
191
180
|
peer: remotePeer,
|
192
|
-
relay: this.peerId,
|
181
|
+
relay: this.components.peerId,
|
193
182
|
expiration: expire
|
194
|
-
}), this.privateKey);
|
183
|
+
}), this.components.privateKey);
|
195
184
|
return {
|
196
185
|
addrs,
|
197
186
|
expire,
|
@@ -200,7 +189,7 @@ class CircuitRelayServer extends TypedEventEmitter {
|
|
200
189
|
payloadType: envelope.payloadType,
|
201
190
|
payload: {
|
202
191
|
peer: remotePeer.toMultihash().bytes,
|
203
|
-
relay: this.peerId.toMultihash().bytes,
|
192
|
+
relay: this.components.peerId.toMultihash().bytes,
|
204
193
|
expiration: expire
|
205
194
|
},
|
206
195
|
signature: envelope.signature
|
@@ -209,7 +198,7 @@ class CircuitRelayServer extends TypedEventEmitter {
|
|
209
198
|
}
|
210
199
|
async handleConnect({ stream, request, connection }, options) {
|
211
200
|
const hopstr = stream.pb(HopMessage);
|
212
|
-
if (
|
201
|
+
if (Circuit.matches(connection.remoteAddr)) {
|
213
202
|
this.log.error('relay reservation over circuit connection denied for peer: %p', connection.remotePeer);
|
214
203
|
await hopstr.write({ type: HopMessage.Type.STATUS, status: Status.PERMISSION_DENIED }, options);
|
215
204
|
return;
|
@@ -235,12 +224,12 @@ class CircuitRelayServer extends TypedEventEmitter {
|
|
235
224
|
await hopstr.write({ type: HopMessage.Type.STATUS, status: Status.NO_RESERVATION }, options);
|
236
225
|
return;
|
237
226
|
}
|
238
|
-
if ((await this.connectionGater.denyOutboundRelayedConnection?.(connection.remotePeer, dstPeer)) === true) {
|
227
|
+
if ((await this.components.connectionGater.denyOutboundRelayedConnection?.(connection.remotePeer, dstPeer)) === true) {
|
239
228
|
this.log.error('hop connect for %p to %p denied by connection gater', connection.remotePeer, dstPeer);
|
240
229
|
await hopstr.write({ type: HopMessage.Type.STATUS, status: Status.PERMISSION_DENIED }, options);
|
241
230
|
return;
|
242
231
|
}
|
243
|
-
const connections = this.connectionManager.getConnections(dstPeer);
|
232
|
+
const connections = this.components.connectionManager.getConnections(dstPeer);
|
244
233
|
if (connections.length === 0) {
|
245
234
|
this.log('hop connect denied for destination peer %p not having a connection for %p as there is no destination connection', dstPeer, connection.remotePeer);
|
246
235
|
await hopstr.write({ type: HopMessage.Type.STATUS, status: Status.NO_RESERVATION }, options);
|
@@ -268,10 +257,9 @@ class CircuitRelayServer extends TypedEventEmitter {
|
|
268
257
|
status: Status.OK,
|
269
258
|
limit: reservation?.limit
|
270
259
|
}, options);
|
271
|
-
const sourceStream = stream.unwrap();
|
272
260
|
this.log('connection from %p to %p established - merging streams', connection.remotePeer, dstPeer);
|
273
261
|
// Short circuit the two streams to create the relayed connection
|
274
|
-
createLimitedRelay(
|
262
|
+
createLimitedRelay(stream.unwrap(), destinationStream, this.shutdownController.signal, reservation, {
|
275
263
|
log: this.log
|
276
264
|
});
|
277
265
|
}
|
@@ -280,7 +268,7 @@ class CircuitRelayServer extends TypedEventEmitter {
|
|
280
268
|
*/
|
281
269
|
async stopHop({ connection, request }, options) {
|
282
270
|
this.log('starting circuit relay v2 stop request to %s', connection.remotePeer);
|
283
|
-
const stream = await connection.newStream(
|
271
|
+
const stream = await connection.newStream(RELAY_V2_STOP_CODEC, {
|
284
272
|
maxOutboundStreams: this.maxOutboundStopStreams,
|
285
273
|
runOnLimitedConnection: true,
|
286
274
|
...options
|
@@ -311,9 +299,4 @@ class CircuitRelayServer extends TypedEventEmitter {
|
|
311
299
|
return this.reservationStore.reservations;
|
312
300
|
}
|
313
301
|
}
|
314
|
-
export function circuitRelayServer(init = {}) {
|
315
|
-
return (components) => {
|
316
|
-
return new CircuitRelayServer(components, init);
|
317
|
-
};
|
318
|
-
}
|
319
302
|
//# sourceMappingURL=index.js.map
|