Switch to explicit fragments.

This commit is contained in:
Keith Winstein
2011-08-12 04:02:14 -04:00
parent f0f74a3971
commit 14667da4f5
6 changed files with 235 additions and 132 deletions
+32 -2
View File
@@ -5,6 +5,7 @@
#include <signal.h>
#include <time.h>
#include <list>
#include <vector>
#include "network.hpp"
@@ -13,22 +14,48 @@ using namespace std;
namespace Network {
class Instruction
{
private:
static const size_t inst_header_len = 4 * sizeof( uint64_t ) + 1 * sizeof( uint16_t );
public:
uint64_t old_num, new_num;
uint64_t ack_num;
uint64_t throwaway_num;
uint16_t fragment_num;
string diff;
Instruction() : old_num( -1 ), new_num( -1 ), ack_num( -1 ), throwaway_num( -1 ), fragment_num( -1 ),
diff( "" )
{}
Instruction( uint64_t s_old_num, uint64_t s_new_num,
uint64_t s_ack_num, uint64_t s_throwaway_num, string s_diff )
uint64_t s_ack_num, uint64_t s_throwaway_num, uint16_t s_fragment_num,
string s_diff )
: old_num( s_old_num ), new_num( s_new_num ),
ack_num( s_ack_num ), throwaway_num( s_throwaway_num ), diff( s_diff )
ack_num( s_ack_num ), throwaway_num( s_throwaway_num ), fragment_num( s_fragment_num ),
diff( s_diff )
{}
Instruction( string &x );
string tostring( void );
bool operator==( const Instruction &x );
};
class FragmentAssembly
{
private:
vector<Instruction> fragments;
Instruction current_template;
int fragments_arrived, fragments_total;
public:
FragmentAssembly() : fragments(), current_template(), fragments_arrived( 0 ), fragments_total( -1 ) {}
static bool same_template( Instruction &a, Instruction &b );
bool add_fragment( Instruction &inst );
Instruction get_assembly( void );
};
template <class State>
@@ -56,6 +83,7 @@ namespace Network {
void update_assumed_receiver_state( void );
void rationalize_states( void );
void send_to_receiver( void );
void send_in_fragments( string diff, uint64_t new_num );
/* helper methods for recv() */
void process_acknowledgment_through( uint64_t ack_num );
@@ -78,6 +106,8 @@ namespace Network {
list< TimestampedState<RemoteState> > received_states;
MyState last_receiver_state; /* the state we were in when user last queried state */
FragmentAssembly fragments;
public:
Transport( MyState &initial_state, RemoteState &initial_remote );
Transport( MyState &initial_state, RemoteState &initial_remote,