Merge branch 'protocol' of https://github.com/Atlante45/hifi into atp

This commit is contained in:
Stephen Birarda 2015-07-15 13:17:38 -07:00
commit 6b05b7ef31
6 changed files with 55 additions and 17 deletions

View file

@ -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

View file

@ -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<NLPacket&>(packet).writeSourceID(sessionUUID);
const_cast<NLPacket&>(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<NLPacket&>(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<NLPacket> packet, const Node& destinationNode) {
@ -280,7 +275,7 @@ qint64 LimitedNodeList::sendPacket(std::unique_ptr<NLPacket> packet, const Node&
qint64 LimitedNodeList::sendPacket(std::unique_ptr<NLPacket> 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<NLPacket> packet,
eachNode([&](const SharedNodePointer& node){
if (destinationNodeTypes.contains(node->getType())) {
writeDatagram(*packet, *node->getActiveSocket());
writePacket(*packet, *node->getActiveSocket(), node->getConnectionSecret());
++n;
}
});

View file

@ -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);

View file

@ -14,5 +14,8 @@
#include "NodeList.h"
PacketListener::~PacketListener() {
DependencyManager::get<LimitedNodeList>()->getPacketReceiver().unregisterListener(this);
auto limitedNodelist = DependencyManager::get<LimitedNodeList>();
if (limitedNodelist) {
limitedNodelist->getPacketReceiver().unregisterListener(this);
}
}

View file

@ -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)

View file

@ -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 <QtTest/QtTest>
class PacketTests : public QObject {
Q_OBJECT
private slots:
void readTest();
};
#endif // hifi_PacketTests_h