@libp2p/autonat-v2 0.0.0-2d6079bc1

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,22 @@
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 = '2';
13
+ export const TIMEOUT = 30_000;
14
+ export const MAX_INBOUND_STREAMS = 2;
15
+ export const MAX_OUTBOUND_STREAMS = 20;
16
+ export const DEFAULT_CONNECTION_THRESHOLD = 80;
17
+ export const MAX_MESSAGE_SIZE = 8192;
18
+ export const DIAL_REQUEST = 'dial-request';
19
+ export const DIAL_BACK = 'dial-back';
20
+ export const MAX_DIAL_DATA_BYTES = 200n * 1024n;
21
+ export const DIAL_DATA_CHUNK_SIZE = 4096;
22
+ //# 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,GAAG,CAAA;AACnC,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAA;AAC7B,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAA;AACpC,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAA;AACtC,MAAM,CAAC,MAAM,4BAA4B,GAAG,EAAE,CAAA;AAC9C,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAA;AAEpC,MAAM,CAAC,MAAM,YAAY,GAAG,cAAc,CAAA;AAC1C,MAAM,CAAC,MAAM,SAAS,GAAG,WAAW,CAAA;AACpC,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,GAAG,KAAK,CAAA;AAC/C,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,CAAA"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * @packageDocumentation
3
+ *
4
+ * The AutoNATv2 service implements the [AutoNAT v2 protocol](https://github.com/libp2p/specs/blob/master/autonat/autonat-v2.md)
5
+ * to confirm whether addresses the node is listening on are dialable by remote
6
+ * peers.
7
+ *
8
+ * It does not implement NAT hole punching.
9
+ *
10
+ * @example
11
+ *
12
+ * ```typescript
13
+ * import { createLibp2p } from 'libp2p'
14
+ * import { autoNATv2 } from '@libp2p/autonat-v2'
15
+ *
16
+ * const node = await createLibp2p({
17
+ * // ...other options
18
+ * services: {
19
+ * autoNAT: autoNATv2()
20
+ * }
21
+ * })
22
+ * ```
23
+ */
24
+ import type { ComponentLogger, Metrics, PeerStore } from '@libp2p/interface';
25
+ import type { AddressManager, ConnectionManager, RandomWalk, Registrar } from '@libp2p/interface-internal';
26
+ export interface AutoNATv2ServiceInit {
27
+ /**
28
+ * Allows overriding the protocol prefix used
29
+ */
30
+ protocolPrefix?: string;
31
+ /**
32
+ * How long we should wait for a remote peer to verify our external address
33
+ */
34
+ timeout?: number;
35
+ /**
36
+ * How long to wait after startup before trying to verify our external address
37
+ */
38
+ startupDelay?: number;
39
+ /**
40
+ * Verify our external addresses this often
41
+ */
42
+ refreshInterval?: number;
43
+ /**
44
+ * How many parallel inbound autoNAT streams we allow per-connection
45
+ */
46
+ maxInboundStreams?: number;
47
+ /**
48
+ * How many parallel outbound autoNAT streams we allow per-connection
49
+ */
50
+ maxOutboundStreams?: number;
51
+ /**
52
+ * If the number of currently open connections is higher than this value as
53
+ * a percentage of the maximum number of allowed connections, automatically
54
+ * reverify previously verified addresses since auto nat peers may find it
55
+ * hard to dial and will report that the address is not dialable leading this
56
+ * node to delist it.
57
+ *
58
+ * @default 80
59
+ */
60
+ connectionThreshold?: number;
61
+ /**
62
+ * How large incoming autonat messages are allowed to be in bytes. If messages
63
+ * larger than this are received the stream will be reset.
64
+ *
65
+ * @default 8192
66
+ */
67
+ maxMessageSize?: number;
68
+ /**
69
+ * When asked to send data as part of the amplification attack protection,
70
+ * refuse to send more than this amount of data.
71
+ *
72
+ * @default 200_000n
73
+ */
74
+ maxDialDataBytes?: bigint;
75
+ /**
76
+ * When asked to send data as part of the amplification attack protection,
77
+ * send data in with this size chunks
78
+ *
79
+ * @default 4096
80
+ */
81
+ dialDataChunkSize?: number;
82
+ }
83
+ export interface AutoNATv2Components {
84
+ registrar: Registrar;
85
+ addressManager: AddressManager;
86
+ connectionManager: ConnectionManager;
87
+ logger: ComponentLogger;
88
+ randomWalk: RandomWalk;
89
+ peerStore: PeerStore;
90
+ metrics?: Metrics;
91
+ }
92
+ export declare function autoNATv2(init?: AutoNATv2ServiceInit): (components: AutoNATv2Components) => unknown;
93
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC5E,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAE1G,MAAM,WAAW,oBAAoB;IACnC;;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;IAE3B;;;;;;;;OAQG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAE5B;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAA;IAEzB;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAC3B;AAED,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,SAAS,CAAA;IACpB,cAAc,EAAE,cAAc,CAAA;IAC9B,iBAAiB,EAAE,iBAAiB,CAAA;IACpC,MAAM,EAAE,eAAe,CAAA;IACvB,UAAU,EAAE,UAAU,CAAA;IACtB,SAAS,EAAE,SAAS,CAAA;IACpB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,SAAS,CAAE,IAAI,GAAE,oBAAyB,GAAG,CAAC,UAAU,EAAE,mBAAmB,KAAK,OAAO,CAIxG"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @packageDocumentation
3
+ *
4
+ * The AutoNATv2 service implements the [AutoNAT v2 protocol](https://github.com/libp2p/specs/blob/master/autonat/autonat-v2.md)
5
+ * to confirm whether addresses the node is listening on are dialable by remote
6
+ * peers.
7
+ *
8
+ * It does not implement NAT hole punching.
9
+ *
10
+ * @example
11
+ *
12
+ * ```typescript
13
+ * import { createLibp2p } from 'libp2p'
14
+ * import { autoNATv2 } from '@libp2p/autonat-v2'
15
+ *
16
+ * const node = await createLibp2p({
17
+ * // ...other options
18
+ * services: {
19
+ * autoNAT: autoNATv2()
20
+ * }
21
+ * })
22
+ * ```
23
+ */
24
+ import { AutoNATv2Service } from "./autonat.js";
25
+ export function autoNATv2(init = {}) {
26
+ return (components) => {
27
+ return new AutoNATv2Service(components, init);
28
+ };
29
+ }
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAiF/C,MAAM,UAAU,SAAS,CAAE,OAA6B,EAAE;IACxD,OAAO,CAAC,UAAU,EAAE,EAAE;QACpB,OAAO,IAAI,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;IAC/C,CAAC,CAAA;AACH,CAAC"}
@@ -0,0 +1,90 @@
1
+ import type { Codec, DecodeOptions } from 'protons-runtime';
2
+ import type { Uint8ArrayList } from 'uint8arraylist';
3
+ export interface Message {
4
+ dialRequest?: DialRequest;
5
+ dialResponse?: DialResponse;
6
+ dialDataRequest?: DialDataRequest;
7
+ dialDataResponse?: DialDataResponse;
8
+ }
9
+ export declare namespace Message {
10
+ const codec: () => Codec<Message>;
11
+ const encode: (obj: Partial<Message>) => Uint8Array;
12
+ const decode: (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<Message>) => Message;
13
+ }
14
+ export interface DialRequest {
15
+ addrs: Uint8Array[];
16
+ nonce: bigint;
17
+ }
18
+ export declare namespace DialRequest {
19
+ const codec: () => Codec<DialRequest>;
20
+ const encode: (obj: Partial<DialRequest>) => Uint8Array;
21
+ const decode: (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<DialRequest>) => DialRequest;
22
+ }
23
+ export interface DialDataRequest {
24
+ addrIdx: number;
25
+ numBytes: bigint;
26
+ }
27
+ export declare namespace DialDataRequest {
28
+ const codec: () => Codec<DialDataRequest>;
29
+ const encode: (obj: Partial<DialDataRequest>) => Uint8Array;
30
+ const decode: (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<DialDataRequest>) => DialDataRequest;
31
+ }
32
+ export declare enum DialStatus {
33
+ UNUSED = "UNUSED",
34
+ E_DIAL_ERROR = "E_DIAL_ERROR",
35
+ E_DIAL_BACK_ERROR = "E_DIAL_BACK_ERROR",
36
+ OK = "OK"
37
+ }
38
+ export declare namespace DialStatus {
39
+ const codec: () => Codec<DialStatus>;
40
+ }
41
+ export interface DialResponse {
42
+ status: DialResponse.ResponseStatus;
43
+ addrIdx: number;
44
+ dialStatus: DialStatus;
45
+ }
46
+ export declare namespace DialResponse {
47
+ enum ResponseStatus {
48
+ E_INTERNAL_ERROR = "E_INTERNAL_ERROR",
49
+ E_REQUEST_REJECTED = "E_REQUEST_REJECTED",
50
+ E_DIAL_REFUSED = "E_DIAL_REFUSED",
51
+ OK = "OK"
52
+ }
53
+ namespace ResponseStatus {
54
+ const codec: () => Codec<ResponseStatus>;
55
+ }
56
+ const codec: () => Codec<DialResponse>;
57
+ const encode: (obj: Partial<DialResponse>) => Uint8Array;
58
+ const decode: (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<DialResponse>) => DialResponse;
59
+ }
60
+ export interface DialDataResponse {
61
+ data: Uint8Array;
62
+ }
63
+ export declare namespace DialDataResponse {
64
+ const codec: () => Codec<DialDataResponse>;
65
+ const encode: (obj: Partial<DialDataResponse>) => Uint8Array;
66
+ const decode: (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<DialDataResponse>) => DialDataResponse;
67
+ }
68
+ export interface DialBack {
69
+ nonce: bigint;
70
+ }
71
+ export declare namespace DialBack {
72
+ const codec: () => Codec<DialBack>;
73
+ const encode: (obj: Partial<DialBack>) => Uint8Array;
74
+ const decode: (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<DialBack>) => DialBack;
75
+ }
76
+ export interface DialBackResponse {
77
+ status: DialBackResponse.DialBackStatus;
78
+ }
79
+ export declare namespace DialBackResponse {
80
+ enum DialBackStatus {
81
+ OK = "OK"
82
+ }
83
+ namespace DialBackStatus {
84
+ const codec: () => Codec<DialBackStatus>;
85
+ }
86
+ const codec: () => Codec<DialBackResponse>;
87
+ const encode: (obj: Partial<DialBackResponse>) => Uint8Array;
88
+ const decode: (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<DialBackResponse>) => DialBackResponse;
89
+ }
90
+ //# sourceM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