summaryrefslogtreecommitdiffstats
path: root/src/network/transportsender.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/transportsender.h')
-rw-r--r--src/network/transportsender.h195
1 files changed, 102 insertions, 93 deletions
diff --git a/src/network/transportsender.h b/src/network/transportsender.h
index 27fd2af..c0f48cc 100644
--- a/src/network/transportsender.h
+++ b/src/network/transportsender.h
@@ -30,137 +30,146 @@
also delete it here.
*/
-
#ifndef TRANSPORT_SENDER_HPP
#define TRANSPORT_SENDER_HPP
-#include <string>
#include <list>
+#include <string>
+#include "src/crypto/prng.h"
#include "src/network/network.h"
#include "src/protobufs/transportinstruction.pb.h"
-#include "transportstate.h"
#include "transportfragment.h"
-#include "src/crypto/prng.h"
+#include "transportstate.h"
namespace Network {
- using namespace TransportBuffers;
-
- /* timing parameters */
- const int SEND_INTERVAL_MIN = 20; /* ms between frames */
- const int SEND_INTERVAL_MAX = 250; /* ms between frames */
- const int ACK_INTERVAL = 3000; /* ms between empty acks */
- const int ACK_DELAY = 100; /* ms before delayed ack */
- const int SHUTDOWN_RETRIES = 16; /* number of shutdown packets to send before giving up */
- const int ACTIVE_RETRY_TIMEOUT = 10000; /* attempt to resend at frame rate */
-
- template <class MyState>
- class TransportSender
- {
- private:
- /* helper methods for tick() */
- void update_assumed_receiver_state( void );
- void attempt_prospective_resend_optimization( std::string &proposed_diff );
- void rationalize_states( void );
- void send_to_receiver( const std::string & diff );
- void send_empty_ack( void );
- void send_in_fragments( const std::string & diff, uint64_t new_num );
- void add_sent_state( uint64_t the_timestamp, uint64_t num, MyState &state );
+using namespace TransportBuffers;
+
+/* timing parameters */
+const int SEND_INTERVAL_MIN = 20; /* ms between frames */
+const int SEND_INTERVAL_MAX = 250; /* ms between frames */
+const int ACK_INTERVAL = 3000; /* ms between empty acks */
+const int ACK_DELAY = 100; /* ms before delayed ack */
+const int SHUTDOWN_RETRIES = 16; /* number of shutdown packets to send before giving up */
+const int ACTIVE_RETRY_TIMEOUT = 10000; /* attempt to resend at frame rate */
- /* state of sender */
- Connection *connection;
+template<class MyState>
+class TransportSender
+{
+private:
+ /* helper methods for tick() */
+ void update_assumed_receiver_state( void );
+ void attempt_prospective_resend_optimization( std::string& proposed_diff );
+ void rationalize_states( void );
+ void send_to_receiver( const std::string& diff );
+ void send_empty_ack( void );
+ void send_in_fragments( const std::string& diff, uint64_t new_num );
+ void add_sent_state( uint64_t the_timestamp, uint64_t num, MyState& state );
- MyState current_state;
+ /* state of sender */
+ Connection* connection;
- using sent_states_type = std::list<TimestampedState<MyState>>;
- sent_states_type sent_states;
- /* first element: known, acknowledged receiver state */
- /* last element: last sent state */
+ MyState current_state;
- /* somewhere in the middle: the assumed state of the receiver */
- typename sent_states_type::iterator assumed_receiver_state;
+ using sent_states_type = std::list<TimestampedState<MyState>>;
+ sent_states_type sent_states;
+ /* first element: known, acknowledged receiver state */
+ /* last element: last sent state */
- /* for fragment creation */
- Fragmenter fragmenter;
+ /* somewhere in the middle: the assumed state of the receiver */
+ typename sent_states_type::iterator assumed_receiver_state;
- /* timing state */
- uint64_t next_ack_time;
- uint64_t next_send_time;
+ /* for fragment creation */
+ Fragmenter fragmenter;
- void calculate_timers( void );
+ /* timing state */
+ uint64_t next_ack_time;
+ uint64_t next_send_time;
- unsigned int verbose;
- bool shutdown_in_progress;
- int shutdown_tries;
- uint64_t shutdown_start;
+ void calculate_timers( void );
- /* information about receiver state */
- uint64_t ack_num;
- bool pending_data_ack;
+ unsigned int verbose;
+ bool shutdown_in_progress;
+ int shutdown_tries;
+ uint64_t shutdown_start;
- unsigned int SEND_MINDELAY; /* ms to collect all input */
+ /* information about receiver state */
+ uint64_t ack_num;
+ bool pending_data_ack;
- uint64_t last_heard; /* last time received new state */
+ unsigned int SEND_MINDELAY; /* ms to collect all input */
- /* chaff to disguise instruction length */
- PRNG prng;
- const std::string make_chaff( void );
+ uint64_t last_heard; /* last time received new state */
- uint64_t mindelay_clock; /* time of first pending change to current state */
+ /* chaff to disguise instruction length */
+ PRNG prng;
+ const std::string make_chaff( void );
- public:
- /* constructor */
- TransportSender( Connection *s_connection, MyState &initial_state );
+ uint64_t mindelay_clock; /* time of first pending change to current state */
- /* Send data or an ack if necessary */
- void tick( void );
+public:
+ /* constructor */
+ TransportSender( Connection* s_connection, MyState& initial_state );
- /* Returns the number of ms to wait until next possible event. */
- int wait_time( void );
+ /* Send data or an ack if necessary */
+ void tick( void );
- /* Executed upon receipt of ack */
- void process_acknowledgment_through( uint64_t ack_num );
+ /* Returns the number of ms to wait until next possible event. */
+ int wait_time( void );
- /* Executed upon entry to new receiver state */
- void set_ack_num( uint64_t s_ack_num );
+ /* Executed upon receipt of ack */
+ void process_acknowledgment_through( uint64_t ack_num );
- /* Accelerate reply ack */
- void set_data_ack( void ) { pending_data_ack = true; }
+ /* Executed upon entry to new receiver state */
+ void set_ack_num( uint64_t s_ack_num );
- /* Received something */
- void remote_heard( uint64_t ts ) { last_heard = ts; }
+ /* Accelerate reply ack */
+ void set_data_ack( void ) { pending_data_ack = true; }
- /* Starts shutdown sequence */
- void start_shutdown( void ) { if ( !shutdown_in_progress ) { shutdown_start = timestamp(); shutdown_in_progress = true; } }
+ /* Received something */
+ void remote_heard( uint64_t ts ) { last_heard = ts; }
- /* Misc. getters and setters */
- /* Cannot modify current_state while shutdown in progress */
- MyState &get_current_state( void ) { assert( !shutdown_in_progress ); return current_state; }
- void set_current_state( const MyState &x )
- {
- assert( !shutdown_in_progress );
- current_state = x;
- current_state.reset_input();
+ /* Starts shutdown sequence */
+ void start_shutdown( void )
+ {
+ if ( !shutdown_in_progress ) {
+ shutdown_start = timestamp();
+ shutdown_in_progress = true;
}
- void set_verbose( unsigned int s_verbose ) { verbose = s_verbose; }
+ }
+
+ /* Misc. getters and setters */
+ /* Cannot modify current_state while shutdown in progress */
+ MyState& get_current_state( void )
+ {
+ assert( !shutdown_in_progress );
+ return current_state;
+ }
+ void set_current_state( const MyState& x )
+ {
+ assert( !shutdown_in_progress );
+ current_state = x;
+ current_state.reset_input();
+ }
+ void set_verbose( unsigned int s_verbose ) { verbose = s_verbose; }
- bool get_shutdown_in_progress( void ) const { return shutdown_in_progress; }
- bool get_shutdown_acknowledged( void ) const { return sent_states.front().num == uint64_t(-1); }
- bool get_counterparty_shutdown_acknowledged( void ) const { return fragmenter.last_ack_sent() == uint64_t(-1); }
- uint64_t get_sent_state_acked_timestamp( void ) const { return sent_states.front().timestamp; }
- uint64_t get_sent_state_acked( void ) const { return sent_states.front().num; }
- uint64_t get_sent_state_last( void ) const { return sent_states.back().num; }
+ bool get_shutdown_in_progress( void ) const { return shutdown_in_progress; }
+ bool get_shutdown_acknowledged( void ) const { return sent_states.front().num == uint64_t( -1 ); }
+ bool get_counterparty_shutdown_acknowledged( void ) const { return fragmenter.last_ack_sent() == uint64_t( -1 ); }
+ uint64_t get_sent_state_acked_timestamp( void ) const { return sent_states.front().timestamp; }
+ uint64_t get_sent_state_acked( void ) const { return sent_states.front().num; }
+ uint64_t get_sent_state_last( void ) const { return sent_states.back().num; }
- bool shutdown_ack_timed_out( void ) const;
+ bool shutdown_ack_timed_out( void ) const;
- void set_send_delay( int new_delay ) { SEND_MINDELAY = new_delay; }
+ void set_send_delay( int new_delay ) { SEND_MINDELAY = new_delay; }
- unsigned int send_interval( void ) const;
+ unsigned int send_interval( void ) const;
- /* nonexistent methods to satisfy -Weffc++ */
- TransportSender( const TransportSender &x );
- TransportSender & operator=( const TransportSender &x );
- };
+ /* nonexistent methods to satisfy -Weffc++ */
+ TransportSender( const TransportSender& x );
+ TransportSender& operator=( const TransportSender& x );
+};
}
#endif