@libp2p/autonat 0.0.0-05b52d69c

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.
@@ -0,0 +1,29 @@
1
+ import type { AutoNATComponents, AutoNATServiceInit } from './index.js';
2
+ import type { Startable } from '@libp2p/interface/startable';
3
+ import type { IncomingStreamData } from '@libp2p/interface-internal/registrar';
4
+ export declare class AutoNATService implements Startable {
5
+ private readonly components;
6
+ private readonly startupDelay;
7
+ private readonly refreshInterval;
8
+ private readonly protocol;
9
+ private readonly timeout;
10
+ private readonly maxInboundStreams;
11
+ private readonly maxOutboundStreams;
12
+ private verifyAddressTimeout?;
13
+ private started;
14
+ private readonly log;
15
+ constructor(components: AutoNATComponents, init: AutoNATServiceInit);
16
+ isStarted(): boolean;
17
+ start(): Promise<void>;
18
+ stop(): Promise<void>;
19
+ /**
20
+ * Handle an incoming AutoNAT request
21
+ */
22
+ handleIncomingAutonatStream(data: IncomingStreamData): Promise<void>;
23
+ _verifyExternalAddresses(): void;
24
+ /**
25
+ * Our multicodec topology noticed a new peer that supports autonat
26
+ */
27
+ verifyExternalAddresses(): Promise<void>;
28
+ }
29
+ //# sourceMappingURL=autonat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autonat.d.ts","sourceRoot":"","sources":["../../src/autonat.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAKvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAA;AAO9E,qBAAa,cAAe,YAAW,SAAS;IAC9C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmB;IAC9C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAQ;IACrC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAQ;IACxC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAQ;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAQ;IAChC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAQ;IAC1C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAQ;IAC3C,OAAO,CAAC,oBAAoB,CAAC,CAA+B;IAC5D,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;gBAEf,UAAU,EAAE,iBAAiB,EAAE,IAAI,EAAE,kBAAkB;IAapE,SAAS,IAAK,OAAO;IAIf,KAAK,IAAK,OAAO,CAAC,IAAI,CAAC;IAoBvB,IAAI,IAAK,OAAO,CAAC,IAAI,CAAC;IAO5B;;OAEG;IACG,2BAA2B,CAAE,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IA8O3E,wBAAwB,IAAK,IAAI;IAOjC;;OAEG;IACG,uBAAuB,IAAK,OAAO,CAAC,IAAI,CAAC;CA2LhD"}
@@ -0,0 +1,421 @@
1
+ import { CodeError, ERR_TIMEOUT } from '@libp2p/interface/errors';
2
+ import { setMaxListeners } from '@libp2p/interface/events';
3
+ import { peerIdFromBytes } from '@libp2p/peer-id';
4
+ import { createEd25519PeerId } from '@libp2p/peer-id-factory';
5
+ import { multiaddr, protocols } from '@multiformats/multiaddr';
6
+ import first from 'it-first';
7
+ import * as lp from 'it-length-prefixed';
8
+ import map from 'it-map';
9
+ import parallel from 'it-parallel';
10
+ import { pipe } from 'it-pipe';
11
+ import isPrivateIp from 'private-ip';
12
+ import { MAX_INBOUND_STREAMS, MAX_OUTBOUND_STREAMS, PROTOCOL_NAME, PROTOCOL_PREFIX, PROTOCOL_VERSION, REFRESH_INTERVAL, STARTUP_DELAY, TIMEOUT } from './constants.js';
13
+ import { Message } from './pb/index.js';
14
+ // if more than 3 peers manage to dial us on what we believe to be our external
15
+ // IP then we are convinced that it is, in fact, our external IP
16
+ // https://github.com/libp2p/specs/blob/master/autonat/README.md#autonat-protocol
17
+ const REQUIRED_SUCCESSFUL_DIALS = 4;
18
+ export class AutoNATService {
19
+ components;
20
+ startupDelay;
21
+ refreshInterval;
22
+ protocol;
23
+ timeout;
24
+ maxInboundStreams;
25
+ maxOutboundStreams;
26
+ verifyAddressTimeout;
27
+ started;
28
+ log;
29
+ constructor(components, init) {
30
+ this.components = components;
31
+ this.log = components.logger.forComponent('libp2p:autonat');
32
+ this.started = false;
33
+ this.protocol = `/${init.protocolPrefix ?? PROTOCOL_PREFIX}/${PROTOCOL_NAME}/${PROTOCOL_VERSION}`;
34
+ this.timeout = init.timeout ?? TIMEOUT;
35
+ this.maxInboundStreams = init.maxInboundStreams ?? MAX_INBOUND_STREAMS;
36
+ this.maxOutboundStreams = init.maxOutboundStreams ?? MAX_OUTBOUND_STREAMS;
37
+ this.startupDelay = init.startupDelay ?? STARTUP_DELAY;
38
+ this.refreshInterval = init.refreshInterval ?? REFRESH_INTERVAL;
39
+ this._verifyExternalAddresses = this._verifyExternalAddresses.bind(this);
40
+ }
41
+ isStarted() {
42
+ return this.started;
43
+ }
44
+ async start() {
45
+ if (this.started) {
46
+ return;
47
+ }
48
+ await this.components.registrar.handle(this.protocol, (data) => {
49
+ void this.handleIncomingAutonatStream(data)
50
+ .catch(err => {
51
+ this.log.error('error handling incoming autonat stream', err);
52
+ });
53
+ }, {
54
+ maxInboundStreams: this.maxInboundStreams,
55
+ maxOutboundStreams: this.maxOutboundStreams
56
+ });
57
+ this.verifyAddressTimeout = setTimeout(this._verifyExternalAddresses, this.startupDelay);
58
+ this.started = true;
59
+ }
60
+ async stop() {
61
+ await this.components.registrar.unhandle(this.protocol);
62
+ clearTimeout(this.verifyAddressTimeout);
63
+ this.started = false;
64
+ }
65
+ /**
66
+ * Handle an incoming AutoNAT request
67
+ */
68
+ async handleIncomingAutonatStream(data) {
69
+ const signal = AbortSignal.timeout(this.timeout);
70
+ const onAbort = () => {
71
+ data.stream.abort(new CodeError('handleIncomingAutonatStream timeout', ERR_TIMEOUT));
72
+ };
73
+ signal.addEventListener('abort', onAbort, { once: true });
74
+ // this controller may be used while dialing lots of peers so prevent MaxListenersExceededWarning
75
+ // appearing in the console
76
+ setMaxListeners(Infinity, signal);
77
+ const ourHosts = this.components.addressManager.getAddresses()
78
+ .map(ma => ma.toOptions().host);
79
+ try {
80
+ const self = this;
81
+ await pipe(data.stream, (source) => lp.decode(source), async function* (stream) {
82
+ const buf = await first(stream);
83
+ if (buf == null) {
84
+ self.log('no message received');
85
+ yield Message.encode({
86
+ type: Message.MessageType.DIAL_RESPONSE,
87
+ dialResponse: {
88
+ status: Message.ResponseStatus.E_BAD_REQUEST,
89
+ statusText: 'No message was sent'
90
+ }
91
+ });
92
+ return;
93
+ }
94
+ let request;
95
+ try {
96
+ request = Message.decode(buf);
97
+ }
98
+ catch (err) {
99
+ self.log.error('could not decode message', err);
100
+ yield Message.encode({
101
+ type: Message.MessageType.DIAL_RESPONSE,
102
+ dialResponse: {
103
+ status: Message.ResponseStatus.E_BAD_REQUEST,
104
+ statusText: 'Could not decode message'
105
+ }
106
+ });
107
+ return;
108
+ }
109
+ const dialRequest = request.dial;
110
+ if (dialRequest == null) {
111
+ self.log.error('dial was missing from message');
112
+ yield Message.encode({
113
+ type: Message.MessageType.DIAL_RESPONSE,
114
+ dialResponse: {
115
+ status: Message.ResponseStatus.E_BAD_REQUEST,
116
+ statusText: 'No Dial message found in message'
117
+ }
118
+ });
119
+ return;
120
+ }
121
+ let peerId;
122
+ const peer = dialRequest.peer;
123
+ if (peer == null || peer.id == null) {
124
+ self.log.error('PeerId missing from message');
125
+ yield Message.encode({
126
+ type: Message.MessageType.DIAL_RESPONSE,
127
+ dialResponse: {
128
+ status: Message.ResponseStatus.E_BAD_REQUEST,
129
+ statusText: 'missing peer info'
130
+ }
131
+ });
132
+ return;
133
+ }
134
+ try {
135
+ peerId = peerIdFromBytes(peer.id);
136
+ }
137
+ catch (err) {
138
+ self.log.error('invalid PeerId', err);
139
+ yield Message.encode({
140
+ type: Message.MessageType.DIAL_RESPONSE,
141
+ dialResponse: {
142
+ status: Message.ResponseStatus.E_BAD_REQUEST,
143
+ statusText: 'bad peer id'
144
+ }
145
+ });
146
+ return;
147
+ }
148
+ self.log('incoming request from %p', peerId);
149
+ // reject any dial requests that arrive via relays
150
+ if (!data.connection.remotePeer.equals(peerId)) {
151
+ self.log('target peer %p did not equal sending peer %p', peerId, data.connection.remotePeer);
152
+ yield Message.encode({
153
+ type: Message.MessageType.DIAL_RESPONSE,
154
+ dialResponse: {
155
+ status: Message.ResponseStatus.E_BAD_REQUEST,
156
+ statusText: 'peer id mismatch'
157
+ }
158
+ });
159
+ return;
160
+ }
161
+ // get a list of multiaddrs to dial
162
+ const multiaddrs = peer.addrs
163
+ .map(buf => multiaddr(buf))
164
+ .filter(ma => {
165
+ const isFromSameHost = ma.toOptions().host === data.connection.remoteAddr.toOptions().host;
166
+ self.log.trace('request to dial %a was sent from %a is same host %s', ma, data.connection.remoteAddr, isFromSameHost);
167
+ // skip any Multiaddrs where the target node's IP does not match the sending node's IP
168
+ return isFromSameHost;
169
+ })
170
+ .filter(ma => {
171
+ const host = ma.toOptions().host;
172
+ const isPublicIp = !(isPrivateIp(host) ?? false);
173
+ self.log.trace('host %s was public %s', host, isPublicIp);
174
+ // don't try to dial private addresses
175
+ return isPublicIp;
176
+ })
177
+ .filter(ma => {
178
+ const host = ma.toOptions().host;
179
+ const isNotOurHost = !ourHosts.includes(host);
180
+ self.log.trace('host %s was not our host %s', host, isNotOurHost);
181
+ // don't try to dial nodes on the same host as us
182
+ return isNotOurHost;
183
+ })
184
+ .filter(ma => {
185
+ const isSupportedTransport = Boolean(self.components.transportManager.transportForMultiaddr(ma));
186
+ self.log.trace('transport for %a is supported %s', ma, isSupportedTransport);
187
+ // skip any Multiaddrs that have transports we do not support
188
+ return isSupportedTransport;
189
+ })
190
+ .map(ma => {
191
+ if (ma.getPeerId() == null) {
192
+ // make sure we have the PeerId as part of the Multiaddr
193
+ ma = ma.encapsulate(`/p2p/${peerId.toString()}`);
194
+ }
195
+ return ma;
196
+ });
197
+ // make sure we have something to dial
198
+ if (multiaddrs.length === 0) {
199
+ self.log('no valid multiaddrs for %p in message', peerId);
200
+ yield Message.encode({
201
+ type: Message.MessageType.DIAL_RESPONSE,
202
+ dialResponse: {
203
+ status: Message.ResponseStatus.E_DIAL_REFUSED,
204
+ statusText: 'no dialable addresses'
205
+ }
206
+ });
207
+ return;
208
+ }
209
+ self.log('dial multiaddrs %s for peer %p', multiaddrs.map(ma => ma.toString()).join(', '), peerId);
210
+ let errorMessage = '';
211
+ let lastMultiaddr = multiaddrs[0];
212
+ for await (const multiaddr of multiaddrs) {
213
+ let connection;
214
+ lastMultiaddr = multiaddr;
215
+ try {
216
+ connection = await self.components.connectionManager.openConnection(multiaddr, {
217
+ signal
218
+ });
219
+ if (!connection.remoteAddr.equals(multiaddr)) {
220
+ self.log.error('tried to dial %a but dialed %a', multiaddr, connection.remoteAddr);
221
+ throw new Error('Unexpected remote address');
222
+ }
223
+ self.log('Success %p', peerId);
224
+ yield Message.encode({
225
+ type: Message.MessageType.DIAL_RESPONSE,
226
+ dialResponse: {
227
+ status: Message.ResponseStatus.OK,
228
+ addr: connection.remoteAddr.decapsulateCode(protocols('p2p').code).bytes
229
+ }
230
+ });
231
+ return;
232
+ }
233
+ catch (err) {
234
+ self.log('could not dial %p', peerId, err);
235
+ errorMessage = err.message;
236
+ }
237
+ finally {
238
+ if (connection != null) {
239
+ await connection.close();
240
+ }
241
+ }
242
+ }
243
+ yield Message.encode({
244
+ type: Message.MessageType.DIAL_RESPONSE,
245
+ dialResponse: {
246
+ status: Message.ResponseStatus.E_DIAL_ERROR,
247
+ statusText: errorMessage,
248
+ addr: lastMultiaddr.bytes
249
+ }
250
+ });
251
+ }, (source) => lp.encode(source), data.stream);
252
+ }
253
+ catch (err) {
254
+ this.log.error('error handling incoming autonat stream', err);
255
+ }
256
+ finally {
257
+ signal.removeEventListener('abort', onAbort);
258
+ }
259
+ }
260
+ _verifyExternalAddresses() {
261
+ void this.verifyExternalAddresses()
262
+ .catch(err => {
263
+ this.log.error('error verifying external address', err);
264
+ });
265
+ }
266
+ /**
267
+ * Our multicodec topology noticed a new peer that supports autonat
268
+ */
269
+ async verifyExternalAddresses() {
270
+ clearTimeout(this.verifyAddressTimeout);
271
+ // Do not try to push if we are not running
272
+ if (!this.isStarted()) {
273
+ return;
274
+ }
275
+ const addressManager = this.components.addressManager;
276
+ const multiaddrs = addressManager.getObservedAddrs()
277
+ .filter(ma => {
278
+ const options = ma.toOptions();
279
+ return !(isPrivateIp(options.host) ?? false);
280
+ });
281
+ if (multiaddrs.length === 0) {
282
+ this.log('no public addresses found, not requesting verification');
283
+ this.verifyAddressTimeout = setTimeout(this._verifyExternalAddresses, this.refreshInterval);
284
+ return;
285
+ }
286
+ const signal = AbortSignal.timeout(this.timeout);
287
+ // this controller may be used while dialing lots of peers so prevent MaxListenersExceededWarning
288
+ // appearing in the console
289
+ setMaxListeners(Infinity, signal);
290
+ const self = this;
291
+ try {
292
+ this.log('verify multiaddrs %s', multiaddrs.map(ma => ma.toString()).join(', '));
293
+ const request = Message.encode({
294
+ type: Message.MessageType.DIAL,
295
+ dial: {
296
+ peer: {
297
+ id: this.components.peerId.toBytes(),
298
+ addrs: multiaddrs.map(map => map.bytes)
299
+ }
300
+ }
301
+ });
302
+ // find some random peers
303
+ const randomPeer = await createEd25519PeerId();
304
+ const randomCid = randomPeer.toBytes();
305
+ const results = {};
306
+ const networkSegments = [];
307
+ const verifyAddress = async (peer) => {
308
+ let onAbort = () => { };
309
+ try {
310
+ this.log('asking %p to verify multiaddr', peer.id);
311
+ const connection = await self.components.connectionManager.openConnection(peer.id, {
312
+ signal
313
+ });
314
+ const stream = await connection.newStream(this.protocol, {
315
+ signal
316
+ });
317
+ onAbort = () => { stream.abort(new CodeError('verifyAddress timeout', ERR_TIMEOUT)); };
318
+ signal.addEventListener('abort', onAbort, { once: true });
319
+ const buf = await pipe([request], (source) => lp.encode(source), stream, (source) => lp.decode(source), async (stream) => first(stream));
320
+ if (buf == null) {
321
+ this.log('no response received from %p', connection.remotePeer);
322
+ return undefined;
323
+ }
324
+ const response = Message.decode(buf);
325
+ if (response.type !== Message.MessageType.DIAL_RESPONSE || response.dialResponse == null) {
326
+ this.log('invalid autonat response from %p', connection.remotePeer);
327
+ return undefined;
328
+ }
329
+ if (response.dialResponse.status === Message.ResponseStatus.OK) {
330
+ // make sure we use different network segments
331
+ const options = connection.remoteAddr.toOptions();
332
+ let segment;
333
+ if (options.family === 4) {
334
+ const octets = options.host.split('.');
335
+ segment = octets[0];
336
+ }
337
+ else if (options.family === 6) {
338
+ const octets = options.host.split(':');
339
+ segment = octets[0];
340
+ }
341
+ else {
342
+ this.log('remote address "%s" was not IP4 or IP6?', options.host);
343
+ return undefined;
344
+ }
345
+ if (networkSegments.includes(segment)) {
346
+ this.log('already have response from network segment %d - %s', segment, options.host);
347
+ return undefined;
348
+ }
349
+ networkSegments.push(segment);
350
+ }
351
+ return response.dialResponse;
352
+ }
353
+ catch (err) {
354
+ this.log.error('error asking remote to verify multiaddr', err);
355
+ }
356
+ finally {
357
+ signal.removeEventListener('abort', onAbort);
358
+ }
359
+ };
360
+ for await (const dialResponse of parallel(map(this.components.peerRouting.getClosestPeers(randomCid, {
361
+ signal
362
+ }), (peer) => async () => verifyAddress(peer)), {
363
+ concurrency: REQUIRED_SUCCESSFUL_DIALS
364
+ })) {
365
+ try {
366
+ if (dialResponse == null) {
367
+ continue;
368
+ }
369
+ // they either told us which address worked/didn't work, or we only sent them one address
370
+ const addr = dialResponse.addr == null ? multiaddrs[0] : multiaddr(dialResponse.addr);
371
+ this.log('autonat response for %a is %s', addr, dialResponse.status);
372
+ if (dialResponse.status === Message.ResponseStatus.E_BAD_REQUEST) {
373
+ // the remote could not parse our request
374
+ continue;
375
+ }
376
+ if (dialResponse.status === Message.ResponseStatus.E_DIAL_REFUSED) {
377
+ // the remote could not honour our request
378
+ continue;
379
+ }
380
+ if (dialResponse.addr == null && multiaddrs.length > 1) {
381
+ // we sent the remote multiple addrs but they didn't tell us which ones worked/didn't work
382
+ continue;
383
+ }
384
+ if (!multiaddrs.some(ma => ma.equals(addr))) {
385
+ this.log('peer reported %a as %s but it was not in our observed address list', addr, dialResponse.status);
386
+ continue;
387
+ }
388
+ const addrStr = addr.toString();
389
+ if (results[addrStr] == null) {
390
+ results[addrStr] = { success: 0, failure: 0 };
391
+ }
392
+ if (dialResponse.status === Message.ResponseStatus.OK) {
393
+ results[addrStr].success++;
394
+ }
395
+ else if (dialResponse.status === Message.ResponseStatus.E_DIAL_ERROR) {
396
+ results[addrStr].failure++;
397
+ }
398
+ if (results[addrStr].success === REQUIRED_SUCCESSFUL_DIALS) {
399
+ // we are now convinced
400
+ this.log('%a is externally dialable', addr);
401
+ addressManager.confirmObservedAddr(addr);
402
+ return;
403
+ }
404
+ if (results[addrStr].failure === REQUIRED_SUCCESSFUL_DIALS) {
405
+ // we are now unconvinced
406
+ this.log('%a is not externally dialable', addr);
407
+ addressManager.removeObservedAddr(addr);
408
+ return;
409
+ }
410
+ }
411
+ catch (err) {
412
+ this.log.error('could not verify external address', err);
413
+ }
414
+ }
415
+ }
416
+ finally {
417
+ this.verifyAddressTimeout = setTimeout(this._verifyExternalAddresses, this.refreshInterval);
418
+ }
419
+ }
420
+ }
421
+ //# sourceMappingURL=autonat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autonat.js","sourceRoot":"","sources":["../../src/autonat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAA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wBAC3C,cAAc,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAA;wBACxC,OAAM;qBACP;oBAED,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,KAAK,yBAAyB,EAAE;wBAC1D,yBAAyB;wBACzB,IAAI,CAAC,GAAG,CAAC,+BAA+B,EAAE,IAAI,CAAC,CAAA;wBAC/C,cAAc,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAA;wBACvC,OAAM;qBACP;iBACF;gBAAC,OAAO,GAAG,EAAE;oBACZ,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,mCAAmC,EAAE,GAAG,CAAC,CAAA;iBACzD;aACF;SACF;gBAAS;YACR,IAAI,CAAC,oBAAoB,GAAG,UAAU,CAAC,IAAI,CAAC,wBAAwB,EAAE,IAAI,CAAC,eAAe,CAAC,CAAA;SAC5F;IACH,CAAC;CACF"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The prefix to use in the protocol
3
+ */
4
+ export declare const PROTOCOL_PREFIX = "libp2p";
5
+ /**
6
+ * The name to use in the protocol
7
+ */
8
+ export declare const PROTOCOL_NAME = "autonat";
9
+ /**
10
+ * The version to use in the protocol
11
+ */
12
+ export declare const PROTOCOL_VERSION = "1.0.0";
13
+ export declare const TIMEOUT = 30000;
14
+ export declare const STARTUP_DELAY = 5000;
15
+ export declare const REFRESH_INTERVAL = 60000;
16
+ export declare const MAX_INBOUND_STREAMS = 1;
17
+ export declare const MAX_OUTBOUND_STREAMS = 1;
18
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,eAAe,WAAW,CAAA;AAEvC;;GAEG;AACH,eAAO,MAAM,aAAa,YAAY,CAAA;AAEtC;;GAEG;AACH,eAAO,MAAM,gBAAgB,UAAU,CAAA;AACvC,eAAO,MAAM,OAAO,QAAQ,CAAA;AAC5B,eAAO,MAAM,aAAa,OAAO,CAAA;AACjC,eAAO,MAAM,gBAAgB,QAAQ,CAAA;AACrC,eAAO,MAAM,mBAAmB,IAAI,CAAA;AACpC,eAAO,MAAM,oBAAoB,IAAI,CAAA"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The prefix to use in the protocol
3
+ */
4
+ export const PROTOCOL_PREFIX = 'libp2p';
5
+ /**
6
+ * The name to use in the protocol
7
+ */
8
+ export const PROTOCOL_NAME = 'autonat';
9
+ /**
10
+ * The version to use in the protocol
11
+ */
12
+ export const PROTOCOL_VERSION = '1.0.0';
13
+ export const TIMEOUT = 30000;
14
+ export const STARTUP_DELAY = 5000;
15
+ export const REFRESH_INTERVAL = 60000;
16
+ export const MAX_INBOUND_STREAMS = 1;
17
+ export const MAX_OUTBOUND_STREAMS = 1;
18
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAA;AAEvC;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAA;AAEtC;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAA;AACvC,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,CAAA;AAC5B,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAA;AACjC,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAA;AACrC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAA;AACpC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAA"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * @packageDocumentation
3
+ *
4
+ * Use the `autoNATService` function to add support for the [AutoNAT protocol](https://docs.libp2p.io/concepts/nat/autonat/)
5
+ * to libp2p.
6
+ *
7
+ * @example
8
+ *
9
+ * ```typescript
10
+ * import { createLibp2p } from 'libp2p'
11
+ * import { autoNAT } from '@libp2p/autonat'
12
+ *
13
+ * const node = await createLibp2p({
14
+ * // ...other options
15
+ * services: {
16
+ * autoNAT: autoNAT()
17
+ * }
18
+ * })
19
+ * ```
20
+ */
21
+ import type { ComponentLogger } from '@libp2p/interface';
22
+ import type { PeerId } from '@libp2p/interface/peer-id';
23
+ import type { PeerRouting } from '@libp2p/interface/peer-routing';
24
+ import type { AddressManager } from '@libp2p/interface-internal/address-manager';
25
+ import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager';
26
+ import type { Registrar } from '@libp2p/interface-internal/registrar';
27
+ import type { TransportManager } from '@libp2p/interface-internal/transport-manager';
28
+ export interface AutoNATServiceInit {
29
+ /**
30
+ * Allows overriding the protocol prefix used
31
+ */
32
+ protocolPrefix?: string;
33
+ /**
34
+ * How long we should wait for a remote peer to verify our external address
35
+ */
36
+ timeout?: number;
37
+ /**
38
+ * How long to wait after startup before trying to verify our external address
39
+ */
40
+ startupDelay?: number;
41
+ /**
42
+ * Verify our external addresses this often
43
+ */
44
+ refreshInterval?: number;
45
+ /**
46
+ * How many parallel inbound autoNAT streams we allow per-connection
47
+ */
48
+ maxInboundStreams?: number;
49
+ /**
50
+ * How many parallel outbound autoNAT streams we allow per-connection
51
+ */
52
+ maxOutboundStreams?: number;
53
+ }
54
+ export interface AutoNATComponents {
55
+ registrar: Registrar;
56
+ addressManager: AddressManager;
57
+ transportManager: TransportManager;
58
+ peerId: PeerId;
59
+ connectionManager: ConnectionManager;
60
+ peerRouting: PeerRouting;
61
+ logger: ComponentLogger;
62
+ }
63
+ export declare function autoNAT(init?: AutoNATServiceInit): (components: AutoNATComponents) => unknown;
64
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAA;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAA;AAChF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAA;AACtF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAA;AACrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8CAA8C,CAAA;AAEpF,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IAExB;;OAEG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAE1B;;OAEG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAC5B;AAED,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,SAAS,CAAA;IACpB,cAAc,EAAE,cAAc,CAAA;IAC9B,gBAAgB,EAAE,gBAAgB,CAAA;IAClC,MAAM,EAAE,MAAM,CAAA;IACd,iBAAiB,EAAE,iBAAiB,CAAA;IACpC,WAAW,EAAE,WAAW,CAAA;IACxB,MAAM,EAAE,eAAe,CAAA;CACxB;AAED,wBAAgB,OAAO,CAAE,IAAI,GAAE,kBAAuB,GAAG,CAAC,UAAU,EAAE,iBAAiB,KAAK,OAAO,CAIlG"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @packageDocumentation
3
+ *
4
+ * Use the `autoNATService` function to add support for the [AutoNAT protocol](https://docs.libp2p.io/concepts/nat/autonat/)
5
+ * to libp2p.
6
+ *
7
+ * @example
8
+ *
9
+ * ```typescript
10
+ * import { createLibp2p } from 'libp2p'
11
+ * import { autoNAT } from '@libp2p/autonat'
12
+ *
13
+ * const node = await createLibp2p({
14
+ * // ...other options
15
+ * services: {
16
+ * autoNAT: autoNAT()
17
+ * }
18
+ * })
19
+ * ```
20
+ */
21
+ import { AutoNATService } from './autonat.js';
22
+ export function autoNAT(init = {}) {
23
+ return (components) => {
24
+ return new AutoNATService(components, init);
25
+ };
26
+ }
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAmD7C,MAAM,UAAU,OAAO,CAAE,OAA2B,EAAE;IACpD,OAAO,CAAC,UAAU,EAAE,EAAE;QACpB,OAAO,IAAI,cAAc,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;IAC7C,CAAC,CAAA;AACH,CAAC"}