mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-05 06:01:20 +00:00
parent
d6f1b9bf5b
commit
1e86c6ed35
@ -5,7 +5,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
arrayvec = "0.4.7"
|
arrayvec = "0.4.7"
|
||||||
base58 = "0.1.0"
|
bs58 = "0.2.0"
|
||||||
bigint = "4.2"
|
bigint = "4.2"
|
||||||
bytes = "0.4"
|
bytes = "0.4"
|
||||||
datastore = { path = "../datastore" }
|
datastore = { path = "../datastore" }
|
||||||
|
@ -62,8 +62,8 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
extern crate arrayvec;
|
extern crate arrayvec;
|
||||||
extern crate base58;
|
|
||||||
extern crate bigint;
|
extern crate bigint;
|
||||||
|
extern crate bs58;
|
||||||
extern crate bytes;
|
extern crate bytes;
|
||||||
extern crate datastore;
|
extern crate datastore;
|
||||||
extern crate fnv;
|
extern crate fnv;
|
||||||
|
@ -4,7 +4,7 @@ version = "0.1.0"
|
|||||||
authors = ["Parity Technologies <admin@parity.io>"]
|
authors = ["Parity Technologies <admin@parity.io>"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
base58 = "0.1.0"
|
bs58 = "0.2.0"
|
||||||
datastore = { path = "../datastore" }
|
datastore = { path = "../datastore" }
|
||||||
futures = "0.1.0"
|
futures = "0.1.0"
|
||||||
owning_ref = "0.3.3"
|
owning_ref = "0.3.3"
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
|
|
||||||
use super::TTL;
|
use super::TTL;
|
||||||
use PeerId;
|
use PeerId;
|
||||||
use base58::{FromBase58, ToBase58};
|
|
||||||
use datastore::{Datastore, JsonFileDatastore, JsonFileDatastoreEntry, Query};
|
use datastore::{Datastore, JsonFileDatastore, JsonFileDatastoreEntry, Query};
|
||||||
use futures::{Future, Stream};
|
use futures::{Future, Stream};
|
||||||
use multiaddr::Multiaddr;
|
use multiaddr::Multiaddr;
|
||||||
@ -32,6 +31,7 @@ use std::io::Error as IoError;
|
|||||||
use std::iter;
|
use std::iter;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::vec::IntoIter as VecIntoIter;
|
use std::vec::IntoIter as VecIntoIter;
|
||||||
|
use bs58;
|
||||||
|
|
||||||
/// Peerstore backend that uses a Json file.
|
/// Peerstore backend that uses a Json file.
|
||||||
pub struct JsonPeerstore {
|
pub struct JsonPeerstore {
|
||||||
@ -70,13 +70,13 @@ impl<'a> Peerstore for &'a JsonPeerstore {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn peer(self, peer_id: &PeerId) -> Option<Self::PeerAccess> {
|
fn peer(self, peer_id: &PeerId) -> Option<Self::PeerAccess> {
|
||||||
let hash = peer_id.as_bytes().to_base58();
|
let hash = bs58::encode(peer_id.as_bytes()).into_string();
|
||||||
self.store.lock(hash.into()).map(JsonPeerstoreAccess)
|
self.store.lock(hash.into()).map(JsonPeerstoreAccess)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn peer_or_create(self, peer_id: &PeerId) -> Self::PeerAccess {
|
fn peer_or_create(self, peer_id: &PeerId) -> Self::PeerAccess {
|
||||||
let hash = peer_id.as_bytes().to_base58();
|
let hash = bs58::encode(peer_id.as_bytes()).into_string();
|
||||||
JsonPeerstoreAccess(self.store.lock_or_create(hash.into()))
|
JsonPeerstoreAccess(self.store.lock_or_create(hash.into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ impl<'a> Peerstore for &'a JsonPeerstore {
|
|||||||
.filter_map(|(key, _)| {
|
.filter_map(|(key, _)| {
|
||||||
// We filter out invalid elements. This can happen if the JSON storage file was
|
// We filter out invalid elements. This can happen if the JSON storage file was
|
||||||
// corrupted or manually modified by the user.
|
// corrupted or manually modified by the user.
|
||||||
PeerId::from_bytes(key.from_base58().ok()?).ok()
|
PeerId::from_bytes(bs58::decode(key).into_vec().ok()?).ok()
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
.wait(); // Wait can never block for the JSON datastore.
|
.wait(); // Wait can never block for the JSON datastore.
|
||||||
|
@ -67,7 +67,7 @@
|
|||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
extern crate base58;
|
extern crate bs58;
|
||||||
extern crate datastore;
|
extern crate datastore;
|
||||||
extern crate futures;
|
extern crate futures;
|
||||||
extern crate multiaddr;
|
extern crate multiaddr;
|
||||||
@ -78,7 +78,6 @@ extern crate serde;
|
|||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use base58::ToBase58;
|
|
||||||
|
|
||||||
pub use self::peerstore::{PeerAccess, Peerstore};
|
pub use self::peerstore::{PeerAccess, Peerstore};
|
||||||
|
|
||||||
@ -103,7 +102,7 @@ pub struct PeerId {
|
|||||||
|
|
||||||
impl fmt::Debug for PeerId {
|
impl fmt::Debug for PeerId {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "PeerId({})", self.multihash.to_base58())
|
write!(f, "PeerId({})", bs58::encode(&self.multihash).into_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user