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:
Pierre Krieger
2018-06-05 12:29:59 +02:00
committed by GitHub
parent be2fa0e531
commit dbbee5756e
12 changed files with 134 additions and 41 deletions

View File

@ -31,7 +31,7 @@ use futures::Stream;
use futures::future::Future;
use std::{env, mem};
use libp2p::core::{either::EitherOutput, upgrade};
use libp2p::core::{Multiaddr, Transport};
use libp2p::core::{Multiaddr, Transport, PublicKeyBytesSlice};
use libp2p::peerstore::PeerId;
use libp2p::tcp::TcpConfig;
use tokio_core::reactor::Core;
@ -91,7 +91,7 @@ fn main() {
// or substream to our server.
let my_id = {
let key = (0..2048).map(|_| rand::random::<u8>()).collect::<Vec<_>>();
PeerId::from_public_key(&key)
PeerId::from_public_key(PublicKeyBytesSlice(&key))
};
let (floodsub_upgrade, floodsub_rx) = libp2p::floodsub::FloodSubUpgrade::new(my_id);

View File

@ -33,7 +33,7 @@ use libp2p::Multiaddr;
use std::env;
use std::sync::Arc;
use std::time::Duration;
use libp2p::core::Transport;
use libp2p::core::{Transport, PublicKeyBytesSlice};
use libp2p::core::{upgrade, either::EitherOutput};
use libp2p::tcp::TcpConfig;
use tokio_core::reactor::Core;
@ -96,7 +96,7 @@ fn main() {
// incoming connections, and that will automatically apply secio and multiplex on top
// of any opened stream.
let my_peer_id = PeerId::from_public_key(include_bytes!("test-rsa-public-key.der"));
let my_peer_id = PeerId::from_public_key(PublicKeyBytesSlice(include_bytes!("test-rsa-public-key.der")));
println!("Local peer id is: {:?}", my_peer_id);
// Let's put this `transport` into a Kademlia *swarm*. The swarm will handle all the incoming

View File

@ -21,12 +21,12 @@
extern crate libp2p;
extern crate rand;
use libp2p::PeerId;
use libp2p::{PeerId, core::PublicKeyBytesSlice};
fn main() {
let pid = {
let key = (0..2048).map(|_| rand::random::<u8>()).collect::<Vec<_>>();
PeerId::from_public_key(&key)
PeerId::from_public_key(PublicKeyBytesSlice(&key))
};
println!("{}", pid.to_base58());
}