diff --git a/Cargo.lock b/Cargo.lock index 8707f0a1..61a2d284 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1975,7 +1975,6 @@ dependencies = [ "log", "rand 0.8.5", "redis", - "strum", "tokio", ] @@ -4140,12 +4139,6 @@ dependencies = [ "base64 0.21.0", ] -[[package]] -name = "rustversion" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5583e89e108996506031660fe09baa5011b9dd0341b89029313006d1fb508d70" - [[package]] name = "rw-stream-sink" version = "0.3.0" @@ -4463,28 +4456,6 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" -[[package]] -name = "strum" -version = "0.24.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" -dependencies = [ - "strum_macros", -] - -[[package]] -name = "strum_macros" -version = "0.24.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "rustversion", - "syn", -] - [[package]] name = "stun" version = "0.4.4" diff --git a/interop-tests/Cargo.toml b/interop-tests/Cargo.toml index 159cdc38..da3cc00a 100644 --- a/interop-tests/Cargo.toml +++ b/interop-tests/Cargo.toml @@ -14,5 +14,4 @@ libp2p = { path = "../", features = ["websocket", "quic", "mplex", "yamux", "tc log = "0.4" rand = "0.8.5" redis = { version = "0.22.1", default-features = false, features = ["tokio-comp"] } -strum = { version = "0.24.1", features = ["derive"] } tokio = { version = "1.24.1", features = ["full"] } diff --git a/interop-tests/src/bin/ping.rs b/interop-tests/src/bin/ping.rs index 04363298..113f3bea 100644 --- a/interop-tests/src/bin/ping.rs +++ b/interop-tests/src/bin/ping.rs @@ -17,14 +17,13 @@ use libp2p::{ OutboundUpgradeExt, PeerId, Swarm, Transport as _, }; use redis::AsyncCommands; -use strum::EnumString; #[tokio::main] async fn main() -> Result<()> { let local_key = identity::Keypair::generate_ed25519(); let local_peer_id = PeerId::from(local_key.public()); - let transport_param: Transport = from_env("transport").context("unsupported transport")?; + let transport_param: Transport = from_env("transport")?; let ip = env::var("ip").context("ip environment variable is not set")?; @@ -172,7 +171,7 @@ fn secure_channel_protocol_from_env, >, > { - let either_sec_upgrade = match from_env("security").context("unsupported secure channel")? { + let either_sec_upgrade = match from_env("security")? { SecProtocol::Noise => Either::Left( noise::NoiseAuthenticated::xx(identity).context("failed to intialise noise")?, ), @@ -199,17 +198,14 @@ fn factor_peer_id( } fn muxer_protocol_from_env() -> Result> { - Ok( - match from_env("muxer").context("unsupported multiplexer")? { - Muxer::Yamux => Either::Left(yamux::YamuxConfig::default()), - Muxer::Mplex => Either::Right(mplex::MplexConfig::new()), - }, - ) + Ok(match from_env("muxer")? { + Muxer::Yamux => Either::Left(yamux::YamuxConfig::default()), + Muxer::Mplex => Either::Right(mplex::MplexConfig::new()), + }) } /// Supported transports by rust-libp2p. -#[derive(Clone, Debug, EnumString)] -#[strum(serialize_all = "kebab-case")] +#[derive(Clone, Debug)] pub enum Transport { Tcp, QuicV1, @@ -217,22 +213,58 @@ pub enum Transport { Ws, } +impl FromStr for Transport { + type Err = anyhow::Error; + + fn from_str(s: &str) -> std::result::Result { + Ok(match s { + "tcp" => Self::Tcp, + "quic-v1" => Self::QuicV1, + "webrtc" => Self::Webrtc, + "ws" => Self::Ws, + other => bail!("unknown transport {other}"), + }) + } +} + /// Supported stream multiplexers by rust-libp2p. -#[derive(Clone, Debug, EnumString)] -#[strum(serialize_all = "kebab-case")] +#[derive(Clone, Debug)] pub enum Muxer { Mplex, Yamux, } +impl FromStr for Muxer { + type Err = anyhow::Error; + + fn from_str(s: &str) -> std::result::Result { + Ok(match s { + "mplex" => Self::Mplex, + "yamux" => Self::Yamux, + other => bail!("unknown muxer {other}"), + }) + } +} + /// Supported security protocols by rust-libp2p. -#[derive(Clone, Debug, EnumString)] -#[strum(serialize_all = "kebab-case")] +#[derive(Clone, Debug)] pub enum SecProtocol { Noise, Tls, } +impl FromStr for SecProtocol { + type Err = anyhow::Error; + + fn from_str(s: &str) -> std::result::Result { + Ok(match s { + "noise" => Self::Noise, + "tls" => Self::Tls, + other => bail!("unknown security protocol {other}"), + }) + } +} + #[derive(NetworkBehaviour)] struct Behaviour { ping: ping::Behaviour, @@ -242,8 +274,7 @@ struct Behaviour { /// Helper function to get a ENV variable into an test parameter like `Transport`. pub fn from_env(env_var: &str) -> Result where - T: FromStr, - T::Err: std::error::Error + Send + Sync + 'static, + T: FromStr, { env::var(env_var) .with_context(|| format!("{env_var} environment variable is not set"))?