mirror of
https://github.com/vacp2p/de-mls.git
synced 2026-01-07 20:54:09 -05:00
* start building waku for group_chat * replace test * replace test * fix building issue on m2 * continue waku integration * add admin trait * update cfg * update code * replace cli to ws * add docker for each instance * fully working process for joining to the group * update readme * Add Waku and WebSocket actors for message processing and group management - Introduced `WakuActor` for handling message sending and group subscriptions using Waku protocol. - Implemented `Group` actor for managing group creation, member addition/removal, and message processing. - Added `WsActor` for WebSocket communication, enabling user connections and message handling. - Defined message structures for processing and sending messages within the Waku and WebSocket contexts. - Enhanced error handling and logging for message operations. * Refactor Waku and WebSocket integration for improved message handling - Updated `WakuActor` to return a vector of `WakuContentTopic` upon subscription, enhancing group topic management. - Introduced `AppState` struct to centralize application state, including Waku actor reference and content topics. - Refactored main loop to utilize `AppState`, improving message flow between Waku and WebSocket actors. - Enhanced message handling in `WsActor` to support `MessageToPrint`, allowing for structured message sending. - Improved error handling and logging throughout the message processing pipeline. * Refactor Waku message handling and clean up unused code * Refactor and remove unused components from the project - Deleted the `sc_key_store` module and its associated files, streamlining the codebase. - Removed unused Docker and Git configuration files, enhancing project clarity. - Cleaned up `.gitignore` and `.dockerignore` to reflect current project structure. - Updated `Cargo.toml` files to remove references to deleted modules and dependencies. - Refactored Waku and WebSocket actors to improve message handling and group management. - Enhanced error handling and logging throughout the message processing pipeline. - Adjusted frontend input styling for better user experience. * Update CI workflow to use 'main' branch and add support for manual triggers * Enhance Waku integration and documentation - Added instructions for running a test Waku node in the README. - Refactored Waku message handling in `ds_waku.rs` to improve content topic management and error handling. - Updated `Cargo.toml` dependencies for better compatibility and removed unused entries. - Improved error handling in `DeliveryServiceError` for Waku node operations. - Cleaned up CI workflow by commenting out unused test jobs. - Enhanced logging in tests for better traceability of message flows. * Update CI workflow to include Go setup for testing - Added steps to the CI configuration to set up Go version 1.20.x for user tests. - Ensured consistent environment setup across different jobs in the CI pipeline. * Update package versions to 1.0.0 in Cargo.toml files for the main project and 'ds' module * Update README to include note on frontend implementation based on Chatr
133 lines
3.7 KiB
Rust
133 lines
3.7 KiB
Rust
use kameo::{
|
|
actor::pubsub::PubSub,
|
|
message::{Context, Message},
|
|
Actor,
|
|
};
|
|
use log::{error, info};
|
|
use std::{
|
|
sync::{Arc, Mutex},
|
|
time::Duration,
|
|
};
|
|
use tokio::sync::mpsc::channel;
|
|
use waku_bindings::WakuMessage;
|
|
|
|
use ds::{
|
|
ds_waku::{
|
|
build_content_topics, match_content_topic, setup_node_handle, APP_MSG_SUBTOPIC,
|
|
GROUP_VERSION,
|
|
},
|
|
waku_actor::{ProcessMessageToSend, ProcessSubscribeToGroup, WakuActor},
|
|
DeliveryServiceError,
|
|
};
|
|
use waku_bindings::waku_set_event_callback;
|
|
|
|
#[derive(Debug, Clone, Actor)]
|
|
pub struct ActorA {
|
|
pub app_id: String,
|
|
}
|
|
|
|
impl ActorA {
|
|
pub fn new() -> Self {
|
|
let app_id = uuid::Uuid::new_v4().to_string();
|
|
Self { app_id }
|
|
}
|
|
}
|
|
|
|
impl Message<WakuMessage> for ActorA {
|
|
type Reply = Result<WakuMessage, DeliveryServiceError>;
|
|
|
|
async fn handle(
|
|
&mut self,
|
|
msg: WakuMessage,
|
|
_ctx: Context<'_, Self, Self::Reply>,
|
|
) -> Self::Reply {
|
|
println!("ActorA received message: {:?}", msg.timestamp());
|
|
Ok(msg)
|
|
}
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_waku_client() {
|
|
let group_name = "new_group".to_string();
|
|
let mut pubsub = PubSub::<WakuMessage>::new();
|
|
let (sender_alice, mut receiver_alice) = channel(100);
|
|
// TODO: get node from env
|
|
let res = setup_node_handle(vec![]);
|
|
assert!(res.is_ok());
|
|
let node = res.unwrap();
|
|
let uuid = uuid::Uuid::new_v4().as_bytes().to_vec();
|
|
let waku_actor = WakuActor::new(Arc::new(node));
|
|
let actor_ref = kameo::spawn(waku_actor);
|
|
|
|
let actor_a = ActorA::new();
|
|
let actor_a_ref = kameo::spawn(actor_a);
|
|
|
|
pubsub.subscribe(actor_a_ref);
|
|
|
|
let content_topics = Arc::new(Mutex::new(build_content_topics(&group_name, GROUP_VERSION)));
|
|
|
|
assert!(actor_ref
|
|
.ask(ProcessSubscribeToGroup {
|
|
group_name: group_name.clone(),
|
|
})
|
|
.await
|
|
.is_ok());
|
|
|
|
waku_set_event_callback(move |signal| {
|
|
match signal.event() {
|
|
waku_bindings::Event::WakuMessage(event) => {
|
|
let content_topic = event.waku_message().content_topic();
|
|
// Check if message belongs to a relevant topic
|
|
assert!(match_content_topic(&content_topics, content_topic));
|
|
let msg = event.waku_message().clone();
|
|
info!("msg: {:?}", msg.timestamp());
|
|
assert!(sender_alice.blocking_send(msg).is_ok());
|
|
}
|
|
|
|
waku_bindings::Event::Unrecognized(data) => {
|
|
error!("Unrecognized event!\n {data:?}");
|
|
}
|
|
_ => {
|
|
error!(
|
|
"Unrecognized signal!\n {:?}",
|
|
serde_json::to_string(&signal)
|
|
);
|
|
}
|
|
}
|
|
});
|
|
|
|
let sender = tokio::spawn(async move {
|
|
for _ in 0..10 {
|
|
assert!(actor_ref
|
|
.ask(ProcessMessageToSend {
|
|
msg: format!("test_message").as_bytes().to_vec(),
|
|
subtopic: APP_MSG_SUBTOPIC.to_string(),
|
|
group_id: group_name.clone(),
|
|
app_id: uuid.clone(),
|
|
})
|
|
.await
|
|
.is_ok());
|
|
|
|
tokio::time::sleep(Duration::from_secs(1)).await;
|
|
}
|
|
info!("sender handle is finished");
|
|
});
|
|
|
|
let receiver = tokio::spawn(async move {
|
|
while let Some(msg) = receiver_alice.recv().await {
|
|
info!("msg received: {:?}", msg.timestamp());
|
|
pubsub.publish(msg).await;
|
|
}
|
|
info!("receiver handle is finished");
|
|
});
|
|
|
|
tokio::select! {
|
|
x = sender => {
|
|
info!("get from sender: {:?}", x);
|
|
}
|
|
w = receiver => {
|
|
info!("get from receiver: {:?}", w);
|
|
}
|
|
}
|
|
}
|