From 9079f891e97a5c82d2a4f1137b9dca10e2b7e5a0 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 6 Oct 2015 14:09:21 -0700 Subject: [PATCH] repair broken node bandwidth stats --- libraries/networking/src/LimitedNodeList.cpp | 7 +++++++ libraries/networking/src/NetworkPeer.cpp | 8 ++++---- libraries/networking/src/NetworkPeer.h | 8 ++++---- libraries/networking/src/PacketReceiver.cpp | 2 ++ 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index c13a82f821..41789315c1 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -274,10 +274,14 @@ void LimitedNodeList::fillPacketHeader(const NLPacket& packet, const QUuid& conn qint64 LimitedNodeList::sendUnreliablePacket(const NLPacket& packet, const Node& destinationNode) { Q_ASSERT(!packet.isPartOfMessage()); + if (!destinationNode.getActiveSocket()) { return 0; } + emit dataSent(destinationNode.getType(), packet.getDataSize()); + destinationNode.recordBytesSent(packet.getDataSize()); + return sendUnreliablePacket(packet, *destinationNode.getActiveSocket(), destinationNode.getConnectionSecret()); } @@ -298,7 +302,10 @@ qint64 LimitedNodeList::sendPacket(std::unique_ptr packet, const Node& if (!destinationNode.getActiveSocket()) { return 0; } + emit dataSent(destinationNode.getType(), packet->getDataSize()); + destinationNode.recordBytesSent(packet->getDataSize()); + return sendPacket(std::move(packet), *destinationNode.getActiveSocket(), destinationNode.getConnectionSecret()); } diff --git a/libraries/networking/src/NetworkPeer.cpp b/libraries/networking/src/NetworkPeer.cpp index b17656aea0..9253243a7f 100644 --- a/libraries/networking/src/NetworkPeer.cpp +++ b/libraries/networking/src/NetworkPeer.cpp @@ -232,22 +232,22 @@ BandwidthRecorder& getBandwidthRecorder(const QUuid & uuid) { return *PEER_BANDWIDTH[uuid].data(); } -void NetworkPeer::recordBytesSent(int count) { +void NetworkPeer::recordBytesSent(int count) const { auto& bw = getBandwidthRecorder(_uuid); bw.updateOutboundData(0, count); } -void NetworkPeer::recordBytesReceived(int count) { +void NetworkPeer::recordBytesReceived(int count) const { auto& bw = getBandwidthRecorder(_uuid); bw.updateInboundData(0, count); } -float NetworkPeer::getOutboundBandwidth() { +float NetworkPeer::getOutboundBandwidth() const { auto& bw = getBandwidthRecorder(_uuid); return bw.getAverageOutputKilobitsPerSecond(0); } -float NetworkPeer::getInboundBandwidth() { +float NetworkPeer::getInboundBandwidth() const { auto& bw = getBandwidthRecorder(_uuid); return bw.getAverageInputKilobitsPerSecond(0); } diff --git a/libraries/networking/src/NetworkPeer.h b/libraries/networking/src/NetworkPeer.h index 8446586121..c10d44bfa9 100644 --- a/libraries/networking/src/NetworkPeer.h +++ b/libraries/networking/src/NetworkPeer.h @@ -70,11 +70,11 @@ public: void incrementConnectionAttempts() { ++_connectionAttempts; } void resetConnectionAttempts() { _connectionAttempts = 0; } - void recordBytesSent(int count); - void recordBytesReceived(int count); + void recordBytesSent(int count) const; + void recordBytesReceived(int count) const; - float getOutboundBandwidth(); // in kbps - float getInboundBandwidth(); // in kbps + float getOutboundBandwidth() const; // in kbps + float getInboundBandwidth() const; // in kbps friend QDataStream& operator<<(QDataStream& out, const NetworkPeer& peer); friend QDataStream& operator>>(QDataStream& in, NetworkPeer& peer); diff --git a/libraries/networking/src/PacketReceiver.cpp b/libraries/networking/src/PacketReceiver.cpp index 0efb8bba7c..9d25724f6c 100644 --- a/libraries/networking/src/PacketReceiver.cpp +++ b/libraries/networking/src/PacketReceiver.cpp @@ -404,6 +404,8 @@ void PacketReceiver::handleVerifiedPacket(std::unique_ptr packet) { if (matchingNode) { emit dataReceived(matchingNode->getType(), nlPacket->getDataSize()); + matchingNode->recordBytesReceived(nlPacket->getDataSize()); + QMetaMethod metaMethod = listener.second; static const QByteArray QSHAREDPOINTER_NODE_NORMALIZED = QMetaObject::normalizedType("QSharedPointer");