static void natPulse( tr_shared * s, bool do_check ) { const tr_port private_peer_port = s->session->private_peer_port; const int is_enabled = s->isEnabled && !s->isShuttingDown; tr_port public_peer_port; int oldStatus; int newStatus; if( s->natpmp == NULL ) s->natpmp = tr_natpmpInit( ); if( s->upnp == NULL ) s->upnp = tr_upnpInit( ); oldStatus = tr_sharedTraversalStatus( s ); s->natpmpStatus = tr_natpmpPulse( s->natpmp, private_peer_port, is_enabled, &public_peer_port ); if( s->natpmpStatus == TR_PORT_MAPPED ) s->session->public_peer_port = public_peer_port; s->upnpStatus = tr_upnpPulse( s->upnp, private_peer_port, is_enabled, do_check ); newStatus = tr_sharedTraversalStatus( s ); if( newStatus != oldStatus ) tr_ninf( getKey( ), _( "State changed from \"%1$s\" to \"%2$s\"" ), getNatStateStr( oldStatus ), getNatStateStr( newStatus ) ); }
static void set_evtimer_from_status( tr_shared * s ) { int sec=0, msec=0; /* when to wake up again */ switch( tr_sharedTraversalStatus( s ) ) { case TR_PORT_MAPPED: /* if we're mapped, everything is fine... check back in 20 minutes * to renew the port forwarding if it's expired */ s->doPortCheck = TRUE; sec = 60 * 20; break; case TR_PORT_ERROR: /* some kind of an error. wait 60 seconds and retry */ sec = 60; break; default: /* in progress. pulse frequently. */ msec = 333000; break; } if( s->timer != NULL ) tr_timerAdd( s->timer, sec, msec ); }
tr_port_forwarding tr_sessionGetPortForwarding( const tr_session * session ) { assert( tr_isSession( session ) ); return tr_sharedTraversalStatus( session->shared ); }
static void natPulse( tr_shared * s, tr_bool doPortCheck ) { const tr_port port = s->session->peerPort; const int isEnabled = s->isEnabled && !s->isShuttingDown; int oldStatus; int newStatus; if( s->natpmp == NULL ) s->natpmp = tr_natpmpInit( ); if( s->upnp == NULL ) s->upnp = tr_upnpInit( ); oldStatus = tr_sharedTraversalStatus( s ); s->natpmpStatus = tr_natpmpPulse( s->natpmp, port, isEnabled ); s->upnpStatus = tr_upnpPulse( s->upnp, port, isEnabled, doPortCheck ); newStatus = tr_sharedTraversalStatus( s ); if( newStatus != oldStatus ) tr_ninf( getKey( ), _( "State changed from \"%1$s\" to \"%2$s\"" ), getNatStateStr( oldStatus ), getNatStateStr( newStatus ) ); }