Browse Source

this way can not get right extern ip

open-trade 4 years ago
parent
commit
d039bed577
1 changed files with 2 additions and 19 deletions
  1. 2 19
      src/rendezvous_server.rs

+ 2 - 19
src/rendezvous_server.rs

@@ -66,10 +66,6 @@ struct PeerMap {
66
     db: super::SledAsync,
66
     db: super::SledAsync,
67
 }
67
 }
68
 
68
 
69
-lazy_static::lazy_static! {
70
-    static ref PUBLIC_IP: Arc<RwLock<String>> = Default::default();
71
-}
72
-
73
 pub const DEFAULT_PORT: &'static str = "21116";
69
 pub const DEFAULT_PORT: &'static str = "21116";
74
 
70
 
75
 impl PeerMap {
71
 impl PeerMap {
@@ -223,12 +219,6 @@ impl RendezvousServer {
223
                 }
219
                 }
224
                 Ok((stream, addr)) = listener.accept() => {
220
                 Ok((stream, addr)) = listener.accept() => {
225
                     log::debug!("Tcp connection from {:?}", addr);
221
                     log::debug!("Tcp connection from {:?}", addr);
226
-                    if let Ok(local_addr) = stream.local_addr() {
227
-                        if PUBLIC_IP.write().unwrap().is_empty() {
228
-                            log::info!("Public ip is {}", local_addr.ip().to_string());
229
-                        }
230
-                        *PUBLIC_IP.write().unwrap() = local_addr.ip().to_string();
231
-                    }
232
                     let (a, mut b) = Framed::new(stream, BytesCodec::new()).split();
222
                     let (a, mut b) = Framed::new(stream, BytesCodec::new()).split();
233
                     let tcp_punch = rs.tcp_punch.clone();
223
                     let tcp_punch = rs.tcp_punch.clone();
234
                     let mut rs = rs.clone();
224
                     let mut rs = rs.clone();
@@ -604,7 +594,7 @@ impl RendezvousServer {
604
                 };
594
                 };
605
                 msg_out.set_fetch_local_addr(FetchLocalAddr {
595
                 msg_out.set_fetch_local_addr(FetchLocalAddr {
606
                     socket_addr,
596
                     socket_addr,
607
-                    relay_server: check_relay_server(&self.relay_servers[i]),
597
+                    relay_server: self.relay_servers[i].clone(),
608
                     ..Default::default()
598
                     ..Default::default()
609
                 });
599
                 });
610
             } else {
600
             } else {
@@ -621,7 +611,7 @@ impl RendezvousServer {
621
                 msg_out.set_punch_hole(PunchHole {
611
                 msg_out.set_punch_hole(PunchHole {
622
                     socket_addr,
612
                     socket_addr,
623
                     nat_type: ph.nat_type,
613
                     nat_type: ph.nat_type,
624
-                    relay_server: check_relay_server(&self.relay_servers[i]),
614
+                    relay_server: self.relay_servers[i].clone(),
625
                     ..Default::default()
615
                     ..Default::default()
626
                 });
616
                 });
627
             }
617
             }
@@ -709,10 +699,3 @@ pub fn test_if_valid_server(host: &str, name: &str) -> ResultType<SocketAddr> {
709
     }
699
     }
710
     res
700
     res
711
 }
701
 }
712
-
713
-fn check_relay_server(addr: &str) -> String {
714
-    if addr.contains("0.0.0.0") {
715
-        return addr.replace("0.0.0.0", &PUBLIC_IP.read().unwrap());
716
-    }
717
-    addr.to_owned()
718
-}