*: Support multiple Dhts

This commit is contained in:
Max Inden 2020-04-12 00:51:33 +02:00
parent d5ceae965f
commit 2efff13ee7
No known key found for this signature in database
GPG Key ID: 5403C5464810BC26
5 changed files with 370 additions and 164 deletions

338
Cargo.lock generated
View File

@ -58,6 +58,15 @@ dependencies = [
"memchr",
]
[[package]]
name = "ansi_term"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
dependencies = [
"winapi 0.3.8",
]
[[package]]
name = "anyhow"
version = "1.0.25"
@ -152,14 +161,14 @@ dependencies = [
[[package]]
name = "async-tls"
version = "0.6.0"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ce6977f57fa68da77ffe5542950d47e9c23d65f5bc7cb0a9f8700996913eec7"
checksum = "95fd83426b89b034bf4e9ceb9c533c2f2386b813fd3dcae0a425ec6f1837d78a"
dependencies = [
"futures 0.3.4",
"rustls",
"webpki",
"webpki-roots 0.17.0",
"webpki-roots 0.19.0",
]
[[package]]
@ -200,15 +209,6 @@ dependencies = [
"libc",
]
[[package]]
name = "base64"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e"
dependencies = [
"byteorder 1.3.2",
]
[[package]]
name = "base64"
version = "0.11.0"
@ -221,18 +221,6 @@ version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "blake2"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94cb07b0da6a73955f8fb85d24c466778e70cda767a568229b104f0264089330"
dependencies = [
"byte-tools",
"crypto-mac",
"digest",
"opaque-debug",
]
[[package]]
name = "blake2-rfc"
version = "0.2.18"
@ -243,6 +231,28 @@ dependencies = [
"constant_time_eq",
]
[[package]]
name = "blake2b_simd"
version = "0.5.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8fb2d74254a3a0b5cac33ac9f8ed0e44aa50378d9dbb2e5d83bd21ed1dc2c8a"
dependencies = [
"arrayref",
"arrayvec 0.5.1",
"constant_time_eq",
]
[[package]]
name = "blake2s_simd"
version = "0.5.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab9e07352b829279624ceb7c64adb4f585dacdb81d35cafae81139ccd617cf44"
dependencies = [
"arrayref",
"arrayvec 0.5.1",
"constant_time_eq",
]
[[package]]
name = "block-buffer"
version = "0.7.3"
@ -370,6 +380,21 @@ dependencies = [
"constant_time_eq",
]
[[package]]
name = "clap"
version = "2.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9"
dependencies = [
"ansi_term",
"atty",
"bitflags",
"strsim",
"textwrap",
"unicode-width",
"vec_map",
]
[[package]]
name = "clear_on_drop"
version = "0.2.3"
@ -631,7 +656,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ab49e9dcb602294bc42f9a7dfc9bc6e936fca4418ea300dbfb84fe16de0b7d9"
dependencies = [
"backtrace",
"version_check",
"version_check 0.1.5",
]
[[package]]
@ -1165,6 +1190,7 @@ dependencies = [
"libp2p",
"libp2p-kad",
"prometheus",
"structopt",
"tide",
"void",
]
@ -1208,9 +1234,9 @@ checksum = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558"
[[package]]
name = "libp2p"
version = "0.16.2"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bba17ee9cac4bb89de5812159877d9b4f0a993bf41697a5a875940cd1eb71f24"
checksum = "aa5aedb713f76577818529be8283e35ec5e8b3ecdccfe0231ba4d860687438ab"
dependencies = [
"bytes 0.5.4",
"futures 0.3.4",
@ -1236,8 +1262,8 @@ dependencies = [
"libp2p-wasm-ext",
"libp2p-websocket",
"libp2p-yamux",
"multihash",
"parity-multiaddr",
"parity-multihash",
"parking_lot 0.10.0",
"pin-project",
"smallvec 1.2.0",
@ -1246,22 +1272,23 @@ dependencies = [
[[package]]
name = "libp2p-core"
version = "0.16.0"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b874594c4b29de1a29f27871feba8e6cd13aa54a8a1e8f8c7cf3dfac5ca287c"
checksum = "a1d2c17158c4dca984a77a5927aac6f0862d7f50c013470a415f93be498b5739"
dependencies = [
"asn1_der",
"bs58",
"ed25519-dalek",
"either",
"fnv",
"futures 0.3.4",
"futures-timer 3.0.2",
"lazy_static",
"libsecp256k1",
"log",
"multihash",
"multistream-select",
"parity-multiaddr",
"parity-multihash",
"parking_lot 0.10.0",
"pin-project",
"prost",
@ -1279,9 +1306,9 @@ dependencies = [
[[package]]
name = "libp2p-core-derive"
version = "0.16.0"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96d472e9d522f588805c77801de10b957be84e10f019ca5f869fa1825b15ea9b"
checksum = "329127858e4728db5ab60c33d5ae352a999325fdf190ed022ec7d3a4685ae2e6"
dependencies = [
"quote",
"syn",
@ -1289,9 +1316,9 @@ dependencies = [
[[package]]
name = "libp2p-deflate"
version = "0.16.0"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e25004d4d9837b44b22c5f1a69be1724a5168fef6cff1716b5176a972c3aa62"
checksum = "4ad32b006ea922da8cc66e537cf2df4b0fad8ebaa467d2a8c63d7784ac252ec6"
dependencies = [
"flate2",
"futures 0.3.4",
@ -1300,9 +1327,9 @@ dependencies = [
[[package]]
name = "libp2p-dns"
version = "0.16.0"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b99e552f9939b606eb4b59f7f64d9b01e3f96752f47e350fc3c5fc646ed3f649"
checksum = "c0d0993481203d68e5ce2f787d033fb0cac6b850659ed6c784612db678977c71"
dependencies = [
"futures 0.3.4",
"libp2p-core",
@ -1311,9 +1338,9 @@ dependencies = [
[[package]]
name = "libp2p-floodsub"
version = "0.16.0"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d3234f12e44f9a50351a9807b97fe7de11eb9ae4482370392ba10da6dc90722"
checksum = "3673153ca967c179d745fadf047d069355d6669ecf7f261b450fbaebf1bffd3d"
dependencies = [
"cuckoofilter",
"fnv",
@ -1328,11 +1355,11 @@ dependencies = [
[[package]]
name = "libp2p-gossipsub"
version = "0.16.0"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d46cb3e0841bd951cbf4feae56cdc081e6347836a644fb260c3ec554149b4006"
checksum = "3f7f3f79f060864db0317cc47641b7d35276dee52a0ffa91553fbd0c153863a3"
dependencies = [
"base64 0.11.0",
"base64",
"byteorder 1.3.2",
"bytes 0.5.4",
"fnv",
@ -1353,9 +1380,9 @@ dependencies = [
[[package]]
name = "libp2p-identify"
version = "0.16.0"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfeb935a9bd41263e4f3a24b988e9f4a044f3ae89ac284e83c17fe2f84e0d66b"
checksum = "a38ca3eb807789e26f41c82ca7cd2b3843c66c5587b8b5f709a2f421f3061414"
dependencies = [
"futures 0.3.4",
"libp2p-core",
@ -1369,9 +1396,9 @@ dependencies = [
[[package]]
name = "libp2p-kad"
version = "0.16.2"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "464dc8412978d40f0286be72ed9ab5e0e1386a4a06e7f174526739b5c3c1f041"
checksum = "a92cda1fb8149ea64d092a2b99d2bd7a2c309eee38ea322d02e4480bd6ee1759"
dependencies = [
"arrayvec 0.5.1",
"bytes 0.5.4",
@ -1382,7 +1409,7 @@ dependencies = [
"libp2p-core",
"libp2p-swarm",
"log",
"parity-multihash",
"multihash",
"prost",
"prost-build",
"rand 0.7.3",
@ -1396,9 +1423,9 @@ dependencies = [
[[package]]
name = "libp2p-mdns"
version = "0.16.0"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "881fcfb360c2822db9f0e6bb6f89529621556ed9a8b038313414eda5107334de"
checksum = "41e908d2aaf8ff0ec6ad1f02fe1844fd777fb0b03a68a226423630750ab99471"
dependencies = [
"async-std",
"data-encoding",
@ -1418,9 +1445,9 @@ dependencies = [
[[package]]
name = "libp2p-mplex"
version = "0.16.0"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8507b37ad0eed275efcde67a023c3d85af6c80768b193845b9288e848e1af95"
checksum = "0832882b06619b2e81d74e71447753ea3c068164a0bca67847d272e856a04a02"
dependencies = [
"bytes 0.5.4",
"fnv",
@ -1434,9 +1461,9 @@ dependencies = [
[[package]]
name = "libp2p-noise"
version = "0.16.2"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b15a8a3d71f898beb6f854c8aae27aa1d198e0d1f2e49412261c2d90ef39675a"
checksum = "918e94a649e1139c24ee9f1f8c1f2adaba6d157b9471af787f2d9beac8c29c77"
dependencies = [
"curve25519-dalek 2.0.0",
"futures 0.3.4",
@ -1455,9 +1482,9 @@ dependencies = [
[[package]]
name = "libp2p-ping"
version = "0.16.0"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33d22f2f228b3a828dca1cb8aa9fa331e0bc9c36510cb2c1916956e20dc85e8c"
checksum = "f9bfbf87eebb492d040f9899c5c81c9738730465ac5e78d9b7a7d086d0f07230"
dependencies = [
"futures 0.3.4",
"libp2p-core",
@ -1470,9 +1497,9 @@ dependencies = [
[[package]]
name = "libp2p-plaintext"
version = "0.16.0"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56126a204d7b3382bac163143ff4125a14570b3ba76ba979103d1ae1abed1923"
checksum = "fabb00553a49bf6d4a8ce362f6eefac410227a14d03c3acffbb8cc3f022ea019"
dependencies = [
"bytes 0.5.4",
"futures 0.3.4",
@ -1488,9 +1515,9 @@ dependencies = [
[[package]]
name = "libp2p-pnet"
version = "0.16.0"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b916938a8868f75180aeeffcc6a516a922d165e8fa2a90b57bad989d1ccbb57a"
checksum = "9f81b8b37ff529e1f51c20c396dac657def2108da174c1d27e57e72c9fe2d411"
dependencies = [
"futures 0.3.4",
"log",
@ -1502,9 +1529,9 @@ dependencies = [
[[package]]
name = "libp2p-secio"
version = "0.16.1"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1219e9ecb4945d7331a05f5ffe96a1f6e28051bfa1223d4c60353c251de0354e"
checksum = "a7a0509a7e47245259954fef58b85b81bf4d29ae33a4365e38d718a866698774"
dependencies = [
"aes-ctr",
"ctr",
@ -1532,13 +1559,14 @@ dependencies = [
[[package]]
name = "libp2p-swarm"
version = "0.16.1"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "275471e7c0e88ae004660866cd54f603bd8bd1f4caef541a27f50dd8640c4d4c"
checksum = "622605817885e67b5572189c2507e514b786beb69ed85a120dbb245a7f15383d"
dependencies = [
"futures 0.3.4",
"libp2p-core",
"log",
"rand 0.7.3",
"smallvec 1.2.0",
"void",
"wasm-timer",
@ -1546,9 +1574,9 @@ dependencies = [
[[package]]
name = "libp2p-tcp"
version = "0.16.0"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9e80ad4e3535345f3d666554ce347d3100453775611c05c60786bf9a1747a10"
checksum = "b37ea44823d3ed223e4605da94b50177bc520f05ae2452286700549a32d81669"
dependencies = [
"async-std",
"futures 0.3.4",
@ -1561,9 +1589,9 @@ dependencies = [
[[package]]
name = "libp2p-uds"
version = "0.16.0"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76d329564a43da9d0e055a5b938633c4a8ceab1f59cec133fbc4647917c07341"
checksum = "281c18ea2faacb9c8a6ff76c4405df5918d9a263770e3847bf03f099abadc010"
dependencies = [
"async-std",
"futures 0.3.4",
@ -1573,9 +1601,9 @@ dependencies = [
[[package]]
name = "libp2p-wasm-ext"
version = "0.16.2"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "923581c055bc4b8c5f42d4ce5ef43e52fe5216f1ea4bc26476cb8a966ce6220b"
checksum = "e3ac7dbde0f88cad191dcdfd073b8bae28d01823e8ca313f117b6ecb914160c3"
dependencies = [
"futures 0.3.4",
"js-sys",
@ -1587,9 +1615,9 @@ dependencies = [
[[package]]
name = "libp2p-websocket"
version = "0.16.0"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5351ca9eea122081c1c0f9323164d2918cac29b5a6bfe5054d4ba8ec9447cf42"
checksum = "6874c9069ce93d899df9dc7b29f129c706b2a0fdc048f11d878935352b580190"
dependencies = [
"async-tls",
"bytes 0.5.4",
@ -1608,9 +1636,9 @@ dependencies = [
[[package]]
name = "libp2p-yamux"
version = "0.16.2"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9dac30de24ccde0e67f363d71a125c587bbe6589503f664947e9b084b68a34f1"
checksum = "02f91aea50f6571e0bc6c058dc0e9b270afd41ec28dd94e9e4bf607e78b9ab87"
dependencies = [
"futures 0.3.4",
"libp2p-core",
@ -1757,6 +1785,21 @@ dependencies = [
"ws2_32-sys",
]
[[package]]
name = "multihash"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47fbc227f7e2b1cb701f95404579ecb2668abbdd3c7ef7a6cbb3cc0d3b236869"
dependencies = [
"blake2b_simd",
"blake2s_simd",
"digest",
"sha-1",
"sha2",
"sha3",
"unsigned-varint",
]
[[package]]
name = "multimap"
version = "0.8.1"
@ -1765,15 +1808,15 @@ checksum = "d8883adfde9756c1d30b0f519c9b8c502a94b41ac62f696453c37c7fc0a958ce"
[[package]]
name = "multistream-select"
version = "0.7.0"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f938ffe420493e77c8b6cbcc3f282283f68fc889c5dcbc8e51668d5f3a01ad94"
checksum = "74cdcf7cfb3402881e15a1f95116cb033d69b33c83d481e1234777f5ef0c3d2c"
dependencies = [
"bytes 0.5.4",
"futures 0.1.29",
"futures 0.3.4",
"log",
"pin-project",
"smallvec 1.2.0",
"tokio-io",
"unsigned-varint",
]
@ -1820,7 +1863,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6"
dependencies = [
"memchr",
"version_check",
"version_check 0.1.5",
]
[[package]]
@ -1847,15 +1890,15 @@ checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c"
[[package]]
name = "parity-multiaddr"
version = "0.7.3"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f77055f9e81921a8cc7bebeb6cded3d128931d51f1e3dd6251f0770a6d431477"
checksum = "4db35e222f783ef4e6661873f6c165c4eb7b65e0c408349818517d5705c2d7d3"
dependencies = [
"arrayref",
"bs58",
"byteorder 1.3.2",
"data-encoding",
"parity-multihash",
"multihash",
"percent-encoding 2.1.0",
"serde",
"static_assertions",
@ -1863,21 +1906,6 @@ dependencies = [
"url 2.1.0",
]
[[package]]
name = "parity-multihash"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a1cd2ba02391b81367bec529fb209019d718684fdc8ad6a712c2b536e46f775"
dependencies = [
"blake2",
"bytes 0.5.4",
"rand 0.7.3",
"sha-1",
"sha2",
"sha3",
"unsigned-varint",
]
[[package]]
name = "parity-send-wrapper"
version = "0.1.0"
@ -2000,6 +2028,32 @@ version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b"
[[package]]
name = "proc-macro-error"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98e9e4b82e0ef281812565ea4751049f1bdcdfccda7d3f459f2e138a40c08678"
dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
"syn",
"version_check 0.9.1",
]
[[package]]
name = "proc-macro-error-attr"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f5444ead4e9935abd7f27dc51f7e852a0569ac888096d5ec2499470794e2e53"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn-mid",
"version_check 0.9.1",
]
[[package]]
name = "proc-macro-hack"
version = "0.5.11"
@ -2337,9 +2391,9 @@ dependencies = [
[[package]]
name = "ring"
version = "0.16.9"
version = "0.16.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6747f8da1f2b1fabbee1aaa4eb8a11abf9adef0bf58a41cee45db5d59cecdfac"
checksum = "1ba5a8ec64ee89a76c98c549af81ff14813df09c3e6dc4766c3856da48597a0c"
dependencies = [
"cc",
"lazy_static",
@ -2379,11 +2433,11 @@ dependencies = [
[[package]]
name = "rustls"
version = "0.16.0"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b25a18b1bf7387f0145e7f8324e700805aade3842dd3db2e74e4cdeb4677c09e"
checksum = "c0d4a31f5d68413404705d6982529b0e11a9aacd4839d1d6222ee3b8cb4015e1"
dependencies = [
"base64 0.10.1",
"base64",
"log",
"ring",
"sct",
@ -2581,7 +2635,7 @@ version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c9dab3f95c9ebdf3a88268c19af668f637a3c5039c2c56ff2d40b1b2d64a25b"
dependencies = [
"base64 0.11.0",
"base64",
"bytes 0.5.4",
"flate2",
"futures 0.3.4",
@ -2631,6 +2685,36 @@ dependencies = [
"bytes 0.4.12",
]
[[package]]
name = "strsim"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
name = "structopt"
version = "0.3.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff6da2e8d107dfd7b74df5ef4d205c6aebee0706c647f6bc6a2d5789905c00fb"
dependencies = [
"clap",
"lazy_static",
"structopt-derive",
]
[[package]]
name = "structopt-derive"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a489c87c08fbaf12e386665109dd13470dcc9c4583ea3e10dd2b4523e5ebd9ac"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "subtle"
version = "1.0.0"
@ -2654,6 +2738,17 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "syn-mid"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7be3539f6c128a931cf19dcee741c1af532c7fd387baa739c03dd2e96479338a"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "synstructure"
version = "0.12.3"
@ -2689,6 +2784,15 @@ dependencies = [
"wincolor",
]
[[package]]
name = "textwrap"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
dependencies = [
"unicode-width",
]
[[package]]
name = "thiserror"
version = "1.0.6"
@ -2941,6 +3045,12 @@ version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0"
[[package]]
name = "unicode-width"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479"
[[package]]
name = "unicode-xid"
version = "0.2.0"
@ -2991,12 +3101,24 @@ version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33dd455d0f96e90a75803cfeb7f948768c08d70a6de9a8d2362461935698bf95"
[[package]]
name = "vec_map"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
[[package]]
name = "version_check"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
[[package]]
name = "version_check"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce"
[[package]]
name = "void"
version = "1.0.2"
@ -3133,9 +3255,9 @@ dependencies = [
[[package]]
name = "webpki"
version = "0.21.0"
version = "0.21.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7e664e770ac0110e2384769bcc59ed19e329d81f555916a6e072714957b81b4"
checksum = "f1f50e1972865d6b1adb54167d1c8ed48606004c2c9d0ea5f1eeb34d95e863ef"
dependencies = [
"ring",
"untrusted",
@ -3143,18 +3265,18 @@ dependencies = [
[[package]]
name = "webpki-roots"
version = "0.17.0"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a262ae37dd9d60f60dd473d1158f9fbebf110ba7b6a5051c8160460f6043718b"
checksum = "91cd5736df7f12a964a5067a12c62fa38e1bd8080aff1f80bc29be7c80d19ab4"
dependencies = [
"webpki",
]
[[package]]
name = "webpki-roots"
version = "0.18.0"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91cd5736df7f12a964a5067a12c62fa38e1bd8080aff1f80bc29be7c80d19ab4"
checksum = "f8eff4b7516a57307f9349c64bf34caa34b940b66fed4b2fb3136cb7386e5739"
dependencies = [
"webpki",
]

View File

@ -10,11 +10,12 @@ edition = "2018"
async-std = "1.0"
env_logger = "0.7.1"
futures = "0.3.1"
libp2p = "0.16.2"
libp2p-kad = "0.16.2"
libp2p = "0.18.0"
libp2p-kad = "0.18.0"
prometheus = "0.7"
void = "1.0.2"
tide = "0.6"
exit-future = "0.2"
ctrlc = "3"
structopt = "0.3"

View File

@ -1,8 +1,9 @@
use client::Client;
use futures::{prelude::*, ready};
use libp2p::{identify::IdentifyEvent, kad::KademliaEvent};
use prometheus::{CounterVec, Gauge, Opts, Registry};
use futures::{prelude::*};
use libp2p::{core::Multiaddr, identify::IdentifyEvent, kad::KademliaEvent};
use prometheus::{CounterVec, GaugeVec, Opts, Registry};
use std::{
collections::HashMap,
error::Error,
pin::Pin,
task::{Context, Poll},
@ -11,44 +12,48 @@ use std::{
mod client;
pub(crate) struct Exporter {
client: Client,
clients: HashMap<String, Client>,
metrics: Metrics,
}
impl Exporter {
pub(crate) fn new(registry: &Registry) -> Result<Self, Box<dyn Error>> {
pub(crate) fn new(dhts: Vec<Multiaddr>, registry: &Registry) -> Result<Self, Box<dyn Error>> {
let metrics = Metrics::register(registry);
let clients = dhts.into_iter().map(|addr| {
(addr.iter().next().unwrap().to_string(), client::Client::new(addr).unwrap())
}).collect();
Ok(Exporter {
client: Client::new()?,
clients,
metrics,
})
}
fn record_event(&self, event: client::Event) {
fn record_event(&self, name: String, event: client::Event) {
match event {
client::Event::Ping(_) => {
self.metrics
.event_counter
.with_label_values(&["ping", "ping_event"])
.with_label_values(&[&name, "ping", "ping_event"])
.inc();
}
client::Event::Identify(event) => match *event {
IdentifyEvent::Error { .. } => {
self.metrics
.event_counter
.with_label_values(&["identify", "error"])
.with_label_values(&[&name, "identify", "error"])
.inc();
}
IdentifyEvent::Sent { .. } => {
self.metrics
.event_counter
.with_label_values(&["identify", "sent"])
.with_label_values(&[&name, "identify", "sent"])
.inc();
}
IdentifyEvent::Received { .. } => {
self.metrics
.event_counter
.with_label_values(&["identify", "received"])
.with_label_values(&[&name, "identify", "received"])
.inc();
}
},
@ -57,71 +62,71 @@ impl Exporter {
KademliaEvent::BootstrapResult(_) => {
self.metrics
.event_counter
.with_label_values(&["kad", "bootstrap"])
.with_label_values(&[&name, "kad", "bootstrap"])
.inc();
}
KademliaEvent::GetClosestPeersResult(_) => {
self.metrics
.event_counter
.with_label_values(&["kad", "get_closest_peers"])
.with_label_values(&[&name, "kad", "get_closest_peers"])
.inc();
}
KademliaEvent::GetProvidersResult(_) => {
self.metrics
.event_counter
.with_label_values(&["kad", "get_providers"])
.with_label_values(&[&name, "kad", "get_providers"])
.inc();
}
KademliaEvent::StartProvidingResult(_) => {
self.metrics
.event_counter
.with_label_values(&["kad", "start_providing"])
.with_label_values(&[&name, "kad", "start_providing"])
.inc();
}
KademliaEvent::RepublishProviderResult(_) => {
self.metrics
.event_counter
.with_label_values(&["kad", "republish_provider"])
.with_label_values(&[&name, "kad", "republish_provider"])
.inc();
}
KademliaEvent::GetRecordResult(_) => {
self.metrics
.event_counter
.with_label_values(&["kad", "get_record"])
.with_label_values(&[&name, "kad", "get_record"])
.inc();
}
KademliaEvent::PutRecordResult(_) => {
self.metrics
.event_counter
.with_label_values(&["kad", "put_record"])
.with_label_values(&[&name, "kad", "put_record"])
.inc();
}
KademliaEvent::RepublishRecordResult(_) => {
self.metrics
.event_counter
.with_label_values(&["kad", "republish_record"])
.with_label_values(&[&name, "kad", "republish_record"])
.inc();
}
KademliaEvent::Discovered { .. } => {
self.metrics
.event_counter
.with_label_values(&["kad", "discovered"])
.with_label_values(&[&name, "kad", "discovered"])
.inc();
}
KademliaEvent::RoutingUpdated { old_peer, .. } => {
// Check if it is a new node, or just an update to a node.
if old_peer.is_none() {
self.metrics.bucket_size.inc();
self.metrics.bucket_size.with_label_values(&[&name]).inc();
}
self.metrics
.event_counter
.with_label_values(&["kad", "routing_updated"])
.with_label_values(&[&name, "kad", "routing_updated"])
.inc();
}
KademliaEvent::UnroutablePeer { .. } => {
self.metrics
.event_counter
.with_label_values(&["kad", "unroutable_peer"])
.with_label_values(&[&name, "kad", "unroutable_peer"])
.inc();
}
}
@ -132,19 +137,30 @@ impl Exporter {
impl Future for Exporter {
type Output = ();
fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
loop {
match ready!(self.client.poll_next_unpin(cx)) {
Some(event) => self.record_event(event),
None => return Poll::Ready(()),
fn poll(mut self: Pin<&mut Self>, ctx: &mut Context) -> Poll<Self::Output> {
let mut events = vec![];
for (name, client) in &mut self.clients {
loop {
match client.poll_next_unpin(ctx) {
Poll::Ready(Some(event)) => events.push((name.clone(), event)),
Poll::Ready(None) => return Poll::Ready(()),
Poll::Pending => break,
}
}
}
for (name, event) in events {
self.record_event(name, event);
}
Poll::Pending
}
}
struct Metrics {
event_counter: CounterVec,
bucket_size: Gauge,
bucket_size: GaugeVec,
}
impl Metrics {
@ -153,17 +169,16 @@ impl Metrics {
Opts::new(
"network_behaviour_event",
"Libp2p network behaviour events.",
)
.variable_labels(vec!["behaviour".to_string(), "event".to_string()]),
&["behaviour", "event"],
),
&["dht", "behaviour", "event"],
)
.unwrap();
registry.register(Box::new(event_counter.clone())).unwrap();
let bucket_size = Gauge::with_opts(Opts::new(
let bucket_size = GaugeVec::new(Opts::new(
"kad_kbuckets_size",
"Libp2p Kademlia K-Buckets size.",
))
), &["dht"])
.unwrap();
registry.register(Box::new(bucket_size.clone())).unwrap();
Metrics {

View File

@ -1,22 +1,29 @@
use futures::prelude::*;
use libp2p::{
core::{
self, muxing::StreamMuxerBox, transport::boxed::Boxed, transport::Transport, Multiaddr,
self, muxing::StreamMuxerBox, transport::boxed::Boxed, transport::Transport, Multiaddr, multiaddr::Protocol,
either::EitherError, either::EitherOutput, upgrade,
},
dns,
mplex,
identify::{Identify, IdentifyEvent},
identity::Keypair,
kad::{record::store::MemoryStore, Kademlia, KademliaEvent},
kad::{record::store::MemoryStore, Kademlia, KademliaConfig, KademliaEvent, protocol::KademliaProtocolConfig},
noise,
ping::{Ping, PingConfig, PingEvent},
swarm::{NetworkBehaviourAction, NetworkBehaviourEventProcess, PollParameters},
tcp, yamux, NetworkBehaviour, PeerId, Swarm,
secio,
InboundUpgradeExt,
OutboundUpgradeExt,
};
use std::{
io,
usize,
str::FromStr,
convert::TryInto,
error::Error,
pin::Pin,
str::FromStr,
task::{Context, Poll},
time::Duration,
};
@ -27,13 +34,13 @@ pub struct Client {
}
impl Client {
pub fn new() -> Result<Client, Box<dyn Error>> {
env_logger::init();
pub fn new(mut bootnode: Multiaddr) -> Result<Client, Box<dyn Error>> {
// Create a random key for ourselves.
let local_key = Keypair::generate_ed25519();
let local_peer_id = PeerId::from(local_key.public());
&local_peer_id;
let behaviour = MyBehaviour::new(local_key.clone())?;
let transport = build_transport(local_key);
let mut swarm = Swarm::new(transport, behaviour, local_peer_id);
@ -41,12 +48,15 @@ impl Client {
// Listen on all interfaces and whatever port the OS assigns.
Swarm::listen_on(&mut swarm, "/ip4/0.0.0.0/tcp/0".parse()?)?;
// Bootstrapping.
let bootnode: Multiaddr = "/dns4/p2p.cc3-5.kusama.network/tcp/30100"
.try_into()
.unwrap();
let bootnode_peer_id =
PeerId::from_str("QmdePe9MiAJT4yHT2tEwmazCsckAZb19uaoSUgRDffPq3G").unwrap();
let bootnode_peer_id = if let Protocol::P2p(hash) = bootnode.pop().unwrap() {
PeerId::from_multihash(hash).unwrap()
} else {
panic!("expected peer id");
};
swarm.kademlia.add_address(&bootnode_peer_id, bootnode);
swarm.kademlia.bootstrap();
@ -89,6 +99,7 @@ pub(crate) struct MyBehaviour {
event_buffer: Vec<Event>,
}
#[derive(Debug)]
pub enum Event {
Ping(PingEvent),
Identify(Box<IdentifyEvent>),
@ -98,9 +109,19 @@ pub enum Event {
impl MyBehaviour {
fn new(local_key: Keypair) -> Result<Self, Box<dyn Error>> {
let local_peer_id = PeerId::from(local_key.public());
// Create a Kademlia behaviour.
let store = MemoryStore::new(local_peer_id.clone());
let kademlia = Kademlia::new(local_peer_id, store);
let mut kademlia_config = KademliaConfig::default();
// TODO: Seems like rust and golang use diffferent max packet sizes
// https://github.com/libp2p/go-libp2p-core/blob/master/network/network.go#L23
// https://github.com/libp2p/rust-libp2p/blob/master/protocols/kad/src/protocol.rs#L170
// This results in `[2020-04-11T22:45:24Z DEBUG libp2p_kad::behaviour]
// Request to PeerId("") in query QueryId(0) failed with Io(Custom {
// kind: PermissionDenied, error: "len > max" })`
kademlia_config.set_max_packet_size(8000);
let kademlia = Kademlia::with_config(local_peer_id, store, kademlia_config);
let ping = Ping::new(PingConfig::new().with_keep_alive(true));
let user_agent = "substrate-node/v2.0.0-e3245d49d-x86_64-linux-gnu (unknown)".to_string();
@ -153,12 +174,46 @@ fn build_transport(keypair: Keypair) -> Boxed<(PeerId, StreamMuxerBox), impl Err
let transport = dns::DnsConfig::new(tcp).unwrap();
let noise_keypair = noise::Keypair::new().into_authentic(&keypair).unwrap();
let noise_config = noise::NoiseConfig::ix(noise_keypair);
let secio_config = secio::SecioConfig::new(keypair).max_frame_len(1024 * 1024);
let transport = transport.and_then(move |stream, endpoint| {
let upgrade = core::upgrade::SelectUpgrade::new(noise_config, secio_config);
core::upgrade::apply(stream, upgrade, endpoint, upgrade::Version::V1)
.map(|out| match out? {
// We negotiated noise
EitherOutput::First((remote_id, out)) => {
let remote_key = match remote_id {
noise::RemoteIdentity::IdentityKey(key) => key,
_ => return Err(upgrade::UpgradeError::Apply(EitherError::A(noise::NoiseError::InvalidKey)))
};
Ok((EitherOutput::First(out), remote_key.into_peer_id()))
}
// We negotiated secio
EitherOutput::Second((remote_id, out)) =>
Ok((EitherOutput::Second(out), remote_id))
})
});
let mut mplex_config = mplex::MplexConfig::new();
mplex_config.max_buffer_len_behaviour(mplex::MaxBufferBehaviour::Block);
mplex_config.max_buffer_len(usize::MAX);
let yamux_config = yamux::Config::default();
// Multiplexing
let transport = transport.and_then(move |(stream, peer_id), endpoint| {
let peer_id2 = peer_id.clone();
let upgrade = core::upgrade::SelectUpgrade::new(yamux_config, mplex_config)
.map_inbound(move |muxer| (peer_id, muxer))
.map_outbound(move |muxer| (peer_id2, muxer));
core::upgrade::apply(stream, upgrade, endpoint, upgrade::Version::V1)
.map_ok(|(id, muxer)| (id, core::muxing::StreamMuxerBox::new(muxer)))
})
.timeout(Duration::from_secs(20))
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))
.boxed();
transport
.upgrade(core::upgrade::Version::V1)
.authenticate(noise::NoiseConfig::ix(noise_keypair).into_authenticated())
.multiplex(yamux::Config::default())
.map(|(peer, muxer), _| (peer, core::muxing::StreamMuxerBox::new(muxer)))
.timeout(Duration::from_secs(20))
.boxed()
}

View File

@ -1,13 +1,26 @@
use async_std::task;
use libp2p::core::Multiaddr;
use prometheus::{Encoder, Registry, TextEncoder};
use std::{
error::Error,
sync::{Arc, Mutex},
};
use structopt::StructOpt;
mod exporter;
#[derive(Debug, StructOpt)]
#[structopt(name = "Kademlia exporter", about = "Monitor the state of a Kademlia Dht.")]
struct Opt {
#[structopt(long)]
dht: Vec<Multiaddr>,
}
fn main() -> Result<(), Box<dyn Error>> {
let opt = Opt::from_args();
env_logger::init();
let (signal, exit) = exit_future::signal();
let signal = Arc::new(Mutex::new(Some(signal)));
@ -19,7 +32,7 @@ fn main() -> Result<(), Box<dyn Error>> {
.unwrap();
let registry = Registry::new();
let exporter = exporter::Exporter::new(&registry)?;
let exporter = exporter::Exporter::new(opt.dht, &registry)?;
let exit_clone = exit.clone();
let metrics_server = std::thread::spawn(move || {