-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.rs
78 lines (65 loc) · 2.12 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use std::collections::HashMap;
use std::fs::read_to_string;
use std::net::SocketAddr;
use clap::Parser;
use scupt_net::notifier::Notifier;
use scupt_util::logger::logger_setup;
use scupt_util::node_id::NID;
use scupt_util::res::Res;
use scupt_util::res_of::{res_io, res_parse};
use toml;
use tracing::debug;
use player_conf::PlayerConf;
use sedeve_kit::dtm::action_incoming_factory::ActionIncomingFactory;
use sedeve_kit::dtm::dtm_player::DTMPlayer;
use sedeve_kit::trace::trace_db::TraceDB;
mod player_conf;
/// action definition to Rust code template
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
/// player config path
#[arg(short, long)]
pub conf_path: String,
}
fn player_gut(db_path: String, player_id: NID, player_address: SocketAddr, peers: HashMap<NID, SocketAddr>) -> Res<()> {
let db = TraceDB::new(db_path)?;
let vec = db.read_trace()?;
for (i, s) in vec.iter().enumerate() {
let notifier = Notifier::new();
let n = notifier.clone();
let incoming = ActionIncomingFactory::action_incoming_from_string(s.clone())?;
let f_done = move || {
n.task_notify_all();
};
debug!("DTM player run trace {} {}", i + 1, s);
DTMPlayer::run_trace(
player_id,
player_address.clone(),
peers.clone(),
incoming,
notifier.clone(),
Default::default(),
f_done,
)?;
}
Ok(())
}
fn player_run(conf: String) -> Res<()> {
let s = res_io(read_to_string(conf))?;
let c: PlayerConf = toml::from_str(s.as_str()).unwrap();
let player_addr: SocketAddr = res_parse(c.player_addr.addr.parse())?;
let mut peers = HashMap::new();
logger_setup(c.log_level.as_str());
for addr in c.peer_addr.iter() {
let a: SocketAddr = res_parse(addr.addr.parse())?;
peers.insert(addr.nid.clone(), a);
}
player_gut(c.trace_db_path, c.player_addr.nid, player_addr, peers)?;
Ok(())
}
fn main() {
let args = Args::parse();
let conf_path: String = args.conf_path.clone();
player_run(conf_path).unwrap();
}