From 3cd2887a089ad752f6c6d6f04a7743158cd1aeeb Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 14 Jul 2015 16:11:29 -0700 Subject: [PATCH 1/6] add initial packet tests --- tests/networking/src/PacketTests.cpp | 14 ++++++++++++++ tests/networking/src/PacketTests.h | 25 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 tests/networking/src/PacketTests.cpp create mode 100644 tests/networking/src/PacketTests.h diff --git a/tests/networking/src/PacketTests.cpp b/tests/networking/src/PacketTests.cpp new file mode 100644 index 0000000000..c8c88679fb --- /dev/null +++ b/tests/networking/src/PacketTests.cpp @@ -0,0 +1,14 @@ +// +// PacketTests.cpp +// tests/networking/src +// +// Created by Stephen Birarda on 07/14/15. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "PacketTests.h" + +QTEST_MAIN(PacketTests) diff --git a/tests/networking/src/PacketTests.h b/tests/networking/src/PacketTests.h new file mode 100644 index 0000000000..498fddf39a --- /dev/null +++ b/tests/networking/src/PacketTests.h @@ -0,0 +1,25 @@ +// +// PacketTests.h +// tests/networking/src +// +// Created by Stephen Birarda on 07/14/15. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_PacketTests_h +#define hifi_PacketTests_h + +#pragma once + +#include + +class PacketTests : public QObject { + Q_OBJECT +private slots: + void readTest(); +}; + +#endif // hifi_PacketTests_h From 3b8a335c8c5ac424ea8ddccf6b713fd5d54b9472 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 15 Jul 2015 10:51:40 -0700 Subject: [PATCH 2/6] Fix bytesLeftToRead --- libraries/networking/src/udt/Packet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/networking/src/udt/Packet.h b/libraries/networking/src/udt/Packet.h index c7933606be..70a11137db 100644 --- a/libraries/networking/src/udt/Packet.h +++ b/libraries/networking/src/udt/Packet.h @@ -53,7 +53,7 @@ public: qint64 getSizeUsed() const { return _sizeUsed; } void setSizeUsed(qint64 sizeUsed) { _sizeUsed = sizeUsed; } - void bytesLeftToRead() const { return _capacity - pos(); } + qint64 bytesLeftToRead() const { return _capacity - pos(); } qint64 bytesAvailableForWrite() const { return _capacity - pos(); } HifiSockAddr& getSenderSockAddr() { return _senderSockAddr; } From cee173400614fa5d82c5c85178c052e1f9a03ca6 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 15 Jul 2015 11:48:30 -0700 Subject: [PATCH 3/6] Remove helper function --- libraries/networking/src/LimitedNodeList.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index 090c3bdd8b..70c3bb3704 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -214,19 +214,14 @@ bool LimitedNodeList::packetSourceAndHashMatch(const NLPacket& packet, SharedNod return false; } -// NLPacket helper for filling the header -void writePacketheader(const NLPacket& packet, const QUuid& sessionUUID = QUuid(), const QUuid& connectionSecret = QUuid()) { +qint64 LimitedNodeList::writeDatagram(const NLPacket& packet, const HifiSockAddr& destinationSockAddr, + const QUuid& connectionSecret) { if (!NON_SOURCED_PACKETS.contains(packet.getType())) { - const_cast(packet).writeSourceID(sessionUUID); + const_cast(packet).writeSourceID(getSessionUUID()); } if (!connectionSecret.isNull() && !NON_VERIFIED_PACKETS.contains(packet.getType())) { const_cast(packet).writeVerificationHash(packet.payloadHashWithConnectionUUID(connectionSecret)); } -} - -qint64 LimitedNodeList::writeDatagram(const NLPacket& packet, const HifiSockAddr& destinationSockAddr, - const QUuid& connectionSecret) { - writePacketheader(packet, getSessionUUID(), connectionSecret); return writeDatagram({packet.getData(), static_cast(packet.getSizeWithHeader())}, destinationSockAddr); } From e744e08577c575d98a01955d73afc928a6b5726a Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 15 Jul 2015 11:56:01 -0700 Subject: [PATCH 4/6] Missed one connection secret --- libraries/networking/src/LimitedNodeList.cpp | 10 +++++----- libraries/networking/src/LimitedNodeList.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index a015e11a33..66755c9d53 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -214,8 +214,8 @@ bool LimitedNodeList::packetSourceAndHashMatch(const NLPacket& packet, SharedNod return false; } -qint64 LimitedNodeList::writeDatagram(const NLPacket& packet, const HifiSockAddr& destinationSockAddr, - const QUuid& connectionSecret) { +qint64 LimitedNodeList::writePacket(const NLPacket& packet, const HifiSockAddr& destinationSockAddr, + const QUuid& connectionSecret) { if (!NON_SOURCED_PACKETS.contains(packet.getType())) { const_cast(packet).writeSourceID(getSessionUUID()); } @@ -254,7 +254,7 @@ qint64 LimitedNodeList::sendUnreliablePacket(const NLPacket& packet, const Node& qint64 LimitedNodeList::sendUnreliablePacket(const NLPacket& packet, const HifiSockAddr& sockAddr, const QUuid& connectionSecret) { - return writeDatagram(packet, sockAddr, connectionSecret); + return writePacket(packet, sockAddr, connectionSecret); } qint64 LimitedNodeList::sendPacket(std::unique_ptr packet, const Node& destinationNode) { @@ -270,7 +270,7 @@ qint64 LimitedNodeList::sendPacket(std::unique_ptr packet, const Node& qint64 LimitedNodeList::sendPacket(std::unique_ptr packet, const HifiSockAddr& sockAddr, const QUuid& connectionSecret) { - return writeDatagram(*packet, sockAddr, connectionSecret); + return writePacket(*packet, sockAddr, connectionSecret); } qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const Node& destinationNode) { @@ -491,7 +491,7 @@ unsigned int LimitedNodeList::broadcastToNodes(std::unique_ptr packet, eachNode([&](const SharedNodePointer& node){ if (destinationNodeTypes.contains(node->getType())) { - writeDatagram(*packet, *node->getActiveSocket()); + writePacket(*packet, *node->getActiveSocket(), node->getConnectionSecret()); ++n; } }); diff --git a/libraries/networking/src/LimitedNodeList.h b/libraries/networking/src/LimitedNodeList.h index cd3a0f0594..a2cbac7348 100644 --- a/libraries/networking/src/LimitedNodeList.h +++ b/libraries/networking/src/LimitedNodeList.h @@ -248,8 +248,8 @@ protected: LimitedNodeList(LimitedNodeList const&); // Don't implement, needed to avoid copies of singleton void operator=(LimitedNodeList const&); // Don't implement, needed to avoid copies of singleton - qint64 writeDatagram(const NLPacket& packet, const HifiSockAddr& destinationSockAddr, - const QUuid& connectionSecret = QUuid()); + qint64 writePacket(const NLPacket& packet, const HifiSockAddr& destinationSockAddr, + const QUuid& connectionSecret = QUuid()); qint64 writeDatagram(const QByteArray& datagram, const HifiSockAddr& destinationSockAddr); PacketSequenceNumber getNextSequenceNumberForPacket(const QUuid& nodeUUID, PacketType::Value packetType); From aa517adb73272057613cde28bb58411510616e7c Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 15 Jul 2015 13:09:04 -0700 Subject: [PATCH 5/6] Fix Application inheritance formatting --- interface/src/Application.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/interface/src/Application.h b/interface/src/Application.h index 5d67270533..53c94619a9 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -135,9 +135,10 @@ class Application; typedef bool (Application::* AcceptURLMethod)(const QString &); -class Application : public QApplication, +class Application : + public QApplication, public AbstractViewStateInterface, - AbstractScriptingServicesInterface, + public AbstractScriptingServicesInterface, public PacketListener { Q_OBJECT From f3800cacdadff7a8d73ce7166dd6cb07ff31215f Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 15 Jul 2015 13:10:16 -0700 Subject: [PATCH 6/6] Don't unregister packet listeners when no nodelist --- libraries/networking/src/PacketListener.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libraries/networking/src/PacketListener.cpp b/libraries/networking/src/PacketListener.cpp index 3036afc7cb..f4a5c4a9cd 100644 --- a/libraries/networking/src/PacketListener.cpp +++ b/libraries/networking/src/PacketListener.cpp @@ -14,5 +14,8 @@ #include "NodeList.h" PacketListener::~PacketListener() { - DependencyManager::get()->getPacketReceiver().unregisterListener(this); + auto limitedNodelist = DependencyManager::get(); + if (limitedNodelist) { + limitedNodelist->getPacketReceiver().unregisterListener(this); + } }