]> git.lizzy.rs Git - minetest.git/blobdiff - src/connection.h
Fix a crash (assert) when client set serial version < 24 in INIT
[minetest.git] / src / connection.h
index 43fd2fb88e8b6735a4f46d53dbbfe6e063bee630..be1627dfa079b6484018d6b187b9309177665b9f 100644 (file)
@@ -120,9 +120,9 @@ class IncomingDataCorruption : public BaseException
 };
 
 typedef enum MTProtocols {
-       PRIMARY,
-       UDP,
-       MINETEST_RELIABLE_UDP
+       MTP_PRIMARY,
+       MTP_UDP,
+       MTP_MINETEST_RELIABLE_UDP
 } MTProtocols;
 
 #define SEQNUM_MAX 65535
@@ -162,16 +162,19 @@ inline bool seqnum_in_window(u16 seqnum, u16 next,u16 window_size)
 struct BufferedPacket
 {
        BufferedPacket(u8 *a_data, u32 a_size):
-               data(a_data, a_size), time(0.0), totaltime(0.0), absolute_send_time(-1)
+               data(a_data, a_size), time(0.0), totaltime(0.0), absolute_send_time(-1),
+               resend_count(0)
        {}
        BufferedPacket(u32 a_size):
-               data(a_size), time(0.0), totaltime(0.0), absolute_send_time(-1)
+               data(a_size), time(0.0), totaltime(0.0), absolute_send_time(-1),
+               resend_count(0)
        {}
        SharedBuffer<u8> data; // Data of the packet, including headers
        float time; // Seconds from buffering the packet or re-sending
        float totaltime; // Seconds from buffering the packet
        unsigned int absolute_send_time;
        Address address; // Sender or destination
+       unsigned int resend_count;
 };
 
 // This adds the base headers to the data and makes a packet out of it
@@ -515,8 +518,9 @@ class Channel
        void UpdatePacketTooLateCounter();
        void UpdateBytesSent(unsigned int bytes,unsigned int packages=1);
        void UpdateBytesLost(unsigned int bytes);
+       void UpdateBytesReceived(unsigned int bytes);
 
-       void UpdateTimers(float dtime);
+       void UpdateTimers(float dtime, bool legacy_peer);
 
        const float getCurrentDownloadRateKB()
                { JMutexAutoLock lock(m_internal_mutex); return cur_kbps; };
@@ -528,17 +532,24 @@ class Channel
        const float getMaxLossRateKB()
                { JMutexAutoLock lock(m_internal_mutex); return max_kbps_lost; };
 
+       const float getCurrentIncomingRateKB()
+               { JMutexAutoLock lock(m_internal_mutex); return cur_incoming_kbps; };
+       const float getMaxIncomingRateKB()
+               { JMutexAutoLock lock(m_internal_mutex); return max_incoming_kbps; };
+
        const float getAvgDownloadRateKB()
                { JMutexAutoLock lock(m_internal_mutex); return avg_kbps; };
        const float getAvgLossRateKB()
                { JMutexAutoLock lock(m_internal_mutex); return avg_kbps_lost; };
+       const float getAvgIncomingRateKB()
+               { JMutexAutoLock lock(m_internal_mutex); return avg_incoming_kbps; };
 
        const unsigned int getWindowSize() const { return window_size; };
 
        void setWindowSize(unsigned int size) { window_size = size; };
 private:
        JMutex m_internal_mutex;
-       unsigned int window_size;
+       int window_size;
 
        u16 next_incoming_seqnum;
 
@@ -551,14 +562,20 @@ class Channel
        float packet_loss_counter;
 
        unsigned int current_bytes_transfered;
+       unsigned int current_bytes_received;
        unsigned int current_bytes_lost;
        float max_kbps;
        float cur_kbps;
        float avg_kbps;
+       float max_incoming_kbps;
+       float cur_incoming_kbps;
+       float avg_incoming_kbps;
        float max_kbps_lost;
        float cur_kbps_lost;
        float avg_kbps_lost;
        float bpm_counter;
+
+       unsigned int rate_samples;
 };
 
 class Peer;
@@ -617,7 +634,7 @@ class PeerHelper
 
 class Connection;
 
-typedef enum rtt_stat_type {
+typedef enum {
        MIN_RTT,
        MAX_RTT,
        AVG_RTT,
@@ -626,6 +643,15 @@ typedef enum rtt_stat_type {
        AVG_JITTER
 } rtt_stat_type;
 
+typedef enum {
+       CUR_DL_RATE,
+       AVG_DL_RATE,
+       CUR_INC_RATE,
+       AVG_INC_RATE,
+       CUR_LOSS_RATE,
+       AVG_LOSS_RATE,
+} rate_stat_type;
+
 class Peer {
        public:
                friend class PeerHelper;
@@ -765,6 +791,7 @@ class UDPPeer : public Peer
        friend class PeerHelper;
        friend class ConnectionReceiveThread;
        friend class ConnectionSendThread;
+       friend class Connection;
 
        UDPPeer(u16 a_id, Address a_address, Connection* connection);
        virtual ~UDPPeer() {};
@@ -891,13 +918,17 @@ class ConnectionSendThread : public JThread {
 public:
        friend class UDPPeer;
 
-       ConnectionSendThread(Connection* parent,
-                                                       unsigned int max_packet_size, float timeout);
+       ConnectionSendThread(unsigned int max_packet_size, float timeout);
 
        void * Thread       ();
 
        void Trigger();
 
+       void setParent(Connection* parent) {
+               assert(parent != NULL);
+               m_connection = parent;
+       }
+
        void setPeerTimeout(float peer_timeout)
                { m_timeout = peer_timeout; }
 
@@ -943,11 +974,15 @@ class ConnectionSendThread : public JThread {
 
 class ConnectionReceiveThread : public JThread {
 public:
-       ConnectionReceiveThread(Connection* parent,
-                                                       unsigned int max_packet_size);
+       ConnectionReceiveThread(unsigned int max_packet_size);
 
        void * Thread       ();
 
+       void setParent(Connection* parent) {
+               assert(parent != NULL);
+               m_connection = parent;
+       }
+
 private:
        void receive        ();
 
@@ -1002,6 +1037,7 @@ class Connection
        u16 GetPeerID(){ return m_peer_id; }
        Address GetPeerAddress(u16 peer_id);
        float getPeerStat(u16 peer_id, rtt_stat_type type);
+       float getLocalStat(rate_stat_type type);
        const u32 GetProtocolID() const { return m_protocol_id; };
        const std::string getDesc();
        void DisconnectPeer(u16 peer_id);