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
79
80
use crate::dht::{dht_protocol::*, dht_trait::Dht};
use lib3h_protocol::{Address, DidWork, Lib3hResult};
use std::collections::VecDeque;
use url::Url;
pub struct RrDht {
inbox: VecDeque<DhtCommand>,
this_peer: PeerData,
}
impl RrDht {
pub fn new() -> Self {
RrDht {
inbox: VecDeque::new(),
this_peer: PeerData {
peer_address: "FIXME".to_string(),
peer_uri: Url::parse("fixme://host:123").expect("a valid transport url"),
timestamp: 0,
},
}
}
pub fn new_with_raw_config(_config: &[u8]) -> Lib3hResult<Self> {
Ok(Self::new())
}
}
impl Dht for RrDht {
fn get_peer_list(&self) -> Vec<PeerData> {
vec![]
}
fn get_peer(&self, _peer_address: &str) -> Option<PeerData> {
None
}
fn this_peer(&self) -> &PeerData {
&self.this_peer
}
fn get_entry_address_list(&self) -> Vec<&Address> {
vec![]
}
fn get_aspects_of(&self, _entry_address: &Address) -> Option<Vec<Address>> {
None
}
fn post(&mut self, cmd: DhtCommand) -> Lib3hResult<()> {
self.inbox.push_back(cmd);
Ok(())
}
fn process(&mut self) -> Lib3hResult<(DidWork, Vec<DhtEvent>)> {
let outbox = Vec::new();
let mut did_work = false;
loop {
let cmd = match self.inbox.pop_front() {
None => break,
Some(msg) => msg,
};
did_work = true;
trace!("RrDht.process(): {:?}", cmd)
}
Ok((did_work, outbox))
}
}