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
81
82
83
84
85
86
use log::{info,warn};
use ra_common::models::{Packet, Service, Envelope};
use i2p::sam::{SamConnection, Session, SessionStyle, DEFAULT_API, StreamConnect};
pub enum ClientType {
Local = 0,
Embedded = 1,
}
pub struct I2PClient {
}
impl I2PClient {
pub fn new() -> I2PClient {
I2PClient {}
}
pub fn init(&mut self) {
info!("{}","Initializing I2P Client...");
match SamConnection::connect(DEFAULT_API) {
Ok(mut conn) => {
match conn.naming_lookup("ME") {
Ok(local_dest) => info!("local: {}",local_dest),
Err(e) => warn!("Error: {}",e.to_string())
}
},
Err(e) => warn!("Error: {}",e.to_string())
}
info!("{}","I2P Client initialized.");
}
pub fn handle(&mut self, packet: &mut Packet) {
info!("Handling incoming packet id={}",packet.id);
}
pub fn send(&mut self, env: Envelope) {
match SamConnection::connect(DEFAULT_API) {
Ok(mut conn) => {
let dest = conn.naming_lookup("1m5.i2p").unwrap();
info!("dest: {}",dest);
},
Err(e) => {
warn!("Error: {}",e.to_string());
}
}
match Session::create(DEFAULT_API,
"1m5.i2p",
"1m5",
SessionStyle::Datagram) {
Ok(session) => {
info!("IP: {}",session.sam_api().unwrap().ip().to_string())
},
Err(err) => {
warn!("Error: {}",err.to_string());
}
}
}
}
impl Service for I2PClient {
fn operate(&mut self, operation: u8, env: Envelope) {
unimplemented!()
}
}
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}