mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-04-25 03:02:12 +00:00
Merge pull request #47 from fluencelabs/fix_test
This commit is contained in:
commit
9e6aedf401
@ -23,6 +23,7 @@ use multihash::{Code, Error, Multihash, MultihashDigest};
|
|||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use std::{convert::TryFrom, fmt, str::FromStr};
|
use std::{convert::TryFrom, fmt, str::FromStr};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
use crate::identity::Keypair;
|
||||||
|
|
||||||
/// Public keys with byte-lengths smaller than `MAX_INLINE_KEY_LENGTH` will be
|
/// Public keys with byte-lengths smaller than `MAX_INLINE_KEY_LENGTH` will be
|
||||||
/// automatically used as the peer id using an identity multihash.
|
/// 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.
|
/// Generates a random peer ID from a cryptographically secure PRNG.
|
||||||
///
|
///
|
||||||
/// This is useful for randomly walking on a DHT, or for testing purposes.
|
/// This is useful for randomly walking on a DHT, or for testing purposes.
|
||||||
|
@ -347,7 +347,7 @@ impl<'de> Deserialize<'de> for Multiaddr {
|
|||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
struct Visitor { is_human_readable: bool };
|
struct Visitor { is_human_readable: bool }
|
||||||
|
|
||||||
impl<'de> de::Visitor<'de> for Visitor {
|
impl<'de> de::Visitor<'de> for Visitor {
|
||||||
type Value = Multiaddr;
|
type Value = Multiaddr;
|
||||||
|
@ -1941,11 +1941,28 @@ where
|
|||||||
.find_map(|q| q.inner.contacts.get(&source))
|
.find_map(|q| q.inner.contacts.get(&source))
|
||||||
.cloned()
|
.cloned()
|
||||||
.and_then(|mut c|
|
.and_then(|mut c|
|
||||||
new_address.map(|addr| {
|
new_address.as_ref().map(|addr| {
|
||||||
c.insert(addr);
|
c.insert(addr.clone());
|
||||||
c
|
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);
|
self.connection_updated(source, contact, NodeStatus::Connected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1119,7 +1119,7 @@ fn manual_bucket_inserts() {
|
|||||||
fn network_behaviour_inject_address_change() {
|
fn network_behaviour_inject_address_change() {
|
||||||
let (_, _, mut kademlia) = build_node();
|
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 connection_id = ConnectionId::new(1);
|
||||||
let old_address: Multiaddr = Protocol::Memory(1).into();
|
let old_address: Multiaddr = Protocol::Memory(1).into();
|
||||||
let new_address: Multiaddr = Protocol::Memory(2).into();
|
let new_address: Multiaddr = Protocol::Memory(2).into();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user