libp2p 0.46.21 → 1.0.0-7682861f9

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 (301) hide show
  1. package/README.md +51 -47
  2. package/dist/index.min.js +40 -28
  3. package/dist/src/address-manager/index.d.ts +4 -5
  4. package/dist/src/address-manager/index.d.ts.map +1 -1
  5. package/dist/src/address-manager/index.js +3 -3
  6. package/dist/src/address-manager/index.js.map +1 -1
  7. package/dist/src/components.d.ts +4 -15
  8. package/dist/src/components.d.ts.map +1 -1
  9. package/dist/src/components.js +2 -2
  10. package/dist/src/components.js.map +1 -1
  11. package/dist/src/config/connection-gater.browser.d.ts +1 -1
  12. package/dist/src/config/connection-gater.browser.d.ts.map +1 -1
  13. package/dist/src/config/connection-gater.browser.js.map +1 -1
  14. package/dist/src/config/connection-gater.d.ts +1 -1
  15. package/dist/src/config/connection-gater.d.ts.map +1 -1
  16. package/dist/src/config.d.ts.map +1 -1
  17. package/dist/src/config.js +1 -2
  18. package/dist/src/config.js.map +1 -1
  19. package/dist/src/connection/index.d.ts +4 -6
  20. package/dist/src/connection/index.d.ts.map +1 -1
  21. package/dist/src/connection/index.js +11 -13
  22. package/dist/src/connection/index.js.map +1 -1
  23. package/dist/src/connection-manager/auto-dial.d.ts +3 -6
  24. package/dist/src/connection-manager/auto-dial.d.ts.map +1 -1
  25. package/dist/src/connection-manager/auto-dial.js +21 -21
  26. package/dist/src/connection-manager/auto-dial.js.map +1 -1
  27. package/dist/src/connection-manager/connection-pruner.d.ts +3 -5
  28. package/dist/src/connection-manager/connection-pruner.d.ts.map +1 -1
  29. package/dist/src/connection-manager/connection-pruner.js +8 -8
  30. package/dist/src/connection-manager/connection-pruner.js.map +1 -1
  31. package/dist/src/connection-manager/constants.defaults.d.ts +0 -4
  32. package/dist/src/connection-manager/constants.defaults.d.ts.map +1 -1
  33. package/dist/src/connection-manager/constants.defaults.js +0 -4
  34. package/dist/src/connection-manager/constants.defaults.js.map +1 -1
  35. package/dist/src/connection-manager/dial-queue.d.ts +3 -10
  36. package/dist/src/connection-manager/dial-queue.d.ts.map +1 -1
  37. package/dist/src/connection-manager/dial-queue.js +30 -38
  38. package/dist/src/connection-manager/dial-queue.js.map +1 -1
  39. package/dist/src/connection-manager/index.d.ts +3 -18
  40. package/dist/src/connection-manager/index.d.ts.map +1 -1
  41. package/dist/src/connection-manager/index.js +17 -18
  42. package/dist/src/connection-manager/index.js.map +1 -1
  43. package/dist/src/connection-manager/utils.js +1 -1
  44. package/dist/src/connection-manager/utils.js.map +1 -1
  45. package/dist/src/content-routing/index.d.ts +1 -5
  46. package/dist/src/content-routing/index.d.ts.map +1 -1
  47. package/dist/src/content-routing/index.js +2 -2
  48. package/dist/src/content-routing/index.js.map +1 -1
  49. package/dist/src/content-routing/utils.d.ts +1 -2
  50. package/dist/src/content-routing/utils.d.ts.map +1 -1
  51. package/dist/src/content-routing/utils.js +1 -1
  52. package/dist/src/content-routing/utils.js.map +1 -1
  53. package/dist/src/errors.d.ts +0 -2
  54. package/dist/src/errors.d.ts.map +1 -1
  55. package/dist/src/errors.js +0 -2
  56. package/dist/src/errors.js.map +1 -1
  57. package/dist/src/get-peer.d.ts +1 -1
  58. package/dist/src/get-peer.d.ts.map +1 -1
  59. package/dist/src/get-peer.js +1 -5
  60. package/dist/src/get-peer.js.map +1 -1
  61. package/dist/src/index.d.ts +5 -16
  62. package/dist/src/index.d.ts.map +1 -1
  63. package/dist/src/index.js.map +1 -1
  64. package/dist/src/libp2p.d.ts +4 -12
  65. package/dist/src/libp2p.d.ts.map +1 -1
  66. package/dist/src/libp2p.js +31 -65
  67. package/dist/src/libp2p.js.map +1 -1
  68. package/dist/src/peer-routing.d.ts +6 -6
  69. package/dist/src/peer-routing.d.ts.map +1 -1
  70. package/dist/src/peer-routing.js +12 -9
  71. package/dist/src/peer-routing.js.map +1 -1
  72. package/dist/src/registrar.d.ts +5 -7
  73. package/dist/src/registrar.d.ts.map +1 -1
  74. package/dist/src/registrar.js +4 -4
  75. package/dist/src/registrar.js.map +1 -1
  76. package/dist/src/transport-manager.d.ts +5 -9
  77. package/dist/src/transport-manager.d.ts.map +1 -1
  78. package/dist/src/transport-manager.js +12 -13
  79. package/dist/src/transport-manager.js.map +1 -1
  80. package/dist/src/upgrader.d.ts +8 -19
  81. package/dist/src/upgrader.d.ts.map +1 -1
  82. package/dist/src/upgrader.js +75 -38
  83. package/dist/src/upgrader.js.map +1 -1
  84. package/dist/src/version.d.ts +1 -1
  85. package/dist/src/version.d.ts.map +1 -1
  86. package/dist/src/version.js +1 -1
  87. package/dist/src/version.js.map +1 -1
  88. package/package.json +37 -106
  89. package/src/address-manager/index.ts +6 -9
  90. package/src/components.ts +5 -16
  91. package/src/config/connection-gater.browser.ts +1 -1
  92. package/src/config/connection-gater.ts +1 -1
  93. package/src/config.ts +1 -2
  94. package/src/connection/index.ts +12 -17
  95. package/src/connection-manager/auto-dial.ts +23 -26
  96. package/src/connection-manager/connection-pruner.ts +10 -12
  97. package/src/connection-manager/constants.defaults.ts +0 -5
  98. package/src/connection-manager/dial-queue.ts +31 -46
  99. package/src/connection-manager/index.ts +19 -36
  100. package/src/connection-manager/utils.ts +1 -1
  101. package/src/content-routing/index.ts +3 -7
  102. package/src/content-routing/utils.ts +2 -3
  103. package/src/errors.ts +0 -2
  104. package/src/get-peer.ts +2 -7
  105. package/src/index.ts +6 -17
  106. package/src/libp2p.ts +32 -80
  107. package/src/peer-routing.ts +16 -15
  108. package/src/registrar.ts +8 -12
  109. package/src/transport-manager.ts +15 -22
  110. package/src/upgrader.ts +110 -64
  111. package/src/version.ts +1 -1
  112. package/dist/src/autonat/constants.d.ts +0 -18
  113. package/dist/src/autonat/constants.d.ts.map +0 -1
  114. package/dist/src/autonat/constants.js +0 -18
  115. package/dist/src/autonat/constants.js.map +0 -1
  116. package/dist/src/autonat/index.d.ts +0 -62
  117. package/dist/src/autonat/index.d.ts.map +0 -1
  118. package/dist/src/autonat/index.js +0 -447
  119. package/dist/src/autonat/index.js.map +0 -1
  120. package/dist/src/autonat/pb/index.d.ts +0 -57
  121. package/dist/src/autonat/pb/index.d.ts.map +0 -1
  122. package/dist/src/autonat/pb/index.js +0 -250
  123. package/dist/src/autonat/pb/index.js.map +0 -1
  124. package/dist/src/circuit-relay/constants.d.ts +0 -50
  125. package/dist/src/circuit-relay/constants.d.ts.map +0 -1
  126. package/dist/src/circuit-relay/constants.js +0 -56
  127. package/dist/src/circuit-relay/constants.js.map +0 -1
  128. package/dist/src/circuit-relay/index.d.ts +0 -55
  129. package/dist/src/circuit-relay/index.d.ts.map +0 -1
  130. package/dist/src/circuit-relay/index.js +0 -38
  131. package/dist/src/circuit-relay/index.js.map +0 -1
  132. package/dist/src/circuit-relay/pb/index.d.ts +0 -93
  133. package/dist/src/circuit-relay/pb/index.d.ts.map +0 -1
  134. package/dist/src/circuit-relay/pb/index.js +0 -425
  135. package/dist/src/circuit-relay/pb/index.js.map +0 -1
  136. package/dist/src/circuit-relay/server/advert-service.d.ts +0 -43
  137. package/dist/src/circuit-relay/server/advert-service.d.ts.map +0 -1
  138. package/dist/src/circuit-relay/server/advert-service.js +0 -73
  139. package/dist/src/circuit-relay/server/advert-service.js.map +0 -1
  140. package/dist/src/circuit-relay/server/index.d.ts +0 -65
  141. package/dist/src/circuit-relay/server/index.d.ts.map +0 -1
  142. package/dist/src/circuit-relay/server/index.js +0 -312
  143. package/dist/src/circuit-relay/server/index.js.map +0 -1
  144. package/dist/src/circuit-relay/server/reservation-store.d.ts +0 -49
  145. package/dist/src/circuit-relay/server/reservation-store.d.ts.map +0 -1
  146. package/dist/src/circuit-relay/server/reservation-store.js +0 -65
  147. package/dist/src/circuit-relay/server/reservation-store.js.map +0 -1
  148. package/dist/src/circuit-relay/server/reservation-voucher.d.ts +0 -18
  149. package/dist/src/circuit-relay/server/reservation-voucher.d.ts.map +0 -1
  150. package/dist/src/circuit-relay/server/reservation-voucher.js +0 -36
  151. package/dist/src/circuit-relay/server/reservation-voucher.js.map +0 -1
  152. package/dist/src/circuit-relay/transport/discovery.d.ts +0 -45
  153. package/dist/src/circuit-relay/transport/discovery.d.ts.map +0 -1
  154. package/dist/src/circuit-relay/transport/discovery.js +0 -97
  155. package/dist/src/circuit-relay/transport/discovery.js.map +0 -1
  156. package/dist/src/circuit-relay/transport/index.d.ts +0 -57
  157. package/dist/src/circuit-relay/transport/index.d.ts.map +0 -1
  158. package/dist/src/circuit-relay/transport/index.js +0 -276
  159. package/dist/src/circuit-relay/transport/index.js.map +0 -1
  160. package/dist/src/circuit-relay/transport/listener.d.ts +0 -9
  161. package/dist/src/circuit-relay/transport/listener.d.ts.map +0 -1
  162. package/dist/src/circuit-relay/transport/listener.js +0 -66
  163. package/dist/src/circuit-relay/transport/listener.js.map +0 -1
  164. package/dist/src/circuit-relay/transport/reservation-store.d.ts +0 -72
  165. package/dist/src/circuit-relay/transport/reservation-store.d.ts.map +0 -1
  166. package/dist/src/circuit-relay/transport/reservation-store.js +0 -209
  167. package/dist/src/circuit-relay/transport/reservation-store.js.map +0 -1
  168. package/dist/src/circuit-relay/utils.d.ts +0 -13
  169. package/dist/src/circuit-relay/utils.d.ts.map +0 -1
  170. package/dist/src/circuit-relay/utils.js +0 -108
  171. package/dist/src/circuit-relay/utils.js.map +0 -1
  172. package/dist/src/dcutr/dcutr.d.ts +0 -43
  173. package/dist/src/dcutr/dcutr.d.ts.map +0 -1
  174. package/dist/src/dcutr/dcutr.js +0 -313
  175. package/dist/src/dcutr/dcutr.js.map +0 -1
  176. package/dist/src/dcutr/index.d.ts +0 -92
  177. package/dist/src/dcutr/index.d.ts.map +0 -1
  178. package/dist/src/dcutr/index.js +0 -63
  179. package/dist/src/dcutr/index.js.map +0 -1
  180. package/dist/src/dcutr/pb/message.d.ts +0 -20
  181. package/dist/src/dcutr/pb/message.d.ts.map +0 -1
  182. package/dist/src/dcutr/pb/message.js +0 -77
  183. package/dist/src/dcutr/pb/message.js.map +0 -1
  184. package/dist/src/dcutr/utils.d.ts +0 -8
  185. package/dist/src/dcutr/utils.d.ts.map +0 -1
  186. package/dist/src/dcutr/utils.js +0 -27
  187. package/dist/src/dcutr/utils.js.map +0 -1
  188. package/dist/src/fetch/constants.d.ts +0 -3
  189. package/dist/src/fetch/constants.d.ts.map +0 -1
  190. package/dist/src/fetch/constants.js +0 -4
  191. package/dist/src/fetch/constants.js.map +0 -1
  192. package/dist/src/fetch/index.d.ts +0 -61
  193. package/dist/src/fetch/index.d.ts.map +0 -1
  194. package/dist/src/fetch/index.js +0 -205
  195. package/dist/src/fetch/index.js.map +0 -1
  196. package/dist/src/fetch/pb/proto.d.ts +0 -28
  197. package/dist/src/fetch/pb/proto.d.ts.map +0 -1
  198. package/dist/src/fetch/pb/proto.js +0 -120
  199. package/dist/src/fetch/pb/proto.js.map +0 -1
  200. package/dist/src/identify/consts.d.ts +0 -10
  201. package/dist/src/identify/consts.d.ts.map +0 -1
  202. package/dist/src/identify/consts.js +0 -11
  203. package/dist/src/identify/consts.js.map +0 -1
  204. package/dist/src/identify/identify.d.ts +0 -54
  205. package/dist/src/identify/identify.d.ts.map +0 -1
  206. package/dist/src/identify/identify.js +0 -447
  207. package/dist/src/identify/identify.js.map +0 -1
  208. package/dist/src/identify/index.d.ts +0 -72
  209. package/dist/src/identify/index.d.ts.map +0 -1
  210. package/dist/src/identify/index.js +0 -15
  211. package/dist/src/identify/index.js.map +0 -1
  212. package/dist/src/identify/pb/message.d.ts +0 -17
  213. package/dist/src/identify/pb/message.d.ts.map +0 -1
  214. package/dist/src/identify/pb/message.js +0 -98
  215. package/dist/src/identify/pb/message.js.map +0 -1
  216. package/dist/src/insecure/index.d.ts +0 -26
  217. package/dist/src/insecure/index.d.ts.map +0 -1
  218. package/dist/src/insecure/index.js +0 -110
  219. package/dist/src/insecure/index.js.map +0 -1
  220. package/dist/src/insecure/pb/proto.d.ts +0 -30
  221. package/dist/src/insecure/pb/proto.d.ts.map +0 -1
  222. package/dist/src/insecure/pb/proto.js +0 -127
  223. package/dist/src/insecure/pb/proto.js.map +0 -1
  224. package/dist/src/ping/constants.d.ts +0 -9
  225. package/dist/src/ping/constants.d.ts.map +0 -1
  226. package/dist/src/ping/constants.js +0 -15
  227. package/dist/src/ping/constants.js.map +0 -1
  228. package/dist/src/ping/index.d.ts +0 -24
  229. package/dist/src/ping/index.d.ts.map +0 -1
  230. package/dist/src/ping/index.js +0 -115
  231. package/dist/src/ping/index.js.map +0 -1
  232. package/dist/src/pnet/crypto.d.ts +0 -18
  233. package/dist/src/pnet/crypto.d.ts.map +0 -1
  234. package/dist/src/pnet/crypto.js +0 -60
  235. package/dist/src/pnet/crypto.js.map +0 -1
  236. package/dist/src/pnet/errors.d.ts +0 -6
  237. package/dist/src/pnet/errors.d.ts.map +0 -1
  238. package/dist/src/pnet/errors.js +0 -6
  239. package/dist/src/pnet/errors.js.map +0 -1
  240. package/dist/src/pnet/index.d.ts +0 -31
  241. package/dist/src/pnet/index.d.ts.map +0 -1
  242. package/dist/src/pnet/index.js +0 -97
  243. package/dist/src/pnet/index.js.map +0 -1
  244. package/dist/src/pnet/key-generator.d.ts +0 -11
  245. package/dist/src/pnet/key-generator.d.ts.map +0 -1
  246. package/dist/src/pnet/key-generator.js +0 -22
  247. package/dist/src/pnet/key-generator.js.map +0 -1
  248. package/dist/src/upnp-nat/index.d.ts +0 -71
  249. package/dist/src/upnp-nat/index.d.ts.map +0 -1
  250. package/dist/src/upnp-nat/index.js +0 -136
  251. package/dist/src/upnp-nat/index.js.map +0 -1
  252. package/dist/src/utils/peer-job-queue.d.ts +0 -33
  253. package/dist/src/utils/peer-job-queue.d.ts.map +0 -1
  254. package/dist/src/utils/peer-job-queue.js +0 -82
  255. package/dist/src/utils/peer-job-queue.js.map +0 -1
  256. package/dist/typedoc-urls.json +0 -71
  257. package/src/autonat/constants.ts +0 -19
  258. package/src/autonat/index.ts +0 -597
  259. package/src/autonat/pb/index.proto +0 -35
  260. package/src/autonat/pb/index.ts +0 -320
  261. package/src/circuit-relay/constants.ts +0 -72
  262. package/src/circuit-relay/index.ts +0 -59
  263. package/src/circuit-relay/pb/index.proto +0 -67
  264. package/src/circuit-relay/pb/index.ts +0 -539
  265. package/src/circuit-relay/server/advert-service.ts +0 -108
  266. package/src/circuit-relay/server/index.ts +0 -443
  267. package/src/circuit-relay/server/reservation-store.ts +0 -116
  268. package/src/circuit-relay/server/reservation-voucher.ts +0 -51
  269. package/src/circuit-relay/transport/discovery.ts +0 -136
  270. package/src/circuit-relay/transport/index.ts +0 -396
  271. package/src/circuit-relay/transport/listener.ts +0 -97
  272. package/src/circuit-relay/transport/reservation-store.ts +0 -312
  273. package/src/circuit-relay/utils.ts +0 -136
  274. package/src/dcutr/dcutr.ts +0 -378
  275. package/src/dcutr/index.ts +0 -102
  276. package/src/dcutr/pb/message.proto +0 -12
  277. package/src/dcutr/pb/message.ts +0 -96
  278. package/src/dcutr/utils.ts +0 -33
  279. package/src/fetch/README.md +0 -41
  280. package/src/fetch/constants.ts +0 -3
  281. package/src/fetch/index.ts +0 -315
  282. package/src/fetch/pb/proto.proto +0 -15
  283. package/src/fetch/pb/proto.ts +0 -153
  284. package/src/identify/README.md +0 -13
  285. package/src/identify/consts.ts +0 -12
  286. package/src/identify/identify.ts +0 -561
  287. package/src/identify/index.ts +0 -90
  288. package/src/identify/pb/message.proto +0 -30
  289. package/src/identify/pb/message.ts +0 -126
  290. package/src/insecure/index.ts +0 -138
  291. package/src/insecure/pb/proto.proto +0 -18
  292. package/src/insecure/pb/proto.ts +0 -161
  293. package/src/ping/constants.ts +0 -15
  294. package/src/ping/index.ts +0 -170
  295. package/src/pnet/README.md +0 -68
  296. package/src/pnet/crypto.ts +0 -67
  297. package/src/pnet/errors.ts +0 -5
  298. package/src/pnet/index.ts +0 -126
  299. package/src/pnet/key-generator.ts +0 -23
  300. package/src/upnp-nat/index.ts +0 -212
  301. package/src/utils/peer-job-queue.ts +0 -119
@@ -1,313 +0,0 @@
1
- import { CodeError } from '@libp2p/interface/errors';
2
- import { logger } from '@libp2p/logger';
3
- import { multiaddr } from '@multiformats/multiaddr';
4
- import delay from 'delay';
5
- import { pbStream } from 'it-protobuf-stream';
6
- import { codes } from '../errors.js';
7
- import { HolePunch } from './pb/message.js';
8
- import { isPublicAndDialable } from './utils.js';
9
- import { multicodec } from './index.js';
10
- const log = logger('libp2p:dcutr');
11
- // https://github.com/libp2p/specs/blob/master/relay/DCUtR.md#rpc-messages
12
- const MAX_DCUTR_MESSAGE_SIZE = 1024 * 4;
13
- // ensure the dial has a high priority to jump to the head of the dial queue
14
- const DCUTR_DIAL_PRIORITY = 100;
15
- const defaultValues = {
16
- // https://github.com/libp2p/go-libp2p/blob/8d2e54e1637041d5cf4fac1e531287560bd1f4ac/p2p/protocol/holepunch/holepuncher.go#L27
17
- timeout: 5000,
18
- // https://github.com/libp2p/go-libp2p/blob/8d2e54e1637041d5cf4fac1e531287560bd1f4ac/p2p/protocol/holepunch/holepuncher.go#L28
19
- retries: 3,
20
- maxInboundStreams: 1,
21
- maxOutboundStreams: 1
22
- };
23
- export class DefaultDCUtRService {
24
- started;
25
- timeout;
26
- retries;
27
- maxInboundStreams;
28
- maxOutboundStreams;
29
- peerStore;
30
- registrar;
31
- connectionManager;
32
- addressManager;
33
- transportManager;
34
- topologyId;
35
- constructor(components, init) {
36
- this.started = false;
37
- this.peerStore = components.peerStore;
38
- this.registrar = components.registrar;
39
- this.addressManager = components.addressManager;
40
- this.connectionManager = components.connectionManager;
41
- this.transportManager = components.transportManager;
42
- this.timeout = init.timeout ?? defaultValues.timeout;
43
- this.retries = init.retries ?? defaultValues.retries;
44
- this.maxInboundStreams = init.maxInboundStreams ?? defaultValues.maxInboundStreams;
45
- this.maxOutboundStreams = init.maxOutboundStreams ?? defaultValues.maxOutboundStreams;
46
- }
47
- isStarted() {
48
- return this.started;
49
- }
50
- async start() {
51
- if (this.started) {
52
- return;
53
- }
54
- // register for notifications of when peers that support DCUtR connect
55
- // nb. requires the identify service to be enabled
56
- this.topologyId = await this.registrar.register(multicodec, {
57
- notifyOnTransient: true,
58
- onConnect: (peerId, connection) => {
59
- if (!connection.transient) {
60
- // the connection is already direct, no upgrade is required
61
- return;
62
- }
63
- // the inbound peer starts the connection upgrade
64
- if (connection.direction !== 'inbound') {
65
- return;
66
- }
67
- this.upgradeInbound(connection)
68
- .catch(err => {
69
- log.error('error during outgoing DCUtR attempt', err);
70
- });
71
- }
72
- });
73
- await this.registrar.handle(multicodec, (data) => {
74
- void this.handleIncomingUpgrade(data.stream, data.connection).catch(err => {
75
- log.error('error during incoming DCUtR attempt', err);
76
- data.stream.abort(err);
77
- });
78
- }, {
79
- maxInboundStreams: this.maxInboundStreams,
80
- maxOutboundStreams: this.maxOutboundStreams,
81
- runOnTransientConnection: true
82
- });
83
- this.started = true;
84
- }
85
- async stop() {
86
- await this.registrar.unhandle(multicodec);
87
- if (this.topologyId != null) {
88
- this.registrar.unregister(this.topologyId);
89
- }
90
- this.started = false;
91
- }
92
- /**
93
- * Perform the inbound connection upgrade as B
94
- *
95
- * @see https://github.com/libp2p/specs/blob/master/relay/DCUtR.md#the-protocol
96
- */
97
- async upgradeInbound(relayedConnection) {
98
- // Upon observing the new connection, the inbound peer (here B) checks the
99
- // addresses advertised by A via identify.
100
- //
101
- // If that set includes public addresses, then A may be reachable by a direct
102
- // connection, in which case B attempts a unilateral connection upgrade by
103
- // initiating a direct connection to A.
104
- if (await this.attemptUnilateralConnectionUpgrade(relayedConnection)) {
105
- return;
106
- }
107
- let stream;
108
- for (let i = 0; i < this.retries; i++) {
109
- const options = {
110
- signal: AbortSignal.timeout(this.timeout)
111
- };
112
- try {
113
- // 1. B opens a stream to A using the /libp2p/dcutr protocol.
114
- stream = await relayedConnection.newStream([multicodec], {
115
- signal: options.signal,
116
- runOnTransientConnection: true
117
- });
118
- const pb = pbStream(stream, {
119
- maxDataLength: MAX_DCUTR_MESSAGE_SIZE
120
- }).pb(HolePunch);
121
- // 2. B sends to A a Connect message containing its observed (and
122
- // possibly predicted) addresses from identify and starts a timer
123
- // to measure RTT of the relay connection.
124
- log('B sending connect to %p', relayedConnection.remotePeer);
125
- const connectTimer = Date.now();
126
- await pb.write({
127
- type: HolePunch.Type.CONNECT,
128
- observedAddresses: this.addressManager.getAddresses().map(ma => ma.bytes)
129
- }, options);
130
- log('B receiving connect from %p', relayedConnection.remotePeer);
131
- // 4. Upon receiving the Connect, B sends a Sync message
132
- const connect = await pb.read(options);
133
- if (connect.type !== HolePunch.Type.CONNECT) {
134
- log('A sent wrong message type');
135
- throw new CodeError('DCUtR message type was incorrect', codes.ERR_INVALID_MESSAGE);
136
- }
137
- const multiaddrs = this.getDialableMultiaddrs(connect.observedAddresses);
138
- if (multiaddrs.length === 0) {
139
- log('A did not have any dialable multiaddrs');
140
- throw new CodeError('DCUtR connect message had no multiaddrs', codes.ERR_INVALID_MESSAGE);
141
- }
142
- const rtt = Date.now() - connectTimer;
143
- log('A sending sync, rtt %dms', rtt);
144
- await pb.write({
145
- type: HolePunch.Type.SYNC,
146
- observedAddresses: []
147
- }, options);
148
- log('A waiting for half RTT');
149
- // ..and starts a timer for half the RTT measured from the time between
150
- // sending the initial Connect and receiving the response
151
- await delay(rtt / 2);
152
- // TODO: when we have a QUIC transport, the dial step is different - for
153
- // now we only have tcp support
154
- // https://github.com/libp2p/specs/blob/master/relay/DCUtR.md#the-protocol
155
- log('B dialing', multiaddrs);
156
- // Upon expiry of the timer, B dials the address to A.
157
- const conn = await this.connectionManager.openConnection(multiaddrs, {
158
- signal: options.signal,
159
- priority: DCUTR_DIAL_PRIORITY
160
- });
161
- log('DCUtR to %p succeeded to address %a, closing relayed connection', relayedConnection.remotePeer, conn.remoteAddr);
162
- await relayedConnection.close(options);
163
- break;
164
- }
165
- catch (err) {
166
- log.error('error while attempting DCUtR on attempt %d of %d', i + 1, this.retries, err);
167
- stream?.abort(err);
168
- if (i === this.retries) {
169
- throw err;
170
- }
171
- }
172
- finally {
173
- if (stream != null) {
174
- await stream.close(options);
175
- }
176
- }
177
- }
178
- }
179
- /**
180
- * This is performed when A has dialed B via a relay but A also has a public
181
- * address that B can dial directly
182
- */
183
- async attemptUnilateralConnectionUpgrade(relayedConnection) {
184
- // Upon observing the new connection, the inbound peer (here B) checks the
185
- // addresses advertised by A via identify.
186
- const peerInfo = await this.peerStore.get(relayedConnection.remotePeer);
187
- // If that set includes public addresses, then A may be reachable by a direct
188
- // connection, in which case B attempts a unilateral connection upgrade by
189
- // initiating a direct connection to A.
190
- const publicAddresses = peerInfo.addresses
191
- .map(address => {
192
- const ma = address.multiaddr;
193
- // ensure all multiaddrs have the peer id
194
- if (ma.getPeerId() == null) {
195
- return ma.encapsulate(`/p2p/${relayedConnection.remotePeer}`);
196
- }
197
- return ma;
198
- })
199
- .filter(ma => {
200
- return isPublicAndDialable(ma, this.transportManager);
201
- });
202
- if (publicAddresses.length > 0) {
203
- const signal = AbortSignal.timeout(this.timeout);
204
- try {
205
- log('attempting unilateral connection upgrade to %a', publicAddresses);
206
- // force-dial the multiaddr(s), otherwise `connectionManager.openConnection`
207
- // will return the existing relayed connection
208
- const connection = await this.connectionManager.openConnection(publicAddresses, {
209
- signal,
210
- force: true
211
- });
212
- if (connection.transient) {
213
- throw new Error('Could not open a new, non-transient, connection');
214
- }
215
- log('unilateral connection upgrade to %p succeeded via %a, closing relayed connection', relayedConnection.remotePeer, connection.remoteAddr);
216
- await relayedConnection.close({
217
- signal
218
- });
219
- return true;
220
- }
221
- catch (err) {
222
- log.error('unilateral connection upgrade to %p on addresses %a failed', relayedConnection.remotePeer, publicAddresses, err);
223
- }
224
- }
225
- else {
226
- log('peer %p has no public addresses, not attempting unilateral connection upgrade', relayedConnection.remotePeer);
227
- }
228
- // no public addresses or failed to dial public addresses
229
- return false;
230
- }
231
- /**
232
- * Perform the connection upgrade as A
233
- *
234
- * @see https://github.com/libp2p/specs/blob/master/relay/DCUtR.md#the-protocol
235
- */
236
- async handleIncomingUpgrade(stream, relayedConnection) {
237
- const options = {
238
- signal: AbortSignal.timeout(this.timeout)
239
- };
240
- try {
241
- const pb = pbStream(stream, {
242
- maxDataLength: MAX_DCUTR_MESSAGE_SIZE
243
- }).pb(HolePunch);
244
- log('A receiving connect');
245
- // 3. Upon receiving the Connect, A responds back with a Connect message
246
- // containing its observed (and possibly predicted) addresses.
247
- const connect = await pb.read(options);
248
- if (connect.type !== HolePunch.Type.CONNECT) {
249
- log('B sent wrong message type');
250
- throw new CodeError('DCUtR message type was incorrect', codes.ERR_INVALID_MESSAGE);
251
- }
252
- if (connect.observedAddresses.length === 0) {
253
- log('B sent no multiaddrs');
254
- throw new CodeError('DCUtR connect message had no multiaddrs', codes.ERR_INVALID_MESSAGE);
255
- }
256
- const multiaddrs = this.getDialableMultiaddrs(connect.observedAddresses);
257
- if (multiaddrs.length === 0) {
258
- log('B had no dialable multiaddrs');
259
- throw new CodeError('DCUtR connect message had no dialable multiaddrs', codes.ERR_INVALID_MESSAGE);
260
- }
261
- log('A sending connect');
262
- await pb.write({
263
- type: HolePunch.Type.CONNECT,
264
- observedAddresses: this.addressManager.getAddresses().map(ma => ma.bytes)
265
- });
266
- log('A receiving sync');
267
- const sync = await pb.read(options);
268
- if (sync.type !== HolePunch.Type.SYNC) {
269
- throw new CodeError('DCUtR message type was incorrect', codes.ERR_INVALID_MESSAGE);
270
- }
271
- // TODO: when we have a QUIC transport, the dial step is different - for
272
- // now we only have tcp support
273
- // https://github.com/libp2p/specs/blob/master/relay/DCUtR.md#the-protocol
274
- // Upon receiving the Sync, A immediately dials the address to B
275
- log('A dialing', multiaddrs);
276
- const connection = await this.connectionManager.openConnection(multiaddrs, {
277
- signal: options.signal,
278
- priority: DCUTR_DIAL_PRIORITY,
279
- force: true
280
- });
281
- log('DCUtR to %p succeeded via %a, closing relayed connection', relayedConnection.remotePeer, connection.remoteAddr);
282
- await relayedConnection.close(options);
283
- }
284
- catch (err) {
285
- log.error('incoming DCUtR from %p failed', relayedConnection.remotePeer, err);
286
- stream.abort(err);
287
- }
288
- finally {
289
- await stream.close(options);
290
- }
291
- }
292
- /**
293
- * Takes the `addr` and converts it to a Multiaddr if possible
294
- */
295
- getDialableMultiaddrs(addrs) {
296
- const output = [];
297
- for (const addr of addrs) {
298
- if (addr == null || addr.length === 0) {
299
- continue;
300
- }
301
- try {
302
- const ma = multiaddr(addr);
303
- if (!isPublicAndDialable(ma, this.transportManager)) {
304
- continue;
305
- }
306
- output.push(ma);
307
- }
308
- catch { }
309
- }
310
- return output;
311
- }
312
- }
313
- //# sourceMappingURL=dcutr.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dcutr.js","sourceRoot":"","sources":["../../../src/dcutr/dcutr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAkB,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnE,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAUvC,MAAM,GAAG,GAAG,MAAM,CAAC,cAAc,CAAC,CAAA;AAElC,0EAA0E;AAC1E,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC,CAAA;AACvC,4EAA4E;AAC5E,MAAM,mBAAmB,GAAG,GAAG,CAAA;AAE/B,MAAM,aAAa,GAAG;IACpB,8HAA8H;IAC9H,OAAO,EAAE,IAAI;IACb,8HAA8H;IAC9H,OAAO,EAAE,CAAC;IACV,iBAAiB,EAAE,CAAC;IACpB,kBAAkB,EAAE,CAAC;CACtB,CAAA;AAED,MAAM,OAAO,mBAAmB;IACtB,OAAO,CAAS;IACP,OAAO,CAA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@@ -1,92 +0,0 @@
1
- /**
2
- * @packageDocumentation
3
- *
4
- * Direct Connection Upgrade through Relay (DCUtR) is a protocol that allows two
5
- * nodes to connect to each other who would otherwise be prevented doing so due
6
- * to being behind NATed connections or firewalls.
7
- *
8
- * The protocol involves making a relayed connection between the two peers and
9
- * using the relay to synchronise connection timings so that they dial each other
10
- * at precisely the same moment.
11
- *
12
- * @example
13
- *
14
- * ```ts
15
- * import { createLibp2p } from 'libp2p'
16
- * import { circuitRelayTransport } from 'libp2p/circuit-relay'
17
- * import { tcp } from '@libp2p/tcp'
18
- * import { identifyService } from 'libp2p/identify'
19
- * import { dCUtRService } from 'libp2p/dcutr'
20
- *
21
- * const node = await createLibp2p({
22
- * transports: [
23
- * circuitRelayTransport(),
24
- * tcp()
25
- * ],
26
- * services: {
27
- * identify: identifyService(),
28
- * dcutr: dcutrService()
29
- * }
30
- * })
31
- *
32
- * // QmTarget is a peer that is behind a NAT, supports TCP and has a relay
33
- * // reservation
34
- * await node.dial('/ip4/.../p2p/QmRelay/p2p-circuit/p2p/QmTarget')
35
- *
36
- * // after a while the connection should automatically get upgraded to a
37
- * // direct connection (e.g. non-transient)
38
- * while (true) {
39
- * const connections = node.getConnections()
40
- *
41
- * if (connections.find(conn => conn.transient === false)) {
42
- * console.info('have direct connection')
43
- * break
44
- * } else {
45
- * console.info('have relayed connection')
46
- *
47
- * // wait a few seconds to see if it's succeeded yet
48
- * await new Promise((resolve) => {
49
- * setTimeout(() => resolve(), 5000)
50
- * })
51
- * }
52
- * }
53
- * ```
54
- */
55
- import type { PeerStore } from '@libp2p/interface/peer-store';
56
- import type { AddressManager } from '@libp2p/interface-internal/address-manager';
57
- import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager';
58
- import type { Registrar } from '@libp2p/interface-internal/registrar';
59
- import type { TransportManager } from '@libp2p/interface-internal/transport-manager';
60
- export interface DCUtRServiceInit {
61
- /**
62
- * How long we should wait for the connection upgrade to complete (default: 5s)
63
- */
64
- timeout?: number;
65
- /**
66
- * How many times to retry the connection upgrade (default: 3)
67
- */
68
- retries?: number;
69
- /**
70
- * How many simultaneous inbound DCUtR protocol streams to allow on each
71
- * connection (default: 1)
72
- */
73
- maxInboundStreams?: number;
74
- /**
75
- * How many simultaneous outbound DCUtR protocol streams to allow on each
76
- * connection (default: 1)
77
- */
78
- maxOutboundStreams?: number;
79
- }
80
- export interface DCUtRServiceComponents {
81
- peerStore: PeerStore;
82
- connectionManager: ConnectionManager;
83
- registrar: Registrar;
84
- addressManager: AddressManager;
85
- transportManager: TransportManager;
86
- }
87
- /**
88
- * The DCUtR protocol
89
- */
90
- export declare const multicodec = "/libp2p/dcutr";
91
- export declare function dcutrService(init?: DCUtRServiceInit): (components: DCUtRServiceComponents) => unknown;
92
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/dcutr/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAA;AAChF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAA;AACtF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAA;AACrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8CAA8C,CAAA;AAEpF,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAE1B;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAC5B;AAED,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,SAAS,CAAA;IACpB,iBAAiB,EAAE,iBAAiB,CAAA;IACpC,SAAS,EAAE,SAAS,CAAA;IACpB,cAAc,EAAE,cAAc,CAAA;IAC9B,gBAAgB,EAAE,gBAAgB,CAAA;CACnC;AAED;;GAEG;AACH,eAAO,MAAM,UAAU,kBAAkB,CAAA;AAEzC,wBAAgB,YAAY,CAAE,IAAI,GAAE,gBAAqB,GAAG,CAAC,UAAU,EAAE,sBAAsB,KAAK,OAAO,CAE1G"}
@@ -1,63 +0,0 @@
1
- /**
2
- * @packageDocumentation
3
- *
4
- * Direct Connection Upgrade through Relay (DCUtR) is a protocol that allows two
5
- * nodes to connect to each other who would otherwise be prevented doing so due
6
- * to being behind NATed connections or firewalls.
7
- *
8
- * The protocol involves making a relayed connection between the two peers and
9
- * using the relay to synchronise connection timings so that they dial each other
10
- * at precisely the same moment.
11
- *
12
- * @example
13
- *
14
- * ```ts
15
- * import { createLibp2p } from 'libp2p'
16
- * import { circuitRelayTransport } from 'libp2p/circuit-relay'
17
- * import { tcp } from '@libp2p/tcp'
18
- * import { identifyService } from 'libp2p/identify'
19
- * import { dCUtRService } from 'libp2p/dcutr'
20
- *
21
- * const node = await createLibp2p({
22
- * transports: [
23
- * circuitRelayTransport(),
24
- * tcp()
25
- * ],
26
- * services: {
27
- * identify: identifyService(),
28
- * dcutr: dcutrService()
29
- * }
30
- * })
31
- *
32
- * // QmTarget is a peer that is behind a NAT, supports TCP and has a relay
33
- * // reservation
34
- * await node.dial('/ip4/.../p2p/QmRelay/p2p-circuit/p2p/QmTarget')
35
- *
36
- * // after a while the connection should automatically get upgraded to a
37
- * // direct connection (e.g. non-transient)
38
- * while (true) {
39
- * const connections = node.getConnections()
40
- *
41
- * if (connections.find(conn => conn.transient === false)) {
42
- * console.info('have direct connection')
43
- * break
44
- * } else {
45
- * console.info('have relayed connection')
46
- *
47
- * // wait a few seconds to see if it's succeeded yet
48
- * await new Promise((resolve) => {
49
- * setTimeout(() => resolve(), 5000)
50
- * })
51
- * }
52
- * }
53
- * ```
54
- */
55
- import { DefaultDCUtRService } from './dcutr.js';
56
- /**
57
- * The DCUtR protocol
58
- */
59
- export const multicodec = '/libp2p/dcutr';
60
- export function dcutrService(init = {}) {
61
- return (components) => new DefaultDCUtRService(components, init);
62
- }
63
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/dcutr/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAuChD;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,eAAe,CAAA;AAEzC,MAAM,UAAU,YAAY,CAAE,OAAyB,EAAE;IACvD,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,mBAAmB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AAClE,CAAC"}
@@ -1,20 +0,0 @@
1
- import type { Codec } from 'protons-runtime';
2
- import type { Uint8ArrayList } from 'uint8arraylist';
3
- export interface HolePunch {
4
- type?: HolePunch.Type;
5
- observedAddresses: Uint8Array[];
6
- }
7
- export declare namespace HolePunch {
8
- enum Type {
9
- UNUSED = "UNUSED",
10
- CONNECT = "CONNECT",
11
- SYNC = "SYNC"
12
- }
13
- namespace Type {
14
- const codec: () => Codec<Type>;
15
- }
16
- const codec: () => Codec<HolePunch>;
17
- const encode: (obj: Partial<HolePunch>) => Uint8Array;
18
- const decode: (buf: Uint8Array | Uint8ArrayList) => HolePunch;
19
- }
20
- //# sourceMappingURL=message.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../../../src/dcutr/pb/message.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,MAAM,WAAW,SAAS;IACxB,IAAI,CAAC,EAAE,SAAS,CAAC,IAAI,CAAA;IACrB,iBAAiB,EAAE,UAAU,EAAE,CAAA;CAChC;AAED,yBAAiB,SAAS,CAAC;IACzB,KAAY,IAAI;QACd,MAAM,WAAW;QACjB,OAAO,YAAY;QACnB,IAAI,SAAS;KACd;IAQD,UAAiB,IAAI,CAAC;QACb,MAAM,KAAK,QAAO,MAAM,IAAI,CAElC,CAAA;KACF;IAIM,MAAM,KAAK,QAAO,MAAM,SAAS,CAkDvC,CAAA;IAEM,MAAM,MAAM,QAAS,QAAQ,SAAS,CAAC,KAAG,UAEhD,CAAA;IAEM,MAAM,MAAM,QAAS,UAAU,GAAG,cAAc,KAAG,SAEzD,CAAA;CACF"}
@@ -1,77 +0,0 @@
1
- /* eslint-disable import/export */
2
- /* eslint-disable complexity */
3
- /* eslint-disable @typescript-eslint/no-namespace */
4
- /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
5
- /* eslint-disable @typescript-eslint/no-empty-interface */
6
- import { enumeration, encodeMessage, decodeMessage, message } from 'protons-runtime';
7
- export var HolePunch;
8
- (function (HolePunch) {
9
- let Type;
10
- (function (Type) {
11
- Type["UNUSED"] = "UNUSED";
12
- Type["CONNECT"] = "CONNECT";
13
- Type["SYNC"] = "SYNC";
14
- })(Type = HolePunch.Type || (HolePunch.Type = {}));
15
- let __TypeValues;
16
- (function (__TypeValues) {
17
- __TypeValues[__TypeValues["UNUSED"] = 0] = "UNUSED";
18
- __TypeValues[__TypeValues["CONNECT"] = 100] = "CONNECT";
19
- __TypeValues[__TypeValues["SYNC"] = 300] = "SYNC";
20
- })(__TypeValues || (__TypeValues = {}));
21
- (function (Type) {
22
- Type.codec = () => {
23
- return enumeration(__TypeValues);
24
- };
25
- })(Type = HolePunch.Type || (HolePunch.Type = {}));
26
- let _codec;
27
- HolePunch.codec = () => {
28
- if (_codec == null) {
29
- _codec = message((obj, w, opts = {}) => {
30
- if (opts.lengthDelimited !== false) {
31
- w.fork();
32
- }
33
- if (obj.type != null) {
34
- w.uint32(8);
35
- HolePunch.Type.codec().encode(obj.type, w);
36
- }
37
- if (obj.observedAddresses != null) {
38
- for (const value of obj.observedAddresses) {
39
- w.uint32(18);
40
- w.bytes(value);
41
- }
42
- }
43
- if (opts.lengthDelimited !== false) {
44
- w.ldelim();
45
- }
46
- }, (reader, length) => {
47
- const obj = {
48
- observedAddresses: []
49
- };
50
- const end = length == null ? reader.len : reader.pos + length;
51
- while (reader.pos < end) {
52
- const tag = reader.uint32();
53
- switch (tag >>> 3) {
54
- case 1:
55
- obj.type = HolePunch.Type.codec().decode(reader);
56
- break;
57
- case 2:
58
- obj.observedAddresses.push(reader.bytes());
59
- break;
60
- default:
61
- reader.skipType(tag & 7);
62
- break;
63
- }
64
- }
65
- return obj;
66
- });
67
- }
68
- return _codec;
69
- };
70
- HolePunch.encode = (obj) => {
71
- return encodeMessage(obj, HolePunch.codec());
72
- };
73
- HolePunch.decode = (buf) => {
74
- return decodeMessage(buf, HolePunch.codec());
75
- };
76
- })(HolePunch || (HolePunch = {}));
77
- //# sourceMappingURL=message.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"message.js","sourceRoot":"","sources":["../../../../src/dcutr/pb/message.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,+BAA+B;AAC/B,oDAAoD;AACpD,8EAA8E;AAC9E,0DAA0D;AAE1D,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AASpF,MAAM,KAAW,SAAS,CAgFzB;AAhFD,WAAiB,SAAS;IACxB,IAAY,IAIX;IAJD,WAAY,IAAI;QACd,yBAAiB,CAAA;QACjB,2BAAmB,CAAA;QACnB,qBAAa,CAAA;IACf,CAAC,EAJW,IAAI,GAAJ,cAAI,KAAJ,cAAI,QAIf;IAED,IAAK,YAIJ;IAJD,WAAK,YAAY;QACf,mDAA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M,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,GAAG,MAAM,CAAA;gBAE7D,OAAO,MAAM,CAAC,GAAG,GAAG,GAAG,EAAE;oBACvB,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,CAAA;oBAE3B,QAAQ,GAAG,KAAK,CAAC,EAAE;wBACjB,KAAK,CAAC;4BACJ,GAAG,CAAC,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;4BAChD,MAAK;wBACP,KAAK,CAAC;4BACJ,GAAG,CAAC,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAA;4BAC1C,MAAK;wBACP;4BACE,MAAM,CAAC,QAAQ,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;4BACxB,MAAK;qBACR;iBACF;gBAED,OAAO,GAAG,CAAA;YACZ,CAAC,CAAC,CAAA;SACH;QAED,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;IAEY,gBAAM,GAAG,CAAC,GAAuB,EAAc,EAAE;QAC5D,OAAO,aAAa,CAAC,GAAG,EAAE,SAAS,CAAC,KAAK,EAAE,CAAC,CAAA;IAC9C,CAAC,CAAA;IAEY,gBAAM,GAAG,CAAC,GAAgC,EAAa,EAAE;QACpE,OAAO,aAAa,CAAC,GAAG,EAAE,SAAS,CAAC,KAAK,EAAE,CAAC,CAAA;IAC9C,CAAC,CAAA;AACH,CAAC,EAhFgB,SAAS,KAAT,SAAS,QAgFzB"}
@@ -1,8 +0,0 @@
1
- import { type Multiaddr } from '@multiformats/multiaddr';
2
- import type { TransportManager } from '@libp2p/interface-internal/src/transport-manager';
3
- /**
4
- * Returns true if the passed multiaddr is public, not relayed and we have a
5
- * transport that can dial it
6
- */
7
- export declare function isPublicAndDialable(ma: Multiaddr, transportManager: TransportManager): boolean;
8
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/dcutr/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAGxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kDAAkD,CAAA;AAExF;;;GAGG;AACH,wBAAgB,mBAAmB,CAAE,EAAE,EAAE,SAAS,EAAE,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAuB/F"}
@@ -1,27 +0,0 @@
1
- import {} from '@multiformats/multiaddr';
2
- import { Circuit, IP, DNS } from '@multiformats/multiaddr-matcher';
3
- import isPrivate from 'private-ip';
4
- /**
5
- * Returns true if the passed multiaddr is public, not relayed and we have a
6
- * transport that can dial it
7
- */
8
- export function isPublicAndDialable(ma, transportManager) {
9
- // ignore circuit relay
10
- if (Circuit.matches(ma)) {
11
- return false;
12
- }
13
- const transport = transportManager.transportForMultiaddr(ma);
14
- if (transport == null) {
15
- return false;
16
- }
17
- // dns addresses are probably public?
18
- if (DNS.matches(ma)) {
19
- return true;
20
- }
21
- // ensure we have only IPv4/IPv6 addresses
22
- if (!IP.matches(ma)) {
23
- return false;
24
- }
25
- return isPrivate(ma.toOptions().host) === false;
26
- }
27
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/dcutr/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,iCAAiC,CAAA;AAClE,OAAO,SAAS,MAAM,YAAY,CAAA;AAGlC;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAE,EAAa,EAAE,gBAAkC;IACpF,uBAAuB;IACvB,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;QACvB,OAAO,KAAK,CAAA;KACb;IAED,MAAM,SAAS,GAAG,gBAAgB,CAAC,qBAAqB,CAAC,EAAE,CAAC,CAAA;IAE5D,IAAI,SAAS,IAAI,IAAI,EAAE;QACrB,OAAO,KAAK,CAAA;KACb;IAED,qCAAqC;IACrC,IAAI,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;QACnB,OAAO,IAAI,CAAA;KACZ;IAED,0CAA0C;IAC1C,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;QACnB,OAAO,KAAK,CAAA;KACb;IAED,OAAO,SAAS,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,KAAK,KAAK,CAAA;AACjD,CAAC"}
@@ -1,3 +0,0 @@
1
- export declare const PROTOCOL_VERSION = "0.0.1";
2
- export declare const PROTOCOL_NAME = "fetch";
3
- //# sourceMappingURL=constants.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/fetch/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,gBAAgB,UAAU,CAAA;AACvC,eAAO,MAAM,aAAa,UAAU,CAAA"}