Skip to content
This repository has been archived by the owner on Jan 6, 2020. It is now read-only.

Commit

Permalink
SimpleUdpHolePunchServer cleanup
Browse files Browse the repository at this point in the history
Server only returns non-nat-restricted addresses.
Server doesn't try to decode ListenerResponse messages.
  • Loading branch information
canndrew committed Feb 15, 2016
1 parent a6d83c2 commit 1bbd6cb
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/simple_udp_hole_punch_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use socket_addr::SocketAddr;
use listener_message;

use mapping_context::MappingContext;
use mapped_socket_addr::MappedSocketAddr;
use mapped_udp_socket::{MappedUdpSocket, MappedUdpSocketNewError, MappedUdpSocketMapWarning};

const UDP_READ_TIMEOUT_SECS: u64 = 2;
Expand All @@ -43,7 +42,7 @@ pub struct SimpleUdpHolePunchServer<'a> {
_mapping_context: &'a MappingContext,
stop_flag: Arc<AtomicBool>,
_raii_joiner: RaiiThreadJoiner,
known_endpoints: Vec<MappedSocketAddr>,
known_endpoints: Vec<SocketAddr>,
}

quick_error! {
Expand Down Expand Up @@ -98,11 +97,17 @@ impl<'a> SimpleUdpHolePunchServer<'a> {
Self::run(udp_socket, cloned_stop_flag);
}));

let unrestricted_endpoints = mapped_socket.endpoints.into_iter().filter_map(|msa| {
match msa.nat_restricted {
false => Some(msa.addr),
true => None,
}
}).collect();
WOk(SimpleUdpHolePunchServer {
_mapping_context: mapping_context,
stop_flag: stop_flag,
_raii_joiner: raii_joiner,
known_endpoints: mapped_socket.endpoints,
known_endpoints: unrestricted_endpoints,
}, warnings)
}

Expand All @@ -127,17 +132,7 @@ impl<'a> SimpleUdpHolePunchServer<'a> {
}

/// Get the external addresses of this server to be shared with peers.
pub fn addresses(&self) -> Vec<MappedSocketAddr> {
// TODO:

// The idea was it would need to know it's own external IP and whether
// it has an open port or not. And it might occasionally need to make
// sure its port is still mapped. ie still open on the router

// So it wants to find external ports with `nat_restricted ==
// false`. Those are the only ones worth sharing with other peers. it
// can get those by doing upnp for example

pub fn addresses(&self) -> Vec<SocketAddr> {
self.known_endpoints.clone()
}
}
Expand Down

0 comments on commit 1bbd6cb

Please sign in to comment.