mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 06:44:06 +02:00
Merge branch 'atp' of github.com:birarda/hifi into protocol
This commit is contained in:
commit
988fc79126
39 changed files with 198 additions and 400 deletions
|
@ -161,7 +161,16 @@ void Agent::run() {
|
|||
|
||||
// give this AvatarData object to the script engine
|
||||
_scriptEngine.setAvatarData(&scriptedAvatar, "Avatar");
|
||||
_scriptEngine.setAvatarHashMap(DependencyManager::get<AvatarHashMap>().data(), "AvatarList");
|
||||
|
||||
auto avatarHashMap = DependencyManager::set<AvatarHashMap>();
|
||||
|
||||
_scriptEngine.setAvatarHashMap(avatarHashMap.data(), "AvatarList");
|
||||
|
||||
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
|
||||
packetReceiver.registerListener(PacketType::BulkAvatarData, avatarHashMap.data(), "processAvatarDataPacket");
|
||||
packetReceiver.registerListener(PacketType::KillAvatar, avatarHashMap.data(), "processKillAvatar");
|
||||
packetReceiver.registerListener(PacketType::AvatarIdentity, avatarHashMap.data(), "processAvatarIdentityPacket");
|
||||
packetReceiver.registerListener(PacketType::AvatarBillboard, avatarHashMap.data(), "processAvatarBillboardPacket");
|
||||
|
||||
// register ourselves to the script engine
|
||||
_scriptEngine.registerGlobalObject("Agent", this);
|
||||
|
@ -184,6 +193,9 @@ void Agent::run() {
|
|||
|
||||
void Agent::aboutToFinish() {
|
||||
_scriptEngine.stop();
|
||||
|
||||
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
|
||||
packetReceiver.unregisterListener(DependencyManager::get<AvatarHashMap>().data());
|
||||
|
||||
// our entity tree is going to go away so tell that to the EntityScriptingInterface
|
||||
DependencyManager::get<EntityScriptingInterface>()->setEntityTree(NULL);
|
||||
|
|
|
@ -56,7 +56,6 @@ AssignmentClient::AssignmentClient(Assignment::Type requestAssignmentType, QStri
|
|||
auto nodeList = DependencyManager::set<NodeList>(NodeType::Unassigned);
|
||||
|
||||
auto animationCache = DependencyManager::set<AnimationCache>();
|
||||
auto avatarHashMap = DependencyManager::set<AvatarHashMap>();
|
||||
auto entityScriptingInterface = DependencyManager::set<EntityScriptingInterface>();
|
||||
|
||||
DependencyManager::registerInheritance<EntityActionFactoryInterface, AssignmentActionFactory>();
|
||||
|
|
|
@ -15,13 +15,11 @@
|
|||
#include <QtCore/QCoreApplication>
|
||||
#include <QtCore/QPointer>
|
||||
|
||||
#include <PacketListener.h>
|
||||
|
||||
#include "ThreadedAssignment.h"
|
||||
|
||||
class QSharedMemory;
|
||||
|
||||
class AssignmentClient : public QObject, public PacketListener {
|
||||
class AssignmentClient : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
AssignmentClient(Assignment::Type requestAssignmentType, QString assignmentPool,
|
||||
|
|
|
@ -176,7 +176,7 @@ void AssignmentClientMonitor::checkSpares() {
|
|||
AssignmentClientChildData* childData = static_cast<AssignmentClientChildData*>(node->getLinkedData());
|
||||
totalCount ++;
|
||||
if (childData->getChildType() == Assignment::Type::AllTypes) {
|
||||
spareCount ++;
|
||||
++spareCount;
|
||||
aSpareId = node->getUUID();
|
||||
}
|
||||
});
|
||||
|
@ -203,7 +203,9 @@ void AssignmentClientMonitor::checkSpares() {
|
|||
}
|
||||
|
||||
void AssignmentClientMonitor::handleChildStatusPacket(QSharedPointer<NLPacket> packet) {
|
||||
// read out the sender ID
|
||||
QUuid senderID = QUuid::fromRfc4122(QByteArray::fromRawData(packet->getPayload(), NUM_BYTES_RFC4122_UUID));
|
||||
packet->seek(NUM_BYTES_RFC4122_UUID);
|
||||
|
||||
auto nodeList = DependencyManager::get<NodeList>();
|
||||
|
||||
|
|
|
@ -23,8 +23,7 @@
|
|||
|
||||
extern const char* NUM_FORKS_PARAMETER;
|
||||
|
||||
|
||||
class AssignmentClientMonitor : public QObject, public PacketListener {
|
||||
class AssignmentClientMonitor : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
AssignmentClientMonitor(const unsigned int numAssignmentClientForks, const unsigned int minAssignmentClientForks,
|
||||
|
|
|
@ -341,6 +341,9 @@ void AvatarMixer::broadcastAvatarData() {
|
|||
++_sumIdentityPackets;
|
||||
}
|
||||
});
|
||||
|
||||
// close the current packet so that we're always sending something
|
||||
avatarPacketList.closeCurrentPacket(true);
|
||||
|
||||
// send the avatar data PacketList
|
||||
nodeList->sendPacketList(avatarPacketList, *node);
|
||||
|
|
|
@ -636,7 +636,7 @@ void DomainServer::processConnectRequestPacket(QSharedPointer<NLPacket> packet)
|
|||
// this is an agent and we've decided we won't let them connect - send them a packet to deny connection
|
||||
|
||||
QByteArray utfString = reason.toUtf8();
|
||||
qint16 payloadSize = utfString.size();
|
||||
quint16 payloadSize = utfString.size();
|
||||
|
||||
auto connectionDeniedPacket = NLPacket::create(PacketType::DomainConnectionDenied, payloadSize + sizeof(payloadSize));
|
||||
connectionDeniedPacket->writePrimitive(payloadSize);
|
||||
|
@ -2224,7 +2224,7 @@ void DomainServer::processPathQueryPacket(QSharedPointer<NLPacket> packet) {
|
|||
|
||||
// are we going to be able to fit this response viewpoint in a packet?
|
||||
if (numPathBytes + numViewpointBytes + sizeof(numViewpointBytes) + sizeof(numPathBytes)
|
||||
< (unsigned long) pathResponsePacket->bytesLeftToRead()) {
|
||||
< (unsigned long) pathResponsePacket->bytesAvailableForWrite()) {
|
||||
// append the number of bytes this path is
|
||||
pathResponsePacket->writePrimitive(numPathBytes);
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#include <Assignment.h>
|
||||
#include <HTTPSConnection.h>
|
||||
#include <LimitedNodeList.h>
|
||||
#include <PacketListener.h>
|
||||
|
||||
#include "DomainServerSettingsManager.h"
|
||||
#include "DomainServerWebSessionData.h"
|
||||
|
@ -35,7 +34,7 @@
|
|||
typedef QSharedPointer<Assignment> SharedAssignmentPointer;
|
||||
typedef QMultiHash<QUuid, WalletTransaction*> TransactionHash;
|
||||
|
||||
class DomainServer : public QCoreApplication, public HTTPSRequestHandler, public PacketListener {
|
||||
class DomainServer : public QCoreApplication, public HTTPSRequestHandler {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DomainServer(int argc, char* argv[]);
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
#include <OctreeQuery.h>
|
||||
#include <OffscreenUi.h>
|
||||
#include <udt/PacketHeaders.h>
|
||||
#include <PacketListener.h>
|
||||
#include <PhysicalEntitySimulation.h>
|
||||
#include <PhysicsEngine.h>
|
||||
#include <ScriptEngine.h>
|
||||
|
@ -126,11 +125,7 @@ class Application;
|
|||
|
||||
typedef bool (Application::* AcceptURLMethod)(const QString &);
|
||||
|
||||
class Application :
|
||||
public QApplication,
|
||||
public AbstractViewStateInterface,
|
||||
public AbstractScriptingServicesInterface,
|
||||
public PacketListener {
|
||||
class Application : public QApplication, public AbstractViewStateInterface, public AbstractScriptingServicesInterface {
|
||||
Q_OBJECT
|
||||
|
||||
friend class OctreePacketProcessor;
|
||||
|
|
|
@ -61,10 +61,17 @@ void AvatarManager::registerMetaTypes(QScriptEngine* engine) {
|
|||
}
|
||||
|
||||
AvatarManager::AvatarManager(QObject* parent) :
|
||||
_avatarFades() {
|
||||
_avatarFades()
|
||||
{
|
||||
// register a meta type for the weak pointer we'll use for the owning avatar mixer for each avatar
|
||||
qRegisterMetaType<QWeakPointer<Node> >("NodeWeakPointer");
|
||||
_myAvatar = std::make_shared<MyAvatar>();
|
||||
|
||||
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
|
||||
packetReceiver.registerListener(PacketType::BulkAvatarData, this, "processAvatarDataPacket");
|
||||
packetReceiver.registerListener(PacketType::KillAvatar, this, "processKillAvatar");
|
||||
packetReceiver.registerListener(PacketType::AvatarIdentity, this, "processAvatarIdentityPacket");
|
||||
packetReceiver.registerListener(PacketType::AvatarBillboard, this, "processAvatarBillboardPacket");
|
||||
}
|
||||
|
||||
void AvatarManager::init() {
|
||||
|
|
|
@ -21,7 +21,7 @@ OctreePacketProcessor::OctreePacketProcessor() {
|
|||
|
||||
QSet<PacketType::Value> types {
|
||||
PacketType::OctreeStats, PacketType::EntityData,
|
||||
PacketType::EntityErase, PacketType::OctreeStats, PacketType::EnvironmentData
|
||||
PacketType::EntityErase, PacketType::OctreeStats
|
||||
};
|
||||
|
||||
packetReceiver.registerDirectListenerForTypes(types, this, "handleOctreePacket");
|
||||
|
@ -106,10 +106,6 @@ void OctreePacketProcessor::processPacket(QSharedPointer<NLPacket> packet, Share
|
|||
}
|
||||
} break;
|
||||
|
||||
case PacketType::EnvironmentData: {
|
||||
app->_environment.processPacket(*packet);
|
||||
} break;
|
||||
|
||||
default: {
|
||||
// nothing to do
|
||||
} break;
|
||||
|
|
|
@ -13,11 +13,10 @@
|
|||
#define hifi_OctreePacketProcessor_h
|
||||
|
||||
#include <ReceivedPacketProcessor.h>
|
||||
#include <PacketListener.h>
|
||||
|
||||
/// Handles processing of incoming voxel packets for the interface application. As with other ReceivedPacketProcessor classes
|
||||
/// the user is responsible for reading inbound packets and adding them to the processing queue by calling queueReceivedPacket()
|
||||
class OctreePacketProcessor : public ReceivedPacketProcessor, public PacketListener {
|
||||
class OctreePacketProcessor : public ReceivedPacketProcessor {
|
||||
Q_OBJECT
|
||||
public:
|
||||
OctreePacketProcessor();
|
||||
|
|
|
@ -39,7 +39,6 @@
|
|||
#include <NLPacket.h>
|
||||
#include <MixedProcessedAudioStream.h>
|
||||
#include <RingBufferHistory.h>
|
||||
#include <PacketListener.h>
|
||||
#include <SettingHandle.h>
|
||||
#include <Sound.h>
|
||||
#include <StDev.h>
|
||||
|
@ -81,7 +80,7 @@ typedef glm::quat (*AudioOrientationGetter)();
|
|||
|
||||
class NLPacket;
|
||||
|
||||
class AudioClient : public AbstractAudioInterface, public Dependency, public PacketListener {
|
||||
class AudioClient : public AbstractAudioInterface, public Dependency {
|
||||
Q_OBJECT
|
||||
SINGLETON_DEPENDENCY
|
||||
public:
|
||||
|
|
|
@ -19,11 +19,10 @@
|
|||
#include <AudioStreamStats.h>
|
||||
#include <Node.h>
|
||||
#include <NLPacket.h>
|
||||
#include <PacketListener.h>
|
||||
|
||||
class MixedProcessedAudioStream;
|
||||
|
||||
class AudioIOStats : public QObject, public PacketListener {
|
||||
class AudioIOStats : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
AudioIOStats(MixedProcessedAudioStream* receivedAudioStream);
|
||||
|
|
|
@ -214,6 +214,11 @@ void AudioInjector::injectToMixer() {
|
|||
(AudioConstants::MAX_SAMPLE_VALUE / 2.0f);
|
||||
}
|
||||
_loudness /= (float)(bytesToCopy / sizeof(int16_t));
|
||||
|
||||
audioPacket->seek(0);
|
||||
|
||||
// pack the sequence number
|
||||
audioPacket->writePrimitive(outgoingInjectedAudioSequenceNumber);
|
||||
|
||||
audioPacket->seek(positionOptionOffset);
|
||||
audioPacket->writePrimitive(_options.position);
|
||||
|
@ -225,9 +230,6 @@ void AudioInjector::injectToMixer() {
|
|||
|
||||
audioPacket->seek(audioDataOffset);
|
||||
|
||||
// pack the sequence number
|
||||
audioPacket->writePrimitive(outgoingInjectedAudioSequenceNumber);
|
||||
|
||||
// copy the next NETWORK_BUFFER_LENGTH_BYTES_PER_CHANNEL bytes to the packet
|
||||
audioPacket->write(_audioData.data() + _currentSendPosition, bytesToCopy);
|
||||
|
||||
|
@ -236,10 +238,12 @@ void AudioInjector::injectToMixer() {
|
|||
|
||||
// grab our audio mixer from the NodeList, if it exists
|
||||
SharedNodePointer audioMixer = nodeList->soloNodeOfType(NodeType::AudioMixer);
|
||||
|
||||
// send off this audio packet
|
||||
nodeList->sendUnreliablePacket(*audioPacket, *audioMixer);
|
||||
outgoingInjectedAudioSequenceNumber++;
|
||||
|
||||
if (audioMixer) {
|
||||
// send off this audio packet
|
||||
nodeList->sendUnreliablePacket(*audioPacket, *audioMixer);
|
||||
outgoingInjectedAudioSequenceNumber++;
|
||||
}
|
||||
|
||||
_currentSendPosition += bytesToCopy;
|
||||
|
||||
|
|
|
@ -20,12 +20,6 @@
|
|||
|
||||
AvatarHashMap::AvatarHashMap() {
|
||||
connect(DependencyManager::get<NodeList>().data(), &NodeList::uuidChanged, this, &AvatarHashMap::sessionUUIDChanged);
|
||||
|
||||
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
|
||||
packetReceiver.registerListener(PacketType::BulkAvatarData, this, "processAvatarDataPacket");
|
||||
packetReceiver.registerListener(PacketType::KillAvatar, this, "processKillAvatar");
|
||||
packetReceiver.registerListener(PacketType::AvatarIdentity, this, "processAvatarIdentityPacket");
|
||||
packetReceiver.registerListener(PacketType::AvatarBillboard, this, "processAvatarBillboardPacket");
|
||||
}
|
||||
|
||||
bool AvatarHashMap::isAvatarInRange(const glm::vec3& position, const float range) {
|
||||
|
|
|
@ -21,12 +21,11 @@
|
|||
#include <DependencyManager.h>
|
||||
#include <NLPacket.h>
|
||||
#include <Node.h>
|
||||
#include <PacketListener.h>
|
||||
|
||||
#include "AvatarData.h"
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
class AvatarHashMap : public QObject, public Dependency, public PacketListener {
|
||||
class AvatarHashMap : public QObject, public Dependency {
|
||||
Q_OBJECT
|
||||
SINGLETON_DEPENDENCY
|
||||
|
||||
|
@ -36,14 +35,15 @@ public:
|
|||
|
||||
public slots:
|
||||
bool isAvatarInRange(const glm::vec3 & position, const float range);
|
||||
|
||||
private slots:
|
||||
void sessionUUIDChanged(const QUuid& sessionUUID, const QUuid& oldUUID);
|
||||
|
||||
void processAvatarDataPacket(QSharedPointer<NLPacket> packet, SharedNodePointer sendingNode);
|
||||
void processAvatarIdentityPacket(QSharedPointer<NLPacket> packet, SharedNodePointer sendingNode);
|
||||
void processAvatarBillboardPacket(QSharedPointer<NLPacket> packet, SharedNodePointer sendingNode);
|
||||
void processKillAvatar(QSharedPointer<NLPacket> packet, SharedNodePointer sendingNode);
|
||||
|
||||
private slots:
|
||||
void sessionUUIDChanged(const QUuid& sessionUUID, const QUuid& oldUUID);
|
||||
|
||||
protected:
|
||||
AvatarHashMap();
|
||||
|
||||
|
|
|
@ -22,9 +22,9 @@ EntityEditPacketSender::EntityEditPacketSender() {
|
|||
packetReceiver.registerListener(PacketType::EntityEditNack, this, "processEntityEditNackPacket");
|
||||
}
|
||||
|
||||
void EntityEditPacketSender::processEntityEditNackPacket(QSharedPointer<NLPacket> packet) {
|
||||
void EntityEditPacketSender::processEntityEditNackPacket(QSharedPointer<NLPacket> packet, SharedNodePointer sendingNode) {
|
||||
if (_shouldNack) {
|
||||
processNackPacket(QByteArray::fromRawData(packet->getData(), packet->getDataSize()));
|
||||
processNackPacket(*packet, sendingNode);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,12 +14,10 @@
|
|||
|
||||
#include <OctreeEditPacketSender.h>
|
||||
|
||||
#include <PacketListener.h>
|
||||
|
||||
#include "EntityItem.h"
|
||||
|
||||
/// Utility for processing, packing, queueing and sending of outbound edit voxel messages.
|
||||
class EntityEditPacketSender : public OctreeEditPacketSender, public PacketListener {
|
||||
class EntityEditPacketSender : public OctreeEditPacketSender {
|
||||
Q_OBJECT
|
||||
public:
|
||||
EntityEditPacketSender();
|
||||
|
@ -37,7 +35,7 @@ public:
|
|||
virtual void adjustEditPacketForClockSkew(PacketType::Value type, QByteArray& buffer, int clockSkew);
|
||||
|
||||
public slots:
|
||||
void processEntityEditNackPacket(QSharedPointer<NLPacket> packet);
|
||||
void processEntityEditNackPacket(QSharedPointer<NLPacket> packet, SharedNodePointer sendingNode);
|
||||
void toggleNackPackets() { _shouldNack = !_shouldNack; }
|
||||
|
||||
private:
|
||||
|
|
|
@ -22,14 +22,13 @@
|
|||
#include "HifiSockAddr.h"
|
||||
#include "NetworkPeer.h"
|
||||
#include "NLPacket.h"
|
||||
#include "PacketListener.h"
|
||||
|
||||
const unsigned short DEFAULT_DOMAIN_SERVER_PORT = 40102;
|
||||
const unsigned short DEFAULT_DOMAIN_SERVER_DTLS_PORT = 40103;
|
||||
const quint16 DOMAIN_SERVER_HTTP_PORT = 40100;
|
||||
const quint16 DOMAIN_SERVER_HTTPS_PORT = 40101;
|
||||
|
||||
class DomainHandler : public QObject, public PacketListener {
|
||||
class DomainHandler : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DomainHandler(QObject* parent = 0);
|
||||
|
|
|
@ -206,9 +206,9 @@ bool LimitedNodeList::packetSourceAndHashMatch(const NLPacket& packet, SharedNod
|
|||
|
||||
} else {
|
||||
static QString repeatedMessage
|
||||
= LogHandler::getInstance().addRepeatedMessageRegex("Packet of type \\d+ received from unknown node with UUID");
|
||||
= LogHandler::getInstance().addRepeatedMessageRegex("Packet of type \\d+ \\([\\sa-zA-Z]+\\) received from unknown node with UUID");
|
||||
|
||||
qCDebug(networking) << "Packet of type" << packet.getType() << "(" << nameForPacketType(packet.getType()) << ")"
|
||||
qCDebug(networking) << "Packet of type" << packet.getType() << "(" << qPrintable(nameForPacketType(packet.getType())) << ")"
|
||||
<< "received from unknown node with UUID" << qPrintable(uuidStringWithoutCurlyBraces(packet.getSourceID()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,6 @@
|
|||
#include "NLPacket.h"
|
||||
#include "udt/PacketHeaders.h"
|
||||
#include "PacketReceiver.h"
|
||||
#include "PacketListener.h"
|
||||
#include "NLPacketList.h"
|
||||
#include "UUIDHasher.h"
|
||||
|
||||
|
@ -74,7 +73,7 @@ namespace PingType {
|
|||
const PingType_t Symmetric = 3;
|
||||
}
|
||||
|
||||
class LimitedNodeList : public QObject, public Dependency, public PacketListener {
|
||||
class LimitedNodeList : public QObject, public Dependency {
|
||||
Q_OBJECT
|
||||
SINGLETON_DEPENDENCY
|
||||
public:
|
||||
|
|
|
@ -98,6 +98,7 @@ NodeList::NodeList(char newOwnerType, unsigned short socketListenPort, unsigned
|
|||
packetReceiver.registerListener(PacketType::ICEServerPeerInformation, &_domainHandler, "processICEResponsePacket");
|
||||
packetReceiver.registerListener(PacketType::DomainServerRequireDTLS, &_domainHandler, "processDTLSRequirementPacket");
|
||||
packetReceiver.registerListener(PacketType::ICEPingReply, &_domainHandler, "processICEPingReplyPacket");
|
||||
packetReceiver.registerListener(PacketType::DomainServerPathResponse, this, "processDomainServerPathResponse");
|
||||
}
|
||||
|
||||
qint64 NodeList::sendStats(const QJsonObject& statsObject, const HifiSockAddr& destination) {
|
||||
|
@ -339,9 +340,9 @@ void NodeList::sendDSPathQuery(const QString& newPath) {
|
|||
QByteArray pathQueryUTF8 = newPath.toUtf8();
|
||||
|
||||
// get the size of the UTF8 representation of the desired path
|
||||
qint64 numPathBytes = pathQueryUTF8.size();
|
||||
quint16 numPathBytes = pathQueryUTF8.size();
|
||||
|
||||
if (numPathBytes + ((qint64) sizeof(numPathBytes)) < pathQueryPacket->bytesAvailableForWrite()) {
|
||||
if (numPathBytes + ((qint16) sizeof(numPathBytes)) < pathQueryPacket->bytesAvailableForWrite()) {
|
||||
// append the size of the path to the query packet
|
||||
pathQueryPacket->writePrimitive(numPathBytes);
|
||||
|
||||
|
@ -360,35 +361,41 @@ void NodeList::sendDSPathQuery(const QString& newPath) {
|
|||
}
|
||||
}
|
||||
|
||||
void NodeList::processDomainServerPathQueryResponse(QSharedPointer<NLPacket> packet) {
|
||||
void NodeList::processDomainServerPathResponse(QSharedPointer<NLPacket> packet) {
|
||||
// This is a response to a path query we theoretically made.
|
||||
// In the future we may want to check that this was actually from our DS and for a query we actually made.
|
||||
|
||||
// figure out how many bytes the path query is
|
||||
qint16 numPathBytes;
|
||||
quint16 numPathBytes;
|
||||
packet->readPrimitive(&numPathBytes);
|
||||
|
||||
// pull the path from the packet
|
||||
QString pathQuery = QString::fromUtf8(packet->read(numPathBytes));
|
||||
if (packet->bytesLeftToRead() < numPathBytes) {
|
||||
qCDebug(networking) << "Could not read query path from DomainServerPathQueryResponse. Bailing.";
|
||||
return;
|
||||
}
|
||||
|
||||
QString pathQuery = QString::fromUtf8(packet->getPayload() + packet->pos(), numPathBytes);
|
||||
packet->seek(packet->pos() + numPathBytes);
|
||||
|
||||
// figure out how many bytes the viewpoint is
|
||||
qint16 numViewpointBytes;
|
||||
quint16 numViewpointBytes;
|
||||
packet->readPrimitive(&numViewpointBytes);
|
||||
|
||||
if (packet->bytesLeftToRead() < numViewpointBytes) {
|
||||
qCDebug(networking) << "Could not read resulting viewpoint from DomainServerPathQueryReponse. Bailing";
|
||||
return;
|
||||
}
|
||||
|
||||
// pull the viewpoint from the packet
|
||||
auto stringData = packet->read(numViewpointBytes);
|
||||
if (stringData.size() == numViewpointBytes) {
|
||||
QString viewpoint = QString::fromUtf8(stringData);
|
||||
|
||||
// Hand it off to the AddressManager so it can handle it as a relative viewpoint
|
||||
if (DependencyManager::get<AddressManager>()->goToViewpointForPath(viewpoint, pathQuery)) {
|
||||
qCDebug(networking) << "Going to viewpoint" << viewpoint << "which was the lookup result for path" << pathQuery;
|
||||
} else {
|
||||
qCDebug(networking) << "Could not go to viewpoint" << viewpoint
|
||||
<< "which was the lookup result for path" << pathQuery;
|
||||
}
|
||||
QString viewpoint = QString::fromUtf8(packet->getPayload() + packet->pos(), numViewpointBytes);
|
||||
|
||||
// Hand it off to the AddressManager so it can handle it as a relative viewpoint
|
||||
if (DependencyManager::get<AddressManager>()->goToViewpointForPath(viewpoint, pathQuery)) {
|
||||
qCDebug(networking) << "Going to viewpoint" << viewpoint << "which was the lookup result for path" << pathQuery;
|
||||
} else {
|
||||
qCDebug(networking) << "Error loading viewpoint from path query response";
|
||||
qCDebug(networking) << "Could not go to viewpoint" << viewpoint
|
||||
<< "which was the lookup result for path" << pathQuery;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ public slots:
|
|||
|
||||
void processDomainServerList(QSharedPointer<NLPacket> packet);
|
||||
void processDomainServerAddedNode(QSharedPointer<NLPacket> packet);
|
||||
void processDomainServerPathQueryResponse(QSharedPointer<NLPacket> packet);
|
||||
void processDomainServerPathResponse(QSharedPointer<NLPacket> packet);
|
||||
|
||||
void processPingPacket(QSharedPointer<NLPacket> packet, SharedNodePointer sendingNode);
|
||||
void processPingReplyPacket(QSharedPointer<NLPacket> packet, SharedNodePointer sendingNode);
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
//
|
||||
// PacketListener.cpp
|
||||
// libraries/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 "PacketListener.h"
|
||||
|
||||
#include "NodeList.h"
|
||||
|
||||
PacketListener::~PacketListener() {
|
||||
auto limitedNodelist = DependencyManager::get<LimitedNodeList>();
|
||||
if (limitedNodelist) {
|
||||
limitedNodelist->getPacketReceiver().unregisterListener(this);
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
//
|
||||
// PacketListener.h
|
||||
// libraries/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_PacketListener_h
|
||||
#define hifi_PacketListener_h
|
||||
|
||||
#pragma once
|
||||
|
||||
class PacketListener {
|
||||
public:
|
||||
virtual ~PacketListener();
|
||||
};
|
||||
|
||||
#endif // hifi_PacketListener_h
|
|
@ -24,7 +24,7 @@ PacketReceiver::PacketReceiver(QObject* parent) :
|
|||
qRegisterMetaType<QSharedPointer<NLPacket>>();
|
||||
}
|
||||
|
||||
bool PacketReceiver::registerListenerForTypes(const QSet<PacketType::Value>& types, PacketListener* listener, const char* slot) {
|
||||
bool PacketReceiver::registerListenerForTypes(const QSet<PacketType::Value>& types, QObject* listener, const char* slot) {
|
||||
QSet<PacketType::Value> nonSourcedTypes;
|
||||
QSet<PacketType::Value> sourcedTypes;
|
||||
|
||||
|
@ -36,14 +36,13 @@ bool PacketReceiver::registerListenerForTypes(const QSet<PacketType::Value>& typ
|
|||
}
|
||||
}
|
||||
|
||||
QObject* object = dynamic_cast<QObject*>(listener);
|
||||
Q_ASSERT(object);
|
||||
Q_ASSERT(listener);
|
||||
|
||||
if (nonSourcedTypes.size() > 0) {
|
||||
QMetaMethod nonSourcedMethod = matchingMethodForListener(*nonSourcedTypes.begin(), object, slot);
|
||||
QMetaMethod nonSourcedMethod = matchingMethodForListener(*nonSourcedTypes.begin(), listener, slot);
|
||||
if (nonSourcedMethod.isValid()) {
|
||||
foreach(PacketType::Value type, nonSourcedTypes) {
|
||||
registerVerifiedListener(type, object, nonSourcedMethod);
|
||||
registerVerifiedListener(type, listener, nonSourcedMethod);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
|
@ -51,10 +50,10 @@ bool PacketReceiver::registerListenerForTypes(const QSet<PacketType::Value>& typ
|
|||
}
|
||||
|
||||
if (sourcedTypes.size() > 0) {
|
||||
QMetaMethod sourcedMethod = matchingMethodForListener(*sourcedTypes.begin(), object, slot);
|
||||
QMetaMethod sourcedMethod = matchingMethodForListener(*sourcedTypes.begin(), listener, slot);
|
||||
if (sourcedMethod.isValid()) {
|
||||
foreach(PacketType::Value type, sourcedTypes) {
|
||||
registerVerifiedListener(type, object, sourcedMethod);
|
||||
registerVerifiedListener(type, listener, sourcedMethod);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
|
@ -66,7 +65,7 @@ bool PacketReceiver::registerListenerForTypes(const QSet<PacketType::Value>& typ
|
|||
|
||||
|
||||
void PacketReceiver::registerDirectListenerForTypes(const QSet<PacketType::Value>& types,
|
||||
PacketListener* listener, const char* slot) {
|
||||
QObject* listener, const char* slot) {
|
||||
// just call register listener for types to start
|
||||
bool success = registerListenerForTypes(types, listener, slot);
|
||||
if (success) {
|
||||
|
@ -79,14 +78,13 @@ void PacketReceiver::registerDirectListenerForTypes(const QSet<PacketType::Value
|
|||
}
|
||||
}
|
||||
|
||||
bool PacketReceiver::registerListener(PacketType::Value type, PacketListener* listener, const char* slot) {
|
||||
QObject* object = dynamic_cast<QObject*>(listener);
|
||||
Q_ASSERT(object);
|
||||
bool PacketReceiver::registerListener(PacketType::Value type, QObject* listener, const char* slot) {
|
||||
Q_ASSERT(listener);
|
||||
|
||||
QMetaMethod matchingMethod = matchingMethodForListener(type, object, slot);
|
||||
QMetaMethod matchingMethod = matchingMethodForListener(type, listener, slot);
|
||||
|
||||
if (matchingMethod.isValid()) {
|
||||
registerVerifiedListener(type, object, matchingMethod);
|
||||
registerVerifiedListener(type, listener, matchingMethod);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -151,25 +149,24 @@ void PacketReceiver::registerVerifiedListener(PacketType::Value type, QObject* o
|
|||
|
||||
if (_packetListenerMap.contains(type)) {
|
||||
qDebug() << "Warning: Registering a packet listener for packet type" << type
|
||||
<< "(" << qPrintable(nameForPacketType(type)) << ")"
|
||||
<< "that will remove a previously registered listener";
|
||||
}
|
||||
|
||||
// add the mapping
|
||||
_packetListenerMap[type] = ObjectMethodPair(object, slot);
|
||||
_packetListenerMap[type] = ObjectMethodPair(QPointer<QObject>(object), slot);
|
||||
|
||||
_packetListenerLock.unlock();
|
||||
|
||||
}
|
||||
|
||||
void PacketReceiver::unregisterListener(PacketListener* listener) {
|
||||
QObject* listenerObject = dynamic_cast<QObject*>(listener);
|
||||
|
||||
void PacketReceiver::unregisterListener(QObject* listener) {
|
||||
_packetListenerLock.lock();
|
||||
|
||||
auto it = _packetListenerMap.begin();
|
||||
|
||||
while (it != _packetListenerMap.end()) {
|
||||
if (it.value().first == listenerObject) {
|
||||
if (it.value().first == listener) {
|
||||
// this listener matches - erase it
|
||||
it = _packetListenerMap.erase(it);
|
||||
} else {
|
||||
|
@ -180,7 +177,7 @@ void PacketReceiver::unregisterListener(PacketListener* listener) {
|
|||
_packetListenerLock.unlock();
|
||||
|
||||
_directConnectSetMutex.lock();
|
||||
_directlyConnectedObjects.remove(listenerObject);
|
||||
_directlyConnectedObjects.remove(listener);
|
||||
_directConnectSetMutex.unlock();
|
||||
}
|
||||
|
||||
|
@ -189,19 +186,35 @@ bool PacketReceiver::packetVersionMatch(const NLPacket& packet) {
|
|||
if (packet.getVersion() != versionForPacketType(packet.getType())
|
||||
&& packet.getType() != PacketType::StunResponse) {
|
||||
|
||||
static QMultiMap<QUuid, PacketType::Value> versionDebugSuppressMap;
|
||||
static QMultiHash<QUuid, PacketType::Value> sourcedVersionDebugSuppressMap;
|
||||
static QMultiHash<HifiSockAddr, PacketType::Value> versionDebugSuppressMap;
|
||||
|
||||
const QUuid& senderID = packet.getSourceID();
|
||||
|
||||
if (!versionDebugSuppressMap.contains(senderID, packet.getType())) {
|
||||
bool hasBeenOutput = false;
|
||||
QString senderString;
|
||||
|
||||
if (NON_SOURCED_PACKETS.contains(packet.getType())) {
|
||||
const HifiSockAddr& senderSockAddr = packet.getSenderSockAddr();
|
||||
hasBeenOutput = versionDebugSuppressMap.contains(senderSockAddr, packet.getType());
|
||||
|
||||
if (!hasBeenOutput) {
|
||||
versionDebugSuppressMap.insert(senderSockAddr, packet.getType());
|
||||
senderString = QString("%1:%2").arg(senderSockAddr.getAddress().toString()).arg(senderSockAddr.getPort());
|
||||
}
|
||||
} else {
|
||||
hasBeenOutput = sourcedVersionDebugSuppressMap.contains(packet.getSourceID(), packet.getType());
|
||||
|
||||
if (!hasBeenOutput) {
|
||||
sourcedVersionDebugSuppressMap.insert(packet.getSourceID(), packet.getType());
|
||||
senderString = uuidStringWithoutCurlyBraces(packet.getSourceID().toString());
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasBeenOutput) {
|
||||
qCDebug(networking) << "Packet version mismatch on" << packet.getType() << "- Sender"
|
||||
<< senderID << "sent" << qPrintable(QString::number(packet.getVersion())) << "but"
|
||||
<< senderString << "sent" << qPrintable(QString::number(packet.getVersion())) << "but"
|
||||
<< qPrintable(QString::number(versionForPacketType(packet.getType()))) << "expected.";
|
||||
|
||||
emit packetVersionMismatch(packet.getType());
|
||||
|
||||
versionDebugSuppressMap.insert(senderID, packet.getType());
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -251,6 +264,8 @@ void PacketReceiver::processDatagrams() {
|
|||
}
|
||||
|
||||
_packetListenerLock.lock();
|
||||
|
||||
bool listenerIsDead = false;
|
||||
|
||||
auto it = _packetListenerMap.find(packet->getType());
|
||||
|
||||
|
@ -284,27 +299,33 @@ void PacketReceiver::processDatagrams() {
|
|||
|
||||
static const QByteArray QSHAREDPOINTER_NODE_NORMALIZED = QMetaObject::normalizedType("QSharedPointer<Node>");
|
||||
static const QByteArray SHARED_NODE_NORMALIZED = QMetaObject::normalizedType("SharedNodePointer");
|
||||
|
||||
if (metaMethod.parameterTypes().contains(SHARED_NODE_NORMALIZED)) {
|
||||
success = metaMethod.invoke(listener.first,
|
||||
connectionType,
|
||||
Q_ARG(QSharedPointer<NLPacket>,
|
||||
QSharedPointer<NLPacket>(packet.release())),
|
||||
Q_ARG(SharedNodePointer, matchingNode));
|
||||
|
||||
} else if (metaMethod.parameterTypes().contains(QSHAREDPOINTER_NODE_NORMALIZED)) {
|
||||
success = metaMethod.invoke(listener.first,
|
||||
connectionType,
|
||||
Q_ARG(QSharedPointer<NLPacket>,
|
||||
QSharedPointer<NLPacket>(packet.release())),
|
||||
Q_ARG(QSharedPointer<Node>, matchingNode));
|
||||
|
||||
|
||||
// one final check on the QPointer before we go to invoke
|
||||
if (listener.first) {
|
||||
if (metaMethod.parameterTypes().contains(SHARED_NODE_NORMALIZED)) {
|
||||
success = metaMethod.invoke(listener.first,
|
||||
connectionType,
|
||||
Q_ARG(QSharedPointer<NLPacket>,
|
||||
QSharedPointer<NLPacket>(packet.release())),
|
||||
Q_ARG(SharedNodePointer, matchingNode));
|
||||
|
||||
} else if (metaMethod.parameterTypes().contains(QSHAREDPOINTER_NODE_NORMALIZED)) {
|
||||
success = metaMethod.invoke(listener.first,
|
||||
connectionType,
|
||||
Q_ARG(QSharedPointer<NLPacket>,
|
||||
QSharedPointer<NLPacket>(packet.release())),
|
||||
Q_ARG(QSharedPointer<Node>, matchingNode));
|
||||
|
||||
} else {
|
||||
success = metaMethod.invoke(listener.first,
|
||||
connectionType,
|
||||
Q_ARG(QSharedPointer<NLPacket>,
|
||||
QSharedPointer<NLPacket>(packet.release())));
|
||||
}
|
||||
} else {
|
||||
success = metaMethod.invoke(listener.first,
|
||||
connectionType,
|
||||
Q_ARG(QSharedPointer<NLPacket>,
|
||||
QSharedPointer<NLPacket>(packet.release())));
|
||||
listenerIsDead = true;
|
||||
}
|
||||
|
||||
} else {
|
||||
emit dataReceived(NodeType::Unassigned, packet->getDataSize());
|
||||
|
||||
|
@ -318,7 +339,17 @@ void PacketReceiver::processDatagrams() {
|
|||
<< listener.first << "::" << qPrintable(listener.second.methodSignature());
|
||||
}
|
||||
|
||||
} else {
|
||||
listenerIsDead = true;
|
||||
}
|
||||
|
||||
if (listenerIsDead) {
|
||||
qDebug().nospace() << "Listener for packet" << packet->getType()
|
||||
<< " (" << qPrintable(nameForPacketType(packet->getType())) << ")"
|
||||
<< " has been destroyed. Removing from listener map.";
|
||||
it = _packetListenerMap.erase(it);
|
||||
}
|
||||
|
||||
} else {
|
||||
qWarning() << "No listener found for packet type " << nameForPacketType(packet->getType());
|
||||
|
||||
|
|
|
@ -17,13 +17,13 @@
|
|||
#include <QtCore/QMetaMethod>
|
||||
#include <QtCore/QMutex>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QPointer>
|
||||
#include <QtCore/QSet>
|
||||
|
||||
#include "NLPacket.h"
|
||||
#include "udt/PacketHeaders.h"
|
||||
|
||||
class OctreePacketProcessor;
|
||||
class PacketListener;
|
||||
|
||||
class PacketReceiver : public QObject {
|
||||
Q_OBJECT
|
||||
|
@ -40,9 +40,9 @@ public:
|
|||
|
||||
void resetCounters() { _inPacketCount = 0; _inByteCount = 0; }
|
||||
|
||||
bool registerListenerForTypes(const QSet<PacketType::Value>& types, PacketListener* listener, const char* slot);
|
||||
bool registerListener(PacketType::Value type, PacketListener* listener, const char* slot);
|
||||
void unregisterListener(PacketListener* listener);
|
||||
bool registerListenerForTypes(const QSet<PacketType::Value>& types, QObject* listener, const char* slot);
|
||||
bool registerListener(PacketType::Value type, QObject* listener, const char* slot);
|
||||
void unregisterListener(QObject* listener);
|
||||
|
||||
public slots:
|
||||
void processDatagrams();
|
||||
|
@ -55,14 +55,14 @@ signals:
|
|||
private:
|
||||
// this is a brutal hack for now - ideally GenericThread / ReceivedPacketProcessor
|
||||
// should be changed to have a true event loop and be able to handle our QMetaMethod::invoke
|
||||
void registerDirectListenerForTypes(const QSet<PacketType::Value>& types, PacketListener* listener, const char* slot);
|
||||
void registerDirectListenerForTypes(const QSet<PacketType::Value>& types, QObject* listener, const char* slot);
|
||||
|
||||
bool packetVersionMatch(const NLPacket& packet);
|
||||
|
||||
QMetaMethod matchingMethodForListener(PacketType::Value type, QObject* object, const char* slot) const;
|
||||
void registerVerifiedListener(PacketType::Value type, QObject* listener, const QMetaMethod& slot);
|
||||
|
||||
using ObjectMethodPair = std::pair<QObject*, QMetaMethod>;
|
||||
using ObjectMethodPair = std::pair<QPointer<QObject>, QMetaMethod>;
|
||||
|
||||
QMutex _packetListenerLock;
|
||||
QHash<PacketType::Value, ObjectMethodPair> _packetListenerMap;
|
||||
|
|
|
@ -14,11 +14,9 @@
|
|||
|
||||
#include <QtCore/QSharedPointer>
|
||||
|
||||
#include "PacketListener.h"
|
||||
|
||||
#include "Assignment.h"
|
||||
|
||||
class ThreadedAssignment : public Assignment, public PacketListener {
|
||||
class ThreadedAssignment : public Assignment {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ThreadedAssignment(NLPacket& packet);
|
||||
|
|
|
@ -32,7 +32,7 @@ const QSet<PacketType::Value> NON_SOURCED_PACKETS = QSet<PacketType::Value>()
|
|||
<< DomainServerAddedNode
|
||||
<< ICEServerPeerInformation << ICEServerQuery << ICEServerHeartbeat
|
||||
<< ICEPing << ICEPingReply
|
||||
<< AssignmentClientStatus;
|
||||
<< AssignmentClientStatus << StopNode;
|
||||
|
||||
int arithmeticCodingValueFromBuffer(const char* checkValue) {
|
||||
if (((uchar) *checkValue) < 255) {
|
||||
|
@ -64,50 +64,12 @@ int packArithmeticallyCodedValue(int value, char* destination) {
|
|||
|
||||
PacketVersion versionForPacketType(PacketType::Value packetType) {
|
||||
switch (packetType) {
|
||||
case MicrophoneAudioNoEcho:
|
||||
case MicrophoneAudioWithEcho:
|
||||
return 3;
|
||||
case SilentAudioFrame:
|
||||
return 5;
|
||||
case MixedAudio:
|
||||
return 2;
|
||||
case InjectAudio:
|
||||
return 2;
|
||||
case AvatarData:
|
||||
return 7;
|
||||
case AvatarIdentity:
|
||||
return 2;
|
||||
case EnvironmentData:
|
||||
return 3;
|
||||
case DomainList:
|
||||
case DomainListRequest:
|
||||
return 6;
|
||||
case DomainConnectRequest:
|
||||
return 2;
|
||||
case CreateAssignment:
|
||||
case RequestAssignment:
|
||||
return 3;
|
||||
case OctreeStats:
|
||||
return 2;
|
||||
case OctreeDataNack:
|
||||
return 2;
|
||||
case StopNode:
|
||||
return 2;
|
||||
case EntityAdd:
|
||||
case EntityEdit:
|
||||
case EntityData:
|
||||
return VERSION_ENTITIES_NEW_PROTOCOL_LAYER;
|
||||
case EntityEditNack:
|
||||
return 2;
|
||||
case EntityErase:
|
||||
return 3;
|
||||
case AudioStreamStats:
|
||||
return 2;
|
||||
case ICEServerHeartbeat:
|
||||
case ICEServerQuery:
|
||||
return 2;
|
||||
default:
|
||||
return 1;
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,7 +90,6 @@ QString nameForPacketType(PacketType::Value packetType) {
|
|||
PACKET_TYPE_NAME_LOOKUP(MicrophoneAudioWithEcho);
|
||||
PACKET_TYPE_NAME_LOOKUP(BulkAvatarData);
|
||||
PACKET_TYPE_NAME_LOOKUP(SilentAudioFrame);
|
||||
PACKET_TYPE_NAME_LOOKUP(EnvironmentData);
|
||||
PACKET_TYPE_NAME_LOOKUP(DomainListRequest);
|
||||
PACKET_TYPE_NAME_LOOKUP(RequestAssignment);
|
||||
PACKET_TYPE_NAME_LOOKUP(CreateAssignment);
|
||||
|
@ -150,7 +111,6 @@ QString nameForPacketType(PacketType::Value packetType) {
|
|||
PACKET_TYPE_NAME_LOOKUP(StopNode);
|
||||
PACKET_TYPE_NAME_LOOKUP(AudioEnvironment);
|
||||
PACKET_TYPE_NAME_LOOKUP(EntityEditNack);
|
||||
PACKET_TYPE_NAME_LOOKUP(SignedTransactionPayment);
|
||||
PACKET_TYPE_NAME_LOOKUP(ICEServerHeartbeat);
|
||||
PACKET_TYPE_NAME_LOOKUP(DomainServerAddedNode);
|
||||
PACKET_TYPE_NAME_LOOKUP(ICEServerQuery);
|
||||
|
@ -165,66 +125,6 @@ QString nameForPacketType(PacketType::Value packetType) {
|
|||
return QString("unexpected");
|
||||
}
|
||||
|
||||
int numBytesForPacketHeader(const QByteArray& packet) {
|
||||
PacketType::Value packetType = packetTypeForPacket(packet);
|
||||
return numBytesForPacketHeaderGivenPacketType(packetType);
|
||||
}
|
||||
|
||||
int numBytesForPacketHeader(const char* packet) {
|
||||
PacketType::Value packetType = packetTypeForPacket(packet);
|
||||
return numBytesForPacketHeaderGivenPacketType(packetType);
|
||||
}
|
||||
|
||||
int numBytesForArithmeticCodedPacketType(PacketType::Value packetType) {
|
||||
return (int) ceilf((float) packetType / 255);
|
||||
}
|
||||
|
||||
int numBytesForPacketHeaderGivenPacketType(PacketType::Value packetType) {
|
||||
return numBytesForArithmeticCodedPacketType(packetType)
|
||||
+ numHashBytesForType(packetType)
|
||||
+ numSequenceNumberBytesForType(packetType)
|
||||
+ NUM_STATIC_HEADER_BYTES;
|
||||
}
|
||||
|
||||
int numHashBytesForType(PacketType::Value packetType) {
|
||||
return (NON_VERIFIED_PACKETS.contains(packetType) ? 0 : NUM_BYTES_MD5_HASH);
|
||||
}
|
||||
|
||||
int numSequenceNumberBytesForType(PacketType::Value packetType) {
|
||||
return (SEQUENCE_NUMBERED_PACKETS.contains(packetType) ? sizeof(PacketSequenceNumber) : 0);
|
||||
}
|
||||
|
||||
QUuid uuidFromPacketHeader(const QByteArray& packet) {
|
||||
return QUuid::fromRfc4122(packet.mid(numBytesArithmeticCodingFromBuffer(packet.data()) + sizeof(PacketVersion),
|
||||
NUM_BYTES_RFC4122_UUID));
|
||||
}
|
||||
|
||||
int hashOffsetForPacketType(PacketType::Value packetType) {
|
||||
return numBytesForArithmeticCodedPacketType(packetType) + NUM_STATIC_HEADER_BYTES;
|
||||
}
|
||||
|
||||
int sequenceNumberOffsetForPacketType(PacketType::Value packetType) {
|
||||
return numBytesForPacketHeaderGivenPacketType(packetType) - sizeof(PacketSequenceNumber);
|
||||
}
|
||||
|
||||
PacketSequenceNumber sequenceNumberFromHeader(const QByteArray& packet, PacketType::Value packetType) {
|
||||
if (packetType == PacketType::Unknown) {
|
||||
packetType = packetTypeForPacket(packet);
|
||||
}
|
||||
|
||||
PacketSequenceNumber result = DEFAULT_SEQUENCE_NUMBER;
|
||||
|
||||
if (SEQUENCE_NUMBERED_PACKETS.contains(packetType)) {
|
||||
memcpy(&result, packet.data() + sequenceNumberOffsetForPacketType(packetType), sizeof(PacketSequenceNumber));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
PacketType::Value packetTypeForPacket(const QByteArray& packet) {
|
||||
return (PacketType::Value) arithmeticCodingValueFromBuffer(packet.data());
|
||||
}
|
||||
|
||||
PacketType::Value packetTypeForPacket(const char* packet) {
|
||||
return (PacketType::Value) arithmeticCodingValueFromBuffer(packet);
|
||||
}
|
||||
|
|
|
@ -28,62 +28,59 @@
|
|||
|
||||
namespace PacketType {
|
||||
enum Value {
|
||||
Unknown, // 0
|
||||
Unknown,
|
||||
StunResponse,
|
||||
DomainList,
|
||||
Ping,
|
||||
PingReply,
|
||||
KillAvatar, // 5
|
||||
KillAvatar,
|
||||
AvatarData,
|
||||
InjectAudio,
|
||||
MixedAudio,
|
||||
MicrophoneAudioNoEcho,
|
||||
MicrophoneAudioWithEcho, // 10
|
||||
MicrophoneAudioWithEcho,
|
||||
BulkAvatarData,
|
||||
SilentAudioFrame,
|
||||
EnvironmentData,
|
||||
DomainListRequest,
|
||||
RequestAssignment, // 15
|
||||
RequestAssignment,
|
||||
CreateAssignment,
|
||||
DomainConnectionDenied,
|
||||
MuteEnvironment,
|
||||
AudioStreamStats,
|
||||
UNUSED, // 20
|
||||
DomainServerPathQuery,
|
||||
DomainServerPathResponse,
|
||||
DomainServerAddedNode,
|
||||
ICEServerPeerInformation,
|
||||
ICEServerQuery, // 25
|
||||
ICEServerQuery,
|
||||
OctreeStats,
|
||||
Jurisdiction,
|
||||
JurisdictionRequest,
|
||||
AssignmentClientStatus,
|
||||
UNUSED_7, // 30
|
||||
UNUSED_8,
|
||||
UNUSED_9,
|
||||
NoisyMute,
|
||||
UNUSED_10,
|
||||
AvatarIdentity, // 35
|
||||
AvatarIdentity,
|
||||
AvatarBillboard,
|
||||
DomainConnectRequest,
|
||||
DomainServerRequireDTLS,
|
||||
NodeJsonStats,
|
||||
EntityQuery, // 40
|
||||
EntityQuery,
|
||||
EntityData,
|
||||
EntityAdd,
|
||||
EntityErase,
|
||||
EntityEdit,
|
||||
OctreeDataNack, // 45
|
||||
OctreeDataNack,
|
||||
StopNode,
|
||||
AudioEnvironment,
|
||||
EntityEditNack,
|
||||
SignedTransactionPayment,
|
||||
ICEServerHeartbeat, // 50
|
||||
ICEServerHeartbeat,
|
||||
ICEPing,
|
||||
ICEPingReply
|
||||
};
|
||||
};
|
||||
|
||||
const int NUM_BYTES_MD5_HASH = 16;
|
||||
|
||||
const int MAX_PACKET_SIZE = 1450;
|
||||
const int MAX_PACKET_HEADER_BYTES = 4 + NUM_BYTES_RFC4122_UUID + NUM_BYTES_MD5_HASH;
|
||||
|
||||
typedef char PacketVersion;
|
||||
|
||||
|
@ -96,37 +93,13 @@ extern const QSet<PacketType::Value> NON_VERIFIED_PACKETS;
|
|||
extern const QSet<PacketType::Value> SEQUENCE_NUMBERED_PACKETS;
|
||||
extern const QSet<PacketType::Value> NON_SOURCED_PACKETS;
|
||||
|
||||
const int NUM_BYTES_MD5_HASH = 16;
|
||||
const int NUM_STATIC_HEADER_BYTES = sizeof(PacketVersion) + NUM_BYTES_RFC4122_UUID;
|
||||
const int MAX_PACKET_HEADER_BYTES = sizeof(PacketType::Value) + NUM_BYTES_MD5_HASH + NUM_STATIC_HEADER_BYTES;
|
||||
|
||||
PacketType::Value packetTypeForPacket(const QByteArray& packet);
|
||||
PacketType::Value packetTypeForPacket(const char* packet);
|
||||
|
||||
PacketVersion versionForPacketType(PacketType::Value packetType);
|
||||
QString nameForPacketType(PacketType::Value packetType);
|
||||
PacketVersion versionForPacketType(PacketType::Value packetType);
|
||||
|
||||
const QUuid nullUUID = QUuid();
|
||||
|
||||
int numHashBytesForType(PacketType::Value packetType);
|
||||
int numSequenceNumberBytesForType(PacketType::Value packetType);
|
||||
|
||||
int numBytesForPacketHeader(const QByteArray& packet);
|
||||
int numBytesForPacketHeader(const char* packet);
|
||||
int numBytesForArithmeticCodedPacketType(PacketType::Value packetType);
|
||||
int numBytesForPacketHeaderGivenPacketType(PacketType::Value packetType);
|
||||
int packArithmeticallyCodedValue(int value, char* destination);
|
||||
|
||||
QUuid uuidFromPacketHeader(const QByteArray& packet);
|
||||
|
||||
int hashOffsetForPacketType(PacketType::Value packetType);
|
||||
int sequenceNumberOffsetForPacketType(PacketType::Value packetType);
|
||||
|
||||
// NOTE: The following four methods accept a PacketType::Value which defaults to PacketType::Unknown.
|
||||
// If the caller has already looked at the packet type and can provide it then the methods below won't have to look it up.
|
||||
|
||||
PacketSequenceNumber sequenceNumberFromHeader(const QByteArray& packet, PacketType::Value packetType = PacketType::Unknown);
|
||||
|
||||
int arithmeticCodingValueFromBuffer(const char* checkValue);
|
||||
int numBytesArithmeticCodingFromBuffer(const char* checkValue);
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ std::unique_ptr<Packet> PacketList::createPacketWithExtendedHeader() {
|
|||
// add the extended header to the front of the packet
|
||||
if (packet->write(_extendedHeader) == -1) {
|
||||
qDebug() << "Could not write extendedHeader in PacketList::createPacketWithExtendedHeader"
|
||||
<< "- make sure that _extendedHeader is not larger than the payload capacity.";
|
||||
<< "- make sure that _extendedHeader is not larger than the payload capacity.";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -591,38 +591,6 @@ void Octree::eraseAllOctreeElements(bool createNewRoot) {
|
|||
_isDirty = true;
|
||||
}
|
||||
|
||||
void Octree::processRemoveOctreeElementsBitstream(const unsigned char* bitstream, int bufferSizeBytes) {
|
||||
//unsigned short int itemNumber = (*((unsigned short int*)&bitstream[sizeof(PACKET_HEADER)]));
|
||||
|
||||
int numBytesPacketHeader = numBytesForPacketHeader(reinterpret_cast<const char*>(bitstream));
|
||||
unsigned short int sequence = (*((unsigned short int*)(bitstream + numBytesPacketHeader)));
|
||||
quint64 sentAt = (*((quint64*)(bitstream + numBytesPacketHeader + sizeof(sequence))));
|
||||
|
||||
int atByte = numBytesPacketHeader + sizeof(sequence) + sizeof(sentAt);
|
||||
|
||||
unsigned char* voxelCode = (unsigned char*)&bitstream[atByte];
|
||||
while (atByte < bufferSizeBytes) {
|
||||
int maxSize = bufferSizeBytes - atByte;
|
||||
int codeLength = numberOfThreeBitSectionsInCode(voxelCode, maxSize);
|
||||
|
||||
if (codeLength == OVERFLOWED_OCTCODE_BUFFER) {
|
||||
qCDebug(octree, "WARNING! Got remove voxel bitstream that would overflow buffer in numberOfThreeBitSectionsInCode(),"
|
||||
" bailing processing of packet!");
|
||||
break;
|
||||
}
|
||||
int voxelDataSize = bytesRequiredForCodeLength(codeLength) + SIZE_OF_COLOR_DATA;
|
||||
|
||||
if (atByte + voxelDataSize <= bufferSizeBytes) {
|
||||
deleteOctalCodeFromTree(voxelCode, COLLAPSE_EMPTY_TREE);
|
||||
voxelCode += voxelDataSize;
|
||||
atByte += voxelDataSize;
|
||||
} else {
|
||||
qCDebug(octree, "WARNING! Got remove voxel bitstream that would overflow buffer, bailing processing!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Note: this is an expensive call. Don't call it unless you really need to reaverage the entire tree (from startElement)
|
||||
void Octree::reaverageOctreeElements(OctreeElement* startElement) {
|
||||
if (!startElement) {
|
||||
|
|
|
@ -254,7 +254,6 @@ public:
|
|||
|
||||
virtual void eraseAllOctreeElements(bool createNewRoot = true);
|
||||
|
||||
void processRemoveOctreeElementsBitstream(const unsigned char* bitstream, int bufferSizeBytes);
|
||||
void readBitstreamToTree(const unsigned char* bitstream, unsigned long int bufferSizeBytes, ReadBitstreamToTreeParams& args);
|
||||
void deleteOctalCodeFromTree(const unsigned char* codeBuffer, bool collapseEmptyTrees = DONT_COLLAPSE);
|
||||
void reaverageOctreeElements(OctreeElement* startElement = NULL);
|
||||
|
|
|
@ -339,35 +339,24 @@ bool OctreeEditPacketSender::process() {
|
|||
return PacketSender::process();
|
||||
}
|
||||
|
||||
void OctreeEditPacketSender::processNackPacket(const QByteArray& packet) {
|
||||
void OctreeEditPacketSender::processNackPacket(NLPacket& packet, SharedNodePointer sendingNode) {
|
||||
// parse sending node from packet, retrieve packet history for that node
|
||||
QUuid sendingNodeUUID = uuidFromPacketHeader(packet);
|
||||
|
||||
// if packet history doesn't exist for the sender node (somehow), bail
|
||||
if (_sentPacketHistories.count(sendingNodeUUID) == 0) {
|
||||
if (_sentPacketHistories.count(sendingNode->getUUID()) == 0) {
|
||||
return;
|
||||
}
|
||||
const SentPacketHistory& sentPacketHistory = _sentPacketHistories[sendingNodeUUID];
|
||||
|
||||
// TODO: these NAK packets no longer send the number of sequence numbers - just read out sequence numbers in blocks
|
||||
|
||||
int numBytesPacketHeader = numBytesForPacketHeader(packet);
|
||||
const unsigned char* dataAt = reinterpret_cast<const unsigned char*>(packet.data()) + numBytesPacketHeader;
|
||||
|
||||
// read number of sequence numbers
|
||||
uint16_t numSequenceNumbers = (*(uint16_t*)dataAt);
|
||||
dataAt += sizeof(uint16_t);
|
||||
const SentPacketHistory& sentPacketHistory = _sentPacketHistories[sendingNode->getUUID()];
|
||||
|
||||
// read sequence numbers and queue packets for resend
|
||||
for (int i = 0; i < numSequenceNumbers; i++) {
|
||||
unsigned short int sequenceNumber = (*(unsigned short int*)dataAt);
|
||||
dataAt += sizeof(unsigned short int);
|
||||
|
||||
while (packet.bytesLeftToRead() > 0) {
|
||||
unsigned short int sequenceNumber;
|
||||
packet.readPrimitive(&sequenceNumber);
|
||||
|
||||
// retrieve packet from history
|
||||
const NLPacket* packet = sentPacketHistory.getPacket(sequenceNumber);
|
||||
if (packet) {
|
||||
const SharedNodePointer& node = DependencyManager::get<NodeList>()->nodeWithUUID(sendingNodeUUID);
|
||||
queuePacketForSending(node, NLPacket::createCopy(*packet));
|
||||
queuePacketForSending(sendingNode, NLPacket::createCopy(*packet));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ public:
|
|||
virtual char getMyNodeType() const = 0;
|
||||
virtual void adjustEditPacketForClockSkew(PacketType::Value type, QByteArray& buffer, int clockSkew) { }
|
||||
|
||||
void processNackPacket(const QByteArray& packet);
|
||||
void processNackPacket(NLPacket& packet, SharedNodePointer sendingNode);
|
||||
|
||||
public slots:
|
||||
void nodeKilled(SharedNodePointer node);
|
||||
|
|
|
@ -196,30 +196,6 @@ bool Environment::findCapsulePenetration(const glm::vec3& start, const glm::vec3
|
|||
return found;
|
||||
}
|
||||
|
||||
int Environment::processPacket(NLPacket& packet) {
|
||||
// push past flags, sequence, timestamp
|
||||
packet.seek(sizeof(OCTREE_PACKET_FLAGS) + sizeof(OCTREE_PACKET_SEQUENCE) + sizeof(OCTREE_PACKET_SENT_TIME));
|
||||
|
||||
// get the lock for the duration of the call
|
||||
QMutexLocker locker(&_mutex);
|
||||
|
||||
EnvironmentData newData;
|
||||
|
||||
while (packet.bytesLeftToRead() > 0) {
|
||||
int dataLength = newData.parseData(reinterpret_cast<const unsigned char*>(packet.getPayload() + packet.pos()),
|
||||
packet.bytesLeftToRead());
|
||||
packet.seek(packet.pos() + dataLength);
|
||||
|
||||
// update the mapping by address/ID
|
||||
_data[packet.getSourceID()][newData.getID()] = newData;
|
||||
}
|
||||
|
||||
// remove the default mapping, if any
|
||||
_data.remove(QUuid());
|
||||
|
||||
return packet.pos();
|
||||
}
|
||||
|
||||
void Environment::renderAtmosphere(gpu::Batch& batch, ViewFrustum& camera, const EnvironmentData& data) {
|
||||
|
||||
glm::vec3 center = data.getAtmosphereCenter();
|
||||
|
|
|
@ -37,8 +37,6 @@ public:
|
|||
|
||||
EnvironmentData getClosestData(const glm::vec3& position);
|
||||
|
||||
int processPacket(NLPacket& packet);
|
||||
|
||||
private:
|
||||
glm::vec3 getGravity (const glm::vec3& position); // NOTE: Deprecated
|
||||
bool findCapsulePenetration(const glm::vec3& start,
|
||||
|
|
|
@ -35,7 +35,6 @@ void GenericThread::initialize(bool isThreaded, QThread::Priority priority) {
|
|||
|
||||
// match the thread name to our object name
|
||||
_thread->setObjectName(objectName());
|
||||
_thread->setPriority(priority);
|
||||
|
||||
// when the worker thread is started, call our engine's run..
|
||||
connect(_thread, SIGNAL(started()), this, SLOT(threadRoutine()));
|
||||
|
@ -44,6 +43,8 @@ void GenericThread::initialize(bool isThreaded, QThread::Priority priority) {
|
|||
|
||||
// Starts an event loop, and emits _thread->started()
|
||||
_thread->start();
|
||||
|
||||
_thread->setPriority(priority);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue