@ -384,9 +384,43 @@ static void register_with_new_peer(n2n_edge_t * eee,
HASH_COUNT ( eee - > pending_peers ) ) ;
HASH_COUNT ( eee - > pending_peers ) ) ;
/* trace Sending REGISTER */
/* trace Sending REGISTER */
send_register ( eee , & ( scan - > sock ) , mac ) ;
if ( from_supernode ) {
if ( from_supernode ) {
/* UDP NAT hole punching through supernode. Send to peer first(punch local UDP hole)
* and then ask supernode to forward . Supernode then ask peer to ack . Some nat device
* drop and block ports with incoming UDP packet if out - come traffic does not exist .
* So we can alternatively set TTL so that the packet sent to peer never really reaches
* The register_ttl is basically nat level + 1. Set it to 1 means host like DMZ .
*/
if ( eee - > conf . register_ttl = = 1 ) {
/* We are DMZ host or port is directly accessible. Just let peer to send back the ack */
# ifndef WIN32
} else if ( eee - > conf . register_ttl > 1 ) {
/* Setting register_ttl usually implies that the edge knows the internal net topology
* clearly , we can apply aggressive port prediction to support incoming Symmetric NAT
*/
int curTTL = 0 ;
socklen_t lenTTL = sizeof ( int ) ;
n2n_sock_t sock = scan - > sock ;
int alter = 16 ; /* TODO: set by command line or more reliable prediction method */
getsockopt ( eee - > udp_sock , IPPROTO_IP , IP_TTL , ( void * ) ( char * ) & curTTL , & lenTTL ) ;
setsockopt ( eee - > udp_sock , IPPROTO_IP , IP_TTL ,
( void * ) ( char * ) & eee - > conf . register_ttl ,
sizeof ( eee - > conf . register_ttl ) ) ;
for ( ; alter > 0 ; alter - - , sock . port + + )
{
send_register ( eee , & sock , mac ) ;
}
setsockopt ( eee - > udp_sock , IPPROTO_IP , IP_TTL , ( void * ) ( char * ) & curTTL , sizeof ( curTTL ) ) ;
# endif
} else { /* eee->conf.register_ttl <= 0 */
/* Normal STUN */
send_register ( eee , & ( scan - > sock ) , mac ) ;
}
send_register ( eee , & ( eee - > supernode ) , mac ) ;
send_register ( eee , & ( eee - > supernode ) , mac ) ;
} else {
/* P2P register, send directly */
send_register ( eee , & ( scan - > sock ) , mac ) ;
}
}
register_with_local_peers ( eee ) ;
register_with_local_peers ( eee ) ;
@ -1461,6 +1495,16 @@ static void readFromIPSocket(n2n_edge_t * eee, int in_sock) {
if ( is_valid_peer_sock ( & pkt . sock ) )
if ( is_valid_peer_sock ( & pkt . sock ) )
orig_sender = & ( pkt . sock ) ;
orig_sender = & ( pkt . sock ) ;
if ( ! from_supernode ) {
/* This is a P2P packet from the peer. We purge a pending
* registration towards the possibly nat - ted peer address as we now have
* a valid channel . We still use check_peer_registration_needed in
* handle_PACKET to double check this .
*/
traceEvent ( TRACE_DEBUG , " Got P2P packet " ) ;
find_and_remove_peer ( & eee - > pending_peers , pkt . srcMac ) ;
}
traceEvent ( TRACE_INFO , " Rx PACKET from %s (sender=%s) [%u B] " ,
traceEvent ( TRACE_INFO , " Rx PACKET from %s (sender=%s) [%u B] " ,
sock_to_cstr ( sockbuf1 , & sender ) ,
sock_to_cstr ( sockbuf1 , & sender ) ,
sock_to_cstr ( sockbuf2 , orig_sender ) ,
sock_to_cstr ( sockbuf2 , orig_sender ) ,