Skip to content
This repository has been archived by the owner on Jul 1, 2023. It is now read-only.

Commit

Permalink
*: Update to libp2p v0.40.0-rc.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mxinden committed Oct 15, 2021
1 parent b05cad6 commit e710bca
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
libp2p = { version = "0.39.1", default-features = false, features = ["dns-async-std", "noise", "plaintext", "tcp-async-io", "yamux"] }
libp2p = { version = "0.40.0-rc.1", default-features = false, features = ["dns-async-std", "noise", "plaintext", "tcp-async-io", "yamux"] }
futures_codec = "0.4"
futures = "0.3.1"
async-std = { version = "1.6.2", features = ["attributes"] }
Expand Down
38 changes: 25 additions & 13 deletions rust/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use libp2p::{
ConnectedPoint,
},
swarm::{
IntoProtocolsHandler, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler,
DialError, IntoProtocolsHandler, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler,
PollParameters, ProtocolsHandler,
},
Multiaddr, PeerId,
Expand All @@ -18,7 +18,12 @@ use std::time::Duration;
#[derive(Default)]
pub struct Perf {
connected_peers: Vec<(PeerId, Direction)>,
outbox: Vec<NetworkBehaviourAction<<<<Self as NetworkBehaviour>::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::InEvent, <Self as NetworkBehaviour>::OutEvent>>
outbox: Vec<
NetworkBehaviourAction<
<Self as NetworkBehaviour>::OutEvent,
<Self as NetworkBehaviour>::ProtocolsHandler,
>,
>,
}

enum Direction {
Expand Down Expand Up @@ -58,6 +63,7 @@ impl NetworkBehaviour for Perf {
peer_id: &PeerId,
_: &ConnectionId,
connected_point: &ConnectedPoint,
_failed_addresses: Option<&Vec<Multiaddr>>,
) {
let direction = match connected_point {
ConnectedPoint::Dialer { .. } => Direction::Outgoing,
Expand All @@ -67,7 +73,14 @@ impl NetworkBehaviour for Perf {
self.connected_peers.push((peer_id.clone(), direction));
}

fn inject_connection_closed(&mut self, _: &PeerId, _: &ConnectionId, _: &ConnectedPoint) {}
fn inject_connection_closed(
&mut self,
_: &PeerId,
_: &ConnectionId,
_: &ConnectedPoint,
_handler: PerfHandler,
) {
}

fn inject_event(
&mut self,
Expand All @@ -82,16 +95,12 @@ impl NetworkBehaviour for Perf {
}
}

fn inject_addr_reach_failure(
fn inject_dial_failure(
&mut self,
_peer_id: Option<&PeerId>,
_addr: &Multiaddr,
error: &dyn error::Error,
_peer_id: Option<PeerId>,
_handler: PerfHandler,
_error: &DialError,
) {
panic!("inject addr reach failure: {:?}", error);
}

fn inject_dial_failure(&mut self, _peer_id: &PeerId) {
panic!("inject dial failure");
}

Expand All @@ -109,8 +118,11 @@ impl NetworkBehaviour for Perf {
panic!("listener closed {:?}", reason);
}

fn poll(&mut self, _cx: &mut Context, _params: &mut impl PollParameters)
-> Poll<NetworkBehaviourAction<<<Self::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::InEvent, Self::OutEvent>>{
fn poll(
&mut self,
_cx: &mut Context,
_params: &mut impl PollParameters,
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ProtocolsHandler>> {
if let Some(action) = self.outbox.pop() {
return Poll::Ready(action);
}
Expand Down
1 change: 1 addition & 0 deletions rust/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ pub enum PerfHandlerIn {
StartPerf,
}

#[derive(Debug)]
pub enum PerfHandlerOut {
PerfRunDone(Duration, usize),
}
Expand Down

0 comments on commit e710bca

Please sign in to comment.