mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 21:21:11 +00:00
Update libp2p to 0.16 (#4928)
* Update libp2p to 0.16
* Actually update to libp2p 0.16 🤦
* Fix missed updates
* Fix peerset tests
This commit is contained in:
Generated
+112
-55
@@ -580,6 +580,15 @@ version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
||||
|
||||
[[package]]
|
||||
name = "chacha20-poly1305-aead"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77d2058ba29594f69c75e8a9018e0485e3914ca5084e3613cd64529042f5423b"
|
||||
dependencies = [
|
||||
"constant_time_eq",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "chain-spec-builder"
|
||||
version = "2.0.0"
|
||||
@@ -2634,9 +2643,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libp2p"
|
||||
version = "0.15.0"
|
||||
version = "0.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f84847789ab24b3fc5971a68656ac85886df640986d9ce3264c0327694eae471"
|
||||
checksum = "a58becf0b9585fcfbb8215bbe6e6ac187fcc180fd1026925ca180c845aa5a6e8"
|
||||
dependencies = [
|
||||
"bytes 0.5.4",
|
||||
"futures 0.3.4",
|
||||
@@ -2654,6 +2663,7 @@ dependencies = [
|
||||
"libp2p-noise",
|
||||
"libp2p-ping",
|
||||
"libp2p-plaintext",
|
||||
"libp2p-pnet",
|
||||
"libp2p-secio",
|
||||
"libp2p-swarm",
|
||||
"libp2p-tcp",
|
||||
@@ -2671,16 +2681,16 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libp2p-core"
|
||||
version = "0.15.0"
|
||||
version = "0.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dbafb2706b8082233f66dc13e196f9cf9b4c229f2cd7c96b2b16617ad6ee330b"
|
||||
checksum = "3b874594c4b29de1a29f27871feba8e6cd13aa54a8a1e8f8c7cf3dfac5ca287c"
|
||||
dependencies = [
|
||||
"asn1_der",
|
||||
"bs58",
|
||||
"ed25519-dalek",
|
||||
"fnv",
|
||||
"futures 0.3.4",
|
||||
"futures-timer 2.0.2",
|
||||
"futures-timer 3.0.1",
|
||||
"lazy_static",
|
||||
"libsecp256k1",
|
||||
"log 0.4.8",
|
||||
@@ -2698,16 +2708,15 @@ dependencies = [
|
||||
"smallvec 1.2.0",
|
||||
"thiserror",
|
||||
"unsigned-varint",
|
||||
"untrusted",
|
||||
"void",
|
||||
"zeroize 1.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libp2p-core-derive"
|
||||
version = "0.15.0"
|
||||
version = "0.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c320266be0a7760e23484d635acdb83844b2d74d3612d93b41c393c9bcf004e"
|
||||
checksum = "96d472e9d522f588805c77801de10b957be84e10f019ca5f869fa1825b15ea9b"
|
||||
dependencies = [
|
||||
"quote 1.0.2",
|
||||
"syn",
|
||||
@@ -2715,9 +2724,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libp2p-deflate"
|
||||
version = "0.7.0"
|
||||
version = "0.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3be32697b42d040b325c3737f827ea04ede569ec956b7807700dd8d89d8210f9"
|
||||
checksum = "2e25004d4d9837b44b22c5f1a69be1724a5168fef6cff1716b5176a972c3aa62"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"futures 0.3.4",
|
||||
@@ -2726,9 +2735,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libp2p-dns"
|
||||
version = "0.15.0"
|
||||
version = "0.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f11c979b882f25d85726b15637d5bbc722dfa1be576605c54e99b8cf56906be3"
|
||||
checksum = "b99e552f9939b606eb4b59f7f64d9b01e3f96752f47e350fc3c5fc646ed3f649"
|
||||
dependencies = [
|
||||
"futures 0.3.4",
|
||||
"libp2p-core",
|
||||
@@ -2737,11 +2746,10 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libp2p-floodsub"
|
||||
version = "0.15.0"
|
||||
version = "0.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4bdf6fba9272ad47dde94bade89540fdb16e24ae9ff7fb714c1c80a035165f28"
|
||||
checksum = "1d3234f12e44f9a50351a9807b97fe7de11eb9ae4482370392ba10da6dc90722"
|
||||
dependencies = [
|
||||
"bs58",
|
||||
"cuckoofilter",
|
||||
"fnv",
|
||||
"futures 0.3.4",
|
||||
@@ -2755,12 +2763,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libp2p-gossipsub"
|
||||
version = "0.15.0"
|
||||
version = "0.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e6ecd058bf769d27ebec530544b081e08b0a1088e3186da8cc58d59915784d0"
|
||||
checksum = "d46cb3e0841bd951cbf4feae56cdc081e6347836a644fb260c3ec554149b4006"
|
||||
dependencies = [
|
||||
"base64 0.11.0",
|
||||
"bs58",
|
||||
"byteorder 1.3.4",
|
||||
"bytes 0.5.4",
|
||||
"fnv",
|
||||
@@ -2781,9 +2788,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libp2p-identify"
|
||||
version = "0.15.0"
|
||||
version = "0.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9d1a6261b804111c2dbf53f8ca03f66edc5ad1c29b78a61cf0cc5354052e28e9"
|
||||
checksum = "bfeb935a9bd41263e4f3a24b988e9f4a044f3ae89ac284e83c17fe2f84e0d66b"
|
||||
dependencies = [
|
||||
"futures 0.3.4",
|
||||
"libp2p-core",
|
||||
@@ -2797,9 +2804,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libp2p-kad"
|
||||
version = "0.15.0"
|
||||
version = "0.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0c6ea6fece0d99599afb1b2082ca8937944cdd6b0946a88d54cb3ae7a38d1253"
|
||||
checksum = "b2efcff2af085e8181c421f68fe9c2b0a067379d146731925b3ac8f8e605c458"
|
||||
dependencies = [
|
||||
"arrayvec 0.5.1",
|
||||
"bytes 0.5.4",
|
||||
@@ -2824,9 +2831,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libp2p-mdns"
|
||||
version = "0.15.0"
|
||||
version = "0.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "074312353355df310affa105ec71b16fd7e52f5c6ae61d3dcbb3e79e8fdc9e5f"
|
||||
checksum = "881fcfb360c2822db9f0e6bb6f89529621556ed9a8b038313414eda5107334de"
|
||||
dependencies = [
|
||||
"async-std",
|
||||
"data-encoding",
|
||||
@@ -2846,9 +2853,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libp2p-mplex"
|
||||
version = "0.15.0"
|
||||
version = "0.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "89d0b44dfdef80cc2be4b42d127de1c793905eca2459415a5c57d6b4fbd8ec30"
|
||||
checksum = "d8507b37ad0eed275efcde67a023c3d85af6c80768b193845b9288e848e1af95"
|
||||
dependencies = [
|
||||
"bytes 0.5.4",
|
||||
"fnv",
|
||||
@@ -2862,9 +2869,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libp2p-noise"
|
||||
version = "0.13.0"
|
||||
version = "0.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0845e8208d814cd41c26c90a6a2f2b720c31b588209cecc49a44c881a09f417f"
|
||||
checksum = "ac7d33809afdf6794f09fdb2f9f94e1550ae230be5bae6430a078eb96fc9e5a6"
|
||||
dependencies = [
|
||||
"curve25519-dalek 1.2.3",
|
||||
"futures 0.3.4",
|
||||
@@ -2874,17 +2881,18 @@ dependencies = [
|
||||
"prost",
|
||||
"prost-build",
|
||||
"rand 0.7.3",
|
||||
"ring",
|
||||
"sha2",
|
||||
"snow",
|
||||
"x25519-dalek",
|
||||
"static_assertions",
|
||||
"x25519-dalek 0.5.2",
|
||||
"zeroize 1.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libp2p-ping"
|
||||
version = "0.15.0"
|
||||
version = "0.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "16ecced2949ae93b6ff29565303ecd1bef15c4e4efb689033ee744922561a36b"
|
||||
checksum = "33d22f2f228b3a828dca1cb8aa9fa331e0bc9c36510cb2c1916956e20dc85e8c"
|
||||
dependencies = [
|
||||
"futures 0.3.4",
|
||||
"libp2p-core",
|
||||
@@ -2897,9 +2905,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libp2p-plaintext"
|
||||
version = "0.15.0"
|
||||
version = "0.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "195fda6b6a948a242fd30570e0e3418ae8e0a20055ea75d45458e1079a8efb05"
|
||||
checksum = "56126a204d7b3382bac163143ff4125a14570b3ba76ba979103d1ae1abed1923"
|
||||
dependencies = [
|
||||
"bytes 0.5.4",
|
||||
"futures 0.3.4",
|
||||
@@ -2914,10 +2922,24 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libp2p-secio"
|
||||
version = "0.15.0"
|
||||
name = "libp2p-pnet"
|
||||
version = "0.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ceef68ca377b264f84d64c88739a8fa118b5db1e8f18297351dff75314504a5f"
|
||||
checksum = "b916938a8868f75180aeeffcc6a516a922d165e8fa2a90b57bad989d1ccbb57a"
|
||||
dependencies = [
|
||||
"futures 0.3.4",
|
||||
"log 0.4.8",
|
||||
"pin-project",
|
||||
"rand 0.7.3",
|
||||
"salsa20",
|
||||
"sha3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libp2p-secio"
|
||||
version = "0.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec00eb9a3404ed76a0e14f637edcaa7f2b4a27a16884da4a56f2f21e166c2843"
|
||||
dependencies = [
|
||||
"aes-ctr",
|
||||
"ctr",
|
||||
@@ -2945,9 +2967,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libp2p-swarm"
|
||||
version = "0.5.0"
|
||||
version = "0.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "14ea00be81bc3985e36abad263ce2ad1b6aeb862aa743563eb70ad42880c05ae"
|
||||
checksum = "f1e9f4fb84a4bfe3d3a361c1fbcd4af017ba68f0a46a77bfbcc48bf8a456d6ef"
|
||||
dependencies = [
|
||||
"futures 0.3.4",
|
||||
"libp2p-core",
|
||||
@@ -2959,13 +2981,13 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libp2p-tcp"
|
||||
version = "0.15.0"
|
||||
version = "0.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e65ef381570df31cb047dfbc11483ab0fe7e6abbdcf2bdc2c60b5d11133d241"
|
||||
checksum = "f9e80ad4e3535345f3d666554ce347d3100453775611c05c60786bf9a1747a10"
|
||||
dependencies = [
|
||||
"async-std",
|
||||
"futures 0.3.4",
|
||||
"futures-timer 2.0.2",
|
||||
"futures-timer 3.0.1",
|
||||
"get_if_addrs",
|
||||
"ipnet",
|
||||
"libp2p-core",
|
||||
@@ -2974,9 +2996,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libp2p-uds"
|
||||
version = "0.15.0"
|
||||
version = "0.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e4f4f7989b35f33d4b9738aab2f031310eb20fec513cab44d12b1bc985a8074"
|
||||
checksum = "76d329564a43da9d0e055a5b938633c4a8ceab1f59cec133fbc4647917c07341"
|
||||
dependencies = [
|
||||
"async-std",
|
||||
"futures 0.3.4",
|
||||
@@ -2986,9 +3008,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libp2p-wasm-ext"
|
||||
version = "0.8.0"
|
||||
version = "0.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b4d457adb91a5e2212343218a554394cd8ced64a79fb8e36e7aed2a16d49495"
|
||||
checksum = "39703653caa36f4afd0def39cc49a3ac0fa1d4289ca1802e417af03e4f5ef950"
|
||||
dependencies = [
|
||||
"futures 0.3.4",
|
||||
"js-sys",
|
||||
@@ -3000,9 +3022,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libp2p-websocket"
|
||||
version = "0.15.0"
|
||||
version = "0.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bba425f2af1fdb7dece88b9ae05ca9430dfb0b72b2c078e73ded6f1556084509"
|
||||
checksum = "5351ca9eea122081c1c0f9323164d2918cac29b5a6bfe5054d4ba8ec9447cf42"
|
||||
dependencies = [
|
||||
"async-tls",
|
||||
"bytes 0.5.4",
|
||||
@@ -3021,13 +3043,12 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libp2p-yamux"
|
||||
version = "0.15.0"
|
||||
version = "0.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ca25b3aac78a3c93c2a567622abd3cfc16f96f26ae1bf6134f0056203d62d86"
|
||||
checksum = "f72aa5a7273c29c6eaea09108a49feaefc7456164863f64f86a193f9e78a4b7f"
|
||||
dependencies = [
|
||||
"futures 0.3.4",
|
||||
"libp2p-core",
|
||||
"log 0.4.8",
|
||||
"parking_lot 0.10.0",
|
||||
"thiserror",
|
||||
"yamux",
|
||||
@@ -4533,9 +4554,9 @@ checksum = "0c276d76c5333b8c2579e02d49a06733a55b8282d2d9b13e8d53b6406bd7e30a"
|
||||
|
||||
[[package]]
|
||||
name = "parity-multiaddr"
|
||||
version = "0.7.1"
|
||||
version = "0.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "80878c27f90dd162d3143333d672e80b194d6b080f05c83440e3dfda42e409f2"
|
||||
checksum = "26df883298bc3f4e92528b4c5cc9f806b791955b136da3e5e939ed9de0fd958b"
|
||||
dependencies = [
|
||||
"arrayref",
|
||||
"bs58",
|
||||
@@ -4551,9 +4572,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "parity-multihash"
|
||||
version = "0.2.2"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b11f42bbd3a021c5061b77154bd3334d5a57e1a03eb162de0b962681cc25800d"
|
||||
checksum = "7a1cd2ba02391b81367bec529fb209019d718684fdc8ad6a712c2b536e46f775"
|
||||
dependencies = [
|
||||
"blake2",
|
||||
"bytes 0.5.4",
|
||||
@@ -5490,6 +5511,26 @@ version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072"
|
||||
|
||||
[[package]]
|
||||
name = "salsa20"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2324b0e8c3bb9a586a571fdb3136f70e7e2c748de00a78043f86e0cff91f91fe"
|
||||
dependencies = [
|
||||
"byteorder 1.3.4",
|
||||
"salsa20-core",
|
||||
"stream-cipher",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "salsa20-core"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2fe6cc1b9f5a5867853ade63099de70f042f7679e408d1ffe52821c9248e6e69"
|
||||
dependencies = [
|
||||
"stream-cipher",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "same-file"
|
||||
version = "1.0.6"
|
||||
@@ -6768,10 +6809,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "afb767eee7d257ba202f0b9b08673bc13b22281632ef45267b19f13100accd2f"
|
||||
dependencies = [
|
||||
"arrayref",
|
||||
"blake2-rfc",
|
||||
"chacha20-poly1305-aead",
|
||||
"rand 0.7.3",
|
||||
"rand_core 0.5.1",
|
||||
"ring",
|
||||
"rustc_version",
|
||||
"sha2",
|
||||
"subtle 2.2.2",
|
||||
"x25519-dalek 0.6.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -9019,6 +9065,17 @@ dependencies = [
|
||||
"rand_core 0.3.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "x25519-dalek"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "637ff90c9540fa3073bb577e65033069e4bae7c79d49d74aa3ffdf5342a53217"
|
||||
dependencies = [
|
||||
"curve25519-dalek 2.0.0",
|
||||
"rand_core 0.5.1",
|
||||
"zeroize 1.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "xdg"
|
||||
version = "2.2.0"
|
||||
|
||||
@@ -28,7 +28,7 @@ derive_more = { version = "0.99.2" }
|
||||
sc-rpc = { version = "2.0.0", path = "../../../client/rpc" }
|
||||
jsonrpc-core-client = { version = "14.0.3", features = ["http"] }
|
||||
hyper = "0.12.35"
|
||||
libp2p = "0.15.0"
|
||||
libp2p = "0.16.0"
|
||||
serde_json = "1.0"
|
||||
|
||||
[features]
|
||||
|
||||
@@ -15,7 +15,7 @@ codec = { package = "parity-scale-codec", default-features = false, version = "1
|
||||
derive_more = "0.99.2"
|
||||
futures = "0.3.1"
|
||||
futures-timer = "3.0.1"
|
||||
libp2p = { version = "0.15.0", default-features = false, features = ["secp256k1", "libp2p-websocket"] }
|
||||
libp2p = { version = "0.16.0", default-features = false, features = ["secp256k1", "libp2p-websocket"] }
|
||||
log = "0.4.8"
|
||||
prost = "0.6.1"
|
||||
rand = "0.7.2"
|
||||
|
||||
@@ -12,7 +12,7 @@ futures = { version = "0.3.1", features = ["compat"] }
|
||||
wasm-timer = "0.2"
|
||||
futures-timer = "3.0.1"
|
||||
futures01 = { package = "futures", version = "0.1.29" }
|
||||
libp2p = { version = "0.15.0", default-features = false, features = ["libp2p-websocket"] }
|
||||
libp2p = { version = "0.16.0", default-features = false, features = ["libp2p-websocket"] }
|
||||
lru = "0.1.2"
|
||||
parking_lot = "0.10.0"
|
||||
sc-network = { version = "0.8", path = "../network" }
|
||||
|
||||
@@ -22,7 +22,7 @@ futures = "0.3.1"
|
||||
futures_codec = "0.3.3"
|
||||
futures-timer = "3.0.1"
|
||||
wasm-timer = "0.2"
|
||||
libp2p = { version = "0.15.0", default-features = false, features = ["libp2p-websocket"] }
|
||||
libp2p = { version = "0.16.0", default-features = false, features = ["libp2p-websocket"] }
|
||||
linked-hash-map = "0.5.2"
|
||||
linked_hash_set = "0.1.3"
|
||||
log = "0.4.8"
|
||||
|
||||
@@ -23,8 +23,7 @@ use crate::protocol::{self, light_client_handler, CustomMessageOutcome, Protocol
|
||||
use libp2p::NetworkBehaviour;
|
||||
use libp2p::core::{Multiaddr, PeerId, PublicKey};
|
||||
use libp2p::kad::record;
|
||||
use libp2p::swarm::{NetworkBehaviourAction, NetworkBehaviourEventProcess};
|
||||
use libp2p::core::{nodes::Substream, muxing::StreamMuxerBox};
|
||||
use libp2p::swarm::{NetworkBehaviourAction, NetworkBehaviourEventProcess, PollParameters};
|
||||
use log::debug;
|
||||
use sp_consensus::{BlockOrigin, import_queue::{IncomingBlock, Origin}};
|
||||
use sp_runtime::{traits::{Block as BlockT, NumberFor}, Justification};
|
||||
@@ -39,13 +38,13 @@ pub struct Behaviour<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> {
|
||||
substrate: Protocol<B, S, H>,
|
||||
/// Periodically pings and identifies the nodes we are connected to, and store information in a
|
||||
/// cache.
|
||||
debug_info: debug_info::DebugInfoBehaviour<Substream<StreamMuxerBox>>,
|
||||
debug_info: debug_info::DebugInfoBehaviour,
|
||||
/// Discovers nodes of the network.
|
||||
discovery: DiscoveryBehaviour<Substream<StreamMuxerBox>>,
|
||||
discovery: DiscoveryBehaviour,
|
||||
/// Block request handling.
|
||||
block_requests: protocol::BlockRequests<Substream<StreamMuxerBox>, B>,
|
||||
block_requests: protocol::BlockRequests<B>,
|
||||
/// Light client request handling.
|
||||
light_client_handler: protocol::LightClientHandler<Substream<StreamMuxerBox>, B>,
|
||||
light_client_handler: protocol::LightClientHandler<B>,
|
||||
/// Queue of events to produce for the outside.
|
||||
#[behaviour(ignore)]
|
||||
events: Vec<BehaviourOut<B>>,
|
||||
@@ -69,8 +68,8 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Behaviour<B, S, H> {
|
||||
enable_mdns: bool,
|
||||
allow_private_ipv4: bool,
|
||||
discovery_only_if_under_num: u64,
|
||||
block_requests: protocol::BlockRequests<Substream<StreamMuxerBox>, B>,
|
||||
light_client_handler: protocol::LightClientHandler<Substream<StreamMuxerBox>, B>,
|
||||
block_requests: protocol::BlockRequests<B>,
|
||||
light_client_handler: protocol::LightClientHandler<B>,
|
||||
) -> Self {
|
||||
Behaviour {
|
||||
substrate,
|
||||
@@ -223,7 +222,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> NetworkBehaviourEventPr
|
||||
}
|
||||
|
||||
impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Behaviour<B, S, H> {
|
||||
fn poll<TEv>(&mut self, _: &mut Context) -> Poll<NetworkBehaviourAction<TEv, BehaviourOut<B>>> {
|
||||
fn poll<TEv>(&mut self, _: &mut Context, _: &mut impl PollParameters) -> Poll<NetworkBehaviourAction<TEv, BehaviourOut<B>>> {
|
||||
if !self.events.is_empty() {
|
||||
return Poll::Ready(NetworkBehaviourAction::GenerateEvent(self.events.remove(0)))
|
||||
}
|
||||
|
||||
@@ -39,11 +39,11 @@ const GARBAGE_COLLECT_INTERVAL: Duration = Duration::from_secs(2 * 60);
|
||||
|
||||
/// Implementation of `NetworkBehaviour` that holds information about nodes in cache for diagnostic
|
||||
/// purposes.
|
||||
pub struct DebugInfoBehaviour<TSubstream> {
|
||||
pub struct DebugInfoBehaviour {
|
||||
/// Periodically ping nodes, and close the connection if it's unresponsive.
|
||||
ping: Ping<TSubstream>,
|
||||
ping: Ping,
|
||||
/// Periodically identifies the remote and responds to incoming requests.
|
||||
identify: Identify<TSubstream>,
|
||||
identify: Identify,
|
||||
/// Information that we know about all nodes.
|
||||
nodes_info: FnvHashMap<PeerId, NodeInfo>,
|
||||
/// Interval at which we perform garbage collection in `nodes_info`.
|
||||
@@ -64,7 +64,7 @@ struct NodeInfo {
|
||||
latest_ping: Option<Duration>,
|
||||
}
|
||||
|
||||
impl<TSubstream> DebugInfoBehaviour<TSubstream> {
|
||||
impl DebugInfoBehaviour {
|
||||
/// Builds a new `DebugInfoBehaviour`.
|
||||
pub fn new(
|
||||
user_agent: String,
|
||||
@@ -151,11 +151,10 @@ pub enum DebugInfoEvent {
|
||||
},
|
||||
}
|
||||
|
||||
impl<TSubstream> NetworkBehaviour for DebugInfoBehaviour<TSubstream>
|
||||
where TSubstream: AsyncRead + AsyncWrite + Unpin + Send + 'static {
|
||||
impl NetworkBehaviour for DebugInfoBehaviour {
|
||||
type ProtocolsHandler = IntoProtocolsHandlerSelect<
|
||||
<Ping<TSubstream> as NetworkBehaviour>::ProtocolsHandler,
|
||||
<Identify<TSubstream> as NetworkBehaviour>::ProtocolsHandler
|
||||
<Ping as NetworkBehaviour>::ProtocolsHandler,
|
||||
<Identify as NetworkBehaviour>::ProtocolsHandler
|
||||
>;
|
||||
type OutEvent = DebugInfoEvent;
|
||||
|
||||
|
||||
@@ -55,8 +55,6 @@ use libp2p::kad::record::{self, store::MemoryStore};
|
||||
#[cfg(not(target_os = "unknown"))]
|
||||
use libp2p::{swarm::toggle::Toggle};
|
||||
#[cfg(not(target_os = "unknown"))]
|
||||
use libp2p::core::{nodes::Substream, muxing::StreamMuxerBox};
|
||||
#[cfg(not(target_os = "unknown"))]
|
||||
use libp2p::mdns::{Mdns, MdnsEvent};
|
||||
use libp2p::multiaddr::Protocol;
|
||||
use log::{debug, info, trace, warn, error};
|
||||
@@ -65,15 +63,15 @@ use std::task::{Context, Poll};
|
||||
use sp_core::hexdisplay::HexDisplay;
|
||||
|
||||
/// Implementation of `NetworkBehaviour` that discovers the nodes on the network.
|
||||
pub struct DiscoveryBehaviour<TSubstream> {
|
||||
pub struct DiscoveryBehaviour {
|
||||
/// User-defined list of nodes and their addresses. Typically includes bootstrap nodes and
|
||||
/// reserved nodes.
|
||||
user_defined: Vec<(PeerId, Multiaddr)>,
|
||||
/// Kademlia requests and answers.
|
||||
kademlia: Kademlia<TSubstream, MemoryStore>,
|
||||
kademlia: Kademlia<MemoryStore>,
|
||||
/// Discovers nodes on the local network.
|
||||
#[cfg(not(target_os = "unknown"))]
|
||||
mdns: Toggle<Mdns<Substream<StreamMuxerBox>>>,
|
||||
mdns: Toggle<Mdns>,
|
||||
/// Stream that fires when we need to perform the next random Kademlia query.
|
||||
next_kad_random_query: Delay,
|
||||
/// After `next_kad_random_query` triggers, the next one triggers after this duration.
|
||||
@@ -91,7 +89,7 @@ pub struct DiscoveryBehaviour<TSubstream> {
|
||||
discovery_only_if_under_num: u64,
|
||||
}
|
||||
|
||||
impl<TSubstream> DiscoveryBehaviour<TSubstream> {
|
||||
impl DiscoveryBehaviour {
|
||||
/// Builds a new `DiscoveryBehaviour`.
|
||||
///
|
||||
/// `user_defined` is a list of known address for nodes that never expire.
|
||||
@@ -207,11 +205,8 @@ pub enum DiscoveryOut {
|
||||
ValuePutFailed(record::Key),
|
||||
}
|
||||
|
||||
impl<TSubstream> NetworkBehaviour for DiscoveryBehaviour<TSubstream>
|
||||
where
|
||||
TSubstream: AsyncRead + AsyncWrite + Unpin,
|
||||
{
|
||||
type ProtocolsHandler = <Kademlia<TSubstream, MemoryStore> as NetworkBehaviour>::ProtocolsHandler;
|
||||
impl NetworkBehaviour for DiscoveryBehaviour {
|
||||
type ProtocolsHandler = <Kademlia<MemoryStore> as NetworkBehaviour>::ProtocolsHandler;
|
||||
type OutEvent = DiscoveryOut;
|
||||
|
||||
fn new_handler(&mut self) -> Self::ProtocolsHandler {
|
||||
|
||||
@@ -20,7 +20,7 @@ use crate::utils::interval;
|
||||
use bytes::{Bytes, BytesMut};
|
||||
use futures::prelude::*;
|
||||
use libp2p::{Multiaddr, PeerId};
|
||||
use libp2p::core::{ConnectedPoint, nodes::{listeners::ListenerId, Substream}, muxing::StreamMuxerBox};
|
||||
use libp2p::core::{ConnectedPoint, nodes::listeners::ListenerId};
|
||||
use libp2p::swarm::{ProtocolsHandler, IntoProtocolsHandler};
|
||||
use libp2p::swarm::{NetworkBehaviour, NetworkBehaviourAction, PollParameters};
|
||||
use sp_core::storage::{StorageKey, ChildInfo};
|
||||
@@ -158,7 +158,7 @@ pub struct Protocol<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> {
|
||||
/// When asked for a proof of finality, we use this struct to build one.
|
||||
finality_proof_provider: Option<Arc<dyn FinalityProofProvider<B>>>,
|
||||
/// Handles opening the unique substream and sending and receiving raw messages.
|
||||
behaviour: LegacyProto<Substream<StreamMuxerBox>>,
|
||||
behaviour: LegacyProto,
|
||||
/// List of notification protocols that have been registered.
|
||||
registered_notif_protocols: HashSet<ConsensusEngineId>,
|
||||
}
|
||||
@@ -207,7 +207,7 @@ pub struct PeerInfo<B: BlockT> {
|
||||
}
|
||||
|
||||
struct LightDispatchIn<'a> {
|
||||
behaviour: &'a mut LegacyProto<Substream<StreamMuxerBox>>,
|
||||
behaviour: &'a mut LegacyProto,
|
||||
peerset: sc_peerset::PeersetHandle,
|
||||
}
|
||||
|
||||
@@ -347,7 +347,7 @@ pub trait Context<B: BlockT> {
|
||||
|
||||
/// Protocol context.
|
||||
struct ProtocolContext<'a, B: 'a + BlockT, H: 'a + ExHashT> {
|
||||
behaviour: &'a mut LegacyProto<Substream<StreamMuxerBox>>,
|
||||
behaviour: &'a mut LegacyProto,
|
||||
context_data: &'a mut ContextData<B, H>,
|
||||
peerset_handle: &'a sc_peerset::PeersetHandle,
|
||||
}
|
||||
@@ -355,7 +355,7 @@ struct ProtocolContext<'a, B: 'a + BlockT, H: 'a + ExHashT> {
|
||||
impl<'a, B: BlockT + 'a, H: 'a + ExHashT> ProtocolContext<'a, B, H> {
|
||||
fn new(
|
||||
context_data: &'a mut ContextData<B, H>,
|
||||
behaviour: &'a mut LegacyProto<Substream<StreamMuxerBox>>,
|
||||
behaviour: &'a mut LegacyProto,
|
||||
peerset_handle: &'a sc_peerset::PeersetHandle,
|
||||
) -> Self {
|
||||
ProtocolContext { context_data, peerset_handle, behaviour }
|
||||
@@ -913,14 +913,14 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
|
||||
if peer.block_request.as_ref().map_or(false, |(t, _)| (tick - *t).as_secs() > REQUEST_TIMEOUT_SEC) {
|
||||
log!(
|
||||
target: "sync",
|
||||
if self.important_peers.contains(&who) { Level::Warn } else { Level::Trace },
|
||||
if self.important_peers.contains(who) { Level::Warn } else { Level::Trace },
|
||||
"Request timeout {}", who
|
||||
);
|
||||
aborting.push(who.clone());
|
||||
} else if peer.obsolete_requests.values().any(|t| (tick - *t).as_secs() > REQUEST_TIMEOUT_SEC) {
|
||||
log!(
|
||||
target: "sync",
|
||||
if self.important_peers.contains(&who) { Level::Warn } else { Level::Trace },
|
||||
if self.important_peers.contains(who) { Level::Warn } else { Level::Trace },
|
||||
"Obsolete timeout {}", who
|
||||
);
|
||||
aborting.push(who.clone());
|
||||
@@ -931,7 +931,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
|
||||
{
|
||||
log!(
|
||||
target: "sync",
|
||||
if self.important_peers.contains(&who) { Level::Warn } else { Level::Trace },
|
||||
if self.important_peers.contains(who) { Level::Warn } else { Level::Trace },
|
||||
"Handshake timeout {}", who
|
||||
);
|
||||
aborting.push(who.clone());
|
||||
@@ -1835,7 +1835,7 @@ pub enum CustomMessageOutcome<B: BlockT> {
|
||||
}
|
||||
|
||||
fn send_request<B: BlockT, H: ExHashT>(
|
||||
behaviour: &mut LegacyProto<Substream<StreamMuxerBox>>,
|
||||
behaviour: &mut LegacyProto,
|
||||
stats: &mut HashMap<&'static str, PacketStats>,
|
||||
peers: &mut HashMap<PeerId, Peer<B, H>>,
|
||||
who: &PeerId,
|
||||
@@ -1856,7 +1856,7 @@ fn send_request<B: BlockT, H: ExHashT>(
|
||||
}
|
||||
|
||||
fn send_message<B: BlockT>(
|
||||
behaviour: &mut LegacyProto<Substream<StreamMuxerBox>>,
|
||||
behaviour: &mut LegacyProto,
|
||||
stats: &mut HashMap<&'static str, PacketStats>,
|
||||
who: &PeerId,
|
||||
message: Message<B>,
|
||||
@@ -1870,7 +1870,7 @@ fn send_message<B: BlockT>(
|
||||
|
||||
impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> NetworkBehaviour for
|
||||
Protocol<B, S, H> {
|
||||
type ProtocolsHandler = <LegacyProto<Substream<StreamMuxerBox>> as NetworkBehaviour>::ProtocolsHandler;
|
||||
type ProtocolsHandler = <LegacyProto as NetworkBehaviour>::ProtocolsHandler;
|
||||
type OutEvent = CustomMessageOutcome<B>;
|
||||
|
||||
fn new_handler(&mut self) -> Self::ProtocolsHandler {
|
||||
|
||||
@@ -38,7 +38,14 @@ use libp2p::{
|
||||
upgrade::{InboundUpgrade, ReadOneError, UpgradeInfo, Negotiated},
|
||||
upgrade::{DeniedUpgrade, read_one, write_one}
|
||||
},
|
||||
swarm::{NetworkBehaviour, NetworkBehaviourAction, OneShotHandler, PollParameters, SubstreamProtocol}
|
||||
swarm::{
|
||||
NegotiatedSubstream,
|
||||
NetworkBehaviour,
|
||||
NetworkBehaviourAction,
|
||||
OneShotHandler,
|
||||
PollParameters,
|
||||
SubstreamProtocol
|
||||
}
|
||||
};
|
||||
use prost::Message;
|
||||
use sp_runtime::{generic::BlockId, traits::{Block, Header, One, Zero}};
|
||||
@@ -111,20 +118,17 @@ impl Config {
|
||||
}
|
||||
|
||||
/// The block request handling behaviour.
|
||||
pub struct BlockRequests<T, B: Block> {
|
||||
pub struct BlockRequests<B: Block> {
|
||||
/// This behaviour's configuration.
|
||||
config: Config,
|
||||
/// Blockchain client.
|
||||
chain: Arc<dyn Client<B>>,
|
||||
/// Futures sending back the block request response.
|
||||
outgoing: FuturesUnordered<BoxFuture<'static, ()>>,
|
||||
/// Type witness term.
|
||||
_marker: std::marker::PhantomData<T>
|
||||
}
|
||||
|
||||
impl<T, B> BlockRequests<T, B>
|
||||
impl<B> BlockRequests<B>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
|
||||
B: Block,
|
||||
{
|
||||
pub fn new(cfg: Config, chain: Arc<dyn Client<B>>) -> Self {
|
||||
@@ -132,7 +136,6 @@ where
|
||||
config: cfg,
|
||||
chain,
|
||||
outgoing: FuturesUnordered::new(),
|
||||
_marker: std::marker::PhantomData
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,12 +246,11 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, B> NetworkBehaviour for BlockRequests<T, B>
|
||||
impl<B> NetworkBehaviour for BlockRequests<B>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
|
||||
B: Block
|
||||
{
|
||||
type ProtocolsHandler = OneShotHandler<T, Protocol, DeniedUpgrade, Request<Negotiated<T>>>;
|
||||
type ProtocolsHandler = OneShotHandler<Protocol, DeniedUpgrade, Request<NegotiatedSubstream>>;
|
||||
type OutEvent = Void;
|
||||
|
||||
fn new_handler(&mut self) -> Self::ProtocolsHandler {
|
||||
@@ -269,7 +271,7 @@ where
|
||||
fn inject_disconnected(&mut self, _peer: &PeerId, _info: ConnectedPoint) {
|
||||
}
|
||||
|
||||
fn inject_node_event(&mut self, peer: PeerId, Request(request, mut stream): Request<Negotiated<T>>) {
|
||||
fn inject_node_event(&mut self, peer: PeerId, Request(request, mut stream): Request<NegotiatedSubstream>) {
|
||||
match self.on_block_request(&peer, &request) {
|
||||
Ok(res) => {
|
||||
log::trace!("enqueueing block response {} for peer {} with {} blocks", res.id, peer, res.blocks.len());
|
||||
|
||||
@@ -25,7 +25,7 @@ use libp2p::swarm::{NetworkBehaviour, NetworkBehaviourAction, PollParameters};
|
||||
use log::{debug, error, trace, warn};
|
||||
use rand::distributions::{Distribution as _, Uniform};
|
||||
use smallvec::SmallVec;
|
||||
use std::{borrow::Cow, collections::hash_map::Entry, cmp, error, marker::PhantomData, mem, pin::Pin};
|
||||
use std::{borrow::Cow, collections::hash_map::Entry, cmp, error, mem, pin::Pin};
|
||||
use std::time::Duration;
|
||||
use wasm_timer::Instant;
|
||||
use std::task::{Context, Poll};
|
||||
@@ -60,7 +60,7 @@ use std::task::{Context, Poll};
|
||||
/// Note that this "banning" system is not an actual ban. If a "banned" node tries to connect to
|
||||
/// us, we accept the connection. The "banning" system is only about delaying dialing attempts.
|
||||
///
|
||||
pub struct LegacyProto< TSubstream> {
|
||||
pub struct LegacyProto {
|
||||
/// List of protocols to open with peers. Never modified.
|
||||
protocol: RegisteredProtocol,
|
||||
|
||||
@@ -80,9 +80,6 @@ pub struct LegacyProto< TSubstream> {
|
||||
|
||||
/// Events to produce from `poll()`.
|
||||
events: SmallVec<[NetworkBehaviourAction<CustomProtoHandlerIn, LegacyProtoOut>; 4]>,
|
||||
|
||||
/// Marker to pin the generics.
|
||||
marker: PhantomData<TSubstream>,
|
||||
}
|
||||
|
||||
/// State of a peer we're connected to.
|
||||
@@ -225,7 +222,7 @@ pub enum LegacyProtoOut {
|
||||
},
|
||||
}
|
||||
|
||||
impl<TSubstream> LegacyProto<TSubstream> {
|
||||
impl LegacyProto {
|
||||
/// Creates a `CustomProtos`.
|
||||
pub fn new(
|
||||
protocol: impl Into<ProtocolId>,
|
||||
@@ -241,7 +238,6 @@ impl<TSubstream> LegacyProto<TSubstream> {
|
||||
incoming: SmallVec::new(),
|
||||
next_incoming_index: sc_peerset::IncomingIndex(0),
|
||||
events: SmallVec::new(),
|
||||
marker: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -605,7 +601,7 @@ impl<TSubstream> LegacyProto<TSubstream> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<TSubstream> DiscoveryNetBehaviour for LegacyProto<TSubstream> {
|
||||
impl DiscoveryNetBehaviour for LegacyProto {
|
||||
fn add_discovered_nodes(&mut self, peer_ids: impl Iterator<Item = PeerId>) {
|
||||
self.peerset.discovered(peer_ids.into_iter().map(|peer_id| {
|
||||
debug!(target: "sub-libp2p", "PSM <= Discovered({:?})", peer_id);
|
||||
@@ -614,11 +610,8 @@ impl<TSubstream> DiscoveryNetBehaviour for LegacyProto<TSubstream> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<TSubstream> NetworkBehaviour for LegacyProto<TSubstream>
|
||||
where
|
||||
TSubstream: AsyncRead + AsyncWrite + Unpin,
|
||||
{
|
||||
type ProtocolsHandler = CustomProtoHandlerProto<TSubstream>;
|
||||
impl NetworkBehaviour for LegacyProto {
|
||||
type ProtocolsHandler = CustomProtoHandlerProto;
|
||||
type OutEvent = LegacyProtoOut;
|
||||
|
||||
fn new_handler(&mut self) -> Self::ProtocolsHandler {
|
||||
|
||||
@@ -18,7 +18,7 @@ use super::upgrade::{RegisteredProtocol, RegisteredProtocolEvent, RegisteredProt
|
||||
use bytes::BytesMut;
|
||||
use futures::prelude::*;
|
||||
use futures_timer::Delay;
|
||||
use libp2p::core::{ConnectedPoint, Negotiated, PeerId, Endpoint};
|
||||
use libp2p::core::{ConnectedPoint, PeerId, Endpoint};
|
||||
use libp2p::core::upgrade::{InboundUpgrade, OutboundUpgrade};
|
||||
use libp2p::swarm::{
|
||||
ProtocolsHandler, ProtocolsHandlerEvent,
|
||||
@@ -26,10 +26,11 @@ use libp2p::swarm::{
|
||||
KeepAlive,
|
||||
ProtocolsHandlerUpgrErr,
|
||||
SubstreamProtocol,
|
||||
NegotiatedSubstream,
|
||||
};
|
||||
use log::{debug, error};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use std::{borrow::Cow, error, fmt, io, marker::PhantomData, mem, time::Duration};
|
||||
use std::{borrow::Cow, error, fmt, io, mem, time::Duration};
|
||||
use std::{pin::Pin, task::{Context, Poll}};
|
||||
|
||||
/// Implements the `IntoProtocolsHandler` trait of libp2p.
|
||||
@@ -86,32 +87,22 @@ use std::{pin::Pin, task::{Context, Poll}};
|
||||
/// We consider that we are now "closed" if the remote closes all the existing substreams.
|
||||
/// Re-opening it can then be performed by closing all active substream and re-opening one.
|
||||
///
|
||||
pub struct CustomProtoHandlerProto<TSubstream> {
|
||||
pub struct CustomProtoHandlerProto {
|
||||
/// Configuration for the protocol upgrade to negotiate.
|
||||
protocol: RegisteredProtocol,
|
||||
|
||||
/// Marker to pin the generic type.
|
||||
marker: PhantomData<TSubstream>,
|
||||
}
|
||||
|
||||
impl<TSubstream> CustomProtoHandlerProto<TSubstream>
|
||||
where
|
||||
TSubstream: AsyncRead + AsyncWrite + Unpin,
|
||||
{
|
||||
impl CustomProtoHandlerProto {
|
||||
/// Builds a new `CustomProtoHandlerProto`.
|
||||
pub fn new(protocol: RegisteredProtocol) -> Self {
|
||||
CustomProtoHandlerProto {
|
||||
protocol,
|
||||
marker: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<TSubstream> IntoProtocolsHandler for CustomProtoHandlerProto<TSubstream>
|
||||
where
|
||||
TSubstream: AsyncRead + AsyncWrite + Unpin,
|
||||
{
|
||||
type Handler = CustomProtoHandler<TSubstream>;
|
||||
impl IntoProtocolsHandler for CustomProtoHandlerProto {
|
||||
type Handler = CustomProtoHandler;
|
||||
|
||||
fn inbound_protocol(&self) -> RegisteredProtocol {
|
||||
self.protocol.clone()
|
||||
@@ -132,12 +123,12 @@ where
|
||||
}
|
||||
|
||||
/// The actual handler once the connection has been established.
|
||||
pub struct CustomProtoHandler<TSubstream> {
|
||||
pub struct CustomProtoHandler {
|
||||
/// Configuration for the protocol upgrade to negotiate.
|
||||
protocol: RegisteredProtocol,
|
||||
|
||||
/// State of the communications with the remote.
|
||||
state: ProtocolState<TSubstream>,
|
||||
state: ProtocolState,
|
||||
|
||||
/// Identifier of the node we're talking to. Used only for logging purposes and shouldn't have
|
||||
/// any influence on the behaviour.
|
||||
@@ -155,11 +146,11 @@ pub struct CustomProtoHandler<TSubstream> {
|
||||
}
|
||||
|
||||
/// State of the handler.
|
||||
enum ProtocolState<TSubstream> {
|
||||
enum ProtocolState {
|
||||
/// Waiting for the behaviour to tell the handler whether it is enabled or disabled.
|
||||
Init {
|
||||
/// List of substreams opened by the remote but that haven't been processed yet.
|
||||
substreams: SmallVec<[RegisteredProtocolSubstream<Negotiated<TSubstream>>; 6]>,
|
||||
substreams: SmallVec<[RegisteredProtocolSubstream<NegotiatedSubstream>; 6]>,
|
||||
/// Deadline after which the initialization is abnormally long.
|
||||
init_deadline: Delay,
|
||||
},
|
||||
@@ -175,9 +166,9 @@ enum ProtocolState<TSubstream> {
|
||||
/// If we are in this state, we have sent a `CustomProtocolOpen` message to the outside.
|
||||
Normal {
|
||||
/// The substreams where bidirectional communications happen.
|
||||
substreams: SmallVec<[RegisteredProtocolSubstream<Negotiated<TSubstream>>; 4]>,
|
||||
substreams: SmallVec<[RegisteredProtocolSubstream<NegotiatedSubstream>; 4]>,
|
||||
/// Contains substreams which are being shut down.
|
||||
shutdown: SmallVec<[RegisteredProtocolSubstream<Negotiated<TSubstream>>; 4]>,
|
||||
shutdown: SmallVec<[RegisteredProtocolSubstream<NegotiatedSubstream>; 4]>,
|
||||
},
|
||||
|
||||
/// We are disabled. Contains substreams that are being closed.
|
||||
@@ -185,7 +176,7 @@ enum ProtocolState<TSubstream> {
|
||||
/// outside or we have never sent any `CustomProtocolOpen` in the first place.
|
||||
Disabled {
|
||||
/// List of substreams to shut down.
|
||||
shutdown: SmallVec<[RegisteredProtocolSubstream<Negotiated<TSubstream>>; 6]>,
|
||||
shutdown: SmallVec<[RegisteredProtocolSubstream<NegotiatedSubstream>; 6]>,
|
||||
|
||||
/// If true, we should reactivate the handler after all the substreams in `shutdown` have
|
||||
/// been closed.
|
||||
@@ -257,10 +248,7 @@ pub enum CustomProtoHandlerOut {
|
||||
},
|
||||
}
|
||||
|
||||
impl<TSubstream> CustomProtoHandler<TSubstream>
|
||||
where
|
||||
TSubstream: AsyncRead + AsyncWrite + Unpin,
|
||||
{
|
||||
impl CustomProtoHandler {
|
||||
/// Enables the handler.
|
||||
fn enable(&mut self) {
|
||||
self.state = match mem::replace(&mut self.state, ProtocolState::Poisoned) {
|
||||
@@ -459,7 +447,7 @@ where
|
||||
/// Called by `inject_fully_negotiated_inbound` and `inject_fully_negotiated_outbound`.
|
||||
fn inject_fully_negotiated(
|
||||
&mut self,
|
||||
mut substream: RegisteredProtocolSubstream<Negotiated<TSubstream>>
|
||||
mut substream: RegisteredProtocolSubstream<NegotiatedSubstream>
|
||||
) {
|
||||
self.state = match mem::replace(&mut self.state, ProtocolState::Poisoned) {
|
||||
ProtocolState::Poisoned => {
|
||||
@@ -515,11 +503,9 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<TSubstream> ProtocolsHandler for CustomProtoHandler<TSubstream>
|
||||
where TSubstream: AsyncRead + AsyncWrite + Unpin {
|
||||
impl ProtocolsHandler for CustomProtoHandler {
|
||||
type InEvent = CustomProtoHandlerIn;
|
||||
type OutEvent = CustomProtoHandlerOut;
|
||||
type Substream = TSubstream;
|
||||
type Error = ConnectionKillError;
|
||||
type InboundProtocol = RegisteredProtocol;
|
||||
type OutboundProtocol = RegisteredProtocol;
|
||||
@@ -531,14 +517,14 @@ where TSubstream: AsyncRead + AsyncWrite + Unpin {
|
||||
|
||||
fn inject_fully_negotiated_inbound(
|
||||
&mut self,
|
||||
proto: <Self::InboundProtocol as InboundUpgrade<Negotiated<TSubstream>>>::Output
|
||||
proto: <Self::InboundProtocol as InboundUpgrade<NegotiatedSubstream>>::Output
|
||||
) {
|
||||
self.inject_fully_negotiated(proto);
|
||||
}
|
||||
|
||||
fn inject_fully_negotiated_outbound(
|
||||
&mut self,
|
||||
proto: <Self::OutboundProtocol as OutboundUpgrade<Negotiated<TSubstream>>>::Output,
|
||||
proto: <Self::OutboundProtocol as OutboundUpgrade<NegotiatedSubstream>>::Output,
|
||||
_: Self::OutboundOpenInfo
|
||||
) {
|
||||
self.inject_fully_negotiated(proto);
|
||||
@@ -601,10 +587,7 @@ where TSubstream: AsyncRead + AsyncWrite + Unpin {
|
||||
}
|
||||
}
|
||||
|
||||
impl<TSubstream> fmt::Debug for CustomProtoHandler<TSubstream>
|
||||
where
|
||||
TSubstream: AsyncRead + AsyncWrite + Unpin,
|
||||
{
|
||||
impl fmt::Debug for CustomProtoHandler {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
f.debug_struct("CustomProtoHandler")
|
||||
.finish()
|
||||
@@ -613,10 +596,10 @@ where
|
||||
|
||||
/// Given a list of substreams, tries to shut them down. The substreams that have been successfully
|
||||
/// shut down are removed from the list.
|
||||
fn shutdown_list<TSubstream>
|
||||
(list: &mut SmallVec<impl smallvec::Array<Item = RegisteredProtocolSubstream<Negotiated<TSubstream>>>>,
|
||||
fn shutdown_list
|
||||
(list: &mut SmallVec<impl smallvec::Array<Item = RegisteredProtocolSubstream<NegotiatedSubstream>>>,
|
||||
cx: &mut Context)
|
||||
where TSubstream: AsyncRead + AsyncWrite + Unpin {
|
||||
{
|
||||
'outer: for n in (0..list.len()).rev() {
|
||||
let mut substream = list.swap_remove(n);
|
||||
loop {
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
use futures::{prelude::*, ready};
|
||||
use codec::{Encode, Decode};
|
||||
use libp2p::core::nodes::{Substream, listeners::ListenerId};
|
||||
use libp2p::core::{ConnectedPoint, transport::boxed::Boxed, muxing::StreamMuxerBox};
|
||||
use libp2p::core::nodes::listeners::ListenerId;
|
||||
use libp2p::core::ConnectedPoint;
|
||||
use libp2p::swarm::{Swarm, ProtocolsHandler, IntoProtocolsHandler};
|
||||
use libp2p::swarm::{PollParameters, NetworkBehaviour, NetworkBehaviourAction};
|
||||
use libp2p::{PeerId, Multiaddr, Transport};
|
||||
@@ -31,11 +31,7 @@ use sp_test_primitives::Block;
|
||||
|
||||
/// Builds two nodes that have each other as bootstrap nodes.
|
||||
/// This is to be used only for testing, and a panic will happen if something goes wrong.
|
||||
fn build_nodes()
|
||||
-> (
|
||||
Swarm<Boxed<(PeerId, StreamMuxerBox), io::Error>, CustomProtoWithAddr>,
|
||||
Swarm<Boxed<(PeerId, StreamMuxerBox), io::Error>, CustomProtoWithAddr>
|
||||
) {
|
||||
fn build_nodes() -> (Swarm<CustomProtoWithAddr>, Swarm<CustomProtoWithAddr>) {
|
||||
let mut out = Vec::with_capacity(2);
|
||||
|
||||
let keypairs: Vec<_> = (0..2).map(|_| libp2p::identity::Keypair::generate_ed25519()).collect();
|
||||
@@ -115,12 +111,12 @@ fn build_nodes()
|
||||
|
||||
/// Wraps around the `CustomBehaviour` network behaviour, and adds hardcoded node addresses to it.
|
||||
struct CustomProtoWithAddr {
|
||||
inner: LegacyProto<Substream<StreamMuxerBox>>,
|
||||
inner: LegacyProto,
|
||||
addrs: Vec<(PeerId, Multiaddr)>,
|
||||
}
|
||||
|
||||
impl std::ops::Deref for CustomProtoWithAddr {
|
||||
type Target = LegacyProto<Substream<StreamMuxerBox>>;
|
||||
type Target = LegacyProto;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.inner
|
||||
@@ -134,9 +130,8 @@ impl std::ops::DerefMut for CustomProtoWithAddr {
|
||||
}
|
||||
|
||||
impl NetworkBehaviour for CustomProtoWithAddr {
|
||||
type ProtocolsHandler =
|
||||
<LegacyProto<Substream<StreamMuxerBox>> as NetworkBehaviour>::ProtocolsHandler;
|
||||
type OutEvent = <LegacyProto<Substream<StreamMuxerBox>> as NetworkBehaviour>::OutEvent;
|
||||
type ProtocolsHandler = <LegacyProto as NetworkBehaviour>::ProtocolsHandler;
|
||||
type OutEvent = <LegacyProto as NetworkBehaviour>::OutEvent;
|
||||
|
||||
fn new_handler(&mut self) -> Self::ProtocolsHandler {
|
||||
self.inner.new_handler()
|
||||
|
||||
@@ -40,7 +40,14 @@ use libp2p::{
|
||||
upgrade::{InboundUpgrade, ReadOneError, UpgradeInfo, Negotiated},
|
||||
upgrade::{OutboundUpgrade, read_one, write_one}
|
||||
},
|
||||
swarm::{NetworkBehaviour, NetworkBehaviourAction, OneShotHandler, PollParameters, SubstreamProtocol}
|
||||
swarm::{
|
||||
NegotiatedSubstream,
|
||||
NetworkBehaviour,
|
||||
NetworkBehaviourAction,
|
||||
OneShotHandler,
|
||||
PollParameters,
|
||||
SubstreamProtocol
|
||||
}
|
||||
};
|
||||
use nohash_hasher::IntMap;
|
||||
use prost::Message;
|
||||
@@ -220,7 +227,7 @@ enum PeerStatus {
|
||||
}
|
||||
|
||||
/// The light client handler behaviour.
|
||||
pub struct LightClientHandler<T, B: Block> {
|
||||
pub struct LightClientHandler<B: Block> {
|
||||
/// This behaviour's configuration.
|
||||
config: Config,
|
||||
/// Blockchain client.
|
||||
@@ -239,13 +246,10 @@ pub struct LightClientHandler<T, B: Block> {
|
||||
next_request_id: u64,
|
||||
/// Handle to use for reporting misbehaviour of peers.
|
||||
peerset: sc_peerset::PeersetHandle,
|
||||
/// Type witness term.
|
||||
_marker: std::marker::PhantomData<T>
|
||||
}
|
||||
|
||||
impl<T, B> LightClientHandler<T, B>
|
||||
impl<B> LightClientHandler<B>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
|
||||
B: Block,
|
||||
{
|
||||
/// Construct a new light client handler.
|
||||
@@ -266,7 +270,6 @@ where
|
||||
outstanding: IntMap::default(),
|
||||
next_request_id: 1,
|
||||
peerset,
|
||||
_marker: std::marker::PhantomData
|
||||
}
|
||||
}
|
||||
|
||||
@@ -646,12 +649,11 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, B> NetworkBehaviour for LightClientHandler<T, B>
|
||||
impl<B> NetworkBehaviour for LightClientHandler<B>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
|
||||
B: Block
|
||||
{
|
||||
type ProtocolsHandler = OneShotHandler<T, InboundProtocol, OutboundProtocol, Event<Negotiated<T>>>;
|
||||
type ProtocolsHandler = OneShotHandler<InboundProtocol, OutboundProtocol, Event<NegotiatedSubstream>>;
|
||||
type OutEvent = Void;
|
||||
|
||||
fn new_handler(&mut self) -> Self::ProtocolsHandler {
|
||||
@@ -690,7 +692,7 @@ where
|
||||
self.remove_peer(peer)
|
||||
}
|
||||
|
||||
fn inject_node_event(&mut self, peer: PeerId, event: Event<Negotiated<T>>) {
|
||||
fn inject_node_event(&mut self, peer: PeerId, event: Event<NegotiatedSubstream>) {
|
||||
match event {
|
||||
// An incoming request from remote has been received.
|
||||
Event::Request(request, mut stream) => {
|
||||
@@ -1144,8 +1146,8 @@ mod tests {
|
||||
const CHILD_INFO: ChildInfo<'static> = ChildInfo::new_default(b"foobarbaz");
|
||||
|
||||
type Block = sp_runtime::generic::Block<Header<u64, BlakeTwo256>, substrate_test_runtime::Extrinsic>;
|
||||
type Handler = LightClientHandler<SubstreamRef<Arc<StreamMuxerBox>>, Block>;
|
||||
type Swarm = libp2p::swarm::Swarm<Boxed<(PeerId, StreamMuxerBox), io::Error>, Handler>;
|
||||
type Handler = LightClientHandler<Block>;
|
||||
type Swarm = libp2p::swarm::Swarm<Handler>;
|
||||
|
||||
fn empty_proof() -> Vec<u8> {
|
||||
StorageProof::empty().encode()
|
||||
@@ -1210,7 +1212,7 @@ mod tests {
|
||||
( ok: bool
|
||||
, ps: sc_peerset::PeersetHandle
|
||||
, cf: super::Config
|
||||
) -> LightClientHandler<futures::io::Cursor<Vec<u8>>, Block>
|
||||
) -> LightClientHandler<Block>
|
||||
{
|
||||
let client = Arc::new(substrate_test_runtime_client::new());
|
||||
let checker = Arc::new(DummyFetchChecker::new(ok));
|
||||
@@ -1221,10 +1223,7 @@ mod tests {
|
||||
ConnectedPoint::Dialer { address: Multiaddr::empty() }
|
||||
}
|
||||
|
||||
fn poll<T>(mut b: &mut LightClientHandler<T, Block>) -> Poll<NetworkBehaviourAction<OutboundProtocol, Void>>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite + Unpin + Send + 'static
|
||||
{
|
||||
fn poll(mut b: &mut LightClientHandler<Block>) -> Poll<NetworkBehaviourAction<OutboundProtocol, Void>> {
|
||||
let mut p = EmptyPollParams(PeerId::random());
|
||||
match future::poll_fn(|cx| Pin::new(&mut b).poll(cx, &mut p)).now_or_never() {
|
||||
Some(a) => Poll::Ready(a),
|
||||
|
||||
@@ -504,7 +504,7 @@ impl<B: BlockT> LightDispatch<B> where
|
||||
}
|
||||
|
||||
pub fn is_light_response(&self, peer: &PeerId, request_id: message::RequestId) -> bool {
|
||||
self.active_peers.get(&peer).map_or(false, |r| r.id == request_id)
|
||||
self.active_peers.get(peer).map_or(false, |r| r.id == request_id)
|
||||
}
|
||||
|
||||
fn remove(&mut self, peer: PeerId, id: u64) -> Option<Request<B>> {
|
||||
|
||||
@@ -35,7 +35,6 @@ use sp_consensus::import_queue::{BlockImportResult, BlockImportError};
|
||||
use futures::{prelude::*, channel::mpsc};
|
||||
use log::{warn, error, info, trace};
|
||||
use libp2p::{PeerId, Multiaddr, kad::record};
|
||||
use libp2p::core::{transport::boxed::Boxed, muxing::StreamMuxerBox};
|
||||
use libp2p::swarm::{NetworkBehaviour, SwarmBuilder, SwarmEvent};
|
||||
use parking_lot::Mutex;
|
||||
use sc_peerset::PeersetHandle;
|
||||
@@ -854,7 +853,6 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> Unpin for Net
|
||||
|
||||
/// The libp2p swarm, customized for our needs.
|
||||
type Swarm<B, S, H> = libp2p::swarm::Swarm<
|
||||
Boxed<(PeerId, StreamMuxerBox), io::Error>,
|
||||
Behaviour<B, S, H>
|
||||
>;
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ futures = "0.1.29"
|
||||
futures03 = { package = "futures", version = "0.3.1", features = ["compat"] }
|
||||
futures-timer = "3.0.1"
|
||||
rand = "0.7.2"
|
||||
libp2p = { version = "0.15.0", default-features = false, features = ["libp2p-websocket"] }
|
||||
libp2p = { version = "0.16.0", default-features = false, features = ["libp2p-websocket"] }
|
||||
sp-consensus = { version = "0.8", path = "../../../primitives/consensus/common" }
|
||||
sc-client = { version = "0.8", path = "../../" }
|
||||
sc-client-api = { version = "2.0.0", path = "../../api" }
|
||||
|
||||
@@ -9,7 +9,7 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
futures = "0.3.1"
|
||||
libp2p = { version = "0.15.0", default-features = false }
|
||||
libp2p = { version = "0.16.0", default-features = false }
|
||||
log = "0.4.8"
|
||||
serde_json = "1.0.41"
|
||||
wasm-timer = "0.2"
|
||||
|
||||
@@ -156,7 +156,7 @@ impl PeersState {
|
||||
pub fn priority_not_connected_peer(&mut self) -> Option<NotConnectedPeer> {
|
||||
let id = self.priority_nodes.values()
|
||||
.flatten()
|
||||
.find(|id| self.nodes.get(id).map_or(false, |node| !node.connection_state.is_connected()))
|
||||
.find(|&id| self.nodes.get(id).map_or(false, |node| !node.connection_state.is_connected()))
|
||||
.cloned();
|
||||
id.map(move |id| NotConnectedPeer {
|
||||
state: self,
|
||||
@@ -170,7 +170,7 @@ impl PeersState {
|
||||
pub fn priority_not_connected_peer_from_group(&mut self, group_id: &str) -> Option<NotConnectedPeer> {
|
||||
let id = self.priority_nodes.get(group_id)
|
||||
.and_then(|group| group.iter()
|
||||
.find(|id| self.nodes.get(id).map_or(false, |node| !node.connection_state.is_connected()))
|
||||
.find(|&id| self.nodes.get(id).map_or(false, |node| !node.connection_state.is_connected()))
|
||||
.cloned());
|
||||
id.map(move |id| NotConnectedPeer {
|
||||
state: self,
|
||||
@@ -300,7 +300,7 @@ impl PeersState {
|
||||
|
||||
for id in &peers {
|
||||
// update slots for nodes that become priority
|
||||
if !all_other_groups.contains(&id) {
|
||||
if !all_other_groups.contains(id) {
|
||||
let peer = self.nodes.entry(id.clone()).or_default();
|
||||
match peer.connection_state {
|
||||
ConnectionState::In => self.num_in -= 1,
|
||||
@@ -322,7 +322,7 @@ impl PeersState {
|
||||
/// Remove a peer from a priority group.
|
||||
pub fn remove_from_priority_group(&mut self, group_id: &str, peer_id: &PeerId) {
|
||||
let mut peers = self.priority_nodes.get(group_id).cloned().unwrap_or_default();
|
||||
peers.remove(&peer_id);
|
||||
peers.remove(peer_id);
|
||||
self.set_priority_group(group_id, peers);
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ fn test_once() {
|
||||
|
||||
// If we generate 4, connect to a random node.
|
||||
4 => if let Some(id) = known_nodes.iter()
|
||||
.filter(|n| incoming_nodes.values().all(|m| m != *n) && !connected_nodes.contains(n))
|
||||
.filter(|n| incoming_nodes.values().all(|m| m != *n) && !connected_nodes.contains(*n))
|
||||
.choose(&mut rng) {
|
||||
peerset.incoming(id.clone(), next_incoming_id.clone());
|
||||
incoming_nodes.insert(next_incoming_id.clone(), id.clone());
|
||||
@@ -120,7 +120,7 @@ fn test_once() {
|
||||
6 => peerset_handle.set_reserved_only(false),
|
||||
|
||||
// 7 and 8 are about switching a random node in or out of reserved mode.
|
||||
7 => if let Some(id) = known_nodes.iter().filter(|n| !reserved_nodes.contains(n)).choose(&mut rng) {
|
||||
7 => if let Some(id) = known_nodes.iter().filter(|n| !reserved_nodes.contains(*n)).choose(&mut rng) {
|
||||
peerset_handle.add_reserved_peer(id.clone());
|
||||
reserved_nodes.insert(id.clone());
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ parking_lot = "0.10.0"
|
||||
futures = "0.3.1"
|
||||
futures-timer = "3.0.1"
|
||||
wasm-timer = "0.2.0"
|
||||
libp2p = { version = "0.15.0", default-features = false, features = ["libp2p-websocket"] }
|
||||
libp2p = { version = "0.16.0", default-features = false, features = ["libp2p-websocket"] }
|
||||
log = "0.4.8"
|
||||
pin-project = "0.4.6"
|
||||
rand = "0.7.2"
|
||||
|
||||
@@ -8,7 +8,7 @@ license = "GPL-3.0"
|
||||
|
||||
[dependencies]
|
||||
derive_more = "0.99.2"
|
||||
libp2p = { version = "0.15.0", default-features = false }
|
||||
libp2p = { version = "0.16.0", default-features = false }
|
||||
log = "0.4.8"
|
||||
sp-core = { path= "../../core" }
|
||||
sp-inherents = { version = "2.0.0", path = "../../inherents" }
|
||||
|
||||
@@ -10,7 +10,7 @@ license = "GPL-3.0"
|
||||
futures = "0.3"
|
||||
futures01 = { package = "futures", version = "0.1.29" }
|
||||
log = "0.4.8"
|
||||
libp2p = { version = "0.15.0", default-features = false }
|
||||
libp2p = { version = "0.16.0", default-features = false }
|
||||
console_error_panic_hook = "0.1.6"
|
||||
console_log = "0.1.2"
|
||||
js-sys = "0.3.34"
|
||||
|
||||
Reference in New Issue
Block a user