@libp2p/circuit-relay-v2 0.0.0 → 1.0.0-551622a96
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/README.md +1 -1
- package/dist/index.min.js +7 -7
- package/dist/src/index.d.ts +3 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/pb/index.js.map +1 -1
- package/dist/src/server/advert-service.d.ts +2 -4
- package/dist/src/server/advert-service.d.ts.map +1 -1
- package/dist/src/server/advert-service.js +1 -1
- package/dist/src/server/advert-service.js.map +1 -1
- package/dist/src/server/index.d.ts +2 -8
- package/dist/src/server/index.d.ts.map +1 -1
- package/dist/src/server/index.js +1 -1
- package/dist/src/server/index.js.map +1 -1
- package/dist/src/server/reservation-store.d.ts +1 -3
- package/dist/src/server/reservation-store.d.ts.map +1 -1
- package/dist/src/server/reservation-store.js.map +1 -1
- package/dist/src/server/reservation-voucher.d.ts +1 -2
- package/dist/src/server/reservation-voucher.d.ts.map +1 -1
- package/dist/src/server/reservation-voucher.js.map +1 -1
- package/dist/src/transport/discovery.d.ts +3 -9
- package/dist/src/transport/discovery.d.ts.map +1 -1
- package/dist/src/transport/discovery.js +1 -1
- package/dist/src/transport/discovery.js.map +1 -1
- package/dist/src/transport/index.d.ts +2 -10
- package/dist/src/transport/index.d.ts.map +1 -1
- package/dist/src/transport/index.js +4 -273
- package/dist/src/transport/index.js.map +1 -1
- package/dist/src/transport/listener.d.ts +2 -3
- package/dist/src/transport/listener.d.ts.map +1 -1
- package/dist/src/transport/listener.js +2 -2
- package/dist/src/transport/listener.js.map +1 -1
- package/dist/src/transport/reservation-store.d.ts +2 -7
- package/dist/src/transport/reservation-store.d.ts.map +1 -1
- package/dist/src/transport/reservation-store.js +17 -1
- package/dist/src/transport/reservation-store.js.map +1 -1
- package/dist/src/transport/transport.d.ts +61 -0
- package/dist/src/transport/transport.d.ts.map +1 -0
- package/dist/src/transport/transport.js +285 -0
- package/dist/src/transport/transport.js.map +1 -0
- package/dist/src/utils.d.ts +1 -2
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +4 -10
- package/dist/src/utils.js.map +1 -1
- package/package.json +16 -11
- package/src/index.ts +3 -3
- package/src/server/advert-service.ts +2 -4
- package/src/server/index.ts +3 -10
- package/src/server/reservation-store.ts +1 -3
- package/src/server/reservation-voucher.ts +1 -2
- package/src/transport/discovery.ts +3 -9
- package/src/transport/index.ts +5 -343
- package/src/transport/listener.ts +4 -6
- package/src/transport/reservation-store.ts +21 -8
- package/src/transport/transport.ts +346 -0
- package/src/utils.ts +6 -13
@@ -0,0 +1,285 @@
|
|
1
|
+
import { CodeError, transportSymbol } from '@libp2p/interface';
|
2
|
+
import { peerIdFromBytes, peerIdFromString } from '@libp2p/peer-id';
|
3
|
+
import { streamToMaConnection } from '@libp2p/utils/stream-to-ma-conn';
|
4
|
+
import * as mafmt from '@multiformats/mafmt';
|
5
|
+
import { multiaddr } from '@multiformats/multiaddr';
|
6
|
+
import { pbStream } from 'it-protobuf-stream';
|
7
|
+
import { CIRCUIT_PROTO_CODE, ERR_HOP_REQUEST_FAILED, ERR_RELAYED_DIAL, MAX_CONNECTIONS, RELAY_V2_HOP_CODEC, RELAY_V2_STOP_CODEC } from '../constants.js';
|
8
|
+
import { StopMessage, HopMessage, Status } from '../pb/index.js';
|
9
|
+
import { RelayDiscovery } from './discovery.js';
|
10
|
+
import { createListener } from './listener.js';
|
11
|
+
import { ReservationStore } from './reservation-store.js';
|
12
|
+
const isValidStop = (request) => {
|
13
|
+
if (request.peer == null) {
|
14
|
+
return false;
|
15
|
+
}
|
16
|
+
try {
|
17
|
+
request.peer.addrs.forEach(multiaddr);
|
18
|
+
}
|
19
|
+
catch {
|
20
|
+
return false;
|
21
|
+
}
|
22
|
+
return true;
|
23
|
+
};
|
24
|
+
const defaults = {
|
25
|
+
maxInboundStopStreams: MAX_CONNECTIONS,
|
26
|
+
maxOutboundStopStreams: MAX_CONNECTIONS,
|
27
|
+
stopTimeout: 30000
|
28
|
+
};
|
29
|
+
export class CircuitRelayTransport {
|
30
|
+
discovery;
|
31
|
+
registrar;
|
32
|
+
peerStore;
|
33
|
+
connectionManager;
|
34
|
+
transportManager;
|
35
|
+
peerId;
|
36
|
+
upgrader;
|
37
|
+
addressManager;
|
38
|
+
connectionGater;
|
39
|
+
reservationStore;
|
40
|
+
logger;
|
41
|
+
maxInboundStopStreams;
|
42
|
+
maxOutboundStopStreams;
|
43
|
+
stopTimeout;
|
44
|
+
started;
|
45
|
+
log;
|
46
|
+
constructor(components, init) {
|
47
|
+
this.log = components.logger.forComponent('libp2p:circuit-relay:transport');
|
48
|
+
this.registrar = components.registrar;
|
49
|
+
this.peerStore = components.peerStore;
|
50
|
+
this.connectionManager = components.connectionManager;
|
51
|
+
this.transportManager = components.transportManager;
|
52
|
+
this.logger = components.logger;
|
53
|
+
this.peerId = components.peerId;
|
54
|
+
this.upgrader = components.upgrader;
|
55
|
+
this.addressManager = components.addressManager;
|
56
|
+
this.connectionGater = components.connectionGater;
|
57
|
+
this.maxInboundStopStreams = init.maxInboundStopStreams ?? defaults.maxInboundStopStreams;
|
58
|
+
this.maxOutboundStopStreams = init.maxOutboundStopStreams ?? defaults.maxOutboundStopStreams;
|
59
|
+
this.stopTimeout = init.stopTimeout ?? defaults.stopTimeout;
|
60
|
+
if (init.discoverRelays != null && init.discoverRelays > 0) {
|
61
|
+
this.discovery = new RelayDiscovery(components);
|
62
|
+
this.discovery.addEventListener('relay:discover', (evt) => {
|
63
|
+
this.reservationStore.addRelay(evt.detail, 'discovered')
|
64
|
+
.catch(err => {
|
65
|
+
this.log.error('could not add discovered relay %p', evt.detail, err);
|
66
|
+
});
|
67
|
+
});
|
68
|
+
}
|
69
|
+
this.reservationStore = new ReservationStore(components, init);
|
70
|
+
this.reservationStore.addEventListener('relay:not-enough-relays', () => {
|
71
|
+
this.discovery?.discover()
|
72
|
+
.catch(err => {
|
73
|
+
this.log.error('could not discover relays', err);
|
74
|
+
});
|
75
|
+
});
|
76
|
+
this.started = false;
|
77
|
+
}
|
78
|
+
isStarted() {
|
79
|
+
return this.started;
|
80
|
+
}
|
81
|
+
async start() {
|
82
|
+
await this.reservationStore.start();
|
83
|
+
await this.discovery?.start();
|
84
|
+
await this.registrar.handle(RELAY_V2_STOP_CODEC, (data) => {
|
85
|
+
void this.onStop(data).catch(err => {
|
86
|
+
this.log.error('error while handling STOP protocol', err);
|
87
|
+
data.stream.abort(err);
|
88
|
+
});
|
89
|
+
}, {
|
90
|
+
maxInboundStreams: this.maxInboundStopStreams,
|
91
|
+
maxOutboundStreams: this.maxOutboundStopStreams,
|
92
|
+
runOnTransientConnection: true
|
93
|
+
});
|
94
|
+
this.started = true;
|
95
|
+
}
|
96
|
+
async stop() {
|
97
|
+
this.discovery?.stop();
|
98
|
+
await this.reservationStore.stop();
|
99
|
+
await this.registrar.unhandle(RELAY_V2_STOP_CODEC);
|
100
|
+
this.started = false;
|
101
|
+
}
|
102
|
+
[transportSymbol] = true;
|
103
|
+
[Symbol.toStringTag] = 'libp2p/circuit-relay-v2';
|
104
|
+
/**
|
105
|
+
* Dial a peer over a relay
|
106
|
+
*/
|
107
|
+
async dial(ma, options = {}) {
|
108
|
+
if (ma.protoCodes().filter(code => code === CIRCUIT_PROTO_CODE).length !== 1) {
|
109
|
+
const errMsg = 'Invalid circuit relay address';
|
110
|
+
this.log.error(errMsg, ma);
|
111
|
+
throw new CodeError(errMsg, ERR_RELAYED_DIAL);
|
112
|
+
}
|
113
|
+
// Check the multiaddr to see if it contains a relay and a destination peer
|
114
|
+
const addrs = ma.toString().split('/p2p-circuit');
|
115
|
+
const relayAddr = multiaddr(addrs[0]);
|
116
|
+
const destinationAddr = multiaddr(addrs[addrs.length - 1]);
|
117
|
+
const relayId = relayAddr.getPeerId();
|
118
|
+
const destinationId = destinationAddr.getPeerId();
|
119
|
+
if (relayId == null || destinationId == null) {
|
120
|
+
const errMsg = `Circuit relay dial to ${ma.toString()} failed as address did not have peer ids`;
|
121
|
+
this.log.error(errMsg);
|
122
|
+
throw new CodeError(errMsg, ERR_RELAYED_DIAL);
|
123
|
+
}
|
124
|
+
const relayPeer = peerIdFromString(relayId);
|
125
|
+
const destinationPeer = peerIdFromString(destinationId);
|
126
|
+
let disconnectOnFailure = false;
|
127
|
+
const relayConnections = this.connectionManager.getConnections(relayPeer);
|
128
|
+
let relayConnection = relayConnections[0];
|
129
|
+
if (relayConnection == null) {
|
130
|
+
await this.peerStore.merge(relayPeer, {
|
131
|
+
multiaddrs: [relayAddr]
|
132
|
+
});
|
133
|
+
relayConnection = await this.connectionManager.openConnection(relayPeer, options);
|
134
|
+
disconnectOnFailure = true;
|
135
|
+
}
|
136
|
+
let stream;
|
137
|
+
try {
|
138
|
+
stream = await relayConnection.newStream(RELAY_V2_HOP_CODEC);
|
139
|
+
return await this.connectV2({
|
140
|
+
stream,
|
141
|
+
connection: relayConnection,
|
142
|
+
destinationPeer,
|
143
|
+
destinationAddr,
|
144
|
+
relayAddr,
|
145
|
+
ma,
|
146
|
+
disconnectOnFailure
|
147
|
+
});
|
148
|
+
}
|
149
|
+
catch (err) {
|
150
|
+
this.log.error('circuit relay dial to destination %p via relay %p failed', destinationPeer, relayPeer, err);
|
151
|
+
if (stream != null) {
|
152
|
+
stream.abort(err);
|
153
|
+
}
|
154
|
+
disconnectOnFailure && await relayConnection.close();
|
155
|
+
throw err;
|
156
|
+
}
|
157
|
+
}
|
158
|
+
async connectV2({ stream, connection, destinationPeer, destinationAddr, relayAddr, ma, disconnectOnFailure }) {
|
159
|
+
try {
|
160
|
+
const pbstr = pbStream(stream);
|
161
|
+
const hopstr = pbstr.pb(HopMessage);
|
162
|
+
await hopstr.write({
|
163
|
+
type: HopMessage.Type.CONNECT,
|
164
|
+
peer: {
|
165
|
+
id: destinationPeer.toBytes(),
|
166
|
+
addrs: [multiaddr(destinationAddr).bytes]
|
167
|
+
}
|
168
|
+
});
|
169
|
+
const status = await hopstr.read();
|
170
|
+
if (status.status !== Status.OK) {
|
171
|
+
throw new CodeError(`failed to connect via relay with status ${status?.status?.toString() ?? 'undefined'}`, ERR_HOP_REQUEST_FAILED);
|
172
|
+
}
|
173
|
+
const maConn = streamToMaConnection({
|
174
|
+
stream: pbstr.unwrap(),
|
175
|
+
remoteAddr: ma,
|
176
|
+
localAddr: relayAddr.encapsulate(`/p2p-circuit/p2p/${this.peerId.toString()}`),
|
177
|
+
logger: this.logger
|
178
|
+
});
|
179
|
+
this.log('new outbound transient connection %a', maConn.remoteAddr);
|
180
|
+
return await this.upgrader.upgradeOutbound(maConn, {
|
181
|
+
transient: true
|
182
|
+
});
|
183
|
+
}
|
184
|
+
catch (err) {
|
185
|
+
this.log.error(`Circuit relay dial to destination ${destinationPeer.toString()} via relay ${connection.remotePeer.toString()} failed`, err);
|
186
|
+
disconnectOnFailure && await connection.close();
|
187
|
+
throw err;
|
188
|
+
}
|
189
|
+
}
|
190
|
+
/**
|
191
|
+
* Create a listener
|
192
|
+
*/
|
193
|
+
createListener(options) {
|
194
|
+
return createListener({
|
195
|
+
connectionManager: this.connectionManager,
|
196
|
+
relayStore: this.reservationStore,
|
197
|
+
logger: this.logger
|
198
|
+
});
|
199
|
+
}
|
200
|
+
/**
|
201
|
+
* Filter check for all Multiaddrs that this transport can dial on
|
202
|
+
*
|
203
|
+
* @param {Multiaddr[]} multiaddrs
|
204
|
+
* @returns {Multiaddr[]}
|
205
|
+
*/
|
206
|
+
filter(multiaddrs) {
|
207
|
+
multiaddrs = Array.isArray(multiaddrs) ? multiaddrs : [multiaddrs];
|
208
|
+
return multiaddrs.filter((ma) => {
|
209
|
+
return mafmt.Circuit.matches(ma);
|
210
|
+
});
|
211
|
+
}
|
212
|
+
/**
|
213
|
+
* An incoming STOP request means a remote peer wants to dial us via a relay
|
214
|
+
*/
|
215
|
+
async onStop({ connection, stream }) {
|
216
|
+
if (!this.reservationStore.hasReservation(connection.remotePeer)) {
|
217
|
+
try {
|
218
|
+
this.log('dialed via relay we did not have a reservation on, start listening on that relay address');
|
219
|
+
await this.transportManager.listen([connection.remoteAddr.encapsulate('/p2p-circuit')]);
|
220
|
+
}
|
221
|
+
catch (err) {
|
222
|
+
// failed to refresh our hitherto unknown relay reservation but allow the connection attempt anyway
|
223
|
+
this.log.error('failed to listen on a relay peer we were dialed via but did not have a reservation on', err);
|
224
|
+
}
|
225
|
+
}
|
226
|
+
const signal = AbortSignal.timeout(this.stopTimeout);
|
227
|
+
const pbstr = pbStream(stream).pb(StopMessage);
|
228
|
+
const request = await pbstr.read({
|
229
|
+
signal
|
230
|
+
});
|
231
|
+
this.log('new circuit relay v2 stop stream from %p with type %s', connection.remotePeer, request.type);
|
232
|
+
if (request?.type === undefined) {
|
233
|
+
this.log.error('type was missing from circuit v2 stop protocol request from %s', connection.remotePeer);
|
234
|
+
await pbstr.write({ type: StopMessage.Type.STATUS, status: Status.MALFORMED_MESSAGE }, {
|
235
|
+
signal
|
236
|
+
});
|
237
|
+
await stream.close();
|
238
|
+
return;
|
239
|
+
}
|
240
|
+
// Validate the STOP request has the required input
|
241
|
+
if (request.type !== StopMessage.Type.CONNECT) {
|
242
|
+
this.log.error('invalid stop connect request via peer %p', connection.remotePeer);
|
243
|
+
await pbstr.write({ type: StopMessage.Type.STATUS, status: Status.UNEXPECTED_MESSAGE }, {
|
244
|
+
signal
|
245
|
+
});
|
246
|
+
await stream.close();
|
247
|
+
return;
|
248
|
+
}
|
249
|
+
if (!isValidStop(request)) {
|
250
|
+
this.log.error('invalid stop connect request via peer %p', connection.remotePeer);
|
251
|
+
await pbstr.write({ type: StopMessage.Type.STATUS, status: Status.MALFORMED_MESSAGE }, {
|
252
|
+
signal
|
253
|
+
});
|
254
|
+
await stream.close();
|
255
|
+
return;
|
256
|
+
}
|
257
|
+
const remotePeerId = peerIdFromBytes(request.peer.id);
|
258
|
+
if ((await this.connectionGater.denyInboundRelayedConnection?.(connection.remotePeer, remotePeerId)) === true) {
|
259
|
+
this.log.error('connection gater denied inbound relayed connection from %p', connection.remotePeer);
|
260
|
+
await pbstr.write({ type: StopMessage.Type.STATUS, status: Status.PERMISSION_DENIED }, {
|
261
|
+
signal
|
262
|
+
});
|
263
|
+
await stream.close();
|
264
|
+
return;
|
265
|
+
}
|
266
|
+
this.log.trace('sending success response to %p', connection.remotePeer);
|
267
|
+
await pbstr.write({ type: StopMessage.Type.STATUS, status: Status.OK }, {
|
268
|
+
signal
|
269
|
+
});
|
270
|
+
const remoteAddr = connection.remoteAddr.encapsulate(`/p2p-circuit/p2p/${remotePeerId.toString()}`);
|
271
|
+
const localAddr = this.addressManager.getAddresses()[0];
|
272
|
+
const maConn = streamToMaConnection({
|
273
|
+
stream: pbstr.unwrap().unwrap(),
|
274
|
+
remoteAddr,
|
275
|
+
localAddr,
|
276
|
+
logger: this.logger
|
277
|
+
});
|
278
|
+
this.log('new inbound transient connection %a', maConn.remoteAddr);
|
279
|
+
await this.upgrader.upgradeInbound(maConn, {
|
280
|
+
transient: true
|
281
|
+
});
|
282
|
+
this.log('%s connection %a upgraded', 'inbound', maConn.remoteAddr);
|
283
|
+
}
|
284
|
+
}
|
285
|
+
//# sourceMappingURL=transport.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../../src/transport/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAC9D,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAA;AACtE,OAAO,KAAK,KAAK,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,eAAe,EAAE,kBAAkB,EAAE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AW,CAAC,oBAAoB,YAAY,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;QACnG,MAAM,SAAS,GAAG,IAAI,CAAC,cAAc,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,CAAA;QACvD,MAAM,MAAM,GAAG,oBAAoB,CAAC;YAClC,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE;YAC/B,UAAU;YACV,SAAS;YACT,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC,CAAA;QAEF,IAAI,CAAC,GAAG,CAAC,qCAAqC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;QAClE,MAAM,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,EAAE;YACzC,SAAS,EAAE,IAAI;SAChB,CAAC,CAAA;QACF,IAAI,CAAC,GAAG,CAAC,2BAA2B,EAAE,SAAS,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;IACrE,CAAC;CACF"}
|
package/dist/src/utils.d.ts
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
import { CID } from 'multiformats/cid';
|
2
2
|
import type { Limit } from './pb/index.js';
|
3
|
-
import type { LoggerOptions } from '@libp2p/interface';
|
4
|
-
import type { Stream } from '@libp2p/interface/connection';
|
3
|
+
import type { LoggerOptions, Stream } from '@libp2p/interface';
|
5
4
|
export declare function createLimitedRelay(src: Stream, dst: Stream, abortSignal: AbortSignal, limit: Limit | undefined, options: LoggerOptions): void;
|
6
5
|
/**
|
7
6
|
* Convert a namespace string into a cid
|
package/dist/src/utils.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAGtC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAGtC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AA+B9D,wBAAgB,kBAAkB,CAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,GAAG,SAAS,EAAE,OAAO,EAAE,aAAa,GAAG,IAAI,CAoE9I;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAKrE;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAE,iBAAiB,EAAE,MAAM,GAAG,MAAM,CAM5E"}
|
package/dist/src/utils.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { CodeError } from '@libp2p/interface
|
1
|
+
import { CodeError } from '@libp2p/interface';
|
2
2
|
import { anySignal } from 'any-signal';
|
3
3
|
import { CID } from 'multiformats/cid';
|
4
4
|
import { sha256 } from 'multiformats/hashes/sha2';
|
@@ -29,16 +29,12 @@ export function createLimitedRelay(src, dst, abortSignal, limit, options) {
|
|
29
29
|
function abortStreams(err) {
|
30
30
|
src.abort(err);
|
31
31
|
dst.abort(err);
|
32
|
-
clearTimeout(timeout);
|
33
32
|
}
|
34
|
-
const
|
35
|
-
const signal = anySignal([abortSignal, abortController.signal]);
|
36
|
-
let timeout;
|
33
|
+
const signals = [abortSignal];
|
37
34
|
if (limit?.duration != null) {
|
38
|
-
timeout
|
39
|
-
abortController.abort();
|
40
|
-
}, limit.duration);
|
35
|
+
signals.push(AbortSignal.timeout(limit.duration));
|
41
36
|
}
|
37
|
+
const signal = anySignal(signals);
|
42
38
|
let srcDstFinished = false;
|
43
39
|
let dstSrcFinished = false;
|
44
40
|
let dataLimit;
|
@@ -62,7 +58,6 @@ export function createLimitedRelay(src, dst, abortSignal, limit, options) {
|
|
62
58
|
if (dstSrcFinished) {
|
63
59
|
signal.removeEventListener('abort', onAbort);
|
64
60
|
signal.clear();
|
65
|
-
clearTimeout(timeout);
|
66
61
|
}
|
67
62
|
});
|
68
63
|
});
|
@@ -81,7 +76,6 @@ export function createLimitedRelay(src, dst, abortSignal, limit, options) {
|
|
81
76
|
if (srcDstFinished) {
|
82
77
|
signal.removeEventListener('abort', onAbort);
|
83
78
|
signal.clear();
|
84
|
-
clearTimeout(timeout);
|
85
79
|
}
|
86
80
|
});
|
87
81
|
});
|
package/dist/src/utils.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AACjD,OAAO,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAA;AAM5D,KAAK,SAAU,CAAC,CAAC,gBAAgB,CAAE,MAA2C,EAAE,KAA4B,EAAE,OAAsB;IAClI,MAAM,UAAU,GAAG,KAAK,CAAC,SAAS,CAAA;IAElC,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;QAC/B,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;QAElC,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,GAAG,CAAC,GAAG,CAAC,EAAE,C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
|
2
2
|
"name": "@libp2p/circuit-relay-v2",
|
3
|
-
"version": "
|
3
|
+
"version": "1.0.0-551622a96",
|
4
4
|
"description": "Implementation of Circuit Relay v2",
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
6
|
-
"homepage": "https://github.com/libp2p/js-libp2p/tree/
|
6
|
+
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/transport-circuit-relay-v2#readme",
|
7
7
|
"repository": {
|
8
8
|
"type": "git",
|
9
9
|
"url": "git+https://github.com/libp2p/js-libp2p.git"
|
@@ -11,6 +11,10 @@
|
|
11
11
|
"bugs": {
|
12
12
|
"url": "https://github.com/libp2p/js-libp2p/issues"
|
13
13
|
},
|
14
|
+
"publishConfig": {
|
15
|
+
"access": "public",
|
16
|
+
"provenance": true
|
17
|
+
},
|
14
18
|
"type": "module",
|
15
19
|
"types": "./dist/src/index.d.ts",
|
16
20
|
"files": [
|
@@ -47,12 +51,12 @@
|
|
47
51
|
"dep-check": "aegir dep-check"
|
48
52
|
},
|
49
53
|
"dependencies": {
|
50
|
-
"@libp2p/interface": "
|
51
|
-
"@libp2p/interface-internal": "
|
52
|
-
"@libp2p/peer-collections": "
|
53
|
-
"@libp2p/peer-id": "
|
54
|
-
"@libp2p/peer-record": "
|
55
|
-
"@libp2p/utils": "
|
54
|
+
"@libp2p/interface": "1.0.0-551622a96",
|
55
|
+
"@libp2p/interface-internal": "0.1.10-551622a96",
|
56
|
+
"@libp2p/peer-collections": "4.0.9-551622a96",
|
57
|
+
"@libp2p/peer-id": "4.0.0-551622a96",
|
58
|
+
"@libp2p/peer-record": "6.0.10-551622a96",
|
59
|
+
"@libp2p/utils": "5.0.0-551622a96",
|
56
60
|
"@multiformats/mafmt": "^12.1.6",
|
57
61
|
"@multiformats/multiaddr": "^12.1.10",
|
58
62
|
"any-signal": "^4.1.1",
|
@@ -63,13 +67,14 @@
|
|
63
67
|
"p-defer": "^4.0.0",
|
64
68
|
"p-retry": "^6.1.0",
|
65
69
|
"protons-runtime": "^5.0.0",
|
70
|
+
"race-signal": "^1.0.2",
|
66
71
|
"uint8arraylist": "^2.4.3",
|
67
72
|
"uint8arrays": "^4.0.6"
|
68
73
|
},
|
69
74
|
"devDependencies": {
|
70
|
-
"@libp2p/interface-compliance-tests": "
|
71
|
-
"@libp2p/logger": "
|
72
|
-
"@libp2p/peer-id-factory": "
|
75
|
+
"@libp2p/interface-compliance-tests": "5.0.0-551622a96",
|
76
|
+
"@libp2p/logger": "4.0.0-551622a96",
|
77
|
+
"@libp2p/peer-id-factory": "3.0.9-551622a96",
|
73
78
|
"aegir": "^41.0.2",
|
74
79
|
"it-drain": "^3.0.3",
|
75
80
|
"it-pair": "^2.0.6",
|
package/src/index.ts
CHANGED
@@ -35,7 +35,7 @@
|
|
35
35
|
*/
|
36
36
|
|
37
37
|
import type { Limit } from './pb/index.js'
|
38
|
-
import type { TypedEventEmitter } from '@libp2p/interface
|
38
|
+
import type { TypedEventEmitter } from '@libp2p/interface'
|
39
39
|
import type { PeerMap } from '@libp2p/peer-collections'
|
40
40
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
41
41
|
|
@@ -55,8 +55,8 @@ export interface CircuitRelayService extends TypedEventEmitter<CircuitRelayServi
|
|
55
55
|
reservations: PeerMap<RelayReservation>
|
56
56
|
}
|
57
57
|
|
58
|
-
export { circuitRelayServer } from './server/index.js'
|
59
|
-
export { circuitRelayTransport } from './transport/index.js'
|
58
|
+
export { circuitRelayServer, type CircuitRelayServerInit, type CircuitRelayServerComponents } from './server/index.js'
|
59
|
+
export { circuitRelayTransport, type CircuitRelayTransportInit, type CircuitRelayTransportComponents } from './transport/index.js'
|
60
60
|
|
61
61
|
export {
|
62
62
|
RELAY_V2_HOP_CODEC,
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { TypedEventEmitter } from '@libp2p/interface
|
1
|
+
import { TypedEventEmitter } from '@libp2p/interface'
|
2
2
|
import pRetry from 'p-retry'
|
3
3
|
import {
|
4
4
|
DEFAULT_ADVERT_BOOT_DELAY,
|
@@ -6,9 +6,7 @@ import {
|
|
6
6
|
RELAY_RENDEZVOUS_NS
|
7
7
|
} from '../constants.js'
|
8
8
|
import { namespaceToCid } from '../utils.js'
|
9
|
-
import type { ComponentLogger, Logger } from '@libp2p/interface'
|
10
|
-
import type { ContentRouting } from '@libp2p/interface/content-routing'
|
11
|
-
import type { Startable } from '@libp2p/interface/startable'
|
9
|
+
import type { ComponentLogger, Logger, ContentRouting, Startable } from '@libp2p/interface'
|
12
10
|
|
13
11
|
export interface AdvertServiceInit {
|
14
12
|
/**
|
package/src/server/index.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { TypedEventEmitter, setMaxListeners } from '@libp2p/interface
|
1
|
+
import { TypedEventEmitter, setMaxListeners } from '@libp2p/interface'
|
2
2
|
import { peerIdFromBytes } from '@libp2p/peer-id'
|
3
3
|
import { RecordEnvelope } from '@libp2p/peer-record'
|
4
4
|
import { type Multiaddr, multiaddr } from '@multiformats/multiaddr'
|
@@ -18,15 +18,8 @@ import { AdvertService, type AdvertServiceComponents, type AdvertServiceInit } f
|
|
18
18
|
import { ReservationStore, type ReservationStoreInit } from './reservation-store.js'
|
19
19
|
import { ReservationVoucherRecord } from './reservation-voucher.js'
|
20
20
|
import type { CircuitRelayService, RelayReservation } from '../index.js'
|
21
|
-
import type { ComponentLogger, Logger } from '@libp2p/interface'
|
22
|
-
import type {
|
23
|
-
import type { ConnectionGater } from '@libp2p/interface/connection-gater'
|
24
|
-
import type { PeerId } from '@libp2p/interface/peer-id'
|
25
|
-
import type { PeerStore } from '@libp2p/interface/peer-store'
|
26
|
-
import type { Startable } from '@libp2p/interface/startable'
|
27
|
-
import type { AddressManager } from '@libp2p/interface-internal/address-manager'
|
28
|
-
import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager'
|
29
|
-
import type { IncomingStreamData, Registrar } from '@libp2p/interface-internal/registrar'
|
21
|
+
import type { ComponentLogger, Logger, Connection, Stream, ConnectionGater, PeerId, PeerStore, Startable } from '@libp2p/interface'
|
22
|
+
import type { AddressManager, ConnectionManager, IncomingStreamData, Registrar } from '@libp2p/interface-internal'
|
30
23
|
import type { PeerMap } from '@libp2p/peer-collections'
|
31
24
|
|
32
25
|
const isRelayAddr = (ma: Multiaddr): boolean => ma.protoCodes().includes(CIRCUIT_PROTO_CODE)
|
@@ -2,9 +2,7 @@ import { PeerMap } from '@libp2p/peer-collections'
|
|
2
2
|
import { DEFAULT_DATA_LIMIT, DEFAULT_DURATION_LIMIT, DEFAULT_MAX_RESERVATION_CLEAR_INTERVAL, DEFAULT_MAX_RESERVATION_STORE_SIZE, DEFAULT_MAX_RESERVATION_TTL } from '../constants.js'
|
3
3
|
import { type Limit, Status } from '../pb/index.js'
|
4
4
|
import type { RelayReservation } from '../index.js'
|
5
|
-
import type { RecursivePartial } from '@libp2p/interface'
|
6
|
-
import type { PeerId } from '@libp2p/interface/peer-id'
|
7
|
-
import type { Startable } from '@libp2p/interface/startable'
|
5
|
+
import type { RecursivePartial, PeerId, Startable } from '@libp2p/interface'
|
8
6
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
9
7
|
|
10
8
|
export type ReservationStatus = Status.OK | Status.PERMISSION_DENIED | Status.RESERVATION_REFUSED
|
@@ -1,6 +1,5 @@
|
|
1
1
|
import { ReservationVoucher } from '../pb/index.js'
|
2
|
-
import type { PeerId } from '@libp2p/interface
|
3
|
-
import type { Record } from '@libp2p/interface/record'
|
2
|
+
import type { PeerId, Record } from '@libp2p/interface'
|
4
3
|
|
5
4
|
export interface ReservationVoucherOptions {
|
6
5
|
relay: PeerId
|
@@ -1,17 +1,11 @@
|
|
1
|
-
import { TypedEventEmitter } from '@libp2p/interface
|
1
|
+
import { TypedEventEmitter } from '@libp2p/interface'
|
2
2
|
import {
|
3
3
|
RELAY_RENDEZVOUS_NS,
|
4
4
|
RELAY_V2_HOP_CODEC
|
5
5
|
} from '../constants.js'
|
6
6
|
import { namespaceToCid } from '../utils.js'
|
7
|
-
import type { ComponentLogger, Logger } from '@libp2p/interface'
|
8
|
-
import type {
|
9
|
-
import type { PeerId } from '@libp2p/interface/peer-id'
|
10
|
-
import type { PeerStore } from '@libp2p/interface/peer-store'
|
11
|
-
import type { Startable } from '@libp2p/interface/startable'
|
12
|
-
import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager'
|
13
|
-
import type { Registrar } from '@libp2p/interface-internal/registrar'
|
14
|
-
import type { TransportManager } from '@libp2p/interface-internal/transport-manager'
|
7
|
+
import type { ComponentLogger, Logger, ContentRouting, PeerId, PeerStore, Startable } from '@libp2p/interface'
|
8
|
+
import type { ConnectionManager, Registrar, TransportManager } from '@libp2p/interface-internal'
|
15
9
|
|
16
10
|
export interface RelayDiscoveryEvents {
|
17
11
|
'relay:discover': CustomEvent<PeerId>
|