@libp2p/circuit-relay-v2 0.0.0 → 1.0.0-7682861f9
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
@@ -1,276 +1,7 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
import * as mafmt from '@multiformats/mafmt';
|
6
|
-
import { multiaddr } from '@multiformats/multiaddr';
|
7
|
-
import { pbStream } from 'it-protobuf-stream';
|
8
|
-
import { CIRCUIT_PROTO_CODE, ERR_HOP_REQUEST_FAILED, ERR_RELAYED_DIAL, MAX_CONNECTIONS, RELAY_V2_HOP_CODEC, RELAY_V2_STOP_CODEC } from '../constants.js';
|
9
|
-
import { StopMessage, HopMessage, Status } from '../pb/index.js';
|
10
|
-
import { RelayDiscovery } from './discovery.js';
|
11
|
-
import { createListener } from './listener.js';
|
12
|
-
import { ReservationStore } from './reservation-store.js';
|
13
|
-
const isValidStop = (request) => {
|
14
|
-
if (request.peer == null) {
|
15
|
-
return false;
|
16
|
-
}
|
17
|
-
try {
|
18
|
-
request.peer.addrs.forEach(multiaddr);
|
19
|
-
}
|
20
|
-
catch {
|
21
|
-
return false;
|
22
|
-
}
|
23
|
-
return true;
|
24
|
-
};
|
25
|
-
const defaults = {
|
26
|
-
maxInboundStopStreams: MAX_CONNECTIONS,
|
27
|
-
maxOutboundStopStreams: MAX_CONNECTIONS,
|
28
|
-
stopTimeout: 30000
|
29
|
-
};
|
30
|
-
class CircuitRelayTransport {
|
31
|
-
discovery;
|
32
|
-
registrar;
|
33
|
-
peerStore;
|
34
|
-
connectionManager;
|
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.logger = components.logger;
|
52
|
-
this.peerId = components.peerId;
|
53
|
-
this.upgrader = components.upgrader;
|
54
|
-
this.addressManager = components.addressManager;
|
55
|
-
this.connectionGater = components.connectionGater;
|
56
|
-
this.maxInboundStopStreams = init.maxInboundStopStreams ?? defaults.maxInboundStopStreams;
|
57
|
-
this.maxOutboundStopStreams = init.maxOutboundStopStreams ?? defaults.maxOutboundStopStreams;
|
58
|
-
this.stopTimeout = init.stopTimeout ?? defaults.stopTimeout;
|
59
|
-
if (init.discoverRelays != null && init.discoverRelays > 0) {
|
60
|
-
this.discovery = new RelayDiscovery(components);
|
61
|
-
this.discovery.addEventListener('relay:discover', (evt) => {
|
62
|
-
this.reservationStore.addRelay(evt.detail, 'discovered')
|
63
|
-
.catch(err => {
|
64
|
-
this.log.error('could not add discovered relay %p', evt.detail, err);
|
65
|
-
});
|
66
|
-
});
|
67
|
-
}
|
68
|
-
this.reservationStore = new ReservationStore(components, init);
|
69
|
-
this.reservationStore.addEventListener('relay:not-enough-relays', () => {
|
70
|
-
this.discovery?.discover()
|
71
|
-
.catch(err => {
|
72
|
-
this.log.error('could not discover relays', err);
|
73
|
-
});
|
74
|
-
});
|
75
|
-
this.started = false;
|
76
|
-
}
|
77
|
-
isStarted() {
|
78
|
-
return this.started;
|
79
|
-
}
|
80
|
-
async start() {
|
81
|
-
await this.reservationStore.start();
|
82
|
-
await this.discovery?.start();
|
83
|
-
await this.registrar.handle(RELAY_V2_STOP_CODEC, (data) => {
|
84
|
-
void this.onStop(data).catch(err => {
|
85
|
-
this.log.error('error while handling STOP protocol', err);
|
86
|
-
data.stream.abort(err);
|
87
|
-
});
|
88
|
-
}, {
|
89
|
-
maxInboundStreams: this.maxInboundStopStreams,
|
90
|
-
maxOutboundStreams: this.maxOutboundStopStreams,
|
91
|
-
runOnTransientConnection: true
|
92
|
-
});
|
93
|
-
this.started = true;
|
94
|
-
}
|
95
|
-
async stop() {
|
96
|
-
this.discovery?.stop();
|
97
|
-
await this.reservationStore.stop();
|
98
|
-
await this.registrar.unhandle(RELAY_V2_STOP_CODEC);
|
99
|
-
this.started = false;
|
100
|
-
}
|
101
|
-
[symbol] = true;
|
102
|
-
[Symbol.toStringTag] = 'libp2p/circuit-relay-v2';
|
103
|
-
/**
|
104
|
-
* Dial a peer over a relay
|
105
|
-
*/
|
106
|
-
async dial(ma, options = {}) {
|
107
|
-
if (ma.protoCodes().filter(code => code === CIRCUIT_PROTO_CODE).length !== 1) {
|
108
|
-
const errMsg = 'Invalid circuit relay address';
|
109
|
-
this.log.error(errMsg, ma);
|
110
|
-
throw new CodeError(errMsg, ERR_RELAYED_DIAL);
|
111
|
-
}
|
112
|
-
// Check the multiaddr to see if it contains a relay and a destination peer
|
113
|
-
const addrs = ma.toString().split('/p2p-circuit');
|
114
|
-
const relayAddr = multiaddr(addrs[0]);
|
115
|
-
const destinationAddr = multiaddr(addrs[addrs.length - 1]);
|
116
|
-
const relayId = relayAddr.getPeerId();
|
117
|
-
const destinationId = destinationAddr.getPeerId();
|
118
|
-
if (relayId == null || destinationId == null) {
|
119
|
-
const errMsg = `Circuit relay dial to ${ma.toString()} failed as address did not have peer ids`;
|
120
|
-
this.log.error(errMsg);
|
121
|
-
throw new CodeError(errMsg, ERR_RELAYED_DIAL);
|
122
|
-
}
|
123
|
-
const relayPeer = peerIdFromString(relayId);
|
124
|
-
const destinationPeer = peerIdFromString(destinationId);
|
125
|
-
let disconnectOnFailure = false;
|
126
|
-
const relayConnections = this.connectionManager.getConnections(relayPeer);
|
127
|
-
let relayConnection = relayConnections[0];
|
128
|
-
if (relayConnection == null) {
|
129
|
-
await this.peerStore.merge(relayPeer, {
|
130
|
-
multiaddrs: [relayAddr]
|
131
|
-
});
|
132
|
-
relayConnection = await this.connectionManager.openConnection(relayPeer, options);
|
133
|
-
disconnectOnFailure = true;
|
134
|
-
}
|
135
|
-
let stream;
|
136
|
-
try {
|
137
|
-
stream = await relayConnection.newStream([RELAY_V2_HOP_CODEC]);
|
138
|
-
return await this.connectV2({
|
139
|
-
stream,
|
140
|
-
connection: relayConnection,
|
141
|
-
destinationPeer,
|
142
|
-
destinationAddr,
|
143
|
-
relayAddr,
|
144
|
-
ma,
|
145
|
-
disconnectOnFailure
|
146
|
-
});
|
147
|
-
}
|
148
|
-
catch (err) {
|
149
|
-
this.log.error('circuit relay dial to destination %p via relay %p failed', destinationPeer, relayPeer, err);
|
150
|
-
if (stream != null) {
|
151
|
-
stream.abort(err);
|
152
|
-
}
|
153
|
-
disconnectOnFailure && await relayConnection.close();
|
154
|
-
throw err;
|
155
|
-
}
|
156
|
-
}
|
157
|
-
async connectV2({ stream, connection, destinationPeer, destinationAddr, relayAddr, ma, disconnectOnFailure }) {
|
158
|
-
try {
|
159
|
-
const pbstr = pbStream(stream);
|
160
|
-
const hopstr = pbstr.pb(HopMessage);
|
161
|
-
await hopstr.write({
|
162
|
-
type: HopMessage.Type.CONNECT,
|
163
|
-
peer: {
|
164
|
-
id: destinationPeer.toBytes(),
|
165
|
-
addrs: [multiaddr(destinationAddr).bytes]
|
166
|
-
}
|
167
|
-
});
|
168
|
-
const status = await hopstr.read();
|
169
|
-
if (status.status !== Status.OK) {
|
170
|
-
throw new CodeError(`failed to connect via relay with status ${status?.status?.toString() ?? 'undefined'}`, ERR_HOP_REQUEST_FAILED);
|
171
|
-
}
|
172
|
-
const maConn = streamToMaConnection({
|
173
|
-
stream: pbstr.unwrap(),
|
174
|
-
remoteAddr: ma,
|
175
|
-
localAddr: relayAddr.encapsulate(`/p2p-circuit/p2p/${this.peerId.toString()}`),
|
176
|
-
logger: this.logger
|
177
|
-
});
|
178
|
-
this.log('new outbound transient connection %a', maConn.remoteAddr);
|
179
|
-
return await this.upgrader.upgradeOutbound(maConn, {
|
180
|
-
transient: true
|
181
|
-
});
|
182
|
-
}
|
183
|
-
catch (err) {
|
184
|
-
this.log.error(`Circuit relay dial to destination ${destinationPeer.toString()} via relay ${connection.remotePeer.toString()} failed`, err);
|
185
|
-
disconnectOnFailure && await connection.close();
|
186
|
-
throw err;
|
187
|
-
}
|
188
|
-
}
|
189
|
-
/**
|
190
|
-
* Create a listener
|
191
|
-
*/
|
192
|
-
createListener(options) {
|
193
|
-
return createListener({
|
194
|
-
connectionManager: this.connectionManager,
|
195
|
-
relayStore: this.reservationStore,
|
196
|
-
logger: this.logger
|
197
|
-
});
|
198
|
-
}
|
199
|
-
/**
|
200
|
-
* Filter check for all Multiaddrs that this transport can dial on
|
201
|
-
*
|
202
|
-
* @param {Multiaddr[]} multiaddrs
|
203
|
-
* @returns {Multiaddr[]}
|
204
|
-
*/
|
205
|
-
filter(multiaddrs) {
|
206
|
-
multiaddrs = Array.isArray(multiaddrs) ? multiaddrs : [multiaddrs];
|
207
|
-
return multiaddrs.filter((ma) => {
|
208
|
-
return mafmt.Circuit.matches(ma);
|
209
|
-
});
|
210
|
-
}
|
211
|
-
/**
|
212
|
-
* An incoming STOP request means a remote peer wants to dial us via a relay
|
213
|
-
*/
|
214
|
-
async onStop({ connection, stream }) {
|
215
|
-
const signal = AbortSignal.timeout(this.stopTimeout);
|
216
|
-
const pbstr = pbStream(stream).pb(StopMessage);
|
217
|
-
const request = await pbstr.read({
|
218
|
-
signal
|
219
|
-
});
|
220
|
-
this.log('new circuit relay v2 stop stream from %p with type %s', connection.remotePeer, request.type);
|
221
|
-
if (request?.type === undefined) {
|
222
|
-
this.log.error('type was missing from circuit v2 stop protocol request from %s', connection.remotePeer);
|
223
|
-
await pbstr.write({ type: StopMessage.Type.STATUS, status: Status.MALFORMED_MESSAGE }, {
|
224
|
-
signal
|
225
|
-
});
|
226
|
-
await stream.close();
|
227
|
-
return;
|
228
|
-
}
|
229
|
-
// Validate the STOP request has the required input
|
230
|
-
if (request.type !== StopMessage.Type.CONNECT) {
|
231
|
-
this.log.error('invalid stop connect request via peer %p', connection.remotePeer);
|
232
|
-
await pbstr.write({ type: StopMessage.Type.STATUS, status: Status.UNEXPECTED_MESSAGE }, {
|
233
|
-
signal
|
234
|
-
});
|
235
|
-
await stream.close();
|
236
|
-
return;
|
237
|
-
}
|
238
|
-
if (!isValidStop(request)) {
|
239
|
-
this.log.error('invalid stop connect request via peer %p', connection.remotePeer);
|
240
|
-
await pbstr.write({ type: StopMessage.Type.STATUS, status: Status.MALFORMED_MESSAGE }, {
|
241
|
-
signal
|
242
|
-
});
|
243
|
-
await stream.close();
|
244
|
-
return;
|
245
|
-
}
|
246
|
-
const remotePeerId = peerIdFromBytes(request.peer.id);
|
247
|
-
if ((await this.connectionGater.denyInboundRelayedConnection?.(connection.remotePeer, remotePeerId)) === true) {
|
248
|
-
this.log.error('connection gater denied inbound relayed connection from %p', connection.remotePeer);
|
249
|
-
await pbstr.write({ type: StopMessage.Type.STATUS, status: Status.PERMISSION_DENIED }, {
|
250
|
-
signal
|
251
|
-
});
|
252
|
-
await stream.close();
|
253
|
-
return;
|
254
|
-
}
|
255
|
-
this.log.trace('sending success response to %p', connection.remotePeer);
|
256
|
-
await pbstr.write({ type: StopMessage.Type.STATUS, status: Status.OK }, {
|
257
|
-
signal
|
258
|
-
});
|
259
|
-
const remoteAddr = connection.remoteAddr.encapsulate(`/p2p-circuit/p2p/${remotePeerId.toString()}`);
|
260
|
-
const localAddr = this.addressManager.getAddresses()[0];
|
261
|
-
const maConn = streamToMaConnection({
|
262
|
-
stream: pbstr.unwrap().unwrap(),
|
263
|
-
remoteAddr,
|
264
|
-
localAddr,
|
265
|
-
logger: this.logger
|
266
|
-
});
|
267
|
-
this.log('new inbound transient connection %a', maConn.remoteAddr);
|
268
|
-
await this.upgrader.upgradeInbound(maConn, {
|
269
|
-
transient: true
|
270
|
-
});
|
271
|
-
this.log('%s connection %a upgraded', 'inbound', maConn.remoteAddr);
|
272
|
-
}
|
273
|
-
}
|
1
|
+
import {} from '@libp2p/interface';
|
2
|
+
import {} from './discovery.js';
|
3
|
+
import {} from './reservation-store.js';
|
4
|
+
import { CircuitRelayTransport } from './transport.js';
|
274
5
|
export function circuitRelayTransport(init = {}) {
|
275
6
|
return (components) => {
|
276
7
|
return new CircuitRelayTransport(components, init);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/transport/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/transport/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyK,MAAM,mBAAmB,CAAA;AACzM,OAAO,EAAiC,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAuB,MAAM,wBAAwB,CAAA;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAA;AAqDtD,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,7 +1,6 @@
|
|
1
1
|
import type { ReservationStore } from './reservation-store.js';
|
2
|
-
import type { ComponentLogger } from '@libp2p/interface';
|
3
|
-
import type {
|
4
|
-
import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager';
|
2
|
+
import type { ComponentLogger, Listener } from '@libp2p/interface';
|
3
|
+
import type { ConnectionManager } from '@libp2p/interface-internal';
|
5
4
|
export interface CircuitRelayTransportListenerComponents {
|
6
5
|
connectionManager: ConnectionManager;
|
7
6
|
relayStore: ReservationStore;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../../../src/transport/listener.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../../../src/transport/listener.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAC9D,OAAO,KAAK,EAAE,eAAe,EAAkB,QAAQ,EAAkB,MAAM,mBAAmB,CAAA;AAClG,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AAGnE,MAAM,WAAW,uCAAuC;IACtD,iBAAiB,EAAE,iBAAiB,CAAA;IACpC,UAAU,EAAE,gBAAgB,CAAA;IAC5B,MAAM,EAAE,eAAe,CAAA;CACxB;AAiFD,wBAAgB,cAAc,CAAE,OAAO,EAAE,uCAAuC,GAAG,QAAQ,CAE1F"}
|
@@ -1,5 +1,4 @@
|
|
1
|
-
import { CodeError } from '@libp2p/interface
|
2
|
-
import { TypedEventEmitter } from '@libp2p/interface/events';
|
1
|
+
import { CodeError, TypedEventEmitter } from '@libp2p/interface';
|
3
2
|
import { PeerMap } from '@libp2p/peer-collections';
|
4
3
|
import { multiaddr } from '@multiformats/multiaddr';
|
5
4
|
class CircuitRelayTransportListener extends TypedEventEmitter {
|
@@ -25,6 +24,7 @@ class CircuitRelayTransportListener extends TypedEventEmitter {
|
|
25
24
|
const relayAddr = addr.decapsulate('/p2p-circuit');
|
26
25
|
const relayConn = await this.connectionManager.openConnection(relayAddr);
|
27
26
|
if (!this.relayStore.hasReservation(relayConn.remotePeer)) {
|
27
|
+
this.log('making reservation on peer %p', relayConn.remotePeer);
|
28
28
|
// addRelay calls transportManager.listen which calls this listen method
|
29
29
|
await this.relayStore.addRelay(relayConn.remotePeer, 'configured');
|
30
30
|
return;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"listener.js","sourceRoot":"","sources":["../../../src/transport/listener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,
|
1
|
+
{"version":3,"file":"listener.js","sourceRoot":"","sources":["../../../src/transport/listener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAYnD,MAAM,6BAA8B,SAAQ,iBAAiC;IAC1D,iBAAiB,CAAmB;IACpC,UAAU,CAAkB;IAC5B,cAAc,CAAsB;IACpC,GAAG,CAAQ;IAE5B,YAAa,UAAmD;QAC9D,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,yCAAyC,CAAC,CAAA;QACpF,IAAI,CAAC,iBAAiB,GAAG,UAAU,CAAC,iBAAiB,CAAA;QACrD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC,UAAU,CAAA;QACvC,IAAI,CAAC,cAAc,GAAG,IAAI,OAAO,EAAE,CAAA;QAEnC,iDAAiD;QACjD,IAAI,CAAC,UAAU,CAAC,gBAAgB,CAAC,eAAe,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAA;IAC5E,CAAC;IAED,kBAAkB,GAAG,CAAC,GAAwB,EAAQ,EAAE;QACtD,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IACnC,CAAC,CAAA;IAED,KAAK,CAAC,MAAM,CAAE,IAAe;QAC3B,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,CAAA;QAE9B,0DAA0D;QAC1D,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,CAAA;QAClD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,iBAAiB,C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AAI,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QAE3C,IAAI,CAAC,GAAG,CAAC,yCAAyC,EAAE,MAAM,EAAE,GAAG,CAAC,CAAA;QAEhE,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QAElC,IAAI,GAAG,EAAE,CAAC;YACR,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,2CAA2C,EAAE,MAAM,CAAC,CAAA;YACnE,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,eAAe,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAA;YAC7E,mCAAmC;YACnC,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;QACrC,CAAC;IACH,CAAC;CACF;AAED,MAAM,UAAU,cAAc,CAAE,OAAgD;IAC9E,OAAO,IAAI,6BAA6B,CAAC,OAAO,CAAC,CAAA;AACnD,CAAC"}
|
@@ -1,11 +1,6 @@
|
|
1
|
-
import { TypedEventEmitter, type TypedEventTarget } from '@libp2p/interface
|
1
|
+
import { TypedEventEmitter, type TypedEventTarget, type Libp2pEvents, type ComponentLogger, type PeerId, type PeerStore, type Startable } from '@libp2p/interface';
|
2
2
|
import type { Reservation } from '../pb/index.js';
|
3
|
-
import type {
|
4
|
-
import type { PeerId } from '@libp2p/interface/peer-id';
|
5
|
-
import type { PeerStore } from '@libp2p/interface/peer-store';
|
6
|
-
import type { Startable } from '@libp2p/interface/startable';
|
7
|
-
import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager';
|
8
|
-
import type { TransportManager } from '@libp2p/interface-internal/transport-manager';
|
3
|
+
import type { ConnectionManager, TransportManager } from '@libp2p/interface-internal';
|
9
4
|
export interface RelayStoreComponents {
|
10
5
|
peerId: PeerId;
|
11
6
|
connectionManager: ConnectionManager;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"reservation-store.d.ts","sourceRoot":"","sources":["../../../src/transport/reservation-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,
|
1
|
+
{"version":3,"file":"reservation-store.d.ts","sourceRoot":"","sources":["../../../src/transport/reservation-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,KAAK,YAAY,EAAqB,KAAK,eAAe,EAAgC,KAAK,MAAM,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAA;AASnN,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAWrF,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAA;IACd,iBAAiB,EAAE,iBAAiB,CAAA;IACpC,gBAAgB,EAAE,gBAAgB,CAAA;IAClC,SAAS,EAAE,SAAS,CAAA;IACpB,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAA;IACtC,MAAM,EAAE,eAAe,CAAA;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B;;;;;;;OAOG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAA;IAE/B;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB;;OAEG;IACH,yBAAyB,CAAC,EAAE,MAAM,CAAA;IAElC;;;OAGG;IACH,4BAA4B,CAAC,EAAE,MAAM,CAAA;CACtC;AAED,MAAM,MAAM,SAAS,GAAG,YAAY,GAAG,YAAY,CAAA;AAQnD,MAAM,WAAW,sBAAsB;IACrC,yBAAyB,EAAE,WAAW,CAAA;IACtC,eAAe,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CACrC;AAED,qBAAa,gBAAiB,SAAQ,iBAAiB,CAAC,sBAAsB,CAAE,YAAW,SAAS;;IAClG,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAC/B,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAmB;IACrD,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAkB;IACnD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;IACrC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgC;IACvD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAc;IAC3C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAqB;IAClD,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAQ;IAC5C,OAAO,CAAC,QAAQ,CAAC,yBAAyB,CAAQ;IAClD,OAAO,CAAC,QAAQ,CAAC,4BAA4B,CAAQ;IACrD,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;gBAEf,UAAU,EAAE,oBAAoB,EAAE,IAAI,CAAC,EAAE,cAAc;IA4BpE,SAAS,IAAK,OAAO;IAIf,KAAK,IAAK,OAAO,CAAC,IAAI,CAAC;IAIvB,IAAI,IAAK,OAAO,CAAC,IAAI,CAAC;IAS5B;;;;;OAKG;IACG,QAAQ,CAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IA8G/D,cAAc,CAAE,MAAM,EAAE,MAAM,GAAG,OAAO;IAIxC,cAAc,CAAE,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;CA0EzD"}
|
@@ -1,8 +1,9 @@
|
|
1
|
-
import { TypedEventEmitter } from '@libp2p/interface
|
1
|
+
import { TypedEventEmitter } from '@libp2p/interface';
|
2
2
|
import { PeerMap } from '@libp2p/peer-collections';
|
3
3
|
import { PeerJobQueue } from '@libp2p/utils/peer-job-queue';
|
4
4
|
import { multiaddr } from '@multiformats/multiaddr';
|
5
5
|
import { pbStream } from 'it-protobuf-stream';
|
6
|
+
import { equals as uint8ArrayEquals } from 'uint8arrays/equals';
|
6
7
|
import { DEFAULT_RESERVATION_CONCURRENCY, RELAY_TAG, RELAY_V2_HOP_CODEC } from '../constants.js';
|
7
8
|
import { HopMessage, Status } from '../pb/index.js';
|
8
9
|
import { getExpirationMilliseconds } from '../utils.js';
|
@@ -176,12 +177,27 @@ export class ReservationStore extends TypedEventEmitter {
|
|
176
177
|
}
|
177
178
|
catch (err) {
|
178
179
|
this.log.error('error parsing reserve message response from %p because', connection.remotePeer, err);
|
180
|
+
stream.abort(err);
|
179
181
|
throw err;
|
180
182
|
}
|
181
183
|
finally {
|
182
184
|
await stream.close();
|
183
185
|
}
|
184
186
|
if (response.status === Status.OK && (response.reservation != null)) {
|
187
|
+
// check that the returned relay has the relay address - this can be
|
188
|
+
// omitted when requesting a reservation from a go-libp2p relay we
|
189
|
+
// already have a reservation on
|
190
|
+
let hasRelayAddress = false;
|
191
|
+
const relayAddressBytes = connection.remoteAddr.bytes;
|
192
|
+
for (const buf of response.reservation.addrs) {
|
193
|
+
if (uint8ArrayEquals(relayAddressBytes, buf)) {
|
194
|
+
hasRelayAddress = true;
|
195
|
+
break;
|
196
|
+
}
|
197
|
+
}
|
198
|
+
if (!hasRelayAddress) {
|
199
|
+
response.reservation.addrs.push(relayAddressBytes);
|
200
|
+
}
|
185
201
|
return response.reservation;
|
186
202
|
}
|
187
203
|
const errMsg = `reservation failed with status ${response.status ?? 'undefined'}`;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"reservation-store.js","sourceRoot":"","sources":["../../../src/transport/reservation-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,
|
1
|
+
{"version":3,"file":"reservation-store.js","sourceRoot":"","sources":["../../../src/transport/reservation-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAgK,MAAM,mBAAmB,CAAA;AACnN,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAA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D,CAAC;IACH,CAAC;CACF"}
|
@@ -0,0 +1,61 @@
|
|
1
|
+
import { transportSymbol } from '@libp2p/interface';
|
2
|
+
import { ReservationStore } from './reservation-store.js';
|
3
|
+
import type { CircuitRelayTransportComponents, CircuitRelayTransportInit } from './index.js';
|
4
|
+
import type { AbortOptions, Connection, Stream, PeerId, Transport, CreateListenerOptions, Listener } from '@libp2p/interface';
|
5
|
+
import type { IncomingStreamData } from '@libp2p/interface-internal';
|
6
|
+
import type { Multiaddr } from '@multiformats/multiaddr';
|
7
|
+
interface ConnectOptions {
|
8
|
+
stream: Stream;
|
9
|
+
connection: Connection;
|
10
|
+
destinationPeer: PeerId;
|
11
|
+
destinationAddr: Multiaddr;
|
12
|
+
relayAddr: Multiaddr;
|
13
|
+
ma: Multiaddr;
|
14
|
+
disconnectOnFailure: boolean;
|
15
|
+
}
|
16
|
+
export declare class CircuitRelayTransport implements Transport {
|
17
|
+
private readonly discovery?;
|
18
|
+
private readonly registrar;
|
19
|
+
private readonly peerStore;
|
20
|
+
private readonly connectionManager;
|
21
|
+
private readonly transportManager;
|
22
|
+
private readonly peerId;
|
23
|
+
private readonly upgrader;
|
24
|
+
private readonly addressManager;
|
25
|
+
private readonly connectionGater;
|
26
|
+
readonly reservationStore: ReservationStore;
|
27
|
+
private readonly logger;
|
28
|
+
private readonly maxInboundStopStreams;
|
29
|
+
private readonly maxOutboundStopStreams?;
|
30
|
+
private readonly stopTimeout;
|
31
|
+
private started;
|
32
|
+
private readonly log;
|
33
|
+
constructor(components: CircuitRelayTransportComponents, init: CircuitRelayTransportInit);
|
34
|
+
isStarted(): boolean;
|
35
|
+
start(): Promise<void>;
|
36
|
+
stop(): Promise<void>;
|
37
|
+
readonly [transportSymbol] = true;
|
38
|
+
readonly [Symbol.toStringTag] = "libp2p/circuit-relay-v2";
|
39
|
+
/**
|
40
|
+
* Dial a peer over a relay
|
41
|
+
*/
|
42
|
+
dial(ma: Multiaddr, options?: AbortOptions): Promise<Connection>;
|
43
|
+
connectV2({ stream, connection, destinationPeer, destinationAddr, relayAddr, ma, disconnectOnFailure }: ConnectOptions): Promise<Connection>;
|
44
|
+
/**
|
45
|
+
* Create a listener
|
46
|
+
*/
|
47
|
+
createListener(options: CreateListenerOptions): Listener;
|
48
|
+
/**
|
49
|
+
* Filter check for all Multiaddrs that this transport can dial on
|
50
|
+
*
|
51
|
+
* @param {Multiaddr[]} multiaddrs
|
52
|
+
* @returns {Multiaddr[]}
|
53
|
+
*/
|
54
|
+
filter(multiaddrs: Multiaddr[]): Multiaddr[];
|
55
|
+
/**
|
56
|
+
* An incoming STOP request means a remote peer wants to dial us via a relay
|
57
|
+
*/
|
58
|
+
onStop({ connection, stream }: IncomingStreamData): Promise<void>;
|
59
|
+
}
|
60
|
+
export {};
|
61
|
+
//# sourceMappingURL=transport.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../../src/transport/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAU9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,KAAK,EAAE,+BAA+B,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAC5F,OAAO,KAAK,EAAE,YAAY,EAA2B,UAAU,EAAE,MAAM,EAAmB,MAAM,EAAa,SAAS,EAAE,qBAAqB,EAAE,QAAQ,EAAY,MAAM,mBAAmB,CAAA;AAC5L,OAAO,KAAK,EAAqC,kBAAkB,EAA+B,MAAM,4BAA4B,CAAA;AACpI,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAgBxD,UAAU,cAAc;IACtB,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,UAAU,CAAA;IACtB,eAAe,EAAE,MAAM,CAAA;IACvB,eAAe,EAAE,SAAS,CAAA;IAC1B,SAAS,EAAE,SAAS,CAAA;IACpB,EAAE,EAA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