Skip to content

Commit

Permalink
swarm/src/dial_opts: Implement From<PeerId> for DialOpts
Browse files Browse the repository at this point in the history
  • Loading branch information
mxinden committed Nov 15, 2021
1 parent fed72bf commit 09293c4
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 1 addition & 3 deletions protocols/identify/src/identify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,9 +757,7 @@ mod tests {
});

// We should still be able to dial now!
swarm2
.dial(DialOpts::peer_id(swarm1_peer_id).build())
.unwrap();
swarm2.dial(swarm1_peer_id).unwrap();

let connected_peer = async_std::task::block_on(async {
loop {
Expand Down
6 changes: 2 additions & 4 deletions protocols/rendezvous/tests/rendezvous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ async fn discover_allows_for_dial_by_peer_id() {
let alices_peer_id = *alice.local_peer_id();
let bobs_peer_id = *bob.local_peer_id();

bob.dial(DialOpts::peer_id(alices_peer_id).build()).unwrap();
bob.dial(alices_peer_id).unwrap();

let alice_connected_to = tokio::spawn(async move {
loop {
Expand Down Expand Up @@ -295,9 +295,7 @@ async fn registration_on_clients_expire() {
tokio::time::sleep(Duration::from_secs(registration_ttl + 5)).await;

let event = bob.select_next_some().await;
let error = bob
.dial(DialOpts::peer_id(*alice.local_peer_id()).build())
.unwrap_err();
let error = bob.dial(*alice.local_peer_id()).unwrap_err();

assert!(matches!(
event,
Expand Down
3 changes: 2 additions & 1 deletion swarm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
Changes required to maintain status quo:

- Previously `swarm.dial(peer_id)`
now `swarm.dial(DialOpts::peer_id(swarm1_peer_id).build())`
now `swarm.dial(DialOpts::peer_id(peer_id).build())`
or `swarm.dial(peer_id)` given that `DialOpts` implements `From<PeerId>`.

- Previously `swarm.dial_addr(addr)`
now `swarm.dial(DialOpts::unknown_peer_id().address(addr).build())`
Expand Down
6 changes: 6 additions & 0 deletions swarm/src/dial_opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ impl From<Multiaddr> for DialOpts {
}
}

impl From<PeerId> for DialOpts {
fn from(peer_id: PeerId) -> Self {
DialOpts::peer_id(peer_id).build()
}
}

/// Internal options type.
///
/// Not to be constructed manually. Use either of the below instead:
Expand Down
5 changes: 1 addition & 4 deletions swarm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,7 @@ where
/// );
///
/// // Dial a known peer.
/// swarm.dial(
/// DialOpts::peer_id(PeerId::random())
/// .build()
/// );
/// swarm.dial(PeerId::random());
///
/// // Dial an unknown peer.
/// swarm.dial("/ip6/::1/tcp/12345".parse().unwrap());
Expand Down

0 comments on commit 09293c4

Please sign in to comment.