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
use crate::{relay, Context, Executor, Mailbox, NodeMessage};
use ockam_core::Address;
use std::sync::Arc;
use tokio::runtime::Runtime;
use tokio::sync::mpsc::{channel, Sender};
use tracing_subscriber::{filter::LevelFilter, fmt, EnvFilter};
pub struct NullWorker;
impl NullWorker {
pub(crate) fn new(rt: Arc<Runtime>, addr: &Address, tx: Sender<NodeMessage>) -> Context {
let (mb_tx, mb_rx) = channel(32);
let mb = Mailbox::new(mb_rx, mb_tx.clone());
let ctx = Context::new(rt, tx, addr.into(), mb);
ctx
}
}
impl ockam_core::Worker for NullWorker {
type Context = Context;
type Message = ();
}
pub fn start_node() -> (Context, Executor) {
setup_tracing();
info!("Initializing ockam node");
let mut exe = Executor::new();
let addr = "app".into();
let ctx = NullWorker::new(exe.runtime(), &addr, exe.sender());
let sender = relay::build_root::<NullWorker, _>(exe.runtime(), &ctx.mailbox);
exe.initialize_system("app", sender);
(ctx, exe)
}
fn setup_tracing() {
if let Err(_) = fmt()
.with_env_filter(EnvFilter::try_from_env("OCKAM_LOG").unwrap_or_else(|_| {
EnvFilter::default()
.add_directive(LevelFilter::INFO.into())
.add_directive("ockam_node=info".parse().unwrap())
}))
.try_init()
{
debug!("Failed to initialise tracing_subscriber. Is an instance already running?");
}
}