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 diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index f6bf785d00..34ac2c7b20 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -216,10 +216,10 @@ 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::writePacket(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() @@ -227,12 +227,7 @@ void writePacketHeader(const NLPacket& packet, const QUuid& sessionUUID = QUuid( && !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(), (int) packet.getDataSize() }, destinationSockAddr); + return writeDatagram({ packet.getData(), (int)packet.getDataSize() }, destinationSockAddr); } qint64 LimitedNodeList::writeDatagram(const QByteArray& datagram, const HifiSockAddr& destinationSockAddr) { @@ -264,7 +259,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) { @@ -280,7 +275,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) { @@ -501,7 +496,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); 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); + } } 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