Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies #13

Merged
merged 10 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2,495 changes: 1,915 additions & 580 deletions censoring/Cargo.lock

Large diffs are not rendered by default.

22 changes: 9 additions & 13 deletions censoring/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,26 @@ edition = "2021"
chrono = { version = "0.4.19", default-features = false, features = ["clock"] }
delay_map = "0.1.1"

# TODO:
# * Switch back from the forked one, once the `protobuf` encoding is supported in rust-libp2p (libp2p-gossipsub).
# * See https://github.com/libp2p/rust-libp2p/pull/2911 for the progress to support the `protobuf` encoding.
# libp2p = { version = "0.48.0", default-features = false, features = ["gossipsub", "dns-tokio", "tcp-tokio", "noise", "mplex", "yamux", "serde"] }
# NOTE:
# * We are using the fork whose metrics encoding format is fixed to `protobuf`.
# https://github.com/libp2p/rust-libp2p/compare/master...ackintosh:rust-libp2p:prometheus-ptotobuf-support
# * That is due to that `protobuf` encoding is not supported in rust-libp2p (libp2p-gossipsub) yet.
libp2p = { git = "https://github.com/ackintosh/rust-libp2p.git", branch = "prometheus-ptotobuf-support", default-features = false, features = ["gossipsub", "dns-tokio", "tcp-tokio", "noise", "mplex", "yamux", "serde"] }
# TODO: Update libp2p once the next version, which includes prometheus-client v0.20, has been released.
# See https://github.com/ackintosh/rust-libp2p/commit/df09870c8c2294cbaeb881f58d4f9752125562bc
libp2p = { git = "https://github.com/ackintosh/rust-libp2p.git", branch = "prometheus-client-0.20.0", default-features = false, features = ["gossipsub", "dns", "tcp", "tokio", "noise", "mplex", "yamux", "serde"] }

# This is a fork of `libp2p` in order to implement malicious behaviour in the `attacker` module.
# This `libp2p-testground` is used in `attacker` module instead of `libp2p`.
# See https://github.com/ackintosh/rust-libp2p/pull/50
libp2p-testground = { git = "https://github.com/ackintosh/rust-libp2p.git", branch = "testground", package = "libp2p", default-features = false, features = ["gossipsub", "dns-tokio", "tcp-tokio", "noise", "mplex", "yamux", "serde"] }
libp2p-testground = { git = "https://github.com/ackintosh/rust-libp2p.git", rev = "8e8be3f465cb9815fd84184c32805541db546aa7", package = "libp2p", default-features = false, features = ["gossipsub", "dns", "tcp", "tokio", "noise", "mplex", "yamux", "serde"] }

rand = "0.8.5"
serde = "1.0.139"
serde_json = "1.0.82"
testground = "0.4"
# TODO: Update testground once the next version(v0.5.0).
testground = { git = "https://github.com/testground/sdk-rust.git", rev = "1fd032ec29361a00b25c0c8a6bac5f19a43019eb" }
tokio = { version = "1.20.0", features = ["macros"] }
tracing = "0.1.35"
tracing-subscriber = { version = "0.3.14", features = ["env-filter"] }

# TODO: Update once v0.19.0 has been released.
prometheus-client = { git = "https://github.com/prometheus/client_rust.git", rev = "682b24ee8c6c857b76c0683b1dd7df5a97b75c27", features = ["protobuf"] }
# TODO: Update prometheus-client once the next version, which includes the fix, has been released.
# See https://github.com/prometheus/client_rust/pull/123
prometheus-client = { git = "https://github.com/ackintosh/client_rust.git", branch = "fix/protobuf-labels", features = ["protobuf"] }

prost = "0.11"
2 changes: 1 addition & 1 deletion censoring/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This Dockerfile is for the `docker:generic` builder.
# See https://docs.testground.ai/builder-library/docker-generic for details about the builder.
FROM rust:1.62-bullseye as builder
FROM rust:1.67-bullseye as builder
WORKDIR /usr/src/test-plan

# * `prost-build`, a dependency of `libp2p-gossipsub`, requires cmake.
Expand Down
24 changes: 8 additions & 16 deletions censoring/src/attacker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ use libp2p_testground::swarm::{
ConnectionHandler, IntoConnectionHandler, NetworkBehaviour, NetworkBehaviourAction,
NotifyHandler, PollParameters, SwarmBuilder, SwarmEvent,
};
use libp2p_testground::tcp::{GenTcpConfig, TokioTcpTransport};
use libp2p_testground::tcp::tokio::Transport as TcpTransport;
use libp2p_testground::tcp::Config;
use libp2p_testground::yamux::YamuxConfig;
use libp2p_testground::Transport;
use libp2p_testground::{PeerId, Swarm};
use prost::Message;
use std::collections::VecDeque;
use std::sync::Arc;
use std::task::{Context, Poll};
use std::time::Duration;
use testground::client::Client;
Expand Down Expand Up @@ -90,24 +90,19 @@ pub(crate) async fn run(
}

fn build_swarm(keypair: Keypair) -> Swarm<MaliciousBehaviour> {
SwarmBuilder::new(
SwarmBuilder::with_tokio_executor(
build_transport(&keypair),
MaliciousBehaviour::new(),
PeerId::from(keypair.public()),
)
.executor(Box::new(|future| {
tokio::spawn(future);
}))
.build()
}

fn build_transport(
keypair: &Keypair,
) -> libp2p_testground::core::transport::Boxed<(PeerId, StreamMuxerBox)> {
let transport = TokioDnsConfig::system(TokioTcpTransport::new(
GenTcpConfig::default().nodelay(true),
))
.expect("DNS config");
let transport = TokioDnsConfig::system(TcpTransport::new(Config::default().nodelay(true)))
.expect("DNS config");

let noise_keys = libp2p_testground::noise::Keypair::<X25519Spec>::new()
.into_authentic(keypair)
Expand All @@ -125,7 +120,7 @@ fn build_transport(
}

type GossipsubNetworkBehaviourAction =
NetworkBehaviourAction<GossipsubEvent, GossipsubHandler, Arc<GossipsubHandlerIn>>;
NetworkBehaviourAction<GossipsubEvent, GossipsubHandler, GossipsubHandlerIn>;

pub struct MaliciousBehaviour {
/// Configuration providing gossipsub performance parameters.
Expand Down Expand Up @@ -225,7 +220,7 @@ impl MaliciousBehaviour {
self.events
.push_back(NetworkBehaviourAction::NotifyHandler {
peer_id,
event: Arc::new(GossipsubHandlerIn::Message(message)),
event: GossipsubHandlerIn::Message(message),
handler: NotifyHandler::Any,
})
}
Expand Down Expand Up @@ -415,10 +410,7 @@ impl NetworkBehaviour for MaliciousBehaviour {
_params: &mut impl PollParameters,
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ConnectionHandler>> {
if let Some(event) = self.events.pop_front() {
return Poll::Ready(event.map_in(|e: Arc<GossipsubHandlerIn>| {
// clone send event reference if others references are present
Arc::try_unwrap(e).unwrap_or_else(|e| (*e).clone())
}));
return Poll::Ready(event);
}

loop {
Expand Down
Loading