Skip to content

Commit

Permalink
Remove ConnectionInfo trait (#1813)
Browse files Browse the repository at this point in the history
In all cases, we pass the PeerId directly as the connection info.
The flexbility of doing something different here was originally
envisioned but turned out to be never needed.

For reference see: #1798 (comment)

Co-authored-by: Max Inden <mail@max-inden.de>
  • Loading branch information
thomaseizinger and mxinden committed Oct 30, 2020
1 parent 421ae9d commit 335e55e
Show file tree
Hide file tree
Showing 54 changed files with 555 additions and 589 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
- [`parity-multiaddr` CHANGELOG](misc/multiaddr/CHANGELOG.md)
- [`libp2p-core-derive` CHANGELOG](misc/core-derive/CHANGELOG.md)

# Version 0.30.0 [unreleased]

- Update `libp2p-core` and all its dependers.

# Version 0.29.1 [2020-10-20]

- Update `libp2p-core`.
Expand Down
40 changes: 20 additions & 20 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "libp2p"
edition = "2018"
description = "Peer-to-peer networking library"
version = "0.29.1"
version = "0.30.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down Expand Up @@ -62,22 +62,22 @@ atomic = "0.5.0"
bytes = "0.5"
futures = "0.3.1"
lazy_static = "1.2"
libp2p-core = { version = "0.23.1", path = "core" }
libp2p-core = { version = "0.24.0", path = "core" }
libp2p-core-derive = { version = "0.20.2", path = "misc/core-derive" }
libp2p-floodsub = { version = "0.23.0", path = "protocols/floodsub", optional = true }
libp2p-gossipsub = { version = "0.23.0", path = "./protocols/gossipsub", optional = true }
libp2p-identify = { version = "0.23.0", path = "protocols/identify", optional = true }
libp2p-kad = { version = "0.24.0", path = "protocols/kad", optional = true }
libp2p-mplex = { version = "0.23.0", path = "muxers/mplex", optional = true }
libp2p-noise = { version = "0.25.0", path = "protocols/noise", optional = true }
libp2p-ping = { version = "0.23.0", path = "protocols/ping", optional = true }
libp2p-plaintext = { version = "0.23.0", path = "protocols/plaintext", optional = true }
libp2p-floodsub = { version = "0.24.0", path = "protocols/floodsub", optional = true }
libp2p-gossipsub = { version = "0.24.0", path = "./protocols/gossipsub", optional = true }
libp2p-identify = { version = "0.24.0", path = "protocols/identify", optional = true }
libp2p-kad = { version = "0.25.0", path = "protocols/kad", optional = true }
libp2p-mplex = { version = "0.24.0", path = "muxers/mplex", optional = true }
libp2p-noise = { version = "0.26.0", path = "protocols/noise", optional = true }
libp2p-ping = { version = "0.24.0", path = "protocols/ping", optional = true }
libp2p-plaintext = { version = "0.24.0", path = "protocols/plaintext", optional = true }
libp2p-pnet = { version = "0.19.2", path = "protocols/pnet", optional = true }
libp2p-request-response = { version = "0.4.0", path = "protocols/request-response", optional = true }
libp2p-swarm = { version = "0.23.0", path = "swarm" }
libp2p-uds = { version = "0.23.0", path = "transports/uds", optional = true }
libp2p-wasm-ext = { version = "0.23.0", path = "transports/wasm-ext", optional = true }
libp2p-yamux = { version = "0.26.0", path = "muxers/yamux", optional = true }
libp2p-request-response = { version = "0.5.0", path = "protocols/request-response", optional = true }
libp2p-swarm = { version = "0.24.0", path = "swarm" }
libp2p-uds = { version = "0.24.0", path = "transports/uds", optional = true }
libp2p-wasm-ext = { version = "0.24.0", path = "transports/wasm-ext", optional = true }
libp2p-yamux = { version = "0.27.0", path = "muxers/yamux", optional = true }
multiaddr = { package = "parity-multiaddr", version = "0.9.3", path = "misc/multiaddr" }
multihash = "0.11.0"
parking_lot = "0.11.0"
Expand All @@ -86,11 +86,11 @@ smallvec = "1.0"
wasm-timer = "0.2.4"

[target.'cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))'.dependencies]
libp2p-deflate = { version = "0.23.0", path = "protocols/deflate", optional = true }
libp2p-dns = { version = "0.23.0", path = "transports/dns", optional = true }
libp2p-mdns = { version = "0.23.0", path = "protocols/mdns", optional = true }
libp2p-tcp = { version = "0.23.0", path = "transports/tcp", optional = true }
libp2p-websocket = { version = "0.24.0", path = "transports/websocket", optional = true }
libp2p-deflate = { version = "0.24.0", path = "protocols/deflate", optional = true }
libp2p-dns = { version = "0.24.0", path = "transports/dns", optional = true }
libp2p-mdns = { version = "0.24.0", path = "protocols/mdns", optional = true }
libp2p-tcp = { version = "0.24.0", path = "transports/tcp", optional = true }
libp2p-websocket = { version = "0.25.0", path = "transports/websocket", optional = true }

[dev-dependencies]
async-std = "1.6.2"
Expand Down
6 changes: 6 additions & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 0.24.0 [unreleased]

- Remove `ConnectionInfo` trait and replace it with `PeerId`
everywhere. This was already effectively the case because
`ConnectionInfo` was implemented on `PeerId`.

# 0.23.1 [2020-10-20]

- Update dependencies.
Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "libp2p-core"
edition = "2018"
description = "Core traits and structs of libp2p"
version = "0.23.1"
version = "0.24.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
36 changes: 5 additions & 31 deletions core/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,37 +159,11 @@ impl ConnectedPoint {

/// Information about a successfully established connection.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Connected<I> {
pub struct Connected {
/// The connected endpoint, including network address information.
pub endpoint: ConnectedPoint,
/// Information obtained from the transport.
pub info: I,
}

impl<I> Connected<I>
where
I: ConnectionInfo
{
pub fn peer_id(&self) -> &I::PeerId {
self.info.peer_id()
}
}

/// Information about a connection.
pub trait ConnectionInfo {
/// Identity of the node we are connected to.
type PeerId: Eq + Hash;

/// Returns the identity of the node we are connected to on this connection.
fn peer_id(&self) -> &Self::PeerId;
}

impl ConnectionInfo for PeerId {
type PeerId = PeerId;

fn peer_id(&self) -> &PeerId {
self
}
pub peer_id: PeerId,
}

/// Event generated by a [`Connection`].
Expand Down Expand Up @@ -334,12 +308,12 @@ impl<'a> IncomingInfo<'a> {

/// Borrowed information about an outgoing connection currently being negotiated.
#[derive(Debug, Copy, Clone)]
pub struct OutgoingInfo<'a, TPeerId> {
pub struct OutgoingInfo<'a> {
pub address: &'a Multiaddr,
pub peer_id: Option<&'a TPeerId>,
pub peer_id: Option<&'a PeerId>,
}

impl<'a, TPeerId> OutgoingInfo<'a, TPeerId> {
impl<'a> OutgoingInfo<'a> {
/// Builds a `ConnectedPoint` corresponding to the outgoing connection.
pub fn to_connected_point(&self) -> ConnectedPoint {
ConnectedPoint::Dialer {
Expand Down
10 changes: 5 additions & 5 deletions core/src/connection/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

use crate::{Multiaddr, PeerId};
use crate::Multiaddr;
use std::{task::Context, task::Poll};
use super::{Connected, SubstreamEndpoint};

Expand Down Expand Up @@ -69,24 +69,24 @@ pub trait ConnectionHandler {
}

/// Prototype for a `ConnectionHandler`.
pub trait IntoConnectionHandler<TConnInfo = PeerId> {
pub trait IntoConnectionHandler {
/// The node handler.
type Handler: ConnectionHandler;

/// Builds the node handler.
///
/// The implementation is given a `Connected` value that holds information about
/// the newly established connection for which a handler should be created.
fn into_handler(self, connected: &Connected<TConnInfo>) -> Self::Handler;
fn into_handler(self, connected: &Connected) -> Self::Handler;
}

impl<T, TConnInfo> IntoConnectionHandler<TConnInfo> for T
impl<T> IntoConnectionHandler for T
where
T: ConnectionHandler
{
type Handler = Self;

fn into_handler(self, _: &Connected<TConnInfo>) -> Self {
fn into_handler(self, _: &Connected) -> Self {
self
}
}
Expand Down
Loading

0 comments on commit 335e55e

Please sign in to comment.