Move node received bandwidth tracking to LimitedNodeList

This commit is contained in:
Ryan Huffman 2016-08-15 09:22:56 -07:00
parent 473a7e9593
commit b5e2913eb9
5 changed files with 12 additions and 25 deletions

View file

@ -845,7 +845,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
QSharedPointer<BandwidthRecorder> bandwidthRecorder = DependencyManager::get<BandwidthRecorder>();
connect(nodeList.data(), &LimitedNodeList::dataSent,
bandwidthRecorder.data(), &BandwidthRecorder::updateOutboundData);
connect(&nodeList->getPacketReceiver(), &PacketReceiver::dataReceived,
connect(nodeList.data(), &LimitedNodeList::dataReceived,
bandwidthRecorder.data(), &BandwidthRecorder::updateInboundData);
// FIXME -- I'm a little concerned about this.

View file

@ -175,7 +175,11 @@ QUdpSocket& LimitedNodeList::getDTLSSocket() {
}
bool LimitedNodeList::isPacketVerified(const udt::Packet& packet) {
return packetVersionMatch(packet) && packetSourceAndHashMatch(packet);
// We track bandwidth when doing packet verification to avoid needing to do a node lookup
// later when we already do it in packetSourceAndHashMatchAndTrackBandwidth. A node lookup
// incurs a lock, so it is ideal to avoid needing to do it 2+ times for each packet
// received.
return packetVersionMatch(packet) && packetSourceAndHashMatchAndTrackBandwidth(packet);
}
bool LimitedNodeList::packetVersionMatch(const udt::Packet& packet) {
@ -224,11 +228,12 @@ bool LimitedNodeList::packetVersionMatch(const udt::Packet& packet) {
}
}
bool LimitedNodeList::packetSourceAndHashMatch(const udt::Packet& packet) {
bool LimitedNodeList::packetSourceAndHashMatchAndTrackBandwidth(const udt::Packet& packet) {
PacketType headerType = NLPacket::typeInHeader(packet);
if (NON_SOURCED_PACKETS.contains(headerType)) {
emit dataReceived(NodeType::Unassigned, packet.getPayloadSize());
return true;
} else {
QUuid sourceID = NLPacket::sourceIDInHeader(packet);
@ -260,6 +265,8 @@ bool LimitedNodeList::packetSourceAndHashMatch(const udt::Packet& packet) {
// from this sending node
matchingNode->setLastHeardMicrostamp(usecTimestampNow());
emit dataReceived(matchingNode->getType(), packet.getPayloadSize());
return true;
} else {

View file

@ -243,6 +243,7 @@ public slots:
signals:
void dataSent(quint8 channelType, int bytes);
void dataReceived(quint8 channelType, int bytes);
// QUuid might be zero for non-sourced packet types.
void packetVersionMismatch(PacketType type, const HifiSockAddr& senderSockAddr, const QUuid& senderUUID);
@ -279,7 +280,7 @@ protected:
void setLocalSocket(const HifiSockAddr& sockAddr);
bool packetSourceAndHashMatch(const udt::Packet& packet);
bool packetSourceAndHashMatchAndTrackBandwidth(const udt::Packet& packet);
void processSTUNResponse(std::unique_ptr<udt::BasePacket> packet);
void handleNodeKill(const SharedNodePointer& node);

View file

@ -215,15 +215,6 @@ void PacketReceiver::handleVerifiedPacket(std::unique_ptr<udt::Packet> packet) {
_inPacketCount += 1;
_inByteCount += nlPacket->size();
SharedNodePointer matchingNode;
NodeType_t nodeType = NodeType::Unassigned;
if (!nlPacket->getSourceID().isNull()) {
auto nodeList = DependencyManager::get<LimitedNodeList>();
matchingNode = nodeList->nodeWithUUID(nlPacket->getSourceID());
nodeType = matchingNode->getType();
}
emit dataReceived(nodeType, nlPacket->getPayloadSize());
handleVerifiedMessage(receivedMessage, true);
}
@ -233,15 +224,6 @@ void PacketReceiver::handleVerifiedMessagePacket(std::unique_ptr<udt::Packet> pa
_inPacketCount += 1;
_inByteCount += nlPacket->size();
SharedNodePointer matchingNode;
NodeType_t nodeType = NodeType::Unassigned;
if (!nlPacket->getSourceID().isNull()) {
auto nodeList = DependencyManager::get<LimitedNodeList>();
matchingNode = nodeList->nodeWithUUID(nlPacket->getSourceID());
nodeType = matchingNode->getType();
}
emit dataReceived(nodeType, nlPacket->getPayloadSize());
auto key = std::pair<HifiSockAddr, udt::Packet::MessageNumber>(nlPacket->getSenderSockAddr(), nlPacket->getMessageNumber());
auto it = _pendingMessages.find(key);
QSharedPointer<ReceivedMessage> message;

View file

@ -67,9 +67,6 @@ public:
void handleVerifiedPacket(std::unique_ptr<udt::Packet> packet);
void handleVerifiedMessagePacket(std::unique_ptr<udt::Packet> message);
void handleMessageFailure(HifiSockAddr from, udt::Packet::MessageNumber messageNumber);
signals:
void dataReceived(quint8 channelType, int bytes);
private:
struct Listener {