From bee895ba0a3a37a9703bd979771bb9bac03107d1 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Sat, 31 Jan 2015 20:02:04 -0800 Subject: [PATCH] capture network bandwidth stats from NodeList rather than various places --- .gitignore | 2 + interface/src/Application.cpp | 31 +---- interface/src/Audio.cpp | 6 - interface/src/BandwidthRecorder.cpp | 64 --------- interface/src/DatagramProcessor.cpp | 19 ++- interface/src/MetavoxelSystem.cpp | 4 - interface/src/ui/BandwidthDialog.cpp | 7 +- interface/src/ui/BandwidthDialog.h | 1 + interface/src/ui/Stats.cpp | 10 +- .../networking/src/BandwidthRecorder.cpp | 123 ++++++++++++++++++ .../networking}/src/BandwidthRecorder.h | 41 +++--- libraries/networking/src/LimitedNodeList.cpp | 27 +++- libraries/networking/src/LimitedNodeList.h | 5 + libraries/networking/src/Node.cpp | 44 +++---- libraries/networking/src/Node.h | 8 +- libraries/networking/src/NodeList.cpp | 4 + tools/refresh-tags.sh | 2 +- 17 files changed, 239 insertions(+), 159 deletions(-) delete mode 100644 interface/src/BandwidthRecorder.cpp create mode 100644 libraries/networking/src/BandwidthRecorder.cpp rename {interface => libraries/networking}/src/BandwidthRecorder.h (63%) diff --git a/.gitignore b/.gitignore index 34f11c273a..16b588bcd2 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,5 @@ interface/resources/visage/* # Ignore interfaceCache for Linux users interface/interfaceCache/ + +TAGS diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 8f31872437..c984df5707 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -433,6 +433,12 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : connect(this, SIGNAL(aboutToQuit()), this, SLOT(saveScripts())); connect(this, SIGNAL(aboutToQuit()), this, SLOT(aboutToQuit())); + // hook up bandwidth estimator + connect(nodeList.data(), SIGNAL(dataSent(const quint8, const int)), + &_bandwidthRecorder, SLOT(updateOutboundData(const quint8, const int))); + connect(nodeList.data(), SIGNAL(dataReceived(const quint8, const int)), + &_bandwidthRecorder, SLOT(updateInboundData(const quint8, const int))); + // check first run... bool firstRun = SettingHandles::firstRun.get(); if (firstRun) { @@ -771,25 +777,8 @@ void Application::updateProjectionMatrix(Camera& camera, bool updateViewFrustum) void Application::controlledBroadcastToNodes(const QByteArray& packet, const NodeSet& destinationNodeTypes) { foreach(NodeType_t type, destinationNodeTypes) { - // Perform the broadcast for one type - int nReceivingNodes = DependencyManager::get()->broadcastToNodes(packet, NodeSet() << type); - - // Feed number of bytes to corresponding channel of the bandwidth meter, if any (done otherwise) - double bandwidth_amount = nReceivingNodes * packet.size(); - switch (type) { - case NodeType::Agent: - case NodeType::AvatarMixer: - _bandwidthRecorder.avatarsChannel->output.updateValue(bandwidth_amount); - _bandwidthRecorder.totalChannel->input.updateValue(bandwidth_amount); - break; - case NodeType::EntityServer: - _bandwidthRecorder.octreeChannel->output.updateValue(bandwidth_amount); - _bandwidthRecorder.totalChannel->output.updateValue(bandwidth_amount); - break; - default: - continue; - } + DependencyManager::get()->broadcastToNodes(packet, NodeSet() << type); } } @@ -2383,10 +2372,6 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node // make sure we still have an active socket nodeList->writeUnverifiedDatagram(reinterpret_cast(queryPacket), packetLength, node); - - // Feed number of bytes to corresponding channel of the bandwidth meter - _bandwidthRecorder.octreeChannel->output.updateValue(packetLength); - _bandwidthRecorder.totalChannel->output.updateValue(packetLength); } }); } @@ -3374,8 +3359,6 @@ int Application::parseOctreeStats(const QByteArray& packet, const SharedNodePoin } void Application::packetSent(quint64 length) { - _bandwidthRecorder.octreeChannel->output.updateValue(length); - _bandwidthRecorder.totalChannel->output.updateValue(length); } const QString SETTINGS_KEY = "Settings"; diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 2bc5aa5023..2c34518ba5 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -768,9 +768,6 @@ void Audio::handleAudioInput() { int packetBytes = currentPacketPtr - audioDataPacket; nodeList->writeDatagram(audioDataPacket, packetBytes, audioMixer); _outgoingAvatarAudioSequenceNumber++; - - Application::getInstance()->getBandwidthRecorder()->audioChannel->output.updateValue(packetBytes); - Application::getInstance()->getBandwidthRecorder()->totalChannel->output.updateValue(packetBytes); } delete[] inputAudioSamples; } @@ -828,9 +825,6 @@ void Audio::addReceivedAudioToStream(const QByteArray& audioByteArray) { // Audio output must exist and be correctly set up if we're going to process received audio _receivedAudioStream.parseData(audioByteArray); } - - Application::getInstance()->getBandwidthRecorder()->audioChannel->input.updateValue(audioByteArray.size()); - Application::getInstance()->getBandwidthRecorder()->totalChannel->input.updateValue(audioByteArray.size()); } void Audio::parseAudioEnvironmentData(const QByteArray &packet) { diff --git a/interface/src/BandwidthRecorder.cpp b/interface/src/BandwidthRecorder.cpp deleted file mode 100644 index db59c680f5..0000000000 --- a/interface/src/BandwidthRecorder.cpp +++ /dev/null @@ -1,64 +0,0 @@ -// -// BandwidthMeter.cpp -// interface/src/ui -// -// Created by Seth Alves on 2015-1-30 -// Copyright 2015 High Fidelity, Inc. -// -// Based on code by Tobias Schwinger -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#include -#include "BandwidthRecorder.h" - - -BandwidthRecorder::Channel::Channel(char const* const caption, - char const* unitCaption, - double unitScale, - unsigned colorRGBA) : - caption(caption), - unitCaption(unitCaption), - unitScale(unitScale), - colorRGBA(colorRGBA) -{ -} - - - -BandwidthRecorder::BandwidthRecorder() { -} - - -BandwidthRecorder::~BandwidthRecorder() { - delete audioChannel; - delete avatarsChannel; - delete octreeChannel; - delete metavoxelsChannel; - delete totalChannel; -} - - -BandwidthRecorder::Stream::Stream(float msToAverage) : _value(0.0f), _msToAverage(msToAverage) { - _prevTime.start(); -} - - -void BandwidthRecorder::Stream::updateValue(double amount) { - - // Determine elapsed time - double dt = (double)_prevTime.nsecsElapsed() / 1000000.0; // ns to ms - - // Ignore this value when timer imprecision yields dt = 0 - if (dt == 0.0) { - return; - } - - _prevTime.start(); - - // Compute approximate average - _value = glm::mix(_value, amount / dt, - glm::clamp(dt / _msToAverage, 0.0, 1.0)); -} diff --git a/interface/src/DatagramProcessor.cpp b/interface/src/DatagramProcessor.cpp index 01c1c0d0c2..eb589140d0 100644 --- a/interface/src/DatagramProcessor.cpp +++ b/interface/src/DatagramProcessor.cpp @@ -39,8 +39,7 @@ void DatagramProcessor::processDatagrams() { while (DependencyManager::get()->getNodeSocket().hasPendingDatagrams()) { incomingPacket.resize(nodeList->getNodeSocket().pendingDatagramSize()); - nodeList->getNodeSocket().readDatagram(incomingPacket.data(), incomingPacket.size(), - senderSockAddr.getAddressPointer(), senderSockAddr.getPortPointer()); + nodeList->readDatagram(incomingPacket, senderSockAddr.getAddressPointer(), senderSockAddr.getPortPointer()); _inPacketCount++; _inByteCount += incomingPacket.size(); @@ -73,7 +72,7 @@ void DatagramProcessor::processDatagrams() { if (audioMixer) { audioMixer->setLastHeardMicrostamp(usecTimestampNow()); - audioMixer->recordBytesReceived(incomingPacket.size()); + // audioMixer->recordBytesReceived(incomingPacket.size()); } break; @@ -82,8 +81,8 @@ void DatagramProcessor::processDatagrams() { // this will keep creatorTokenIDs to IDs mapped correctly EntityItemID::handleAddEntityResponse(incomingPacket); application->getEntities()->getTree()->handleAddEntityResponse(incomingPacket); - application->_bandwidthRecorder.octreeChannel->input.updateValue(incomingPacket.size()); - application->_bandwidthRecorder.totalChannel->input.updateValue(incomingPacket.size()); + // application->_bandwidthRecorder.octreeChannel->input.updateValue(incomingPacket.size()); + // application->_bandwidthRecorder.totalChannel->input.updateValue(incomingPacket.size()); break; case PacketTypeEntityData: case PacketTypeEntityErase: @@ -97,8 +96,8 @@ void DatagramProcessor::processDatagrams() { // add this packet to our list of octree packets and process them on the octree data processing application->_octreeProcessor.queueReceivedPacket(matchedNode, incomingPacket); } - application->_bandwidthRecorder.octreeChannel->input.updateValue(incomingPacket.size()); - application->_bandwidthRecorder.totalChannel->input.updateValue(incomingPacket.size()); + // application->_bandwidthRecorder.octreeChannel->input.updateValue(incomingPacket.size()); + // application->_bandwidthRecorder.totalChannel->input.updateValue(incomingPacket.size()); break; } case PacketTypeMetavoxelData: @@ -113,15 +112,15 @@ void DatagramProcessor::processDatagrams() { if (avatarMixer) { avatarMixer->setLastHeardMicrostamp(usecTimestampNow()); - avatarMixer->recordBytesReceived(incomingPacket.size()); + // avatarMixer->recordBytesReceived(incomingPacket.size()); QMetaObject::invokeMethod(&application->getAvatarManager(), "processAvatarMixerDatagram", Q_ARG(const QByteArray&, incomingPacket), Q_ARG(const QWeakPointer&, avatarMixer)); } - application->_bandwidthRecorder.avatarsChannel->input.updateValue(incomingPacket.size()); - application->_bandwidthRecorder.totalChannel->input.updateValue(incomingPacket.size()); + // application->_bandwidthRecorder.avatarsChannel->input.updateValue(incomingPacket.size()); + // application->_bandwidthRecorder.totalChannel->input.updateValue(incomingPacket.size()); break; } case PacketTypeDomainConnectionDenied: { diff --git a/interface/src/MetavoxelSystem.cpp b/interface/src/MetavoxelSystem.cpp index c81286b579..df8632d875 100644 --- a/interface/src/MetavoxelSystem.cpp +++ b/interface/src/MetavoxelSystem.cpp @@ -899,8 +899,6 @@ int MetavoxelSystemClient::parseData(const QByteArray& packet) { } else { QMetaObject::invokeMethod(&_sequencer, "receivedDatagram", Q_ARG(const QByteArray&, packet)); } - Application::getInstance()->getBandwidthRecorder()->metavoxelsChannel->input.updateValue(packet.size()); - Application::getInstance()->getBandwidthRecorder()->totalChannel->input.updateValue(packet.size()); } return packet.size(); } @@ -1016,8 +1014,6 @@ void MetavoxelSystemClient::sendDatagram(const QByteArray& data) { } else { DependencyManager::get()->writeDatagram(data, _node); } - Application::getInstance()->getBandwidthRecorder()->metavoxelsChannel->output.updateValue(data.size()); - Application::getInstance()->getBandwidthRecorder()->totalChannel->output.updateValue(data.size()); } } diff --git a/interface/src/ui/BandwidthDialog.cpp b/interface/src/ui/BandwidthDialog.cpp index 8b1afc9abf..88d30ae5a6 100644 --- a/interface/src/ui/BandwidthDialog.cpp +++ b/interface/src/ui/BandwidthDialog.cpp @@ -47,8 +47,8 @@ QLabel* BandwidthDialog::ChannelDisplay::setupLabel(QFormLayout* form) { void BandwidthDialog::ChannelDisplay::setLabelText() { std::string strBuf = - std::to_string ((int) (ch->input.getValue() * ch->unitScale)) + "/" + - std::to_string ((int) (ch->output.getValue() * ch->unitScale)) + " " + ch->unitCaption; + std::to_string ((int) (ch->getAverageInputKilobitsPerSecond() * ch->unitScale)) + "/" + + std::to_string ((int) (ch->getAverageOutputKilobitsPerSecond() * ch->unitScale)) + " " + ch->unitCaption; label->setText(strBuf.c_str()); } @@ -68,6 +68,7 @@ BandwidthDialog::BandwidthDialog(QWidget* parent, BandwidthRecorder* model) : avatarsChannelDisplay = new ChannelDisplay(_model->avatarsChannel, form); octreeChannelDisplay = new ChannelDisplay(_model->octreeChannel, form); metavoxelsChannelDisplay = new ChannelDisplay(_model->metavoxelsChannel, form); + otherChannelDisplay = new ChannelDisplay(_model->otherChannel, form); totalChannelDisplay = new ChannelDisplay(_model->totalChannel, form); } @@ -77,6 +78,7 @@ BandwidthDialog::~BandwidthDialog() { delete avatarsChannelDisplay; delete octreeChannelDisplay; delete metavoxelsChannelDisplay; + delete otherChannelDisplay; delete totalChannelDisplay; } @@ -86,6 +88,7 @@ void BandwidthDialog::paintEvent(QPaintEvent* event) { avatarsChannelDisplay->setLabelText(); octreeChannelDisplay->setLabelText(); metavoxelsChannelDisplay->setLabelText(); + otherChannelDisplay->setLabelText(); totalChannelDisplay->setLabelText(); this->QDialog::paintEvent(event); diff --git a/interface/src/ui/BandwidthDialog.h b/interface/src/ui/BandwidthDialog.h index a171c98e12..7f5a9068b4 100644 --- a/interface/src/ui/BandwidthDialog.h +++ b/interface/src/ui/BandwidthDialog.h @@ -42,6 +42,7 @@ public: ChannelDisplay* avatarsChannelDisplay; ChannelDisplay* octreeChannelDisplay; ChannelDisplay* metavoxelsChannelDisplay; + ChannelDisplay* otherChannelDisplay; // sums of all the other channels ChannelDisplay* totalChannelDisplay; diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp index a913aff332..0416bf31ed 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -216,6 +216,8 @@ void Stats::display( QLocale locale(QLocale::English); std::stringstream octreeStats; + BandwidthRecorder* bandwidthRecorder = Application::getInstance()->getBandwidthRecorder(); + if (_lastHorizontalOffset != horizontalOffset) { resetWidth(glCanvas->width(), horizontalOffset); _lastHorizontalOffset = horizontalOffset; @@ -440,8 +442,12 @@ void Stats::display( SharedNodePointer avatarMixer = DependencyManager::get()->soloNodeOfType(NodeType::AvatarMixer); if (avatarMixer) { sprintf(avatarMixerStats, "Avatar Mixer: %.f kbps, %.f pps", - roundf(avatarMixer->getAverageKilobitsPerSecond()), - roundf(avatarMixer->getAveragePacketsPerSecond())); + // roundf(avatarMixer->getAverageKilobitsPerSecond()), + // roundf(avatarMixer->getAveragePacketsPerSecond()) + roundf(bandwidthRecorder->audioChannel->getAverageInputKilobitsPerSecond() + + bandwidthRecorder->audioChannel->getAverageOutputKilobitsPerSecond()), + roundf(bandwidthRecorder->audioChannel->getAverageInputPacketsPerSecond() + + bandwidthRecorder->audioChannel->getAverageOutputPacketsPerSecond())); } else { sprintf(avatarMixerStats, "No Avatar Mixer"); } diff --git a/libraries/networking/src/BandwidthRecorder.cpp b/libraries/networking/src/BandwidthRecorder.cpp new file mode 100644 index 0000000000..e56bae16dd --- /dev/null +++ b/libraries/networking/src/BandwidthRecorder.cpp @@ -0,0 +1,123 @@ +// +// BandwidthMeter.cpp +// interface/src/ui +// +// Created by Seth Alves on 2015-1-30 +// Copyright 2015 High Fidelity, Inc. +// +// Based on code by Tobias Schwinger +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +// #include +#include "BandwidthRecorder.h" + + +BandwidthRecorder::Channel::Channel(char const* const caption, + char const* unitCaption, + double unitScale, + unsigned colorRGBA) : + caption(caption), + unitCaption(unitCaption), + unitScale(unitScale), + colorRGBA(colorRGBA) +{ +} + +float BandwidthRecorder::Channel::getAverageInputPacketsPerSecond() { + return (1 / _input.getEventDeltaAverage()); +} + +float BandwidthRecorder::Channel::getAverageOutputPacketsPerSecond() { + return (1 / _output.getEventDeltaAverage()); +} + +float BandwidthRecorder::Channel::getAverageInputKilobitsPerSecond() { + return (_input.getAverageSampleValuePerSecond() * (8.0f / 1000)); +} + +float BandwidthRecorder::Channel::getAverageOutputKilobitsPerSecond() { + return (_output.getAverageSampleValuePerSecond() * (8.0f / 1000)); +} + + +void BandwidthRecorder::Channel::updateInputAverage(const float sample) { + _input.updateAverage(sample); +} + +void BandwidthRecorder::Channel::updateOutputAverage(const float sample) { + _output.updateAverage(sample); +} + + + +BandwidthRecorder::BandwidthRecorder() { +} + + +BandwidthRecorder::~BandwidthRecorder() { + delete audioChannel; + delete avatarsChannel; + delete octreeChannel; + delete metavoxelsChannel; + delete totalChannel; +} + + +void BandwidthRecorder::updateInboundData(const quint8 channelType, const int sample) { + + totalChannel->updateInputAverage(sample); + + // see Node.h NodeType + switch (channelType) { + case NodeType::DomainServer: + case NodeType::EntityServer: + octreeChannel->updateInputAverage(sample); + break; + case NodeType::MetavoxelServer: + case NodeType::EnvironmentServer: + metavoxelsChannel->updateInputAverage(sample); + break; + case NodeType::AudioMixer: + audioChannel->updateInputAverage(sample); + break; + case NodeType::Agent: + case NodeType::AvatarMixer: + avatarsChannel->updateInputAverage(sample); + break; + case NodeType::Unassigned: + default: + otherChannel->updateInputAverage(sample); + break; + } +} + +void BandwidthRecorder::updateOutboundData(const quint8 channelType, const int sample) { + + totalChannel->updateOutputAverage(sample); + + // see Node.h NodeType + switch (channelType) { + case NodeType::DomainServer: + case NodeType::EntityServer: + octreeChannel->updateOutputAverage(sample); + break; + case NodeType::MetavoxelServer: + case NodeType::EnvironmentServer: + metavoxelsChannel->updateOutputAverage(sample); + break; + case NodeType::AudioMixer: + audioChannel->updateOutputAverage(sample); + break; + case NodeType::Agent: + case NodeType::AvatarMixer: + avatarsChannel->updateOutputAverage(sample); + break; + case NodeType::Unassigned: + default: + otherChannel->updateOutputAverage(sample); + break; + } +} diff --git a/interface/src/BandwidthRecorder.h b/libraries/networking/src/BandwidthRecorder.h similarity index 63% rename from interface/src/BandwidthRecorder.h rename to libraries/networking/src/BandwidthRecorder.h index 8613c5fdcd..6f0ccf2c04 100644 --- a/interface/src/BandwidthRecorder.h +++ b/libraries/networking/src/BandwidthRecorder.h @@ -14,42 +14,46 @@ #ifndef hifi_BandwidthRecorder_h #define hifi_BandwidthRecorder_h +#include #include +#include "Node.h" +#include "SimpleMovingAverage.h" -const double DEFAULT_UNIT_SCALE = 8000.0 / 1024.0; +const double DEFAULT_UNIT_SCALE = 1.0; const unsigned int COLOR0 = 0x33cc99ff; const unsigned int COLOR1 = 0xffef40c0; const unsigned int COLOR2 = 0xd0d0d0a0; -class BandwidthRecorder { +class BandwidthRecorder : public QObject { + Q_OBJECT + public: BandwidthRecorder(); ~BandwidthRecorder(); - // keep track of data rate in one direction - class Stream { - public: - Stream(float msToAverage = 3000.0f); - void updateValue(double amount); - double getValue() const { return _value; } - private: - double _value; // Current value. - double _msToAverage; // Milliseconds to average. - QElapsedTimer _prevTime; // Time of last feed. - }; - // keep track of data rate in two directions as well as units and style to use during display class Channel { public: Channel(char const* const caption, char const* unitCaption, double unitScale, unsigned colorRGBA); - Stream input; - Stream output; + float getAverageInputPacketsPerSecond(); + float getAverageOutputPacketsPerSecond(); + float getAverageInputKilobitsPerSecond(); + float getAverageOutputKilobitsPerSecond(); + + void updateInputAverage(const float sample); + void updateOutputAverage(const float sample); + + // XXX make these private char const* const caption; char const* unitCaption; double unitScale; unsigned colorRGBA; + + private: + SimpleMovingAverage _input; + SimpleMovingAverage _output; }; // create the channels we keep track of @@ -57,7 +61,12 @@ class BandwidthRecorder { Channel* avatarsChannel = new Channel("Avatars", "Kbps", DEFAULT_UNIT_SCALE, COLOR1); Channel* octreeChannel = new Channel("Octree", "Kbps", DEFAULT_UNIT_SCALE, COLOR2); Channel* metavoxelsChannel = new Channel("Metavoxels", "Kbps", DEFAULT_UNIT_SCALE, COLOR2); + Channel* otherChannel = new Channel("Other", "Kbps", DEFAULT_UNIT_SCALE, COLOR2); Channel* totalChannel = new Channel("Total", "Kbps", DEFAULT_UNIT_SCALE, COLOR2); + + public slots: + void updateInboundData(const quint8 channelType, const int bytes); + void updateOutboundData(const quint8 channelType, const int bytes); }; #endif diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index 5bf416af7f..666424151c 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -208,6 +208,22 @@ bool LimitedNodeList::packetVersionAndHashMatch(const QByteArray& packet) { return false; } +// qint64 LimitedNodeList::readDatagram(char* data, qint64 maxSize, QHostAddress* address = 0, quint16 * port = 0) { + +qint64 LimitedNodeList::readDatagram(QByteArray& incomingPacket, QHostAddress* address = 0, quint16 * port = 0) { + qint64 result = getNodeSocket().readDatagram(incomingPacket.data(), incomingPacket.size(), address, port); + + SharedNodePointer sendingNode = sendingNodeForPacket(incomingPacket); + if (sendingNode) { + emit dataReceived(sendingNode->getType(), incomingPacket.size()); + } + else { + emit dataReceived(NodeType::Unassigned, incomingPacket.size()); + } + + return result; +} + qint64 LimitedNodeList::writeDatagram(const QByteArray& datagram, const HifiSockAddr& destinationSockAddr, const QUuid& connectionSecret) { QByteArray datagramCopy = datagram; @@ -231,10 +247,11 @@ qint64 LimitedNodeList::writeDatagram(const QByteArray& datagram, const HifiSock return bytesWritten; } -qint64 LimitedNodeList::writeDatagram(const QByteArray& datagram, const SharedNodePointer& destinationNode, - const HifiSockAddr& overridenSockAddr) { +qint64 LimitedNodeList::writeDatagram(const QByteArray& datagram, + const SharedNodePointer& destinationNode, + const HifiSockAddr& overridenSockAddr) { if (destinationNode) { - // if we don't have an ovveriden address, assume they want to send to the node's active socket + // if we don't have an overridden address, assume they want to send to the node's active socket const HifiSockAddr* destinationSockAddr = &overridenSockAddr; if (overridenSockAddr.isNull()) { if (destinationNode->getActiveSocket()) { @@ -245,6 +262,8 @@ qint64 LimitedNodeList::writeDatagram(const QByteArray& datagram, const SharedNo return 0; } } + + emit dataSent(destinationNode->getType(), datagram.size()); return writeDatagram(datagram, *destinationSockAddr, destinationNode->getConnectionSecret()); } @@ -303,7 +322,7 @@ int LimitedNodeList::updateNodeWithDataFromPacket(const SharedNodePointer& match QMutexLocker locker(&matchingNode->getMutex()); matchingNode->setLastHeardMicrostamp(usecTimestampNow()); - matchingNode->recordBytesReceived(packet.size()); + // matchingNode->recordBytesReceived(packet.size()); if (!matchingNode->getLinkedData() && linkedDataCreateCallback) { linkedDataCreateCallback(matchingNode.data()); diff --git a/libraries/networking/src/LimitedNodeList.h b/libraries/networking/src/LimitedNodeList.h index 1c841637df..233d3c9f0c 100644 --- a/libraries/networking/src/LimitedNodeList.h +++ b/libraries/networking/src/LimitedNodeList.h @@ -82,6 +82,8 @@ public: QUdpSocket& getDTLSSocket(); bool packetVersionAndHashMatch(const QByteArray& packet); + + qint64 readDatagram(QByteArray& incomingPacket, QHostAddress* address, quint16 * port); qint64 writeDatagram(const QByteArray& datagram, const SharedNodePointer& destinationNode, const HifiSockAddr& overridenSockAddr = HifiSockAddr()); @@ -180,6 +182,9 @@ signals: void localSockAddrChanged(const HifiSockAddr& localSockAddr); void publicSockAddrChanged(const HifiSockAddr& publicSockAddr); + + void dataSent(const quint8 channel_type, const int bytes); + void dataReceived(const quint8 channel_type, const int bytes); protected: LimitedNodeList(unsigned short socketListenPort = 0, unsigned short dtlsListenPort = 0); diff --git a/libraries/networking/src/Node.cpp b/libraries/networking/src/Node.cpp index 2095acdf66..e8c73896f1 100644 --- a/libraries/networking/src/Node.cpp +++ b/libraries/networking/src/Node.cpp @@ -47,7 +47,7 @@ Node::Node(const QUuid& uuid, NodeType_t type, const HifiSockAddr& publicSocket, _activeSocket(NULL), _symmetricSocket(), _connectionSecret(), - _bytesReceivedMovingAverage(NULL), + // _bytesReceivedMovingAverage(NULL), _linkedData(NULL), _isAlive(true), _pingMs(-1), // "Uninitialized" @@ -60,32 +60,32 @@ Node::Node(const QUuid& uuid, NodeType_t type, const HifiSockAddr& publicSocket, Node::~Node() { delete _linkedData; - delete _bytesReceivedMovingAverage; + // delete _bytesReceivedMovingAverage; } -void Node::recordBytesReceived(int bytesReceived) { - if (!_bytesReceivedMovingAverage) { - _bytesReceivedMovingAverage = new SimpleMovingAverage(100); - } +// void Node::recordBytesReceived(int bytesReceived) { +// if (!_bytesReceivedMovingAverage) { +// _bytesReceivedMovingAverage = new SimpleMovingAverage(100); +// } - _bytesReceivedMovingAverage->updateAverage((float) bytesReceived); -} +// _bytesReceivedMovingAverage->updateAverage((float) bytesReceived); +// } -float Node::getAveragePacketsPerSecond() { - if (_bytesReceivedMovingAverage) { - return (1 / _bytesReceivedMovingAverage->getEventDeltaAverage()); - } else { - return 0; - } -} +// float Node::getAveragePacketsPerSecond() { +// if (_bytesReceivedMovingAverage) { +// return (1 / _bytesReceivedMovingAverage->getEventDeltaAverage()); +// } else { +// return 0; +// } +// } -float Node::getAverageKilobitsPerSecond() { - if (_bytesReceivedMovingAverage) { - return (_bytesReceivedMovingAverage->getAverageSampleValuePerSecond() * (8.0f / 1000)); - } else { - return 0; - } -} +// float Node::getAverageKilobitsPerSecond() { +// if (_bytesReceivedMovingAverage) { +// return (_bytesReceivedMovingAverage->getAverageSampleValuePerSecond() * (8.0f / 1000)); +// } else { +// return 0; +// } +// } void Node::updateClockSkewUsec(int clockSkewSample) { _clockSkewMovingPercentile.updatePercentile((float)clockSkewSample); diff --git a/libraries/networking/src/Node.h b/libraries/networking/src/Node.h index 6399c80edc..7d5e088038 100644 --- a/libraries/networking/src/Node.h +++ b/libraries/networking/src/Node.h @@ -63,9 +63,9 @@ public: bool isAlive() const { return _isAlive; } void setAlive(bool isAlive) { _isAlive = isAlive; } - void recordBytesReceived(int bytesReceived); - float getAverageKilobitsPerSecond(); - float getAveragePacketsPerSecond(); + // void recordBytesReceived(int bytesReceived); + // float getAverageKilobitsPerSecond(); + // float getAveragePacketsPerSecond(); int getPingMs() const { return _pingMs; } void setPingMs(int pingMs) { _pingMs = pingMs; } @@ -99,7 +99,7 @@ private: HifiSockAddr _symmetricSocket; QUuid _connectionSecret; - SimpleMovingAverage* _bytesReceivedMovingAverage; + // SimpleMovingAverage* _bytesReceivedMovingAverage; NodeData* _linkedData; bool _isAlive; int _pingMs; diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index bb095b2a3d..f86e0b85e4 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -108,6 +108,9 @@ void NodeList::timePingReply(const QByteArray& packet, const SharedNodePointer& } void NodeList::processNodeData(const HifiSockAddr& senderSockAddr, const QByteArray& packet) { + + emit dataReceived(NodeType::AudioMixer, packet.size()); // XXX + switch (packetTypeForPacket(packet)) { case PacketTypeDomainList: { processDomainServerList(packet); @@ -157,6 +160,7 @@ void NodeList::processNodeData(const HifiSockAddr& senderSockAddr, const QByteAr break; } case PacketTypeUnverifiedPing: { + // send back a reply QByteArray replyPacket = constructPingReplyPacket(packet, _domainHandler.getICEClientID()); writeUnverifiedDatagram(replyPacket, senderSockAddr); diff --git a/tools/refresh-tags.sh b/tools/refresh-tags.sh index 86749bf20c..d3157fa179 100755 --- a/tools/refresh-tags.sh +++ b/tools/refresh-tags.sh @@ -8,7 +8,7 @@ do done -find . -name *.cpp -print | while read I +find . -name *.cpp -print | grep -v 'moc_' | while read I do etags --append "$I" done