Skip to content

Commit

Permalink
feat: Add AddPeerOpt::{set_keepalive, keepalive, can_keep_alive) (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
dariusc93 committed Jun 13, 2024
1 parent ad5f24c commit cea5eae
Show file tree
Hide file tree
Showing 5 changed files with 285 additions and 42 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- feat: Add {Into}AddPeerOpt. [PR 226](https://github.com/dariusc93/rust-ipfs/pull/226)
- refactor: Simplify bitswap WantSession. [PR 234](https://github.com/dariusc93/rust-ipfs/pull/234)
- chore: Use default handler in bitswap behaviour. [PR 235](https://github.com/dariusc93/rust-ipfs/pull/235)
- feat: Add AddPeerOpt::{set_keepalive, keepalive, can_keep_alive). [PR XXX](https://github.com/dariusc93/rust-ipfs/pull/XXX)

# 0.11.20
- feat: Add Ipfs::{add,remove}_external_address.
Expand Down
22 changes: 20 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2449,6 +2449,7 @@ pub struct AddPeerOpt {
addresses: Vec<Multiaddr>,
condition: Option<PeerCondition>,
dial: bool,
keepalive: bool,
}

impl AddPeerOpt {
Expand All @@ -2458,6 +2459,7 @@ impl AddPeerOpt {
addresses: vec![],
condition: None,
dial: false,
keepalive: false,
}
}

Expand Down Expand Up @@ -2499,6 +2501,16 @@ impl AddPeerOpt {
self.dial = dial;
self
}

pub fn keepalive(mut self) -> Self {
self.keepalive = true;
self
}

pub fn set_keepalive(mut self, keepalive: bool) -> Self {
self.keepalive = keepalive;
self
}
}

impl AddPeerOpt {
Expand All @@ -2510,6 +2522,10 @@ impl AddPeerOpt {
&self.addresses
}

pub fn can_keep_alive(&self) -> bool {
self.keepalive
}

pub fn to_dial_opts(&self) -> Option<DialOpts> {
if !self.dial {
return None;
Expand Down Expand Up @@ -2537,13 +2553,15 @@ impl IntoAddPeerOpt for AddPeerOpt {

impl IntoAddPeerOpt for (PeerId, Multiaddr) {
fn into_opt(self) -> Result<AddPeerOpt, anyhow::Error> {
Ok(AddPeerOpt::with_peer_id(self.0).add_address(self.1))
let (peer_id, addr) = self;
Ok(AddPeerOpt::with_peer_id(peer_id).add_address(addr))
}
}

impl IntoAddPeerOpt for (PeerId, Vec<Multiaddr>) {
fn into_opt(self) -> Result<AddPeerOpt, anyhow::Error> {
Ok(AddPeerOpt::with_peer_id(self.0).set_addresses(self.1))
let (peer_id, addrs) = self;
Ok(AddPeerOpt::with_peer_id(peer_id).set_addresses(addrs))
}
}

Expand Down
Loading

0 comments on commit cea5eae

Please sign in to comment.