libp2p 0.43.4 → 0.44.0-0d46c78f
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/dist/index.min.js +29 -29
- package/dist/src/address-manager/index.d.ts +4 -4
- package/dist/src/address-manager/index.d.ts.map +1 -1
- package/dist/src/address-manager/index.js +9 -6
- package/dist/src/address-manager/index.js.map +1 -1
- package/dist/src/autonat/index.d.ts +1 -2
- package/dist/src/autonat/index.d.ts.map +1 -1
- package/dist/src/autonat/index.js +19 -19
- package/dist/src/autonat/index.js.map +1 -1
- package/dist/src/circuit-relay/server/advert-service.d.ts.map +1 -1
- package/dist/src/circuit-relay/server/advert-service.js +2 -2
- package/dist/src/circuit-relay/server/advert-service.js.map +1 -1
- package/dist/src/circuit-relay/server/index.d.ts.map +1 -1
- package/dist/src/circuit-relay/server/index.js +7 -3
- package/dist/src/circuit-relay/server/index.js.map +1 -1
- package/dist/src/circuit-relay/transport/discovery.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/discovery.js +3 -1
- package/dist/src/circuit-relay/transport/discovery.js.map +1 -1
- package/dist/src/circuit-relay/transport/index.d.ts +3 -0
- package/dist/src/circuit-relay/transport/index.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/index.js +6 -2
- package/dist/src/circuit-relay/transport/index.js.map +1 -1
- package/dist/src/circuit-relay/transport/listener.d.ts +3 -0
- package/dist/src/circuit-relay/transport/listener.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/listener.js +5 -4
- package/dist/src/circuit-relay/transport/listener.js.map +1 -1
- package/dist/src/circuit-relay/transport/reservation-store.d.ts +4 -1
- package/dist/src/circuit-relay/transport/reservation-store.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/reservation-store.js +11 -6
- package/dist/src/circuit-relay/transport/reservation-store.js.map +1 -1
- package/dist/src/circuit-relay/utils.d.ts.map +1 -1
- package/dist/src/circuit-relay/utils.js +3 -1
- package/dist/src/circuit-relay/utils.js.map +1 -1
- package/dist/src/components.d.ts +7 -69
- package/dist/src/components.d.ts.map +1 -1
- package/dist/src/components.js +60 -174
- package/dist/src/components.js.map +1 -1
- package/dist/src/config/connection-gater.browser.d.ts +8 -0
- package/dist/src/config/connection-gater.browser.d.ts.map +1 -0
- package/dist/src/config/connection-gater.browser.js +27 -0
- package/dist/src/config/connection-gater.browser.js.map +1 -0
- package/dist/src/config/connection-gater.d.ts +6 -0
- package/dist/src/config/connection-gater.d.ts.map +1 -0
- package/dist/src/config/connection-gater.js +18 -0
- package/dist/src/config/connection-gater.js.map +1 -0
- package/dist/src/config.d.ts +2 -1
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +0 -71
- package/dist/src/config.js.map +1 -1
- package/dist/src/connection-manager/auto-dial.d.ts +39 -0
- package/dist/src/connection-manager/auto-dial.d.ts.map +1 -0
- package/dist/src/connection-manager/auto-dial.js +136 -0
- package/dist/src/connection-manager/auto-dial.js.map +1 -0
- package/dist/src/connection-manager/connection-pruner.d.ts +32 -0
- package/dist/src/connection-manager/connection-pruner.d.ts.map +1 -0
- package/dist/src/connection-manager/connection-pruner.js +111 -0
- package/dist/src/connection-manager/connection-pruner.js.map +1 -0
- package/dist/src/connection-manager/constants.d.ts +49 -0
- package/dist/src/connection-manager/constants.d.ts.map +1 -0
- package/dist/src/connection-manager/constants.js +49 -0
- package/dist/src/connection-manager/constants.js.map +1 -0
- package/dist/src/connection-manager/dial-queue.d.ts +78 -0
- package/dist/src/connection-manager/dial-queue.d.ts.map +1 -0
- package/dist/src/connection-manager/dial-queue.js +372 -0
- package/dist/src/connection-manager/dial-queue.js.map +1 -0
- package/dist/src/connection-manager/index.d.ts +70 -73
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +118 -247
- package/dist/src/connection-manager/index.js.map +1 -1
- package/dist/src/connection-manager/utils.d.ts +9 -0
- package/dist/src/connection-manager/utils.d.ts.map +1 -0
- package/dist/src/connection-manager/utils.js +66 -0
- package/dist/src/connection-manager/utils.js.map +1 -0
- package/dist/src/content-routing/index.d.ts +0 -10
- package/dist/src/content-routing/index.d.ts.map +1 -1
- package/dist/src/content-routing/index.js +7 -42
- package/dist/src/content-routing/index.js.map +1 -1
- package/dist/src/content-routing/utils.d.ts.map +1 -1
- package/dist/src/content-routing/utils.js +3 -1
- package/dist/src/content-routing/utils.js.map +1 -1
- package/dist/src/fetch/index.d.ts +13 -35
- package/dist/src/fetch/index.d.ts.map +1 -1
- package/dist/src/fetch/index.js +10 -12
- package/dist/src/fetch/index.js.map +1 -1
- package/dist/src/identify/index.d.ts +16 -48
- package/dist/src/identify/index.d.ts.map +1 -1
- package/dist/src/identify/index.js +203 -201
- package/dist/src/identify/index.js.map +1 -1
- package/dist/src/index.d.ts +11 -67
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/insecure/index.d.ts.map +1 -1
- package/dist/src/insecure/index.js +3 -1
- package/dist/src/insecure/index.js.map +1 -1
- package/dist/src/libp2p.d.ts +12 -35
- package/dist/src/libp2p.d.ts.map +1 -1
- package/dist/src/libp2p.js +141 -206
- package/dist/src/libp2p.js.map +1 -1
- package/dist/src/peer-routing.d.ts +1 -38
- package/dist/src/peer-routing.d.ts.map +1 -1
- package/dist/src/peer-routing.js +0 -59
- package/dist/src/peer-routing.js.map +1 -1
- package/dist/src/ping/constants.d.ts +4 -0
- package/dist/src/ping/constants.d.ts.map +1 -1
- package/dist/src/ping/constants.js +10 -0
- package/dist/src/ping/constants.js.map +1 -1
- package/dist/src/ping/index.d.ts +10 -27
- package/dist/src/ping/index.d.ts.map +1 -1
- package/dist/src/ping/index.js +18 -21
- package/dist/src/ping/index.js.map +1 -1
- package/dist/src/registrar.d.ts +5 -2
- package/dist/src/registrar.d.ts.map +1 -1
- package/dist/src/registrar.js +27 -25
- package/dist/src/registrar.js.map +1 -1
- package/dist/src/transport-manager.d.ts +15 -4
- package/dist/src/transport-manager.d.ts.map +1 -1
- package/dist/src/transport-manager.js +37 -12
- package/dist/src/transport-manager.js.map +1 -1
- package/dist/src/upgrader.d.ts +16 -11
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +38 -47
- package/dist/src/upgrader.js.map +1 -1
- package/dist/src/upnp-nat/index.d.ts +42 -0
- package/dist/src/upnp-nat/index.d.ts.map +1 -0
- package/dist/src/{nat-manager.js → upnp-nat/index.js} +11 -7
- package/dist/src/upnp-nat/index.js.map +1 -0
- package/package.json +70 -54
- package/src/address-manager/index.ts +12 -8
- package/src/autonat/index.ts +20 -22
- package/src/circuit-relay/server/advert-service.ts +2 -2
- package/src/circuit-relay/server/index.ts +7 -3
- package/src/circuit-relay/transport/discovery.ts +3 -1
- package/src/circuit-relay/transport/index.ts +10 -2
- package/src/circuit-relay/transport/listener.ts +8 -4
- package/src/circuit-relay/transport/reservation-store.ts +15 -7
- package/src/circuit-relay/utils.ts +3 -1
- package/src/components.ts +72 -251
- package/src/config/connection-gater.browser.ts +31 -0
- package/src/config/connection-gater.ts +19 -0
- package/src/config.ts +3 -73
- package/src/connection-manager/auto-dial.ts +189 -0
- package/src/connection-manager/connection-pruner.ts +157 -0
- package/src/connection-manager/constants.ts +60 -0
- package/src/connection-manager/dial-queue.ts +506 -0
- package/src/connection-manager/index.ts +194 -339
- package/src/connection-manager/utils.ts +76 -0
- package/src/content-routing/index.ts +7 -55
- package/src/content-routing/utils.ts +3 -1
- package/src/fetch/index.ts +55 -18
- package/src/identify/index.ts +238 -228
- package/src/index.ts +12 -76
- package/src/insecure/index.ts +9 -5
- package/src/libp2p.ts +146 -265
- package/src/peer-routing.ts +1 -101
- package/src/ping/constants.ts +11 -0
- package/src/ping/index.ts +32 -28
- package/src/registrar.ts +31 -27
- package/src/transport-manager.ts +49 -15
- package/src/upgrader.ts +62 -57
- package/src/{nat-manager.ts → upnp-nat/index.ts} +15 -16
- package/src/version.ts +1 -1
- package/dist/src/connection-manager/auto-dialler.d.ts +0 -42
- package/dist/src/connection-manager/auto-dialler.d.ts.map +0 -1
- package/dist/src/connection-manager/auto-dialler.js +0 -105
- package/dist/src/connection-manager/auto-dialler.js.map +0 -1
- package/dist/src/connection-manager/dialer/dial-request.d.ts +0 -27
- package/dist/src/connection-manager/dialer/dial-request.d.ts.map +0 -1
- package/dist/src/connection-manager/dialer/dial-request.js +0 -114
- package/dist/src/connection-manager/dialer/dial-request.js.map +0 -1
- package/dist/src/connection-manager/dialer/index.d.ts +0 -121
- package/dist/src/connection-manager/dialer/index.d.ts.map +0 -1
- package/dist/src/connection-manager/dialer/index.js +0 -324
- package/dist/src/connection-manager/dialer/index.js.map +0 -1
- package/dist/src/connection-manager/latency-monitor.d.ts +0 -120
- package/dist/src/connection-manager/latency-monitor.d.ts.map +0 -1
- package/dist/src/connection-manager/latency-monitor.js +0 -220
- package/dist/src/connection-manager/latency-monitor.js.map +0 -1
- package/dist/src/connection-manager/visibility-change-emitter.d.ts +0 -66
- package/dist/src/connection-manager/visibility-change-emitter.d.ts.map +0 -1
- package/dist/src/connection-manager/visibility-change-emitter.js +0 -118
- package/dist/src/connection-manager/visibility-change-emitter.js.map +0 -1
- package/dist/src/constants.d.ts +0 -27
- package/dist/src/constants.d.ts.map +0 -1
- package/dist/src/constants.js +0 -31
- package/dist/src/constants.js.map +0 -1
- package/dist/src/dht/dht-content-routing.d.ts +0 -17
- package/dist/src/dht/dht-content-routing.d.ts.map +0 -1
- package/dist/src/dht/dht-content-routing.js +0 -32
- package/dist/src/dht/dht-content-routing.js.map +0 -1
- package/dist/src/dht/dht-peer-routing.d.ts +0 -15
- package/dist/src/dht/dht-peer-routing.d.ts.map +0 -1
- package/dist/src/dht/dht-peer-routing.js +0 -26
- package/dist/src/dht/dht-peer-routing.js.map +0 -1
- package/dist/src/dht/dummy-dht.d.ts +0 -20
- package/dist/src/dht/dummy-dht.d.ts.map +0 -1
- package/dist/src/dht/dummy-dht.js +0 -46
- package/dist/src/dht/dummy-dht.js.map +0 -1
- package/dist/src/nat-manager.d.ts +0 -74
- package/dist/src/nat-manager.d.ts.map +0 -1
- package/dist/src/nat-manager.js.map +0 -1
- package/dist/src/peer-record-updater.d.ts +0 -24
- package/dist/src/peer-record-updater.d.ts.map +0 -1
- package/dist/src/peer-record-updater.js +0 -44
- package/dist/src/peer-record-updater.js.map +0 -1
- package/dist/typedoc-urls.json +0 -41
- package/src/connection-manager/auto-dialler.ts +0 -158
- package/src/connection-manager/dialer/dial-request.ts +0 -144
- package/src/connection-manager/dialer/index.ts +0 -461
- package/src/connection-manager/latency-monitor.ts +0 -319
- package/src/connection-manager/visibility-change-emitter.ts +0 -135
- package/src/constants.ts +0 -36
- package/src/dht/dht-content-routing.ts +0 -44
- package/src/dht/dht-peer-routing.ts +0 -36
- package/src/dht/dummy-dht.ts +0 -60
- package/src/peer-record-updater.ts +0 -65
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libp2p",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.44.0-0d46c78f",
|
|
4
4
|
"description": "JavaScript implementation of libp2p, a modular peer to peer network stack",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p#readme",
|
|
@@ -52,14 +52,34 @@
|
|
|
52
52
|
"types": "./dist/src/index.d.ts",
|
|
53
53
|
"import": "./dist/src/index.js"
|
|
54
54
|
},
|
|
55
|
+
"./autonat": {
|
|
56
|
+
"types": "./dist/src/autonat/index.d.ts",
|
|
57
|
+
"import": "./dist/src/autonat/index.js"
|
|
58
|
+
},
|
|
55
59
|
"./circuit-relay": {
|
|
56
60
|
"types": "./dist/src/circuit-relay/index.d.ts",
|
|
57
61
|
"import": "./dist/src/circuit-relay/index.js"
|
|
58
62
|
},
|
|
63
|
+
"./fetch": {
|
|
64
|
+
"types": "./dist/src/fetch/index.d.ts",
|
|
65
|
+
"import": "./dist/src/fetch/index.js"
|
|
66
|
+
},
|
|
67
|
+
"./identify": {
|
|
68
|
+
"types": "./dist/src/identify/index.d.ts",
|
|
69
|
+
"import": "./dist/src/identify/index.js"
|
|
70
|
+
},
|
|
59
71
|
"./insecure": {
|
|
60
72
|
"types": "./dist/src/insecure/index.d.ts",
|
|
61
73
|
"import": "./dist/src/insecure/index.js"
|
|
62
74
|
},
|
|
75
|
+
"./upnp-nat": {
|
|
76
|
+
"types": "./dist/src/upnp-nat/index.d.ts",
|
|
77
|
+
"import": "./dist/src/upnp-nat/index.js"
|
|
78
|
+
},
|
|
79
|
+
"./ping": {
|
|
80
|
+
"types": "./dist/src/ping/index.d.ts",
|
|
81
|
+
"import": "./dist/src/ping/index.js"
|
|
82
|
+
},
|
|
63
83
|
"./pnet": {
|
|
64
84
|
"types": "./dist/src/pnet/index.d.ts",
|
|
65
85
|
"import": "./dist/src/pnet/index.js"
|
|
@@ -101,94 +121,89 @@
|
|
|
101
121
|
"dependencies": {
|
|
102
122
|
"@achingbrain/nat-port-mapper": "^1.0.3",
|
|
103
123
|
"@libp2p/crypto": "^1.0.4",
|
|
104
|
-
"@libp2p/interface-address-manager": "^
|
|
105
|
-
"@libp2p/interface-connection": "^
|
|
106
|
-
"@libp2p/interface-connection-encrypter": "^
|
|
107
|
-
"@libp2p/interface-connection-gater": "^
|
|
108
|
-
"@libp2p/interface-connection-manager": "^
|
|
109
|
-
"@libp2p/interface-content-routing": "^2.
|
|
110
|
-
"@libp2p/interface-dht": "^2.0.0",
|
|
124
|
+
"@libp2p/interface-address-manager": "^3.0.0",
|
|
125
|
+
"@libp2p/interface-connection": "^5.0.0",
|
|
126
|
+
"@libp2p/interface-connection-encrypter": "^4.0.0",
|
|
127
|
+
"@libp2p/interface-connection-gater": "^3.0.0",
|
|
128
|
+
"@libp2p/interface-connection-manager": "^3.0.0",
|
|
129
|
+
"@libp2p/interface-content-routing": "^2.1.0",
|
|
111
130
|
"@libp2p/interface-keychain": "^2.0.4",
|
|
112
|
-
"@libp2p/interface-libp2p": "^
|
|
131
|
+
"@libp2p/interface-libp2p": "^3.0.0",
|
|
113
132
|
"@libp2p/interface-metrics": "^4.0.0",
|
|
114
|
-
"@libp2p/interface-peer-discovery": "^
|
|
133
|
+
"@libp2p/interface-peer-discovery": "^2.0.0",
|
|
115
134
|
"@libp2p/interface-peer-id": "^2.0.1",
|
|
116
135
|
"@libp2p/interface-peer-info": "^1.0.3",
|
|
117
|
-
"@libp2p/interface-peer-routing": "^1.0
|
|
118
|
-
"@libp2p/interface-peer-store": "^
|
|
119
|
-
"@libp2p/interface-pubsub": "^
|
|
136
|
+
"@libp2p/interface-peer-routing": "^1.1.0",
|
|
137
|
+
"@libp2p/interface-peer-store": "^2.0.0",
|
|
138
|
+
"@libp2p/interface-pubsub": "^4.0.0",
|
|
120
139
|
"@libp2p/interface-record": "^2.0.6",
|
|
121
140
|
"@libp2p/interface-registrar": "^2.0.3",
|
|
122
|
-
"@libp2p/interface-stream-muxer": "^
|
|
123
|
-
"@libp2p/interface-transport": "^
|
|
141
|
+
"@libp2p/interface-stream-muxer": "^4.0.0",
|
|
142
|
+
"@libp2p/interface-transport": "^4.0.0",
|
|
124
143
|
"@libp2p/interfaces": "^3.2.0",
|
|
125
144
|
"@libp2p/keychain": "^2.0.0",
|
|
126
145
|
"@libp2p/logger": "^2.0.1",
|
|
127
|
-
"@libp2p/multistream-select": "^3.
|
|
146
|
+
"@libp2p/multistream-select": "^3.1.8",
|
|
128
147
|
"@libp2p/peer-collections": "^3.0.0",
|
|
129
148
|
"@libp2p/peer-id": "^2.0.0",
|
|
130
149
|
"@libp2p/peer-id-factory": "^2.0.0",
|
|
131
150
|
"@libp2p/peer-record": "^5.0.0",
|
|
132
|
-
"@libp2p/peer-store": "^
|
|
151
|
+
"@libp2p/peer-store": "^8.0.0",
|
|
133
152
|
"@libp2p/topology": "^4.0.1",
|
|
134
153
|
"@libp2p/tracked-map": "^3.0.0",
|
|
135
|
-
"@libp2p/utils": "^3.0.
|
|
154
|
+
"@libp2p/utils": "^3.0.10",
|
|
136
155
|
"@multiformats/mafmt": "^12.0.0",
|
|
137
156
|
"@multiformats/multiaddr": "^12.0.0",
|
|
138
|
-
"abortable-iterator": "^
|
|
139
|
-
"any-signal": "^
|
|
157
|
+
"abortable-iterator": "^5.0.1",
|
|
158
|
+
"any-signal": "^4.1.1",
|
|
140
159
|
"datastore-core": "^9.0.0",
|
|
141
160
|
"interface-datastore": "^8.0.0",
|
|
142
|
-
"it-all": "^
|
|
143
|
-
"it-drain": "^
|
|
144
|
-
"it-filter": "^
|
|
145
|
-
"it-first": "^
|
|
146
|
-
"it-
|
|
147
|
-
"it-
|
|
148
|
-
"it-
|
|
149
|
-
"it-
|
|
150
|
-
"it-merge": "^2.0.0",
|
|
161
|
+
"it-all": "^3.0.1",
|
|
162
|
+
"it-drain": "^3.0.1",
|
|
163
|
+
"it-filter": "^3.0.1",
|
|
164
|
+
"it-first": "^3.0.1",
|
|
165
|
+
"it-handshake": "^4.1.3",
|
|
166
|
+
"it-length-prefixed": "^9.0.1",
|
|
167
|
+
"it-map": "^3.0.2",
|
|
168
|
+
"it-merge": "^3.0.0",
|
|
151
169
|
"it-pair": "^2.0.2",
|
|
152
|
-
"it-
|
|
153
|
-
"it-
|
|
154
|
-
"it-
|
|
170
|
+
"it-parallel": "^3.0.0",
|
|
171
|
+
"it-pb-stream": "^4.0.1",
|
|
172
|
+
"it-pipe": "^3.0.1",
|
|
173
|
+
"it-stream-types": "^2.0.1",
|
|
155
174
|
"merge-options": "^3.0.4",
|
|
156
175
|
"multiformats": "^11.0.0",
|
|
157
176
|
"p-defer": "^4.0.0",
|
|
158
|
-
"p-fifo": "^1.0.0",
|
|
159
177
|
"p-queue": "^7.3.4",
|
|
160
178
|
"p-retry": "^5.0.0",
|
|
161
179
|
"private-ip": "^3.0.0",
|
|
162
180
|
"protons-runtime": "^5.0.0",
|
|
163
181
|
"rate-limiter-flexible": "^2.3.11",
|
|
164
|
-
"retimer": "^3.0.0",
|
|
165
182
|
"set-delayed-interval": "^1.0.0",
|
|
166
|
-
"timeout-abort-controller": "^3.0.0",
|
|
167
183
|
"uint8arraylist": "^2.3.2",
|
|
168
184
|
"uint8arrays": "^4.0.2",
|
|
169
185
|
"wherearewe": "^2.0.0",
|
|
170
186
|
"xsalsa20": "^1.1.0"
|
|
171
187
|
},
|
|
172
188
|
"devDependencies": {
|
|
173
|
-
"@chainsafe/libp2p-gossipsub": "^
|
|
189
|
+
"@chainsafe/libp2p-gossipsub": "^7.0.0",
|
|
174
190
|
"@chainsafe/libp2p-noise": "^11.0.0",
|
|
175
|
-
"@chainsafe/libp2p-yamux": "^
|
|
176
|
-
"@libp2p/bootstrap": "^
|
|
177
|
-
"@libp2p/daemon-client": "^
|
|
178
|
-
"@libp2p/daemon-server": "^
|
|
179
|
-
"@libp2p/floodsub": "^
|
|
180
|
-
"@libp2p/interface-compliance-tests": "^3.0.
|
|
181
|
-
"@libp2p/interface-connection-compliance-tests": "^2.0.
|
|
182
|
-
"@libp2p/interface-connection-encrypter-compliance-tests": "^
|
|
183
|
-
"@libp2p/interface-mocks": "^
|
|
184
|
-
"@libp2p/interop": "^
|
|
185
|
-
"@libp2p/kad-dht": "^
|
|
186
|
-
"@libp2p/mdns": "^
|
|
187
|
-
"@libp2p/mplex": "^
|
|
188
|
-
"@libp2p/pubsub": "^
|
|
189
|
-
"@libp2p/tcp": "^
|
|
190
|
-
"@libp2p/websockets": "^
|
|
191
|
-
"@types/p-fifo": "^1.0.0",
|
|
191
|
+
"@chainsafe/libp2p-yamux": "^4.0.0",
|
|
192
|
+
"@libp2p/bootstrap": "^8.0.0",
|
|
193
|
+
"@libp2p/daemon-client": "^6.0.2",
|
|
194
|
+
"@libp2p/daemon-server": "^5.0.2",
|
|
195
|
+
"@libp2p/floodsub": "^7.0.1",
|
|
196
|
+
"@libp2p/interface-compliance-tests": "^3.0.6",
|
|
197
|
+
"@libp2p/interface-connection-compliance-tests": "^2.0.8",
|
|
198
|
+
"@libp2p/interface-connection-encrypter-compliance-tests": "^5.0.0",
|
|
199
|
+
"@libp2p/interface-mocks": "^12.0.0",
|
|
200
|
+
"@libp2p/interop": "^8.0.0",
|
|
201
|
+
"@libp2p/kad-dht": "^9.1.4",
|
|
202
|
+
"@libp2p/mdns": "^8.0.0",
|
|
203
|
+
"@libp2p/mplex": "^8.0.1",
|
|
204
|
+
"@libp2p/pubsub": "^7.0.1",
|
|
205
|
+
"@libp2p/tcp": "^7.0.1",
|
|
206
|
+
"@libp2p/websockets": "^6.0.1",
|
|
192
207
|
"@types/varint": "^6.0.0",
|
|
193
208
|
"@types/xsalsa20": "^1.1.0",
|
|
194
209
|
"aegir": "^38.1.7",
|
|
@@ -197,7 +212,7 @@
|
|
|
197
212
|
"execa": "^7.0.0",
|
|
198
213
|
"go-libp2p": "^1.0.1",
|
|
199
214
|
"it-pushable": "^3.0.0",
|
|
200
|
-
"it-to-buffer": "^
|
|
215
|
+
"it-to-buffer": "^4.0.1",
|
|
201
216
|
"npm-run-all": "^4.1.5",
|
|
202
217
|
"p-event": "^5.0.1",
|
|
203
218
|
"p-times": "^4.0.0",
|
|
@@ -207,6 +222,7 @@
|
|
|
207
222
|
"sinon-ts": "^1.0.0"
|
|
208
223
|
},
|
|
209
224
|
"browser": {
|
|
225
|
+
"./dist/src/config/connection-gater.js": "./dist/src/config/connection-gater.browser.js",
|
|
210
226
|
"nat-api": false
|
|
211
227
|
}
|
|
212
228
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import type { AddressManagerEvents } from '@libp2p/interface-address-manager'
|
|
2
|
-
import { CustomEvent, EventEmitter } from '@libp2p/interfaces/events'
|
|
3
1
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
4
2
|
import { multiaddr } from '@multiformats/multiaddr'
|
|
5
3
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
6
4
|
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
7
5
|
import type { TransportManager } from '@libp2p/interface-transport'
|
|
6
|
+
import type { PeerStore } from '@libp2p/interface-peer-store'
|
|
7
|
+
import { logger } from '@libp2p/logger'
|
|
8
|
+
|
|
9
|
+
const log = logger('libp2p:address-manager')
|
|
8
10
|
|
|
9
11
|
export interface AddressManagerInit {
|
|
10
12
|
/**
|
|
@@ -32,6 +34,7 @@ export interface AddressManagerInit {
|
|
|
32
34
|
export interface DefaultAddressManagerComponents {
|
|
33
35
|
peerId: PeerId
|
|
34
36
|
transportManager: TransportManager
|
|
37
|
+
peerStore: PeerStore
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
/**
|
|
@@ -67,7 +70,7 @@ function stripPeerId (ma: Multiaddr, peerId: PeerId): Multiaddr {
|
|
|
67
70
|
return ma
|
|
68
71
|
}
|
|
69
72
|
|
|
70
|
-
export class DefaultAddressManager
|
|
73
|
+
export class DefaultAddressManager {
|
|
71
74
|
private readonly components: DefaultAddressManagerComponents
|
|
72
75
|
// this is an array to allow for duplicates, e.g. multiples of `/ip4/0.0.0.0/tcp/0`
|
|
73
76
|
private readonly listen: string[]
|
|
@@ -81,9 +84,7 @@ export class DefaultAddressManager extends EventEmitter<AddressManagerEvents> {
|
|
|
81
84
|
* The listen addresses will be used by the libp2p transports to listen for new connections,
|
|
82
85
|
* while the announce addresses will be used for the peer addresses' to other peers in the network.
|
|
83
86
|
*/
|
|
84
|
-
constructor (components: DefaultAddressManagerComponents, init: AddressManagerInit) {
|
|
85
|
-
super()
|
|
86
|
-
|
|
87
|
+
constructor (components: DefaultAddressManagerComponents, init: AddressManagerInit = {}) {
|
|
87
88
|
const { listen = [], announce = [] } = init
|
|
88
89
|
|
|
89
90
|
this.components = components
|
|
@@ -145,9 +146,12 @@ export class DefaultAddressManager extends EventEmitter<AddressManagerEvents> {
|
|
|
145
146
|
confident: true
|
|
146
147
|
})
|
|
147
148
|
|
|
148
|
-
// only trigger the
|
|
149
|
+
// only trigger the 'self:peer:update' event if our confidence in an address has changed
|
|
149
150
|
if (!startingConfidence) {
|
|
150
|
-
this.
|
|
151
|
+
this.components.peerStore.patch(this.components.peerId, {
|
|
152
|
+
multiaddrs: this.getAddresses()
|
|
153
|
+
})
|
|
154
|
+
.catch(err => { log.error('error updating addresses', err) })
|
|
151
155
|
}
|
|
152
156
|
}
|
|
153
157
|
|
package/src/autonat/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AddressManager } from '@libp2p/interface-address-manager'
|
|
2
2
|
import type { Connection } from '@libp2p/interface-connection'
|
|
3
|
-
import type { ConnectionManager
|
|
3
|
+
import type { ConnectionManager } from '@libp2p/interface-connection-manager'
|
|
4
4
|
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
5
5
|
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
6
6
|
import type { PeerRouting } from '@libp2p/interface-peer-routing'
|
|
@@ -19,11 +19,11 @@ import map from 'it-map'
|
|
|
19
19
|
import parallel from 'it-parallel'
|
|
20
20
|
import { pipe } from 'it-pipe'
|
|
21
21
|
import isPrivateIp from 'private-ip'
|
|
22
|
-
import { TimeoutController } from 'timeout-abort-controller'
|
|
23
22
|
import {
|
|
24
23
|
PROTOCOL
|
|
25
24
|
} from './constants.js'
|
|
26
25
|
import { Message } from './pb/index.js'
|
|
26
|
+
import { anySignal } from 'any-signal'
|
|
27
27
|
|
|
28
28
|
const log = logger('libp2p:autonat')
|
|
29
29
|
|
|
@@ -74,7 +74,6 @@ export interface DefaultAutonatComponents {
|
|
|
74
74
|
registrar: Registrar
|
|
75
75
|
addressManager: AddressManager
|
|
76
76
|
transportManager: TransportManager
|
|
77
|
-
dialer: Dialer
|
|
78
77
|
peerId: PeerId
|
|
79
78
|
connectionManager: ConnectionManager
|
|
80
79
|
peerRouting: PeerRouting
|
|
@@ -133,25 +132,25 @@ export class AutonatService implements Startable {
|
|
|
133
132
|
* Handle an incoming autonat request
|
|
134
133
|
*/
|
|
135
134
|
async handleIncomingAutonatStream (data: IncomingStreamData): Promise<void> {
|
|
136
|
-
const
|
|
135
|
+
const signal = anySignal([AbortSignal.timeout(this._init.timeout)])
|
|
137
136
|
|
|
138
137
|
// this controller may be used while dialing lots of peers so prevent MaxListenersExceededWarning
|
|
139
138
|
// appearing in the console
|
|
140
139
|
try {
|
|
141
140
|
// fails on node < 15.4
|
|
142
|
-
setMaxListeners?.(Infinity,
|
|
141
|
+
setMaxListeners?.(Infinity, signal)
|
|
143
142
|
} catch {}
|
|
144
143
|
|
|
145
144
|
const ourHosts = this.components.addressManager.getAddresses()
|
|
146
145
|
.map(ma => ma.toOptions().host)
|
|
147
146
|
|
|
148
147
|
try {
|
|
149
|
-
const source = abortableDuplex(data.stream,
|
|
148
|
+
const source = abortableDuplex(data.stream, signal)
|
|
150
149
|
const self = this
|
|
151
150
|
|
|
152
151
|
await pipe(
|
|
153
152
|
source,
|
|
154
|
-
lp.decode(),
|
|
153
|
+
(source) => lp.decode(source),
|
|
155
154
|
async function * (stream) {
|
|
156
155
|
const buf = await first(stream)
|
|
157
156
|
|
|
@@ -319,10 +318,8 @@ export class AutonatService implements Startable {
|
|
|
319
318
|
lastMultiaddr = multiaddr
|
|
320
319
|
|
|
321
320
|
try {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
connection = await self.components.dialer.dial(multiaddr, {
|
|
325
|
-
signal: controller.signal
|
|
321
|
+
connection = await self.components.connectionManager.openConnection(multiaddr, {
|
|
322
|
+
signal
|
|
326
323
|
})
|
|
327
324
|
|
|
328
325
|
if (!connection.remoteAddr.equals(multiaddr)) {
|
|
@@ -360,13 +357,15 @@ export class AutonatService implements Startable {
|
|
|
360
357
|
}
|
|
361
358
|
})
|
|
362
359
|
},
|
|
363
|
-
lp.encode(),
|
|
360
|
+
(source) => lp.encode(source),
|
|
364
361
|
// pipe to the stream, not the abortable source other wise we
|
|
365
362
|
// can't tell the remote when a dial timed out..
|
|
366
363
|
data.stream
|
|
367
364
|
)
|
|
365
|
+
} catch (err) {
|
|
366
|
+
log.error(err)
|
|
368
367
|
} finally {
|
|
369
|
-
|
|
368
|
+
signal.clear()
|
|
370
369
|
}
|
|
371
370
|
}
|
|
372
371
|
|
|
@@ -404,13 +403,13 @@ export class AutonatService implements Startable {
|
|
|
404
403
|
return
|
|
405
404
|
}
|
|
406
405
|
|
|
407
|
-
const
|
|
406
|
+
const signal = AbortSignal.timeout(this._init.timeout)
|
|
408
407
|
|
|
409
408
|
// this controller may be used while dialing lots of peers so prevent MaxListenersExceededWarning
|
|
410
409
|
// appearing in the console
|
|
411
410
|
try {
|
|
412
411
|
// fails on node < 15.4
|
|
413
|
-
setMaxListeners?.(Infinity,
|
|
412
|
+
setMaxListeners?.(Infinity, signal)
|
|
414
413
|
} catch {}
|
|
415
414
|
|
|
416
415
|
const self = this
|
|
@@ -439,19 +438,19 @@ export class AutonatService implements Startable {
|
|
|
439
438
|
log('Asking %p to verify multiaddr', peer.id)
|
|
440
439
|
|
|
441
440
|
const connection = await self.components.connectionManager.openConnection(peer.id, {
|
|
442
|
-
signal
|
|
441
|
+
signal
|
|
443
442
|
})
|
|
444
443
|
|
|
445
444
|
const stream = await connection.newStream(PROTOCOL, {
|
|
446
|
-
signal
|
|
445
|
+
signal
|
|
447
446
|
})
|
|
448
|
-
const source = abortableDuplex(stream,
|
|
447
|
+
const source = abortableDuplex(stream, signal)
|
|
449
448
|
|
|
450
449
|
const buf = await pipe(
|
|
451
450
|
[request],
|
|
452
|
-
lp.encode(),
|
|
451
|
+
(source) => lp.encode(source),
|
|
453
452
|
source,
|
|
454
|
-
lp.decode(),
|
|
453
|
+
(source) => lp.decode(source),
|
|
455
454
|
async (stream) => await first(stream)
|
|
456
455
|
)
|
|
457
456
|
if (buf == null) {
|
|
@@ -496,7 +495,7 @@ export class AutonatService implements Startable {
|
|
|
496
495
|
}
|
|
497
496
|
|
|
498
497
|
for await (const dialResponse of parallel(map(this.components.peerRouting.getClosestPeers(randomCid, {
|
|
499
|
-
signal
|
|
498
|
+
signal
|
|
500
499
|
}), (peer) => async () => await verifyAddress(peer)), {
|
|
501
500
|
concurrency: REQUIRED_SUCCESSFUL_DIALS
|
|
502
501
|
})) {
|
|
@@ -560,7 +559,6 @@ export class AutonatService implements Startable {
|
|
|
560
559
|
}
|
|
561
560
|
}
|
|
562
561
|
} finally {
|
|
563
|
-
controller.clear()
|
|
564
562
|
this.verifyAddressTimeout = setTimeout(this._verifyExternalAddresses, this.refreshInterval)
|
|
565
563
|
}
|
|
566
564
|
}
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from '../constants.js'
|
|
8
8
|
import type { Startable } from '@libp2p/interfaces/startable'
|
|
9
9
|
import type { ContentRouting } from '@libp2p/interface-content-routing'
|
|
10
|
-
import {
|
|
10
|
+
import { EventEmitter } from '@libp2p/interfaces/events'
|
|
11
11
|
import pRetry from 'p-retry'
|
|
12
12
|
|
|
13
13
|
const log = logger('libp2p:circuit-relay:advert-service')
|
|
@@ -90,7 +90,7 @@ export class AdvertService extends EventEmitter<AdvertServiceEvents> implements
|
|
|
90
90
|
const cid = await namespaceToCid(RELAY_RENDEZVOUS_NS)
|
|
91
91
|
await this.contentRouting.provide(cid)
|
|
92
92
|
|
|
93
|
-
this.
|
|
93
|
+
this.safeDispatchEvent('advert:success', { detail: undefined })
|
|
94
94
|
} catch (err: any) {
|
|
95
95
|
this.safeDispatchEvent('advert:error', { detail: err })
|
|
96
96
|
|
|
@@ -24,7 +24,7 @@ import { ReservationVoucherRecord } from './reservation-voucher.js'
|
|
|
24
24
|
import type { AddressManager } from '@libp2p/interface-address-manager'
|
|
25
25
|
import type { ConnectionManager } from '@libp2p/interface-connection-manager'
|
|
26
26
|
import type { CircuitRelayService, RelayReservation } from '../index.js'
|
|
27
|
-
import {
|
|
27
|
+
import { EventEmitter } from '@libp2p/interfaces/events'
|
|
28
28
|
import { setMaxListeners } from 'events'
|
|
29
29
|
import type { PeerMap } from '@libp2p/peer-collections'
|
|
30
30
|
|
|
@@ -128,7 +128,7 @@ class CircuitRelayServer extends EventEmitter<RelayServerEvents> implements Star
|
|
|
128
128
|
if (init.advertise != null && init.advertise !== false) {
|
|
129
129
|
this.advertService = new AdvertService(components, init.advertise === true ? undefined : init.advertise)
|
|
130
130
|
this.advertService.addEventListener('advert:success', () => {
|
|
131
|
-
this.
|
|
131
|
+
this.safeDispatchEvent('relay:advert:success', {})
|
|
132
132
|
})
|
|
133
133
|
this.advertService.addEventListener('advert:error', (evt) => {
|
|
134
134
|
this.safeDispatchEvent('relay:advert:error', { detail: evt.detail })
|
|
@@ -260,7 +260,11 @@ class CircuitRelayServer extends EventEmitter<RelayServerEvents> implements Star
|
|
|
260
260
|
// result.expire is non-null if `ReservationStore.reserve` returns with status == OK
|
|
261
261
|
if (result.expire != null) {
|
|
262
262
|
const ttl = (result.expire * 1000) - Date.now()
|
|
263
|
-
await this.peerStore.
|
|
263
|
+
await this.peerStore.merge(connection.remotePeer, {
|
|
264
|
+
tags: {
|
|
265
|
+
[RELAY_SOURCE_TAG]: { value: 1, ttl }
|
|
266
|
+
}
|
|
267
|
+
})
|
|
264
268
|
}
|
|
265
269
|
|
|
266
270
|
hopstr.write({
|
|
@@ -113,7 +113,9 @@ export class RelayDiscovery extends EventEmitter<RelayDiscoveryEvents> implement
|
|
|
113
113
|
|
|
114
114
|
found++
|
|
115
115
|
log('found relay peer %p in content routing', peerId)
|
|
116
|
-
await this.peerStore.
|
|
116
|
+
await this.peerStore.merge(peerId, {
|
|
117
|
+
multiaddrs: provider.multiaddrs
|
|
118
|
+
})
|
|
117
119
|
|
|
118
120
|
this.safeDispatchEvent('relay:discover', { detail: peerId })
|
|
119
121
|
}
|
|
@@ -23,6 +23,8 @@ import { CIRCUIT_PROTO_CODE, RELAY_V2_HOP_CODEC, RELAY_V2_STOP_CODEC } from '../
|
|
|
23
23
|
import { RelayStoreInit, ReservationStore } from './reservation-store.js'
|
|
24
24
|
import { RelayDiscovery, RelayDiscoveryComponents } from './discovery.js'
|
|
25
25
|
import { CodeError } from '@libp2p/interfaces/errors'
|
|
26
|
+
import type { EventEmitter } from '@libp2p/interfaces/events'
|
|
27
|
+
import type { Libp2pEvents } from '@libp2p/interface-libp2p'
|
|
26
28
|
|
|
27
29
|
const log = logger('libp2p:circuit-relay:transport')
|
|
28
30
|
|
|
@@ -49,6 +51,7 @@ export interface CircuitRelayTransportComponents extends RelayDiscoveryComponent
|
|
|
49
51
|
addressManager: AddressManager
|
|
50
52
|
contentRouting: ContentRouting
|
|
51
53
|
connectionGater: ConnectionGater
|
|
54
|
+
events: EventEmitter<Libp2pEvents>
|
|
52
55
|
}
|
|
53
56
|
|
|
54
57
|
interface ConnectOptions {
|
|
@@ -81,6 +84,7 @@ class CircuitRelayTransport implements Transport {
|
|
|
81
84
|
private readonly upgrader: Upgrader
|
|
82
85
|
private readonly addressManager: AddressManager
|
|
83
86
|
private readonly connectionGater: ConnectionGater
|
|
87
|
+
private readonly events: EventEmitter<Libp2pEvents>
|
|
84
88
|
private readonly reservationStore: ReservationStore
|
|
85
89
|
private started: boolean
|
|
86
90
|
|
|
@@ -92,6 +96,7 @@ class CircuitRelayTransport implements Transport {
|
|
|
92
96
|
this.upgrader = components.upgrader
|
|
93
97
|
this.addressManager = components.addressManager
|
|
94
98
|
this.connectionGater = components.connectionGater
|
|
99
|
+
this.events = components.events
|
|
95
100
|
|
|
96
101
|
if (init.discoverRelays != null && init.discoverRelays > 0) {
|
|
97
102
|
this.discovery = new RelayDiscovery(components)
|
|
@@ -178,7 +183,9 @@ class CircuitRelayTransport implements Transport {
|
|
|
178
183
|
let relayConnection = relayConnections[0]
|
|
179
184
|
|
|
180
185
|
if (relayConnection == null) {
|
|
181
|
-
await this.peerStore.
|
|
186
|
+
await this.peerStore.merge(relayPeer, {
|
|
187
|
+
multiaddrs: [relayAddr]
|
|
188
|
+
})
|
|
182
189
|
relayConnection = await this.connectionManager.openConnection(relayPeer, options)
|
|
183
190
|
disconnectOnFailure = true
|
|
184
191
|
}
|
|
@@ -249,7 +256,8 @@ class CircuitRelayTransport implements Transport {
|
|
|
249
256
|
createListener (options: CreateListenerOptions): Listener {
|
|
250
257
|
return createListener({
|
|
251
258
|
connectionManager: this.connectionManager,
|
|
252
|
-
relayStore: this.reservationStore
|
|
259
|
+
relayStore: this.reservationStore,
|
|
260
|
+
events: this.events
|
|
253
261
|
})
|
|
254
262
|
}
|
|
255
263
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EventEmitter } from '@libp2p/interfaces/events'
|
|
2
2
|
import type { ConnectionManager } from '@libp2p/interface-connection-manager'
|
|
3
3
|
import type { Listener, ListenerEvents } from '@libp2p/interface-transport'
|
|
4
4
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
@@ -7,24 +7,28 @@ import type { ReservationStore } from './reservation-store.js'
|
|
|
7
7
|
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
8
8
|
import { PeerMap } from '@libp2p/peer-collections'
|
|
9
9
|
import { logger } from '@libp2p/logger'
|
|
10
|
+
import type { Libp2pEvents } from '@libp2p/interface-libp2p'
|
|
10
11
|
|
|
11
12
|
const log = logger('libp2p:circuit-relay:transport:listener')
|
|
12
13
|
|
|
13
14
|
export interface CircuitRelayTransportListenerComponents {
|
|
14
15
|
connectionManager: ConnectionManager
|
|
15
16
|
relayStore: ReservationStore
|
|
17
|
+
events: EventEmitter<Libp2pEvents>
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
class CircuitRelayTransportListener extends EventEmitter<ListenerEvents> implements Listener {
|
|
19
21
|
private readonly connectionManager: ConnectionManager
|
|
20
22
|
private readonly relayStore: ReservationStore
|
|
21
23
|
private readonly listeningAddrs: PeerMap<Multiaddr>
|
|
24
|
+
private readonly events: EventEmitter<Libp2pEvents>
|
|
22
25
|
|
|
23
26
|
constructor (components: CircuitRelayTransportListenerComponents) {
|
|
24
27
|
super()
|
|
25
28
|
|
|
26
29
|
this.connectionManager = components.connectionManager
|
|
27
30
|
this.relayStore = components.relayStore
|
|
31
|
+
this.events = components.events
|
|
28
32
|
this.listeningAddrs = new PeerMap()
|
|
29
33
|
|
|
30
34
|
// remove listening addrs when a relay is removed
|
|
@@ -33,7 +37,7 @@ class CircuitRelayTransportListener extends EventEmitter<ListenerEvents> impleme
|
|
|
33
37
|
})
|
|
34
38
|
|
|
35
39
|
// remove listening addrs when a peer disconnects
|
|
36
|
-
this.
|
|
40
|
+
this.events.addEventListener('connection:close', (evt) => {
|
|
37
41
|
this.#removeRelayPeer(evt.detail.remotePeer)
|
|
38
42
|
})
|
|
39
43
|
}
|
|
@@ -57,7 +61,7 @@ class CircuitRelayTransportListener extends EventEmitter<ListenerEvents> impleme
|
|
|
57
61
|
}
|
|
58
62
|
|
|
59
63
|
this.listeningAddrs.set(relayConn.remotePeer, addr)
|
|
60
|
-
this.
|
|
64
|
+
this.safeDispatchEvent('listening', {})
|
|
61
65
|
}
|
|
62
66
|
|
|
63
67
|
/**
|
|
@@ -89,7 +93,7 @@ class CircuitRelayTransportListener extends EventEmitter<ListenerEvents> impleme
|
|
|
89
93
|
|
|
90
94
|
if (had) {
|
|
91
95
|
// Announce listen addresses change
|
|
92
|
-
this.
|
|
96
|
+
this.safeDispatchEvent('close', {})
|
|
93
97
|
}
|
|
94
98
|
}
|
|
95
99
|
}
|
|
@@ -10,10 +10,11 @@ import type { Reservation } from '../pb/index.js'
|
|
|
10
10
|
import { HopMessage, Status } from '../pb/index.js'
|
|
11
11
|
import { getExpirationMilliseconds } from '../utils.js'
|
|
12
12
|
import type { TransportManager } from '@libp2p/interface-transport'
|
|
13
|
-
import type { Startable } from '@libp2p/interfaces/
|
|
14
|
-
import {
|
|
13
|
+
import type { Startable } from '@libp2p/interfaces/startable'
|
|
14
|
+
import { EventEmitter } from '@libp2p/interfaces/events'
|
|
15
15
|
import type { PeerStore } from '@libp2p/interface-peer-store'
|
|
16
16
|
import { multiaddr } from '@multiformats/multiaddr'
|
|
17
|
+
import type { Libp2pEvents } from '@libp2p/interface-libp2p'
|
|
17
18
|
|
|
18
19
|
const log = logger('libp2p:circuit-relay:transport:reservation-store')
|
|
19
20
|
|
|
@@ -31,6 +32,7 @@ export interface RelayStoreComponents {
|
|
|
31
32
|
connectionManager: ConnectionManager
|
|
32
33
|
transportManager: TransportManager
|
|
33
34
|
peerStore: PeerStore
|
|
35
|
+
events: EventEmitter<Libp2pEvents>
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
export interface RelayStoreInit {
|
|
@@ -68,6 +70,7 @@ export class ReservationStore extends EventEmitter<ReservationStoreEvents> imple
|
|
|
68
70
|
private readonly connectionManager: ConnectionManager
|
|
69
71
|
private readonly transportManager: TransportManager
|
|
70
72
|
private readonly peerStore: PeerStore
|
|
73
|
+
private readonly events: EventEmitter<Libp2pEvents>
|
|
71
74
|
private readonly reserveQueue: PQueue
|
|
72
75
|
private readonly reservations: PeerMap<RelayEntry>
|
|
73
76
|
private readonly maxDiscoveredRelays: number
|
|
@@ -80,6 +83,7 @@ export class ReservationStore extends EventEmitter<ReservationStoreEvents> imple
|
|
|
80
83
|
this.connectionManager = components.connectionManager
|
|
81
84
|
this.transportManager = components.transportManager
|
|
82
85
|
this.peerStore = components.peerStore
|
|
86
|
+
this.events = components.events
|
|
83
87
|
this.reservations = new PeerMap()
|
|
84
88
|
this.maxDiscoveredRelays = init?.discoverRelays ?? 0
|
|
85
89
|
this.started = false
|
|
@@ -92,7 +96,7 @@ export class ReservationStore extends EventEmitter<ReservationStoreEvents> imple
|
|
|
92
96
|
// When a peer disconnects, if we had a reservation on that peer
|
|
93
97
|
// remove the reservation and multiaddr and maybe trigger search
|
|
94
98
|
// for new relays
|
|
95
|
-
this.
|
|
99
|
+
this.events.addEventListener('connection:close', (evt) => {
|
|
96
100
|
this.removeRelay(evt.detail.remotePeer)
|
|
97
101
|
})
|
|
98
102
|
}
|
|
@@ -184,9 +188,13 @@ export class ReservationStore extends EventEmitter<ReservationStoreEvents> imple
|
|
|
184
188
|
})
|
|
185
189
|
|
|
186
190
|
// ensure we don't close the connection to the relay
|
|
187
|
-
await this.peerStore.
|
|
188
|
-
|
|
189
|
-
|
|
191
|
+
await this.peerStore.merge(peerId, {
|
|
192
|
+
tags: {
|
|
193
|
+
[RELAY_TAG]: {
|
|
194
|
+
value: 1,
|
|
195
|
+
ttl: expiration
|
|
196
|
+
}
|
|
197
|
+
}
|
|
190
198
|
})
|
|
191
199
|
|
|
192
200
|
await this.transportManager.listen(
|
|
@@ -250,7 +258,7 @@ export class ReservationStore extends EventEmitter<ReservationStoreEvents> imple
|
|
|
250
258
|
this.safeDispatchEvent('relay:removed', { detail: peerId })
|
|
251
259
|
|
|
252
260
|
if (this.reservations.size < this.maxDiscoveredRelays) {
|
|
253
|
-
this.
|
|
261
|
+
this.safeDispatchEvent('relay:not-enough-relays', {})
|
|
254
262
|
}
|
|
255
263
|
}
|
|
256
264
|
}
|