libp2p-next (#5278)

* Adapt to rust-libp2p#1440.

* Further adapt to libp2p/master.

* Update to libp2p-0.17

* Finishing touches.

* Remove stray TODO.

* Incorporate review feedback.

* Remove unused import.
This commit is contained in:
Roman Borschel
2020-04-08 09:23:21 +02:00
committed by GitHub
parent 1a9c0fee30
commit f8c8355ac7
26 changed files with 1049 additions and 681 deletions
@@ -18,7 +18,7 @@ codec = { package = "parity-scale-codec", default-features = false, version = "1
derive_more = "0.99.2"
futures = "0.3.4"
futures-timer = "3.0.1"
libp2p = { version = "0.16.2", default-features = false, features = ["secp256k1", "libp2p-websocket"] }
libp2p = { version = "0.17.0", default-features = false, features = ["secp256k1", "libp2p-websocket"] }
log = "0.4.8"
prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../utils/prometheus", version = "0.8.0-alpha.5"}
prost = "0.6.1"
@@ -300,7 +300,7 @@ where
.map_err(Error::EncodingProto)?;
self.network.put_value(
hash_authority_id(key.1.as_ref())?,
hash_authority_id(key.1.as_ref()),
signed_addresses,
);
}
@@ -323,7 +323,7 @@ where
for authority_id in authorities.iter() {
self.network
.get_value(&hash_authority_id(authority_id.as_ref())?);
.get_value(&hash_authority_id(authority_id.as_ref()));
}
Ok(())
@@ -408,8 +408,8 @@ where
self.addr_cache.retain_ids(&authorities);
authorities
.into_iter()
.map(|id| hash_authority_id(id.as_ref()).map(|h| (h, id)))
.collect::<Result<HashMap<_, _>>>()?
.map(|id| (hash_authority_id(id.as_ref()), id))
.collect::<HashMap<_, _>>()
};
// Check if the event origins from an authority in the current authority set.
@@ -586,10 +586,8 @@ where
}
}
fn hash_authority_id(id: &[u8]) -> Result<libp2p::kad::record::Key> {
libp2p::multihash::encode(libp2p::multihash::Hash::SHA2256, id)
.map(|k| libp2p::kad::record::Key::new(&k))
.map_err(Error::HashingAuthorityId)
fn hash_authority_id(id: &[u8]) -> libp2p::kad::record::Key {
libp2p::kad::record::Key::new(&libp2p::multihash::Sha2_256::digest(id))
}
fn interval_at(start: Instant, duration: Duration) -> Interval {
@@ -304,7 +304,7 @@ fn handle_dht_events_with_value_found_should_call_set_priority_group() {
// Create sample dht event.
let authority_id_1 = hash_authority_id(key_pair.public().as_ref()).unwrap();
let authority_id_1 = hash_authority_id(key_pair.public().as_ref());
let address_1: Multiaddr = "/ip6/2001:db8::".parse().unwrap();
let mut serialized_addresses = vec![];