Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Merge Identity and Friend modules, misc #335

Merged
merged 27 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
08d04a6
refactor: Move logic outside task and change Config
dariusc93 Oct 4, 2023
0891dce
refactor: Merge friend module into identity
dariusc93 Oct 7, 2023
27b566e
chore: cleanup linting
dariusc93 Oct 7, 2023
6c5cc59
chore: Cleanup
dariusc93 Oct 7, 2023
c3e7984
chore: Formatted code
dariusc93 Oct 7, 2023
6707cc1
chore: Make select branches biased
dariusc93 Oct 8, 2023
88f53f0
chore: Reduce spawned tasks
dariusc93 Oct 8, 2023
f6f8f42
chore: Select peer for the initial provider
dariusc93 Oct 8, 2023
ef8f464
Merge branch 'main' into refactor/config
dariusc93 Oct 8, 2023
bbcacf6
chore: Validate username, status and short id
dariusc93 Oct 8, 2023
87ba960
chore: Remove spawned task when checking document cache
dariusc93 Oct 8, 2023
e0fe289
chore: Remove unused arguments
dariusc93 Oct 9, 2023
4d707eb
chore: Use and_then instead
dariusc93 Oct 9, 2023
47cd328
chore: Simplify logic when resolving root document
dariusc93 Oct 9, 2023
6081bda
chore: Added logging and simplify logic
dariusc93 Oct 10, 2023
02c149c
chore: Minor cleanup
dariusc93 Oct 10, 2023
89038e3
chore: Add test
dariusc93 Oct 11, 2023
e026b96
chore: Cleanup
dariusc93 Oct 11, 2023
86cd727
add: Implement IdentityCache
dariusc93 Oct 11, 2023
cb2713b
chore: Change and properly respond; load cid from file
dariusc93 Oct 11, 2023
331f790
chore: Switch to using IdentityCache
dariusc93 Oct 11, 2023
9cdcc5b
chore: Cleanup
dariusc93 Oct 11, 2023
0e01f7d
add: Added RootDocumentMap
dariusc93 Oct 11, 2023
47ee2fd
chore: Switch to using RootDocumentMap
dariusc93 Oct 11, 2023
aa57f19
chore: Remove redundant fields and methods
dariusc93 Oct 11, 2023
c6eb7f1
chore: Return default for list function
dariusc93 Oct 11, 2023
95271ae
chore: Remove redundant calls
dariusc93 Oct 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading