diff --git a/network.cpp b/network.cpp index ac9e5cf..05bc0a1 100644 --- a/network.cpp +++ b/network.cpp @@ -94,8 +94,8 @@ Connection::Connection() /* server */ next_seq( 0 ), saved_timestamp( -1 ), RTT_hit( false ), - SRTT( 1 ), - RTTVAR( .5 ) + SRTT( 1000 ), + RTTVAR( 500 ) { setup(); } @@ -112,8 +112,8 @@ Connection::Connection( const char *key_str, const char *ip, int port ) /* clien next_seq( 0 ), saved_timestamp( -1 ), RTT_hit( false ), - SRTT( 1 ), - RTTVAR( .5 ) + SRTT( 1000 ), + RTTVAR( 500 ) { setup(); @@ -204,6 +204,8 @@ string Connection::recv( void ) assert( now >= p.timestamp_reply ); const double R = now - p.timestamp_reply; + fprintf( stderr, "Saw delay of %f\r\n", R ); + if ( !RTT_hit ) { /* first measurement */ SRTT = R; RTTVAR = R / 2; diff --git a/network.hpp b/network.hpp index f59c600..bb14e1b 100644 --- a/network.hpp +++ b/network.hpp @@ -95,6 +95,7 @@ namespace Network { bool get_attached( void ) { return attached; } int timeout( void ) { return (int)lrint( ceil( SRTT + 4 * RTTVAR ) ); } + bool pending_timestamp( void ) { return ( saved_timestamp != uint64_t(-1) ); } }; } diff --git a/networktransport.cpp b/networktransport.cpp index 37b6bec..2507e40 100644 --- a/networktransport.cpp +++ b/networktransport.cpp @@ -78,7 +78,8 @@ void Transport::send_to_receiver( void ) if ( assumed_receiver_state->state == target_receiver_state ) { /* send empty ack */ - if ( timestamp() - sent_states.back().timestamp < int64_t( ACK_INTERVAL ) ) { + if ( (!connection.pending_timestamp()) + && (timestamp() - sent_states.back().timestamp < int64_t( ACK_INTERVAL )) ) { return; } @@ -147,7 +148,7 @@ void Transport::send_to_receiver( void ) string s = inst.tostring(); try { - fprintf( stderr, "Sent instruction from %d => %d (terminal %d): %s\r\n", int(inst.old_num), int(inst.new_num), int(sent_states.back().num), inst.diff.c_str() ); + fprintf( stderr, "Sent instruction (timeout %d) from %d => %d (terminal %d): %s\r\n", connection.timeout(), int(inst.old_num), int(inst.new_num), int(sent_states.back().num), inst.diff.c_str() ); connection.send( s ); } catch ( MTUException m ) { continue; @@ -200,7 +201,6 @@ void Transport::recv( void ) Instruction inst( s ); process_acknowledgment_through( inst.ack_num ); - // process_throwaway_until( inst.throwaway.num ); /* first, make sure we don't already have the new state */ for ( typename list< TimestampedState >::iterator i = received_states.begin();