diff options
author | SmallJoker <SmallJoker@users.noreply.github.com> | 2021-09-27 17:45:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-27 17:45:44 +0200 |
commit | d51d0f3a5a60679436bf7d4e1980f3a82f229848 (patch) | |
tree | e6d15df599dd04df76b8493a4cdcaf6b550c4cce /src/network | |
parent | 918fbe3ec1667c65a320f1f6b432449f104d8e26 (diff) | |
download | minetest-d51d0f3a5a60679436bf7d4e1980f3a82f229848.tar.gz minetest-d51d0f3a5a60679436bf7d4e1980f3a82f229848.tar.bz2 minetest-d51d0f3a5a60679436bf7d4e1980f3a82f229848.zip |
Various code improvements
* Camera: Fix division by 0 after view bobbing
* Remove ignored constness
* Connection: Improve window size range limits
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/connection.cpp | 32 | ||||
-rw-r--r-- | src/network/connection.h | 30 | ||||
-rw-r--r-- | src/network/networkpacket.h | 2 |
3 files changed, 28 insertions, 36 deletions
diff --git a/src/network/connection.cpp b/src/network/connection.cpp index a4970954f..548b2e3a0 100644 --- a/src/network/connection.cpp +++ b/src/network/connection.cpp @@ -578,7 +578,7 @@ u16 Channel::getOutgoingSequenceNumber(bool& successful) // ugly cast but this one is required in order to tell compiler we // know about difference of two unsigned may be negative in general // but we already made sure it won't happen in this case - if (((u16)(next_outgoing_seqnum - lowest_unacked_seqnumber)) > window_size) { + if (((u16)(next_outgoing_seqnum - lowest_unacked_seqnumber)) > m_window_size) { successful = false; return 0; } @@ -588,7 +588,7 @@ u16 Channel::getOutgoingSequenceNumber(bool& successful) // know about difference of two unsigned may be negative in general // but we already made sure it won't happen in this case if ((next_outgoing_seqnum + (u16)(SEQNUM_MAX - lowest_unacked_seqnumber)) > - window_size) { + m_window_size) { successful = false; return 0; } @@ -666,7 +666,7 @@ void Channel::UpdateTimers(float dtime) //packet_too_late = current_packet_too_late; packets_successful = current_packet_successful; - if (current_bytes_transfered > (unsigned int) (window_size*512/2)) { + if (current_bytes_transfered > (unsigned int) (m_window_size*512/2)) { reasonable_amount_of_data_transmitted = true; } current_packet_loss = 0; @@ -681,37 +681,25 @@ void Channel::UpdateTimers(float dtime) if (packets_successful > 0) { successful_to_lost_ratio = packet_loss/packets_successful; } else if (packet_loss > 0) { - window_size = std::max( - (window_size - 10), - MIN_RELIABLE_WINDOW_SIZE); + setWindowSize(m_window_size - 10); done = true; } if (!done) { - if ((successful_to_lost_ratio < 0.01f) && - (window_size < MAX_RELIABLE_WINDOW_SIZE)) { + if (successful_to_lost_ratio < 0.01f) { /* don't even think about increasing if we didn't even * use major parts of our window */ if (reasonable_amount_of_data_transmitted) - window_size = std::min( - (window_size + 100), - MAX_RELIABLE_WINDOW_SIZE); - } else if ((successful_to_lost_ratio < 0.05f) && - (window_size < MAX_RELIABLE_WINDOW_SIZE)) { + setWindowSize(m_window_size + 100); + } else if (successful_to_lost_ratio < 0.05f) { /* don't even think about increasing if we didn't even * use major parts of our window */ if (reasonable_amount_of_data_transmitted) - window_size = std::min( - (window_size + 50), - MAX_RELIABLE_WINDOW_SIZE); + setWindowSize(m_window_size + 50); } else if (successful_to_lost_ratio > 0.15f) { - window_size = std::max( - (window_size - 100), - MIN_RELIABLE_WINDOW_SIZE); + setWindowSize(m_window_size - 100); } else if (successful_to_lost_ratio > 0.1f) { - window_size = std::max( - (window_size - 50), - MIN_RELIABLE_WINDOW_SIZE); + setWindowSize(m_window_size - 50); } } } diff --git a/src/network/connection.h b/src/network/connection.h index 49bb65c3e..ea74ffb1c 100644 --- a/src/network/connection.h +++ b/src/network/connection.h @@ -420,34 +420,38 @@ public: void UpdateTimers(float dtime); - const float getCurrentDownloadRateKB() + float getCurrentDownloadRateKB() { MutexAutoLock lock(m_internal_mutex); return cur_kbps; }; - const float getMaxDownloadRateKB() + float getMaxDownloadRateKB() { MutexAutoLock lock(m_internal_mutex); return max_kbps; }; - const float getCurrentLossRateKB() + float getCurrentLossRateKB() { MutexAutoLock lock(m_internal_mutex); return cur_kbps_lost; }; - const float getMaxLossRateKB() + float getMaxLossRateKB() { MutexAutoLock lock(m_internal_mutex); return max_kbps_lost; }; - const float getCurrentIncomingRateKB() + float getCurrentIncomingRateKB() { MutexAutoLock lock(m_internal_mutex); return cur_incoming_kbps; }; - const float getMaxIncomingRateKB() + float getMaxIncomingRateKB() { MutexAutoLock lock(m_internal_mutex); return max_incoming_kbps; }; - const float getAvgDownloadRateKB() + float getAvgDownloadRateKB() { MutexAutoLock lock(m_internal_mutex); return avg_kbps; }; - const float getAvgLossRateKB() + float getAvgLossRateKB() { MutexAutoLock lock(m_internal_mutex); return avg_kbps_lost; }; - const float getAvgIncomingRateKB() + float getAvgIncomingRateKB() { MutexAutoLock lock(m_internal_mutex); return avg_incoming_kbps; }; - const unsigned int getWindowSize() const { return window_size; }; + u16 getWindowSize() const { return m_window_size; }; + + void setWindowSize(long size) + { + m_window_size = (u16)rangelim(size, MIN_RELIABLE_WINDOW_SIZE, MAX_RELIABLE_WINDOW_SIZE); + } - void setWindowSize(unsigned int size) { window_size = size; }; private: std::mutex m_internal_mutex; - int window_size = MIN_RELIABLE_WINDOW_SIZE; + u16 m_window_size = MIN_RELIABLE_WINDOW_SIZE; u16 next_incoming_seqnum = SEQNUM_INITIAL; @@ -765,7 +769,7 @@ public: Address GetPeerAddress(session_t peer_id); float getPeerStat(session_t peer_id, rtt_stat_type type); float getLocalStat(rate_stat_type type); - const u32 GetProtocolID() const { return m_protocol_id; }; + u32 GetProtocolID() const { return m_protocol_id; }; const std::string getDesc(); void DisconnectPeer(session_t peer_id); diff --git a/src/network/networkpacket.h b/src/network/networkpacket.h index b1c44f055..b9c39f332 100644 --- a/src/network/networkpacket.h +++ b/src/network/networkpacket.h @@ -41,7 +41,7 @@ public: u32 getSize() const { return m_datasize; } session_t getPeerId() const { return m_peer_id; } u16 getCommand() { return m_command; } - const u32 getRemainingBytes() const { return m_datasize - m_read_offset; } + u32 getRemainingBytes() const { return m_datasize - m_read_offset; } const char *getRemainingString() { return getString(m_read_offset); } // Returns a c-string without copying. |