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

protocols/relay: Implement circuit relay specification #1838

Merged
merged 133 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
133 commits
Select commit Hold shift + click to select a range
69bc317
Add back the relay
tomaka Mar 24, 2019
11b0c9a
Merge remote-tracking branch 'upstream/master' into relay
tomaka Jun 8, 2019
ccbc906
Merge branch 'libp2p/master' into relay
mxinden Oct 19, 2020
a4d4049
*: Add unit test instantiating a relay
mxinden Oct 25, 2020
c404b45
protocols/transport: Add channel between transport and behaviour
mxinden Oct 25, 2020
6a17ff5
protocols/relay: Add custom Transport structs
mxinden Oct 25, 2020
2721f79
protocols/relay: Send relayed dial to behaviour
mxinden Oct 25, 2020
96f2294
protocols/relay/tests: Connect to relay via listen_on
mxinden Oct 25, 2020
7dc0142
protocols/relay: Add TODO on how to specify relays
mxinden Oct 28, 2020
5dc6ab8
protocols/relay: Send listen requests to behaviour
mxinden Oct 31, 2020
43a2eec
protocols/relay: Track progress of listen requests in behaviour
mxinden Oct 31, 2020
6cbd22f
protocols/relay: Poll inner upgrade listener
mxinden Oct 31, 2020
98a5ff1
protocols/relay: Track relay listeners
mxinden Oct 31, 2020
ed98b91
protocols/relay/tests: Introduce node a dialing node b via relay
mxinden Oct 31, 2020
77469d5
protocols/relay: Split relay and destination address
mxinden Oct 31, 2020
e9b7edd
protocols/relay: Dial relay on dial request
mxinden Oct 31, 2020
ff37628
protocols/relay: Send hop request to relay
mxinden Nov 1, 2020
0f0e052
protocols/relay: Parse relay request
mxinden Nov 1, 2020
240d258
protocols/relay: Ask the remote to act as a destination
mxinden Nov 1, 2020
db56783
protocols/relay: Accept incoming requests
mxinden Nov 1, 2020
559527e
protocols/relay: Pass incoming substream to transport
mxinden Nov 1, 2020
a513866
protocols/relay: Pass source address to transport.rs
mxinden Nov 7, 2020
babd49b
protocols/relay: Copy bytes from source to destination and vice versa
mxinden Nov 7, 2020
2a99f5f
protocols/relay: Pass negotiated connection back to dialer
mxinden Nov 7, 2020
55956eb
protocols/relay: Stricten test execution
mxinden Nov 7, 2020
1dd5cd6
protocols/relay: Fix warnings
mxinden Nov 7, 2020
43ce960
protocols/relay: Refactor test
mxinden Nov 7, 2020
88a3dae
protocols/relay: Add Ping to behaviour
mxinden Nov 7, 2020
18bcc70
Merge branch 'libp2p/master' into relay
mxinden Nov 14, 2020
d300c36
protocols/relay/src/lib: Add terminology section
mxinden Nov 14, 2020
7930623
protocols/relay: Apply unified terminology
mxinden Nov 14, 2020
56d5f58
protocols/relay/transport: Add doc test
mxinden Nov 14, 2020
b6138a0
protocols/relay: Handle error on multiaddr splitting
mxinden Nov 14, 2020
5859df3
protocols/relay/transport: Handle error sending to behaviour
mxinden Nov 14, 2020
93d86b6
protocols/relay/transport: Handle dial communication failure
mxinden Nov 14, 2020
5145965
protocols/relay: Ensure not to remove wrong request
mxinden Nov 15, 2020
a940134
protocols/relay: Initiate connection to destination if needed
mxinden Nov 15, 2020
14c57bb
protocols/relay: Fail when outgoing relay request fails
mxinden Nov 15, 2020
59b8c79
Merge branch 'libp2p/master' into relay
mxinden Nov 15, 2020
4196b24
Merge branch 'libp2p/master' into relay
mxinden Nov 23, 2020
9773670
protocols/relay/transport: Improve dial error handling
mxinden Nov 23, 2020
b3907e4
protocols/relay: Simplify request tracking datastructures
mxinden Nov 23, 2020
3f8d281
protocols/relay: Do not panic when already connected to relay
mxinden Nov 28, 2020
11d29fb
protocols/relay: Panic on subset of copy future errors
mxinden Nov 28, 2020
05644e0
Merge branch 'libp2p/master' into relay
mxinden Nov 28, 2020
23b6d00
protocols/relay: Remove Mutex hack for incominng dest req
mxinden Nov 28, 2020
b503ccb
protocols/relay: Set max message length
mxinden Nov 28, 2020
cd3ae65
protocols/relay: Move protocol name to const
mxinden Nov 28, 2020
cdb169c
protocols/relay: Handle errors sending relay request
mxinden Nov 28, 2020
cabf36b
Merge branch 'libp2p/master' into relay
mxinden Dec 5, 2020
3f943fc
protocols/relay: Improve error handling
mxinden Dec 5, 2020
cbdbb81
protocols/relay/examples: Add sample relay server
mxinden Dec 5, 2020
41dbe29
protocols/relay: Export Relay via behaviour module
mxinden Dec 5, 2020
18dadf3
Merge branch 'libp2p/master' into relay
mxinden Dec 13, 2020
827a868
Reexport Relay and RelayTransportWrapper.
dvc94ch Dec 10, 2020
35d497a
protocols/relay/tests: Introduce Firewall dropping incoming connections
mxinden Jan 6, 2021
95e9576
protocols/relay/tests: Add Kademlia to CombinedBehaviour
mxinden Jan 6, 2021
9722cf2
Merge branch 'libp2p/master' into relay
mxinden Jan 10, 2021
1640b3a
protocols/relay: Return new listening address
mxinden Jan 10, 2021
88f9a73
protocols/relay/tests: Discover relayed firewalled peer via kad
mxinden Jan 10, 2021
7c7c628
protocols/relay: Fix warnings
mxinden Jan 10, 2021
3521ff5
protocols/relay: Don't require Clone on RelayHandlerIn event
mxinden Jan 10, 2021
28e0963
Merge branch 'libp2p/master' into relay
mxinden Jan 17, 2021
0521525
protocols/relay: Implement address_translation
mxinden Jan 17, 2021
55c2e0e
protocols/relay: Add custom copy future implementation
mxinden Jan 17, 2021
8a01bd8
protocols/relay: Implement basic keep-alive handling
mxinden Jan 21, 2021
62810f2
protocols/relay/behaviour: Split dialing and upgrading requests
mxinden Jan 31, 2021
89981dc
protocols/relay: Use request ids to allow concurrent connections
mxinden Jan 31, 2021
394408e
protocols/relay: Set max msg length when listening
mxinden Jan 31, 2021
7076655
protocols/relay: Pass only single destination address
mxinden Jan 31, 2021
221977b
protocols/relay: Remove unnecessary trait bounds
mxinden Jan 31, 2021
3cfea50
protocols/relay: Use IntoProtocolsHandler to record remote address
mxinden Feb 3, 2021
1de3b16
protocols/relay: Report relay dial error to transport
mxinden Feb 13, 2021
3bc1a3e
protocols/relay: Inform source when connection to destination fails
mxinden Feb 13, 2021
0817e78
src/protocol/copy_future: Close writer when reader is finished
mxinden Feb 13, 2021
b80cb18
src/protocol/copy_future: Continue until both src and dst are done
mxinden Feb 13, 2021
128db56
Merge branch 'libp2p/master' into relay
mxinden Feb 13, 2021
5a0dcfe
protocols/relay: Update to unsigned-varint and dependencies
mxinden Feb 13, 2021
600b5e6
protocols/relay: Handle FramedParts read and write buffers
mxinden Feb 13, 2021
2cf4d5d
protocols/relay: Don't forget previous connections
mxinden Feb 14, 2021
c495268
protocols/relay: Keep connection to relay alive if listening
mxinden Feb 14, 2021
ffc4d1d
protocols/relay: Keep active relay connections alive
mxinden Feb 14, 2021
6a496fc
protocols/relay: Rename request to req
mxinden Feb 14, 2021
916d077
protocols/relay: Rename destination to dst
mxinden Feb 14, 2021
107a2b1
protocols/relay: Rename source to src
mxinden Feb 14, 2021
cf17855
protocols/relay/tests: Remove unnecessary loops
mxinden Feb 15, 2021
69669cd
protocols/relay: Make connection idle timeout configurable
mxinden Feb 15, 2021
7b60940
protocols/relay: Notify src when disconnecting from destination
mxinden Feb 15, 2021
606fc97
protocols/relay: Deny incoming relay request when destination fails
mxinden Feb 17, 2021
cc5b446
protocols/relay: Address minor TODOs
mxinden Feb 18, 2021
566f941
protocols/relay: Replace TSubstream in favor of NegotiatedSubstream
mxinden Feb 18, 2021
d6ab740
protocols/relay: Tell src when dst does not support relay proto
mxinden Feb 18, 2021
ce7ecc0
protocols/relay: Handle dial upgrade errors gracefully
mxinden Feb 18, 2021
3894252
protocols/relay: Report relay as local_addr as destination
mxinden Feb 18, 2021
2f434be
protocols/relay: Use correct protocol id
mxinden Feb 18, 2021
88e53c6
protocols/relay: Send dst address to dst
mxinden Feb 18, 2021
6403c71
protocols/relay: Do not loose read buffer when unwrapping Framed
mxinden Feb 18, 2021
7e7de12
protocols/relay: Use plaintext in example
mxinden Feb 18, 2021
12c2f4b
protocols/relay: Pass src PeerId in outgoing relay request
mxinden Feb 19, 2021
0c2a33a
protocols/relay: Improve documentation
mxinden Feb 19, 2021
406d6bb
protocols/relay: Use wasm-timer
mxinden Feb 19, 2021
82ba74a
Merge branch 'libp2p/master' into relay
mxinden Feb 19, 2021
cc9ac66
protocols/relay/example: Set connection idle timeout
mxinden Feb 19, 2021
d2f17b3
protocols/relay: Add crate level example
mxinden Feb 19, 2021
364fa98
protocols/relay: Apply smaller comments from code review
mxinden Mar 2, 2021
ecf215d
protocols/relay: Send back AcceptDstReq to same handler
mxinden Mar 2, 2021
7ae9290
protocols/relay: Deny incoming relay request with correct handler
mxinden Mar 3, 2021
194d252
protocols/relay: Make handler error handling more specific
mxinden Mar 3, 2021
ff0e437
protocols/relay: Add test yielding connection on right listener
mxinden Mar 5, 2021
6072cce
Merge branch 'libp2p/master' into relay
mxinden Mar 5, 2021
bedbd63
protocols/relay: Yield connection on right listener
mxinden Mar 5, 2021
437c112
protocols/relay: Clean up listener test
mxinden Mar 6, 2021
f1bb866
protocols/relay/tests: Use src/dst node terminology
mxinden Mar 6, 2021
c50ea88
protocols/relay/transport: Improve docs on listen addresses
mxinden Mar 6, 2021
2220c5f
protocols/relay/behaviour: Do minor renamings
mxinden Mar 6, 2021
fb1589d
protocols/relay: Rework dst req acceptance / denial
mxinden Mar 6, 2021
a5254af
protocols/relay: Rework listener selection
mxinden Mar 6, 2021
560eb31
protocols/relay/handler: Implement inject_listen_upgrade_error
mxinden Mar 6, 2021
9e74558
protocols/relay: Consolidate incoming_relay_req naming
mxinden Mar 6, 2021
d700b53
protocols/relay/protocol: Increase max message length
mxinden Mar 6, 2021
2ef5e51
protocols/relay/protocol: Use Bytes returned by split_to
mxinden Mar 6, 2021
4f16531
protocols/relay: Rename RelayTransportWrapper to RelayTransport
mxinden Mar 6, 2021
6bd1c98
protocols/relay: Terminate listener when channel to behaviour closed
mxinden Mar 6, 2021
b8f7a00
protocols/relay/behaviour: Ignore error when returning dialed conection
mxinden Mar 6, 2021
5899ecd
protocols/relay: Fix broken intra doc links
mxinden Mar 6, 2021
a6f1fe7
protocols/relay: Do not panic when accepting dst req fails
mxinden Mar 6, 2021
bc4959d
protocols/relay: Track peer id as peer_id
mxinden Mar 6, 2021
4c37a94
protocols/relay: Implement Display for RelayError
mxinden Mar 6, 2021
c5aa466
protocols/relay: Print trace log when dropping event to unknown listener
mxinden Mar 10, 2021
7956f0b
protocols/relay: Disable active relay behaviour by default
mxinden Mar 10, 2021
d55bd99
protocols/relay: Do not close connection on upgrade timeouts
mxinden Mar 10, 2021
0c7f825
Merge branch 'master' into relay
mxinden Mar 11, 2021
ded2d51
*: Update changelogs
mxinden Mar 11, 2021
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- [`libp2p-kad` CHANGELOG](protocols/kad/CHANGELOG.md)
- [`libp2p-mdns` CHANGELOG](protocols/mdns/CHANGELOG.md)
- [`libp2p-ping` CHANGELOG](protocols/ping/CHANGELOG.md)
- [`libp2p-relay` CHANGELOG](protocols/relay/CHANGELOG.md)
- [`libp2p-request-response` CHANGELOG](protocols/request-response/CHANGELOG.md)

## Transport Protocols & Upgrades
Expand Down Expand Up @@ -48,6 +49,8 @@
- Do not leak default features from libp2p crates.
[PR 1986](https://github.com/libp2p/rust-libp2p/pull/1986).

- Add `libp2p-relay` to `libp2p` facade crate.

## Version 0.35.1 [2021-02-17]

- Update `libp2p-yamux` to latest patch version.
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ default = [
"ping",
"plaintext",
"pnet",
"relay",
"request-response",
"secp256k1",
"tcp-async-io",
Expand All @@ -43,6 +44,7 @@ noise = ["libp2p-noise"]
ping = ["libp2p-ping"]
plaintext = ["libp2p-plaintext"]
pnet = ["libp2p-pnet"]
relay = ["libp2p-relay"]
request-response = ["libp2p-request-response"]
tcp-async-io = ["libp2p-tcp", "libp2p-tcp/async-io"]
tcp-tokio = ["libp2p-tcp", "libp2p-tcp/tokio"]
Expand Down Expand Up @@ -71,6 +73,7 @@ libp2p-noise = { version = "0.29.0", path = "transports/noise", optional = true
libp2p-ping = { version = "0.28.0", path = "protocols/ping", optional = true }
libp2p-plaintext = { version = "0.27.1", path = "transports/plaintext", optional = true }
libp2p-pnet = { version = "0.20.0", path = "transports/pnet", optional = true }
libp2p-relay = { version = "0.1.0", path = "protocols/relay", optional = true }
libp2p-request-response = { version = "0.10.0", path = "protocols/request-response", optional = true }
libp2p-swarm = { version = "0.28.0", path = "swarm" }
libp2p-swarm-derive = { version = "0.22.0", path = "swarm-derive" }
Expand Down Expand Up @@ -109,6 +112,7 @@ members = [
"protocols/kad",
"protocols/mdns",
"protocols/ping",
"protocols/relay",
"protocols/request-response",
"swarm",
"swarm-derive",
Expand Down
4 changes: 4 additions & 0 deletions protocols/relay/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# 0.1.0 [unreleased]

- First release supporting all major features of the circuit relay v1
specification. [PR 1838](https://github.com/libp2p/rust-libp2p/pull/1838).
38 changes: 38 additions & 0 deletions protocols/relay/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[package]
name = "libp2p-relay"
edition = "2018"
description = "Communications relaying for libp2p"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
keywords = ["peer-to-peer", "libp2p", "networking"]
categories = ["network-programming", "asynchronous"]

[dependencies]
asynchronous-codec = "0.6"
bytes = "1"
futures = "0.3.1"
futures-timer = "3"
libp2p-core = { version = "0.27", path = "../../core" }
libp2p-swarm = { version = "0.28", path = "../../swarm" }
log = "0.4"
pin-project = "1"
prost = "0.7"
rand = "0.7"
smallvec = "0.6.9"
unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] }
void = "1"
wasm-timer = "0.2"

[build-dependencies]
prost-build = "0.7"

[dev-dependencies]
env_logger = "0.7.1"
libp2p = { path = "../.." }
libp2p-kad = { path = "../kad" }
libp2p-ping = { path = "../ping" }
libp2p-identify = { path = "../identify" }
libp2p-plaintext = { path = "../../transports/plaintext" }
libp2p-yamux = { path = "../../muxers/yamux" }
23 changes: 23 additions & 0 deletions protocols/relay/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2020 Parity Technologies (UK) Ltd.
//
// 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.

fn main() {
prost_build::compile_protos(&["src/message.proto"], &["src"]).unwrap();
}
84 changes: 84 additions & 0 deletions protocols/relay/examples/relay.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright 2020 Parity Technologies (UK) Ltd.
//
// 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.

use futures::executor::block_on;
use futures::stream::StreamExt;
use libp2p::core::upgrade;
use libp2p::plaintext;
use libp2p::relay::RelayConfig;
use libp2p::tcp::TcpConfig;
use libp2p::Transport;
use libp2p::{identity, PeerId, Swarm};
use std::error::Error;
use std::task::{Context, Poll};
use std::time::Duration;

fn main() -> Result<(), Box<dyn Error>> {
env_logger::init();

// Create a random PeerId
let local_key = identity::Keypair::generate_ed25519();
let local_peer_id = PeerId::from(local_key.public());
println!("Local peer id: {:?}", local_peer_id);

let tcp_transport = TcpConfig::new();

let relay_config = RelayConfig {
connection_idle_timeout: Duration::from_secs(10 * 60),
..Default::default()
};
let (relay_wrapped_transport, relay_behaviour) =
libp2p_relay::new_transport_and_behaviour(relay_config, tcp_transport);

let plaintext = plaintext::PlainText2Config {
local_public_key: local_key.public(),
};

let transport = relay_wrapped_transport
.upgrade(upgrade::Version::V1)
.authenticate(plaintext)
.multiplex(libp2p_yamux::YamuxConfig::default())
.boxed();

let mut swarm = Swarm::new(transport, relay_behaviour, local_peer_id);

// Listen on all interfaces and whatever port the OS assigns
Swarm::listen_on(&mut swarm, "/ip6/::/tcp/0".parse()?)?;

let mut listening = false;
block_on(futures::future::poll_fn(move |cx: &mut Context<'_>| {
loop {
match swarm.poll_next_unpin(cx) {
Poll::Ready(Some(event)) => println!("{:?}", event),
Poll::Ready(None) => return Poll::Ready(Ok(())),
Poll::Pending => {
if !listening {
for addr in Swarm::listeners(&swarm) {
println!("Listening on {:?}", addr);
listening = true;
}
}
break;
}
}
}
Poll::Pending
}))
}
Loading