Skip to content

Commit

Permalink
Merge branch 'maintain/0.11' into libp2p-next
Browse files Browse the repository at this point in the history
  • Loading branch information
dariusc93 committed Jun 6, 2024
2 parents 927a506 + d23210d commit 9bc8910
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@

# next
- chore: Cleanup Keystore logic and implementation. [PR 222](https://github.com/dariusc93/rust-ipfs/pull/222)
- 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)

# 0.11.20
- feat: Add Ipfs::{add,remove}_external_address.

# 0.11.19
- chore: Pin getrandom to 0.2.14 due to libc 0.2.154 being yanked.

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "rust-ipfs"
readme = "README.md"
repository = "https://github.com/dariusc93/rust-ipfs"
description = "IPFS node implementation"
version = "0.11.19"
version = "0.11.20"

[features]

Expand Down
35 changes: 35 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ enum IpfsEvent {
PubsubSubscribed(Channel<Vec<String>>),
AddListeningAddress(Multiaddr, Channel<Multiaddr>),
RemoveListeningAddress(Multiaddr, Channel<()>),
AddExternalAddress(Multiaddr, Channel<()>),
RemoveExternalAddress(Multiaddr, Channel<()>),
Bootstrap(Channel<ReceiverChannel<KadResult>>),
AddPeer(AddPeerOpt, Channel<()>),
RemovePeer(PeerId, Option<Multiaddr>, Channel<bool>),
Expand Down Expand Up @@ -1786,6 +1788,39 @@ impl Ipfs {
.await
}

/// Add a given multiaddr as a external address to indenticate how our node can be reached.
/// Note: We will not perform checks
pub async fn add_external_address(&self, addr: Multiaddr) -> Result<(), Error> {
async move {
let (tx, rx) = oneshot_channel();

self.to_task
.clone()
.send(IpfsEvent::AddExternalAddress(addr, tx))
.await?;

rx.await?
}
.instrument(self.span.clone())
.await
}

/// Removes a previously added external address.
pub async fn remove_external_address(&self, addr: Multiaddr) -> Result<(), Error> {
async move {
let (tx, rx) = oneshot_channel();

self.to_task
.clone()
.send(IpfsEvent::RemoveExternalAddress(addr, tx))
.await?;

rx.await?
}
.instrument(self.span.clone())
.await
}

/// Obtain the addresses associated with the given `PeerId`; they are first searched for locally
/// and the DHT is used as a fallback: a `Kademlia::get_closest_peers(peer_id)` query is run and
/// when it's finished, the newly added DHT records are checked for the existence of the desired
Expand Down
8 changes: 8 additions & 0 deletions src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,14 @@ impl<C: NetworkBehaviour<ToSwarm = void::Void>> IpfsTask<C> {
}
}
}
IpfsEvent::AddExternalAddress(addr, ret) => {
self.swarm.add_external_address(addr);
_ = ret.send(Ok(()))
}
IpfsEvent::RemoveExternalAddress(addr, ret) => {
self.swarm.remove_external_address(&addr);
_ = ret.send(Ok(()))
}
IpfsEvent::Bootstrap(ret) => {
let Some(kad) = self.swarm.behaviour_mut().kademlia.as_mut() else {
let _ = ret.send(Err(anyhow!("kad protocol is disabled")));
Expand Down

0 comments on commit 9bc8910

Please sign in to comment.