repair broken node bandwidth stats

This commit is contained in:
Stephen Birarda 2015-10-06 14:09:21 -07:00
parent 5989cad054
commit 9079f891e9
4 changed files with 17 additions and 8 deletions

View file

@ -274,10 +274,14 @@ void LimitedNodeList::fillPacketHeader(const NLPacket& packet, const QUuid& conn
qint64 LimitedNodeList::sendUnreliablePacket(const NLPacket& packet, const Node& destinationNode) { qint64 LimitedNodeList::sendUnreliablePacket(const NLPacket& packet, const Node& destinationNode) {
Q_ASSERT(!packet.isPartOfMessage()); Q_ASSERT(!packet.isPartOfMessage());
if (!destinationNode.getActiveSocket()) { if (!destinationNode.getActiveSocket()) {
return 0; return 0;
} }
emit dataSent(destinationNode.getType(), packet.getDataSize()); emit dataSent(destinationNode.getType(), packet.getDataSize());
destinationNode.recordBytesSent(packet.getDataSize());
return sendUnreliablePacket(packet, *destinationNode.getActiveSocket(), destinationNode.getConnectionSecret()); return sendUnreliablePacket(packet, *destinationNode.getActiveSocket(), destinationNode.getConnectionSecret());
} }
@ -298,7 +302,10 @@ qint64 LimitedNodeList::sendPacket(std::unique_ptr<NLPacket> packet, const Node&
if (!destinationNode.getActiveSocket()) { if (!destinationNode.getActiveSocket()) {
return 0; return 0;
} }
emit dataSent(destinationNode.getType(), packet->getDataSize()); emit dataSent(destinationNode.getType(), packet->getDataSize());
destinationNode.recordBytesSent(packet->getDataSize());
return sendPacket(std::move(packet), *destinationNode.getActiveSocket(), destinationNode.getConnectionSecret()); return sendPacket(std::move(packet), *destinationNode.getActiveSocket(), destinationNode.getConnectionSecret());
} }

View file

@ -232,22 +232,22 @@ BandwidthRecorder& getBandwidthRecorder(const QUuid & uuid) {
return *PEER_BANDWIDTH[uuid].data(); return *PEER_BANDWIDTH[uuid].data();
} }
void NetworkPeer::recordBytesSent(int count) { void NetworkPeer::recordBytesSent(int count) const {
auto& bw = getBandwidthRecorder(_uuid); auto& bw = getBandwidthRecorder(_uuid);
bw.updateOutboundData(0, count); bw.updateOutboundData(0, count);
} }
void NetworkPeer::recordBytesReceived(int count) { void NetworkPeer::recordBytesReceived(int count) const {
auto& bw = getBandwidthRecorder(_uuid); auto& bw = getBandwidthRecorder(_uuid);
bw.updateInboundData(0, count); bw.updateInboundData(0, count);
} }
float NetworkPeer::getOutboundBandwidth() { float NetworkPeer::getOutboundBandwidth() const {
auto& bw = getBandwidthRecorder(_uuid); auto& bw = getBandwidthRecorder(_uuid);
return bw.getAverageOutputKilobitsPerSecond(0); return bw.getAverageOutputKilobitsPerSecond(0);
} }
float NetworkPeer::getInboundBandwidth() { float NetworkPeer::getInboundBandwidth() const {
auto& bw = getBandwidthRecorder(_uuid); auto& bw = getBandwidthRecorder(_uuid);
return bw.getAverageInputKilobitsPerSecond(0); return bw.getAverageInputKilobitsPerSecond(0);
} }

View file

@ -70,11 +70,11 @@ public:
void incrementConnectionAttempts() { ++_connectionAttempts; } void incrementConnectionAttempts() { ++_connectionAttempts; }
void resetConnectionAttempts() { _connectionAttempts = 0; } void resetConnectionAttempts() { _connectionAttempts = 0; }
void recordBytesSent(int count); void recordBytesSent(int count) const;
void recordBytesReceived(int count); void recordBytesReceived(int count) const;
float getOutboundBandwidth(); // in kbps float getOutboundBandwidth() const; // in kbps
float getInboundBandwidth(); // in kbps float getInboundBandwidth() const; // in kbps
friend QDataStream& operator<<(QDataStream& out, const NetworkPeer& peer); friend QDataStream& operator<<(QDataStream& out, const NetworkPeer& peer);
friend QDataStream& operator>>(QDataStream& in, NetworkPeer& peer); friend QDataStream& operator>>(QDataStream& in, NetworkPeer& peer);

View file

@ -404,6 +404,8 @@ void PacketReceiver::handleVerifiedPacket(std::unique_ptr<udt::Packet> packet) {
if (matchingNode) { if (matchingNode) {
emit dataReceived(matchingNode->getType(), nlPacket->getDataSize()); emit dataReceived(matchingNode->getType(), nlPacket->getDataSize());
matchingNode->recordBytesReceived(nlPacket->getDataSize());
QMetaMethod metaMethod = listener.second; QMetaMethod metaMethod = listener.second;
static const QByteArray QSHAREDPOINTER_NODE_NORMALIZED = QMetaObject::normalizedType("QSharedPointer<Node>"); static const QByteArray QSHAREDPOINTER_NODE_NORMALIZED = QMetaObject::normalizedType("QSharedPointer<Node>");