{core,swarm}/: Don't require Transport: Clone and take &mut (#2529)

Previously `libp2p-swarm` required a `Transport` to be `Clone`. Methods
on `Transport`, e.g. `Transport::dial` would take ownership, requiring
e.g. a `Clone::clone` before calling `Transport::dial`.

The requirement of `Transport` to be `Clone` is no longer needed in
`libp2p-swarm`. E.g.  concurrent dialing can be done without a clone per
dial.

This commit removes the requirement of `Clone` for `Transport` in
`libp2p-swarm`. As a follow-up methods on `Transport` no longer take
ownership, but instead a mutable reference (`&mut self`).

On the one hand this simplifies `libp2p-swarm`, on the other it
simplifies implementations of `Transport`.
This commit is contained in:
Max Inden
2022-04-06 20:23:16 +02:00
committed by GitHub
parent 7a1147877a
commit 2ad905f35a
82 changed files with 751 additions and 449 deletions

View File

@ -276,7 +276,7 @@ mod tests {
let (tx, rx) = oneshot::channel();
let bg_task = async_std::task::spawn(async move {
let transport = TcpConfig::new();
let mut transport = TcpConfig::new();
let mut listener = transport
.listen_on("/ip4/127.0.0.1/tcp/0".parse().unwrap())
@ -321,7 +321,7 @@ mod tests {
});
async_std::task::block_on(async move {
let transport = TcpConfig::new();
let mut transport = TcpConfig::new();
let socket = transport.dial(rx.await.unwrap()).unwrap().await.unwrap();
let info = apply_outbound(socket, IdentifyProtocol, upgrade::Version::V1)