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

chore: Upgrade arti_client to 0.24 #18

Merged
merged 17 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
38 changes: 12 additions & 26 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,38 +1,24 @@
[package]
name = "libp2p-community-tor"
version = "0.3.0-alpha"
version = "0.2.0"
binarybaron marked this conversation as resolved.
Show resolved Hide resolved
edition = "2021"
description = "Tor transport for libp2p"
repository = "https://github.com/hannes-furmans/libp2p-community-tor"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the url of this repository.

license = "MIT"
resolver = "2"
binarybaron marked this conversation as resolved.
Show resolved Hide resolved
description = "Tor transport for libp2p."
repository = "https://github.com/umgefahren/libp2p-tor"
authors = ["umgefahren <[email protected]>"]
binarybaron marked this conversation as resolved.
Show resolved Hide resolved
keywords = ["libp2p", "tor", "p2p", "networking"]
categories = ["network-programming", "asynchronous"]

[dependencies]
arti-client = { version = "0.8", default-features = false }
async-std-crate = { package = "async-std", version = "1", optional = true, default-features = false }
arti-client = "0.24.0"
futures = "0.3"
libp2p-core = { version = "0.39" }
thiserror = "1"
tokio-crate = { package = "tokio", version = "1", optional = true, default-features = false }
tor-rtcompat = "0.8"
libp2p = { version = "0.53", default-features = false, features = ["tokio", "tcp", "tls"] }
tor-rtcompat = { version = "0.24.0", features = ["tokio", "rustls"] }
tokio = { version = "1.0", features = ["io-util", "rt", "rt-multi-thread", "macros"] }
tracing = "0.1.40"

[dev-dependencies]
libp2p = { version = "0.51", features = ["mplex", "noise", "ping", "yamux", "macros", "async-std"] }
tokio-crate = { package = "tokio", version = "1", features = ["rt", "macros"] }
async-std-crate = { package = "async-std", version = "1", features = ["attributes"] }

[features]
tokio = ["arti-client/tokio", "dep:tokio-crate"]
async-std = ["arti-client/async-std", "dep:async-std-crate"]
native-tls = ["arti-client/native-tls"]
rustls = ["arti-client/rustls"]

[[example]]
name = "ping-onion"
required-features = ["async-std", "rustls"]
binarybaron marked this conversation as resolved.
Show resolved Hide resolved
libp2p = { version = "0.53", default-features = false, features = ["tokio", "noise", "yamux", "ping", "noise", "macros", "tcp", "tls"] }

[package.metadata.docs.rs]
rustdoc-args = ["--cfg", "docsrs"]
rustc-args = ["--cfg", "docsrs"]
binarybaron marked this conversation as resolved.
Show resolved Hide resolved
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
113 changes: 57 additions & 56 deletions examples/ping-onion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,78 +43,79 @@
//! The two nodes establish a connection, negotiate the ping protocol
//! and begin pinging each other over Tor.

use async_std_crate as async_std;
use futures::prelude::*;
use libp2p::swarm::{keep_alive, NetworkBehaviour, SwarmBuilder, SwarmEvent};
use libp2p::{core::upgrade, identity, mplex, noise, ping, yamux, Multiaddr, PeerId, Transport};
use libp2p_community_tor::{AddressConversion, AsyncStdRustlsTorTransport};
use futures::StreamExt;
use libp2p::core::upgrade::Version;
use libp2p::Transport;
use libp2p::{
core::muxing::StreamMuxerBox,
identity, noise,
swarm::{NetworkBehaviour, SwarmEvent},
yamux, Multiaddr, PeerId, SwarmBuilder,
};
use libp2p_community_tor::{AddressConversion, TorTransport};
use std::error::Error;

async fn onion_transport(
keypair: identity::Keypair,
) -> Result<
libp2p_core::transport::Boxed<(PeerId, libp2p_core::muxing::StreamMuxerBox)>,
Box<dyn Error>,
> {
use std::time::Duration;

let transport = AsyncStdRustlsTorTransport::bootstrapped()
.await?
.with_address_conversion(AddressConversion::IpAndDns);
Ok(transport
.upgrade(upgrade::Version::V1)
.authenticate(
noise::NoiseAuthenticated::xx(&keypair)
.expect("Signing libp2p-noise static DH keypair failed."),
)
.multiplex(upgrade::SelectUpgrade::new(
yamux::YamuxConfig::default(),
mplex::MplexConfig::default(),
))
.timeout(Duration::from_secs(20))
.boxed())
#[derive(NetworkBehaviour)]
struct Behaviour {
ping: libp2p::ping::Behaviour,
}

#[async_std::main]
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let addr = std::env::args().nth(1).expect("no multiaddr given");
let local_key = identity::Keypair::generate_ed25519();
let local_peer_id = PeerId::from(local_key.public());
println!("Local peer id: {:?}", local_peer_id);
println!("Local peer id: {local_peer_id}");

let transport = onion_transport(local_key).await?;
let transport = TorTransport::bootstrapped()
.await?
.with_address_conversion(AddressConversion::IpAndDns)
.boxed();

let auth_upgrade = noise::Config::new(&local_key)?;
let multiplex_upgrade = yamux::Config::default();

let mut swarm =
SwarmBuilder::with_async_std_executor(transport, Behaviour::default(), local_peer_id)
.build();
let transport = transport
.upgrade(Version::V1)
.authenticate(auth_upgrade)
.multiplex(multiplex_upgrade)
.map(|(peer, muxer), _| (peer, StreamMuxerBox::new(muxer)))
.boxed();

let mut swarm = SwarmBuilder::with_new_identity()
.with_tokio()
.with_tcp(
Default::default(),
(libp2p::tls::Config::new, libp2p::noise::Config::new),
libp2p::yamux::Config::default,
)
.unwrap()
.with_other_transport(|_| transport)
.unwrap()
.with_behaviour(|_| Behaviour {
ping: libp2p::ping::Behaviour::default(),
})
.unwrap()
.build();

// Tell the swarm to listen on all interfaces and a random, OS-assigned
// port.
swarm
.listen_on("/ip4/0.0.0.0/tcp/0".parse().unwrap())
.unwrap();

// Dial the peer identified by the multi-address given as the second
// command-line argument, if any.
let remote: Multiaddr = addr.parse()?;
swarm.dial(remote)?;
println!("Dialed {}", addr);
if let Some(addr) = std::env::args().nth(1) {
let remote: Multiaddr = addr.parse()?;
swarm.dial(remote)?;
println!("Dialed {addr}")
}

loop {
match swarm.select_next_some().await {
SwarmEvent::ConnectionEstablished { endpoint, .. } => {
let endpoint_addr = endpoint.get_remote_address();
println!("Connection established to {:?}", endpoint_addr);
}
SwarmEvent::OutgoingConnectionError { error, .. } => {
println!("Error establishing outgoing connection: {:?}", error)
}
SwarmEvent::Behaviour(event) => println!("{:?}", event),
SwarmEvent::NewListenAddr { address, .. } => println!("Listening on {address:?}"),
SwarmEvent::Behaviour(event) => println!("{event:?}"),
_ => {}
}
}
}

/// Our network behaviour.
///
/// For illustrative purposes, this includes the [`KeepAlive`](behaviour::KeepAlive) behaviour so a continuous sequence of
/// pings can be observed.
#[derive(NetworkBehaviour, Default)]
struct Behaviour {
keep_alive: keep_alive::Behaviour,
ping: ping::Behaviour,
}
2 changes: 1 addition & 1 deletion src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// DEALINGS IN THE SOFTWARE.

use arti_client::{DangerouslyIntoTorAddr, IntoTorAddr, TorAddr};
use libp2p_core::{multiaddr::Protocol, Multiaddr};
use libp2p::{core::multiaddr::Protocol, Multiaddr};
use std::net::SocketAddr;

/// "Dangerously" extract a Tor address from the provided [`Multiaddr`].
Expand Down
Loading
Loading