Merge pull request #47 from fluencelabs/fix_test

This commit is contained in:
Dima 2021-02-16 04:21:22 +03:00 committed by GitHub
commit 9e6aedf401
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 4 deletions

View File

@ -23,6 +23,7 @@ use multihash::{Code, Error, Multihash, MultihashDigest};
use rand::Rng;
use std::{convert::TryFrom, fmt, str::FromStr};
use thiserror::Error;
use crate::identity::Keypair;
/// Public keys with byte-lengths smaller than `MAX_INLINE_KEY_LENGTH` will be
/// automatically used as the peer id using an identity multihash.
@ -86,6 +87,11 @@ impl PeerId {
}
}
/// Generates a peerId with a public key in it
pub fn random_with_pk() -> PeerId {
PeerId::from_public_key(Keypair::generate_ed25519().public())
}
/// Generates a random peer ID from a cryptographically secure PRNG.
///
/// This is useful for randomly walking on a DHT, or for testing purposes.

View File

@ -347,7 +347,7 @@ impl<'de> Deserialize<'de> for Multiaddr {
where
D: Deserializer<'de>,
{
struct Visitor { is_human_readable: bool };
struct Visitor { is_human_readable: bool }
impl<'de> de::Visitor<'de> for Visitor {
type Value = Multiaddr;

View File

@ -1941,11 +1941,28 @@ where
.find_map(|q| q.inner.contacts.get(&source))
.cloned()
.and_then(|mut c|
new_address.map(|addr| {
c.insert(addr);
new_address.as_ref().map(|addr| {
c.insert(addr.clone());
c
}));
let contact = contact.or({
let pk = source.as_public_key()
.and_then(|pk| {
match pk {
libp2p_core::identity::PublicKey::Ed25519(pk) => {
Some(pk)
}
_ => {
log::warn!("Cannot create contact with non-ed25519 key.");
None
}
}
});
let address = new_address.map(Addresses::new);
address.zip(pk).map(|(addr, pk)| Contact::new(addr, pk))
});
self.connection_updated(source, contact, NodeStatus::Connected);
}

View File

@ -1119,7 +1119,7 @@ fn manual_bucket_inserts() {
fn network_behaviour_inject_address_change() {
let (_, _, mut kademlia) = build_node();
let remote_peer_id = PeerId::random();
let remote_peer_id = PeerId::random_with_pk();
let connection_id = ConnectionId::new(1);
let old_address: Multiaddr = Protocol::Memory(1).into();
let new_address: Multiaddr = Protocol::Memory(2).into();