diff --git a/nix/generated/node-packages.nix b/nix/generated/node-packages.nix index 4455c304d6..2755b03060 100644 --- a/nix/generated/node-packages.nix +++ b/nix/generated/node-packages.nix @@ -1813,15 +1813,6 @@ let sha512 = "p32cOF5q0Zqs9uBiONKYLm6BClCoBCM5O9JfeUSlnQLBTxYdTK+pW+nXflm8UkKd2UYlEbYz5qEi0JuZR9ckSw=="; }; }; - "asn1.js-5.4.1" = { - name = "asn1.js"; - packageName = "asn1.js"; - version = "5.4.1"; - src = fetchurl { - url = "https://registry.npmjs.org/asn1.js/-/asn1.js-5.4.1.tgz"; - sha512 = "+I//4cYPccV8LdmBLiX8CYvf9Sp3vQsrqu2QNXRcrbiWvcx/UdlFiqUJJzxRQxgsZmvhXhn4cSKeSmoFjVdupA=="; - }; - }; "assert-1.5.0" = { name = "assert"; packageName = "assert"; @@ -2830,6 +2821,15 @@ let sha1 = "7bde5ced145b6d551a90db87f83c558b4eb48a8f"; }; }; + "base-x-3.0.8" = { + name = "base-x"; + packageName = "base-x"; + version = "3.0.8"; + src = fetchurl { + url = "https://registry.npmjs.org/base-x/-/base-x-3.0.8.tgz"; + sha512 = "Rl/1AWP4J/zRrk54hhlxH4drNxPJXYUaKffODVI53/dAsV4t9fBxyxYKAVPU1XBHxYwOWP9h9H0hM2MVw4YfJA=="; + }; + }; "base64-js-1.3.0" = { name = "base64-js"; packageName = "base64-js"; @@ -4324,6 +4324,15 @@ let sha512 = "TLz+x/vEXm/Y7P7wn1EJFNLxYpUD4TgMosxY6fAVJUnJMbupHBOncxyWUG9OpTaH9EBD7uFI5LfEgmMOc54DsA=="; }; }; + "detect-node-2.0.4" = { + name = "detect-node"; + packageName = "detect-node"; + version = "2.0.4"; + src = fetchurl { + url = "https://registry.npmjs.org/detect-node/-/detect-node-2.0.4.tgz"; + sha512 = "ZIzRpLJrOj7jjP2miAtgqIfmzbxa4ZOr5jJc601zklsfEx9oTzmmj2nVpIPRpNlRTIh8lc1kyViIY7BWSGNmKw=="; + }; + }; "detective-4.7.1" = { name = "detective"; packageName = "detective"; @@ -4549,15 +4558,6 @@ let sha512 = "BsXLz5sqX8OHcsh7CqBMztyXARmGQ3LWPtGjJi6DiJHq5C/qvi9P3OqgswKSDftbu8+IoI/QDTAm2fFnQ9SZSQ=="; }; }; - "elliptic-6.5.3" = { - name = "elliptic"; - packageName = "elliptic"; - version = "6.5.3"; - src = fetchurl { - url = "https://registry.npmjs.org/elliptic/-/elliptic-6.5.3.tgz"; - sha512 = "IMqzv5wNQf+E6aHeIqATs0tOLeOTwj1QKbRcS3jBbYkl5oLAserA8yJTT7/VyHUYG91PRmPyeQDObKLPpeS4dw=="; - }; - }; "emoji-regex-6.1.1" = { name = "emoji-regex"; packageName = "emoji-regex"; @@ -4675,15 +4675,6 @@ let sha512 = "bHz59NlBbtS0NhftmR8+ExBEekE7br0e01jw+kk0NDro7TtZzBYZ5ScGPs3OmwnpyfHTHOtr1Y6uedCdrIldtg=="; }; }; - "err-code-2.0.3" = { - name = "err-code"; - packageName = "err-code"; - version = "2.0.3"; - src = fetchurl { - url = "https://registry.npmjs.org/err-code/-/err-code-2.0.3.tgz"; - sha512 = "2bmlRpNKBxT/CRmPOlyISQpNj+qSeYvcym/uT0Jx2bMOlKLtSy1ZmLuVxSEKKyor/N5yhvp/ZiG1oE3DEYMSFA=="; - }; - }; "errno-0.1.7" = { name = "errno"; packageName = "errno"; @@ -6907,15 +6898,6 @@ let sha1 = "e8fbf374dc556ff8947a10dcb0572d633f2cfa10"; }; }; - "iso-random-stream-1.1.1" = { - name = "iso-random-stream"; - packageName = "iso-random-stream"; - version = "1.1.1"; - src = fetchurl { - url = "https://registry.npmjs.org/iso-random-stream/-/iso-random-stream-1.1.1.tgz"; - sha512 = "YEt/7xOwTdu4KXIgtdgGFkiLUsBaddbnkmHyaFdjJYIcD7V4gpQHPvYC5tyh3kA0PQ01y9lWm1ruVdf8Mqzovg=="; - }; - }; "isobject-2.1.0" = { name = "isobject"; packageName = "isobject"; @@ -7564,6 +7546,15 @@ let sha512 = "KDncfTmOZoOMTFG4mBlG0qUIOlc03fmzH+ru6RgYVZhPkyiy/92Owlt/8UEN+a4TXR1FQetfIpJE8ApdvdVxTg=="; }; }; + "k-bucket-5.0.0" = { + name = "k-bucket"; + packageName = "k-bucket"; + version = "5.0.0"; + src = fetchurl { + url = "https://registry.npmjs.org/k-bucket/-/k-bucket-5.0.0.tgz"; + sha512 = "r/q+wV/Kde62/tk+rqyttEJn6h0jR7x+incdMVSYTqK73zVxVrzJa70kJL49cIKen8XjIgUZKSvk8ktnrQbK4w=="; + }; + }; "kbpgp-2.0.82" = { name = "kbpgp"; packageName = "kbpgp"; @@ -7600,15 +7591,6 @@ let sha1 = "3865831e9481516488df7cbd989467e950d87a8b"; }; }; - "keypair-1.0.1" = { - name = "keypair"; - packageName = "keypair"; - version = "1.0.1"; - src = fetchurl { - url = "https://registry.npmjs.org/keypair/-/keypair-1.0.1.tgz"; - sha1 = "7603719270afb6564ed38a22087a06fc9aa4ea1b"; - }; - }; "kind-of-3.2.2" = { name = "kind-of"; packageName = "kind-of"; @@ -7744,15 +7726,6 @@ let sha512 = "+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ=="; }; }; - "libp2p-crypto-0.18.0" = { - name = "libp2p-crypto"; - packageName = "libp2p-crypto"; - version = "0.18.0"; - src = fetchurl { - url = "https://registry.npmjs.org/libp2p-crypto/-/libp2p-crypto-0.18.0.tgz"; - sha512 = "zNMHDwf2J4t1LRjrBPMiSa4+14u0SfZRu66FyIVZtOnBGo3V/8imbJsOp8RPT8IgeHRN7EVIUt9lp8dcgXHMOw=="; - }; - }; "lines-and-columns-1.1.6" = { name = "lines-and-columns"; packageName = "lines-and-columns"; @@ -8716,6 +8689,15 @@ let sha512 = "xY8pX7V+ybyUpbYMxtjM9KAiD9ixtg5/JkeKUTD6xilfDv0vzzOFcCp4Ljb1UU3tSOM3VTZtKo63OmzOrGi3Cg=="; }; }; + "multibase-0.7.0" = { + name = "multibase"; + packageName = "multibase"; + version = "0.7.0"; + src = fetchurl { + url = "https://registry.npmjs.org/multibase/-/multibase-0.7.0.tgz"; + sha512 = "TW8q03O0f6PNFTQDvh3xxH03c8CjGaaYrjkl9UQPG6rz53TQzzxJVCIWVjzcbN/Q5Y53Zd0IBQBMVktVgNx4Fg=="; + }; + }; "multibase-3.0.1" = { name = "multibase"; packageName = "multibase"; @@ -8734,6 +8716,15 @@ let sha512 = "YDYeWn9iGa76hOHAyyZa0kbt3tr5FLg1ZXUHrZUJltjnxxdbTIbHnxWLd2zTcMOjdT3QyO+Xs4bQgJUcC2RWUA=="; }; }; + "multihashes-0.4.21" = { + name = "multihashes"; + packageName = "multihashes"; + version = "0.4.21"; + src = fetchurl { + url = "https://registry.npmjs.org/multihashes/-/multihashes-0.4.21.tgz"; + sha512 = "uVSvmeCWf36pU2nB4/1kzYZjsXD9vofZKpgudqkceYY5g2aZZXJ5r9lxuzoRLl1OAp28XljXsEJ/X/85ZsKmKw=="; + }; + }; "multihashes-3.0.1" = { name = "multihashes"; packageName = "multihashes"; @@ -8743,13 +8734,13 @@ let sha512 = "fFY67WOtb0359IjDZxaCU3gJILlkwkFbxbwrK9Bej5+NqNaYztzLOj8/NgMNMg/InxmhK+Uu8S/U4EcqsHzB7Q=="; }; }; - "multihashing-async-2.0.1" = { - name = "multihashing-async"; - packageName = "multihashing-async"; - version = "2.0.1"; + "multihashing-0.3.3" = { + name = "multihashing"; + packageName = "multihashing"; + version = "0.3.3"; src = fetchurl { - url = "https://registry.npmjs.org/multihashing-async/-/multihashing-async-2.0.1.tgz"; - sha512 = "LZcH8PqW4iEKymaJ3RpsgpSJhXF29kAvO02ccqbysiXkQhZpVce8rrg+vzRKWO89hhyIBnQHI2e/ZoRVxmiJ2Q=="; + url = "https://registry.npmjs.org/multihashing/-/multihashing-0.3.3.tgz"; + sha512 = "jXVWf5uqnZUhc1mLFPWOssuOpkj/A/vVLKrtEscD1PzSLobXYocBy9Gqa/Aw4229/heGnl0RBHU3cD53MbHUig=="; }; }; "multimatch-4.0.0" = { @@ -8761,15 +8752,6 @@ let sha512 = "lDmx79y1z6i7RNx0ZGCPq1bzJ6ZoDDKbvh7jxr9SJcWLkShMzXrHbYVpTdnhNM5MXpDUxCQ4DgqVttVXlBgiBQ=="; }; }; - "murmurhash3js-revisited-3.0.0" = { - name = "murmurhash3js-revisited"; - packageName = "murmurhash3js-revisited"; - version = "3.0.0"; - src = fetchurl { - url = "https://registry.npmjs.org/murmurhash3js-revisited/-/murmurhash3js-revisited-3.0.0.tgz"; - sha512 = "/sF3ee6zvScXMb1XFJ8gDsSnY+X8PbOyjIuBhtgis10W2Jx4ZjIhikUCIF9c4gpJxVnQIsPAFrSwTCuAjicP6g=="; - }; - }; "mv-2.1.1" = { name = "mv"; packageName = "mv"; @@ -8851,15 +8833,6 @@ let sha512 = "1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ=="; }; }; - "node-addon-api-2.0.2" = { - name = "node-addon-api"; - packageName = "node-addon-api"; - version = "2.0.2"; - src = fetchurl { - url = "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.2.tgz"; - sha512 = "Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA=="; - }; - }; "node-fetch-2.6.1" = { name = "node-fetch"; packageName = "node-fetch"; @@ -8887,15 +8860,6 @@ let sha512 = "naKSScof4Wn+aoHU6HBsifh92Zeicm1GDQKd1vp3Y/kOi8ub0DozCa9KpvYNCXslFHYRmLNiqRopGdTGwNLpNw=="; }; }; - "node-gyp-build-4.2.3" = { - name = "node-gyp-build"; - packageName = "node-gyp-build"; - version = "4.2.3"; - src = fetchurl { - url = "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.2.3.tgz"; - sha512 = "MN6ZpzmfNCRM+3t57PTJHgHyw/h4OWnZ6mR8P5j/uZtqQr46RRuDE/P+g3n0YR/AiYXeWixZZzaip77gdICfRg=="; - }; - }; "node-int64-0.4.0" = { name = "node-int64"; packageName = "node-int64"; @@ -9760,24 +9724,6 @@ let sha512 = "U/il5MsrZp7mGg3mSQfn742na2T+1/vHDCG5/iTI3X9MKUuYUZVLQhyRsg06mCgDBTd57TxzgZt7P+fYfjRLtA=="; }; }; - "peer-id-0.14.2" = { - name = "peer-id"; - packageName = "peer-id"; - version = "0.14.2"; - src = fetchurl { - url = "https://registry.npmjs.org/peer-id/-/peer-id-0.14.2.tgz"; - sha512 = "8iZWaUT7jq8rVyyFZUHYUwFCvhoI5B1Q2MAJjUF9MTf4TsNRQPnod4Mycf2jrK/uXFBN5/9K1NhPoieFyz/PRw=="; - }; - }; - "pem-jwk-2.0.0" = { - name = "pem-jwk"; - packageName = "pem-jwk"; - version = "2.0.0"; - src = fetchurl { - url = "https://registry.npmjs.org/pem-jwk/-/pem-jwk-2.0.0.tgz"; - sha512 = "rFxu7rVoHgQ5H9YsP50dDWf0rHjreVA2z0yPiWr5WdH/UHb29hKtF7h6l8vNd1cbYR1t0QL+JKhW55a2ZV4KtA=="; - }; - }; "performance-now-2.1.0" = { name = "performance-now"; packageName = "performance-now"; @@ -10102,15 +10048,6 @@ let sha1 = "991c407e99de264aadf8f81504b5e7faf7bfa260"; }; }; - "protocol-buffers-schema-3.4.0" = { - name = "protocol-buffers-schema"; - packageName = "protocol-buffers-schema"; - version = "3.4.0"; - src = fetchurl { - url = "https://registry.npmjs.org/protocol-buffers-schema/-/protocol-buffers-schema-3.4.0.tgz"; - sha512 = "G/2kcamPF2S49W5yaMGdIpkG6+5wZF0fzBteLKgEHjbNzqjZQ85aAs1iJGto31EJaSTkNvHs5IXuHSaTLWBAiA=="; - }; - }; "protocols-1.4.6" = { name = "protocols"; packageName = "protocols"; @@ -10120,15 +10057,6 @@ let sha1 = "f8bb263ea1b5fd7a7604d26b8be39bd77678bf8a"; }; }; - "protons-2.0.0" = { - name = "protons"; - packageName = "protons"; - version = "2.0.0"; - src = fetchurl { - url = "https://registry.npmjs.org/protons/-/protons-2.0.0.tgz"; - sha512 = "BTrE9D6/d1NGis+0D8TqAO1THdn4evHQhfjapA0NUaRH4+ecJJcbqaF7TE/DKv5czE9VB/TeOllBOmCyJhHnhg=="; - }; - }; "proxy-addr-2.0.6" = { name = "proxy-addr"; packageName = "proxy-addr"; @@ -11074,15 +11002,6 @@ let sha512 = "0ilKFI6QQF5nxDZLFn2dMjvc4hjg/Wkg7rHd3jK6/A4a1Hl9VFdQWvgB1UMGoU94pad1P/8N7fMcEnLnSiju8A=="; }; }; - "secp256k1-4.0.2" = { - name = "secp256k1"; - packageName = "secp256k1"; - version = "4.0.2"; - src = fetchurl { - url = "https://registry.npmjs.org/secp256k1/-/secp256k1-4.0.2.tgz"; - sha512 = "UDar4sKvWAksIlfX3xIaQReADn+WFnHvbVujpcbr+9Sf/69odMwy2MUsz5CKLQgX9nsIyrjuxL2imVyoNHa3fg=="; - }; - }; "secure-random-bytes-1.0.1" = { name = "secure-random-bytes"; packageName = "secure-random-bytes"; @@ -11308,15 +11227,6 @@ let sha1 = "b5fdc08f1287ea1178628e415e25132b73646c6d"; }; }; - "signed-varint-2.0.1" = { - name = "signed-varint"; - packageName = "signed-varint"; - version = "2.0.1"; - src = fetchurl { - url = "https://registry.npmjs.org/signed-varint/-/signed-varint-2.0.1.tgz"; - sha1 = "50a9989da7c98c2c61dad119bc97470ef8528129"; - }; - }; "simple-concat-1.0.1" = { name = "simple-concat"; packageName = "simple-concat"; @@ -12892,15 +12802,6 @@ let sha1 = "3838e97cfc60521eb73c525a8e55bfdd9e2e28f1"; }; }; - "ursa-optional-0.10.1" = { - name = "ursa-optional"; - packageName = "ursa-optional"; - version = "0.10.1"; - src = fetchurl { - url = "https://registry.npmjs.org/ursa-optional/-/ursa-optional-0.10.1.tgz"; - sha512 = "/pgpBXVJut57dHNrdGF+1/qXi+5B7JrlmZDWPSyoivEcbwFWRZJBJGkWb6ivknMBA3bnFA7lqsb6iHiFfp79QQ=="; - }; - }; "use-3.1.1" = { name = "use"; packageName = "use"; @@ -13189,6 +13090,15 @@ let sha512 = "DcXs2lbVPzuJmn2kuDEwul2oZg7p4YMa5J2f0YzsOBHaAnBYGPNUB/rJ74DTjTKpw7F0+lSsVM8sFHE2UyBixg=="; }; }; + "webcrypto-0.1.1" = { + name = "webcrypto"; + packageName = "webcrypto"; + version = "0.1.1"; + src = fetchurl { + url = "https://registry.npmjs.org/webcrypto/-/webcrypto-0.1.1.tgz"; + sha512 = "BAvoatS38TbHdyt42ECLroi27NmDh5iea5l5rHC6nZTZjlbJlndrT0FoIiEq7fmPHpmNtP0lMFKVMEKZQFIrGA=="; + }; + }; "webidl-conversions-4.0.2" = { name = "webidl-conversions"; packageName = "webidl-conversions"; @@ -14229,6 +14139,7 @@ let sources."kind-of-6.0.2" ]; }) + sources."base-x-3.0.8" sources."base64-js-1.3.0" (sources."bcrypt-pbkdf-1.0.2" // { dependencies = [ @@ -14469,6 +14380,7 @@ let sources."detect-file-1.0.0" sources."detect-indent-4.0.0" sources."detect-newline-3.1.0" + sources."detect-node-2.0.4" sources."detective-4.7.1" sources."diagnostics-1.1.1" (sources."dicer-0.2.5" // { @@ -14636,7 +14548,6 @@ let sources."enhanced-resolve-4.1.1" sources."enquirer-2.3.6" sources."env-variable-0.0.6" - sources."err-code-2.0.3" sources."errno-0.1.7" sources."error-7.0.2" sources."error-ex-1.3.2" @@ -15073,7 +14984,6 @@ let sources."is-wsl-2.1.1" sources."isarray-1.0.0" sources."isexe-2.0.0" - sources."iso-random-stream-1.1.1" (sources."isomorphic-git-1.7.4" // { dependencies = [ sources."pako-1.0.11" @@ -15515,6 +15425,7 @@ let sources."jsprim-1.4.1" sources."jwa-2.0.0" sources."jws-4.0.0" + sources."k-bucket-5.0.0" (sources."kbpgp-2.0.82" // { dependencies = [ sources."deep-equal-1.0.1" @@ -15529,7 +15440,6 @@ let sources."tweetnacl-0.13.3" ]; }) - sources."keypair-1.0.1" sources."kind-of-3.2.2" sources."kleur-3.0.3" sources."kuler-1.0.1" @@ -15543,7 +15453,6 @@ let sources."lead-1.0.0" sources."leven-3.1.0" sources."levn-0.3.0" - sources."libp2p-crypto-0.18.0" sources."lines-and-columns-1.1.6" sources."livereload-js-2.3.0" sources."load-json-file-2.0.0" @@ -15701,9 +15610,13 @@ let ]; }) sources."multihashes-3.0.1" - sources."multihashing-async-2.0.1" + (sources."multihashing-0.3.3" // { + dependencies = [ + sources."multibase-0.7.0" + sources."multihashes-0.4.21" + ]; + }) sources."multimatch-4.0.0" - sources."murmurhash3js-revisited-3.0.0" (sources."mv-2.1.1" // { dependencies = [ sources."glob-6.0.4" @@ -15723,10 +15636,8 @@ let sources."negotiator-0.6.2" sources."neo-async-2.6.1" sources."nice-try-1.0.5" - sources."node-addon-api-2.0.2" sources."node-fetch-2.6.1" sources."node-forge-0.9.2" - sources."node-gyp-build-4.2.3" sources."node-int64-0.4.0" (sources."node-libs-browser-2.2.1" // { dependencies = [ @@ -15862,16 +15773,6 @@ let sources."sha.js-2.4.11" ]; }) - (sources."peer-id-0.14.2" // { - dependencies = [ - sources."minimist-1.2.5" - ]; - }) - (sources."pem-jwk-2.0.0" // { - dependencies = [ - sources."asn1.js-5.4.1" - ]; - }) sources."performance-now-2.1.0" sources."permaproxy-0.0.2" sources."pgp-utils-0.0.34" @@ -15928,9 +15829,7 @@ let sources."property-information-3.2.0" sources."protobufjs-6.9.0" sources."protochain-1.0.5" - sources."protocol-buffers-schema-3.4.0" sources."protocols-1.4.6" - sources."protons-2.0.0" sources."proxy-addr-2.0.6" sources."prr-1.0.1" sources."pseudomap-1.0.2" @@ -16106,11 +16005,6 @@ let }) sources."saxes-3.1.11" sources."schema-utils-1.0.0" - (sources."secp256k1-4.0.2" // { - dependencies = [ - sources."elliptic-6.5.3" - ]; - }) sources."secure-random-bytes-1.0.1" sources."secure-random-octet-1.0.2" sources."semver-5.5.1" @@ -16140,7 +16034,6 @@ let sources."shelljs-0.8.4" sources."shellwords-0.1.1" sources."signal-exit-3.0.2" - sources."signed-varint-2.0.1" sources."simple-concat-1.0.1" sources."simple-get-3.1.0" (sources."simple-swizzle-0.2.2" // { @@ -16493,7 +16386,6 @@ let sources."punycode-1.3.2" ]; }) - sources."ursa-optional-0.10.1" sources."use-3.1.1" sources."util-0.11.1" sources."util-deprecate-1.0.2" @@ -16616,6 +16508,7 @@ let ]; }) sources."web-encoding-1.0.4" + sources."webcrypto-0.1.1" sources."webidl-conversions-4.0.2" (sources."webpack-4.43.0" // { dependencies = [ diff --git a/proto/js/Peer.d.ts b/proto/js/Peer.d.ts index 2cf9a1ecca..73db698762 100644 --- a/proto/js/Peer.d.ts +++ b/proto/js/Peer.d.ts @@ -1282,8 +1282,8 @@ declare namespace Peer { /** PeerDHTFindNodeMessage publicKey */ publicKey?: (string|null); - /** PeerDHTFindNodeMessage kNodes */ - kNodes?: (string[]|null); + /** PeerDHTFindNodeMessage closestPeers */ + closestPeers?: (peerInterface.IPeerInfoMessage[]|null); } /** Represents a PeerDHTFindNodeMessage. */ @@ -1298,8 +1298,8 @@ declare namespace Peer { /** PeerDHTFindNodeMessage publicKey. */ public publicKey: string; - /** PeerDHTFindNodeMessage kNodes. */ - public kNodes: string[]; + /** PeerDHTFindNodeMessage closestPeers. */ + public closestPeers: peerInterface.IPeerInfoMessage[]; /** * Creates a new PeerDHTFindNodeMessage instance using the specified properties. diff --git a/proto/js/Peer.js b/proto/js/Peer.js index 348b373002..e7558748cb 100644 --- a/proto/js/Peer.js +++ b/proto/js/Peer.js @@ -2544,7 +2544,7 @@ $root.peerInterface = (function() { * @memberof peerInterface * @interface IPeerDHTFindNodeMessage * @property {string|null} [publicKey] PeerDHTFindNodeMessage publicKey - * @property {Array.|null} [kNodes] PeerDHTFindNodeMessage kNodes + * @property {Array.|null} [closestPeers] PeerDHTFindNodeMessage closestPeers */ /** @@ -2556,7 +2556,7 @@ $root.peerInterface = (function() { * @param {peerInterface.IPeerDHTFindNodeMessage=} [p] Properties to set */ function PeerDHTFindNodeMessage(p) { - this.kNodes = []; + this.closestPeers = []; if (p) for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) if (p[ks[i]] != null) @@ -2572,12 +2572,12 @@ $root.peerInterface = (function() { PeerDHTFindNodeMessage.prototype.publicKey = ""; /** - * PeerDHTFindNodeMessage kNodes. - * @member {Array.} kNodes + * PeerDHTFindNodeMessage closestPeers. + * @member {Array.} closestPeers * @memberof peerInterface.PeerDHTFindNodeMessage * @instance */ - PeerDHTFindNodeMessage.prototype.kNodes = $util.emptyArray; + PeerDHTFindNodeMessage.prototype.closestPeers = $util.emptyArray; /** * Creates a new PeerDHTFindNodeMessage instance using the specified properties. @@ -2605,9 +2605,9 @@ $root.peerInterface = (function() { w = $Writer.create(); if (m.publicKey != null && Object.hasOwnProperty.call(m, "publicKey")) w.uint32(10).string(m.publicKey); - if (m.kNodes != null && m.kNodes.length) { - for (var i = 0; i < m.kNodes.length; ++i) - w.uint32(18).string(m.kNodes[i]); + if (m.closestPeers != null && m.closestPeers.length) { + for (var i = 0; i < m.closestPeers.length; ++i) + $root.peerInterface.PeerInfoMessage.encode(m.closestPeers[i], w.uint32(18).fork()).ldelim(); } return w; }; @@ -2647,9 +2647,9 @@ $root.peerInterface = (function() { m.publicKey = r.string(); break; case 2: - if (!(m.kNodes && m.kNodes.length)) - m.kNodes = []; - m.kNodes.push(r.string()); + if (!(m.closestPeers && m.closestPeers.length)) + m.closestPeers = []; + m.closestPeers.push($root.peerInterface.PeerInfoMessage.decode(r, r.uint32())); break; default: r.skipType(t & 7); diff --git a/src/agent/PolykeyAgent.ts b/src/agent/PolykeyAgent.ts index af05a672db..8a85b0d2e1 100644 --- a/src/agent/PolykeyAgent.ts +++ b/src/agent/PolykeyAgent.ts @@ -517,6 +517,7 @@ class PolykeyAgent implements IAgentServer { const publicKeys = this.pk.peerManager.listPeers(); const response = new agent.StringListMessage(); response.setSList(publicKeys); + callback(null, response); } catch (error) { callback(error, null); } @@ -868,10 +869,11 @@ class PolykeyAgent implements IAgentServer { try { this.failOnLocked(); const { publicKey, peerAddress, apiAddress } = call.request!.toObject(); - if (!this.pk.peerManager.hasPeer(publicKey)) { + const peerId = PeerInfo.publicKeyToId(publicKey) + if (!this.pk.peerManager.hasPeer(peerId)) { throw Error('peer does not exist in store'); } - const peerInfo = this.pk.peerManager.getPeer(publicKey)!; + const peerInfo = this.pk.peerManager.getPeer(peerId)!; peerInfo.peerAddress = Address.parse(peerAddress); peerInfo.apiAddress = Address.parse(apiAddress); this.pk.peerManager.updatePeer(peerInfo); diff --git a/src/bin/peers/peerCommands.ts b/src/bin/peers/peerCommands.ts index 1f9a310671..0b76c2d335 100644 --- a/src/bin/peers/peerCommands.ts +++ b/src/bin/peers/peerCommands.ts @@ -86,20 +86,13 @@ function makeGetPeerInfoCommand() { .option('-k, --node-path ', 'provide the polykey path') .option('-b64, --base64', 'output peer info as a base64 string') .option('-cn, --current-node', 'only list the peer information for the current node, useful for sharing') - .option('-pk, --public-key ', 'path to the file which contains the public key') + .option('-pi, --peer-id ', 'unique hash of public key that identifies the peer') .option('-v, --verbose', 'increase verbosity level by one') .action( actionRunner(async (options) => { const nodePath = determineNodePath(options.nodePath); const client = await getAgentClient(nodePath); - const publicKeyPath = options.publicKey; - // read in publicKey if it exists - let publicKey: string | undefined; - if (publicKeyPath) { - publicKey = fs.readFileSync(publicKeyPath).toString(); - } - let res: pb.PeerInfoMessage; if (options.currentNode) { res = (await promisifyGrpc(client.getLocalPeerInfo.bind(client))( @@ -107,7 +100,7 @@ function makeGetPeerInfoCommand() { )) as pb.PeerInfoMessage; } else { const request = new pb.StringMessage(); - request.setS(publicKey!); + request.setS(options.peerId!); res = (await promisifyGrpc(client.getPeerInfo.bind(client))(request)) as pb.PeerInfoMessage; } const peerInfo = new PeerInfo( @@ -119,6 +112,9 @@ function makeGetPeerInfoCommand() { if (options.base64) { pkLogger(peerInfo.toStringB64(), PKMessageType.SUCCESS); } else { + pkLogger('Peer Id:', PKMessageType.INFO); + pkLogger(peerInfo.id, PKMessageType.SUCCESS); + pkLogger('Peer Public Key:', PKMessageType.INFO); pkLogger(peerInfo.publicKey, PKMessageType.SUCCESS); diff --git a/src/peers/PeerInfo.ts b/src/peers/PeerInfo.ts index 7cb53351be..0f1df4ed72 100644 --- a/src/peers/PeerInfo.ts +++ b/src/peers/PeerInfo.ts @@ -92,7 +92,6 @@ class PeerInfo { } } - public get publicKey() : string { return this.readonlyPublicKey } diff --git a/src/peers/PeerManager.ts b/src/peers/PeerManager.ts index 62def09202..6ea42a2747 100644 --- a/src/peers/PeerManager.ts +++ b/src/peers/PeerManager.ts @@ -40,6 +40,7 @@ class PeerManager { private peerStoreMetadataPath: string; peerInfo: PeerInfo; + // peerId -> PeerInfo private peerStore: Map; private keyManager: KeyManager; multicastBroadcaster: MulticastBroadcaster; @@ -63,10 +64,11 @@ class PeerManager { this.fileSystem = fileSystem; this.peerStore = new Map(); + this.peerRelayClients = new Map(); this.fileSystem.mkdirSync(polykeyPath, { recursive: true }); - this.peerInfoMetadataPath = path.join(polykeyPath, '.peerInfo'); - this.peerStoreMetadataPath = path.join(polykeyPath, '.peerStore'); + this.peerInfoMetadataPath = path.join(polykeyPath, '.peers', '.peerInfo'); + this.peerStoreMetadataPath = path.join(polykeyPath, '.peers', '.peerStore'); // Set given variables this.keyManager = keyManager; @@ -97,15 +99,20 @@ class PeerManager { this.peerServer = new PeerServer(this, this.keyManager); this.peerConnections = new Map(); - /////////////////// - // Relay Clients // - /////////////////// - this.peerRelayClients = new Map(); + ////////////// + // Peer DHT // + ////////////// this.peerDHT = new PeerDHT( polykeyPath, this.fileSystem, - this.peerInfo.publicKey, - this.connectToPeer.bind(this) + (() => this.peerInfo.id), + this.connectToPeer.bind(this), + ((id: string) => this.getPeer(id)).bind(this), + ((peerInfo: PeerInfo) => { + if (!this.hasPeer(peerInfo.id)) { + this.addPeer(peerInfo) + } + }).bind(this) ) } @@ -138,8 +145,8 @@ class PeerManager { if (this.hasPeer(publicKey)) { throw Error('peer already exists in peer store'); } - this.peerStore.set(publicKey, peerInfo.deepCopy()); - this.peerRelayClients.set(publicKey, new RelayClient(publicKey, this)) + this.peerStore.set(peerInfo.id, peerInfo.deepCopy()); + this.peerRelayClients.set(peerInfo.id, new RelayClient(publicKey, this)) this.writeMetadata(); } @@ -148,12 +155,11 @@ class PeerManager { * @param peerInfo Info of the peer to be updated */ updatePeer(peerInfo: PeerInfo): void { - const publicKey = PeerInfo.formatPublicKey(peerInfo.publicKey); - if (!this.hasPeer(publicKey)) { + if (!this.hasPeer(peerInfo.id)) { throw Error('peer does not exist in peer store'); } - this.peerStore.set(publicKey, peerInfo.deepCopy()); - this.peerRelayClients.get(publicKey)?.resetConnection() + this.peerStore.set(peerInfo.id, peerInfo.deepCopy()); + this.peerRelayClients.get(peerInfo.id)?.resetConnection() this.writeMetadata(); } @@ -161,37 +167,37 @@ class PeerManager { * Delete a peer from the peerStore * @param peerInfo Info of the peer to be updated */ - deletePeer(publicKey: string): void { - if (!this.hasPeer(publicKey)) { + deletePeer(id: string): void { + if (!this.hasPeer(id)) { throw Error('peer does not exist in peer store'); } - this.peerStore.delete(publicKey); - this.peerRelayClients.get(publicKey)?.terminate() - this.peerRelayClients.delete(publicKey) + this.peerStore.delete(id); + this.peerRelayClients.get(id)?.terminate() + this.peerRelayClients.delete(id) this.writeMetadata(); } /** * Retrieves a peer for the given public key - * @param publicKey Public key of the desired peer + * @param publicKey ID of the desired peer */ - getPeer(publicKey: string): PeerInfo | null { - return this.peerStore.get(PeerInfo.formatPublicKey(publicKey))?.deepCopy() ?? null; + getPeer(id: string): PeerInfo | null { + return this.peerStore.get(id)?.deepCopy() ?? null; } /** * Determines if the peerStore contains the desired peer - * @param publicKey Public key of the desired peer + * @param id ID of the desired peer */ - hasPeer(publicKey: string): boolean { - return this.peerStore.has(PeerInfo.formatPublicKey(publicKey)); + hasPeer(id: string): boolean { + return this.peerStore.has(id); } /** * List all peer public keys in the peer store */ listPeers(): string[] { - return Array.from(this.peerStore.values()).map((p) => p.publicKey); + return Array.from(this.peerStore.values()).map((p) => p.id); } ////////////////////// @@ -238,21 +244,21 @@ class PeerManager { * Get a secure connection to the peer * @param publicKey Public key of an existing peer or address of new peer */ - connectToPeer(publicKey: string): PeerConnection { + connectToPeer(peerId: string): PeerConnection { // Throw error if trying to connect to self - if (publicKey == this.peerInfo.publicKey) { + if (peerId == this.peerInfo.id) { throw Error('Cannot connect to self'); } - const existingSocket = this.peerConnections.get(publicKey); + const existingSocket = this.peerConnections.get(peerId); if (existingSocket) { return existingSocket; } // try to create a connection to the address - const peerConnection = new PeerConnection(publicKey, this.keyManager, this); + const peerConnection = new PeerConnection(peerId, this.keyManager, this); - this.peerConnections.set(publicKey, peerConnection); + this.peerConnections.set(peerId, peerConnection); return peerConnection; } @@ -271,7 +277,6 @@ class PeerManager { peerAddress: peerInfo.peerAddress?.toString(), apiAddress: peerInfo.apiAddress?.toString(), }).finish(); - console.log(this.peerInfoMetadataPath); this.fileSystem.writeFileSync(this.peerInfoMetadataPath, metadata); // write peer store @@ -308,8 +313,8 @@ class PeerManager { peerInfoMessage.peerAddress ?? undefined, peerInfoMessage.apiAddress ?? undefined, ); - this.peerRelayClients.set(peerInfo.publicKey, new RelayClient(peerInfo.publicKey, this)) - this.peerStore.set(peerInfo.publicKey, peerInfo); + this.peerStore.set(peerInfo.id, peerInfo); + this.peerRelayClients.set(peerInfo.id, new RelayClient(peerInfo.publicKey, this)) } } } diff --git a/src/peers/peer-connection/PeerConnection.ts b/src/peers/peer-connection/PeerConnection.ts index bd97578feb..36a3c903fb 100644 --- a/src/peers/peer-connection/PeerConnection.ts +++ b/src/peers/peer-connection/PeerConnection.ts @@ -8,7 +8,7 @@ import { PeerClient } from '../../../proto/compiled/Peer_grpc_pb'; import { PeerMessage, SubServiceType } from '../../../proto/compiled/Peer_pb'; class PeerConnection { - private publicKey: string; + private peerId: string; private keyManager: KeyManager; private peerManager: PeerManager; @@ -16,8 +16,8 @@ class PeerConnection { private connected: boolean = false; private credentials: grpc.ChannelCredentials; - constructor(publicKey: string, keyManager: KeyManager, peerManager: PeerManager) { - this.publicKey = publicKey; + constructor(peerId: string, keyManager: KeyManager, peerManager: PeerManager) { + this.peerId = peerId; this.keyManager = keyManager; this.peerManager = peerManager; @@ -132,10 +132,10 @@ class PeerConnection { } private getPeerInfo() { - if (!this.peerManager.hasPeer(this.publicKey)) { + if (!this.peerManager.hasPeer(this.peerId)) { throw Error('peer does not exist in peer store'); } - return this.peerManager.getPeer(this.publicKey)!; + return this.peerManager.getPeer(this.peerId)!; } private async sendPingRequest(timeout?: number): Promise { @@ -209,7 +209,7 @@ class PeerConnection { private async encodeRequest(type: SubServiceType, request: Uint8Array): Promise { // encrypt message const requestString = protobufToString(request); - const encryptedMessage = await this.keyManager.encryptData(Buffer.from(requestString), Buffer.from(this.publicKey)); + const encryptedMessage = await this.keyManager.encryptData(Buffer.from(requestString), Buffer.from(this.getPeerInfo().publicKey)); // sign message const signedMessage = await this.keyManager.signData(encryptedMessage); const subMessage = signedMessage.toString(); diff --git a/src/peers/peer-dht/KBucket.ts b/src/peers/peer-dht/KBucket.ts index 6c8986d8e4..d574918e7f 100644 --- a/src/peers/peer-dht/KBucket.ts +++ b/src/peers/peer-dht/KBucket.ts @@ -27,20 +27,19 @@ export type PeerContact = { * contact (peer node) information. */ class KBucket { - localPeerId: Uint8Array + private getPeerId: () => string - pingNode: (oldContacts: string[], newContact: string) => void + private pingNode: (oldContacts: string[], newContact: string) => void numberOfNodesPerKBucket: number - numberOfNodesToPing: number - root: Node + private numberOfNodesToPing: number + private root: Node constructor( - publicKey: string, + getPeerId: () => string, pingNode: (oldContacts: string[], newContact: string) => void ) { - const id = PeerInfo.publicKeyToId(publicKey) - this.localPeerId = this.peerIdToU8(id) + this.getPeerId = getPeerId this.pingNode = pingNode // standard configuration @@ -51,6 +50,11 @@ class KBucket { this.root = createNode() } + public get localPeerId() : Uint8Array { + const id = this.getPeerId() + return this.peerIdToU8(id) + } + /** * Default arbiter function for contacts with the same id. Uses * contact.vectorClock to select which contact to update the k-bucket with. diff --git a/src/peers/peer-dht/KademliaDHT.ts b/src/peers/peer-dht/KademliaDHT.ts deleted file mode 100644 index 10407adae7..0000000000 --- a/src/peers/peer-dht/KademliaDHT.ts +++ /dev/null @@ -1,151 +0,0 @@ -import { EventEmitter } from "events"; -import Dialer from "../Dialer/Dialer"; -import PeerId from "peer-id" -import PeerInfo from "../PeerStore/PeerInfo"; -import RoutingTable from "./routing/RoutingTable"; -import PeerStore from "../PeerStore/PeerStore"; -import {RPCMessage} from "../RPC/RPCMessage"; -import pEvent from 'p-event' - -class KademliaDHT extends EventEmitter { - - peerId: PeerInfo - dialer: Dialer - routingTable: RoutingTable - peerStore: PeerStore - - private running: boolean - - constructor( - peerId: PeerInfo, - dialer: Dialer, - peerStore: PeerStore - ) { - super() - - this.peerId = peerId - this.dialer = dialer - this.routingTable = new RoutingTable(this.peerId.id) - this.peerStore = peerStore - this.running - } - - - /** - * Is this DHT running. - * @type {bool} - */ - get isStarted () { - return this.running - } - - /** - * Start listening to incoming connections. - * @returns {Promise} - */ - async start (): Promise { - this.running = true - - // // Start random walk, it will not run if it's disabled - // this.randomWalk.start() - } - - async findLocalPeer(peerId: PeerId): Promise { - const foundPeerId = await this.routingTable.find(peerId) - const foundPeerInfo = foundPeerId && this.peerStore.get(peerId) - if (foundPeerInfo) { - // Found local peer - return foundPeerInfo - } else { - // Either can't find peerId in routing table or - // PeerInfo doesn't exist in store. Either way, - // we just return null - return null - } - } - - // This function either returns the peer info from - // a locally found peer or uses the FIND_NODE protocol - // from kademlia to query peers until it finds the one - // its looking for - async findPeer(peerId: PeerId): Promise { - // Return local peer if it exists in routing table - const localPeerInfo = await this.findLocalPeer(peerId) - if (localPeerInfo) { - return localPeerInfo - } - - - // If local peer was not found, get closest peers and - // start querying the network - - const kBucketSize = this.routingTable.kBucket.numberOfNodesPerKBucket - const closestPeers = await this.routingTable.closestPeers(peerId, kBucketSize) - - // If there are no closest peers, we have failed to find that peer - if (closestPeers.length === 0) { - throw(new Error('Peer lookup failed')) - } - - console.log('closestPeers'); - console.log(closestPeers); - - // Check if peerId is in closest peer and return if found - const match = closestPeers.find((p) => p.isEqual(peerId)) - if (match) { - const peerInfo = this.peerStore.get(peerId) - if (peerInfo) { - return peerInfo - } - } - - // Query the network until the peer id is found - for (const closePeerId of closestPeers) { - const closePeerInfo = this.peerStore.get(closePeerId) - - if (closePeerInfo) { - const conn = await this.dialer.connectToPeer(closePeerInfo) - - const findNodeRequest = RPCMessage.encodeFindNodeMessage(this.peerId, 20, []) - - conn.write(findNodeRequest, (err) => { - if (err) { - console.log('there was an error when writing findNodeMessage'); - console.log(err); - console.log('findNodeMessage'); - console.log(findNodeRequest); - } - }) - - const data: Buffer = await pEvent(conn, 'data') - - const { requestingPeerInfo, numClosestPeers, closestPeerInfoArray } = RPCMessage.decodeFindNodeMessage(data) - - // Found peers! - console.log('Found some peers!'); - - // Add peers to routing table - const closestPeerIds = closestPeerInfoArray.map((p) => {return p.id}) - await this.routingTable.addPeers(closestPeerIds) - - // Get peer info if peerId exists in closestPeerIds - for (const id of closestPeerIds) { - if (peerId.toB58String() == id.toB58String()) { - const peerInfo = this.peerStore.get(id) - if (peerInfo) { - console.log('Peer was found!!'); - return peerInfo - } else { - throw(Error('Peer id was found, but its info does not exist in peer store')) - } - } - } - - return null - } - } - return null - } -} - -export default KademliaDHT diff --git a/src/peers/peer-dht/PeerDHT.ts b/src/peers/peer-dht/PeerDHT.ts index c290cd8156..865b7d9500 100644 --- a/src/peers/peer-dht/PeerDHT.ts +++ b/src/peers/peer-dht/PeerDHT.ts @@ -10,29 +10,32 @@ import { SubServiceType } from '../../../proto/compiled/Peer_pb'; // this implements a very basic map of known peer connections // TODO: implement full kademlia algorithm for distributed peer connection table class PeerDHT { - metadataFilePath: string - fileSystem: typeof fs - publicKey: string; - connectToPeer: (publicKey: string) => PeerConnection - getPeerInfo: (publicKey: string) => PeerInfo + private metadataFilePath: string + private fileSystem: typeof fs + private getPeerId: () => string; + private connectToPeer: (publicKey: string) => PeerConnection + private getPeerInfo: (id: string) => PeerInfo + private updatePeerStore: (peerInfo: PeerInfo) => void kBucket: KBucket constructor( polykeyPath: string, fileSystem: typeof fs, - publicKey: string, + getPeerId: () => string, connectToPeer: (publicKey: string) => PeerConnection, - getPeerInfo: (publicKey: string) => PeerInfo + getPeerInfo: (id: string) => PeerInfo, + updatePeerStore: (peerInfo: PeerInfo) => void, ) { this.metadataFilePath = path.join(polykeyPath, 'peers', '.peersDHT') this.fileSystem = fileSystem - this.publicKey = publicKey + this.getPeerId = getPeerId this.connectToPeer = connectToPeer this.getPeerInfo = getPeerInfo + this.updatePeerStore = updatePeerStore this.kBucket = new KBucket( - publicKey, + this.getPeerId, this.pingNodeUpdate.bind(this) ) @@ -74,7 +77,7 @@ class PeerDHT { } } - closestPeers(publicKey: string, count: number): string[] { + closestPeers(publicKey: string, count?: number): string[] { return this.kBucket.closest(publicKey, count) } @@ -92,6 +95,20 @@ class PeerDHT { this.kBucket.remove(publicKey) } + toPeerInfoMessageList(publicKeys: string[]): peerInterface.IPeerInfoMessage[] { + const peerIdList = publicKeys.map(p => PeerInfo.publicKeyToId(p)) + return peerIdList.filter(p => { + try { const pi = this.getPeerInfo(p); return (pi) ? true : false } catch{ return false } + }).map(p => { + const pi = this.getPeerInfo(p) + return { + publicKey: pi.publicKey, + peerAddress: pi.peerAddress?.toString(), + apiAddress: pi.apiAddress?.toString(), + } + }) + } + async findLocalPeer(publicKey: string): Promise { const closestPublicKey = this.closestPeer(publicKey) if (closestPublicKey && closestPublicKey == publicKey) { @@ -110,7 +127,7 @@ class PeerDHT { // a locally found peer or uses the FIND_NODE protocol // from kademlia to query peers until it finds the one // its looking for - async findPeer(publicKey: string): Promise { + async findPeer(publicKey: string): Promise { // Return local peer if it exists in routing table const localPeerInfo = await this.findLocalPeer(publicKey) if (localPeerInfo) { @@ -146,7 +163,7 @@ class PeerDHT { // encode request const subMessage = peerInterface.PeerDHTFindNodeMessage.encodeDelimited({ publicKey, - kNodes: closestPeerPublicKeys + closestPeers: this.toPeerInfoMessageList(closestPeerPublicKeys) }).finish() const request = peerInterface.PeerDHTMessage.encodeDelimited({ type: peerInterface.PeerDHTMessageType.FIND_NODE, @@ -156,40 +173,41 @@ class PeerDHT { // send request const response = await pc.sendPeerRequest(SubServiceType.PEER_DHT, request) // decode response - const { subMessage: responseSubMessage } = peerInterface.PeerDHTMessage.decodeDelimited(response ) - const { publicKey: responsePublicKey, kNodes } = peerInterface.PeerDHTFindNodeMessage.decodeDelimited(responseSubMessage) + const { subMessage: responseSubMessage } = peerInterface.PeerDHTMessage.decodeDelimited(response) + const { publicKey: responsePublicKey, closestPeers } = peerInterface.PeerDHTFindNodeMessage.decodeDelimited(responseSubMessage) // make sure request and response public keys are the same if (publicKey != responsePublicKey) { throw Error('request and response public keys are not the same!') } + const closestFoundPeerInfoMessageList = closestPeers.map(p => new PeerInfo(p.publicKey!, p.peerAddress ?? undefined, p.apiAddress ?? undefined)) + // Found peers! console.log('Found some peers!'); // Add peers to routing table - const closestPeerIds = closestPeerInfoArray.map((p) => { return p.id }) - await this.addPeers(closestPeerIds) - - // Get peer info if peerId exists in closestPeerIds - for (const id of closestPeerIds) { - if (publicKey.toB58String() == id.toB58String()) { - const peerInfo = this.peerStore.get(id) - if (peerInfo) { - console.log('Peer was found!!'); - return peerInfo - } else { - throw (Error('Peer id was found, but its info does not exist in peer store')) - } + this.addPeers(closestPeers.map(p => p.publicKey!)) + + // add peers to peer store + let foundPeerInfo: PeerInfo | null = null + for (const peerInfo of (closestFoundPeerInfoMessageList)) { + this.updatePeerStore(peerInfo) + if (peerInfo.publicKey == publicKey) { + foundPeerInfo = peerInfo } } - return null + if (foundPeerInfo) { + console.log('Peer was found!!'); + return foundPeerInfo + } else { + throw (Error('Peer id was found, but its info does not exist in peer store')) + } } catch { // don't want to throw if peer contact failed } } - return null } /////////////////// @@ -200,7 +218,7 @@ class PeerDHT { let response: Uint8Array; switch (type) { case peerInterface.PeerDHTMessageType.PING: - throw Error('dht ping message type not implemented, use peer ping channel for a peer aliveness proxy') + throw Error('dht ping is not implemented, use peer ping channel as a proxy for a peer aliveness') break; case peerInterface.PeerDHTMessageType.FIND_NODE: response = await this.handleFindNodeMessage(request) @@ -217,12 +235,18 @@ class PeerDHT { } private async handleFindNodeMessage(request: Uint8Array): Promise { - const {publicKey, kNodes} = peerInterface.PeerDHTFindNodeMessage.decodeDelimited(request) - this.addPeers(kNodes) - return peerInterface.PeerDHTFindNodeMessage.encodeDelimited({ - publicKey: this.publicKey, - kNodes: [...this.closestPeers()] + const { publicKey, closestPeers } = peerInterface.PeerDHTFindNodeMessage.decodeDelimited(request) + const closestPeerInfoList = closestPeers.map(p => new PeerInfo(p.publicKey!, p.peerAddress ?? undefined, p.apiAddress ?? undefined)) + const response = peerInterface.PeerDHTFindNodeMessage.encodeDelimited({ + publicKey, + closestPeers: this.toPeerInfoMessageList(this.closestPeers(publicKey)) }).finish() + // update the peer store + for (const peerInfo of closestPeerInfoList) { + this.updatePeerStore(peerInfo) + } + this.addPeers(closestPeerInfoList.map(p => p.publicKey)) + return response } // // ==== Helper Methods ==== // diff --git a/src/peers/peer-relay/client/RelayClient.ts b/src/peers/peer-relay/client/RelayClient.ts index 86c2029f66..3ee8a98b8b 100644 --- a/src/peers/peer-relay/client/RelayClient.ts +++ b/src/peers/peer-relay/client/RelayClient.ts @@ -1,26 +1,25 @@ // adapted from https://github.com/advance512/nat-traversal import net from 'net'; import { EventEmitter } from 'events'; -import { Address } from '../../PeerInfo'; +import PeerInfo, { Address } from '../../PeerInfo'; import PeerManager from '../../PeerManager'; import { peerInterface } from '../../../../proto/js/Peer'; import { SubServiceType } from '../../../../proto/compiled/Peer_pb'; import UDPHolePunchClient from '../../peer-hole-punch/UDPHolePunchClient'; import ClientSocketPipe from './ClientSocketPipe'; - class RelayClient { peerManager: PeerManager; - relayNodePublicKey: string + relayPeerId: string socketPipes: ClientSocketPipe[]; terminating: boolean; udpHolePunchClient: UDPHolePunchClient; // default is to support up to 10 connections at once, change this with 'numSockets' parameter - constructor(publicKey: string, peerManager: PeerManager) { - this.relayNodePublicKey = publicKey + constructor(relayPeerId: string, peerManager: PeerManager) { + this.relayPeerId = relayPeerId this.peerManager = peerManager; // create udp hole punch client @@ -53,9 +52,10 @@ class RelayClient { async requestPeerConnection(publicKey: string): Promise
{ const requestMessage = peerInterface.PeerConnectionRequest.encodeDelimited({ publicKey }).finish(); + const relayPeerInfo = this.peerManager.getPeer(this.relayPeerId) const responseMessage = await this.sendMessage( peerInterface.NatMessageType.PEER_CONNECTION, - this.relayNodePublicKey, + relayPeerInfo.publicKey, requestMessage, ); @@ -65,7 +65,6 @@ class RelayClient { throw Error('relay does not know of requested peer'); } const address = Address.parse(peerAddress); - const relayPeerInfo = this.peerManager.getPeer(this.relayNodePublicKey); address.updateHost(relayPeerInfo?.peerAddress?.host); return address; }