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 11, 2016
1 parent 65edc7e commit 9a846ab
Showing 1 changed file with 9 additions and 28 deletions.
37 changes: 9 additions & 28 deletions src/simple_udp_hole_punch_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use socket_addr::SocketAddr;
use listener_message::{ListenerRequest, ListenerResponse};

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 @@ -44,7 +43,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 @@ -99,11 +98,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 @@ -117,10 +122,6 @@ impl<'a> SimpleUdpHolePunchServer<'a> {
SimpleUdpHolePunchServer::handle_request(msg,
&udp_socket,
peer_addr);
} else if let Ok(msg) = deserialise::<ListenerResponse>(&read_buf[..bytes_read]) {
SimpleUdpHolePunchServer::handle_response(msg,
&udp_socket,
peer_addr);
}
}
}
Expand All @@ -140,28 +141,8 @@ impl<'a> SimpleUdpHolePunchServer<'a> {
}
}

fn handle_response(_msg: ListenerResponse,
_udp_socket: &UdpSocket,
_peer_addr: net::SocketAddr) {
// This is currently unimplemented as SimpleUdpHolePunchServer should not have made
// any request - it is supposed to get requests, not make one
match _msg {
ListenerResponse::EchoExternalAddr { .. } => unimplemented!(),
}
}

/// 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 9a846ab

Please sign in to comment.