From 7d20233b5df65fdc4f8608db7054551b2ff2291b Mon Sep 17 00:00:00 2001 From: ghassmo Date: Sat, 26 Mar 2022 15:54:56 +0400 Subject: [PATCH] bin/taud: run crdt node in taud --- bin/taud/src/jsonrpc.rs | 7 ++++++- bin/taud/src/main.rs | 34 +++++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/bin/taud/src/jsonrpc.rs b/bin/taud/src/jsonrpc.rs index 3f69174c3..776aadfea 100644 --- a/bin/taud/src/jsonrpc.rs +++ b/bin/taud/src/jsonrpc.rs @@ -20,7 +20,8 @@ use crate::{ }; pub struct JsonRpcInterface { - pub settings: Settings, + settings: Settings, + notify_queue_sender: async_channel::Sender, } #[async_trait] @@ -47,6 +48,10 @@ impl RequestHandler for JsonRpcInterface { } impl JsonRpcInterface { + pub fn new(notify_queue_sender: async_channel::Sender, settings: Settings) -> Self { + Self { notify_queue_sender, settings } + } + // RPCAPI: // Add new task and returns `true` upon success. // --> {"jsonrpc": "2.0", "method": "add", "params": ["title", "desc", ["assign"], ["project"], "due", "rank"], "id": 1} diff --git a/bin/taud/src/main.rs b/bin/taud/src/main.rs index 031061e4e..06f13e1cf 100644 --- a/bin/taud/src/main.rs +++ b/bin/taud/src/main.rs @@ -5,6 +5,7 @@ use clap::{IntoApp, Parser}; use simplelog::{ColorChoice, TermLogger, TerminalMode}; use darkfi::{ + net::Settings as P2pSettings, rpc::rpcserver::{listen_and_serve, RpcServerConfig}, util::{ cli::{log_config, spawn_config, Config}, @@ -20,9 +21,12 @@ mod month_tasks; mod task_info; mod util; -use jsonrpc::JsonRpcInterface; - -use crate::util::{CliTaud, Settings, TauConfig, CONFIG_FILE_CONTENTS}; +use crate::{ + crdt::Node, + jsonrpc::JsonRpcInterface, + task_info::TaskInfo, + util::{CliTaud, Settings, TauConfig, CONFIG_FILE_CONTENTS}, +}; async fn start(config: TauConfig, executor: Arc>) -> Result<()> { if config.dataset_path.is_empty() { @@ -37,6 +41,21 @@ async fn start(config: TauConfig, executor: Arc>) -> Result<()> { let settings = Settings { dataset_path }; + // + // Crdt + // + + let p2p_settings = P2pSettings::default(); + + let node = Node::new("node", p2p_settings).await; + + let ex2 = executor.clone(); + let node2 = node.clone(); + let crdt_task = executor.spawn(node2.start(ex2.clone())); + + // + // RPC + // let server_config = RpcServerConfig { socket_addr: config.rpc_listener_url.url.parse()?, use_tls: false, @@ -45,9 +64,14 @@ async fn start(config: TauConfig, executor: Arc>) -> Result<()> { identity_pass: Default::default(), }; - let rpc_interface = Arc::new(JsonRpcInterface { settings }); + let (snd, _rcv) = async_channel::unbounded::(); - listen_and_serve(server_config, rpc_interface, executor).await + let rpc_interface = Arc::new(JsonRpcInterface::new(snd, settings)); + + listen_and_serve(server_config, rpc_interface, executor).await?; + + crdt_task.cancel().await; + Ok(()) } #[async_std::main]