Skip to content

Commit

Permalink
feat(swarm): Make executor for connection tasks explicit (libp2p#3097)
Browse files Browse the repository at this point in the history
Previously, the executor for connection tasks silently defaulted to a `futures::executor::ThreadPool`. This causes issues such as libp2p#2230.

With this patch, we force the user to choose, which executor they want to run the connection tasks on which results in overall simpler API with less footguns.

Closes libp2p#3068.
  • Loading branch information
umgefahren committed Nov 15, 2022
1 parent c7cd08e commit ff59e46
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/autonat_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async fn main() -> Result<(), Box<dyn Error>> {

let behaviour = Behaviour::new(local_key.public());

let mut swarm = Swarm::new(transport, behaviour, local_peer_id);
let mut swarm = Swarm::with_async_std_executor(transport, behaviour, local_peer_id);
swarm.listen_on(
Multiaddr::empty()
.with(Protocol::Ip4(Ipv4Addr::UNSPECIFIED))
Expand Down
2 changes: 1 addition & 1 deletion examples/autonat_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async fn main() -> Result<(), Box<dyn Error>> {

let behaviour = Behaviour::new(local_key.public());

let mut swarm = Swarm::new(transport, behaviour, local_peer_id);
let mut swarm = Swarm::with_async_std_executor(transport, behaviour, local_peer_id);
swarm.listen_on(
Multiaddr::empty()
.with(Protocol::Ip4(Ipv4Addr::UNSPECIFIED))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async fn init_swarm(config: Config) -> Swarm<Behaviour> {
let local_id = PeerId::from_public_key(&keypair.public());
let transport = development_transport(keypair).await.unwrap();
let behaviour = Behaviour::new(local_id, config);
Swarm::new(transport, behaviour, local_id)
Swarm::with_async_std_executor(transport, behaviour, local_id)
}

async fn spawn_server(kill: oneshot::Receiver<()>) -> (PeerId, Multiaddr) {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async fn init_swarm(config: Config) -> Swarm<Behaviour> {
let local_id = PeerId::from_public_key(&keypair.public());
let transport = development_transport(keypair).await.unwrap();
let behaviour = Behaviour::new(local_id, config);
Swarm::new(transport, behaviour, local_id)
Swarm::with_async_std_executor(transport, behaviour, local_id)
}

async fn init_server(config: Option<Config>) -> (Swarm<Behaviour>, PeerId, Multiaddr) {
Expand Down

0 comments on commit ff59e46

Please sign in to comment.