Skip to content

Commit

Permalink
Merge branch 'main' into feat/shuttle-gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
dariusc93 committed Oct 24, 2023
2 parents a1f04db + ac0dbef commit 79f7987
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 53 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ either = "1"
void = "1"

#ipfs dependency
rust-ipfs = "0.5.0"
rust-ipfs = "0.6.0"


# Blink related crates
Expand Down
45 changes: 24 additions & 21 deletions extensions/warp-ipfs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,18 +279,7 @@ impl WarpIpfs {

info!("Starting ipfs");
let mut uninitialized = UninitializedIpfs::empty()
.set_listening_addrs(config.listen_on.clone())
.set_custom_behaviour(behaviour)
.set_keypair(keypair)
.enable_rendezvous_client()
.set_transport_configuration(TransportConfig {
yamux_update_mode: UpdateMode::Read,
..Default::default()
})
.listen_as_external_addr()
.enable_relay(true)
.set_swarm_configuration(swarm_configuration)
.set_identify_configuration({
.with_identify(Some({
let mut idconfig = IdentifyConfiguration {
protocol_version: "/satellite/warp/0.1".into(),
..Default::default()
Expand All @@ -299,21 +288,35 @@ impl WarpIpfs {
idconfig.agent_version = agent.clone();
}
idconfig
})
.set_kad_configuration(
KadConfig {
}))
.with_autonat()
.with_bitswap(None)
.with_kademlia(
Some(either::Either::Left(KadConfig {
query_timeout: std::time::Duration::from_secs(60),
publication_interval: Some(Duration::from_secs(30 * 60)),
provider_record_ttl: Some(Duration::from_secs(60 * 60)),
insert_method: KadInserts::Manual,
..Default::default()
},
})),
Default::default(),
)
.set_pubsub_configuration(PubsubConfig {
.with_ping(None)
.with_pubsub(Some(PubsubConfig {
max_transmit_size: config.ipfs_setting.pubsub.max_transmit_size,
..Default::default()
});
}))
.with_relay(true)
.set_listening_addrs(config.listen_on.clone())
.with_custom_behaviour(behaviour)
.set_keypair(keypair)
.with_rendezvous_client()
.set_transport_configuration(TransportConfig {
yamux_update_mode: UpdateMode::Read,
..Default::default()
})
.listen_as_external_addr()
.set_swarm_configuration(swarm_configuration);

if let Some(path) = self.config.path.as_ref() {
info!("Instance will be persistent");
Expand All @@ -331,7 +334,7 @@ impl WarpIpfs {
}

if config.ipfs_setting.memory_transport {
uninitialized = uninitialized.set_custom_transport(Box::new(
uninitialized = uninitialized.with_custom_transport(Box::new(
|keypair, relay| -> std::io::Result<Boxed<(PeerId, StreamMuxerBox)>> {
let noise_config = rust_ipfs::libp2p::noise::Config::new(keypair)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
Expand All @@ -357,11 +360,11 @@ impl WarpIpfs {
}

if config.ipfs_setting.portmapping {
uninitialized = uninitialized.enable_upnp();
uninitialized = uninitialized.with_upnp();
}

if config.ipfs_setting.mdns.enable {
uninitialized = uninitialized.enable_mdns();
uninitialized = uninitialized.with_mdns();
}

let ipfs = uninitialized.start().await?;
Expand Down
34 changes: 33 additions & 1 deletion extensions/warp-ipfs/src/store/document/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use futures::{
use libipld::Cid;
use rust_ipfs::{Ipfs, IpfsPath};
use uuid::Uuid;
use warp::{crypto::DID, error::Error};
use warp::{crypto::DID, error::Error, multipass::identity::IdentityStatus};

use crate::store::{ecdh_encrypt, identity::Request, keystore::Keystore, VecExt};

Expand All @@ -29,6 +29,10 @@ pub enum RootDocumentCommand {
Identity {
response: oneshot::Sender<Result<IdentityDocument, Error>>,
},
SetIdentityStatus {
status: IdentityStatus,
response: oneshot::Sender<Result<(), Error>>,
},
AddFriend {
did: DID,
response: oneshot::Sender<Result<(), Error>>,
Expand Down Expand Up @@ -170,6 +174,19 @@ impl RootDocumentMap {
rx.await.map_err(anyhow::Error::from)?
}

pub async fn set_status_indicator(&self, status: IdentityStatus) -> Result<(), Error> {
let (tx, rx) = oneshot::channel();
let _ = self
.tx
.clone()
.send(RootDocumentCommand::SetIdentityStatus {
status,
response: tx,
})
.await;
rx.await.map_err(anyhow::Error::from)?
}

pub async fn add_friend(&self, did: &DID) -> Result<(), Error> {
let (tx, rx) = oneshot::channel();
let _ = self
Expand Down Expand Up @@ -443,6 +460,9 @@ impl RootDocumentTask {
RootDocumentCommand::ExportEncrypted { response } => {
let _ = response.send(self.export_bytes().await);
}
RootDocumentCommand::SetIdentityStatus { status, response } => {
let _ = response.send(self.set_identity_status(status).await);
}
}
}
}
Expand Down Expand Up @@ -502,6 +522,18 @@ impl RootDocumentTask {
Ok(())
}

async fn set_identity_status(&mut self, status: IdentityStatus) -> Result<(), Error> {
let mut root = self.get_root_document().await?;
let mut identity = self.identity().await?;
root.status = Some(status);
identity.status = Some(status);

let identity = identity.sign(&self.keypair)?;
root.identity = identity.to_cid(&self.ipfs).await?;

self.set_root_document(root).await
}

async fn request_list(&self) -> Result<Vec<Request>, Error> {
let cid = match self.cid {
Some(cid) => cid,
Expand Down
30 changes: 6 additions & 24 deletions extensions/warp-ipfs/src/store/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use super::{
cache::IdentityCache, identity::IdentityDocument, image_dag::get_image,
root::RootDocumentMap, utils::GetLocalDag, ExtractedRootDocument, RootDocument, ToCid,
},
ecdh_decrypt, ecdh_encrypt, libp2p_pub_to_did,
ecdh_decrypt, ecdh_encrypt,
phonebook::PhoneBook,
queue::Queue,
};
Expand Down Expand Up @@ -1841,9 +1841,7 @@ impl IdentityStore {

#[tracing::instrument(skip(self))]
pub async fn set_identity_status(&mut self, status: IdentityStatus) -> Result<(), Error> {
let mut root_document = self.root_document.get().await?;
root_document.status = Some(status);
self.root_document.set(root_document).await?;
self.root_document.set_status_indicator(status).await?;
*self.online_status.write().await = Some(status);
self.push_to_all().await;
Ok(())
Expand Down Expand Up @@ -1905,31 +1903,15 @@ impl IdentityStore {
}

pub async fn own_identity_document(&self) -> Result<IdentityDocument, Error> {
let root_document = self.root_document.get().await?;
let path = IpfsPath::from(root_document.identity);
let identity: IdentityDocument = path.get_local_dag(&self.ipfs).await?;
let identity = self.root_document.identity().await?;
identity.verify()?;
Ok(identity)
}

pub async fn own_identity(&self) -> Result<Identity, Error> {
let root_document = self.root_document.get().await?;

let path = IpfsPath::from(root_document.identity);
let identity = self
.get_local_dag::<IdentityDocument>(path)
.await?
.resolve()?;

let public_key = identity.did_key();
let kp_public_key = libp2p_pub_to_did(&self.get_keypair()?.public())?;
if public_key != kp_public_key {
//Note if we reach this point, the identity would need to be reconstructed
return Err(Error::IdentityDoesntExist);
}

*self.online_status.write().await = root_document.status;
Ok(identity)
let identity = self.own_identity_document().await?;
*self.online_status.write().await = identity.status;
Ok(identity.into())
}

#[tracing::instrument(skip(self))]
Expand Down
12 changes: 6 additions & 6 deletions extensions/warp-ipfs/src/store/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1642,9 +1642,9 @@ impl MessageStore {
}

//Temporary limit
if self.list_conversations().await.unwrap_or_default().len() >= 32 {
return Err(Error::ConversationLimitReached);
}
// if self.list_conversations().await.unwrap_or_default().len() >= 256 {
// return Err(Error::ConversationLimitReached);
// }

if !self.discovery.contains(did_key).await {
self.discovery.insert(did_key).await?;
Expand Down Expand Up @@ -1753,9 +1753,9 @@ impl MessageStore {
}

//Temporary limit
if self.list_conversations().await.unwrap_or_default().len() >= 32 {
return Err(Error::ConversationLimitReached);
}
// if self.list_conversations().await.unwrap_or_default().len() >= 256 {
// return Err(Error::ConversationLimitReached);
// }

for recipient in &recipients {
if !self.discovery.contains(recipient).await {
Expand Down

0 comments on commit 79f7987

Please sign in to comment.