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

chore: upgrade to libp2p 0.39 #472

Merged
merged 6 commits into from
Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
style: apply cargo fmt
  • Loading branch information
CHr15F0x committed Aug 18, 2021
commit 99c3b816618319048703b82b1334a6df3be22201
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ impl<TRepoTypes: RepoTypes> Future for IpfsFuture<TRepoTypes> {
// off the events from Ipfs and ... this looping goes on for a while.
done = false;
match inner {
Some(SwarmEvent::NewListenAddr{address, ..}) => {
Some(SwarmEvent::NewListenAddr { address, .. }) => {
self.complete_listening_address_adding(address);
}
_ => trace!("{:?}", inner),
Expand Down
41 changes: 31 additions & 10 deletions src/p2p/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ pub(crate) fn eq_greedy(addr0: &Multiaddr, addr1: &Multiaddr) -> bool {
return true;
}
}

true
},
}
_ => false,
}
}
Expand Down Expand Up @@ -329,15 +329,36 @@ mod tests {
#[test]
fn greedy_multiaddr_comparison() {
assert!(eq_greedy(&Multiaddr::empty(), &Multiaddr::empty()));
assert!(eq_greedy(&build_multiaddr!(Ip4([192, 168, 0, 1])), &build_multiaddr!(Ip4([192, 168, 0, 1]))));
assert!(eq_greedy(&build_multiaddr!(Ip4([192, 168, 0, 1]), Tcp(44444u16)), &build_multiaddr!(Ip4([192, 168, 0, 1]))));
assert!(eq_greedy(&build_multiaddr!(Ip4([192, 168, 0, 1])), &build_multiaddr!(Ip4([192, 168, 0, 1]), Tcp(44444u16))));
assert!(eq_greedy(
&build_multiaddr!(Ip4([192, 168, 0, 1])),
&build_multiaddr!(Ip4([192, 168, 0, 1]))
));
assert!(eq_greedy(
&build_multiaddr!(Ip4([192, 168, 0, 1]), Tcp(44444u16)),
&build_multiaddr!(Ip4([192, 168, 0, 1]))
));
assert!(eq_greedy(
&build_multiaddr!(Ip4([192, 168, 0, 1])),
&build_multiaddr!(Ip4([192, 168, 0, 1]), Tcp(44444u16))
));

// At least one protocol segment needs to be there
assert!(!eq_greedy(&Multiaddr::empty(), &build_multiaddr!(Ip4([192, 168, 0, 1]))));
assert!(!eq_greedy(&build_multiaddr!(Ip4([192, 168, 0, 1])), &Multiaddr::empty()));

assert!(!eq_greedy(&build_multiaddr!(Ip4([192, 168, 0, 1]), Tcp(44444u16)), &build_multiaddr!(Ip4([192, 168, 0, 2]))));
assert!(!eq_greedy(&build_multiaddr!(Ip4([192, 168, 0, 2])), &build_multiaddr!(Ip4([192, 168, 0, 1]), Tcp(44444u16))));
assert!(!eq_greedy(
&Multiaddr::empty(),
&build_multiaddr!(Ip4([192, 168, 0, 1]))
));
assert!(!eq_greedy(
&build_multiaddr!(Ip4([192, 168, 0, 1])),
&Multiaddr::empty()
));

assert!(!eq_greedy(
&build_multiaddr!(Ip4([192, 168, 0, 1]), Tcp(44444u16)),
&build_multiaddr!(Ip4([192, 168, 0, 2]))
));
assert!(!eq_greedy(
&build_multiaddr!(Ip4([192, 168, 0, 2])),
&build_multiaddr!(Ip4([192, 168, 0, 1]), Tcp(44444u16))
));
}
}
2 changes: 1 addition & 1 deletion src/p2p/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl<Types: IpfsTypes> NetworkBehaviourEventProcess<KademliaEvent> for Behaviour
};

match event {
InboundRequestServed { request, } => {
InboundRequestServed { request } => {
trace!("kad: inbound {:?} request handled", request);
}
OutboundQueryCompleted { result, id, .. } => {
Expand Down
5 changes: 4 additions & 1 deletion src/p2p/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,10 @@ impl NetworkBehaviour for Pubsub {
score,
});
}
NetworkBehaviourAction::CloseConnection { peer_id, connection } => {
NetworkBehaviourAction::CloseConnection {
peer_id,
connection,
} => {
return Poll::Ready(NetworkBehaviourAction::CloseConnection {
peer_id,
connection,
Expand Down
15 changes: 10 additions & 5 deletions src/p2p/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,13 @@ impl NetworkBehaviour for SwarmApi {

fn connection_point_addr(cp: &ConnectedPoint) -> MultiaddrWithoutPeerId {
match cp {
ConnectedPoint::Dialer { address } => MultiaddrWithPeerId::try_from(address.to_owned()).expect("dialed address contains peerid in libp2p 0.38").into(),
ConnectedPoint::Listener { send_back_addr, .. } => send_back_addr.to_owned().try_into().expect("send back address does not contain peerid in libp2p 0.38"),
ConnectedPoint::Dialer { address } => MultiaddrWithPeerId::try_from(address.to_owned())
.expect("dialed address contains peerid in libp2p 0.38")
.into(),
ConnectedPoint::Listener { send_back_addr, .. } => send_back_addr
.to_owned()
.try_into()
.expect("send back address does not contain peerid in libp2p 0.38"),
}
}

Expand All @@ -442,7 +447,7 @@ mod tests {
Swarm::listen_on(&mut swarm1, "/ip4/127.0.0.1/tcp/0".parse().unwrap()).unwrap();

loop {
if let Some(SwarmEvent::NewListenAddr{..}) = swarm1.next().await {
if let Some(SwarmEvent::NewListenAddr { .. }) = swarm1.next().await {
break;
}
}
Expand Down Expand Up @@ -502,7 +507,7 @@ mod tests {
let addr;

loop {
if let Some(SwarmEvent::NewListenAddr {address, ..}) = swarm1.next().await {
if let Some(SwarmEvent::NewListenAddr { address, .. }) = swarm1.next().await {
// wonder if there should be a timeout?
addr = address;
break;
Expand Down Expand Up @@ -543,7 +548,7 @@ mod tests {
let mut addr = Vec::with_capacity(2);

while addr.len() < 2 {
if let Some(SwarmEvent::NewListenAddr {address, ..}) = swarm1.next().await {
if let Some(SwarmEvent::NewListenAddr { address, .. }) = swarm1.next().await {
addr.push(address);
}
}
Expand Down