|
@@ -10,9 +10,11 @@ namespace crown
|
|
|
{
|
|
{
|
|
|
namespace network
|
|
namespace network
|
|
|
{
|
|
{
|
|
|
|
|
+ #define DEFAULT_PROTOCOL_ID 0xFFFFFFFF
|
|
|
#define MAX_PACKET_LEN 1400
|
|
#define MAX_PACKET_LEN 1400
|
|
|
#define MAX_MESSAGE_SIZE 16384
|
|
#define MAX_MESSAGE_SIZE 16384
|
|
|
#define MAX_QUEUE_SIZE 16384
|
|
#define MAX_QUEUE_SIZE 16384
|
|
|
|
|
+
|
|
|
|
|
|
|
|
class Connection
|
|
class Connection
|
|
|
{
|
|
{
|
|
@@ -21,26 +23,25 @@ public:
|
|
|
Connection(Allocator& allocator);
|
|
Connection(Allocator& allocator);
|
|
|
~Connection();
|
|
~Connection();
|
|
|
|
|
|
|
|
- void init(const os::NetAddress addr, const int id);
|
|
|
|
|
- void shutdown();
|
|
|
|
|
|
|
+ void init(const os::NetAddress addr, const int32_t id = DEFAULT_PROTOCOL_ID);
|
|
|
void reset_rate();
|
|
void reset_rate();
|
|
|
|
|
|
|
|
// Sets the maximum outgoing rate.
|
|
// Sets the maximum outgoing rate.
|
|
|
- void set_max_outgoing_rate(int rate);
|
|
|
|
|
|
|
+ void set_max_outgoing_rate(int32_t rate);
|
|
|
// Gets the maximum outgoing rate.
|
|
// Gets the maximum outgoing rate.
|
|
|
- int get_max_outgoing_rate();
|
|
|
|
|
|
|
+ int32_t get_max_outgoing_rate();
|
|
|
// Returns the address of the entity at the other side of the channel.
|
|
// Returns the address of the entity at the other side of the channel.
|
|
|
os::NetAddress get_remote_address() const;
|
|
os::NetAddress get_remote_address() const;
|
|
|
// Returns the average outgoing rate over the last second.
|
|
// Returns the average outgoing rate over the last second.
|
|
|
- int get_outgoing_rate() const;
|
|
|
|
|
|
|
+ int32_t get_outgoing_rate() const;
|
|
|
// Returns the average incoming rate over the last second.
|
|
// Returns the average incoming rate over the last second.
|
|
|
- int get_incoming_rate() const;
|
|
|
|
|
|
|
+ int32_t get_incoming_rate() const;
|
|
|
// Returns the average incoming packet loss over the last 5 seconds.
|
|
// Returns the average incoming packet loss over the last 5 seconds.
|
|
|
- float get_incoming_packet_loss() const;
|
|
|
|
|
|
|
+ real get_incoming_packet_loss() const;
|
|
|
// Returns true if the channel is ready to send new data based on the maximum rate.
|
|
// Returns true if the channel is ready to send new data based on the maximum rate.
|
|
|
- bool ready_to_send(const int time) const;
|
|
|
|
|
|
|
+ bool ready_to_send(const int32_t time) const;
|
|
|
// Processes the incoming message.
|
|
// Processes the incoming message.
|
|
|
- bool process(const os::NetAddress from, int time, BitMessage &msg, int &sequence);
|
|
|
|
|
|
|
+ bool process(const os::NetAddress from, int32_t time, BitMessage &msg, int32_t &sequence);
|
|
|
// Sends a reliable message, in order and without duplicates.
|
|
// Sends a reliable message, in order and without duplicates.
|
|
|
void send_reliable_message(const BitMessage &msg);
|
|
void send_reliable_message(const BitMessage &msg);
|
|
|
// Returns true if a new reliable message is available and stores the message.
|
|
// Returns true if a new reliable message is available and stores the message.
|
|
@@ -49,39 +50,35 @@ public:
|
|
|
void clear_reliable_messages();
|
|
void clear_reliable_messages();
|
|
|
|
|
|
|
|
private:
|
|
private:
|
|
|
- // methods which provides a pattern for communication
|
|
|
|
|
- void _write_message(BitMessage &out, const BitMessage &msg);
|
|
|
|
|
- bool _read_message(BitMessage &out, const BitMessage &msg);
|
|
|
|
|
-
|
|
|
|
|
// methods which provides a reliability system
|
|
// methods which provides a reliability system
|
|
|
- void _update_outgoing_rate(const int time, const int size);
|
|
|
|
|
- void _update_incoming_rate(const int time, const int size);
|
|
|
|
|
- void _update_packet_loss(const int time, const int num_recv, const int num_dropped);
|
|
|
|
|
|
|
+ void _update_outgoing_rate(const int32_t time, const int32_t size);
|
|
|
|
|
+ void _update_incoming_rate(const int32_t time, const int32_t size);
|
|
|
|
|
+ void _update_packet_loss(const int32_t time, const int32_t num_recv, const int32_t num_dropped);
|
|
|
|
|
|
|
|
private:
|
|
private:
|
|
|
|
|
|
|
|
os::NetAddress m_remote_address; // address of remote host
|
|
os::NetAddress m_remote_address; // address of remote host
|
|
|
- int m_id; // our identification used instead of port number
|
|
|
|
|
- int m_max_rate; // maximum number of bytes that may go out per second
|
|
|
|
|
|
|
+ int32_t m_id; // our identification used instead of port number
|
|
|
|
|
+ int32_t m_max_rate; // maximum number of bytes that may go out per second
|
|
|
|
|
|
|
|
// variables to control the outgoing rate
|
|
// variables to control the outgoing rate
|
|
|
- int m_last_send_time; // last time data was sent out
|
|
|
|
|
- int m_last_data_bytes; // bytes left to send at last send time
|
|
|
|
|
|
|
+ int32_t m_last_send_time; // last time data was sent out
|
|
|
|
|
+ int32_t m_last_data_bytes; // bytes left to send at last send time
|
|
|
|
|
|
|
|
// variables to keep track of the rate
|
|
// variables to keep track of the rate
|
|
|
- int m_outgoing_rate_time; // outgoing time rate
|
|
|
|
|
- int m_outgoing_rate_bytes; // outgoing bytes rate
|
|
|
|
|
- int m_incoming_rate_time; // incoming time rate
|
|
|
|
|
- int m_incoming_rate_bytes; // incoming bytes rate
|
|
|
|
|
|
|
+ int32_t m_outgoing_rate_time; // outgoing time rate
|
|
|
|
|
+ int32_t m_outgoing_rate_bytes; // outgoing bytes rate
|
|
|
|
|
+ int32_t m_incoming_rate_time; // incoming time rate
|
|
|
|
|
+ int32_t m_incoming_rate_bytes; // incoming bytes rate
|
|
|
|
|
|
|
|
// variables to keep track of the incoming packet loss
|
|
// variables to keep track of the incoming packet loss
|
|
|
- float m_incoming_recv_packets;
|
|
|
|
|
- float m_incoming_dropped_packets;
|
|
|
|
|
- int m_incoming_packet_loss_time;
|
|
|
|
|
|
|
+ real m_incoming_recv_packets;
|
|
|
|
|
+ real m_incoming_dropped_packets;
|
|
|
|
|
+ int32_t m_incoming_packet_loss_time;
|
|
|
|
|
|
|
|
// sequencing variables
|
|
// sequencing variables
|
|
|
- int m_outgoing_sequence;
|
|
|
|
|
- int m_incoming_sequence;
|
|
|
|
|
|
|
+ int32_t m_outgoing_sequence;
|
|
|
|
|
+ int32_t m_incoming_sequence;
|
|
|
|
|
|
|
|
// reliable messages
|
|
// reliable messages
|
|
|
Queue<BitMessage> m_reliable_send;
|
|
Queue<BitMessage> m_reliable_send;
|