open-trade 4 years ago
parent
commit
2b41f7e96b
2 changed files with 20 additions and 6 deletions
  1. 7 5
      mod.rs
  2. 13 1
      src/rendezvous_server.rs

+ 7 - 5
mod.rs

@@ -12,7 +12,7 @@ fn is_running() -> bool {
12
     !*STOP.lock().unwrap()
12
     !*STOP.lock().unwrap()
13
 }
13
 }
14
 
14
 
15
-pub fn start() {
15
+pub fn start(license: &str, host: &str) {
16
     if is_running() {
16
     if is_running() {
17
         return;
17
         return;
18
     }
18
     }
@@ -20,7 +20,8 @@ pub fn start() {
20
     let port = rendezvous_server::DEFAULT_PORT;
20
     let port = rendezvous_server::DEFAULT_PORT;
21
     let addr = format!("0.0.0.0:{}", port);
21
     let addr = format!("0.0.0.0:{}", port);
22
     let addr2 = format!("0.0.0.0:{}", port.parse::<i32>().unwrap_or(0) - 1);
22
     let addr2 = format!("0.0.0.0:{}", port.parse::<i32>().unwrap_or(0) - 1);
23
-    let relay_servers: Vec<String> = Default::default();
23
+    let relay_servers: Vec<String> = vec![format!("{}:{}", host, relay_server::DEFAULT_PORT)];
24
+    let tmp_license = license.to_owned();
24
     std::thread::spawn(move || {
25
     std::thread::spawn(move || {
25
         allow_err!(rendezvous_server::RendezvousServer::start(
26
         allow_err!(rendezvous_server::RendezvousServer::start(
26
             &addr,
27
             &addr,
@@ -29,14 +30,15 @@ pub fn start() {
29
             0,
30
             0,
30
             Default::default(),
31
             Default::default(),
31
             Default::default(),
32
             Default::default(),
32
-            "",
33
+            &tmp_license,
33
             STOP.clone(),
34
             STOP.clone(),
34
         ));
35
         ));
35
     });
36
     });
36
-    std::thread::spawn(|| {
37
+    let tmp_license = license.to_owned();
38
+    std::thread::spawn(move || {
37
         allow_err!(relay_server::start(
39
         allow_err!(relay_server::start(
38
             relay_server::DEFAULT_PORT,
40
             relay_server::DEFAULT_PORT,
39
-            "",
41
+            &tmp_license,
40
             STOP.clone()
42
             STOP.clone()
41
         ));
43
         ));
42
     });
44
     });

+ 13 - 1
src/rendezvous_server.rs

@@ -2,6 +2,7 @@ use hbb_common::{
2
     allow_err,
2
     allow_err,
3
     bytes::{Bytes, BytesMut},
3
     bytes::{Bytes, BytesMut},
4
     bytes_codec::BytesCodec,
4
     bytes_codec::BytesCodec,
5
+    config,
5
     futures_util::{
6
     futures_util::{
6
         sink::SinkExt,
7
         sink::SinkExt,
7
         stream::{SplitSink, StreamExt},
8
         stream::{SplitSink, StreamExt},
@@ -70,9 +71,20 @@ pub const DEFAULT_PORT: &'static str = "21116";
70
 
71
 
71
 impl PeerMap {
72
 impl PeerMap {
72
     fn new() -> ResultType<Self> {
73
     fn new() -> ResultType<Self> {
74
+        let mut db: String = "hbbs.db".to_owned();
75
+        #[cfg(windows)]
76
+        {
77
+            if let Some(path) = config::Config::icon_path().parent() {
78
+                db = format!("{}\\{}", path.to_str().unwrap_or("."), db);
79
+            }
80
+        }
81
+        #[cfg(not(windows))]
82
+        {
83
+            db = format!("./{}", db);
84
+        }
73
         Ok(Self {
85
         Ok(Self {
74
             map: Default::default(),
86
             map: Default::default(),
75
-            db: super::SledAsync::new("./hbbs.db", true)?,
87
+            db: super::SledAsync::new(&db, true)?,
76
         })
88
         })
77
     }
89
     }
78
 
90