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

refactor(relay): revise public API to follow naming convention #3238

Merged
merged 34 commits into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6453766
rename relay::Relay to relay::Behaviour.
jxs Dec 13, 2022
0f1c10e
rename client::Client to client::Behaviour.
jxs Dec 13, 2022
796425a
rename client::transport::ClientTransport to client::transport::Trans…
jxs Dec 13, 2022
f0c8429
rename relay::v2::client::RelayError to relay::v2::client::Error.
jxs Dec 13, 2022
9963cfa
rename relay::v2::client::RelayListener to relay::v2::client::Listener.
jxs Dec 13, 2022
604178b
add CHANGELOG.md entries
jxs Dec 13, 2022
395d516
add missing links to CHANGELOG.md
jxs Dec 13, 2022
50207ba
move relay::v2 root symbols to relay::
jxs Dec 14, 2022
948f87b
move relay::v2::client symbols to relay::client and use them across t…
jxs Dec 14, 2022
dcbca3a
move relay::v2::copy_future module to relay::copy_future and use it a…
jxs Dec 14, 2022
db1ff9f
move relay::v2::relay symbols to relay::behaviour,
jxs Dec 14, 2022
2171c36
chore(ROADMAP): Mark Kademlia efficient querying as done (#3233)
mxinden Dec 13, 2022
e6e4005
feat: move Identify I/O from NetworkBehaviour to ConnectionHandler (#…
jxs Dec 13, 2022
f15d82a
ci(caching): make caching more effective (#3215)
thomaseizinger Dec 13, 2022
63f03be
refactor(swarm)!: deprecate `PollParameters` where possible (#3153)
thomaseizinger Dec 14, 2022
8744f97
Merge branch 'master' of github.com:libp2p/rust-libp2p into rename-relay
jxs Dec 14, 2022
009aadc
fix typo on client deprecation message.
jxs Dec 14, 2022
b4bb917
Update CHANGELOG.md.
jxs Dec 14, 2022
e32d990
Merge branch 'master' of github.com:libp2p/rust-libp2p into rename-relay
jxs Dec 14, 2022
59d3225
Merge branch 'master' of github.com:libp2p/rust-libp2p into rename-relay
jxs Dec 14, 2022
4134363
multiple updates:
jxs Dec 14, 2022
9eb0e21
deprecate client::Behaviour::new_transport_and_behaviour,
jxs Dec 15, 2022
238c779
move UpgradeErrors to inbound or outbound modules.
jxs Dec 15, 2022
43ea4a8
make client::Transport types private.
jxs Dec 15, 2022
12c1128
Merge branch 'master' of github.com:libp2p/rust-libp2p into rename-relay
jxs Dec 15, 2022
64e6dd9
review: apply multiple suggestions:
jxs Dec 16, 2022
bc66c5b
review: address left deprecation messages,
jxs Dec 17, 2022
6f63553
Merge branch 'master' of github.com:libp2p/rust-libp2p into rename-relay
jxs Dec 17, 2022
91241e7
Merge branch 'master' of github.com:libp2p/rust-libp2p into rename-relay
jxs Dec 20, 2022
e3a8f0a
adress Thomas multiple review suggestions.
jxs Dec 21, 2022
7f653b3
Merge branch 'master' of github.com:libp2p/rust-libp2p into rename-relay
jxs Dec 21, 2022
0951271
review: apply suggestions.
jxs Dec 23, 2022
f3bf4bd
Merge branch 'master' into rename-relay
jxs Dec 24, 2022
c532b34
Merge branch 'master' into rename-relay
mxinden Jan 2, 2023
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
4 changes: 2 additions & 2 deletions misc/metrics/src/identify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ impl super::Recorder<libp2p_identify::Event> for Metrics {
#[cfg(feature = "ping")]
libp2p_ping::PROTOCOL_NAME,
#[cfg(feature = "relay")]
libp2p_relay::v2::STOP_PROTOCOL_NAME,
libp2p_relay::STOP_PROTOCOL_NAME,
#[cfg(feature = "relay")]
libp2p_relay::v2::HOP_PROTOCOL_NAME,
libp2p_relay::HOP_PROTOCOL_NAME,
];

allowed_protocols.contains(&p.as_bytes())
Expand Down
4 changes: 2 additions & 2 deletions misc/metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ impl Recorder<libp2p_ping::Event> for Metrics {
}

#[cfg(feature = "relay")]
impl Recorder<libp2p_relay::v2::relay::Event> for Metrics {
fn record(&self, event: &libp2p_relay::v2::relay::Event) {
impl Recorder<libp2p_relay::Event> for Metrics {
fn record(&self, event: &libp2p_relay::Event) {
self.relay.record(event)
}
}
Expand Down
44 changes: 16 additions & 28 deletions misc/metrics/src/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,47 +63,35 @@ enum EventType {
CircuitClosed,
}

impl From<&libp2p_relay::v2::relay::Event> for EventType {
fn from(event: &libp2p_relay::v2::relay::Event) -> Self {
impl From<&libp2p_relay::Event> for EventType {
fn from(event: &libp2p_relay::Event) -> Self {
match event {
libp2p_relay::v2::relay::Event::ReservationReqAccepted { .. } => {
EventType::ReservationReqAccepted
}
libp2p_relay::v2::relay::Event::ReservationReqAcceptFailed { .. } => {
libp2p_relay::Event::ReservationReqAccepted { .. } => EventType::ReservationReqAccepted,
libp2p_relay::Event::ReservationReqAcceptFailed { .. } => {
EventType::ReservationReqAcceptFailed
}
libp2p_relay::v2::relay::Event::ReservationReqDenied { .. } => {
EventType::ReservationReqDenied
}
libp2p_relay::v2::relay::Event::ReservationReqDenyFailed { .. } => {
libp2p_relay::Event::ReservationReqDenied { .. } => EventType::ReservationReqDenied,
libp2p_relay::Event::ReservationReqDenyFailed { .. } => {
EventType::ReservationReqDenyFailed
}
libp2p_relay::v2::relay::Event::ReservationTimedOut { .. } => {
EventType::ReservationTimedOut
}
libp2p_relay::v2::relay::Event::CircuitReqReceiveFailed { .. } => {
libp2p_relay::Event::ReservationTimedOut { .. } => EventType::ReservationTimedOut,
libp2p_relay::Event::CircuitReqReceiveFailed { .. } => {
EventType::CircuitReqReceiveFailed
}
libp2p_relay::v2::relay::Event::CircuitReqDenied { .. } => EventType::CircuitReqDenied,
libp2p_relay::v2::relay::Event::CircuitReqOutboundConnectFailed { .. } => {
libp2p_relay::Event::CircuitReqDenied { .. } => EventType::CircuitReqDenied,
libp2p_relay::Event::CircuitReqOutboundConnectFailed { .. } => {
EventType::CircuitReqOutboundConnectFailed
}
libp2p_relay::v2::relay::Event::CircuitReqDenyFailed { .. } => {
EventType::CircuitReqDenyFailed
}
libp2p_relay::v2::relay::Event::CircuitReqAccepted { .. } => {
EventType::CircuitReqAccepted
}
libp2p_relay::v2::relay::Event::CircuitReqAcceptFailed { .. } => {
EventType::CircuitReqAcceptFailed
}
libp2p_relay::v2::relay::Event::CircuitClosed { .. } => EventType::CircuitClosed,
libp2p_relay::Event::CircuitReqDenyFailed { .. } => EventType::CircuitReqDenyFailed,
libp2p_relay::Event::CircuitReqAccepted { .. } => EventType::CircuitReqAccepted,
libp2p_relay::Event::CircuitReqAcceptFailed { .. } => EventType::CircuitReqAcceptFailed,
libp2p_relay::Event::CircuitClosed { .. } => EventType::CircuitClosed,
}
}
}

impl super::Recorder<libp2p_relay::v2::relay::Event> for Metrics {
fn record(&self, event: &libp2p_relay::v2::relay::Event) {
impl super::Recorder<libp2p_relay::Event> for Metrics {
fn record(&self, event: &libp2p_relay::Event) {
self.events
.get_or_create(&EventLabels {
event: event.into(),
Expand Down
18 changes: 9 additions & 9 deletions protocols/dcutr/examples/dcutr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use libp2p_dns::DnsConfig;
use libp2p_identify as identify;
use libp2p_noise as noise;
use libp2p_ping as ping;
use libp2p_relay::v2::client::{self, Client};
use libp2p_relay as relay;
use libp2p_swarm::{NetworkBehaviour, SwarmBuilder, SwarmEvent};
use libp2p_tcp as tcp;
use log::info;
Expand Down Expand Up @@ -87,7 +87,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let local_peer_id = PeerId::from(local_key.public());
info!("Local peer id: {:?}", local_peer_id);

let (relay_transport, client) = Client::new_transport_and_behaviour(local_peer_id);
let (relay_transport, client) = relay::client::new(local_peer_id);

let transport = OrTransport::new(
relay_transport,
Expand All @@ -111,7 +111,7 @@ fn main() -> Result<(), Box<dyn Error>> {
prelude = "libp2p_swarm::derive_prelude"
)]
struct Behaviour {
relay_client: Client,
relay_client: relay::client::Behaviour,
ping: ping::Behaviour,
identify: identify::Behaviour,
dcutr: dcutr::Behaviour,
Expand All @@ -122,7 +122,7 @@ fn main() -> Result<(), Box<dyn Error>> {
enum Event {
Ping(ping::Event),
Identify(identify::Event),
Relay(client::Event),
Relay(relay::client::Event),
Dcutr(dcutr::Event),
}

Expand All @@ -138,8 +138,8 @@ fn main() -> Result<(), Box<dyn Error>> {
}
}

impl From<client::Event> for Event {
fn from(e: client::Event) -> Self {
impl From<relay::client::Event> for Event {
fn from(e: relay::client::Event) -> Self {
Event::Relay(e)
}
}
Expand Down Expand Up @@ -252,9 +252,9 @@ fn main() -> Result<(), Box<dyn Error>> {
SwarmEvent::NewListenAddr { address, .. } => {
info!("Listening on {:?}", address);
}
SwarmEvent::Behaviour(Event::Relay(client::Event::ReservationReqAccepted {
..
})) => {
SwarmEvent::Behaviour(Event::Relay(
relay::client::Event::ReservationReqAccepted { .. },
)) => {
assert!(opts.mode == Mode::Listen);
info!("Relay accepted our reservation request.");
}
Expand Down
31 changes: 16 additions & 15 deletions protocols/dcutr/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ use libp2p_core::PublicKey;
use libp2p_core::{identity, PeerId};
use libp2p_dcutr as dcutr;
use libp2p_plaintext::PlainText2Config;
use libp2p_relay::v2::client;
use libp2p_relay::v2::relay;
use libp2p_relay as relay;
use libp2p_swarm::{AddressScore, NetworkBehaviour, Swarm, SwarmEvent};
use std::time::Duration;

Expand Down Expand Up @@ -91,7 +90,7 @@ fn connect() {
));
}

fn build_relay() -> Swarm<relay::Relay> {
fn build_relay() -> Swarm<relay::Behaviour> {
let local_key = identity::Keypair::generate_ed25519();
let local_public_key = local_key.public();
let local_peer_id = local_public_key.to_peer_id();
Expand All @@ -100,7 +99,7 @@ fn build_relay() -> Swarm<relay::Relay> {

Swarm::with_threadpool_executor(
transport,
relay::Relay::new(
relay::Behaviour::new(
local_peer_id,
relay::Config {
reservation_duration: Duration::from_secs(2),
Expand All @@ -116,7 +115,7 @@ fn build_client() -> Swarm<Client> {
let local_public_key = local_key.public();
let local_peer_id = local_public_key.to_peer_id();

let (relay_transport, behaviour) = client::Client::new_transport_and_behaviour(local_peer_id);
let (relay_transport, behaviour) = relay::client::new(local_peer_id);
let transport = build_transport(
OrTransport::new(relay_transport, MemoryTransport::default()).boxed(),
local_public_key,
Expand Down Expand Up @@ -153,18 +152,18 @@ where
prelude = "libp2p_swarm::derive_prelude"
)]
struct Client {
relay: client::Client,
relay: relay::client::Behaviour,
dcutr: dcutr::Behaviour,
}

#[derive(Debug)]
enum ClientEvent {
Relay(client::Event),
Relay(relay::client::Event),
Dcutr(dcutr::Event),
}

impl From<client::Event> for ClientEvent {
fn from(event: client::Event) -> Self {
impl From<relay::client::Event> for ClientEvent {
fn from(event: relay::client::Event) -> Self {
ClientEvent::Relay(event)
}
}
Expand Down Expand Up @@ -198,11 +197,13 @@ async fn wait_for_reservation(
break;
}
}
SwarmEvent::Behaviour(ClientEvent::Relay(client::Event::ReservationReqAccepted {
relay_peer_id: peer_id,
renewal,
..
})) if relay_peer_id == peer_id && renewal == is_renewal => {
SwarmEvent::Behaviour(ClientEvent::Relay(
relay::client::Event::ReservationReqAccepted {
relay_peer_id: peer_id,
renewal,
..
},
)) if relay_peer_id == peer_id && renewal == is_renewal => {
reservation_req_accepted = true;
if new_listen_addr_for_relayed_addr {
break;
Expand All @@ -226,7 +227,7 @@ async fn wait_for_connection_established(client: &mut Swarm<Client>, addr: &Mult
}
SwarmEvent::Dialing(_) => {}
SwarmEvent::Behaviour(ClientEvent::Relay(
client::Event::OutboundCircuitEstablished { .. },
relay::client::Event::OutboundCircuitEstablished { .. },
)) => {}
SwarmEvent::ConnectionEstablished { .. } => {}
e => panic!("{e:?}"),
Expand Down
10 changes: 10 additions & 0 deletions protocols/relay/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# 0.15.0 [unreleased]

- Rename types as per [discussion 2174].
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved
`Relay` has been renamed to `Behaviour`.
The `Relay`, and `Client` prefixes have been removed from various types like `ClientTransport`.
the `v2` namespace has also been removed, users should prefer importing the relay protocol as a module (`use libp2p::relay;`),
and refer to its types via `relay::`. For example: `relay::Behaviour` or `relay::client::Behaviour`.
See [PR 3238].

- Update to `libp2p-core` `v0.39.0`.

- Update to `libp2p-swarm` `v0.42.0`.

[PR 3238]: https://github.com/libp2p/rust-libp2p/pull/3238
[discussion 2174]: https://github.com/libp2p/rust-libp2p/issues/2174

# 0.14.0

- Update to `prost-codec` `v0.3.0`.
Expand Down
2 changes: 1 addition & 1 deletion protocols/relay/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
// DEALINGS IN THE SOFTWARE.

fn main() {
prost_build::compile_protos(&["src/v2/message.proto"], &["src/v2"]).unwrap();
prost_build::compile_protos(&["src/message.proto"], &["src/"]).unwrap();
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use libp2p_core::{identity, Multiaddr, PeerId, Transport};
use libp2p_identify as identify;
use libp2p_noise as noise;
use libp2p_ping as ping;
use libp2p_relay::v2::relay::{self, Relay};
use libp2p_relay as relay;
use libp2p_swarm::{NetworkBehaviour, Swarm, SwarmEvent};
use libp2p_tcp as tcp;
use std::error::Error;
Expand Down Expand Up @@ -57,7 +57,7 @@ fn main() -> Result<(), Box<dyn Error>> {
.boxed();

let behaviour = Behaviour {
relay: Relay::new(local_peer_id, Default::default()),
relay: relay::Behaviour::new(local_peer_id, Default::default()),
ping: ping::Behaviour::new(ping::Config::new()),
identify: identify::Behaviour::new(identify::Config::new(
"/TODO/0.0.1".to_string(),
Expand All @@ -79,7 +79,7 @@ fn main() -> Result<(), Box<dyn Error>> {
block_on(async {
loop {
match swarm.next().await.expect("Infinite Stream.") {
SwarmEvent::Behaviour(Event::Relay(event)) => {
SwarmEvent::Behaviour(event) => {
println!("{event:?}")
}
SwarmEvent::NewListenAddr { address, .. } => {
Expand All @@ -92,42 +92,13 @@ fn main() -> Result<(), Box<dyn Error>> {
}

#[derive(NetworkBehaviour)]
#[behaviour(
out_event = "Event",
event_process = false,
prelude = "libp2p_swarm::derive_prelude"
)]
#[behaviour(prelude = "libp2p_swarm::derive_prelude")]
struct Behaviour {
relay: Relay,
relay: relay::Behaviour,
ping: ping::Behaviour,
identify: identify::Behaviour,
}

#[derive(Debug)]
enum Event {
Ping(ping::Event),
Identify(identify::Event),
Relay(relay::Event),
}

impl From<ping::Event> for Event {
fn from(e: ping::Event) -> Self {
Event::Ping(e)
}
}

impl From<identify::Event> for Event {
fn from(e: identify::Event) -> Self {
Event::Identify(e)
}
}

impl From<relay::Event> for Event {
fn from(e: relay::Event) -> Self {
Event::Relay(e)
}
}

fn generate_ed25519(secret_key_seed: u8) -> identity::Keypair {
let mut bytes = [0u8; 32];
bytes[0] = secret_key_seed;
Expand Down
Loading