Skip to content

Commit 079b2d6

Browse files
authored
refactor(*): Transport redesign
Resolves: #4226. Resolves: #3953. Resolves: #3889. Pull-Request: #4568.
1 parent 53eb339 commit 079b2d6

File tree

129 files changed

+1294
-1175
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+1294
-1175
lines changed

Cargo.lock

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,45 +76,44 @@ futures-bounded = { version = "0.2.4" }
7676
futures-rustls = { version = "0.26.0", default-features = false }
7777
libp2p = { version = "0.54.0", path = "libp2p" }
7878
libp2p-allow-block-list = { version = "0.3.0", path = "misc/allow-block-list" }
79-
libp2p-autonat = { version = "0.12.1", path = "protocols/autonat" }
79+
libp2p-autonat = { version = "0.13.0", path = "protocols/autonat" }
8080
libp2p-connection-limits = { version = "0.3.1", path = "misc/connection-limits" }
81-
libp2p-core = { version = "0.41.3", path = "core" }
82-
libp2p-dcutr = { version = "0.11.1", path = "protocols/dcutr" }
83-
libp2p-dns = { version = "0.41.1", path = "transports/dns" }
84-
libp2p-floodsub = { version = "0.44.0", path = "protocols/floodsub" }
81+
libp2p-core = { version = "0.42.0", path = "core" }
82+
libp2p-dcutr = { version = "0.12.0", path = "protocols/dcutr" }
83+
libp2p-dns = { version = "0.42.0", path = "transports/dns" }
84+
libp2p-floodsub = { version = "0.45.0", path = "protocols/floodsub" }
8585
libp2p-gossipsub = { version = "0.47.0", path = "protocols/gossipsub" }
8686
libp2p-identify = { version = "0.45.0", path = "protocols/identify" }
8787
libp2p-identity = { version = "0.2.9" }
8888
libp2p-kad = { version = "0.46.0", path = "protocols/kad" }
89-
libp2p-mdns = { version = "0.45.2", path = "protocols/mdns" }
89+
libp2p-mdns = { version = "0.46.0", path = "protocols/mdns" }
9090
libp2p-memory-connection-limits = { version = "0.2.0", path = "misc/memory-connection-limits" }
9191
libp2p-metrics = { version = "0.14.2", path = "misc/metrics" }
9292
libp2p-mplex = { version = "0.41.0", path = "muxers/mplex" }
93-
libp2p-muxer-test-harness = { path = "muxers/test-harness" }
9493
libp2p-noise = { version = "0.44.0", path = "transports/noise" }
9594
libp2p-perf = { version = "0.4.0", path = "protocols/perf" }
96-
libp2p-ping = { version = "0.44.2", path = "protocols/ping" }
95+
libp2p-ping = { version = "0.45.0", path = "protocols/ping" }
9796
libp2p-plaintext = { version = "0.41.0", path = "transports/plaintext" }
9897
libp2p-pnet = { version = "0.24.0", path = "transports/pnet" }
99-
libp2p-quic = { version = "0.10.3", path = "transports/quic" }
100-
libp2p-relay = { version = "0.17.3", path = "protocols/relay" }
101-
libp2p-rendezvous = { version = "0.14.1", path = "protocols/rendezvous" }
102-
libp2p-request-response = { version = "0.26.4", path = "protocols/request-response" }
98+
libp2p-quic = { version = "0.11.0", path = "transports/quic" }
99+
libp2p-relay = { version = "0.18.0", path = "protocols/relay" }
100+
libp2p-rendezvous = { version = "0.15.0", path = "protocols/rendezvous" }
101+
libp2p-request-response = { version = "0.27.0", path = "protocols/request-response" }
103102
libp2p-server = { version = "0.12.7", path = "misc/server" }
104-
libp2p-stream = { version = "0.1.0-alpha.1", path = "protocols/stream" }
103+
libp2p-stream = { version = "0.2.0-alpha", path = "protocols/stream" }
105104
libp2p-swarm = { version = "0.45.0", path = "swarm" }
106105
libp2p-swarm-derive = { version = "=0.34.2", path = "swarm-derive" } # `libp2p-swarm-derive` may not be compatible with different `libp2p-swarm` non-breaking releases. E.g. `libp2p-swarm` might introduce a new enum variant `FromSwarm` (which is `#[non-exhaustive]`) in a non-breaking release. Older versions of `libp2p-swarm-derive` would not forward this enum variant within the `NetworkBehaviour` hierarchy. Thus the version pinning is required.
107106
libp2p-swarm-test = { version = "0.3.0", path = "swarm-test" }
108107
libp2p-tcp = { version = "0.42.0", path = "transports/tcp" }
109108
libp2p-tls = { version = "0.4.1", path = "transports/tls" }
110-
libp2p-uds = { version = "0.40.0", path = "transports/uds" }
111-
libp2p-upnp = { version = "0.2.2", path = "protocols/upnp" }
112-
libp2p-webrtc = { version = "0.7.1-alpha", path = "transports/webrtc" }
109+
libp2p-uds = { version = "0.41.0", path = "transports/uds" }
110+
libp2p-upnp = { version = "0.3.0", path = "protocols/upnp" }
111+
libp2p-webrtc = { version = "0.8.0-alpha", path = "transports/webrtc" }
113112
libp2p-webrtc-utils = { version = "0.2.1", path = "misc/webrtc-utils" }
114-
libp2p-webrtc-websys = { version = "0.3.0-alpha", path = "transports/webrtc-websys" }
115-
libp2p-websocket = { version = "0.43.2", path = "transports/websocket" }
116-
libp2p-websocket-websys = { version = "0.3.3", path = "transports/websocket-websys" }
117-
libp2p-webtransport-websys = { version = "0.3.0", path = "transports/webtransport-websys" }
113+
libp2p-webrtc-websys = { version = "0.4.0-alpha", path = "transports/webrtc-websys" }
114+
libp2p-websocket = { version = "0.44.0", path = "transports/websocket" }
115+
libp2p-websocket-websys = { version = "0.4.0", path = "transports/websocket-websys" }
116+
libp2p-webtransport-websys = { version = "0.4.0", path = "transports/webtransport-websys" }
118117
libp2p-yamux = { version = "0.45.2", path = "muxers/yamux" }
119118
multiaddr = "0.18.1"
120119
multihash = "0.19.1"

core/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
## 0.42.0
2+
3+
- Update `Transport::dial` function signature with a `DialOpts` param and remove `Transport::dial_as_listener`:
4+
- `DialOpts` struct contains `PortUse` and `Endpoint`,
5+
- `PortUse` allows controling port allocation of new connections (defaults to `PortUse::Reuse`) -
6+
- Add `port_use` field to `ConnectedPoint`
7+
- Set `endpoint` field in `DialOpts` to `Endpoint::Listener` to dial as a listener
8+
- Remove `Transport::address_translation` and relocate functionality to `libp2p_swarm`
9+
10+
See [PR 4568].
11+
112
## 0.41.3
213
- Use `web-time` instead of `instant`.
314
See [PR 5347](https://github.com/libp2p/rust-libp2p/pull/5347).

core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "libp2p-core"
33
edition = "2021"
44
rust-version = { workspace = true }
55
description = "Core traits and structs of libp2p"
6-
version = "0.41.3"
6+
version = "0.42.0"
77
authors = ["Parity Technologies <[email protected]>"]
88
license = "MIT"
99
repository = "https://github.com/libp2p/rust-libp2p"

core/src/connection.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1919
// DEALINGS IN THE SOFTWARE.
2020

21-
use crate::multiaddr::{Multiaddr, Protocol};
21+
use crate::{
22+
multiaddr::{Multiaddr, Protocol},
23+
transport::PortUse,
24+
};
2225

2326
/// The endpoint roles associated with a peer-to-peer communication channel.
2427
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
@@ -80,6 +83,13 @@ pub enum ConnectedPoint {
8083
/// connection as a dialer and one peer dial the other and upgrade the
8184
/// connection _as a listener_ overriding its role.
8285
role_override: Endpoint,
86+
/// Whether the port for the outgoing connection was reused from a listener
87+
/// or a new port was allocated. This is useful for address translation.
88+
///
89+
/// The port use is implemented on a best-effort basis. It is not guaranteed
90+
/// that [`PortUse::Reuse`] actually reused a port. A good example is the case
91+
/// where there is no listener available to reuse a port from.
92+
port_use: PortUse,
8393
},
8494
/// We received the node.
8595
Listener {
@@ -133,6 +143,7 @@ impl ConnectedPoint {
133143
ConnectedPoint::Dialer {
134144
address,
135145
role_override: _,
146+
port_use: _,
136147
} => address,
137148
ConnectedPoint::Listener { local_addr, .. } => local_addr,
138149
}

core/src/either.rs

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
// DEALINGS IN THE SOFTWARE.
2020

2121
use crate::muxing::StreamMuxerEvent;
22+
use crate::transport::DialOpts;
2223
use crate::{
2324
muxing::StreamMuxer,
2425
transport::{ListenerId, Transport, TransportError, TransportEvent},
@@ -172,48 +173,23 @@ where
172173
}
173174
}
174175

175-
fn dial(&mut self, addr: Multiaddr) -> Result<Self::Dial, TransportError<Self::Error>> {
176-
use TransportError::*;
177-
match self {
178-
Either::Left(a) => match a.dial(addr) {
179-
Ok(connec) => Ok(EitherFuture::First(connec)),
180-
Err(MultiaddrNotSupported(addr)) => Err(MultiaddrNotSupported(addr)),
181-
Err(Other(err)) => Err(Other(Either::Left(err))),
182-
},
183-
Either::Right(b) => match b.dial(addr) {
184-
Ok(connec) => Ok(EitherFuture::Second(connec)),
185-
Err(MultiaddrNotSupported(addr)) => Err(MultiaddrNotSupported(addr)),
186-
Err(Other(err)) => Err(Other(Either::Right(err))),
187-
},
188-
}
189-
}
190-
191-
fn dial_as_listener(
176+
fn dial(
192177
&mut self,
193178
addr: Multiaddr,
194-
) -> Result<Self::Dial, TransportError<Self::Error>>
195-
where
196-
Self: Sized,
197-
{
179+
opts: DialOpts,
180+
) -> Result<Self::Dial, TransportError<Self::Error>> {
198181
use TransportError::*;
199182
match self {
200-
Either::Left(a) => match a.dial_as_listener(addr) {
183+
Either::Left(a) => match a.dial(addr, opts) {
201184
Ok(connec) => Ok(EitherFuture::First(connec)),
202185
Err(MultiaddrNotSupported(addr)) => Err(MultiaddrNotSupported(addr)),
203186
Err(Other(err)) => Err(Other(Either::Left(err))),
204187
},
205-
Either::Right(b) => match b.dial_as_listener(addr) {
188+
Either::Right(b) => match b.dial(addr, opts) {
206189
Ok(connec) => Ok(EitherFuture::Second(connec)),
207190
Err(MultiaddrNotSupported(addr)) => Err(MultiaddrNotSupported(addr)),
208191
Err(Other(err)) => Err(Other(Either::Right(err))),
209192
},
210193
}
211194
}
212-
213-
fn address_translation(&self, server: &Multiaddr, observed: &Multiaddr) -> Option<Multiaddr> {
214-
match self {
215-
Either::Left(a) => a.address_translation(server, observed),
216-
Either::Right(b) => b.address_translation(server, observed),
217-
}
218-
}
219195
}

core/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ mod proto {
4545
pub use multiaddr;
4646
pub type Negotiated<T> = multistream_select::Negotiated<T>;
4747

48-
mod translation;
49-
5048
pub mod connection;
5149
pub mod either;
5250
pub mod muxing;
@@ -62,7 +60,6 @@ pub use multihash;
6260
pub use muxing::StreamMuxer;
6361
pub use peer_record::PeerRecord;
6462
pub use signed_envelope::SignedEnvelope;
65-
pub use translation::address_translation;
6663
pub use transport::Transport;
6764
pub use upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo};
6865

0 commit comments

Comments
 (0)