libp2p 0.33.0 → 0.35.2

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 (74) hide show
  1. package/dist/src/circuit/index.d.ts +2 -2
  2. package/dist/src/circuit/index.d.ts.map +1 -1
  3. package/dist/src/circuit/transport.d.ts +1 -1
  4. package/dist/src/circuit/transport.d.ts.map +1 -1
  5. package/dist/src/config.d.ts +0 -1
  6. package/dist/src/connection-manager/auto-dialler.d.ts +56 -0
  7. package/dist/src/connection-manager/auto-dialler.d.ts.map +1 -0
  8. package/dist/src/connection-manager/index.d.ts +0 -10
  9. package/dist/src/connection-manager/index.d.ts.map +1 -1
  10. package/dist/src/content-routing/index.d.ts +4 -2
  11. package/dist/src/content-routing/index.d.ts.map +1 -1
  12. package/dist/src/dht/dht-content-routing.d.ts +30 -0
  13. package/dist/src/dht/dht-content-routing.d.ts.map +1 -0
  14. package/dist/src/dht/dht-peer-routing.d.ts +29 -0
  15. package/dist/src/dht/dht-peer-routing.d.ts.map +1 -0
  16. package/dist/src/dialer/dial-request.d.ts +4 -4
  17. package/dist/src/dialer/dial-request.d.ts.map +1 -1
  18. package/dist/src/dialer/index.d.ts +2 -3
  19. package/dist/src/dialer/index.d.ts.map +1 -1
  20. package/dist/src/errors.d.ts +2 -0
  21. package/dist/src/identify/index.d.ts +1 -1
  22. package/dist/src/identify/index.d.ts.map +1 -1
  23. package/dist/src/index.d.ts +3 -2
  24. package/dist/src/index.d.ts.map +1 -1
  25. package/dist/src/metrics/stats.d.ts +0 -1
  26. package/dist/src/metrics/stats.d.ts.map +1 -1
  27. package/dist/src/nat-manager.d.ts.map +1 -1
  28. package/dist/src/peer-routing.d.ts +8 -1
  29. package/dist/src/peer-routing.d.ts.map +1 -1
  30. package/dist/src/peer-store/address-book.d.ts +1 -1
  31. package/dist/src/peer-store/address-book.d.ts.map +1 -1
  32. package/dist/src/peer-store/index.d.ts +37 -24
  33. package/dist/src/peer-store/index.d.ts.map +1 -1
  34. package/dist/src/peer-store/metadata-book.d.ts +3 -2
  35. package/dist/src/peer-store/metadata-book.d.ts.map +1 -1
  36. package/dist/src/peer-store/persistent/index.d.ts +0 -1
  37. package/dist/src/record/envelope/index.d.ts +23 -0
  38. package/dist/src/record/envelope/index.d.ts.map +1 -1
  39. package/dist/src/record/peer-record/index.d.ts +6 -0
  40. package/dist/src/record/peer-record/index.d.ts.map +1 -1
  41. package/dist/src/registrar.d.ts +1 -1
  42. package/dist/src/registrar.d.ts.map +1 -1
  43. package/dist/src/upgrader.d.ts +1 -1
  44. package/dist/src/upgrader.d.ts.map +1 -1
  45. package/package.json +30 -25
  46. package/src/circuit/auto-relay.js +4 -4
  47. package/src/circuit/circuit/hop.js +2 -2
  48. package/src/circuit/circuit/stop.js +1 -1
  49. package/src/circuit/circuit/utils.js +2 -2
  50. package/src/circuit/index.js +1 -1
  51. package/src/circuit/transport.js +1 -1
  52. package/src/connection-manager/auto-dialler.js +118 -0
  53. package/src/connection-manager/index.js +0 -52
  54. package/src/content-routing/index.js +35 -9
  55. package/src/dht/dht-content-routing.js +44 -0
  56. package/src/dht/dht-peer-routing.js +51 -0
  57. package/src/dialer/dial-request.js +8 -2
  58. package/src/dialer/index.js +3 -4
  59. package/src/errors.js +3 -1
  60. package/src/get-peer.js +1 -1
  61. package/src/identify/index.js +8 -8
  62. package/src/index.js +16 -14
  63. package/src/insecure/plaintext.js +1 -1
  64. package/src/keychain/cms.js +2 -2
  65. package/src/keychain/index.js +9 -9
  66. package/src/nat-manager.js +2 -2
  67. package/src/peer-routing.js +12 -4
  68. package/src/peer-store/address-book.js +1 -1
  69. package/src/peer-store/metadata-book.js +2 -1
  70. package/src/peer-store/persistent/index.js +5 -5
  71. package/src/pnet/crypto.js +1 -1
  72. package/src/pnet/key-generator.js +1 -1
  73. package/src/transport-manager.js +1 -1
  74. package/src/upgrader.js +9 -9
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/record/envelope/index.js"],"names":[],"mappings":";AAcA;;GAEG;AAEH;IACE;;;;;;;;;;OAUG;IACH;QAL0B,MAAM,EAArB,MAAM;QACa,WAAW,EAA9B,UAAU;QACS,OAAO,EAA1B,UAAU;QACS,SAAS,EAA5B,UAAU;OAUpB;IAPC,eAAoB;IACpB,wBAA8B;IAC9B,oBAAsB;IACtB,sBAA0B;IAG1B,iCAAyB;IAG3B;;;;OAIG;IACH,WAFa,UAAU,CAiBtB;IAED;;;;;OAKG;IACH,cAHW,QAAQ,GACN,OAAO,CAOnB;IAED;;;;;OAKG;IACH,iBAHW,MAAM,GACJ,QAAQ,OAAO,CAAC,CAM5B;CACF;;;;;AAwC6B,0CAHnB,UAAU,GACR,QAAQ,QAAQ,CAAC,CAY7B;AAWe,8BAJL,MAAM,UACN,MAAM,GACJ,QAAQ,QAAQ,CAAC,CAgB7B;AAUyB,sCAJf,UAAU,UACV,MAAM,GACJ,QAAQ,QAAQ,CAAC,CAW7B;cArKY,OAAO,oCAAoC,EAAE,MAAM"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/record/envelope/index.js"],"names":[],"mappings":";AAcA;;GAEG;AAEH;IACE;;;;;;;;;;OAUG;IACH;QAL0B,MAAM,EAArB,MAAM;QACa,WAAW,EAA9B,UAAU;QACS,OAAO,EAA1B,UAAU;QACS,SAAS,EAA5B,UAAU;OAUpB;IAPC,eAAoB;IACpB,wBAA8B;IAC9B,oBAAsB;IACtB,sBAA0B;IAG1B,iCAAyB;IAG3B;;;;OAIG;IACH,WAFa,UAAU,CAiBtB;IAED;;;;;OAKG;IACH,cAHW,QAAQ,GACN,OAAO,CAOnB;IAED;;;;;OAKG;IACH,iBAHW,MAAM,GACJ,QAAQ,OAAO,CAAC,CAM5B;CACF;;;;;AAkCD;;;;;GAKG;AACH,0CAHW,UAAU,GACR,QAAQ,QAAQ,CAAC,CAY7B;AAED;;;;;;;;GAQG;AACH,8BAJW,MAAM,UACN,MAAM,GACJ,QAAQ,QAAQ,CAAC,CAgB7B;AAED;;;;;;;GAOG;AACH,sCAJW,UAAU,UACV,MAAM,GACJ,QAAQ,QAAQ,CAAC,CAW7B;cArKY,OAAO,oCAAoC,EAAE,MAAM"}
@@ -48,6 +48,12 @@ declare namespace PeerRecord {
48
48
  type Record = import('libp2p-interfaces/src/record/types').Record;
49
49
  import PeerId = require("peer-id");
50
50
  import { Multiaddr } from "multiaddr";
51
+ /**
52
+ * Unmarshal Peer Record Protobuf.
53
+ *
54
+ * @param {Uint8Array} buf - marshaled peer record.
55
+ * @returns {PeerRecord}
56
+ */
51
57
  declare function createFromProtobuf(buf: Uint8Array): PeerRecord;
52
58
  import { ENVELOPE_DOMAIN_PEER_RECORD } from "./consts";
53
59
  type Address = import('../../peer-store/address-book.js').Address;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/record/peer-record/index.js"],"names":[],"mappings":";AAYA;;;GAGG;AAEH;;GAEG;AACH;IACE;;;;;;;;;OASG;IACH;QAJ0B,MAAM,EAArB,MAAM;QACc,UAAU,EAA9B,SAAS,EAAE;QACK,SAAS;OAYnC;IATC,eAAyC;IACzC,kBAA8C;IAE9C,eAAoB;IACpB,wBAA4B;IAC5B,kBAA0B;IAG1B,iCAAyB;IAG3B;;;;OAIG;IACH,WAFa,UAAU,CAgBtB;IAED;;;;;OAKG;IACH,cAHW,OAAO,GACL,OAAO,CAuBnB;CACF;;;;cA9EY,OAAO,oCAAoC,EAAE,MAAM;;;AAsFhC,yCAHrB,UAAU,GACR,UAAU,CAUtB;;eA/FY,OAAO,kCAAkC,EAAE,OAAO"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/record/peer-record/index.js"],"names":[],"mappings":";AAYA;;;GAGG;AAEH;;GAEG;AACH;IACE;;;;;;;;;OASG;IACH;QAJ0B,MAAM,EAArB,MAAM;QACc,UAAU,EAA9B,SAAS,EAAE;QACK,SAAS;OAYnC;IATC,eAAyC;IACzC,kBAA8C;IAE9C,eAAoB;IACpB,wBAA4B;IAC5B,kBAA0B;IAG1B,iCAAyB;IAG3B;;;;OAIG;IACH,WAFa,UAAU,CAgBtB;IAED;;;;;OAKG;IACH,cAHW,OAAO,GACL,OAAO,CAuBnB;CACF;;;;cA9EY,OAAO,oCAAoC,EAAE,MAAM;;;AAgFhE;;;;;GAKG;AACH,yCAHW,UAAU,GACR,UAAU,CAUtB;;eA/FY,OAAO,kCAAkC,EAAE,OAAO"}
@@ -74,9 +74,9 @@ declare namespace Registrar {
74
74
  export { PeerId, PeerStore, ConnectionManager, Connection, HandlerProps };
75
75
  }
76
76
  import Topology = require("libp2p-interfaces/src/topology");
77
- type HandlerProps = import('./').HandlerProps;
78
77
  type Connection = import("libp2p-interfaces/src/connection/connection");
79
78
  type PeerId = import('peer-id');
80
79
  type PeerStore = import('./peer-store');
81
80
  type ConnectionManager = import('./connection-manager');
81
+ type HandlerProps = import('./').HandlerProps;
82
82
  //# sourceMappingURL=registrar.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"registrar.d.ts","sourceRoot":"","sources":["../../src/registrar.js"],"names":[],"mappings":";AAaA;;;;;;GAMG;AAEH;;GAEG;AAEH;;GAEG;AACH;IACE;;;;;OAKG;IACH;QAJ4B,SAAS,EAA1B,SAAS;QACgB,iBAAiB,EAA1C,iBAAiB;OAsB3B;IAjBC,kCAA0B;IAE1B,kDAA0C;IAE1C;;;;OAIG;IACH,YAFU,IAAI,MAAM,EAAE,QAAQ,CAAC,CAEJ;IAE3B,2FAA2F;IAE3F,qBAFuB,MAAM,EAAE,GAAC,MAAM,mBAAmB,YAAY,KAAK,IAAI,KAAK,IAAI,CAE/D;IA+D1B;;;;;OAKG;IACH,0BAHW,UAAU,GACR,IAAI,CAMhB;IA5DD;;OAEG;IACH,4BATyB,MAAM,EAAE,GAAC,MAAM,mBAAmB,YAAY,KAAK,IAAI,KAAK,IAAI,EAWxF;IAZD;;OAEG;IACH,0BAFyB,MAAM,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AAc,CAAC;yBACtB,OAAO,sBAAsB,CAAC;oBAE9B,OAAO,IAAI,EAAE,YAAY"}
@@ -132,8 +132,8 @@ declare namespace Upgrader {
132
132
  export { MultiaddrConnection, MuxerFactory, Muxer, MuxedStream, Crypto, Connection, Multiaddr, CryptoResult };
133
133
  }
134
134
  import PeerId = require("peer-id");
135
- import { Connection } from "libp2p-interfaces/src/connection";
136
135
  type MultiaddrConnection = import('libp2p-interfaces/src/transport/types').MultiaddrConnection;
136
+ import { Connection } from "libp2p-interfaces/src/connection";
137
137
  type MuxerFactory = import('libp2p-interfaces/src/stream-muxer/types').MuxerFactory;
138
138
  type Muxer = import('libp2p-interfaces/src/stream-muxer/types').Muxer;
139
139
  type MuxedStream = import('libp2p-interfaces/src/stream-muxer/types').MuxedStream;
@@ -1 +1 @@
1
- {"version":3,"file":"upgrader.d.ts","sourceRoot":"","sources":["../../src/upgrader.js"],"names":[],"mappings":";AAiBA;;;;;;;;GAQG;AAEH;;;;;GAKG;AAEH;IACE;;;;;;;;OAQG;IACH;mBAPW,MAAM;;;;mCAIO,UAAU,KAAK,IAAI;sCACnB,UAAU,KAAK,IAAI;OAmB1C;IATC,kBAA0B;IAC1B,yCAAsB;IACtB,0EAAsB;IACtB,qFAAoB;IACpB,sCAAsC;IACtC,WADW,OAAO,QAAQ,CAAC,GAAG,IAAI,CACb;IACrB,yBAA0B;IAC1B,2BAlBsB,UAAU,KAAK,IAAI,CAkBT;IAChC,8BAlBsB,UAAU,KAAK,IAAI,CAkBH;IAGxC;;;;;;OAMG;IACH,uBAHW,mBAAmB,GACjB,QAAQ,UAAU,CAAC,CA6D/B;IAED;;;;;;OAMG;IACH,wBAHW,mBAAmB,GACjB,QAAQ,UAAU,CAAC,CAoE/B;IAED;;;;;;;;;;;;OAYG;IACH,0BA8GC;IAED;;;;;;;;OAQG;IACH,kBAGC;IAED;;;;;;;;;OASG;IACH,wBAqBC;IAED;;;;;;;;;;;OAWG;IACH,yBAqBC;IAED;;;;;;;;;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WAAW;cAC9D,OAAO,oCAAoC,EAAE,MAAM;;iBAEnD,OAAO,WAAW,EAAE,SAAS;;;;;UAK5B,mBAAmB;gBACnB,MAAM;cACN,MAAM"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libp2p",
3
- "version": "0.33.0",
3
+ "version": "0.35.2",
4
4
  "description": "JavaScript implementation of libp2p, a modular peer to peer network stack",
5
5
  "leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
6
6
  "main": "src/index.js",
@@ -41,6 +41,7 @@
41
41
  "test:node": "aegir test -t node -f \"./test/**/*.{node,spec}.js\"",
42
42
  "test:browser": "aegir test -t browser",
43
43
  "test:examples": "cd examples && npm run test:all",
44
+ "test:interop": "LIBP2P_JS=$PWD npx aegir test -t node -f ./node_modules/libp2p-interop/test/*",
44
45
  "prepare": "aegir build --no-bundle",
45
46
  "release": "aegir release -t node -t browser",
46
47
  "release-minor": "aegir release --type minor -t node -t browser",
@@ -65,7 +66,7 @@
65
66
  "homepage": "https://libp2p.io",
66
67
  "license": "MIT",
67
68
  "engines": {
68
- "node": ">=14.0.0"
69
+ "node": ">=15.0.0"
69
70
  },
70
71
  "browser": {
71
72
  "@motrix/nat-api": false
@@ -74,14 +75,15 @@
74
75
  "extends": "ipfs",
75
76
  "ignorePatterns": [
76
77
  "!.aegir.js",
77
- "test/ts-use"
78
+ "test/ts-use",
79
+ "*.d.ts"
78
80
  ]
79
81
  },
80
82
  "dependencies": {
81
- "abortable-iterator": "^3.0.0",
82
83
  "@motrix/nat-api": "^0.3.1",
83
84
  "@vascosantos/moving-average": "^1.1.0",
84
85
  "abort-controller": "^3.0.0",
86
+ "abortable-iterator": "^3.0.0",
85
87
  "aggregate-error": "^3.1.0",
86
88
  "any-signal": "^2.1.1",
87
89
  "bignumber.js": "^9.0.1",
@@ -103,8 +105,8 @@
103
105
  "it-merge": "^1.0.0",
104
106
  "it-pipe": "^1.1.0",
105
107
  "it-take": "^1.0.0",
106
- "libp2p-crypto": "^0.19.4",
107
- "libp2p-interfaces": "^1.0.0",
108
+ "libp2p-crypto": "^0.21.0",
109
+ "libp2p-interfaces": "^2.0.1",
108
110
  "libp2p-utils": "^0.4.0",
109
111
  "mafmt": "^10.0.0",
110
112
  "merge-options": "^3.0.4",
@@ -117,14 +119,14 @@
117
119
  "p-fifo": "^1.0.0",
118
120
  "p-retry": "^4.4.0",
119
121
  "p-settle": "^4.1.1",
120
- "peer-id": "^0.15.0",
122
+ "peer-id": "^0.16.0",
121
123
  "private-ip": "^2.1.0",
122
124
  "protobufjs": "^6.10.2",
123
125
  "retimer": "^3.0.0",
124
126
  "sanitize-filename": "^1.6.3",
125
127
  "set-delayed-interval": "^1.0.0",
126
128
  "streaming-iterables": "^6.0.0",
127
- "timeout-abort-controller": "^1.1.1",
129
+ "timeout-abort-controller": "^2.0.0",
128
130
  "uint8arrays": "^3.0.0",
129
131
  "varint": "^6.0.0",
130
132
  "wherearewe": "^1.0.0",
@@ -137,35 +139,35 @@
137
139
  "@types/node": "^16.0.1",
138
140
  "@types/node-forge": "^0.10.1",
139
141
  "@types/varint": "^6.0.0",
140
- "aegir": "^33.1.1",
142
+ "aegir": "^36.0.0",
141
143
  "buffer": "^6.0.3",
142
144
  "datastore-core": "^6.0.7",
143
145
  "delay": "^5.0.0",
144
- "interop-libp2p": "^0.4.0",
145
- "into-stream": "^7.0.0",
146
- "ipfs-http-client": "^52.0.2",
146
+ "into-stream": "^6.0.0",
147
+ "ipfs-http-client": "^54.0.2",
147
148
  "it-concat": "^2.0.0",
148
149
  "it-pair": "^1.0.0",
149
150
  "it-pushable": "^1.4.0",
150
151
  "libp2p": ".",
151
- "libp2p-bootstrap": "^0.13.0",
152
+ "libp2p-bootstrap": "^0.14.0",
152
153
  "libp2p-delegated-content-routing": "^0.11.0",
153
- "libp2p-delegated-peer-routing": "^0.10.0",
154
+ "libp2p-delegated-peer-routing": "^0.11.0",
154
155
  "libp2p-floodsub": "^0.27.0",
155
156
  "libp2p-gossipsub": "^0.11.0",
156
- "libp2p-interfaces-compliance-tests": "^1.0.0",
157
- "libp2p-kad-dht": "^0.24.2",
158
- "libp2p-mdns": "^0.17.0",
157
+ "libp2p-interfaces-compliance-tests": "^2.0.1",
158
+ "libp2p-interop": "^0.5.0",
159
+ "libp2p-kad-dht": "^0.27.1",
160
+ "libp2p-mdns": "^0.18.0",
159
161
  "libp2p-mplex": "^0.10.1",
160
162
  "libp2p-tcp": "^0.17.0",
161
- "libp2p-webrtc-star": "^0.23.0",
163
+ "libp2p-webrtc-star": "^0.25.0",
162
164
  "libp2p-websockets": "^0.16.0",
163
165
  "nock": "^13.0.3",
164
166
  "p-defer": "^3.0.0",
165
167
  "p-times": "^3.0.0",
166
168
  "p-wait-for": "^3.2.0",
167
169
  "rimraf": "^3.0.2",
168
- "sinon": "^11.1.1",
170
+ "sinon": "^12.0.1",
169
171
  "util": "^0.12.3"
170
172
  },
171
173
  "contributors": [
@@ -179,28 +181,28 @@
179
181
  "Friedel Ziegelmayer <dignifiedquire@gmail.com>",
180
182
  "Maciej Krüger <mkg20001@gmail.com>",
181
183
  "Hugo Dias <mail@hugodias.me>",
182
- "Chris Dostert <chrisdostert@users.noreply.github.com>",
183
184
  "dirkmc <dirkmdev@gmail.com>",
185
+ "Chris Dostert <chrisdostert@users.noreply.github.com>",
184
186
  "Volker Mische <volker.mische@gmail.com>",
185
187
  "zeim839 <50573884+zeim839@users.noreply.github.com>",
186
188
  "Richard Littauer <richard.littauer@gmail.com>",
187
189
  "a1300 <matthias-knopp@gmx.net>",
188
190
  "Ryan Bell <ryan@piing.net>",
189
191
  "ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>",
190
- "Franck Royer <franck@royer.one>",
191
- "Thomas Eizinger <thomas@eizinger.io>",
192
192
  "Giovanni T. Parra <fiatjaf@gmail.com>",
193
193
  "acolytec3 <17355484+acolytec3@users.noreply.github.com>",
194
+ "Franck Royer <franck@royer.one>",
194
195
  "Elven <mon.samuel@qq.com>",
196
+ "Robert Kiel <robert.kiel@hoprnet.org>",
195
197
  "Andrew Nesbitt <andrewnez@gmail.com>",
196
198
  "Samlior <samlior@foxmail.com>",
199
+ "Thomas Eizinger <thomas@eizinger.io>",
197
200
  "Didrik Nordström <didrik.nordstrom@gmail.com>",
198
- "RasmusErik Voel Jensen <github@solsort.com>",
199
- "Robert Kiel <robert.kiel@hoprnet.org>",
200
201
  "Smite Chow <xiaopengyou@live.com>",
201
202
  "Soeren <nikorpoulsen@gmail.com>",
202
203
  "Sönke Hahn <soenkehahn@gmail.com>",
203
204
  "TJKoury <TJKoury@gmail.com>",
205
+ "TheStarBoys <41286328+TheStarBoys@users.noreply.github.com>",
204
206
  "Tiago Alves <alvesjtiago@gmail.com>",
205
207
  "XiaoZhang <zxinmyth@gmail.com>",
206
208
  "Yusef Napora <yusef@napora.org>",
@@ -210,11 +212,13 @@
210
212
  "isan_rivkin <isanrivkin@gmail.com>",
211
213
  "mayerwin <mayerwin@users.noreply.github.com>",
212
214
  "mcclure <andi.m.mcclure@gmail.com>",
215
+ "patrickwoodhead <91056047+patrickwoodhead@users.noreply.github.com>",
213
216
  "phillmac <phillmac@users.noreply.github.com>",
214
217
  "robertkiel <robert.kiel@validitylabs.org>",
215
218
  "shresthagrawal <34920931+shresthagrawal@users.noreply.github.com>",
216
219
  "swedneck <40505480+swedneck@users.noreply.github.com>",
217
220
  "greenSnot <greenSnot@users.noreply.github.com>",
221
+ "Alan Smithee <ggnore.alan.smithee@gmail.com>",
218
222
  "Aleksei <vozhdb@gmail.com>",
219
223
  "Bernd Strehl <bernd.strehl@gmail.com>",
220
224
  "Chris Bratlien <chrisbratlien@gmail.com>",
@@ -242,6 +246,7 @@
242
246
  "Michael Burns <5170+mburns@users.noreply.github.com>",
243
247
  "Miguel Mota <miguelmota2@gmail.com>",
244
248
  "Nuno Nogueira <nunofmn@gmail.com>",
245
- "Philipp Muens <raute1337@gmx.de>"
249
+ "Philipp Muens <raute1337@gmx.de>",
250
+ "RasmusErik Voel Jensen <github@solsort.com>"
246
251
  ]
247
252
  }
@@ -116,7 +116,7 @@ class AutoRelay {
116
116
  this._peerStore.metadataBook.set(peerId, HOP_METADATA_KEY, uint8ArrayFromString(HOP_METADATA_VALUE))
117
117
  await this._addListenRelay(connection, id)
118
118
  }
119
- } catch (err) {
119
+ } catch (/** @type {any} */ err) {
120
120
  this._onError(err)
121
121
  }
122
122
  }
@@ -169,7 +169,7 @@ class AutoRelay {
169
169
  try {
170
170
  await this._transportManager.listen([new Multiaddr(listenAddr)])
171
171
  // Announce multiaddrs will update on listen success by TransportManager event being triggered
172
- } catch (err) {
172
+ } catch (/** @type {any} */ err) {
173
173
  this._onError(err)
174
174
  this._listenRelays.delete(id)
175
175
  }
@@ -267,7 +267,7 @@ class AutoRelay {
267
267
  return
268
268
  }
269
269
  }
270
- } catch (err) {
270
+ } catch (/** @type {any} */ err) {
271
271
  this._onError(err)
272
272
  }
273
273
  }
@@ -279,7 +279,7 @@ class AutoRelay {
279
279
  try {
280
280
  const connection = await this._libp2p.dial(peerId)
281
281
  await this._addListenRelay(connection, peerId.toB58String())
282
- } catch (err) {
282
+ } catch (/** @type {any} */ err) {
283
283
  this._onError(err, `could not connect and listen on known hop relay ${peerId.toB58String()}`)
284
284
  }
285
285
  }
@@ -54,7 +54,7 @@ async function handleHop ({
54
54
  // Validate the HOP request has the required input
55
55
  try {
56
56
  validateAddrs(request, streamHandler)
57
- } catch (err) {
57
+ } catch (/** @type {any} */ err) {
58
58
  return log.error('invalid hop request via peer %s', connection.remotePeer.toB58String(), err)
59
59
  }
60
60
 
@@ -93,7 +93,7 @@ async function handleHop ({
93
93
  connection: destinationConnection,
94
94
  request: stopRequest
95
95
  })
96
- } catch (err) {
96
+ } catch (/** @type {any} */ err) {
97
97
  return log.error(err)
98
98
  }
99
99
 
@@ -34,7 +34,7 @@ module.exports.handleStop = function handleStop ({
34
34
  // Validate the STOP request has the required input
35
35
  try {
36
36
  validateAddrs(request, streamHandler)
37
- } catch (err) {
37
+ } catch (/** @type {any} */ err) {
38
38
  return log.error('invalid stop request via peer %s', connection.remotePeer.toB58String(), err)
39
39
  }
40
40
 
@@ -34,7 +34,7 @@ function validateAddrs (msg, streamHandler) {
34
34
  return new Multiaddr(addr)
35
35
  })
36
36
  }
37
- } catch (err) {
37
+ } catch (/** @type {any} */ err) {
38
38
  writeResponse(streamHandler, msg.type === CircuitRelay.Type.HOP
39
39
  ? CircuitRelay.Status.HOP_DST_MULTIADDR_INVALID
40
40
  : CircuitRelay.Status.STOP_DST_MULTIADDR_INVALID)
@@ -47,7 +47,7 @@ function validateAddrs (msg, streamHandler) {
47
47
  return new Multiaddr(addr)
48
48
  })
49
49
  }
50
- } catch (err) {
50
+ } catch (/** @type {any} */ err) {
51
51
  writeResponse(streamHandler, msg.type === CircuitRelay.Type.HOP
52
52
  ? CircuitRelay.Status.HOP_SRC_MULTIADDR_INVALID
53
53
  : CircuitRelay.Status.STOP_SRC_MULTIADDR_INVALID)
@@ -87,7 +87,7 @@ class Relay {
87
87
  try {
88
88
  const cid = await namespaceToCid(RELAY_RENDEZVOUS_NS)
89
89
  await this._libp2p.contentRouting.provide(cid)
90
- } catch (err) {
90
+ } catch (/** @type {any} */ err) {
91
91
  if (err.code === 'NO_ROUTERS_AVAILABLE') {
92
92
  log.error('a content router, such as a DHT, must be provided in order to advertise the relay service', err)
93
93
  // Stop the advertise
@@ -171,7 +171,7 @@ class Circuit {
171
171
  log('new outbound connection %s', maConn.remoteAddr)
172
172
 
173
173
  return this._upgrader.upgradeOutbound(maConn)
174
- } catch (err) {
174
+ } catch (/** @type {any} */ err) {
175
175
  log.error('Circuit relay dial failed', err)
176
176
  disconnectOnFailure && await relayConnection.close()
177
177
  throw err
@@ -0,0 +1,118 @@
1
+ 'use strict'
2
+
3
+ const debug = require('debug')
4
+ const mergeOptions = require('merge-options')
5
+ // @ts-ignore retimer does not have types
6
+ const retimer = require('retimer')
7
+
8
+ const log = Object.assign(debug('libp2p:connection-manager:auto-dialler'), {
9
+ error: debug('libp2p:connection-manager:auto-dialler:err')
10
+ })
11
+
12
+ const defaultOptions = {
13
+ enabled: true,
14
+ minConnections: 0,
15
+ autoDialInterval: 10000
16
+ }
17
+
18
+ /**
19
+ * @typedef {import('../index')} Libp2p
20
+ * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
21
+ */
22
+
23
+ /**
24
+ * @typedef {Object} AutoDiallerOptions
25
+ * @property {boolean} [enabled = true] - Should preemptively guarantee connections are above the low watermark
26
+ * @property {number} [minConnections = 0] - The minimum number of connections to avoid pruning
27
+ * @property {number} [autoDialInterval = 10000] - How often, in milliseconds, it should preemptively guarantee connections are above the low watermark
28
+ */
29
+
30
+ class AutoDialler {
31
+ /**
32
+ * Proactively tries to connect to known peers stored in the PeerStore.
33
+ * It will keep the number of connections below the upper limit and sort
34
+ * the peers to connect based on wether we know their keys and protocols.
35
+ *
36
+ * @class
37
+ * @param {Libp2p} libp2p
38
+ * @param {AutoDiallerOptions} options
39
+ */
40
+ constructor (libp2p, options = {}) {
41
+ this._options = mergeOptions.call({ ignoreUndefined: true }, defaultOptions, options)
42
+ this._libp2p = libp2p
43
+ this._running = false
44
+ this._autoDialTimeout = null
45
+ this._autoDial = this._autoDial.bind(this)
46
+
47
+ log('options: %j', this._options)
48
+ }
49
+
50
+ /**
51
+ * Starts the auto dialer
52
+ */
53
+ start () {
54
+ if (!this._options.enabled) {
55
+ log('not enabled')
56
+ return
57
+ }
58
+
59
+ this._running = true
60
+ this._autoDial()
61
+ log('started')
62
+ }
63
+
64
+ /**
65
+ * Stops the auto dialler
66
+ */
67
+ async stop () {
68
+ if (!this._options.enabled) {
69
+ log('not enabled')
70
+ return
71
+ }
72
+
73
+ this._running = false
74
+ this._autoDialTimeout && this._autoDialTimeout.clear()
75
+ log('stopped')
76
+ }
77
+
78
+ async _autoDial () {
79
+ const minConnections = this._options.minConnections
80
+
81
+ // Already has enough connections
82
+ if (this._libp2p.connections.size >= minConnections) {
83
+ this._autoDialTimeout = retimer(this._autoDial, this._options.autoDialInterval)
84
+ return
85
+ }
86
+
87
+ // Sort peers on wether we know protocols of public keys for them
88
+ const peers = Array.from(this._libp2p.peerStore.peers.values())
89
+ .sort((a, b) => {
90
+ if (b.protocols && b.protocols.length && (!a.protocols || !a.protocols.length)) {
91
+ return 1
92
+ } else if (b.id.pubKey && !a.id.pubKey) {
93
+ return 1
94
+ }
95
+ return -1
96
+ })
97
+
98
+ for (let i = 0; this._running && i < peers.length && this._libp2p.connections.size < minConnections; i++) {
99
+ if (!this._libp2p.connectionManager.get(peers[i].id)) {
100
+ log('connecting to a peerStore stored peer %s', peers[i].id.toB58String())
101
+ try {
102
+ await this._libp2p.dialer.connectToPeer(peers[i].id)
103
+ } catch (/** @type {any} */ err) {
104
+ log.error('could not connect to peerStore stored peer', err)
105
+ }
106
+ }
107
+ }
108
+
109
+ // Connection Manager was stopped
110
+ if (!this._running) {
111
+ return
112
+ }
113
+
114
+ this._autoDialTimeout = retimer(this._autoDial, this._options.autoDialInterval)
115
+ }
116
+ }
117
+
118
+ module.exports = AutoDialler
@@ -94,9 +94,7 @@ class ConnectionManager extends EventEmitter {
94
94
 
95
95
  this._started = false
96
96
  this._timer = null
97
- this._autoDialTimeout = null
98
97
  this._checkMetrics = this._checkMetrics.bind(this)
99
- this._autoDial = this._autoDial.bind(this)
100
98
 
101
99
  this._latencyMonitor = new LatencyMonitor({
102
100
  latencyCheckIntervalMs: this._options.pollInterval,
@@ -128,8 +126,6 @@ class ConnectionManager extends EventEmitter {
128
126
 
129
127
  this._started = true
130
128
  log('started')
131
-
132
- this._options.autoDial && this._autoDial()
133
129
  }
134
130
 
135
131
  /**
@@ -138,7 +134,6 @@ class ConnectionManager extends EventEmitter {
138
134
  * @async
139
135
  */
140
136
  async stop () {
141
- this._autoDialTimeout && this._autoDialTimeout.clear()
142
137
  this._timer && this._timer.clear()
143
138
 
144
139
  this._latencyMonitor.removeListener('data', this._onLatencyMeasure)
@@ -312,53 +307,6 @@ class ConnectionManager extends EventEmitter {
312
307
  }
313
308
  }
314
309
 
315
- /**
316
- * Proactively tries to connect to known peers stored in the PeerStore.
317
- * It will keep the number of connections below the upper limit and sort
318
- * the peers to connect based on wether we know their keys and protocols.
319
- *
320
- * @async
321
- * @private
322
- */
323
- async _autoDial () {
324
- const minConnections = this._options.minConnections
325
-
326
- // Already has enough connections
327
- if (this.size >= minConnections) {
328
- this._autoDialTimeout = retimer(this._autoDial, this._options.autoDialInterval)
329
- return
330
- }
331
-
332
- // Sort peers on wether we know protocols of public keys for them
333
- const peers = Array.from(this._libp2p.peerStore.peers.values())
334
- .sort((a, b) => {
335
- if (b.protocols && b.protocols.length && (!a.protocols || !a.protocols.length)) {
336
- return 1
337
- } else if (b.id.pubKey && !a.id.pubKey) {
338
- return 1
339
- }
340
- return -1
341
- })
342
-
343
- for (let i = 0; i < peers.length && this.size < minConnections; i++) {
344
- if (!this.get(peers[i].id)) {
345
- log('connecting to a peerStore stored peer %s', peers[i].id.toB58String())
346
- try {
347
- await this._libp2p.dialer.connectToPeer(peers[i].id)
348
-
349
- // Connection Manager was stopped
350
- if (!this._started) {
351
- return
352
- }
353
- } catch (err) {
354
- log.error('could not connect to peerStore stored peer', err)
355
- }
356
- }
357
- }
358
-
359
- this._autoDialTimeout = retimer(this._autoDial, this._options.autoDialInterval)
360
- }
361
-
362
310
  /**
363
311
  * If we have more connections than our maximum, close a connection
364
312
  * to the lowest valued peer.
@@ -8,9 +8,10 @@ const {
8
8
  requirePeers,
9
9
  maybeLimitSource
10
10
  } = require('./utils')
11
-
11
+ const drain = require('it-drain')
12
12
  const merge = require('it-merge')
13
13
  const { pipe } = require('it-pipe')
14
+ const { DHTContentRouting } = require('../dht/dht-content-routing')
14
15
 
15
16
  /**
16
17
  * @typedef {import('peer-id')} PeerId
@@ -38,7 +39,7 @@ class ContentRouting {
38
39
 
39
40
  // If we have the dht, add it to the available content routers
40
41
  if (this.dht && libp2p._config.dht.enabled) {
41
- this.routers.push(this.dht)
42
+ this.routers.push(new DHTContentRouting(this.dht))
42
43
  }
43
44
  }
44
45
 
@@ -91,12 +92,12 @@ class ContentRouting {
91
92
  * @param {number} [options.minPeers] - minimum number of peers required to successfully put
92
93
  * @returns {Promise<void>}
93
94
  */
94
- put (key, value, options) {
95
+ async put (key, value, options) {
95
96
  if (!this.libp2p.isStarted() || !this.dht.isStarted) {
96
97
  throw errCode(new Error(messages.NOT_STARTED_YET), codes.DHT_NOT_STARTED)
97
98
  }
98
99
 
99
- return this.dht.put(key, value, options)
100
+ await drain(this.dht.put(key, value, options))
100
101
  }
101
102
 
102
103
  /**
@@ -108,12 +109,18 @@ class ContentRouting {
108
109
  * @param {number} [options.timeout] - optional timeout (default: 60000)
109
110
  * @returns {Promise<GetData>}
110
111
  */
111
- get (key, options) {
112
+ async get (key, options) {
112
113
  if (!this.libp2p.isStarted() || !this.dht.isStarted) {
113
114
  throw errCode(new Error(messages.NOT_STARTED_YET), codes.DHT_NOT_STARTED)
114
115
  }
115
116
 
116
- return this.dht.get(key, options)
117
+ for await (const event of this.dht.get(key, options)) {
118
+ if (event.name === 'VALUE') {
119
+ return { from: event.peerId, val: event.value }
120
+ }
121
+ }
122
+
123
+ throw errCode(new Error(messages.NOT_FOUND), codes.ERR_NOT_FOUND)
117
124
  }
118
125
 
119
126
  /**
@@ -123,14 +130,33 @@ class ContentRouting {
123
130
  * @param {number} nVals
124
131
  * @param {Object} [options] - get options
125
132
  * @param {number} [options.timeout] - optional timeout (default: 60000)
126
- * @returns {Promise<GetData[]>}
127
133
  */
128
- async getMany (key, nVals, options) { // eslint-disable-line require-await
134
+ async * getMany (key, nVals, options) { // eslint-disable-line require-await
129
135
  if (!this.libp2p.isStarted() || !this.dht.isStarted) {
130
136
  throw errCode(new Error(messages.NOT_STARTED_YET), codes.DHT_NOT_STARTED)
131
137
  }
132
138
 
133
- return this.dht.getMany(key, nVals, options)
139
+ if (!nVals) {
140
+ return
141
+ }
142
+
143
+ let gotValues = 0
144
+
145
+ for await (const event of this.dht.get(key, options)) {
146
+ if (event.name === 'VALUE') {
147
+ yield { from: event.peerId, val: event.value }
148
+
149
+ gotValues++
150
+
151
+ if (gotValues === nVals) {
152
+ break
153
+ }
154
+ }
155
+ }
156
+
157
+ if (gotValues === 0) {
158
+ throw errCode(new Error(messages.NOT_FOUND), codes.ERR_NOT_FOUND)
159
+ }
134
160
  }
135
161
  }
136
162