Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Commit

Permalink
chore: more updating to libp2p
Browse files Browse the repository at this point in the history
  • Loading branch information
rand0m-cloud authored and koivunej committed Apr 1, 2022
1 parent 3b59193 commit 31262b5
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ multihash = { default-features = false, version = "0.11" }
# openssl is required for rsa keygen but not used by the rust-ipfs or its dependencies
openssl = { default-features = false, version = "0.10" }
percent-encoding = { default-features = false, version = "2.1" }
prost = { default-features = false, version = "0.8" }
prost = { default-features = false, version = "0.9" }
serde = { default-features = false, features = ["derive"], version = "1.0" }
serde_json = { default-features = false, version = "1.0" }
structopt = { default-features = false, version = "0.3" }
Expand Down
6 changes: 3 additions & 3 deletions http/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub fn init(
let kp = ipfs::Keypair::rsa_from_pkcs8(&mut pkcs8)
.expect("Failed to turn pkcs#8 into libp2p::identity::Keypair");

let peer_id = kp.public().into_peer_id().to_string();
let peer_id = kp.public().to_peer_id().to_string();

// TODO: this part could be PR'd to rust-libp2p as they already have some public key
// import/export but probably not if ring does not support these required conversions.
Expand Down Expand Up @@ -193,7 +193,7 @@ pub fn load(config: File) -> Result<Config, LoadingError> {

let kp = config_file.identity.load_keypair()?;

let peer_id = kp.public().into_peer_id().to_string();
let peer_id = kp.public().to_peer_id().to_string();

if peer_id != config_file.identity.peer_id {
return Err(LoadingError::PeerIdMismatch {
Expand Down Expand Up @@ -370,7 +370,7 @@ aGVsbG8gd29ybGQ=
.load_keypair()
.unwrap()
.public()
.into_peer_id()
.to_peer_id()
.to_string();

assert_eq!(peer_id, input.peer_id);
Expand Down
4 changes: 2 additions & 2 deletions http/src/v0/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ async fn identity_query<T: IpfsTypes>(

match ipfs.identity().await {
Ok((public_key, addresses)) => {
let peer_id = public_key.clone().into_peer_id();
let peer_id = public_key.to_peer_id();
let id = peer_id.to_string();
let public_key = Base64Pad.encode(public_key.into_protobuf_encoding());
let public_key = Base64Pad.encode(public_key.to_protobuf_encoding());

let addresses = addresses.into_iter().map(|addr| addr.to_string()).collect();

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ impl<Types: IpfsTypes> Ipfs<Types> {
.await?;
let mut addresses = rx.await?;
let public_key = self.keys.get_ref().public();
let peer_id = public_key.clone().to_peer_id();
let peer_id = public_key.to_peer_id();

for addr in &mut addresses {
addr.push(Protocol::P2p(peer_id.into()))
Expand Down
6 changes: 6 additions & 0 deletions src/p2p/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,12 @@ impl<Types: IpfsTypes> NetworkBehaviourEventProcess<PingEvent> for Behaviour<Typ
} => {
error!("ping: failure with {}: {}", peer.to_base58(), error);
}
PingEvent {
peer,
result: Result::Err(PingFailure::Unsupported),
} => {
error!("ping: failure with {}: unsupported", peer.to_base58());
}
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/p2p/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl NetworkBehaviour for SwarmApi {
fn inject_connection_established(
&mut self,
peer_id: &PeerId,
connection_id: &ConnectionId,
_connection_id: &ConnectionId,
endpoint: &ConnectedPoint,
_failed_addresses: Option<&Vec<Multiaddr>>,
_other_established: usize,
Expand All @@ -197,7 +197,7 @@ impl NetworkBehaviour for SwarmApi {

if let ConnectedPoint::Dialer {
address,
role_override,
role_override: _,
} = endpoint
{
// we dialed to the `address`
Expand Down Expand Up @@ -232,8 +232,8 @@ impl NetworkBehaviour for SwarmApi {
peer_id: &PeerId,
_id: &ConnectionId,
endpoint: &ConnectedPoint,
handler: Self::ConnectionHandler,
remaining_established: usize,
_handler: Self::ConnectionHandler,
_remaining_established: usize,
) {
trace!("inject_connection_closed {} {:?}", peer_id, endpoint);
let closed_addr = connection_point_addr(endpoint);
Expand Down Expand Up @@ -301,10 +301,10 @@ impl NetworkBehaviour for SwarmApi {
fn inject_dial_failure(
&mut self,
peer_id: Option<PeerId>,
handler: Self::ConnectionHandler,
_handler: Self::ConnectionHandler,
error: &DialError,
) {
trace!("inject_dial_failure: {:?}", peer_id);
trace!("inject_dial_failure: {:?} ({})", peer_id, error);
if let Some(peer_id) = peer_id {
if self.pending_addresses.contains_key(&peer_id) {
// it is possible that these addresses have not been tried yet; they will be asked
Expand Down Expand Up @@ -348,7 +348,7 @@ fn connection_point_addr(cp: &ConnectedPoint) -> MultiaddrWithoutPeerId {
match cp {
ConnectedPoint::Dialer {
address,
role_override,
role_override: _,
} => MultiaddrWithPeerId::try_from(address.to_owned())
.expect("dialed address contains peerid in libp2p 0.38")
.into(),
Expand Down Expand Up @@ -433,7 +433,7 @@ mod tests {
let (_, mut swarm1) = build_swarm();
let (_, mut swarm2) = build_swarm();

let peer3_id = Keypair::generate_ed25519().public().into_peer_id();
let peer3_id = Keypair::generate_ed25519().public().to_peer_id();

Swarm::listen_on(&mut swarm1, "/ip4/127.0.0.1/tcp/0".parse().unwrap()).unwrap();

Expand Down Expand Up @@ -529,7 +529,7 @@ mod tests {

fn build_swarm() -> (PeerId, libp2p::swarm::Swarm<SwarmApi>) {
let key = Keypair::generate_ed25519();
let peer_id = key.public().into_peer_id();
let peer_id = key.public().to_peer_id();
let transport = build_transport(key).unwrap();

let swarm = SwarmBuilder::new(transport, SwarmApi::default(), peer_id)
Expand Down

0 comments on commit 31262b5

Please sign in to comment.