#undef DEBUG_CONNECTION_KBPS
#else
/* this mutex is used to achieve log message consistency */
-Mutex log_message_mutex;
+std::mutex log_message_mutex;
#define LOG(a) \
{ \
MutexAutoLock loglock(log_message_mutex); \
#endif
-static inline float CALC_DTIME(unsigned int lasttime, unsigned int curtime) {
+static inline float CALC_DTIME(u64 lasttime, u64 curtime)
+{
float value = ( curtime - lasttime) / 1000.0;
return MYMAX(MYMIN(value,0.1),0.0);
}
-/* maximum window size to use, 0xFFFF is theoretical maximum don't think about
- * touching it, the less you're away from it the more likely data corruption
- * will occur
- */
-#define MAX_RELIABLE_WINDOW_SIZE 0x8000
- /* starting value for window size */
-#define MIN_RELIABLE_WINDOW_SIZE 0x40
-
#define MAX_UDP_PEERS 65535
#define PING_TIMEOUT 5.0
ReliablePacketBuffer
*/
-ReliablePacketBuffer::ReliablePacketBuffer(): m_list_size(0) {}
-
void ReliablePacketBuffer::print()
{
MutexAutoLock listlock(m_list_mutex);
Channel
*/
-Channel::Channel() :
- window_size(MIN_RELIABLE_WINDOW_SIZE),
- next_incoming_seqnum(SEQNUM_INITIAL),
- next_outgoing_seqnum(SEQNUM_INITIAL),
- next_outgoing_split_seqnum(SEQNUM_INITIAL),
- current_packet_loss(0),
- current_packet_too_late(0),
- current_packet_successfull(0),
- packet_loss_counter(0),
- current_bytes_transfered(0),
- current_bytes_received(0),
- current_bytes_lost(0),
- max_kbps(0.0),
- cur_kbps(0.0),
- avg_kbps(0.0),
- max_incoming_kbps(0.0),
- cur_incoming_kbps(0.0),
- avg_incoming_kbps(0.0),
- max_kbps_lost(0.0),
- cur_kbps_lost(0.0),
- avg_kbps_lost(0.0),
- bpm_counter(0.0),
- rate_samples(0)
-{
-}
-
-Channel::~Channel()
-{
-}
-
u16 Channel::readNextIncomingSeqNum()
{
MutexAutoLock internal(m_internal_mutex);
Peer
*/
-PeerHelper::PeerHelper() :
- m_peer(0)
-{}
-
PeerHelper::PeerHelper(Peer* peer) :
m_peer(peer)
{
- if (peer != NULL)
- {
- if (!peer->IncUseCount())
- {
- m_peer = 0;
- }
- }
+ if (peer && !peer->IncUseCount())
+ m_peer = nullptr;
}
PeerHelper::~PeerHelper()
{
- if (m_peer != 0)
+ if (m_peer)
m_peer->DecUseCount();
- m_peer = 0;
+ m_peer = nullptr;
}
PeerHelper& PeerHelper::operator=(Peer* peer)
{
m_peer = peer;
- if (peer != NULL)
- {
- if (!peer->IncUseCount())
- {
- m_peer = 0;
- }
- }
+ if (peer && !peer->IncUseCount())
+ m_peer = nullptr;
return *this;
}
{
MutexAutoLock lock(m_exclusive_access_mutex);
- if (!m_pending_deletion)
- {
+ if (!m_pending_deletion) {
this->m_usage++;
return true;
}
delete this;
}
-void Peer::RTTStatistics(float rtt, std::string profiler_id,
+void Peer::RTTStatistics(float rtt, const std::string &profiler_id,
unsigned int num_samples) {
if (m_last_rtt > 0) {
m_rtt.jitter_avg = m_rtt.jitter_avg * (num_samples/(num_samples-1)) +
jitter * (1/num_samples);
- if (profiler_id != "")
- {
+ if (profiler_id != "") {
g_profiler->graphAdd(profiler_id + "_rtt", rtt);
g_profiler->graphAdd(profiler_id + "_jitter", jitter);
}
bool Peer::isTimedOut(float timeout)
{
MutexAutoLock lock(m_exclusive_access_mutex);
- u32 current_time = porting::getTimeMs();
+ u64 current_time = porting::getTimeMs();
float dtime = CALC_DTIME(m_last_timeout_check,current_time);
m_last_timeout_check = current_time;
}
UDPPeer::UDPPeer(u16 a_id, Address a_address, Connection* connection) :
- Peer(a_address,a_id,connection),
- m_pending_disconnect(false),
- resend_timeout(0.5),
- m_legacy_peer(true)
+ Peer(a_address,a_id,connection)
{
}
ConnectionSendThread::ConnectionSendThread(unsigned int max_packet_size,
float timeout) :
Thread("ConnectionSend"),
- m_connection(NULL),
m_max_packet_size(max_packet_size),
m_timeout(timeout),
- m_max_commands_per_iteration(1),
- m_max_data_packets_per_iteration(g_settings->getU16("max_packets_per_iteration")),
- m_max_packets_requeued(256)
+ m_max_data_packets_per_iteration(g_settings->getU16("max_packets_per_iteration"))
{
}
LOG(dout_con<<m_connection->getDesc()
<<"ConnectionSend thread started"<<std::endl);
- u32 curtime = porting::getTimeMs();
- u32 lasttime = curtime;
+ u64 curtime = porting::getTimeMs();
+ u64 lasttime = curtime;
PROFILE(std::stringstream ThreadIdentifier);
PROFILE(ThreadIdentifier << "ConnectionSend: [" << m_connection->getDesc() << "]");
}
ConnectionReceiveThread::ConnectionReceiveThread(unsigned int max_packet_size) :
- Thread("ConnectionReceive"),
- m_connection(NULL)
+ Thread("ConnectionReceive")
{
}
PROFILE(ThreadIdentifier << "ConnectionReceive: [" << m_connection->getDesc() << "]");
#ifdef DEBUG_CONNECTION_KBPS
- u32 curtime = porting::getTimeMs();
- u32 lasttime = curtime;
+ u64 curtime = porting::getTimeMs();
+ u64 lasttime = curtime;
float debug_print_timer = 0.0;
#endif
// only calculate rtt from straight sent packets
if (p.resend_count == 0) {
// Get round trip time
- unsigned int current_time = porting::getTimeMs();
+ u64 current_time = porting::getTimeMs();
// a overflow is quite unlikely but as it'd result in major
// rtt miscalculation we handle it here
Connection::Connection(u32 protocol_id, u32 max_packet_size, float timeout,
bool ipv6, PeerHandler *peerhandler) :
m_udpSocket(ipv6),
- m_command_queue(),
- m_event_queue(),
- m_peer_id(0),
m_protocol_id(protocol_id),
m_sendThread(max_packet_size, timeout),
m_receiveThread(max_packet_size),
- m_info_mutex(),
- m_bc_peerhandler(peerhandler),
- m_bc_receive_timeout(0),
- m_shutting_down(false),
- m_next_remote_peer_id(2)
+ m_bc_peerhandler(peerhandler)
{
m_udpSocket.setTimeoutMs(5);