mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-09 14:48:08 -05:00
bin/taud: add crdt module
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -5983,6 +5983,7 @@ dependencies = [
|
||||
"chrono",
|
||||
"clap 3.1.6",
|
||||
"darkfi",
|
||||
"easy-parallel",
|
||||
"futures",
|
||||
"log",
|
||||
"num_cpus",
|
||||
|
||||
@@ -5,7 +5,7 @@ edition = "2021"
|
||||
|
||||
[dependencies.darkfi]
|
||||
path = "../../"
|
||||
features = ["rpc"]
|
||||
features = ["rpc", "net"]
|
||||
|
||||
[dependencies]
|
||||
# Async
|
||||
@@ -15,6 +15,7 @@ async-std = {version = "1.11.0", features = ["attributes"]}
|
||||
async-trait = "0.1.52"
|
||||
async-channel = "1.6.1"
|
||||
async-executor = "1.4.1"
|
||||
easy-parallel = "3.2.0"
|
||||
|
||||
# Misc
|
||||
clap = {version = "3.1.6", features = ["derive"]}
|
||||
|
||||
@@ -6,7 +6,7 @@ use log::debug;
|
||||
|
||||
use darkfi::{net, Result};
|
||||
|
||||
use crate::{Event, GSet};
|
||||
use super::{Event, GSet};
|
||||
|
||||
pub struct ProtocolCrdt {
|
||||
jobsman: net::ProtocolJobsManagerPtr,
|
||||
@@ -43,7 +43,7 @@ impl ProtocolCrdt {
|
||||
let event = self.event_sub.receive().await?;
|
||||
|
||||
debug!(
|
||||
target: "ircd",
|
||||
target: "crdt",
|
||||
"ProtocolCrdt::handle_receive_event() received {:?}",
|
||||
event
|
||||
);
|
||||
@@ -6,7 +6,7 @@ use log::debug;
|
||||
|
||||
use darkfi::{net, util::serial::Encodable, Result};
|
||||
|
||||
use crate::{Event, GSet, ProtocolCrdt};
|
||||
use super::{Event, GSet, ProtocolCrdt};
|
||||
|
||||
pub struct Node {
|
||||
// name to idnetifie the node
|
||||
@@ -20,6 +20,7 @@ use darkfi::{
|
||||
Error, Result,
|
||||
};
|
||||
|
||||
mod crdt;
|
||||
mod month_tasks;
|
||||
mod task_info;
|
||||
mod util;
|
||||
|
||||
1184
script/research/crdt/Cargo.lock
generated
1184
script/research/crdt/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,33 +0,0 @@
|
||||
[package]
|
||||
name = "crdt"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
||||
[dependencies.darkfi]
|
||||
path = "../../../"
|
||||
features = ["net"]
|
||||
|
||||
[dependencies]
|
||||
serde = {version = "1.0.136", features = ["derive"]}
|
||||
# Async
|
||||
smol = "1.2.5"
|
||||
futures = "0.3.21"
|
||||
async-std = "1.10.0"
|
||||
async-trait = "0.1.52"
|
||||
async-channel = "1.6.1"
|
||||
async-executor = "1.4.1"
|
||||
easy-parallel = "3.2.0"
|
||||
|
||||
# Crypto
|
||||
rand = "0.8.5"
|
||||
|
||||
# Misc
|
||||
clap = "3.1.6"
|
||||
log = "0.4.14"
|
||||
simplelog = "0.11.2"
|
||||
|
||||
|
||||
[workspace]
|
||||
@@ -1,84 +0,0 @@
|
||||
use std::{env, sync::Arc};
|
||||
|
||||
extern crate clap;
|
||||
use async_executor::Executor;
|
||||
use easy_parallel::Parallel;
|
||||
use simplelog::{ColorChoice, TermLogger, TerminalMode};
|
||||
|
||||
use darkfi::{net, util::cli::log_config, Result};
|
||||
|
||||
use crdt::Node;
|
||||
|
||||
async fn start(executor: Arc<Executor<'_>>) -> Result<()> {
|
||||
//
|
||||
// XXX THIS for testing purpose
|
||||
//
|
||||
|
||||
let arg = env::args();
|
||||
let arg = arg.last().unwrap();
|
||||
|
||||
// node 1
|
||||
if arg == "1" {
|
||||
let net_settings = net::Settings {
|
||||
outbound_connections: 5,
|
||||
seeds: vec!["127.0.0.1:9999".parse()?],
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let node1 = Node::new("node1", net_settings).await;
|
||||
|
||||
executor.spawn(node1.clone().start(executor.clone())).detach();
|
||||
|
||||
darkfi::util::sleep(5).await;
|
||||
|
||||
node1.send_event(String::from("hello")).await?;
|
||||
|
||||
loop {}
|
||||
}
|
||||
|
||||
// node 2
|
||||
if arg == "2" {
|
||||
let net_settings = net::Settings {
|
||||
inbound: Some("127.0.0.1:6666".parse()?),
|
||||
external_addr: Some("127.0.0.1:6666".parse()?),
|
||||
seeds: vec!["127.0.0.1:9999".parse()?],
|
||||
..Default::default()
|
||||
};
|
||||
let node2 = Node::new("node2", net_settings).await;
|
||||
|
||||
node2.start(executor.clone()).await?;
|
||||
}
|
||||
|
||||
// seed node
|
||||
if arg == "3" {
|
||||
let net_settings =
|
||||
net::Settings { inbound: Some("127.0.0.1:9999".parse()?), ..Default::default() };
|
||||
|
||||
let node3 = Node::new("node3", net_settings).await;
|
||||
node3.start(executor.clone()).await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let ex = Arc::new(Executor::new());
|
||||
let (signal, shutdown) = async_channel::unbounded::<()>();
|
||||
|
||||
let (lvl, cfg) = log_config(1)?;
|
||||
|
||||
TermLogger::init(lvl, cfg, TerminalMode::Mixed, ColorChoice::Auto)?;
|
||||
|
||||
let ex2 = ex.clone();
|
||||
let (_, result) = Parallel::new()
|
||||
.each(0..4, |_| smol::future::block_on(ex.run(shutdown.recv())))
|
||||
// Run the main future on the current thread.
|
||||
.finish(|| {
|
||||
smol::future::block_on(async move {
|
||||
start(ex2.clone()).await?;
|
||||
drop(signal);
|
||||
Ok::<(), darkfi::Error>(())
|
||||
})
|
||||
});
|
||||
|
||||
result
|
||||
}
|
||||
Reference in New Issue
Block a user