Simplify Transport ack behavior and make more robust (num increases)

This commit is contained in:
Keith Winstein
2011-08-13 01:53:33 -04:00
parent 7e034c27aa
commit 945acbca37
2 changed files with 12 additions and 21 deletions
+11 -20
View File
@@ -67,31 +67,23 @@ void Transport<MyState, RemoteState>::send_to_receiver( void )
return; return;
} }
if ( (assumed_receiver_state->num == sent_states.back().num) string diff = current_state.diff_from( assumed_receiver_state->state );
&& (sent_states.back().state == current_state) ) {
if ( diff.empty() ) {
/* send empty ack */ /* send empty ack */
if ( (!connection.pending_timestamp()) if ( (!connection.pending_timestamp())
&& (timestamp() - sent_states.back().timestamp < int64_t( ACK_INTERVAL )) ) { && (timestamp() - sent_states.back().timestamp < int64_t( ACK_INTERVAL )) ) {
return; return;
} }
/* XXX should increment number each time */ uint64_t new_num = sent_states.back().num + 1;
Instruction inst( assumed_receiver_state->num, send_in_fragments( diff, new_num, false );
assumed_receiver_state->num, sent_states.push_back( TimestampedState<MyState>( timestamp(), new_num, current_state ) );
received_states.back().num,
sent_states.front().num,
0, true,
"" );
string s = inst.tostring();
connection.send( s, false );
assumed_receiver_state->timestamp = timestamp();
return; return;
} }
string diff = current_state.diff_from( assumed_receiver_state->state );
uint64_t new_num; uint64_t new_num;
if ( current_state == sent_states.back().state ) { /* previously sent */ if ( current_state == sent_states.back().state ) { /* previously sent */
new_num = sent_states.back().num; new_num = sent_states.back().num;
@@ -184,7 +176,6 @@ void Transport<MyState, RemoteState>::recv( void )
i != received_states.end(); i != received_states.end();
i++ ) { i++ ) {
if ( inst.new_num == i->num ) { if ( inst.new_num == i->num ) {
i->timestamp = timestamp();
return; return;
} }
} }
@@ -280,13 +271,13 @@ string Transport<MyState, RemoteState>::get_remote_diff( void )
} }
template <class MyState, class RemoteState> template <class MyState, class RemoteState>
void Transport<MyState, RemoteState>::send_in_fragments( string diff, uint64_t new_num ) void Transport<MyState, RemoteState>::send_in_fragments( string diff, uint64_t new_num, bool send_timestamp )
{ {
uint16_t fragment_num = 0; uint16_t fragment_num = 0;
while ( !diff.empty() ) { do {
string this_fragment; string this_fragment;
assert( fragment_num <= 32767 ); assert( fragment_num <= 32767 );
bool final = false; bool final = false;
@@ -308,6 +299,6 @@ void Transport<MyState, RemoteState>::send_in_fragments( string diff, uint64_t n
this_fragment ); this_fragment );
string s = inst.tostring(); string s = inst.tostring();
connection.send( s ); connection.send( s, send_timestamp );
} } while ( !diff.empty() );
} }
+1 -1
View File
@@ -84,7 +84,7 @@ namespace Network {
void update_assumed_receiver_state( void ); void update_assumed_receiver_state( void );
void rationalize_states( void ); void rationalize_states( void );
void send_to_receiver( void ); void send_to_receiver( void );
void send_in_fragments( string diff, uint64_t new_num ); void send_in_fragments( string diff, uint64_t new_num, bool send_timestamp = true );
/* helper methods for recv() */ /* helper methods for recv() */
void process_acknowledgment_through( uint64_t ack_num ); void process_acknowledgment_through( uint64_t ack_num );