libp2p 0.37.3 → 0.38.0-57ef754

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.
Files changed (193) hide show
  1. package/README.md +2 -1
  2. package/dist/src/address-manager/index.d.ts +2 -2
  3. package/dist/src/address-manager/index.d.ts.map +1 -1
  4. package/dist/src/circuit/auto-relay.d.ts +4 -4
  5. package/dist/src/circuit/auto-relay.d.ts.map +1 -1
  6. package/dist/src/circuit/auto-relay.js +4 -0
  7. package/dist/src/circuit/auto-relay.js.map +1 -1
  8. package/dist/src/circuit/circuit/hop.d.ts +7 -5
  9. package/dist/src/circuit/circuit/hop.d.ts.map +1 -1
  10. package/dist/src/circuit/circuit/hop.js +8 -4
  11. package/dist/src/circuit/circuit/hop.js.map +1 -1
  12. package/dist/src/circuit/circuit/stop.d.ts +6 -4
  13. package/dist/src/circuit/circuit/stop.d.ts.map +1 -1
  14. package/dist/src/circuit/circuit/stop.js +4 -2
  15. package/dist/src/circuit/circuit/stop.js.map +1 -1
  16. package/dist/src/circuit/circuit/stream-handler.d.ts +3 -2
  17. package/dist/src/circuit/circuit/stream-handler.d.ts.map +1 -1
  18. package/dist/src/circuit/circuit/stream-handler.js +2 -2
  19. package/dist/src/circuit/circuit/stream-handler.js.map +1 -1
  20. package/dist/src/circuit/index.d.ts +4 -12
  21. package/dist/src/circuit/index.d.ts.map +1 -1
  22. package/dist/src/circuit/index.js.map +1 -1
  23. package/dist/src/circuit/listener.d.ts +3 -3
  24. package/dist/src/circuit/listener.d.ts.map +1 -1
  25. package/dist/src/circuit/pb/index.d.ts +5 -4
  26. package/dist/src/circuit/pb/index.d.ts.map +1 -1
  27. package/dist/src/circuit/pb/index.js +107 -11
  28. package/dist/src/circuit/pb/index.js.map +1 -1
  29. package/dist/src/circuit/transport.d.ts +8 -5
  30. package/dist/src/circuit/transport.d.ts.map +1 -1
  31. package/dist/src/circuit/transport.js +81 -59
  32. package/dist/src/circuit/transport.js.map +1 -1
  33. package/dist/src/config.d.ts.map +1 -1
  34. package/dist/src/config.js +27 -4
  35. package/dist/src/config.js.map +1 -1
  36. package/dist/src/connection-manager/auto-dialler.d.ts +1 -1
  37. package/dist/src/connection-manager/auto-dialler.d.ts.map +1 -1
  38. package/dist/src/connection-manager/dialer/auto-dialer.d.ts +2 -2
  39. package/dist/src/connection-manager/dialer/auto-dialer.d.ts.map +1 -1
  40. package/dist/src/connection-manager/dialer/auto-dialer.js +6 -0
  41. package/dist/src/connection-manager/dialer/auto-dialer.js.map +1 -1
  42. package/dist/src/connection-manager/dialer/dial-request.d.ts +1 -1
  43. package/dist/src/connection-manager/dialer/dial-request.d.ts.map +1 -1
  44. package/dist/src/connection-manager/dialer/index.d.ts +9 -9
  45. package/dist/src/connection-manager/dialer/index.d.ts.map +1 -1
  46. package/dist/src/connection-manager/dialer/index.js +15 -12
  47. package/dist/src/connection-manager/dialer/index.js.map +1 -1
  48. package/dist/src/connection-manager/index.d.ts +20 -16
  49. package/dist/src/connection-manager/index.d.ts.map +1 -1
  50. package/dist/src/connection-manager/index.js +185 -65
  51. package/dist/src/connection-manager/index.js.map +1 -1
  52. package/dist/src/constants.d.ts +4 -0
  53. package/dist/src/constants.d.ts.map +1 -1
  54. package/dist/src/constants.js +4 -0
  55. package/dist/src/constants.js.map +1 -1
  56. package/dist/src/content-routing/index.d.ts +4 -4
  57. package/dist/src/content-routing/index.d.ts.map +1 -1
  58. package/dist/src/content-routing/utils.d.ts +2 -2
  59. package/dist/src/content-routing/utils.d.ts.map +1 -1
  60. package/dist/src/dht/dht-content-routing.d.ts +3 -3
  61. package/dist/src/dht/dht-content-routing.d.ts.map +1 -1
  62. package/dist/src/dht/dht-peer-routing.d.ts +5 -5
  63. package/dist/src/dht/dht-peer-routing.d.ts.map +1 -1
  64. package/dist/src/dht/dummy-dht.d.ts +3 -3
  65. package/dist/src/dht/dummy-dht.d.ts.map +1 -1
  66. package/dist/src/dht/dummy-dht.js +1 -1
  67. package/dist/src/dht/dummy-dht.js.map +1 -1
  68. package/dist/src/errors.d.ts +4 -1
  69. package/dist/src/errors.d.ts.map +1 -1
  70. package/dist/src/errors.js +3 -0
  71. package/dist/src/errors.js.map +1 -1
  72. package/dist/src/fetch/index.d.ts +11 -4
  73. package/dist/src/fetch/index.d.ts.map +1 -1
  74. package/dist/src/fetch/index.js +82 -41
  75. package/dist/src/fetch/index.js.map +1 -1
  76. package/dist/src/fetch/pb/proto.d.ts +4 -3
  77. package/dist/src/fetch/pb/proto.d.ts.map +1 -1
  78. package/dist/src/fetch/pb/proto.js +88 -8
  79. package/dist/src/fetch/pb/proto.js.map +1 -1
  80. package/dist/src/get-peer.d.ts +2 -2
  81. package/dist/src/get-peer.d.ts.map +1 -1
  82. package/dist/src/get-peer.js +1 -1
  83. package/dist/src/get-peer.js.map +1 -1
  84. package/dist/src/identify/index.d.ts +8 -8
  85. package/dist/src/identify/index.d.ts.map +1 -1
  86. package/dist/src/identify/index.js +49 -34
  87. package/dist/src/identify/index.js.map +1 -1
  88. package/dist/src/identify/pb/message.d.ts +2 -1
  89. package/dist/src/identify/pb/message.d.ts.map +1 -1
  90. package/dist/src/identify/pb/message.js +94 -10
  91. package/dist/src/identify/pb/message.js.map +1 -1
  92. package/dist/src/index.d.ts +18 -22
  93. package/dist/src/index.d.ts.map +1 -1
  94. package/dist/src/index.js.map +1 -1
  95. package/dist/src/insecure/index.d.ts +2 -2
  96. package/dist/src/insecure/index.d.ts.map +1 -1
  97. package/dist/src/insecure/index.js +8 -4
  98. package/dist/src/insecure/index.js.map +1 -1
  99. package/dist/src/insecure/pb/proto.d.ts +4 -3
  100. package/dist/src/insecure/pb/proto.d.ts.map +1 -1
  101. package/dist/src/insecure/pb/proto.js +89 -9
  102. package/dist/src/insecure/pb/proto.js.map +1 -1
  103. package/dist/src/keychain/index.d.ts +8 -3
  104. package/dist/src/keychain/index.d.ts.map +1 -1
  105. package/dist/src/keychain/index.js +19 -2
  106. package/dist/src/keychain/index.js.map +1 -1
  107. package/dist/src/libp2p.d.ts +14 -19
  108. package/dist/src/libp2p.d.ts.map +1 -1
  109. package/dist/src/libp2p.js +17 -32
  110. package/dist/src/libp2p.js.map +1 -1
  111. package/dist/src/metrics/index.d.ts +4 -5
  112. package/dist/src/metrics/index.d.ts.map +1 -1
  113. package/dist/src/metrics/index.js +9 -6
  114. package/dist/src/metrics/index.js.map +1 -1
  115. package/dist/src/metrics/moving-average.d.ts +1 -1
  116. package/dist/src/metrics/moving-average.d.ts.map +1 -1
  117. package/dist/src/metrics/stats.d.ts +1 -1
  118. package/dist/src/metrics/stats.d.ts.map +1 -1
  119. package/dist/src/nat-manager.d.ts +1 -1
  120. package/dist/src/nat-manager.d.ts.map +1 -1
  121. package/dist/src/peer-record-updater.d.ts +1 -1
  122. package/dist/src/peer-record-updater.d.ts.map +1 -1
  123. package/dist/src/peer-routing.d.ts +4 -4
  124. package/dist/src/peer-routing.d.ts.map +1 -1
  125. package/dist/src/ping/index.d.ts +10 -3
  126. package/dist/src/ping/index.d.ts.map +1 -1
  127. package/dist/src/ping/index.js +32 -9
  128. package/dist/src/ping/index.js.map +1 -1
  129. package/dist/src/pnet/index.d.ts +1 -2
  130. package/dist/src/pnet/index.d.ts.map +1 -1
  131. package/dist/src/pnet/index.js +2 -1
  132. package/dist/src/pnet/index.js.map +1 -1
  133. package/dist/src/pubsub/dummy-pubsub.d.ts +2 -2
  134. package/dist/src/pubsub/dummy-pubsub.d.ts.map +1 -1
  135. package/dist/src/registrar.d.ts +10 -8
  136. package/dist/src/registrar.d.ts.map +1 -1
  137. package/dist/src/registrar.js +63 -44
  138. package/dist/src/registrar.js.map +1 -1
  139. package/dist/src/transport-manager.d.ts +3 -3
  140. package/dist/src/transport-manager.d.ts.map +1 -1
  141. package/dist/src/upgrader.d.ts +12 -6
  142. package/dist/src/upgrader.d.ts.map +1 -1
  143. package/dist/src/upgrader.js +183 -82
  144. package/dist/src/upgrader.js.map +1 -1
  145. package/dist/src/version.d.ts.map +1 -1
  146. package/dist/src/version.js.map +1 -1
  147. package/package.json +66 -42
  148. package/src/address-manager/index.ts +2 -2
  149. package/src/circuit/README.md +2 -2
  150. package/src/circuit/auto-relay.ts +10 -4
  151. package/src/circuit/circuit/hop.ts +20 -11
  152. package/src/circuit/circuit/stop.ts +10 -5
  153. package/src/circuit/circuit/stream-handler.ts +6 -5
  154. package/src/circuit/index.ts +4 -13
  155. package/src/circuit/listener.ts +3 -3
  156. package/src/circuit/pb/index.ts +133 -15
  157. package/src/circuit/transport.ts +92 -63
  158. package/src/config.ts +27 -4
  159. package/src/connection-manager/auto-dialler.ts +1 -1
  160. package/src/connection-manager/dialer/auto-dialer.ts +8 -2
  161. package/src/connection-manager/dialer/dial-request.ts +1 -1
  162. package/src/connection-manager/dialer/index.ts +19 -16
  163. package/src/connection-manager/index.ts +239 -82
  164. package/src/constants.ts +5 -0
  165. package/src/content-routing/index.ts +2 -2
  166. package/src/content-routing/utils.ts +2 -2
  167. package/src/dht/dht-content-routing.ts +2 -2
  168. package/src/dht/dht-peer-routing.ts +3 -3
  169. package/src/dht/dummy-dht.ts +3 -3
  170. package/src/errors.ts +4 -1
  171. package/src/fetch/index.ts +120 -53
  172. package/src/fetch/pb/proto.ts +109 -11
  173. package/src/get-peer.ts +3 -3
  174. package/src/identify/index.ts +64 -47
  175. package/src/identify/pb/message.ts +111 -11
  176. package/src/index.ts +18 -23
  177. package/src/insecure/index.ts +11 -6
  178. package/src/insecure/pb/proto.ts +111 -12
  179. package/src/keychain/index.ts +29 -5
  180. package/src/libp2p.ts +34 -45
  181. package/src/metrics/index.ts +13 -12
  182. package/src/metrics/moving-average.ts +1 -1
  183. package/src/metrics/stats.ts +1 -1
  184. package/src/nat-manager.ts +1 -1
  185. package/src/peer-record-updater.ts +1 -1
  186. package/src/peer-routing.ts +4 -4
  187. package/src/ping/index.ts +48 -15
  188. package/src/pnet/index.ts +3 -2
  189. package/src/pubsub/dummy-pubsub.ts +2 -2
  190. package/src/registrar.ts +79 -55
  191. package/src/transport-manager.ts +3 -3
  192. package/src/upgrader.ts +223 -93
  193. package/src/version.ts +1 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libp2p",
3
- "version": "0.37.3",
3
+ "version": "0.38.0-57ef754",
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",
@@ -49,15 +49,19 @@
49
49
  ],
50
50
  "exports": {
51
51
  ".": {
52
+ "types": "./src/index.d.ts",
52
53
  "import": "./dist/src/index.js"
53
54
  },
54
55
  "./insecure": {
56
+ "types": "./dist/src/insecure/index.d.ts",
55
57
  "import": "./dist/src/insecure/index.js"
56
58
  },
57
59
  "./pnet": {
60
+ "types": "./dist/src/pnet/index.d.ts",
58
61
  "import": "./dist/src/pnet/index.js"
59
62
  },
60
63
  "./transport-manager": {
64
+ "types": "./dist/src/transport-manager.d.ts",
61
65
  "import": "./dist/src/transport-manager.js"
62
66
  }
63
67
  },
@@ -76,6 +80,7 @@
76
80
  "clean": "aegir clean",
77
81
  "lint": "aegir lint",
78
82
  "dep-check": "aegir dep-check",
83
+ "prepublishOnly": "node scripts/update-version.js",
79
84
  "build": "aegir build",
80
85
  "generate": "run-s generate:proto:*",
81
86
  "generate:proto:circuit": "protons ./src/circuit/pb/index.proto",
@@ -93,34 +98,50 @@
93
98
  },
94
99
  "dependencies": {
95
100
  "@achingbrain/nat-port-mapper": "^1.0.3",
96
- "@libp2p/connection": "^2.0.2",
97
- "@libp2p/crypto": "^0.22.11",
98
- "@libp2p/interfaces": "^2.0.2",
99
- "@libp2p/logger": "^1.1.4",
100
- "@libp2p/multistream-select": "^1.0.4",
101
- "@libp2p/peer-collections": "^1.0.2",
102
- "@libp2p/peer-id": "^1.1.10",
103
- "@libp2p/peer-id-factory": "^1.0.9",
104
- "@libp2p/peer-record": "^1.0.8",
105
- "@libp2p/peer-store": "^1.0.10",
106
- "@libp2p/tracked-map": "^1.0.5",
107
- "@libp2p/utils": "^1.0.10",
101
+ "@libp2p/components": "^2.0.3",
102
+ "@libp2p/connection": "^4.0.1",
103
+ "@libp2p/crypto": "^1.0.3",
104
+ "@libp2p/interface-address-manager": "^1.0.2",
105
+ "@libp2p/interface-connection": "^3.0.1",
106
+ "@libp2p/interface-connection-encrypter": "^2.0.1",
107
+ "@libp2p/interface-content-routing": "^1.0.2",
108
+ "@libp2p/interface-dht": "^1.0.1",
109
+ "@libp2p/interface-metrics": "^3.0.0",
110
+ "@libp2p/interface-peer-discovery": "^1.0.1",
111
+ "@libp2p/interface-peer-id": "^1.0.4",
112
+ "@libp2p/interface-peer-info": "^1.0.2",
113
+ "@libp2p/interface-peer-routing": "^1.0.1",
114
+ "@libp2p/interface-peer-store": "^1.2.1",
115
+ "@libp2p/interface-pubsub": "^2.0.1",
116
+ "@libp2p/interface-registrar": "^2.0.3",
117
+ "@libp2p/interface-stream-muxer": "^2.0.2",
118
+ "@libp2p/interface-transport": "^1.0.3",
119
+ "@libp2p/interfaces": "^3.0.3",
120
+ "@libp2p/logger": "^2.0.1",
121
+ "@libp2p/multistream-select": "^3.0.0",
122
+ "@libp2p/peer-collections": "^2.0.0",
123
+ "@libp2p/peer-id": "^1.1.15",
124
+ "@libp2p/peer-id-factory": "^1.0.18",
125
+ "@libp2p/peer-record": "^4.0.2",
126
+ "@libp2p/peer-store": "^3.1.3",
127
+ "@libp2p/tracked-map": "^2.0.1",
128
+ "@libp2p/utils": "^3.0.1",
108
129
  "@multiformats/mafmt": "^11.0.2",
109
- "@multiformats/multiaddr": "^10.1.8",
130
+ "@multiformats/multiaddr": "^10.3.3",
110
131
  "abortable-iterator": "^4.0.2",
111
132
  "any-signal": "^3.0.0",
112
- "datastore-core": "^7.0.0",
133
+ "datastore-core": "^8.0.1",
113
134
  "err-code": "^3.0.1",
114
135
  "events": "^3.3.0",
115
136
  "hashlru": "^2.3.0",
116
- "interface-datastore": "^6.1.0",
137
+ "interface-datastore": "^7.0.0",
117
138
  "it-all": "^1.0.6",
118
139
  "it-drain": "^1.0.5",
119
140
  "it-filter": "^1.0.3",
120
141
  "it-first": "^1.0.6",
121
142
  "it-foreach": "^0.1.1",
122
- "it-handshake": "^3.0.1",
123
- "it-length-prefixed": "^7.0.1",
143
+ "it-handshake": "^4.1.2",
144
+ "it-length-prefixed": "^8.0.2",
124
145
  "it-map": "^1.0.6",
125
146
  "it-merge": "^1.0.3",
126
147
  "it-pair": "^2.0.2",
@@ -130,58 +151,61 @@
130
151
  "merge-options": "^3.0.4",
131
152
  "multiformats": "^9.6.3",
132
153
  "mutable-proxy": "^1.0.0",
133
- "node-forge": "^1.2.1",
154
+ "node-forge": "^1.3.1",
134
155
  "p-fifo": "^1.0.0",
135
156
  "p-retry": "^5.0.0",
136
157
  "p-settle": "^5.0.0",
137
158
  "private-ip": "^2.3.3",
138
- "protons-runtime": "^1.0.4",
159
+ "protons-runtime": "^3.0.1",
139
160
  "retimer": "^3.0.0",
140
161
  "sanitize-filename": "^1.6.3",
141
162
  "set-delayed-interval": "^1.0.0",
142
163
  "timeout-abort-controller": "^3.0.0",
164
+ "uint8arraylist": "^2.3.2",
143
165
  "uint8arrays": "^3.0.0",
144
- "wherearewe": "^1.0.0",
166
+ "wherearewe": "^2.0.0",
145
167
  "xsalsa20": "^1.1.0"
146
168
  },
147
169
  "devDependencies": {
148
- "@chainsafe/libp2p-noise": "^6.2.0",
149
- "@libp2p/bootstrap": "^1.0.4",
150
- "@libp2p/daemon-client": "^1.0.2",
151
- "@libp2p/daemon-server": "^1.0.2",
152
- "@libp2p/delegated-content-routing": "^1.0.5",
153
- "@libp2p/delegated-peer-routing": "^1.0.5",
154
- "@libp2p/floodsub": "^1.0.6",
155
- "@libp2p/interface-compliance-tests": "^2.0.3",
156
- "@libp2p/interop": "^1.0.3",
157
- "@libp2p/kad-dht": "^1.0.9",
158
- "@libp2p/mdns": "^1.0.5",
159
- "@libp2p/mplex": "^1.1.0",
160
- "@libp2p/pubsub": "^1.2.18",
161
- "@libp2p/tcp": "^1.0.9",
162
- "@libp2p/topology": "^1.1.7",
163
- "@libp2p/webrtc-star": "^1.0.8",
164
- "@libp2p/websockets": "^1.0.7",
170
+ "@chainsafe/libp2p-noise": "^8.0.0",
171
+ "@libp2p/bootstrap": "^2.0.0",
172
+ "@libp2p/daemon-client": "^2.0.4",
173
+ "@libp2p/daemon-server": "^2.0.4",
174
+ "@libp2p/delegated-content-routing": "^2.0.1",
175
+ "@libp2p/delegated-peer-routing": "^2.0.1",
176
+ "@libp2p/floodsub": "^3.0.0",
177
+ "@libp2p/interface-compliance-tests": "^3.0.1",
178
+ "@libp2p/interface-connection-encrypter-compliance-tests": "^2.0.1",
179
+ "@libp2p/interface-mocks": "^4.0.1",
180
+ "@libp2p/interop": "^2.0.0",
181
+ "@libp2p/kad-dht": "^3.0.4",
182
+ "@libp2p/mdns": "^3.0.0",
183
+ "@libp2p/mplex": "^5.0.0",
184
+ "@libp2p/pubsub": "^3.0.1",
185
+ "@libp2p/tcp": "^3.0.5",
186
+ "@libp2p/topology": "^3.0.0",
187
+ "@libp2p/webrtc-star": "^3.0.0",
188
+ "@libp2p/websockets": "^3.0.0",
165
189
  "@types/node-forge": "^1.0.0",
166
190
  "@types/p-fifo": "^1.0.0",
167
191
  "@types/varint": "^6.0.0",
168
192
  "@types/xsalsa20": "^1.1.0",
169
- "aegir": "^37.0.9",
193
+ "aegir": "^37.3.0",
170
194
  "cborg": "^1.8.1",
171
195
  "delay": "^5.0.0",
172
196
  "execa": "^6.1.0",
173
197
  "go-libp2p": "^0.0.6",
174
198
  "into-stream": "^7.0.0",
175
199
  "ipfs-http-client": "^57.0.1",
176
- "it-pushable": "^2.0.1",
200
+ "it-pushable": "^3.0.0",
177
201
  "it-to-buffer": "^2.0.2",
178
202
  "nock": "^13.0.3",
179
203
  "npm-run-all": "^4.1.5",
180
204
  "p-defer": "^4.0.0",
181
205
  "p-event": "^5.0.1",
182
206
  "p-times": "^4.0.0",
183
- "p-wait-for": "^4.1.0",
184
- "protons": "^3.0.4",
207
+ "p-wait-for": "^5.0.0",
208
+ "protons": "^5.0.0",
185
209
  "rimraf": "^3.0.2",
186
210
  "sinon": "^14.0.0",
187
211
  "ts-sinon": "^2.0.2"
@@ -1,8 +1,8 @@
1
- import type { AddressManagerEvents } from '@libp2p/interfaces/address-manager'
1
+ import type { AddressManagerEvents } from '@libp2p/interface-address-manager'
2
2
  import { CustomEvent, EventEmitter } from '@libp2p/interfaces/events'
3
3
  import { Multiaddr } from '@multiformats/multiaddr'
4
4
  import { peerIdFromString } from '@libp2p/peer-id'
5
- import type { Components } from '@libp2p/interfaces/components'
5
+ import type { Components } from '@libp2p/components'
6
6
 
7
7
  export interface AddressManagerInit {
8
8
  announceFilter?: AddressFilter
@@ -41,7 +41,7 @@ import { Multiaddr } from '@multiformats/multiaddr'
41
41
  import Libp2p from 'libp2p'
42
42
  import { TCP } from '@libp2p/tcp'
43
43
  import { Mplex } from '@libp2p/mplex'
44
- import { NOISE } from '@chainsafe/libp2p-noise'
44
+ import { Noise } from '@chainsafe/libp2p-noise'
45
45
 
46
46
  const relayAddr = ...
47
47
 
@@ -56,7 +56,7 @@ const node = await createLibp2p({
56
56
  new Mplex()
57
57
  ],
58
58
  connectionEncryption: [
59
- NOISE
59
+ new Noise()
60
60
  ]
61
61
  },
62
62
  config: {
@@ -10,10 +10,10 @@ import {
10
10
  HOP_METADATA_VALUE,
11
11
  RELAY_RENDEZVOUS_NS
12
12
  } from './constants.js'
13
- import type { PeerId } from '@libp2p/interfaces/peer-id'
14
- import type { AddressSorter, PeerProtocolsChangeData } from '@libp2p/interfaces/peer-store'
15
- import type { Connection } from '@libp2p/interfaces/connection'
16
- import type { Components } from '@libp2p/interfaces/components'
13
+ import type { PeerId } from '@libp2p/interface-peer-id'
14
+ import type { AddressSorter, PeerProtocolsChangeData } from '@libp2p/interface-peer-store'
15
+ import type { Connection } from '@libp2p/interface-connection'
16
+ import type { Components } from '@libp2p/components'
17
17
  import sort from 'it-sort'
18
18
  import all from 'it-all'
19
19
  import { pipe } from 'it-pipe'
@@ -260,6 +260,12 @@ export class AutoRelay {
260
260
  }
261
261
 
262
262
  const peerId = provider.id
263
+
264
+ if (peerId.equals(this.components.getPeerId())) {
265
+ // Skip the provider if it's us as dialing will fail
266
+ continue
267
+ }
268
+
263
269
  await this.components.getPeerStore().addressBook.add(peerId, provider.multiaddrs)
264
270
 
265
271
  await this._tryToListenOnRelay(peerId)
@@ -7,11 +7,13 @@ import { pipe } from 'it-pipe'
7
7
  import { codes as Errors } from '../../errors.js'
8
8
  import { stop } from './stop.js'
9
9
  import { RELAY_CODEC } from '../multicodec.js'
10
- import type { Connection } from '@libp2p/interfaces/connection'
10
+ import type { Connection } from '@libp2p/interface-connection'
11
11
  import { peerIdFromBytes } from '@libp2p/peer-id'
12
12
  import type { Duplex } from 'it-stream-types'
13
13
  import type { Circuit } from '../transport.js'
14
- import type { ConnectionManager } from '@libp2p/interfaces/connection-manager'
14
+ import type { ConnectionManager } from '@libp2p/interface-connection-manager'
15
+ import type { AbortOptions } from '@libp2p/interfaces'
16
+ import type { Uint8ArrayList } from 'uint8arraylist'
15
17
 
16
18
  const log = logger('libp2p:circuit:hop')
17
19
 
@@ -23,7 +25,7 @@ export interface HopRequest {
23
25
  connectionManager: ConnectionManager
24
26
  }
25
27
 
26
- export async function handleHop (hopRequest: HopRequest) {
28
+ export async function handleHop (hopRequest: HopRequest): Promise<void> {
27
29
  const {
28
30
  connection,
29
31
  request,
@@ -83,7 +85,7 @@ export async function handleHop (hopRequest: HopRequest) {
83
85
  srcPeer: request.srcPeer
84
86
  }
85
87
 
86
- let destinationStream: Duplex<Uint8Array>
88
+ let destinationStream: Duplex<Uint8ArrayList>
87
89
  try {
88
90
  log('performing STOP request')
89
91
  const result = await stop({
@@ -118,7 +120,7 @@ export async function handleHop (hopRequest: HopRequest) {
118
120
  )
119
121
  }
120
122
 
121
- export interface HopConfig {
123
+ export interface HopConfig extends AbortOptions {
122
124
  connection: Connection
123
125
  request: CircuitPB
124
126
  }
@@ -127,14 +129,17 @@ export interface HopConfig {
127
129
  * Performs a HOP request to a relay peer, to request a connection to another
128
130
  * peer. A new, virtual, connection will be created between the two via the relay.
129
131
  */
130
- export async function hop (options: HopConfig): Promise<Duplex<Uint8Array>> {
132
+ export async function hop (options: HopConfig): Promise<Duplex<Uint8ArrayList, Uint8ArrayList | Uint8Array>> {
131
133
  const {
132
134
  connection,
133
- request
135
+ request,
136
+ signal
134
137
  } = options
135
138
 
136
139
  // Create a new stream to the relay
137
- const { stream } = await connection.newStream(RELAY_CODEC)
140
+ const stream = await connection.newStream(RELAY_CODEC, {
141
+ signal
142
+ })
138
143
  // Send the HOP request
139
144
  const streamHandler = new StreamHandler({ stream })
140
145
  streamHandler.write(request)
@@ -147,6 +152,7 @@ export async function hop (options: HopConfig): Promise<Duplex<Uint8Array>> {
147
152
 
148
153
  if (response.code === CircuitPB.Status.SUCCESS) {
149
154
  log('hop request was successful')
155
+
150
156
  return streamHandler.rest()
151
157
  }
152
158
 
@@ -156,7 +162,7 @@ export async function hop (options: HopConfig): Promise<Duplex<Uint8Array>> {
156
162
  throw errCode(new Error(`HOP request failed with code "${response.code ?? 'unknown'}"`), Errors.ERR_HOP_REQUEST_FAILED)
157
163
  }
158
164
 
159
- export interface CanHopOptions {
165
+ export interface CanHopOptions extends AbortOptions {
160
166
  connection: Connection
161
167
  }
162
168
 
@@ -165,11 +171,14 @@ export interface CanHopOptions {
165
171
  */
166
172
  export async function canHop (options: CanHopOptions) {
167
173
  const {
168
- connection
174
+ connection,
175
+ signal
169
176
  } = options
170
177
 
171
178
  // Create a new stream to the relay
172
- const { stream } = await connection.newStream(RELAY_CODEC)
179
+ const stream = await connection.newStream(RELAY_CODEC, {
180
+ signal
181
+ })
173
182
 
174
183
  // Send the HOP request
175
184
  const streamHandler = new StreamHandler({ stream })
@@ -3,8 +3,10 @@ import { CircuitRelay as CircuitPB } from '../pb/index.js'
3
3
  import { RELAY_CODEC } from '../multicodec.js'
4
4
  import { StreamHandler } from './stream-handler.js'
5
5
  import { validateAddrs } from './utils.js'
6
- import type { Connection } from '@libp2p/interfaces/connection'
6
+ import type { Connection } from '@libp2p/interface-connection'
7
7
  import type { Duplex } from 'it-stream-types'
8
+ import type { AbortOptions } from '@libp2p/interfaces'
9
+ import type { Uint8ArrayList } from 'uint8arraylist'
8
10
 
9
11
  const log = logger('libp2p:circuit:stop')
10
12
 
@@ -17,7 +19,7 @@ export interface HandleStopOptions {
17
19
  /**
18
20
  * Handles incoming STOP requests
19
21
  */
20
- export function handleStop (options: HandleStopOptions): Duplex<Uint8Array> | undefined {
22
+ export function handleStop (options: HandleStopOptions): Duplex<Uint8ArrayList, Uint8ArrayList | Uint8Array> | undefined {
21
23
  const {
22
24
  connection,
23
25
  request,
@@ -42,7 +44,7 @@ export function handleStop (options: HandleStopOptions): Duplex<Uint8Array> | un
42
44
  return streamHandler.rest()
43
45
  }
44
46
 
45
- export interface StopOptions {
47
+ export interface StopOptions extends AbortOptions {
46
48
  connection: Connection
47
49
  request: CircuitPB
48
50
  }
@@ -53,10 +55,13 @@ export interface StopOptions {
53
55
  export async function stop (options: StopOptions) {
54
56
  const {
55
57
  connection,
56
- request
58
+ request,
59
+ signal
57
60
  } = options
58
61
 
59
- const { stream } = await connection.newStream([RELAY_CODEC])
62
+ const stream = await connection.newStream(RELAY_CODEC, {
63
+ signal
64
+ })
60
65
  log('starting stop request to %p', connection.remotePeer)
61
66
  const streamHandler = new StreamHandler({ stream })
62
67
 
@@ -2,8 +2,9 @@ import { logger } from '@libp2p/logger'
2
2
  import * as lp from 'it-length-prefixed'
3
3
  import { Handshake, handshake } from 'it-handshake'
4
4
  import { CircuitRelay } from '../pb/index.js'
5
- import type { Stream } from '@libp2p/interfaces/connection'
5
+ import type { Stream } from '@libp2p/interface-connection'
6
6
  import type { Source } from 'it-stream-types'
7
+ import type { Uint8ArrayList } from 'uint8arraylist'
7
8
 
8
9
  const log = logger('libp2p:circuit:stream-handler')
9
10
 
@@ -21,8 +22,8 @@ export interface StreamHandlerOptions {
21
22
 
22
23
  export class StreamHandler {
23
24
  private readonly stream: Stream
24
- private readonly shake: Handshake
25
- private readonly decoder: Source<Uint8Array>
25
+ private readonly shake: Handshake<Uint8ArrayList | Uint8Array>
26
+ private readonly decoder: Source<Uint8ArrayList>
26
27
 
27
28
  constructor (options: StreamHandlerOptions) {
28
29
  const { stream, maxLength = 4096 } = options
@@ -40,7 +41,7 @@ export class StreamHandler {
40
41
  const msg = await this.decoder.next()
41
42
 
42
43
  if (msg.value != null) {
43
- const value = CircuitRelay.decode(msg.value.slice())
44
+ const value = CircuitRelay.decode(msg.value)
44
45
  log('read message type', value.type)
45
46
  return value
46
47
  }
@@ -55,7 +56,7 @@ export class StreamHandler {
55
56
  */
56
57
  write (msg: CircuitRelay) {
57
58
  log('write message type %s', msg.type)
58
- this.shake.write(lp.encode.single(CircuitRelay.encode(msg)).slice())
59
+ this.shake.write(lp.encode.single(CircuitRelay.encode(msg)))
59
60
  }
60
61
 
61
62
  /**
@@ -10,9 +10,10 @@ import { namespaceToCid } from './utils.js'
10
10
  import {
11
11
  RELAY_RENDEZVOUS_NS
12
12
  } from './constants.js'
13
- import type { AddressSorter } from '@libp2p/interfaces/peer-store'
13
+ import type { AddressSorter } from '@libp2p/interface-peer-store'
14
14
  import type { Startable } from '@libp2p/interfaces/startable'
15
- import type { Components } from '@libp2p/interfaces/components'
15
+ import type { Components } from '@libp2p/components'
16
+ import type { RelayConfig } from '../index.js'
16
17
 
17
18
  const log = logger('libp2p:relay')
18
19
 
@@ -22,11 +23,6 @@ export interface RelayAdvertiseConfig {
22
23
  ttl?: number
23
24
  }
24
25
 
25
- export interface HopConfig {
26
- enabled?: boolean
27
- active?: boolean
28
- }
29
-
30
26
  export interface AutoRelayConfig {
31
27
  enabled?: boolean
32
28
 
@@ -36,13 +32,8 @@ export interface AutoRelayConfig {
36
32
  maxListeners: number
37
33
  }
38
34
 
39
- export interface RelayInit {
35
+ export interface RelayInit extends RelayConfig {
40
36
  addressSorter?: AddressSorter
41
- maxListeners?: number
42
- onError?: (error: Error, msg?: string) => void
43
- hop: HopConfig
44
- advertise: RelayAdvertiseConfig
45
- autoRelay: AutoRelayConfig
46
37
  }
47
38
 
48
39
  export class Relay implements Startable {
@@ -1,7 +1,7 @@
1
1
  import { CustomEvent, EventEmitter } from '@libp2p/interfaces/events'
2
- import type { ConnectionManager } from '@libp2p/interfaces/connection-manager'
3
- import type { PeerStore } from '@libp2p/interfaces/peer-store'
4
- import type { Listener } from '@libp2p/interfaces/transport'
2
+ import type { ConnectionManager } from '@libp2p/interface-connection-manager'
3
+ import type { PeerStore } from '@libp2p/interface-peer-store'
4
+ import type { Listener } from '@libp2p/interface-transport'
5
5
  import { peerIdFromString } from '@libp2p/peer-id'
6
6
  import { Multiaddr } from '@multiformats/multiaddr'
7
7