mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-28 09:11:34 +00:00
Use stronger typing for the public key of identify (#236)
* Use stronger typing for the public key of identify * Add PartialEq/Eq implementations * Fix tests * Also change is_public_key()
This commit is contained in:
@ -148,7 +148,7 @@ mod tests {
|
||||
let temp_file = self::tempfile::NamedTempFile::new().unwrap();
|
||||
let peer_store = ::json_peerstore::JsonPeerstore::new(temp_file.path()).unwrap();
|
||||
|
||||
let peer_id = PeerId::from_public_key(&[1, 2, 3]);
|
||||
let peer_id = PeerId::from_public_key(PublicKeyBytesSlice(&[1, 2, 3]));
|
||||
let addr = "/ip4/0.0.0.0/tcp/0".parse::<Multiaddr>().unwrap();
|
||||
|
||||
peer_store
|
||||
|
@ -38,17 +38,19 @@
|
||||
//!
|
||||
//! ```
|
||||
//! extern crate multiaddr;
|
||||
//! extern crate libp2p_core;
|
||||
//! extern crate libp2p_peerstore;
|
||||
//!
|
||||
//! # fn main() {
|
||||
//! use libp2p_core::{PeerId, PublicKeyBytesSlice};
|
||||
//! use libp2p_peerstore::memory_peerstore::MemoryPeerstore;
|
||||
//! use libp2p_peerstore::{PeerId, Peerstore, PeerAccess};
|
||||
//! use libp2p_peerstore::{Peerstore, PeerAccess};
|
||||
//! use multiaddr::Multiaddr;
|
||||
//! use std::time::Duration;
|
||||
//!
|
||||
//! // In this example we use a `MemoryPeerstore`, but you can easily swap it for another backend.
|
||||
//! let mut peerstore = MemoryPeerstore::empty();
|
||||
//! let peer_id = PeerId::from_public_key(&[1, 2, 3, 4]);
|
||||
//! let peer_id = PeerId::from_public_key(PublicKeyBytesSlice(&[1, 2, 3, 4]));
|
||||
//!
|
||||
//! // Let's write some information about a peer.
|
||||
//! {
|
||||
|
@ -33,13 +33,14 @@ macro_rules! peerstore_tests {
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use {Peerstore, PeerAccess, PeerId};
|
||||
use libp2p_core::PublicKeyBytesSlice;
|
||||
use multiaddr::Multiaddr;
|
||||
|
||||
#[test]
|
||||
fn initially_empty() {
|
||||
$($stmt;)*
|
||||
let peer_store = $create_peerstore;
|
||||
let peer_id = PeerId::from_public_key(&[1, 2, 3]);
|
||||
let peer_id = PeerId::from_public_key(PublicKeyBytesSlice(&[1, 2, 3]));
|
||||
assert_eq!(peer_store.peers().count(), 0);
|
||||
assert!(peer_store.peer(&peer_id).is_none());
|
||||
}
|
||||
@ -48,7 +49,7 @@ macro_rules! peerstore_tests {
|
||||
fn set_then_get_addr() {
|
||||
$($stmt;)*
|
||||
let peer_store = $create_peerstore;
|
||||
let peer_id = PeerId::from_public_key(&[1, 2, 3]);
|
||||
let peer_id = PeerId::from_public_key(PublicKeyBytesSlice(&[1, 2, 3]));
|
||||
let addr = "/ip4/0.0.0.0/tcp/0".parse::<Multiaddr>().unwrap();
|
||||
|
||||
peer_store.peer_or_create(&peer_id).add_addr(addr.clone(), Duration::from_millis(5000));
|
||||
@ -62,7 +63,7 @@ macro_rules! peerstore_tests {
|
||||
// Add an already-expired address to a peer.
|
||||
$($stmt;)*
|
||||
let peer_store = $create_peerstore;
|
||||
let peer_id = PeerId::from_public_key(&[1, 2, 3]);
|
||||
let peer_id = PeerId::from_public_key(PublicKeyBytesSlice(&[1, 2, 3]));
|
||||
let addr = "/ip4/0.0.0.0/tcp/0".parse::<Multiaddr>().unwrap();
|
||||
|
||||
peer_store.peer_or_create(&peer_id).add_addr(addr.clone(), Duration::from_millis(0));
|
||||
@ -76,7 +77,7 @@ macro_rules! peerstore_tests {
|
||||
fn clear_addrs() {
|
||||
$($stmt;)*
|
||||
let peer_store = $create_peerstore;
|
||||
let peer_id = PeerId::from_public_key(&[1, 2, 3]);
|
||||
let peer_id = PeerId::from_public_key(PublicKeyBytesSlice(&[1, 2, 3]));
|
||||
let addr = "/ip4/0.0.0.0/tcp/0".parse::<Multiaddr>().unwrap();
|
||||
|
||||
peer_store.peer_or_create(&peer_id)
|
||||
@ -91,7 +92,7 @@ macro_rules! peerstore_tests {
|
||||
fn no_update_ttl() {
|
||||
$($stmt;)*
|
||||
let peer_store = $create_peerstore;
|
||||
let peer_id = PeerId::from_public_key(&[1, 2, 3]);
|
||||
let peer_id = PeerId::from_public_key(PublicKeyBytesSlice(&[1, 2, 3]));
|
||||
|
||||
let addr1 = "/ip4/0.0.0.0/tcp/0".parse::<Multiaddr>().unwrap();
|
||||
let addr2 = "/ip4/0.0.0.1/tcp/0".parse::<Multiaddr>().unwrap();
|
||||
@ -112,7 +113,7 @@ macro_rules! peerstore_tests {
|
||||
fn force_update_ttl() {
|
||||
$($stmt;)*
|
||||
let peer_store = $create_peerstore;
|
||||
let peer_id = PeerId::from_public_key(&[1, 2, 3]);
|
||||
let peer_id = PeerId::from_public_key(PublicKeyBytesSlice(&[1, 2, 3]));
|
||||
|
||||
let addr1 = "/ip4/0.0.0.0/tcp/0".parse::<Multiaddr>().unwrap();
|
||||
let addr2 = "/ip4/0.0.0.1/tcp/0".parse::<Multiaddr>().unwrap();
|
||||
|
Reference in New Issue
Block a user