-
Notifications
You must be signed in to change notification settings - Fork 1.2k
transports/onion: Add dial-only implementation of Transport
#2899
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
Closed
Closed
Changes from all commits
Commits
Show all changes
66 commits
Select commit
Hold shift + click to select a range
ecd352b
Initial commit on Onion transport for libp2p
umgefahren ca954bf
Added tests, comments and mate implementation somewhat usesable
umgefahren 59e4792
simplified, streamlined and added an example
umgefahren f69a566
simplified, streamlined and added an example
umgefahren 6cd8ce0
Added some traits
umgefahren ab0197e
Added cargo fmt changes
umgefahren 0c31c37
fixed typo
umgefahren 9380b18
implemented suggestions
umgefahren 3dabad1
implemented suggestions
umgefahren cd9ff90
Merge branch 'master' into add-onion
umgefahren 0c7298c
Addressed latest issues
umgefahren e342500
Merge branch 'add-onion' of github.com:umgefahren/rust-libp2p into ad…
umgefahren d88af2e
fixed test failure
umgefahren 0680655
Ran cargo fmt
umgefahren e04869a
Implemented suggested changes
umgefahren e7db75f
Small module doc
umgefahren c6335b5
compiles again on wasm32
umgefahren 8c20c30
Refactor multiaddress parsing to avoid clones
thomaseizinger b6b2aac
Apply suggestions from code review
umgefahren 9d2d94c
renamed stuff
umgefahren 4076338
corrected issues of previous commit an implemented all recently reque…
umgefahren bf9df0a
formatted
umgefahren 548a815
Apply suggestions from code review
umgefahren 307f19c
Added license headers and added to README.md
umgefahren 6f4bca5
Merge branch 'master' into add-onion
umgefahren 96d0bf9
Merge branch 'master' into add-onion
umgefahren 03ba6e7
addressed todos by @thomaseizinger
umgefahren e6a51c0
Remove `cargo-deny` exception
thomaseizinger 8de49ca
Remove unnecessary empty lines
thomaseizinger 1492557
Merge `use` statements into one block
thomaseizinger 402835d
Make use of link in changelog
thomaseizinger b292cd0
Consistently reference `Pin` with FQP to avoid import
thomaseizinger 85f6eb6
Update `arti` to latest version
thomaseizinger 38ba200
Sort dependencies alphabetically
thomaseizinger 077ab94
Use link reference in CHANGELOG.md
thomaseizinger d57fe41
Fix compile errors
thomaseizinger 389ff09
Merge branch 'master' into add-onion
thomaseizinger ac6b9a8
Merge branch 'master' into add-onion
umgefahren 0a89bef
Merge branch 'master' into add-onion
umgefahren bd7f8ac
Really enable all features in full
umgefahren 86a511c
Merge branch 'master' into add-onion
umgefahren 49f0c79
Merge branch 'master' into add-onion
umgefahren f834d9e
Adjusted example to match the ping example
umgefahren 1a5668b
Fix formatting
thomaseizinger 2fa5162
Merge branch 'master' into add-onion
umgefahren 1d1a219
Merge branch 'master' into add-onion
umgefahren 9bcd2be
Changed CHANGELOG.md entry
umgefahren 65bc267
Update CHANGELOG.md
umgefahren 40765c6
Updated Cargo.toml responding to the requested changes
umgefahren 1f692de
Corrected error in the feature flag
umgefahren 76ed916
Fixed issues with featues
umgefahren 9332ee3
Alphabetically sort feature list
thomaseizinger c09fa80
Alphabetically sort dependency list
thomaseizinger 285bdc0
Update transports/onion/Cargo.toml
umgefahren 5c908a6
Merge branch 'master' into add-onion
umgefahren d2c6256
Changed to alpha version.
umgefahren 9b4fce9
Merge branch 'master' into add-onion
umgefahren 62d093b
Merge branch 'master' into add-onion
mxinden 25ea701
Merge branch 'master' into add-onion
thomaseizinger 7865af7
Fixed issue with Cargo.toml
umgefahren 37f170b
Merge master into add-onion
umgefahren dd5b8b7
Added type alias for DataStream and removed custom doc(cfg( in order …
umgefahren d4c6ff4
Merge branch 'master' into add-onion
umgefahren 6771e93
Merge branch 'master' into add-onion
umgefahren d236989
Merge branch 'master' into add-onion
umgefahren 4f72d3c
Made compileable again
umgefahren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| // 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::prelude::*; | ||
| use libp2p::onion::AddressConversion; | ||
| use libp2p::swarm::{keep_alive, Swarm, SwarmEvent}; | ||
| use libp2p::{ | ||
| core::upgrade, identity, mplex, noise, onion, ping, yamux, Multiaddr, NetworkBehaviour, PeerId, | ||
| Transport, | ||
| }; | ||
| 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 = onion::AsyncStdNativeTlsOnionTransport::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()) | ||
| } | ||
|
|
||
| #[async_std::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); | ||
|
|
||
| let transport = onion_transport(local_key).await?; | ||
|
|
||
| let mut swarm = Swarm::new(transport, Behaviour::default(), local_peer_id); | ||
|
|
||
| // 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); | ||
|
|
||
| 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), | ||
| _ => {} | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// 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, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # 0.37.0 - [unreleased] | ||
|
|
||
| - Initial Implementation. See [PR 2899]. | ||
|
|
||
| [PR 2899]: https://github.com/libp2p/rust-libp2p/pull/2899 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| [package] | ||
| name = "libp2p-onion" | ||
| version = "0.1.0-alpha" | ||
| edition = "2021" | ||
| license = "MIT" | ||
| resolver = "2" | ||
|
|
||
| [dependencies] | ||
| arti-client = { version = "0.7", default-features = false } | ||
| async-std-crate = { package = "async-std", version = "1", optional = true, default-features = false } | ||
| futures = "0.3" | ||
| libp2p-core = { version = "0.38", path = "../../core" } | ||
| thiserror = "1" | ||
| tokio-crate = { package = "tokio", version = "1", optional = true, default-features = false } | ||
| tor-rtcompat = "0.7" | ||
|
|
||
| [dev-dependencies] | ||
| libp2p = { version = "0.50", path = "../../" } | ||
| 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"] | ||
|
|
||
| [package.metadata.docs.rs] | ||
| rustdoc-args = ["--cfg", "docsrs"] | ||
| rustc-args = ["--cfg", "docsrs"] | ||
thomaseizinger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.