@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.
- package/README.md +74 -0
- package/dist/index.min.js +19 -0
- package/dist/index.min.js.map +7 -0
- package/dist/src/autonat.d.ts +14 -0
- package/dist/src/autonat.d.ts.map +1 -0
- package/dist/src/autonat.js +38 -0
- package/dist/src/autonat.js.map +1 -0
- package/dist/src/client.d.ts +58 -0
- package/dist/src/client.d.ts.map +1 -0
- package/dist/src/client.js +476 -0
- package/dist/src/client.js.map +1 -0
- package/dist/src/constants.d.ts +22 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +22 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/index.d.ts +93 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +30 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/pb/index.d.ts +90 -0
- package/dist/src/pb/index.d.ts.map +1 -0
- package/dist/src/pb/index.js +488 -0
- package/dist/src/pb/index.js.map +1 -0
- package/dist/src/server.d.ts +27 -0
- package/dist/src/server.d.ts.map +1 -0
- package/dist/src/server.js +191 -0
- package/dist/src/server.js.map +1 -0
- package/dist/src/utils.d.ts +2 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +4 -0
- package/dist/src/utils.js.map +1 -0
- package/package.json +75 -0
- package/src/autonat.ts +47 -0
- package/src/client.ts +628 -0
- package/src/constants.ts +24 -0
- package/src/index.ts +110 -0
- package/src/pb/index.proto +56 -0
- package/src/pb/index.ts +614 -0
- package/src/server.ts +237 -0
- package/src/utils.ts +3 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
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
|
+
|
|
25
|
+
import { AutoNATv2Service } from './autonat.ts'
|
|
26
|
+
import type { ComponentLogger, Metrics, PeerStore } from '@libp2p/interface'
|
|
27
|
+
import type { AddressManager, ConnectionManager, RandomWalk, Registrar } from '@libp2p/interface-internal'
|
|
28
|
+
|
|
29
|
+
export interface AutoNATv2ServiceInit {
|
|
30
|
+
/**
|
|
31
|
+
* Allows overriding the protocol prefix used
|
|
32
|
+
*/
|
|
33
|
+
protocolPrefix?: string
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* How long we should wait for a remote peer to verify our external address
|
|
37
|
+
*/
|
|
38
|
+
timeout?: number
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* How long to wait after startup before trying to verify our external address
|
|
42
|
+
*/
|
|
43
|
+
startupDelay?: number
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Verify our external addresses this often
|
|
47
|
+
*/
|
|
48
|
+
refreshInterval?: number
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* How many parallel inbound autoNAT streams we allow per-connection
|
|
52
|
+
*/
|
|
53
|
+
maxInboundStreams?: number
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* How many parallel outbound autoNAT streams we allow per-connection
|
|
57
|
+
*/
|
|
58
|
+
maxOutboundStreams?: number
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* If the number of currently open connections is higher than this value as
|
|
62
|
+
* a percentage of the maximum number of allowed connections, automatically
|
|
63
|
+
* reverify previously verified addresses since auto nat peers may find it
|
|
64
|
+
* hard to dial and will report that the address is not dialable leading this
|
|
65
|
+
* node to delist it.
|
|
66
|
+
*
|
|
67
|
+
* @default 80
|
|
68
|
+
*/
|
|
69
|
+
connectionThreshold?: number
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* How large incoming autonat messages are allowed to be in bytes. If messages
|
|
73
|
+
* larger than this are received the stream will be reset.
|
|
74
|
+
*
|
|
75
|
+
* @default 8192
|
|
76
|
+
*/
|
|
77
|
+
maxMessageSize?: number
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* When asked to send data as part of the amplification attack protection,
|
|
81
|
+
* refuse to send more than this amount of data.
|
|
82
|
+
*
|
|
83
|
+
* @default 200_000n
|
|
84
|
+
*/
|
|
85
|
+
maxDialDataBytes?: bigint
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* When asked to send data as part of the amplification attack protection,
|
|
89
|
+
* send data in with this size chunks
|
|
90
|
+
*
|
|
91
|
+
* @default 4096
|
|
92
|
+
*/
|
|
93
|
+
dialDataChunkSize?: number
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface AutoNATv2Components {
|
|
97
|
+
registrar: Registrar
|
|
98
|
+
addressManager: AddressManager
|
|
99
|
+
connectionManager: ConnectionManager
|
|
100
|
+
logger: ComponentLogger
|
|
101
|
+
randomWalk: RandomWalk
|
|
102
|
+
peerStore: PeerStore
|
|
103
|
+
metrics?: Metrics
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function autoNATv2 (init: AutoNATv2ServiceInit = {}): (components: AutoNATv2Components) => unknown {
|
|
107
|
+
return (components) => {
|
|
108
|
+
return new AutoNATv2Service(components, init)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
|
|
3
|
+
message Message {
|
|
4
|
+
oneof msg {
|
|
5
|
+
DialRequest dialRequest = 1;
|
|
6
|
+
DialResponse dialResponse = 2;
|
|
7
|
+
DialDataRequest dialDataRequest = 3;
|
|
8
|
+
DialDataResponse dialDataResponse = 4;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
message DialRequest {
|
|
13
|
+
repeated bytes addrs = 1;
|
|
14
|
+
fixed64 nonce = 2;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
message DialDataRequest {
|
|
18
|
+
uint32 addrIdx = 1;
|
|
19
|
+
uint64 numBytes = 2;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
enum DialStatus {
|
|
23
|
+
UNUSED = 0;
|
|
24
|
+
E_DIAL_ERROR = 100;
|
|
25
|
+
E_DIAL_BACK_ERROR = 101;
|
|
26
|
+
OK = 200;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
message DialResponse {
|
|
30
|
+
enum ResponseStatus {
|
|
31
|
+
E_INTERNAL_ERROR = 0;
|
|
32
|
+
E_REQUEST_REJECTED = 100;
|
|
33
|
+
E_DIAL_REFUSED = 101;
|
|
34
|
+
OK = 200;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
ResponseStatus status = 1;
|
|
38
|
+
uint32 addrIdx = 2;
|
|
39
|
+
DialStatus dialStatus = 3;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
message DialDataResponse {
|
|
43
|
+
bytes data = 1;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
message DialBack {
|
|
47
|
+
fixed64 nonce = 1;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
message DialBackResponse {
|
|
51
|
+
enum DialBackStatus {
|
|
52
|
+
OK = 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
DialBackStatus status = 1;
|
|
56
|
+
}
|