|
|
@@ -11,7 +11,12 @@ use hbb_common::{
|
|
11
|
11
|
rendezvous_proto::*,
|
|
12
|
12
|
tcp::{new_listener, FramedStream},
|
|
13
|
13
|
timeout,
|
|
14
|
|
- tokio::{self, net::TcpStream, sync::mpsc},
|
|
|
14
|
+ tokio::{
|
|
|
15
|
+ self,
|
|
|
16
|
+ net::TcpStream,
|
|
|
17
|
+ sync::mpsc,
|
|
|
18
|
+ time::{interval, Duration},
|
|
|
19
|
+ },
|
|
15
|
20
|
tokio_util::codec::Framed,
|
|
16
|
21
|
udp::FramedSocket,
|
|
17
|
22
|
AddrMangle, ResultType,
|
|
|
@@ -61,6 +66,8 @@ struct PeerMap {
|
|
61
|
66
|
db: super::SledAsync,
|
|
62
|
67
|
}
|
|
63
|
68
|
|
|
|
69
|
+pub const DEFAULT_PORT: &'static str = "21116";
|
|
|
70
|
+
|
|
64
|
71
|
impl PeerMap {
|
|
65
|
72
|
fn new() -> ResultType<Self> {
|
|
66
|
73
|
Ok(Self {
|
|
|
@@ -135,6 +142,7 @@ pub struct RendezvousServer {
|
|
135
|
142
|
}
|
|
136
|
143
|
|
|
137
|
144
|
impl RendezvousServer {
|
|
|
145
|
+ #[tokio::main(basic_scheduler)]
|
|
138
|
146
|
pub async fn start(
|
|
139
|
147
|
addr: &str,
|
|
140
|
148
|
addr2: &str,
|
|
|
@@ -142,6 +150,7 @@ impl RendezvousServer {
|
|
142
|
150
|
serial: i32,
|
|
143
|
151
|
rendezvous_servers: Vec<String>,
|
|
144
|
152
|
software_url: String,
|
|
|
153
|
+ stop: Arc<Mutex<bool>>,
|
|
145
|
154
|
) -> ResultType<()> {
|
|
146
|
155
|
let mut socket = FramedSocket::new(addr).await?;
|
|
147
|
156
|
let (tx, mut rx) = mpsc::unbounded_channel::<(RendezvousMessage, SocketAddr)>();
|
|
|
@@ -161,8 +170,15 @@ impl RendezvousServer {
|
|
161
|
170
|
};
|
|
162
|
171
|
let mut listener = new_listener(addr, false).await?;
|
|
163
|
172
|
let mut listener2 = new_listener(addr2, false).await?;
|
|
|
173
|
+ let mut timer = interval(Duration::from_millis(300));
|
|
164
|
174
|
loop {
|
|
165
|
175
|
tokio::select! {
|
|
|
176
|
+ _ = timer.tick() => {
|
|
|
177
|
+ if *stop.lock().unwrap() {
|
|
|
178
|
+ log::info!("Stopped");
|
|
|
179
|
+ break;
|
|
|
180
|
+ }
|
|
|
181
|
+ }
|
|
166
|
182
|
Some((msg, addr)) = rx.recv() => {
|
|
167
|
183
|
allow_err!(socket.send(&msg, addr).await);
|
|
168
|
184
|
}
|
|
|
@@ -274,6 +290,7 @@ impl RendezvousServer {
|
|
274
|
290
|
}
|
|
275
|
291
|
}
|
|
276
|
292
|
}
|
|
|
293
|
+ Ok(())
|
|
277
|
294
|
}
|
|
278
|
295
|
|
|
279
|
296
|
#[inline]
|