Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
185 commits
Select commit Hold shift + click to select a range
091586f
build: moved tor_crypto.rs and tor_controller.rs to own tor-interface…
May 15, 2023
ed69cae
tor-interface: refactored tor-interface modules; converted crate erro…
May 20, 2023
6d2b3fe
tor_crypto: made signbit an actual enum type rather than using a u8
May 26, 2023
eb22867
tor-interface: added various fmt::Debug and From trait implementations
May 28, 2023
3551c7f
tor-interface: migrated various structs into their own modules
May 29, 2023
a44eb14
gosling, honk-rpc, tor-interface: fixed clippy warnings
May 29, 2023
2f15547
tor-interface: added comment justifying the min required version check
May 31, 2023
8aa9d29
tor-interface: added initial tor traits to generalise TorManager type
Jun 18, 2023
0c03ba4
tor-interface, gosling: implemented new tor provider interfaces and f…
Jun 18, 2023
622c22c
tor-crypto: converted V3OnionServiceId to_string() to std::fmt::Displ…
Jun 18, 2023
55456f3
tor-interface, gosling: OnionStream now exposes custom TargetAddr for…
Jun 18, 2023
5ab195a
tor-interface: renamed various modules to include legacy in the name …
Jun 18, 2023
08cfec4
tor-interface: reduced visibility of internal modules
Jun 18, 2023
4b898c6
tor-interface: renamed many types to include 'Legacy' in the name
Jun 18, 2023
53e5cb1
tor-interface: fixed clippy errors
Jun 18, 2023
8e22493
tor-interface: implemented skeleton for MockTorClient TorProvider
Jun 19, 2023
f098e21
tor-interface: refactored OnionAddr to more closely align with Socket…
Jun 19, 2023
312184f
tor-interface: derived more helper traits for OnionAddr, OnionAddrV3 …
Jun 19, 2023
cd5ccc6
tor-interface: initial MockTorClient implementation
Jun 19, 2023
b7ea86b
tor-interface: refactor to enable dynamic usage of a virtual TorProvi…
Jun 23, 2023
b2e2980
tor-interface, gosling: TorProvider trait now uses a generic error ty…
Jun 23, 2023
3503304
tor-interface, gosling: updated tests to take a Box<dyn TorProvider>
Jun 23, 2023
24edb04
build: added 'offline-test' feature to gosling for automation
Jun 24, 2023
89ec998
build: added separate coverage-offline make target
Jun 29, 2023
69c6a3c
build: updated system to support offline test targets
Jul 1, 2023
5ea6391
format: fixed format errors
Jul 1, 2023
80fedb8
build: fix cmake target dependencies so that Rust source changes trig…
Jul 16, 2023
fd87e23
gosling: moved TorProvider integration tests to gosling/tests/tor_pro…
Jul 24, 2023
36e3afe
tor-interface: re-ran make format
Jul 24, 2023
652bb12
tor-interface: test refactor
Jul 25, 2023
3414a28
tor-interface: added initial fuzz support for the tor_crypto module
Aug 26, 2023
16abcb8
tor-interface: update the from_raw() method on Ed25519PrivateKey to v…
Aug 26, 2023
bf757bc
tor-interface: updated Ed25519PrivateKey::from_raw() function to chec…
Aug 27, 2023
df475d3
tor-interface: implement PartialEq for X25119PrivateKey
Aug 27, 2023
2e5c2e1
tor-interface: updated the from_raw() method on X25519PrivateKey to v…
Aug 28, 2023
f35be44
tor-interface: implmented fuzzing function for tor_interface::tor_cry…
Aug 28, 2023
95c2dd8
tor-interface: implement Debug for TorEvent enum
Sep 17, 2023
71c2fce
honk-rpc, tor-interface, gosling, gosling-ffi: set all crate versions…
Sep 18, 2023
b09139c
tor-interface: fix formatting errors
Nov 18, 2023
f600194
tor-interface: updated Cargo.toml file with more metadata
Dec 3, 2023
085f185
tor-interface: replaced rust-crypto crate usage with sha1 and sha3
Dec 18, 2023
3d3cedf
honk-rpc, tor-ingterface: fix clippy errors
Dec 18, 2023
3870f5a
tor-interface, gosling-ffi, test: fixed various formatting errors
Dec 18, 2023
8caaa78
tor-interface, gosling-ffi: renamed some size constants to be mutally…
Dec 23, 2023
b0307e7
tor-interface, gosling-ffi: bumped crate version due to api-breaking …
Dec 23, 2023
8144645
build: updated Makefile and verified each of our make targets
Dec 28, 2023
616834b
tor-interface: removed control-port read/write printlns
Dec 29, 2023
8cb858c
build: update cargo+cmake integration, properly setup targets and dep…
Jan 26, 2024
e5c16dc
build: move dependency handling of build and test targets into cmake …
Feb 17, 2024
243c7b4
build: reduced required rustc version to 1.63 (from 1.66)
Feb 19, 2024
70a633c
cargo: added Cargo.lock files to source control
Feb 24, 2024
8409d3e
build: updated cmake build files to be more idiomatic; added various …
Mar 3, 2024
355fad8
workflow: update fuzz actions to use cmake targets
Mar 8, 2024
062ec4c
build: removed fuzz .gitignore files
Mar 11, 2024
adc5835
gosling: separate protocol and crate version; update fuzz tests to re…
Mar 13, 2024
72dedc1
cgosling: updated cbindgen dependency and disabled unnecessary features
Mar 15, 2024
960798e
build: updated Rust version minimium requirements to 1.70
Mar 23, 2024
51998bd
tor-interface: update tor-llcrypto dependency to 0.7.0
Mar 26, 2024
fec73ba
tor-interface: fixed a few clippy errors
Mar 28, 2024
f93e064
tor-interface: replace inline constant math in tor_crypto with hard-c…
Mar 29, 2024
c1d4c19
tor-interface: fixed typo in X25519_PUBLIC_KEY_BASE32_SIZE comment
Mar 30, 2024
8ce8ab9
build: removed offline tests in preparation for future feature flags
Apr 1, 2024
b78630b
build: fixed names of old 'offline' tests
Apr 1, 2024
d3b1ed9
build: added ENABLE_LEGACY_TOR_PROVIDER cmake build flag
Mar 29, 2024
cf2a461
build: added ENABLE_MOCK_TOR_PROVIDER cmake build flag
Apr 1, 2024
8b4dcfb
test: added -- --nocapture flags to all cargo tests for easier debugging
Apr 4, 2024
15ed7ce
tor-interface: update tor-llcrypto to 0.18.0
May 1, 2024
81915ae
tor-interface: split apart tests and genericized TorProvider tests
Apr 13, 2024
8beeb03
tor-interface: add arti-client based TorProvider stub gated on ENABLE…
Apr 2, 2024
3b443ec
tor-interface: implement ArtiClientTorCLient::new() method
Apr 3, 2024
2127d0d
tor-interface: add bootstrap support to ArtiClientTorClient
Apr 4, 2024
b4a98dd
tor-interface: expose inner expanded_keypair on Ed25519PrivateKey whe…
Apr 5, 2024
fa92a83
tor-interface: implement listener() method on ArtiClientTorClient
Apr 6, 2024
44867dd
tor-interface: implement connect() method on ArtiClientTorClient
Apr 11, 2024
f5b90b3
tor-interface: added test cases for ArtiClientTorProvider
Apr 13, 2024
c1556a4
tor-interface: added mixed-mode tests with LegacyTorClient and ArtiCl…
Apr 13, 2024
0340173
tor-interface: add timeout and alive flag check to forward_stream() f…
May 25, 2024
92626a3
build: remove Cargo.lock from fuzz projects and add to local .gitignore
May 25, 2024
4bce3fe
test: reformat test workflow to use a matrix
May 25, 2024
781e61c
tor-interface: tweak forward_traffic function to allow limited additi…
May 26, 2024
5c92053
tor-interface: changed function signature of TorProvider::connect() t…
May 26, 2024
e175a45
build: add corpus to fuzz test local .gitignore's
May 31, 2024
565374f
build: ran 'make format'
Jun 1, 2024
0915869
build: added 'artifacts' to fuzz tests local .gitignore
Jun 1, 2024
959bf5b
tor-interface: implement FromStr for TargetAddr
Jun 15, 2024
d6e25b6
tor-interface: implement TryFrom<(String, u16)> for DomainAddr
Jun 15, 2024
90f85b8
tor-interface: implement Display for TargetAddr
Jun 15, 2024
90beeb6
tor-interface: allow TorProvider's to connect to non-onion service ta…
Jun 16, 2024
9555448
tor-interface: LegacyTorClient now takes a LegacyTorClientConfig
Jun 16, 2024
402b843
tor-interface: refactor to make daemon process optional
Jun 16, 2024
aefa8ca
tor-interface: refactor to make socks_listener optionally setable in …
Jun 16, 2024
7e3daa8
tor-interface: explcitly save off bootstrap status and check in Legac…
Jun 16, 2024
b6618f1
tor-interface: add support for manually specifying socks address, con…
Jun 17, 2024
b9d27ba
tor-interface: removed spurious newline from default_torrc
Jun 23, 2024
3f1b410
tor-interface: added missing catchall test
Jun 22, 2024
c36ddfa
tor-interface: update signature of SETCONF related functions in Legac…
Jun 22, 2024
d74e068
tor-interface: set legacy tor daemon working directory to its data di…
Jun 25, 2024
7a3a62b
tor-interface: fix bug where control-port QuotedStrings were not esca…
Jul 2, 2024
d02977a
tor-interface: stubbed out additional configuration options for bundl…
Jun 21, 2024
66e8833
tor-interface: add support for bundled LegacyTorClient proxy settings
Jun 21, 2024
9737a30
tor-interface: add support for bundled LegacyTorClient firewall settings
Jun 22, 2024
0b540ae
tor-interface: add support for bundled LegacyTorClient pluggable tran…
Jun 22, 2024
5387a15
tor-interface: add support for bundled LegacyTorClient bridge settings
Jun 22, 2024
d3b88e6
tor-interface: add bootstrap test using pluggable transport
Jun 23, 2024
568bd90
tor-interface: force more restrictive version requirements to ensure …
Jul 2, 2024
9941154
tor-interface: updated version to 0.3.0
Jul 2, 2024
6d1a7c3
tor-interface, gosling, cgosling, test: re-ran make format
Jul 21, 2024
55ae36c
tor-interface: fix test compile failure when not using legacy-tor-pro…
Jul 18, 2024
2eb5020
tor-interface: remove unused and now unnecessary Ed25519PrivateKey::s…
Jul 21, 2024
778a012
tor-interface: removed unused Ed25519PublicKey::to_base32() method
Jul 21, 2024
18e421b
tor-interface: fixed bug where DomainAddr could be constructed with a…
morganava Jul 24, 2024
084df59
tor-interface: fixed bug where OnionStream::local_addr() was not impl…
morganava Jul 24, 2024
6c06275
tor-interface: renamed TargetAddr::Ip to TargetAddr::Socket for consi…
morganava Jul 24, 2024
fdc9685
tor-interface: merged various parse errors into one
morganava Jul 24, 2024
cc2a09d
tor-interface: de-duplicated copy-pasted OnionListener logic in favor…
morganava Jul 24, 2024
6e6f97d
tor-interface: add crate README.md
Jul 22, 2024
e07bfb7
tor-interface: migrate proxy configuration implementation to seperate…
Jul 22, 2024
aff70e5
tor-interface: drafted in-source documentation of tor_crypto's public…
Jul 22, 2024
b0c47fb
tor-interface: draft in-source documentation of proxy's public API su…
Jul 22, 2024
9b435ec
tor-interface: migrate pluggable-transport and bridge line configurat…
morganava Jul 23, 2024
f6b2008
tor-interface: drafted in-source documentation of censorship_circumve…
morganava Jul 23, 2024
5bd401d
tor-interface: drafted in-source documentation of tor_provider's publ…
morganava Jul 26, 2024
14b046e
tor-interface: drafted in-source documentation of mock_tor_client, le…
morganava Jul 28, 2024
d7bc144
tor-interface: made LegacyTorVersion public and drafted in-source dou…
morganava Jul 28, 2024
fe34a19
tor-interface: update arti-client crate and dependencies to 0.20.0
morganava Jul 28, 2024
f53d310
tor-interface: fix forward_stream() function type annotations
morganava Jul 28, 2024
737faf6
honk-rpc, tor-interface, gosling, cgosling: version updates
morganava Aug 24, 2024
f1ee474
gosling: fix various build warnings/test failures when no tor-provide…
morganava Sep 3, 2024
1abfd02
tor-interface: updated arti-client to 0.22.0
morganava Sep 3, 2024
5e6fff4
tor-interface: replaced deprecated OnionService::new() call with Onio…
morganava Sep 6, 2024
3deb145
tor-interface: added support for configuring onion-services with clie…
morganava Sep 7, 2024
13b79c5
tor-interface: add explicit bootstrapped flag to gracefully handle re…
morganava Sep 22, 2024
c964cac
tor-interface: updated arti-client to 0.23.0
morganava Oct 6, 2024
3c3137b
tor-interface: use arti_client::TorClient::launch_onion_service_with_…
morganava Sep 9, 2024
2182d69
tor-interface: implement add_client_auth() and remove_client_auth() m…
morganava Sep 9, 2024
af17c01
tor-interface: temporarily update arti-client related crates to revis…
morganava Oct 6, 2024
2a2b3e1
tor-interface: create builder functions for various TorProvider imple…
morganava Oct 22, 2024
01f0096
tor-interface: add some connect retries to the client-authentication …
morganava Oct 27, 2024
331bb61
tor-interface: update arti-client and friends to 0.24.0
morganava Nov 2, 2024
80569a4
tor-interface, gosling, cgosling: version updates
morganava Nov 16, 2024
18bdb87
tor-interface: rename test_arti_authenticated_onion_service to test_a…
morganava Nov 28, 2024
1c3eb23
tor-interface: implement Debug trait for OnionStream
morganava Nov 29, 2024
e289c4a
tor-interface: add outgoing connection attempts to each supported Tar…
morganava Nov 29, 2024
6465dc5
tor-interface: migrated TargetAddr tests to seperate tor_utils.rs file
morganava Nov 29, 2024
d37349d
tor-interface: implement stub ArtiTorClient TorProvider
morganava Oct 19, 2024
a506c0e
tor-interface: implement currently failing bootstrap test for ArtiTor…
morganava Nov 28, 2024
246adc4
tor-interface: implement arti_process for ArtiTorClient
morganava Oct 27, 2024
3a860f8
tor-interface: ArtiClient now creates an ArtiProcess from ArtiTorClie…
morganava Nov 28, 2024
c537dd7
tor-interface: initial art-rpc-client-core integration
morganava Nov 29, 2024
ca2c1f7
tor-interface: implement fake-bootstrapping in ArtiTorClient
morganava Nov 29, 2024
0885d02
tor-interface: mostly implement ArtiTorClient::connect()
morganava Nov 29, 2024
a260633
tor-interface: add support for circuit isolation to ArtiTorProvider
morganava Nov 29, 2024
6056bb0
tor-interface: forward arti stdout lines to TorEvent::LogLine in Arti…
morganava Nov 29, 2024
8db5255
workflows, tor-interface: stubbed out/enabled tests exercising ArtiTo…
morganava Nov 29, 2024
0831901
extern, tor-interface, cgosling: update tor-expert-bundle to latest a…
morganava Feb 8, 2025
28cc3b9
tor-interface: updated arti to 0.27.0
morganava Feb 8, 2025
2d75a33
tor-interface: updated arti to 0.31.0
morganava Jun 10, 2025
cff9b6e
tor-interface: fix test_legacy_pluggable_transport_bootstrap() when $…
nabijaczleweli Jun 24, 2025
bfb99a0
tor-interface: fix comments
nabijaczleweli Jun 9, 2025
3abd417
tor-interface: flatten redundant double-init
nabijaczleweli Jun 24, 2025
6e87770
tor-interface: unify 250 checking in LegacyTorController
nabijaczleweli Jun 10, 2025
79c124e
tor-interface: send commands in one, instead of two, writes
nabijaczleweli Jun 9, 2025
bf2274c
tor-interface: support cookie auth in LegacyTorClientConfig
nabijaczleweli Jun 9, 2025
3bba669
tor-interface: use COOKIEFILE if provided
nabijaczleweli Jun 9, 2025
3462ea7
tor-interface: use SAFECOOKIE authentication when possible
nabijaczleweli Jun 9, 2025
57714e6
tor-interface: simplify post-auth setup flow if possible
nabijaczleweli Jun 10, 2025
95464b1
tor-interface: move instead of unnecessary cloning
nabijaczleweli Jun 11, 2025
78c79a0
tor-provider: genericise TorProvider over Stream/Listener, OnionListe…
nabijaczleweli Jun 30, 2025
e5fda65
Devirtualise TcpOnionListener
nabijaczleweli Jul 1, 2025
470cb57
tor-provider: provide ArtiClientTorClient via ArtiClientOnionStream
nabijaczleweli Jul 1, 2025
f1c157e
tor-provider: provide ArtiClientTorClient via ArtiClientOnionListener
nabijaczleweli Jul 1, 2025
9f9163b
tor-interface: use TcpOrUnixStream and SocketAddrOrUnixSocketAddr, al…
nabijaczleweli Jun 9, 2025
30cb1d1
tor-interface: add LegacyTorClientConfig::system_from_environment()
nabijaczleweli Jun 9, 2025
655f65a
tor-interface: add optional binding address parameter to TorProvider:…
nabijaczleweli Jun 24, 2025
c94cbee
tor-interface: add examples
nabijaczleweli Jun 9, 2025
b934f1c
tor-interface: #[derive(ZeroizeOnDrop)] TorAuth
nabijaczleweli Jun 24, 2025
2098c93
tor-interface: add TcpOnionListener::try_clone_inner()
nabijaczleweli Jun 24, 2025
48098ba
tor-interface: add OnionListener::address()
nabijaczleweli Jun 24, 2025
95ac49d
tor-interface: #[derive(Clone, Debug, PartialEq, Eq)] TargetAddr
nabijaczleweli Jun 24, 2025
ca67543
Adapt to work under core
nabijaczleweli Aug 6, 2025
c7b344f
Make unstoppable swap whonix friendly
nabijaczleweli Jun 8, 2025
09e4123
Use system Tor daemon for listening for connections on whonix. Skip i…
nabijaczleweli Jun 12, 2025
2b2fca7
Merge tor-interface from https://github.com/eigenwallet/libp2p-tor/pu…
nabijaczleweli Aug 6, 2025
58d5934
Apply https://github.com/nabijaczleweli/libp2p-tor bce21996c7c3cfcc9f…
nabijaczleweli Aug 6, 2025
3c61fef
Use tor-interface implementation unified into libp2p-tor
nabijaczleweli Jun 15, 2025
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
990 changes: 792 additions & 198 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion libp2p-rendezvous-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2018"
anyhow = "1"
futures = { workspace = true }
libp2p = { workspace = true, default-features = false, features = ["rendezvous", "tcp", "yamux", "dns", "noise", "ping", "websocket", "tokio", "macros"] }
libp2p-tor = { path = "../libp2p-tor", features = ["listen-onion-service"] }
libp2p-tor = { path = "../libp2p-tor", features = ["listen-onion-service", "legacy-tor-provider"] }
tokio = { workspace = true, features = ["rt-multi-thread", "time", "macros", "sync", "process", "fs", "net", "io-util"] }
tor-hsservice = { workspace = true }
tracing = { workspace = true, features = ["attributes"] }
Expand Down
9 changes: 9 additions & 0 deletions libp2p-tor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ thiserror = { workspace = true }
tokio = { workspace = true }

arti-client = { workspace = true, features = ["tokio", "rustls", "onion-service-client", "static-sqlite"] }
# tor-interface = { git = "https://github.com/nabijaczleweli/gosling", rev = "32988e5770c12f1b48b865c158509473123eae90", optional = true }
tor-interface = { path = "../tor-interface", optional = true }
libp2p = { workspace = true, features = ["tokio", "tcp", "tls"] }

data-encoding = { version = "2.6.0" }
Expand All @@ -37,11 +39,18 @@ listen-onion-service = [
"dep:tor-cell",
"dep:tor-proto",
]
arti-client-tor-provider = ["tor-interface", "tor-interface/arti-client-tor-provider"]
legacy-tor-provider = ["tor-interface", "tor-interface/legacy-tor-provider"]
mock-tor-provider = ["tor-interface", "tor-interface/mock-tor-provider"]

[[example]]
name = "ping-onion"
required-features = ["listen-onion-service"]

[[example]]
name = "ping-onion-tor-interface"
required-features = ["tor-interface"]

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
7 changes: 7 additions & 0 deletions libp2p-tor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ let mut transport = libp2p_tor::TorTransport::bootstrapped().await?;
// we have achieved tor connection
let _conn = transport.dial(address)?.await?;
```
```rust
let address = "/dns/www.torproject.org/tcp/1000".parse()?;
let mut provider = libp2p_tor_interface::tor_interface::/* whichever one you want */;
let mut transport = libp2p_tor_interface::TorInterfaceTransport::from_provider(Default::default(), Arc::new(Mutex::new(provider)), None);
// we have achieved tor connection
let _conn = transport.dial(address)?.await?;
```

### About

Expand Down
146 changes: 146 additions & 0 deletions libp2p-tor/examples/ping-onion-tor-interface.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
// Copyright 2022 Hannes Furmans
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

//! Ping-Onion example
//!
//! See ../src/tutorial.rs for a step-by-step guide building the example below.
//!
//! This example requires two seperate computers, one of which has to be reachable from the
//! internet.
//!
//! On the first computer run:
//! ```sh
//! cargo run --example ping
//! ```
//!
//! It will print the PeerId and the listening addresses, e.g. `Listening on
//! "/ip4/0.0.0.0/tcp/24915"`
//!
//! Make sure that the first computer is reachable under one of these ip addresses and port.
//!
//! On the second computer run:
//! ```sh
//! cargo run --example ping-onion -- /ip4/123.45.67.89/tcp/24915
//! ```
//!
//! The two nodes establish a connection, negotiate the ping protocol
//! and begin pinging each other over Tor.

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 std::error::Error;
use std::sync::{Arc, Mutex};
use tor_interface::tor_crypto::Ed25519PrivateKey;

/// Create a transport
/// Returns a tuple of the transport and the onion address we can instruct it to listen on
async fn onion_transport(
keypair: identity::Keypair,
) -> Result<
(
libp2p::core::transport::Boxed<(PeerId, libp2p::core::muxing::StreamMuxerBox)>,
Multiaddr,
),
Box<dyn Error>,
> {
let provider = libp2p_community_tor::tor_interface::legacy_tor_client::LegacyTorClient::new(
libp2p_community_tor::tor_interface::legacy_tor_client::LegacyTorClientConfig::system_from_environment().expect("Configure $TOR_... to talk to"))?;

let mut transport = libp2p_community_tor::TorInterfaceTransport::from_provider(
libp2p_community_tor::AddressConversion::IpAndDns, Arc::new(Mutex::new(provider)), None)?;

let onion_listen_address = transport.add_onion_service(&Ed25519PrivateKey::generate(), 999, None, None).unwrap();

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

let transport = transport
.boxed()
.upgrade(Version::V1)
.authenticate(auth_upgrade)
.multiplex(multiplex_upgrade)
.map(|(peer, muxer), _| (peer, StreamMuxerBox::new(muxer)))
.boxed();

Ok((transport, onion_listen_address))
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
tracing_subscriber::fmt::init();

let local_key = identity::Keypair::generate_ed25519();
let local_peer_id = PeerId::from(local_key.public());

println!("Local peer id: {local_peer_id}");

let (transport, onion_listen_address) = onion_transport(local_key).await?;

let mut swarm = SwarmBuilder::with_new_identity()
.with_tokio()
.with_other_transport(|_| transport)
.unwrap()
.with_behaviour(|_| Behaviour {
ping: libp2p::ping::Behaviour::default(),
})
.unwrap()
.build();

// Dial the peer identified by the multi-address given as the second
// command-line argument, if any.
if let Some(addr) = std::env::args().nth(1) {
let remote: Multiaddr = addr.parse()?;
swarm.dial(remote)?;
println!("Dialed {addr}")
} else {
// If we are not dialing, we need to listen
// Tell the swarm to listen on a specific onion address
swarm.listen_on(onion_listen_address).unwrap();
}

loop {
match swarm.select_next_some().await {
SwarmEvent::ConnectionEstablished {
endpoint, peer_id, ..
} => {
println!("Connection established with {peer_id} on {endpoint:?}");
}
SwarmEvent::OutgoingConnectionError { peer_id, error, .. } => {
println!("Outgoing connection error with {peer_id:?}: {error:?}");
}
SwarmEvent::NewListenAddr { address, .. } => println!("Listening on {address:?}"),
SwarmEvent::Behaviour(event) => println!("{event:?}"),
_ => {}
}
}
}

/// Our network behaviour.
#[derive(NetworkBehaviour)]
struct Behaviour {
ping: libp2p::ping::Behaviour,
}
File renamed without changes.
Loading