From 88b436e6a9c98af7215bd115e1b7a3f1a1db99d3 Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Sat, 19 Aug 2017 22:23:47 +0200 Subject: Code modernization: subfolders (#6283) * Code modernization: subfolders Modernize various code on subfolders client, network, script, threading, unittests, util * empty function * default constructor/destructor * for range-based loops * use emplace_back instead of push_back * C++ STL header style * Make connection.cpp readable in a pointed place + typo --- src/network/connection.cpp | 391 +++++++++++++++++++-------------------------- 1 file changed, 162 insertions(+), 229 deletions(-) (limited to 'src/network/connection.cpp') diff --git a/src/network/connection.cpp b/src/network/connection.cpp index c93971cac..a74e96784 100644 --- a/src/network/connection.cpp +++ b/src/network/connection.cpp @@ -18,7 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include -#include +#include #include "connection.h" #include "serialization.h" #include "log.h" @@ -151,11 +151,9 @@ std::list > makeSplitPacket( } while(end != data.getSize() - 1); - for(std::list >::iterator i = chunks.begin(); - i != chunks.end(); ++i) - { + for (SharedBuffer &chunk : chunks) { // Write chunk_count - writeU16(&((*i)[3]), chunk_count); + writeU16(&(chunk[3]), chunk_count); } return chunks; @@ -174,15 +172,13 @@ std::list > makeAutoSplitPacket( split_seqnum++; return list; } - else - { - list.push_back(makeOriginalPacket(data)); - } + + list.push_back(makeOriginalPacket(data)); return list; } SharedBuffer makeReliablePacket( - SharedBuffer data, + const SharedBuffer &data, u16 seqnum) { u32 header_size = 3; @@ -206,11 +202,8 @@ void ReliablePacketBuffer::print() MutexAutoLock listlock(m_list_mutex); LOG(dout_con<<"Dump of ReliablePacketBuffer:" << std::endl); unsigned int index = 0; - for(std::list::iterator i = m_list.begin(); - i != m_list.end(); - ++i) - { - u16 s = readU16(&(i->data[BASE_HEADER_SIZE+1])); + for (BufferedPacket &bufferedPacket : m_list) { + u16 s = readU16(&(bufferedPacket.data[BASE_HEADER_SIZE+1])); LOG(dout_con<::iterator i = m_list.begin(); - i != m_list.end(); ++i) - { - i->time += dtime; - i->totaltime += dtime; + for (BufferedPacket &bufferedPacket : m_list) { + bufferedPacket.time += dtime; + bufferedPacket.totaltime += dtime; } } @@ -419,14 +410,12 @@ std::list ReliablePacketBuffer::getTimedOuts(float timeout, { MutexAutoLock listlock(m_list_mutex); std::list timed_outs; - for(std::list::iterator i = m_list.begin(); - i != m_list.end(); ++i) - { - if (i->time >= timeout) { - timed_outs.push_back(*i); + for (BufferedPacket &bufferedPacket : m_list) { + if (bufferedPacket.time >= timeout) { + timed_outs.push_back(bufferedPacket); //this packet will be sent right afterwards reset timeout here - i->time = 0.0; + bufferedPacket.time = 0.0f; if (timed_outs.size() >= max_packets) break; } @@ -441,10 +430,8 @@ std::list ReliablePacketBuffer::getTimedOuts(float timeout, IncomingSplitBuffer::~IncomingSplitBuffer() { MutexAutoLock listlock(m_map_mutex); - for(std::map::iterator i = m_buf.begin(); - i != m_buf.end(); ++i) - { - delete i->second; + for (auto &i : m_buf) { + delete i.second; } } /* @@ -506,15 +493,13 @@ SharedBuffer IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable) sp->chunks[chunk_num] = chunkdata; // If not all chunks are received, return empty buffer - if (sp->allReceived() == false) + if (!sp->allReceived()) return SharedBuffer(); // Calculate total size u32 totalsize = 0; - for(std::map >::iterator i = sp->chunks.begin(); - i != sp->chunks.end(); ++i) - { - totalsize += i->second.getSize(); + for (const auto &chunk : sp->chunks) { + totalsize += chunk.second.getSize(); } SharedBuffer fulldata(totalsize); @@ -541,25 +526,21 @@ void IncomingSplitBuffer::removeUnreliableTimedOuts(float dtime, float timeout) std::list remove_queue; { MutexAutoLock listlock(m_map_mutex); - for(std::map::iterator i = m_buf.begin(); - i != m_buf.end(); ++i) - { - IncomingSplitPacket *p = i->second; + for (auto &i : m_buf) { + IncomingSplitPacket *p = i.second; // Reliable ones are not removed by timeout - if (p->reliable == true) + if (p->reliable) continue; p->time += dtime; if (p->time >= timeout) - remove_queue.push_back(i->first); + remove_queue.push_back(i.first); } } - for(std::list::iterator j = remove_queue.begin(); - j != remove_queue.end(); ++j) - { + for (u16 j : remove_queue) { MutexAutoLock listlock(m_map_mutex); LOG(dout_con<<"NOTE: Removing timed out unreliable split packet"<graphAdd(profiler_id + "_rtt", rtt); g_profiler->graphAdd(profiler_id + "_jitter", jitter); } @@ -1071,7 +1052,7 @@ bool UDPPeer::processReliableSendCommand( if (c.raw) { - originals.push_back(c.data); + originals.emplace_back(c.data); } else { originals = makeAutoSplitPacket(c.data, chunksize_max,split_sequence_number); @@ -1083,9 +1064,7 @@ bool UDPPeer::processReliableSendCommand( std::queue toadd; volatile u16 initial_sequence_number = 0; - for(std::list >::iterator i = originals.begin(); - i != originals.end(); ++i) - { + for (SharedBuffer &original : originals) { u16 seqnum = channels[c.channelnum].getOutgoingSequenceNumber(have_sequence_number); /* oops, we don't have enough sequence numbers to send this packet */ @@ -1098,7 +1077,7 @@ bool UDPPeer::processReliableSendCommand( have_initial_sequence_number = true; } - SharedBuffer reliable = makeReliablePacket(*i, seqnum); + SharedBuffer reliable = makeReliablePacket(original, seqnum); // Add base headers and make a packet BufferedPacket p = con::makePacket(address, reliable, @@ -1110,7 +1089,7 @@ bool UDPPeer::processReliableSendCommand( if (have_sequence_number) { volatile u16 pcount = 0; - while(toadd.size() > 0) { + while (!toadd.empty()) { BufferedPacket p = toadd.front(); toadd.pop(); // LOG(dout_con<getDesc() @@ -1124,35 +1103,36 @@ bool UDPPeer::processReliableSendCommand( sanity_check(channels[c.channelnum].queued_reliables.size() < 0xFFFF); return true; } - else { - volatile u16 packets_available = toadd.size(); - /* we didn't get a single sequence number no need to fill queue */ - if (!have_initial_sequence_number) - { - return false; - } - while(toadd.size() > 0) { - /* remove packet */ - toadd.pop(); - - bool successfully_put_back_sequence_number - = channels[c.channelnum].putBackSequenceNumber( - (initial_sequence_number+toadd.size() % (SEQNUM_MAX+1))); - FATAL_ERROR_IF(!successfully_put_back_sequence_number, "error"); - } - LOG(dout_con<getDesc() - << " Windowsize exceeded on reliable sending " - << c.data.getSize() << " bytes" - << std::endl << "\t\tinitial_sequence_number: " - << initial_sequence_number - << std::endl << "\t\tgot at most : " - << packets_available << " packets" - << std::endl << "\t\tpackets queued : " - << channels[c.channelnum].outgoing_reliables_sent.size() - << std::endl); + volatile u16 packets_available = toadd.size(); + /* we didn't get a single sequence number no need to fill queue */ + if (!have_initial_sequence_number) { return false; } + + while (!toadd.empty()) { + /* remove packet */ + toadd.pop(); + + bool successfully_put_back_sequence_number + = channels[c.channelnum].putBackSequenceNumber( + (initial_sequence_number+toadd.size() % (SEQNUM_MAX+1))); + + FATAL_ERROR_IF(!successfully_put_back_sequence_number, "error"); + } + + LOG(dout_con<getDesc() + << " Windowsize exceeded on reliable sending " + << c.data.getSize() << " bytes" + << std::endl << "\t\tinitial_sequence_number: " + << initial_sequence_number + << std::endl << "\t\tgot at most : " + << packets_available << " packets" + << std::endl << "\t\tpackets queued : " + << channels[c.channelnum].outgoing_reliables_sent.size() + << std::endl); + + return false; } void UDPPeer::RunCommandQueues( @@ -1161,21 +1141,21 @@ void UDPPeer::RunCommandQueues( unsigned int maxtransfer) { - for (unsigned int i = 0; i < CHANNEL_COUNT; i++) { + for (Channel &channel : channels) { unsigned int commands_processed = 0; - if ((channels[i].queued_commands.size() > 0) && - (channels[i].queued_reliables.size() < maxtransfer) && + if ((!channel.queued_commands.empty()) && + (channel.queued_reliables.size() < maxtransfer) && (commands_processed < maxcommands)) { try { - ConnectionCommand c = channels[i].queued_commands.front(); + ConnectionCommand c = channel.queued_commands.front(); LOG(dout_con << m_connection->getDesc() << " processing queued reliable command " << std::endl); // Packet is processed, remove it from queue if (processReliableSendCommand(c,max_packet_size)) { - channels[i].queued_commands.pop_front(); + channel.queued_commands.pop_front(); } else { LOG(dout_con << m_connection->getDesc() << " Failed to queue packets for peer_id: " << c.peer_id @@ -1291,10 +1271,8 @@ bool ConnectionSendThread::packetsQueued() if (!m_outgoing_queue.empty() && !peerIds.empty()) return true; - for(std::list::iterator j = peerIds.begin(); - j != peerIds.end(); ++j) - { - PeerHelper peer = m_connection->getPeerNoEx(*j); + for (u16 peerId : peerIds) { + PeerHelper peer = m_connection->getPeerNoEx(peerId); if (!peer) continue; @@ -1302,10 +1280,8 @@ bool ConnectionSendThread::packetsQueued() if (dynamic_cast(&peer) == 0) continue; - for(u16 i=0; i < CHANNEL_COUNT; i++) { - Channel *channel = &(dynamic_cast(&peer))->channels[i]; - - if (channel->queued_commands.size() > 0) { + for (Channel &channel : (dynamic_cast(&peer))->channels) { + if (channel.queued_commands.size() > 0) { return true; } } @@ -1320,10 +1296,8 @@ void ConnectionSendThread::runTimeouts(float dtime) std::list timeouted_peers; std::list peerIds = m_connection->getPeerIDs(); - for(std::list::iterator j = peerIds.begin(); - j != peerIds.end(); ++j) - { - PeerHelper peer = m_connection->getPeerNoEx(*j); + for (u16 &peerId : peerIds) { + PeerHelper peer = m_connection->getPeerNoEx(peerId); if (!peer) continue; @@ -1333,7 +1307,7 @@ void ConnectionSendThread::runTimeouts(float dtime) PROFILE(std::stringstream peerIdentifier); PROFILE(peerIdentifier << "runTimeouts[" << m_connection->getDesc() - << ";" << *j << ";RELIABLE]"); + << ";" << peerId << ";RELIABLE]"); PROFILE(ScopeProfiler peerprofiler(g_profiler, peerIdentifier.str(), SPT_AVG)); SharedBuffer data(2); // data for sending ping, required here because of goto @@ -1356,19 +1330,17 @@ void ConnectionSendThread::runTimeouts(float dtime) float resend_timeout = dynamic_cast(&peer)->getResendTimeout(); bool retry_count_exceeded = false; - for(u16 i=0; i(&peer))->channels) { std::list timed_outs; - Channel *channel = &(dynamic_cast(&peer))->channels[i]; if (dynamic_cast(&peer)->getLegacyPeer()) - channel->setWindowSize(g_settings->getU16("workaround_window_size")); + channel.setWindowSize(g_settings->getU16("workaround_window_size")); // Remove timed out incomplete unreliable split packets - channel->incoming_splits.removeUnreliableTimedOuts(dtime, m_timeout); + channel.incoming_splits.removeUnreliableTimedOuts(dtime, m_timeout); // Increment reliable packet times - channel->outgoing_reliables_sent.incrementTimeouts(dtime); + channel.outgoing_reliables_sent.incrementTimeouts(dtime); unsigned int numpeers = m_connection->m_peers.size(); @@ -1376,11 +1348,10 @@ void ConnectionSendThread::runTimeouts(float dtime) return; // Re-send timed out outgoing reliables - timed_outs = channel-> - outgoing_reliables_sent.getTimedOuts(resend_timeout, - (m_max_data_packets_per_iteration/numpeers)); + timed_outs = channel.outgoing_reliables_sent.getTimedOuts(resend_timeout, + (m_max_data_packets_per_iteration/numpeers)); - channel->UpdatePacketLossCounter(timed_outs.size()); + channel.UpdatePacketLossCounter(timed_outs.size()); g_profiler->graphAdd("packets_lost", timed_outs.size()); m_iteration_packets_avaialble -= timed_outs.size(); @@ -1392,7 +1363,7 @@ void ConnectionSendThread::runTimeouts(float dtime) u8 channelnum = readChannel(*(k->data)); u16 seqnum = readU16(&(k->data[BASE_HEADER_SIZE+1])); - channel->UpdateBytesLost(k->data.getSize()); + channel.UpdateBytesLost(k->data.getSize()); k->resend_count++; if (k-> resend_count > MAX_RELIABLE_RETRY) { @@ -1421,7 +1392,7 @@ void ConnectionSendThread::runTimeouts(float dtime) break; /* no need to check other channels if we already did timeout */ } - channel->UpdateTimers(dtime,dynamic_cast(&peer)->getLegacyPeer()); + channel.UpdateTimers(dtime,dynamic_cast(&peer)->getLegacyPeer()); } /* skip to next peer if we did timeout */ @@ -1447,12 +1418,10 @@ void ConnectionSendThread::runTimeouts(float dtime) } // Remove timed out peers - for(std::list::iterator i = timeouted_peers.begin(); - i != timeouted_peers.end(); ++i) - { - LOG(derr_con<getDesc() - <<"RunTimeouts(): Removing peer "<<(*i)<deletePeer(*i, true); + for (u16 timeouted_peer : timeouted_peers) { + LOG(derr_con << m_connection->getDesc() + << "RunTimeouts(): Removing peer "<< timeouted_peer <deletePeer(timeouted_peer, true); } } @@ -1532,39 +1501,30 @@ bool ConnectionSendThread::rawSendAsPacket(u16 peer_id, u8 channelnum, sendAsPacketReliable(p,channel); return true; } - else { - LOG(dout_con<getDesc() - <<" INFO: queueing reliable packet for peer_id: " << peer_id - <<" channel: " << channelnum - <<" seqnum: " << seqnum << std::endl); - channel->queued_reliables.push(p); - return false; - } + + LOG(dout_con<getDesc() + <<" INFO: queueing reliable packet for peer_id: " << peer_id + <<" channel: " << channelnum + <<" seqnum: " << seqnum << std::endl); + channel->queued_reliables.push(p); + return false; } - else - { - Address peer_address; - if (peer->getAddress(MTP_UDP, peer_address)) - { - // Add base headers and make a packet - BufferedPacket p = con::makePacket(peer_address, data, - m_connection->GetProtocolID(), m_connection->GetPeerID(), - channelnum); + Address peer_address; + if (peer->getAddress(MTP_UDP, peer_address)) { + // Add base headers and make a packet + BufferedPacket p = con::makePacket(peer_address, data, + m_connection->GetProtocolID(), m_connection->GetPeerID(), + channelnum); - // Send the packet - rawSend(p); - return true; - } - else { - LOG(dout_con<getDesc() - <<" INFO: dropped unreliable packet for peer_id: " << peer_id - <<" because of (yet) missing udp address" << std::endl); - return false; - } + // Send the packet + rawSend(p); + return true; } - //never reached + LOG(dout_con << m_connection->getDesc() + << " INFO: dropped unreliable packet for peer_id: " << peer_id + << " because of (yet) missing udp address" << std::endl); return false; } @@ -1731,11 +1691,8 @@ void ConnectionSendThread::disconnect() // Send to all std::list peerids = m_connection->getPeerIDs(); - for (std::list::iterator i = peerids.begin(); - i != peerids.end(); - ++i) - { - sendAsPacket(*i, 0,data,false); + for (u16 peerid : peerids) { + sendAsPacket(peerid, 0,data,false); } } @@ -1790,10 +1747,7 @@ void ConnectionSendThread::send(u16 peer_id, u8 channelnum, peer->setNextSplitSequenceNumber(channelnum,split_sequence_number); - for(std::list >::iterator i = originals.begin(); - i != originals.end(); ++i) - { - SharedBuffer original = *i; + for (const SharedBuffer &original : originals) { sendAsPacket(peer_id, channelnum, original); } } @@ -1811,11 +1765,8 @@ void ConnectionSendThread::sendToAll(u8 channelnum, SharedBuffer data) { std::list peerids = m_connection->getPeerIDs(); - for (std::list::iterator i = peerids.begin(); - i != peerids.end(); - ++i) - { - send(*i, channelnum, data); + for (u16 peerid : peerids) { + send(peerid, channelnum, data); } } @@ -1823,11 +1774,8 @@ void ConnectionSendThread::sendToAllReliable(ConnectionCommand &c) { std::list peerids = m_connection->getPeerIDs(); - for (std::list::iterator i = peerids.begin(); - i != peerids.end(); - ++i) - { - PeerHelper peer = m_connection->getPeerNoEx(*i); + for (u16 peerid : peerids) { + PeerHelper peer = m_connection->getPeerNoEx(peerid); if (!peer) continue; @@ -1842,85 +1790,84 @@ void ConnectionSendThread::sendPackets(float dtime) std::list pendingDisconnect; std::map pending_unreliable; - for(std::list::iterator - j = peerIds.begin(); - j != peerIds.end(); ++j) - { - PeerHelper peer = m_connection->getPeerNoEx(*j); + for (u16 peerId : peerIds) { + PeerHelper peer = m_connection->getPeerNoEx(peerId); //peer may have been removed if (!peer) { - LOG(dout_con<getDesc()<< " Peer not found: peer_id=" << *j << std::endl); + LOG(dout_con<getDesc()<< " Peer not found: peer_id=" << peerId + << std::endl); continue; } peer->m_increment_packets_remaining = m_iteration_packets_avaialble/m_connection->m_peers.size(); - if (dynamic_cast(&peer) == 0) - { + UDPPeer *udpPeer = dynamic_cast(&peer); + + if (!udpPeer) { continue; } - if (dynamic_cast(&peer)->m_pending_disconnect) - { - pendingDisconnect.push_back(*j); + if (udpPeer->m_pending_disconnect) { + pendingDisconnect.push_back(peerId); } PROFILE(std::stringstream peerIdentifier); - PROFILE(peerIdentifier << "sendPackets[" << m_connection->getDesc() << ";" << *j << ";RELIABLE]"); + PROFILE(peerIdentifier << "sendPackets[" << m_connection->getDesc() << ";" << peerId + << ";RELIABLE]"); PROFILE(ScopeProfiler peerprofiler(g_profiler, peerIdentifier.str(), SPT_AVG)); LOG(dout_con<getDesc() - << " Handle per peer queues: peer_id=" << *j - << " packet quota: " << peer->m_increment_packets_remaining << std::endl); + << " Handle per peer queues: peer_id=" << peerId + << " packet quota: " << peer->m_increment_packets_remaining << std::endl); + // first send queued reliable packets for all peers (if possible) - for (unsigned int i=0; i < CHANNEL_COUNT; i++) - { + for (unsigned int i=0; i < CHANNEL_COUNT; i++) { + Channel &channel = udpPeer->channels[i]; u16 next_to_ack = 0; - dynamic_cast(&peer)->channels[i].outgoing_reliables_sent.getFirstSeqnum(next_to_ack); + + channel.outgoing_reliables_sent.getFirstSeqnum(next_to_ack); u16 next_to_receive = 0; - dynamic_cast(&peer)->channels[i].incoming_reliables.getFirstSeqnum(next_to_receive); + channel.incoming_reliables.getFirstSeqnum(next_to_receive); LOG(dout_con<getDesc()<< "\t channel: " << i << ", peer quota:" << peer->m_increment_packets_remaining << std::endl << "\t\t\treliables on wire: " - << dynamic_cast(&peer)->channels[i].outgoing_reliables_sent.size() + << channel.outgoing_reliables_sent.size() << ", waiting for ack for " << next_to_ack << std::endl << "\t\t\tincoming_reliables: " - << dynamic_cast(&peer)->channels[i].incoming_reliables.size() + << channel.incoming_reliables.size() << ", next reliable packet: " - << dynamic_cast(&peer)->channels[i].readNextIncomingSeqNum() + << channel.readNextIncomingSeqNum() << ", next queued: " << next_to_receive << std::endl << "\t\t\treliables queued : " - << dynamic_cast(&peer)->channels[i].queued_reliables.size() + << channel.queued_reliables.size() << std::endl << "\t\t\tqueued commands : " - << dynamic_cast(&peer)->channels[i].queued_commands.size() + << channel.queued_commands.size() << std::endl); - while ((dynamic_cast(&peer)->channels[i].queued_reliables.size() > 0) && - (dynamic_cast(&peer)->channels[i].outgoing_reliables_sent.size() - < dynamic_cast(&peer)->channels[i].getWindowSize())&& + while ((!channel.queued_reliables.empty()) && + (channel.outgoing_reliables_sent.size() + < channel.getWindowSize())&& (peer->m_increment_packets_remaining > 0)) { - BufferedPacket p = dynamic_cast(&peer)->channels[i].queued_reliables.front(); - dynamic_cast(&peer)->channels[i].queued_reliables.pop(); - Channel* channel = &(dynamic_cast(&peer)->channels[i]); + BufferedPacket p = channel.queued_reliables.front(); + channel.queued_reliables.pop(); LOG(dout_con<getDesc() <<" INFO: sending a queued reliable packet " <<" channel: " << i <<", seqnum: " << readU16(&p.data[BASE_HEADER_SIZE+1]) << std::endl); - sendAsPacketReliable(p,channel); + sendAsPacketReliable(p, &channel); peer->m_increment_packets_remaining--; } } } - if (m_outgoing_queue.size()) - { + if (!m_outgoing_queue.empty()) { LOG(dout_con<getDesc() << " Handle non reliable queue (" << m_outgoing_queue.size() << " pkts)" << std::endl); @@ -1944,9 +1891,9 @@ void ConnectionSendThread::sendPackets(float dtime) << ", size: " << packet.data.getSize() <m_increment_packets_remaining = @@ -1965,13 +1912,10 @@ void ConnectionSendThread::sendPackets(float dtime) } } - for(std::list::iterator - k = pendingDisconnect.begin(); - k != pendingDisconnect.end(); ++k) - { - if (!pending_unreliable[*k]) + for (u16 peerId : pendingDisconnect) { + if (!pending_unreliable[peerId]) { - m_connection->deletePeer(*k,false); + m_connection->deletePeer(peerId,false); } } } @@ -2237,21 +2181,16 @@ bool ConnectionReceiveThread::getFromBuffers(u16 &peer_id, SharedBuffer &dst { std::list peerids = m_connection->getPeerIDs(); - for(std::list::iterator j = peerids.begin(); - j != peerids.end(); ++j) - { - PeerHelper peer = m_connection->getPeerNoEx(*j); + for (u16 peerid : peerids) { + PeerHelper peer = m_connection->getPeerNoEx(peerid); if (!peer) continue; if (dynamic_cast(&peer) == 0) continue; - for(u16 i=0; i(&peer))->channels[i]; - - if (checkIncomingBuffers(channel, peer_id, dst)) { + for (Channel &channel : (dynamic_cast(&peer))->channels) { + if (checkIncomingBuffers(&channel, peer_id, dst)) { return true; } } @@ -2425,8 +2364,7 @@ SharedBuffer ConnectionReceiveThread::processPacket(Channel *channel, LOG(dout_con<getDesc() <<"DISCO: Removing peer "<<(peer_id)<deletePeer(peer_id, false) == false) - { + if (!m_connection->deletePeer(peer_id, false)) { derr_con<getDesc() <<"DISCO: Peer not found"<::iterator - j = m_peers.begin(); - j != m_peers.end(); ++j) - { - delete j->second; + for (auto &peer : m_peers) { + delete peer.second; } } @@ -2734,10 +2669,8 @@ u16 Connection::lookupPeer(Address& sender) std::list Connection::getPeers() { std::list list; - for(std::map::iterator j = m_peers.begin(); - j != m_peers.end(); ++j) - { - Peer *peer = j->second; + for (auto &p : m_peers) { + Peer *peer = p.second; list.push_back(peer); } return list; @@ -2904,25 +2837,25 @@ float Connection::getLocalStat(rate_stat_type type) float retval = 0.0; - for (u16 j=0; j(&peer)->channels) { switch(type) { case CUR_DL_RATE: - retval += dynamic_cast(&peer)->channels[j].getCurrentDownloadRateKB(); + retval += channel.getCurrentDownloadRateKB(); break; case AVG_DL_RATE: - retval += dynamic_cast(&peer)->channels[j].getAvgDownloadRateKB(); + retval += channel.getAvgDownloadRateKB(); break; case CUR_INC_RATE: - retval += dynamic_cast(&peer)->channels[j].getCurrentIncomingRateKB(); + retval += channel.getCurrentIncomingRateKB(); break; case AVG_INC_RATE: - retval += dynamic_cast(&peer)->channels[j].getAvgIncomingRateKB(); + retval += channel.getAvgIncomingRateKB(); break; case AVG_LOSS_RATE: - retval += dynamic_cast(&peer)->channels[j].getAvgLossRateKB(); + retval += channel.getAvgLossRateKB(); break; case CUR_LOSS_RATE: - retval += dynamic_cast(&peer)->channels[j].getCurrentLossRateKB(); + retval += channel.getCurrentLossRateKB(); break; default: FATAL_ERROR("Connection::getLocalStat Invalid stat type"); -- cgit v1.2.3