Skip to content

Commit

Permalink
Merge branch 'main' into chore/dated-documents
Browse files Browse the repository at this point in the history
  • Loading branch information
dariusc93 committed Oct 12, 2023
2 parents 35c8088 + daa51cf commit 39e96f0
Show file tree
Hide file tree
Showing 21 changed files with 2,549 additions and 2,649 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.4.4"
rust-ipfs = "0.5.0"

# Blink related crates
# av-data is needed to use libaom. need to ensure that Warp and libaom use the same version of av-data
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.aarch64-android
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y
# RUN . $HOME/.cargo/env && rustup target add aarch64-unknown-linux-gnu
# RUN . $HOME/.cargo/env && rustup toolchain install stable-aarch64-unknown-linux-gnu
RUN . $HOME/.cargo/env && rustup target add aarch64-linux-android
RUN . $HOME/.cargo/env && cargo install --git https://github.com/tauri-apps/tauri-mobile
RUN . $HOME/.cargo/env && cargo install --git https://github.com/tauri-apps/cargo-mobile2

WORKDIR /root/cmake
RUN wget https://github.com/Kitware/CMake/releases/download/v3.23.1/cmake-3.23.1.tar.gz
Expand Down
67 changes: 4 additions & 63 deletions extensions/warp-ipfs/examples/messenger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ struct Opt {
experimental_node: bool,
#[clap(long)]
stdout_log: bool,
#[clap(long)]
disable_sender_emitter: bool,

#[clap(long)]
context: Option<String>,
Expand Down Expand Up @@ -129,7 +127,6 @@ async fn setup<P: AsRef<Path>>(
}

config.store_setting.friend_request_response_duration = opt.wait.map(Duration::from_millis);
config.store_setting.disable_sender_event_emit = opt.disable_sender_emitter;
config.ipfs_setting.mdns.enable = opt.mdns;

let (mut account, raygun, filesystem) = WarpIpfsBuilder::default()
Expand Down Expand Up @@ -324,36 +321,8 @@ async fn main() -> anyhow::Result<()> {
continue
}
};
// Note: This is one way to handle it outside of the event stream
if opt.disable_sender_emitter {
let id = match chat.create_conversation(&did).await {
Ok(id) => id,
Err(e) => {
writeln!(stdout, "Error creating conversation: {e}")?;
continue
}
};

*topic.write() = id.id();
writeln!(stdout, "Set conversation to {}", topic.read())?;
let mut stdout = stdout.clone();
let account = new_account.clone();
let stream = chat.get_conversation_stream(id.id()).await?;
let chat = chat.clone();
let topic = topic.clone();

tokio::spawn(async move {
if let Err(e) = message_event_handle(
stdout.clone(),
account.clone(),
chat.clone(),
stream,
topic.clone(),
).await {
writeln!(stdout, ">> Error processing event task: {e}").unwrap();
}
});
} else if let Err(e) = chat.create_conversation(&did).await {
if let Err(e) = chat.create_conversation(&did).await {
writeln!(stdout, "Error creating conversation: {e}")?;
continue
}
Expand Down Expand Up @@ -422,37 +391,9 @@ async fn main() -> anyhow::Result<()> {
did_keys.push(did);
}

if opt.disable_sender_emitter {
let id = match chat.create_group_conversation(Some(name.to_string()), did_keys).await {
Ok(id) => id,
Err(e) => {
writeln!(stdout, "Error creating conversation: {e}")?;
continue
}
};

*topic.write() = id.id();
writeln!(stdout, "Set conversation to {}", topic.read())?;
let mut stdout = stdout.clone();
let account = new_account.clone();
let stream = chat.get_conversation_stream(id.id()).await?;
let chat = chat.clone();
let topic = topic.clone();

tokio::spawn(async move {
if let Err(e) = message_event_handle(
stdout.clone(),
account.clone(),
chat.clone(),
stream,
topic.clone(),
).await {
writeln!(stdout, ">> Error processing event task: {e}").unwrap();
}
});
} else if let Err(e) = chat.create_group_conversation(Some(name.to_string()), did_keys).await {
writeln!(stdout, "Error creating conversation: {e}")?;
continue
if let Err(e) = chat.create_group_conversation(Some(name.to_string()), did_keys).await {
writeln!(stdout, "Error creating conversation: {e}")?;
continue
}
},
Some("/remove-conversation") => {
Expand Down
2 changes: 1 addition & 1 deletion extensions/warp-ipfs/src/behaviour/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod phonebook;
pub mod discovery;
pub mod phonebook;

use libp2p::swarm::NetworkBehaviour;
use rust_ipfs::libp2p;
Expand Down
77 changes: 50 additions & 27 deletions extensions/warp-ipfs/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,39 @@ use std::{
};
use warp::multipass::identity::Identity;

#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Network {
/// IPFS Public Network
#[default]
Ipfs,
/// Satellite Network
Satellite { addresses: Vec<NetworkAddress> },
/// Custom Network
Custom { addresses: Vec<NetworkAddress> },
/// No network selection.
None,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct NetworkAddress {
/// Address of the node
pub address: Multiaddr,
/// Type for the network.
/// - DHT
/// - Relay
/// - RzPoint
pub network_type: Vec<NetworkType>,
}

#[derive(Debug, Deserialize, Serialize, Clone, Copy)]
#[serde(rename_all = "snake_case")]
pub enum NetworkType {
DHT,
RzPoint,
Relay,
}

#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Bootstrap {
Expand Down Expand Up @@ -232,19 +265,13 @@ pub struct StoreSetting {
pub auto_push: Option<Duration>,
/// Discovery type
pub discovery: Discovery,
#[serde(skip_serializing_if = "Vec::is_empty")]
/// Placeholder for a offline agents to obtain information regarding one own identity
pub sync: Vec<Multiaddr>,
/// Interval to push or check node
pub sync_interval: Duration,
/// Fetch data over bitswap instead of pubsub
pub fetch_over_bitswap: bool,
/// Enables sharing platform (Desktop, Mobile, Web) information to another user
pub share_platform: bool,
/// Enables phonebook service
pub use_phonebook: bool,
/// Emit event for when a friend comes online or offline
pub emit_online_event: bool,
#[serde(skip_serializing_if = "Option::is_none")]
/// Waits for a response from peer for a specific duration
pub friend_request_response_duration: Option<Duration>,
/// Options to allow emitting identity events to all or just friends
Expand All @@ -253,23 +280,23 @@ pub struct StoreSetting {
pub disable_images: bool,
/// Enables spam check
pub check_spam: bool,

/// Load conversation in a separate task
/// Note: While this is loaded in a separate task, not all conversations will be made available up front.
/// If any conversations are corrupted for whatever reason they will not be made available
pub conversation_load_task: bool,

/// Attaches recipients to the local message block
pub attach_recipients_on_storing: bool,

/// Disables emitting an event on stream for creating a conversation
pub disable_sender_event_emit: bool,

/// Function to call to provide data for a default profile picture if one is not apart of the identity
#[serde(skip)]
pub default_profile_picture: Option<DefaultPfpFn>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum SynchronizeType {
/// Export locally to a file
Local { path: PathBuf },
/// Export remotely to a service
Remote,
/// Export locally and remotely
RemoteLocal { path: PathBuf },
/// Dont export
None,
}

impl std::fmt::Debug for StoreSetting {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("StoreSetting").finish()
Expand All @@ -284,19 +311,13 @@ impl Default for StoreSetting {
namespace: None,
discovery_type: Default::default(),
},
sync: Vec::new(),
sync_interval: Duration::from_millis(1000),
fetch_over_bitswap: false,
share_platform: false,
use_phonebook: true,
friend_request_response_duration: None,
emit_online_event: false,
update_events: Default::default(),
disable_images: false,
check_spam: true,
attach_recipients_on_storing: false,
conversation_load_task: false,
disable_sender_event_emit: false,
with_friends: false,
default_profile_picture: None,
}
Expand All @@ -307,26 +328,28 @@ impl Default for StoreSetting {
pub struct Config {
#[serde(skip_serializing_if = "Option::is_none")]
pub path: Option<PathBuf>,
pub network: Network,
pub bootstrap: Bootstrap,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub listen_on: Vec<Multiaddr>,
pub ipfs_setting: IpfsSetting,
pub store_setting: StoreSetting,
pub enable_relay: bool,
pub debug: bool,
pub save_phrase: bool,
pub max_storage_size: Option<usize>,
pub max_file_size: Option<usize>,
pub thumbnail_size: (u32, u32),
pub chunking: Option<usize>,
pub thumbnail_task: bool,
pub thumbnail_exact_format: bool,
pub synchronize_type: SynchronizeType,
}

impl Default for Config {
fn default() -> Self {
Config {
path: None,
network: Network::Ipfs,
bootstrap: Bootstrap::Ipfs,
listen_on: ["/ip4/0.0.0.0/tcp/0", "/ip6/::/tcp/0"]
.iter()
Expand All @@ -338,7 +361,6 @@ impl Default for Config {
..Default::default()
},
store_setting: Default::default(),
debug: false,
enable_relay: false,
save_phrase: false,
max_storage_size: Some(1024 * 1024 * 1024),
Expand All @@ -347,6 +369,7 @@ impl Default for Config {
chunking: None,
thumbnail_task: false,
thumbnail_exact_format: true,
synchronize_type: SynchronizeType::None,
}
}
}
Expand Down
Loading

0 comments on commit 39e96f0

Please sign in to comment.