Skip to content

Commit

Permalink
chore: Remove relay connection from spawn task and minor change
Browse files Browse the repository at this point in the history
  • Loading branch information
dariusc93 committed Nov 3, 2023
1 parent ece6cfe commit 0057618
Showing 1 changed file with 26 additions and 30 deletions.
56 changes: 26 additions & 30 deletions extensions/warp-ipfs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl WarpIpfs {
Bootstrap::None => true,
};

if empty_bootstrap {
if empty_bootstrap && !config.ipfs_setting.dht_client {
warn!("Bootstrap list is empty. Will not be able to perform a bootstrap for DHT");
}

Expand Down Expand Up @@ -383,7 +383,7 @@ impl WarpIpfs {
};

if let Err(e) = ipfs.add_peer(peer_id, addr.clone()).await {
warn!("Error error relay: {e}");
warn!("Failed to add relay to address book: {e}");
}

if let Err(e) = ipfs.add_relay(peer_id, addr).await {
Expand All @@ -398,27 +398,22 @@ impl WarpIpfs {
warn!("No relays available");
}

tokio::spawn({
let ipfs = ipfs.clone();
async move {
for relay_peer in relay_peers {
if let Err(e) = ipfs.enable_relay(Some(relay_peer)).await {
error!("Error listening on relay peer {relay_peer}: {e}");
continue;
}
for relay_peer in relay_peers {
if let Err(e) = ipfs.enable_relay(Some(relay_peer)).await {
error!("Failed to use {relay_peer} as a relay: {e}");
continue;
}

let list = ipfs.list_relays(true).await.unwrap_or_default();
for addr in list
.iter()
.filter(|(peer_id, _)| *peer_id == relay_peer)
.flat_map(|(_, addrs)| addrs)
{
debug!("Listening on {}", addr.clone().with(Protocol::P2pCircuit));
}
break;
}
let list = ipfs.list_relays(true).await.unwrap_or_default();
for addr in list
.iter()
.filter(|(peer_id, _)| *peer_id == relay_peer)
.flat_map(|(_, addrs)| addrs)
{
info!("Listening on {}", addr.clone().with(Protocol::P2pCircuit));
}
});
break;
}

if config.ipfs_setting.dht_client {
ipfs.dht_mode(DhtMode::Client).await?;
Expand Down Expand Up @@ -478,7 +473,7 @@ impl WarpIpfs {

*self.file_store.write() = Some(filestore);

*self.message_store.write() = MessageStore::new(
let message_store = MessageStore::new(
ipfs.clone(),
config.path.map(|path| path.join("messages")),
identity_store,
Expand All @@ -493,8 +488,9 @@ impl WarpIpfs {
config.store_setting.with_friends,
),
)
.await
.ok();
.await?;

*self.message_store.write() = Some(message_store);

info!("Messaging store initialized");

Expand Down Expand Up @@ -651,14 +647,14 @@ impl MultiPass for WarpIpfs {
async fn get_identity(&self, id: Identifier) -> Result<Vec<Identity>, Error> {
let store = self.identity_store(true).await?;

let idents = match id {
Identifier::DID(pk) => store.lookup(LookupBy::DidKey(pk)).await,
Identifier::Username(username) => store.lookup(LookupBy::Username(username)).await,
Identifier::DIDList(list) => store.lookup(LookupBy::DidKeys(list)).await,
let kind = match id {
Identifier::DID(pk) => LookupBy::DidKey(pk),
Identifier::Username(username) => LookupBy::Username(username),
Identifier::DIDList(list) => LookupBy::DidKeys(list),
Identifier::Own => return store.own_identity().await.map(|i| vec![i]),
}?;
};

Ok(idents)
store.lookup(kind).await
}

async fn update_identity(&mut self, option: IdentityUpdate) -> Result<(), Error> {
Expand Down

0 comments on commit 0057618

Please sign in to comment.