Skip to content

Commit 4fa8360

Browse files
author
Roman S. Borschel
committed
Allow multiple connections per peer in libp2p-core.
Instead of trying to enforce a single connection per peer, which involves quite a bit of additional complexity e.g. to prioritise simultaneously opened connections and can have other undesirable consequences [1], we now make multiple connections per peer a feature. The gist of these changes is as follows: The concept of a "node" with an implicit 1-1 correspondence to a connection has been replaced with the "first-class" concept of a "connection". The code from `src/nodes` has moved (with varying degrees of modification) to `src/connection`. A `HandledNode` has become a `Connection`, a `NodeHandler` a `ConnectionHandler`, the `CollectionStream` was the basis for the new `connection::Pool`, and so forth. Conceptually, a `Network` contains a `connection::Pool` which in turn internally employs the `connection::Manager` for handling the background `connection::manager::Task`s, one per connection, as before. These are all considered implementation details. On the public API, `Peer`s are managed as before through the `Network`, except now the API has changed with the shift of focus to (potentially multiple) connections per peer. The `NetworkEvent`s have accordingly also undergone changes. The Swarm APIs remain largely unchanged, except for the fact that `inject_replaced` is no longer called. It may now practically happen that multiple `ProtocolsHandler`s are associated with a single `NetworkBehaviour`, one per connection. If implementations of `NetworkBehaviour` rely somehow on communicating with exactly one `ProtocolsHandler`, this may cause issues, but it is unlikely. [1]: paritytech/substrate#4272
1 parent 70d634d commit 4fa8360

36 files changed

+4154
-4543
lines changed

core/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ categories = ["network-programming", "asynchronous"]
1313
asn1_der = "0.6.1"
1414
bs58 = "0.3.0"
1515
ed25519-dalek = "1.0.0-pre.3"
16+
either = "1.5"
1617
fnv = "1.0"
1718
futures = { version = "0.3.1", features = ["compat", "io-compat", "executor", "thread-pool"] }
1819
futures-timer = "3"

0 commit comments

Comments
 (0)