libp2p 0.37.3 → 0.38.0

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 (189) hide show
  1. package/README.md +1 -2
  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/circuit/hop.d.ts +7 -5
  7. package/dist/src/circuit/circuit/hop.d.ts.map +1 -1
  8. package/dist/src/circuit/circuit/hop.js +8 -4
  9. package/dist/src/circuit/circuit/hop.js.map +1 -1
  10. package/dist/src/circuit/circuit/stop.d.ts +6 -4
  11. package/dist/src/circuit/circuit/stop.d.ts.map +1 -1
  12. package/dist/src/circuit/circuit/stop.js +4 -2
  13. package/dist/src/circuit/circuit/stop.js.map +1 -1
  14. package/dist/src/circuit/circuit/stream-handler.d.ts +3 -2
  15. package/dist/src/circuit/circuit/stream-handler.d.ts.map +1 -1
  16. package/dist/src/circuit/circuit/stream-handler.js +2 -2
  17. package/dist/src/circuit/circuit/stream-handler.js.map +1 -1
  18. package/dist/src/circuit/index.d.ts +4 -12
  19. package/dist/src/circuit/index.d.ts.map +1 -1
  20. package/dist/src/circuit/index.js.map +1 -1
  21. package/dist/src/circuit/listener.d.ts +3 -3
  22. package/dist/src/circuit/listener.d.ts.map +1 -1
  23. package/dist/src/circuit/pb/index.d.ts +5 -4
  24. package/dist/src/circuit/pb/index.d.ts.map +1 -1
  25. package/dist/src/circuit/pb/index.js +107 -11
  26. package/dist/src/circuit/pb/index.js.map +1 -1
  27. package/dist/src/circuit/transport.d.ts +8 -5
  28. package/dist/src/circuit/transport.d.ts.map +1 -1
  29. package/dist/src/circuit/transport.js +81 -59
  30. package/dist/src/circuit/transport.js.map +1 -1
  31. package/dist/src/config.d.ts.map +1 -1
  32. package/dist/src/config.js +27 -4
  33. package/dist/src/config.js.map +1 -1
  34. package/dist/src/connection-manager/auto-dialler.d.ts +1 -1
  35. package/dist/src/connection-manager/auto-dialler.d.ts.map +1 -1
  36. package/dist/src/connection-manager/dialer/auto-dialer.d.ts +2 -2
  37. package/dist/src/connection-manager/dialer/auto-dialer.d.ts.map +1 -1
  38. package/dist/src/connection-manager/dialer/auto-dialer.js +6 -0
  39. package/dist/src/connection-manager/dialer/auto-dialer.js.map +1 -1
  40. package/dist/src/connection-manager/dialer/dial-request.d.ts +1 -1
  41. package/dist/src/connection-manager/dialer/dial-request.d.ts.map +1 -1
  42. package/dist/src/connection-manager/dialer/index.d.ts +9 -9
  43. package/dist/src/connection-manager/dialer/index.d.ts.map +1 -1
  44. package/dist/src/connection-manager/dialer/index.js +11 -11
  45. package/dist/src/connection-manager/dialer/index.js.map +1 -1
  46. package/dist/src/connection-manager/index.d.ts +20 -16
  47. package/dist/src/connection-manager/index.d.ts.map +1 -1
  48. package/dist/src/connection-manager/index.js +185 -65
  49. package/dist/src/connection-manager/index.js.map +1 -1
  50. package/dist/src/constants.d.ts +4 -0
  51. package/dist/src/constants.d.ts.map +1 -1
  52. package/dist/src/constants.js +4 -0
  53. package/dist/src/constants.js.map +1 -1
  54. package/dist/src/content-routing/index.d.ts +4 -4
  55. package/dist/src/content-routing/index.d.ts.map +1 -1
  56. package/dist/src/content-routing/utils.d.ts +2 -2
  57. package/dist/src/content-routing/utils.d.ts.map +1 -1
  58. package/dist/src/dht/dht-content-routing.d.ts +3 -3
  59. package/dist/src/dht/dht-content-routing.d.ts.map +1 -1
  60. package/dist/src/dht/dht-peer-routing.d.ts +5 -5
  61. package/dist/src/dht/dht-peer-routing.d.ts.map +1 -1
  62. package/dist/src/dht/dummy-dht.d.ts +3 -3
  63. package/dist/src/dht/dummy-dht.d.ts.map +1 -1
  64. package/dist/src/dht/dummy-dht.js +1 -1
  65. package/dist/src/dht/dummy-dht.js.map +1 -1
  66. package/dist/src/errors.d.ts +4 -1
  67. package/dist/src/errors.d.ts.map +1 -1
  68. package/dist/src/errors.js +3 -0
  69. package/dist/src/errors.js.map +1 -1
  70. package/dist/src/fetch/index.d.ts +11 -4
  71. package/dist/src/fetch/index.d.ts.map +1 -1
  72. package/dist/src/fetch/index.js +82 -41
  73. package/dist/src/fetch/index.js.map +1 -1
  74. package/dist/src/fetch/pb/proto.d.ts +4 -3
  75. package/dist/src/fetch/pb/proto.d.ts.map +1 -1
  76. package/dist/src/fetch/pb/proto.js +88 -8
  77. package/dist/src/fetch/pb/proto.js.map +1 -1
  78. package/dist/src/get-peer.d.ts +2 -2
  79. package/dist/src/get-peer.d.ts.map +1 -1
  80. package/dist/src/get-peer.js +1 -1
  81. package/dist/src/get-peer.js.map +1 -1
  82. package/dist/src/identify/index.d.ts +8 -8
  83. package/dist/src/identify/index.d.ts.map +1 -1
  84. package/dist/src/identify/index.js +49 -34
  85. package/dist/src/identify/index.js.map +1 -1
  86. package/dist/src/identify/pb/message.d.ts +2 -1
  87. package/dist/src/identify/pb/message.d.ts.map +1 -1
  88. package/dist/src/identify/pb/message.js +94 -10
  89. package/dist/src/identify/pb/message.js.map +1 -1
  90. package/dist/src/index.d.ts +18 -17
  91. package/dist/src/index.d.ts.map +1 -1
  92. package/dist/src/index.js.map +1 -1
  93. package/dist/src/insecure/index.d.ts +2 -2
  94. package/dist/src/insecure/index.d.ts.map +1 -1
  95. package/dist/src/insecure/index.js +8 -4
  96. package/dist/src/insecure/index.js.map +1 -1
  97. package/dist/src/insecure/pb/proto.d.ts +4 -3
  98. package/dist/src/insecure/pb/proto.d.ts.map +1 -1
  99. package/dist/src/insecure/pb/proto.js +89 -9
  100. package/dist/src/insecure/pb/proto.js.map +1 -1
  101. package/dist/src/keychain/index.d.ts +2 -2
  102. package/dist/src/keychain/index.d.ts.map +1 -1
  103. package/dist/src/libp2p.d.ts +14 -14
  104. package/dist/src/libp2p.d.ts.map +1 -1
  105. package/dist/src/libp2p.js +17 -17
  106. package/dist/src/libp2p.js.map +1 -1
  107. package/dist/src/metrics/index.d.ts +4 -5
  108. package/dist/src/metrics/index.d.ts.map +1 -1
  109. package/dist/src/metrics/index.js +9 -6
  110. package/dist/src/metrics/index.js.map +1 -1
  111. package/dist/src/metrics/moving-average.d.ts +1 -1
  112. package/dist/src/metrics/moving-average.d.ts.map +1 -1
  113. package/dist/src/metrics/stats.d.ts +1 -1
  114. package/dist/src/metrics/stats.d.ts.map +1 -1
  115. package/dist/src/nat-manager.d.ts +1 -1
  116. package/dist/src/nat-manager.d.ts.map +1 -1
  117. package/dist/src/peer-record-updater.d.ts +1 -1
  118. package/dist/src/peer-record-updater.d.ts.map +1 -1
  119. package/dist/src/peer-routing.d.ts +4 -4
  120. package/dist/src/peer-routing.d.ts.map +1 -1
  121. package/dist/src/ping/index.d.ts +10 -3
  122. package/dist/src/ping/index.d.ts.map +1 -1
  123. package/dist/src/ping/index.js +32 -9
  124. package/dist/src/ping/index.js.map +1 -1
  125. package/dist/src/pnet/index.d.ts +1 -2
  126. package/dist/src/pnet/index.d.ts.map +1 -1
  127. package/dist/src/pnet/index.js +2 -1
  128. package/dist/src/pnet/index.js.map +1 -1
  129. package/dist/src/pubsub/dummy-pubsub.d.ts +2 -2
  130. package/dist/src/pubsub/dummy-pubsub.d.ts.map +1 -1
  131. package/dist/src/registrar.d.ts +10 -8
  132. package/dist/src/registrar.d.ts.map +1 -1
  133. package/dist/src/registrar.js +63 -44
  134. package/dist/src/registrar.js.map +1 -1
  135. package/dist/src/transport-manager.d.ts +3 -3
  136. package/dist/src/transport-manager.d.ts.map +1 -1
  137. package/dist/src/upgrader.d.ts +12 -6
  138. package/dist/src/upgrader.d.ts.map +1 -1
  139. package/dist/src/upgrader.js +183 -82
  140. package/dist/src/upgrader.js.map +1 -1
  141. package/dist/src/version.d.ts.map +1 -1
  142. package/dist/src/version.js.map +1 -1
  143. package/package.json +66 -42
  144. package/src/address-manager/index.ts +2 -2
  145. package/src/circuit/README.md +2 -2
  146. package/src/circuit/auto-relay.ts +4 -4
  147. package/src/circuit/circuit/hop.ts +20 -11
  148. package/src/circuit/circuit/stop.ts +10 -5
  149. package/src/circuit/circuit/stream-handler.ts +6 -5
  150. package/src/circuit/index.ts +4 -13
  151. package/src/circuit/listener.ts +3 -3
  152. package/src/circuit/pb/index.ts +133 -15
  153. package/src/circuit/transport.ts +92 -63
  154. package/src/config.ts +27 -4
  155. package/src/connection-manager/auto-dialler.ts +1 -1
  156. package/src/connection-manager/dialer/auto-dialer.ts +8 -2
  157. package/src/connection-manager/dialer/dial-request.ts +1 -1
  158. package/src/connection-manager/dialer/index.ts +15 -15
  159. package/src/connection-manager/index.ts +239 -82
  160. package/src/constants.ts +5 -0
  161. package/src/content-routing/index.ts +2 -2
  162. package/src/content-routing/utils.ts +2 -2
  163. package/src/dht/dht-content-routing.ts +2 -2
  164. package/src/dht/dht-peer-routing.ts +3 -3
  165. package/src/dht/dummy-dht.ts +3 -3
  166. package/src/errors.ts +4 -1
  167. package/src/fetch/index.ts +120 -53
  168. package/src/fetch/pb/proto.ts +109 -11
  169. package/src/get-peer.ts +3 -3
  170. package/src/identify/index.ts +64 -47
  171. package/src/identify/pb/message.ts +111 -11
  172. package/src/index.ts +18 -17
  173. package/src/insecure/index.ts +11 -6
  174. package/src/insecure/pb/proto.ts +111 -12
  175. package/src/keychain/index.ts +2 -2
  176. package/src/libp2p.ts +34 -29
  177. package/src/metrics/index.ts +13 -12
  178. package/src/metrics/moving-average.ts +1 -1
  179. package/src/metrics/stats.ts +1 -1
  180. package/src/nat-manager.ts +1 -1
  181. package/src/peer-record-updater.ts +1 -1
  182. package/src/peer-routing.ts +4 -4
  183. package/src/ping/index.ts +48 -15
  184. package/src/pnet/index.ts +3 -2
  185. package/src/pubsub/dummy-pubsub.ts +2 -2
  186. package/src/registrar.ts +79 -55
  187. package/src/transport-manager.ts +3 -3
  188. package/src/upgrader.ts +223 -93
  189. 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",
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.0",
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'
@@ -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
 
@@ -1,7 +1,8 @@
1
1
  /* eslint-disable import/export */
2
2
  /* eslint-disable @typescript-eslint/no-namespace */
3
3
 
4
- import { enumeration, encodeMessage, decodeMessage, message, bytes } from 'protons-runtime'
4
+ import { enumeration, encodeMessage, decodeMessage, message } from 'protons-runtime'
5
+ import type { Uint8ArrayList } from 'uint8arraylist'
5
6
  import type { Codec } from 'protons-runtime'
6
7
 
7
8
  export interface CircuitRelay {
@@ -52,7 +53,7 @@ export namespace CircuitRelay {
52
53
 
53
54
  export namespace Status {
54
55
  export const codec = () => {
55
- return enumeration<typeof Status>(__StatusValues)
56
+ return enumeration<Status>(__StatusValues)
56
57
  }
57
58
  }
58
59
 
@@ -72,7 +73,7 @@ export namespace CircuitRelay {
72
73
 
73
74
  export namespace Type {
74
75
  export const codec = () => {
75
- return enumeration<typeof Type>(__TypeValues)
76
+ return enumeration<Type>(__TypeValues)
76
77
  }
77
78
  }
78
79
 
@@ -82,36 +83,153 @@ export namespace CircuitRelay {
82
83
  }
83
84
 
84
85
  export namespace Peer {
86
+ let _codec: Codec<Peer>
87
+
85
88
  export const codec = (): Codec<Peer> => {
86
- return message<Peer>({
87
- 1: { name: 'id', codec: bytes },
88
- 2: { name: 'addrs', codec: bytes, repeats: true }
89
- })
89
+ if (_codec == null) {
90
+ _codec = message<Peer>((obj, writer, opts = {}) => {
91
+ if (opts.lengthDelimited !== false) {
92
+ writer.fork()
93
+ }
94
+
95
+ if (obj.id != null) {
96
+ writer.uint32(10)
97
+ writer.bytes(obj.id)
98
+ } else {
99
+ throw new Error('Protocol error: required field "id" was not found in object')
100
+ }
101
+
102
+ if (obj.addrs != null) {
103
+ for (const value of obj.addrs) {
104
+ writer.uint32(18)
105
+ writer.bytes(value)
106
+ }
107
+ } else {
108
+ throw new Error('Protocol error: required field "addrs" was not found in object')
109
+ }
110
+
111
+ if (opts.lengthDelimited !== false) {
112
+ writer.ldelim()
113
+ }
114
+ }, (reader, length) => {
115
+ const obj: any = {}
116
+
117
+ const end = length == null ? reader.len : reader.pos + length
118
+
119
+ while (reader.pos < end) {
120
+ const tag = reader.uint32()
121
+
122
+ switch (tag >>> 3) {
123
+ case 1:
124
+ obj.id = reader.bytes()
125
+ break
126
+ case 2:
127
+ obj.addrs = obj.addrs ?? []
128
+ obj.addrs.push(reader.bytes())
129
+ break
130
+ default:
131
+ reader.skipType(tag & 7)
132
+ break
133
+ }
134
+ }
135
+
136
+ obj.addrs = obj.addrs ?? []
137
+
138
+ if (obj.id == null) {
139
+ throw new Error('Protocol error: value for required field "id" was not found in protobuf')
140
+ }
141
+
142
+ if (obj.addrs == null) {
143
+ throw new Error('Protocol error: value for required field "addrs" was not found in protobuf')
144
+ }
145
+
146
+ return obj
147
+ })
148
+ }
149
+
150
+ return _codec
90
151
  }
91
152
 
92
153
  export const encode = (obj: Peer): Uint8Array => {
93
154
  return encodeMessage(obj, Peer.codec())
94
155
  }
95
156
 
96
- export const decode = (buf: Uint8Array): Peer => {
157
+ export const decode = (buf: Uint8Array | Uint8ArrayList): Peer => {
97
158
  return decodeMessage(buf, Peer.codec())
98
159
  }
99
160
  }
100
161
 
162
+ let _codec: Codec<CircuitRelay>
163
+
101
164
  export const codec = (): Codec<CircuitRelay> => {
102
- return message<CircuitRelay>({
103
- 1: { name: 'type', codec: CircuitRelay.Type.codec(), optional: true },
104
- 2: { name: 'srcPeer', codec: CircuitRelay.Peer.codec(), optional: true },
105
- 3: { name: 'dstPeer', codec: CircuitRelay.Peer.codec(), optional: true },
106
- 4: { name: 'code', codec: CircuitRelay.Status.codec(), optional: true }
107
- })
165
+ if (_codec == null) {
166
+ _codec = message<CircuitRelay>((obj, writer, opts = {}) => {
167
+ if (opts.lengthDelimited !== false) {
168
+ writer.fork()
169
+ }
170
+
171
+ if (obj.type != null) {
172
+ writer.uint32(8)
173
+ CircuitRelay.Type.codec().encode(obj.type, writer)
174
+ }
175
+
176
+ if (obj.srcPeer != null) {
177
+ writer.uint32(18)
178
+ CircuitRelay.Peer.codec().encode(obj.srcPeer, writer)
179
+ }
180
+
181
+ if (obj.dstPeer != null) {
182
+ writer.uint32(26)
183
+ CircuitRelay.Peer.codec().encode(obj.dstPeer, writer)
184
+ }
185
+
186
+ if (obj.code != null) {
187
+ writer.uint32(32)
188
+ CircuitRelay.Status.codec().encode(obj.code, writer)
189
+ }
190
+
191
+ if (opts.lengthDelimited !== false) {
192
+ writer.ldelim()
193
+ }
194
+ }, (reader, length) => {
195
+ const obj: any = {}
196
+
197
+ const end = length == null ? reader.len : reader.pos + length
198
+
199
+ while (reader.pos < end) {
200
+ const tag = reader.uint32()
201
+
202
+ switch (tag >>> 3) {
203
+ case 1:
204
+ obj.type = CircuitRelay.Type.codec().decode(reader)
205
+ break
206
+ case 2:
207
+ obj.srcPeer = CircuitRelay.Peer.codec().decode(reader, reader.uint32())
208
+ break
209
+ case 3:
210
+ obj.dstPeer = CircuitRelay.Peer.codec().decode(reader, reader.uint32())
211
+ break
212
+ case 4:
213
+ obj.code = CircuitRelay.Status.codec().decode(reader)
214
+ break
215
+ default:
216
+ reader.skipType(tag & 7)
217
+ break
218
+ }
219
+ }
220
+
221
+ return obj
222
+ })
223
+ }
224
+
225
+ return _codec
108
226
  }
109
227
 
110
228
  export const encode = (obj: CircuitRelay): Uint8Array => {
111
229
  return encodeMessage(obj, CircuitRelay.codec())
112
230
  }
113
231
 
114
- export const decode = (buf: Uint8Array): CircuitRelay => {
232
+ export const decode = (buf: Uint8Array | Uint8ArrayList): CircuitRelay => {
115
233
  return decodeMessage(buf, CircuitRelay.codec())
116
234
  }
117
235
  }