/
node.rs
53 lines (43 loc) · 1 KB
/
node.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
use actix::{msgs, Actor, Address, Arbiter, Context, System, Handler, Response, ResponseType};
use connection::Connection;
pub struct Node {
neighbours: Vec<NeighbourData>,
id: Option<Address<Node>>,
}
impl Node {
pub fn new() -> Node {
Node {
neighbours: Vec::new(),
id: None
}
}
}
struct NeighbourData {
connection: Connection,
id: Address<Node>,
}
struct Quality {
latency: f32,
bandwidth: f32,
packet_loss: f32,
}
impl Actor for Node {
type Context = Context<Self>;
fn started(&mut self, _ctx: &mut Self::Context) {
println!("I am alive!");
Arbiter::system().send(msgs::SystemExit(0));
}
}
pub struct InitSelf {
pub id: Address<Node>
}
impl ResponseType for InitSelf {
type Item = ();
type Error = ();
}
impl Handler<InitSelf> for Node {
fn handle(&mut self, msg: InitSelf, _ctx: &mut Context<Self>) -> Response<Node, InitSelf> {
self.id = Some(msg.id);
Self::reply(())
}
}