Skip to content

Commit 5d8fc2d

Browse files
committed
chore: minor reversals and changes
1 parent 328889e commit 5d8fc2d

10 files changed

Lines changed: 29 additions & 140 deletions

File tree

Cargo.toml

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ getrandom_03 = { version = "0.3.3", package = "getrandom" }
8383
hickory-resolver = "0.25.2"
8484
idb = "0.6.5"
8585
indexmap = "2.10.0"
86-
libp2p = { version = "0.57.0" }
87-
libp2p-allow-block-list = "0.7.0"
88-
libp2p-connection-limits = "0.7.0"
89-
libp2p-stream = { version = "0.5.0-alpha" }
90-
libp2p-webrtc = { version = "=0.10.0-alpha", features = ["pem"] }
91-
libp2p-webrtc-websys = "0.5.0"
86+
libp2p = { version = "0.56.0" }
87+
libp2p-allow-block-list = "0.6.0"
88+
libp2p-connection-limits = "0.6.0"
89+
libp2p-stream = { version = "=0.4.0-alpha" }
90+
libp2p-webrtc = { version = "=0.9.0-alpha.1", features = ["pem"] }
91+
libp2p-webrtc-websys = "0.4.0"
9292
other-error = "0.1.1"
9393
pollable-map = "0.1.7"
9494
parking_lot = "0.12"
@@ -180,12 +180,4 @@ tokio = { default-features = false, features = ["sync", "macros"], workspace = t
180180
url = { workspace = true, optional = true }
181181
wasm-bindgen.workspace = true
182182
wasm-bindgen-futures.workspace = true
183-
web-sys = { workspace = true, optional = true }
184-
185-
[patch.crates-io]
186-
libp2p = { git = "https://github.com/libp2p/rust-libp2p.git", branch = "master" }
187-
libp2p-allow-block-list = { git = "https://github.com/libp2p/rust-libp2p.git", branch = "master" }
188-
libp2p-connection-limits = { git = "https://github.com/libp2p/rust-libp2p.git", branch = "master" }
189-
libp2p-stream = { git = "https://github.com/libp2p/rust-libp2p.git", branch = "master" }
190-
libp2p-webrtc = { git = "https://github.com/libp2p/rust-libp2p.git", branch = "master" }
191-
libp2p-webrtc-websys = { git = "https://github.com/libp2p/rust-libp2p.git", branch = "master" }
183+
web-sys = { workspace = true, optional = true }

examples/upnp/src/main.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@ async fn main() -> std::io::Result<()> {
1313
println!("New listen address: {addr}")
1414
}
1515
SwarmEvent::Behaviour(BehaviourEvent::Upnp(event)) => match event {
16-
UpnpEvent::NewExternalAddr { external_addr, .. } => {
17-
println!("New external address: {external_addr}")
18-
}
19-
UpnpEvent::ExpiredExternalAddr { external_addr, .. } => {
20-
println!("Expired external address: {external_addr}")
16+
UpnpEvent::NewExternalAddr(addr) => println!("New external address: {addr}"),
17+
UpnpEvent::ExpiredExternalAddr(addr) => {
18+
println!("Expired external address: {addr}")
2119
}
2220
UpnpEvent::GatewayNotFound => println!("Gateway not found"),
2321
UpnpEvent::NonRoutableGateway => println!("Gateway is not routable"),
2422
},
2523
_ => {}
24+
_ => {}
2625
})
2726
.build()
2827
.await?;

src/behaviour/autorelay.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
// TODO: Replace with builtin autorelay behaviour from libp2p. See https://github.com/libp2p/rust-libp2p/pull/6156
2-
use std::{
3-
collections::{HashMap, HashSet, VecDeque},
4-
num::NonZeroU8,
5-
task::{Context, Poll, Waker},
6-
time::Duration,
7-
};
8-
92
use crate::behaviour::autorelay::handler::Out;
103
use crate::multiaddr_ext::MultiaddrExt;
114
use crate::prelude::swarm::derive_prelude::{ListenerId, PortUse};
@@ -22,6 +15,13 @@ use crate::prelude::swarm::{
2215
use crate::prelude::transport::Endpoint;
2316
use crate::prelude::{PeerId, Protocol};
2417
use either::Either;
18+
use std::collections::BTreeMap;
19+
use std::{
20+
collections::{HashMap, HashSet, VecDeque},
21+
num::NonZeroU8,
22+
task::{Context, Poll, Waker},
23+
time::Duration,
24+
};
2525
use web_time::{Instant, SystemTime};
2626

2727
mod handler;
@@ -220,10 +220,10 @@ impl Behaviour {
220220
/// This will dial and establish a connection to the peer if it doesn't already have a direct
221221
/// connection.
222222
/// Note that peers that are through a relay cannot be used as a static peer
223-
pub fn add_static_relay(&mut self, peer_id: PeerId, address: Multiaddr) {
223+
pub fn add_static_relay(&mut self, peer_id: PeerId, address: Multiaddr) -> bool {
224224
if address.is_relayed() {
225225
tracing::warn!(%peer_id, %address, "static relay address is relayed. ignoring.");
226-
return;
226+
return false;
227227
}
228228

229229
let entry = self.static_relays.entry(peer_id).or_default();
@@ -245,6 +245,8 @@ impl Behaviour {
245245
if let Some(waker) = self.waker.take() {
246246
waker.wake();
247247
}
248+
249+
true
248250
}
249251

250252
/// Remove peer as a static relay.
@@ -410,7 +412,7 @@ impl Behaviour {
410412
}
411413

412414
/// Removes all existing reservations.
413-
fn remove_all_reservations(&mut self) {
415+
pub fn remove_all_reservations(&mut self) {
414416
let relay_listeners = self
415417
.reservations
416418
.iter()

src/behaviour/request_response/codec.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use async_trait::async_trait;
12
use bytes::Bytes;
23
use futures::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
34
use libp2p::StreamProtocol;
@@ -17,6 +18,7 @@ impl Codec {
1718
}
1819
}
1920

21+
#[async_trait]
2022
impl libp2p::request_response::Codec for Codec {
2123
type Protocol = StreamProtocol;
2224
type Request = Bytes;

src/handle.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ pub(crate) mod gossipsub;
1010
mod peer_store;
1111
#[cfg(feature = "relay")]
1212
mod relay;
13-
#[cfg(not(target_arch = "wasm32"))]
14-
#[cfg(feature = "relay")]
15-
mod relay_server;
1613
#[cfg(feature = "rendezvous")]
1714
pub(crate) mod rendezvous;
1815
#[cfg(feature = "request-response")]
@@ -35,8 +32,6 @@ use crate::handle::gossipsub::ConnexaGossipsub;
3532
use crate::handle::peer_store::ConnexaPeerstore;
3633
#[cfg(feature = "relay")]
3734
use crate::handle::relay::ConnexaRelay;
38-
#[cfg(feature = "relay")]
39-
use crate::handle::relay_server::ConnexaRelayServer;
4035
#[cfg(feature = "rendezvous")]
4136
use crate::handle::rendezvous::ConnexaRendezvous;
4237
#[cfg(feature = "request-response")]
@@ -152,12 +147,6 @@ where
152147
ConnexaRelay::new(self)
153148
}
154149

155-
/// Returns a handle for relay server functions
156-
#[cfg(feature = "relay")]
157-
pub fn relay_server(&self) -> ConnexaRelayServer<'_, T> {
158-
ConnexaRelayServer::new(self)
159-
}
160-
161150
/// Returns a handle to manage peer whitelist functionality
162151
pub fn whitelist(&self) -> ConnexaWhitelist<'_, T, K> {
163152
ConnexaWhitelist::new(self)

src/handle/relay_server.rs

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/task.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,10 +587,6 @@ where
587587
Command::Rendezvous(rendezvous_command) => {
588588
self.process_rendezvous_command(rendezvous_command)
589589
}
590-
#[cfg(feature = "relay")]
591-
Command::RelayServer(relay_server_command) => {
592-
self.process_relay_server_command(relay_server_command)
593-
}
594590
Command::Custom(custom_command) => {
595591
(self.custom_task_callback)(
596592
swarm,

src/task/relay.rs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::behaviour::autorelay;
22
use crate::behaviour::peer_store::store::Store;
33
use crate::task::ConnexaTask;
44
use crate::types::AutoRelayCommand;
5-
use crate::types::RelayServerCommand;
65
use libp2p::relay::{Event as RelayServerEvent, client::Event as RelayClientEvent};
76
use libp2p::swarm::NetworkBehaviour;
87
use std::fmt::Debug;
@@ -158,36 +157,7 @@ where
158157
} => {
159158
tracing::warn!(%src_peer_id, %dst_peer_id, ?error, "relay server circuit closed");
160159
}
161-
RelayServerEvent::StatusChanged { status } => {
162-
tracing::info!(?status, "relay server status changed");
163-
}
164160
_ => {}
165161
}
166162
}
167163
}
168-
169-
impl<X, C: NetworkBehaviour, S, T> ConnexaTask<X, C, S, T>
170-
where
171-
X: Default + Send + 'static,
172-
C: Send,
173-
C::ToSwarm: Debug,
174-
S: Store,
175-
{
176-
pub fn process_relay_server_command(&mut self, command: RelayServerCommand) {
177-
let swarm = self.swarm.as_mut().expect("swarm is active");
178-
match command {
179-
RelayServerCommand::StatusChanged { status, resp } => {
180-
let Some(relay) = swarm.behaviour_mut().relay.as_mut() else {
181-
let _ = resp.send(Err(std::io::Error::other(
182-
"relay server protocol is not enabled",
183-
)));
184-
return;
185-
};
186-
187-
relay.set_status(status);
188-
189-
let _ = resp.send(Ok(()));
190-
}
191-
}
192-
}
193-
}

src/task/upnp.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,11 @@ where
1313
{
1414
pub fn process_upnp_event(&mut self, event: UpnpEvent) {
1515
match event {
16-
UpnpEvent::NewExternalAddr {
17-
external_addr,
18-
local_addr,
19-
} => {
20-
tracing::info!(
21-
?external_addr,
22-
?local_addr,
23-
"upnp external address discovered"
24-
);
16+
UpnpEvent::NewExternalAddr(addr) => {
17+
tracing::info!(?addr, "upnp external address discovered");
2518
}
26-
UpnpEvent::ExpiredExternalAddr {
27-
external_addr,
28-
local_addr,
29-
} => {
30-
tracing::info!(?external_addr, ?local_addr, "upnp external address expired");
19+
UpnpEvent::ExpiredExternalAddr(addr) => {
20+
tracing::info!(?addr, "upnp external address expired");
3121
}
3222
UpnpEvent::GatewayNotFound => {
3323
tracing::warn!("upnp gateway not found");

src/types.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ pub enum Command<T = ()> {
4848
Autonat(AutonatCommand),
4949
#[cfg(feature = "relay")]
5050
AutoRelay(AutoRelayCommand),
51-
#[cfg(not(target_arch = "wasm32"))]
52-
#[cfg(feature = "relay")]
53-
RelayServer(RelayServerCommand),
5451
Whitelist(WhitelistCommand),
5552
Blacklist(BlacklistCommand),
5653
ConnectionLimits(ConnectionLimitsCommand),
@@ -120,14 +117,6 @@ impl<T> From<AutoRelayCommand> for Command<T> {
120117
}
121118
}
122119

123-
#[cfg(not(target_arch = "wasm32"))]
124-
#[cfg(feature = "relay")]
125-
impl<T> From<RelayServerCommand> for Command<T> {
126-
fn from(cmd: RelayServerCommand) -> Self {
127-
Command::RelayServer(cmd)
128-
}
129-
}
130-
131120
impl<T> From<WhitelistCommand> for Command<T> {
132121
fn from(cmd: WhitelistCommand) -> Self {
133122
Command::Whitelist(cmd)
@@ -555,15 +544,6 @@ pub enum RendezvousCommand {
555544
},
556545
}
557546

558-
#[cfg(feature = "relay")]
559-
#[derive(Debug)]
560-
pub enum RelayServerCommand {
561-
StatusChanged {
562-
status: Option<libp2p::relay::Status>,
563-
resp: oneshot::Sender<Result<()>>,
564-
},
565-
}
566-
567547
#[cfg(feature = "kad")]
568548
#[derive(Clone, Debug)]
569549
pub enum DHTEvent {

0 commit comments

Comments
 (0)