mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 08:30:35 +02:00
Merge branch 'atp' of github.com:birarda/hifi into receive_packets
Conflicts: assignment-client/src/entities/EntityServer.cpp domain-server/src/DomainServer.cpp
This commit is contained in:
commit
56b5c9acff
51 changed files with 301 additions and 178 deletions
|
@ -50,13 +50,13 @@ Agent::Agent(NLPacket& packet) :
|
|||
|
||||
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
|
||||
|
||||
packetReceiver.registerPacketListenerForTypes(
|
||||
QSet<PacketType::Value>({ PacketType::MixedAudio, PacketType::SilentAudioFrame }),
|
||||
packetReceiver.registerListenerForTypes(
|
||||
{ PacketType::MixedAudio, PacketType::SilentAudioFrame },
|
||||
this, "handleAudioPacket");
|
||||
packetReceiver.registerPacketListenerForTypes(
|
||||
QSet<PacketType::Value>({ PacketType::OctreeStats, PacketType::EntityData, PacketType::EntityErase }),
|
||||
packetReceiver.registerListenerForTypes(
|
||||
{ PacketType::OctreeStats, PacketType::EntityData, PacketType::EntityErase },
|
||||
this, "handleOctreePacket");
|
||||
packetReceiver.registerPacketListener(PacketType::Jurisdiction, this, "handleJurisdictionPacket");
|
||||
packetReceiver.registerListener(PacketType::Jurisdiction, this, "handleJurisdictionPacket");
|
||||
}
|
||||
|
||||
void Agent::handleOctreePacket(QSharedPointer<NLPacket> packet, SharedNodePointer senderNode) {
|
||||
|
@ -97,8 +97,8 @@ void Agent::handleJurisdictionPacket(QSharedPointer<NLPacket> packet, SharedNode
|
|||
}
|
||||
}
|
||||
|
||||
void Agent::handleAudioPacket(QSharedPointer<NLPacket> packet, SharedNodePointer senderNode) {
|
||||
_receivedAudioStream.parseData(*packet, senderNode);
|
||||
void Agent::handleAudioPacket(QSharedPointer<NLPacket> packet) {
|
||||
_receivedAudioStream.parseData(*packet);
|
||||
|
||||
_lastReceivedAudioLoudness = _receivedAudioStream.getNextOutputFrameLoudness();
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ public slots:
|
|||
void playAvatarSound(Sound* avatarSound) { _scriptEngine.setAvatarSound(avatarSound); }
|
||||
|
||||
private slots:
|
||||
void handleAudioPacket(QSharedPointer<NLPacket> packet, SharedNodePointer senderNode);
|
||||
void handleAudioPacket(QSharedPointer<NLPacket> packet);
|
||||
void handleOctreePacket(QSharedPointer<NLPacket> packet, SharedNodePointer senderNode);
|
||||
void handleJurisdictionPacket(QSharedPointer<NLPacket> packet, SharedNodePointer senderNode);
|
||||
|
||||
|
|
|
@ -121,11 +121,10 @@ AssignmentClient::AssignmentClient(Assignment::Type requestAssignmentType, QStri
|
|||
setUpStatusToMonitor();
|
||||
}
|
||||
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
|
||||
packetReceiver.registerPacketListener(PacketType::CreateAssignment, this, "handleCreateAssignmentPacket");
|
||||
packetReceiver.registerPacketListener(PacketType::StopNode, this, "handleStopNodePacket");
|
||||
packetReceiver.registerListener(PacketType::CreateAssignment, this, "handleCreateAssignmentPacket");
|
||||
packetReceiver.registerListener(PacketType::StopNode, this, "handleStopNodePacket");
|
||||
}
|
||||
|
||||
|
||||
void AssignmentClient::stopAssignmentClient() {
|
||||
qDebug() << "Forced stop of assignment-client.";
|
||||
|
||||
|
@ -211,7 +210,7 @@ void AssignmentClient::sendAssignmentRequest() {
|
|||
}
|
||||
}
|
||||
|
||||
void AssignmentClient::handleCreateAssignmentPacket(QSharedPointer<NLPacket> packet, SharedNodePointer senderNode, HifiSockAddr senderSockAddr) {
|
||||
void AssignmentClient::handleCreateAssignmentPacket(QSharedPointer<NLPacket> packet) {
|
||||
qDebug() << "Received a PacketType::CreateAssignment - attempting to unpack.";
|
||||
|
||||
// construct the deployed assignment from the packet data
|
||||
|
@ -224,7 +223,7 @@ void AssignmentClient::handleCreateAssignmentPacket(QSharedPointer<NLPacket> pac
|
|||
|
||||
// switch our DomainHandler hostname and port to whoever sent us the assignment
|
||||
|
||||
nodeList->getDomainHandler().setSockAddr(senderSockAddr, _assignmentServerHostname);
|
||||
nodeList->getDomainHandler().setSockAddr(packet->getSenderSockAddr(), _assignmentServerHostname);
|
||||
nodeList->getDomainHandler().setAssignmentUUID(_currentAssignment->getUUID());
|
||||
|
||||
qDebug() << "Destination IP for assignment is" << nodeList->getDomainHandler().getIP().toString();
|
||||
|
@ -262,7 +261,9 @@ void AssignmentClient::handleCreateAssignmentPacket(QSharedPointer<NLPacket> pac
|
|||
}
|
||||
}
|
||||
|
||||
void AssignmentClient::handleStopNodePacket(QSharedPointer<NLPacket> packet, SharedNodePointer senderNode, HifiSockAddr senderSockAddr) {
|
||||
void AssignmentClient::handleStopNodePacket(QSharedPointer<NLPacket> packet) {
|
||||
const HifiSockAddr& senderSockAddr = packet->getSenderSockAddr();
|
||||
|
||||
if (senderSockAddr.getAddress() == QHostAddress::LocalHost ||
|
||||
senderSockAddr.getAddress() == QHostAddress::LocalHostIPv6) {
|
||||
qDebug() << "AssignmentClientMonitor at" << senderSockAddr << "requested stop via PacketType::StopNode.";
|
||||
|
|
|
@ -15,11 +15,13 @@
|
|||
#include <QtCore/QCoreApplication>
|
||||
#include <QtCore/QPointer>
|
||||
|
||||
#include <PacketListener.h>
|
||||
|
||||
#include "ThreadedAssignment.h"
|
||||
|
||||
class QSharedMemory;
|
||||
|
||||
class AssignmentClient : public QObject {
|
||||
class AssignmentClient : public QObject, public PacketListener {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
|
@ -37,8 +39,8 @@ public slots:
|
|||
void aboutToQuit();
|
||||
|
||||
private slots:
|
||||
void handleCreateAssignmentPacket(QSharedPointer<NLPacket> packet, SharedNodePointer senderNode, HifiSockAddr senderSockAddr);
|
||||
void handleStopNodePacket(QSharedPointer<NLPacket> packet, SharedNodePointer senderNode, HifiSockAddr senderSockAddr);
|
||||
void handleCreateAssignmentPacket(QSharedPointer<NLPacket> packet);
|
||||
void handleStopNodePacket(QSharedPointer<NLPacket> packet);
|
||||
|
||||
private:
|
||||
void setUpStatusToMonitor();
|
||||
|
|
|
@ -16,16 +16,13 @@
|
|||
|
||||
|
||||
class AssignmentClientChildData : public NodeData {
|
||||
public:
|
||||
public:
|
||||
AssignmentClientChildData(Assignment::Type childType);
|
||||
|
||||
Assignment::Type getChildType() { return _childType; }
|
||||
void setChildType(Assignment::Type childType) { _childType = childType; }
|
||||
|
||||
// implement parseData to return 0 so we can be a subclass of NodeData
|
||||
int parseData(NLPacket& packet, QSharedPointer<Node> sendingNode) { return 0; }
|
||||
|
||||
private:
|
||||
private:
|
||||
Assignment::Type _childType;
|
||||
};
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ AssignmentClientMonitor::AssignmentClientMonitor(const unsigned int numAssignmen
|
|||
auto nodeList = DependencyManager::set<LimitedNodeList>();
|
||||
|
||||
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
|
||||
packetReceiver.registerPacketListener(PacketType::AssignmentClientStatus, this, "handleChildStatusPacket");
|
||||
packetReceiver.registerListener(PacketType::AssignmentClientStatus, this, "handleChildStatusPacket");
|
||||
|
||||
// use QProcess to fork off a process for each of the child assignment clients
|
||||
for (unsigned int i = 0; i < _numAssignmentClientForks; i++) {
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
extern const char* NUM_FORKS_PARAMETER;
|
||||
|
||||
|
||||
class AssignmentClientMonitor : public QObject {
|
||||
class AssignmentClientMonitor : public QObject, public PacketListener {
|
||||
Q_OBJECT
|
||||
public:
|
||||
AssignmentClientMonitor(const unsigned int numAssignmentClientForks, const unsigned int minAssignmentClientForks,
|
||||
|
|
|
@ -104,8 +104,8 @@ AudioMixer::AudioMixer(NLPacket& packet) :
|
|||
PacketType::AudioStreamStats
|
||||
};
|
||||
|
||||
packetReceiver.registerPacketListenerForTypes(nodeAudioPackets, this, "handleNodeAudioPacket");
|
||||
packetReceiver.registerPacketListener(PacketType::MuteEnvironment, this, "handleMuteEnvironmentPacket");
|
||||
packetReceiver.registerListenerForTypes(nodeAudioPackets, this, "handleNodeAudioPacket");
|
||||
packetReceiver.registerListener(PacketType::MuteEnvironment, this, "handleMuteEnvironmentPacket");
|
||||
}
|
||||
|
||||
const float ATTENUATION_BEGINS_AT_DISTANCE = 1.0f;
|
||||
|
|
|
@ -49,7 +49,7 @@ AvatarAudioStream* AudioMixerClientData::getAvatarAudioStream() const {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int AudioMixerClientData::parseData(NLPacket& packet, SharedNodePointer sendingNode) {
|
||||
int AudioMixerClientData::parseData(NLPacket& packet) {
|
||||
PacketType::Value packetType = packet.getType();
|
||||
|
||||
if (packetType == PacketType::AudioStreamStats) {
|
||||
|
@ -107,7 +107,7 @@ int AudioMixerClientData::parseData(NLPacket& packet, SharedNodePointer sendingN
|
|||
// seek to the beginning of the packet so that the next reader is in the right spot
|
||||
packet.seek(0);
|
||||
|
||||
return matchingStream->parseData(packet, sendingNode);
|
||||
return matchingStream->parseData(packet);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public:
|
|||
const QHash<QUuid, PositionalAudioStream*>& getAudioStreams() const { return _audioStreams; }
|
||||
AvatarAudioStream* getAvatarAudioStream() const;
|
||||
|
||||
int parseData(NLPacket& packet, QSharedPointer<Node> sendingNode);
|
||||
int parseData(NLPacket& packet);
|
||||
|
||||
void checkBuffersBeforeFrameSend();
|
||||
|
||||
|
|
|
@ -48,10 +48,10 @@ AvatarMixer::AvatarMixer(NLPacket& packet) :
|
|||
connect(DependencyManager::get<NodeList>().data(), &NodeList::nodeKilled, this, &AvatarMixer::nodeKilled);
|
||||
|
||||
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
|
||||
packetReceiver.registerPacketListener(PacketType::AvatarData, this, "handleAvatarDataPacket");
|
||||
packetReceiver.registerPacketListener(PacketType::AvatarIdentity, this, "handleAvatarIdentityPacket");
|
||||
packetReceiver.registerPacketListener(PacketType::AvatarBillboard, this, "handleAvatarBillboardPacket");
|
||||
packetReceiver.registerPacketListener(PacketType::KillAvatar, this, "handleKillAvatarPacket");
|
||||
packetReceiver.registerListener(PacketType::AvatarData, this, "handleAvatarDataPacket");
|
||||
packetReceiver.registerListener(PacketType::AvatarIdentity, this, "handleAvatarIdentityPacket");
|
||||
packetReceiver.registerListener(PacketType::AvatarBillboard, this, "handleAvatarBillboardPacket");
|
||||
packetReceiver.registerListener(PacketType::KillAvatar, this, "handleKillAvatarPacket");
|
||||
}
|
||||
|
||||
AvatarMixer::~AvatarMixer() {
|
||||
|
@ -434,9 +434,8 @@ void AvatarMixer::handleAvatarBillboardPacket(QSharedPointer<NLPacket> packet, S
|
|||
}
|
||||
}
|
||||
|
||||
void AvatarMixer::handleKillAvatarPacket(QSharedPointer<NLPacket> packet, SharedNodePointer senderNode) {
|
||||
auto nodeList = DependencyManager::get<NodeList>();
|
||||
nodeList->processKillNode(*packet);
|
||||
void AvatarMixer::handleKillAvatarPacket(QSharedPointer<NLPacket> packet) {
|
||||
DependencyManager::get<NodeList>()->processKillNode(*packet);
|
||||
}
|
||||
|
||||
void AvatarMixer::sendStatsPacket() {
|
||||
|
|
|
@ -35,7 +35,7 @@ private slots:
|
|||
void handleAvatarDataPacket(QSharedPointer<NLPacket> packet, SharedNodePointer senderNode);
|
||||
void handleAvatarIdentityPacket(QSharedPointer<NLPacket> packet, SharedNodePointer senderNode);
|
||||
void handleAvatarBillboardPacket(QSharedPointer<NLPacket> packet, SharedNodePointer senderNode);
|
||||
void handleKillAvatarPacket(QSharedPointer<NLPacket> packet, SharedNodePointer senderNode);
|
||||
void handleKillAvatarPacket(QSharedPointer<NLPacket> packet);
|
||||
|
||||
private:
|
||||
void broadcastAvatarData();
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
#include "AvatarMixerClientData.h"
|
||||
|
||||
int AvatarMixerClientData::parseData(NLPacket& packet, SharedNodePointer sendingNode) {
|
||||
int AvatarMixerClientData::parseData(NLPacket& packet) {
|
||||
// compute the offset to the data payload
|
||||
return _avatar.parseDataFromBuffer(QByteArray::fromRawData(packet.getPayload(), packet.getSizeUsed()));
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ const QString OUTBOUND_AVATAR_DATA_STATS_KEY = "outbound_av_data_kbps";
|
|||
class AvatarMixerClientData : public NodeData {
|
||||
Q_OBJECT
|
||||
public:
|
||||
int parseData(NLPacket& packet, SharedNodePointer sendingNode);
|
||||
int parseData(NLPacket& packet);
|
||||
AvatarData& getAvatar() { return _avatar; }
|
||||
|
||||
bool checkAndSetHasReceivedFirstPackets();
|
||||
|
|
|
@ -26,8 +26,7 @@ EntityServer::EntityServer(NLPacket& packet) :
|
|||
_entitySimulation(NULL)
|
||||
{
|
||||
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
|
||||
packetReceiver.registerPacketListenerForTypes(
|
||||
{ PacketType::EntityAdd, PacketType::EntityEdit, PacketType::EntityErase },
|
||||
packetReceiver.registerListenerForTypes({ PacketType::EntityAdd, PacketType::EntityEdit, PacketType::EntityErase },
|
||||
this, "handleEntityPacket");
|
||||
}
|
||||
|
||||
|
|
|
@ -1029,9 +1029,9 @@ void OctreeServer::readConfiguration() {
|
|||
void OctreeServer::run() {
|
||||
|
||||
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
|
||||
packetReceiver.registerPacketListener(getMyQueryMessageType(), this, "handleOctreeQueryPacket");
|
||||
packetReceiver.registerPacketListener(PacketType::OctreeDataNack, this, "handleOctreeDataNackPacket");
|
||||
packetReceiver.registerPacketListener(PacketType::JurisdictionRequest, this, "handleJurisdictionRequestPacket");
|
||||
packetReceiver.registerListener(getMyQueryMessageType(), this, "handleOctreeQueryPacket");
|
||||
packetReceiver.registerListener(PacketType::OctreeDataNack, this, "handleOctreeDataNackPacket");
|
||||
packetReceiver.registerListener(PacketType::JurisdictionRequest, this, "handleJurisdictionRequestPacket");
|
||||
|
||||
_safeServerName = getMyServerName();
|
||||
|
||||
|
|
|
@ -111,6 +111,7 @@ DomainServer::DomainServer(int argc, char* argv[]) :
|
|||
}
|
||||
|
||||
void DomainServer::aboutToQuit() {
|
||||
|
||||
// clear the log handler so that Qt doesn't call the destructor on LogHandler
|
||||
qInstallMessageHandler(0);
|
||||
}
|
||||
|
@ -280,14 +281,14 @@ void DomainServer::setupNodeListAndAssignments(const QUuid& sessionUUID) {
|
|||
|
||||
// register as the packet receiver for the types we want
|
||||
PacketReceiver& packetReceiver = nodeList->getPacketReceiver();
|
||||
packetReceiver.registerPacketListener(PacketType::RequestAssignment, this, "processRequestAssignmentPacket");
|
||||
packetReceiver.registerPacketListener(PacketType::DomainConnectRequest, this, "processConnectRequestPackets");
|
||||
packetReceiver.registerPacketListener(PacketType::DomainListRequest, this, "processListRequestPacket");
|
||||
packetReceiver.registerPacketListener(PacketType::DomainServerPathQuery, this, "processPathQueryPacket");
|
||||
packetReceiver.registerPacketListener(PacketType::NodeJsonStats, this, "processNodeJSONStatsPacket");
|
||||
packetReceiver.registerPacketListener(PacketType::ICEPing, this, "processICEPingPacket");
|
||||
packetReceiver.registerPacketListener(PacketType::ICEPingReply, this, "processICEPingReplyPacket");
|
||||
packetReceiver.registerPacketListener(PacketType::ICEServerPeerInformation, this, "processICEPeerInformationPacket");
|
||||
packetReceiver.registerListener(PacketType::RequestAssignment, this, "processRequestAssignmentPacket");
|
||||
packetReceiver.registerListener(PacketType::DomainConnectRequest, this, "processConnectRequestPackets");
|
||||
packetReceiver.registerListener(PacketType::DomainListRequest, this, "processListRequestPacket");
|
||||
packetReceiver.registerListener(PacketType::DomainServerPathQuery, this, "processPathQueryPacket");
|
||||
packetReceiver.registerListener(PacketType::NodeJsonStats, this, "processNodeJSONStatsPacket");
|
||||
packetReceiver.registerListener(PacketType::ICEPing, this, "processICEPingPacket");
|
||||
packetReceiver.registerListener(PacketType::ICEPingReply, this, "processICEPingReplyPacket");
|
||||
packetReceiver.registerListener(PacketType::ICEServerPeerInformation, this, "processICEPeerInformationPacket");
|
||||
|
||||
// add whatever static assignments that have been parsed to the queue
|
||||
addStaticAssignmentsToQueue();
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <Assignment.h>
|
||||
#include <HTTPSConnection.h>
|
||||
#include <LimitedNodeList.h>
|
||||
#include <PacketListener.h>
|
||||
|
||||
#include "DomainServerSettingsManager.h"
|
||||
#include "DomainServerWebSessionData.h"
|
||||
|
@ -34,7 +35,7 @@
|
|||
typedef QSharedPointer<Assignment> SharedAssignmentPointer;
|
||||
typedef QMultiHash<QUuid, WalletTransaction*> TransactionHash;
|
||||
|
||||
class DomainServer : public QCoreApplication, public HTTPSRequestHandler {
|
||||
class DomainServer : public QCoreApplication, public HTTPSRequestHandler, public PacketListener {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DomainServer(int argc, char* argv[]);
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
class DomainServerNodeData : public NodeData {
|
||||
public:
|
||||
DomainServerNodeData();
|
||||
int parseData(NLPacket& packet, QSharedPointer<Node> sendingNode) { return 0; }
|
||||
|
||||
const QJsonObject& getStatsJSONObject() const { return _statsJSONObject; }
|
||||
|
||||
|
|
|
@ -416,14 +416,16 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
|||
audioIO->setOrientationGetter(getOrientationForAudio);
|
||||
|
||||
audioIO->moveToThread(audioThread);
|
||||
|
||||
auto& audioScriptingInterface = AudioScriptingInterface::getInstance();
|
||||
|
||||
connect(audioThread, &QThread::started, audioIO.data(), &AudioClient::start);
|
||||
connect(audioIO.data(), &AudioClient::destroyed, audioThread, &QThread::quit);
|
||||
connect(audioThread, &QThread::finished, audioThread, &QThread::deleteLater);
|
||||
connect(audioIO.data(), &AudioClient::muteToggled, this, &Application::audioMuteToggled);
|
||||
connect(audioIO.data(), &AudioClient::receivedFirstPacket,
|
||||
&AudioScriptingInterface::getInstance(), &AudioScriptingInterface::receivedFirstPacket);
|
||||
connect(audioIO.data(), &AudioClient::disconnected,
|
||||
&AudioScriptingInterface::getInstance(), &AudioScriptingInterface::disconnected);
|
||||
connect(audioIO.data(), &AudioClient::mutedByMixer, &audioScriptingInterface, &AudioScriptingInterface::mutedByMixer);
|
||||
connect(audioIO.data(), &AudioClient::receivedFirstPacket, &audioScriptingInterface, &AudioScriptingInterface::receivedFirstPacket);
|
||||
connect(audioIO.data(), &AudioClient::disconnected, &audioScriptingInterface, &AudioScriptingInterface::disconnected);
|
||||
connect(audioIO.data(), &AudioClient::muteEnvironmentRequested, [](glm::vec3 position, float radius) {
|
||||
auto audioClient = DependencyManager::get<AudioClient>();
|
||||
float distance = glm::distance(DependencyManager::get<AvatarManager>()->getMyAvatar()->getPosition(),
|
||||
|
@ -654,7 +656,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
|||
applicationUpdater->checkForUpdate();
|
||||
|
||||
auto& packetReceiver = nodeList->getPacketReceiver();
|
||||
packetReceiver.registerPacketListener(PacketType::DomainConnectionDenied, this, "handleDomainConnectionDeniedPacket");
|
||||
packetReceiver.registerListener(PacketType::DomainConnectionDenied, this, "handleDomainConnectionDeniedPacket");
|
||||
}
|
||||
|
||||
void Application::aboutToQuit() {
|
||||
|
@ -666,6 +668,9 @@ void Application::aboutToQuit() {
|
|||
|
||||
void Application::cleanupBeforeQuit() {
|
||||
|
||||
// stop handling packets we've asked to handle
|
||||
DependencyManager::get<LimitedNodeList>()->getPacketReceiver().unregisterListener(this);
|
||||
|
||||
_entities.clear(); // this will allow entity scripts to properly shutdown
|
||||
|
||||
//_datagramProcessor->shutdown(); // tell the datagram processor we're shutting down, so it can short circuit
|
||||
|
@ -3818,7 +3823,7 @@ void Application::domainChanged(const QString& domainHostname) {
|
|||
_domainConnectionRefusals.clear();
|
||||
}
|
||||
|
||||
void Application::handleDomainConnectionDeniedPacket(QSharedPointer<NLPacket> packet, SharedNodePointer senderNode) {
|
||||
void Application::handleDomainConnectionDeniedPacket(QSharedPointer<NLPacket> packet) {
|
||||
QDataStream packetStream(packet.data());
|
||||
|
||||
QString reason;
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <OctreeQuery.h>
|
||||
#include <OffscreenUi.h>
|
||||
#include <PacketHeaders.h>
|
||||
#include <PacketListener.h>
|
||||
#include <PhysicalEntitySimulation.h>
|
||||
#include <PhysicsEngine.h>
|
||||
#include <ScriptEngine.h>
|
||||
|
@ -134,7 +135,10 @@ class Application;
|
|||
|
||||
typedef bool (Application::* AcceptURLMethod)(const QString &);
|
||||
|
||||
class Application : public QApplication, public AbstractViewStateInterface, AbstractScriptingServicesInterface {
|
||||
class Application : public QApplication,
|
||||
public AbstractViewStateInterface,
|
||||
AbstractScriptingServicesInterface,
|
||||
public PacketListener {
|
||||
Q_OBJECT
|
||||
|
||||
friend class OctreePacketProcessor;
|
||||
|
@ -213,6 +217,7 @@ public:
|
|||
OctreeQuery& getOctreeQuery() { return _octreeQuery; }
|
||||
EntityTree* getEntityClipboard() { return &_entityClipboard; }
|
||||
EntityTreeRenderer* getEntityClipboardRenderer() { return &_entityClipboardRenderer; }
|
||||
EntityEditPacketSender* getEntityEditPacketSender() { return &_entityEditSender; }
|
||||
|
||||
bool isMousePressed() const { return _mousePressed; }
|
||||
bool isMouseHidden() const { return !_cursorVisible; }
|
||||
|
@ -443,7 +448,7 @@ public slots:
|
|||
|
||||
void notifyPacketVersionMismatch();
|
||||
|
||||
void handleDomainConnectionDeniedPacket(QSharedPointer<NLPacket>, SharedNodePointer senderNode);
|
||||
void handleDomainConnectionDeniedPacket(QSharedPointer<NLPacket> packet);
|
||||
|
||||
void cameraMenuChanged();
|
||||
|
||||
|
|
|
@ -500,7 +500,9 @@ Menu::Menu() {
|
|||
#endif
|
||||
|
||||
MenuWrapper* networkMenu = developerMenu->addMenu("Network");
|
||||
addCheckableActionToQMenuAndActionHash(networkMenu, MenuOption::DisableNackPackets, 0, false);
|
||||
addCheckableActionToQMenuAndActionHash(networkMenu, MenuOption::DisableNackPackets, 0, false,
|
||||
qApp->getEntityEditPacketSender(),
|
||||
SLOT(toggleNackPackets()));
|
||||
addCheckableActionToQMenuAndActionHash(networkMenu,
|
||||
MenuOption::DisableActivityLogger,
|
||||
0,
|
||||
|
|
|
@ -169,7 +169,7 @@ namespace MenuOption {
|
|||
const QString DeleteBookmark = "Delete Bookmark...";
|
||||
const QString DisableActivityLogger = "Disable Activity Logger";
|
||||
const QString DisableLightEntities = "Disable Light Entities";
|
||||
const QString DisableNackPackets = "Disable NACK Packets";
|
||||
const QString DisableNackPackets = "Disable Entity NACK Packets";
|
||||
const QString DiskCacheEditor = "Disk Cache Editor";
|
||||
const QString DisplayHands = "Show Hand Info";
|
||||
const QString DisplayHandTargets = "Show Hand Targets";
|
||||
|
|
|
@ -24,7 +24,11 @@ OctreePacketProcessor::OctreePacketProcessor() {
|
|||
PacketType::EntityErase, PacketType::OctreeStats, PacketType::EnvironmentData
|
||||
};
|
||||
|
||||
packetReceiver.registerPacketListenerForTypes(types, this, "handleOctreePacket");
|
||||
packetReceiver.registerListenerForTypes(types, this, "handleOctreePacket");
|
||||
}
|
||||
|
||||
OctreePacketProcessor::~OctreePacketProcessor() {
|
||||
DependencyManager::get<NodeList>()->getPacketReceiver().unregisterListener(this);
|
||||
}
|
||||
|
||||
void OctreePacketProcessor::handleOctreePacket(QSharedPointer<NLPacket> packet, SharedNodePointer senderNode) {
|
||||
|
|
|
@ -13,13 +13,15 @@
|
|||
#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 {
|
||||
class OctreePacketProcessor : public ReceivedPacketProcessor, public PacketListener {
|
||||
Q_OBJECT
|
||||
public:
|
||||
OctreePacketProcessor();
|
||||
~OctreePacketProcessor();
|
||||
|
||||
signals:
|
||||
void packetVersionMismatch();
|
||||
|
|
|
@ -142,12 +142,12 @@ AudioClient::AudioClient() :
|
|||
configureGverbFilter(_gverb);
|
||||
|
||||
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
|
||||
packetReceiver.registerPacketListener(PacketType::AudioStreamStats, &_stats, "handleAudioStreamStatsPacket");
|
||||
packetReceiver.registerPacketListener(PacketType::AudioEnvironment, this, "handleAudioEnvironmentDataPacket");
|
||||
packetReceiver.registerPacketListener(PacketType::SilentAudioFrame, this, "handleAudioDataPacket");
|
||||
packetReceiver.registerPacketListener(PacketType::MixedAudio, this, "handleAudioDataPacket");
|
||||
packetReceiver.registerPacketListener(PacketType::NoisyMute, this, "handleNoisyMutePacket");
|
||||
packetReceiver.registerPacketListener(PacketType::MuteEnvironment, this, "handleMuteEnvironmentPacket");
|
||||
packetReceiver.registerListener(PacketType::AudioStreamStats, &_stats, "handleAudioStreamStatsPacket");
|
||||
packetReceiver.registerListener(PacketType::AudioEnvironment, this, "handleAudioEnvironmentDataPacket");
|
||||
packetReceiver.registerListener(PacketType::SilentAudioFrame, this, "handleAudioDataPacket");
|
||||
packetReceiver.registerListener(PacketType::MixedAudio, this, "handleAudioDataPacket");
|
||||
packetReceiver.registerListener(PacketType::NoisyMute, this, "handleNoisyMutePacket");
|
||||
packetReceiver.registerListener(PacketType::MuteEnvironment, this, "handleMuteEnvironmentPacket");
|
||||
}
|
||||
|
||||
AudioClient::~AudioClient() {
|
||||
|
@ -535,7 +535,7 @@ void AudioClient::stop() {
|
|||
}
|
||||
}
|
||||
|
||||
void AudioClient::handleAudioEnvironmentDataPacket(QSharedPointer<NLPacket> packet, SharedNodePointer sendingNode) {
|
||||
void AudioClient::handleAudioEnvironmentDataPacket(QSharedPointer<NLPacket> packet) {
|
||||
|
||||
char bitset;
|
||||
packet->readPrimitive(&bitset);
|
||||
|
@ -552,7 +552,7 @@ void AudioClient::handleAudioEnvironmentDataPacket(QSharedPointer<NLPacket> pack
|
|||
}
|
||||
}
|
||||
|
||||
void AudioClient::handleAudioDataPacket(QSharedPointer<NLPacket> packet, SharedNodePointer sendingNode) {
|
||||
void AudioClient::handleAudioDataPacket(QSharedPointer<NLPacket> packet) {
|
||||
auto nodeList = DependencyManager::get<NodeList>();
|
||||
nodeList->flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::ReceiveFirstAudioPacket);
|
||||
|
||||
|
@ -566,20 +566,20 @@ void AudioClient::handleAudioDataPacket(QSharedPointer<NLPacket> packet, SharedN
|
|||
}
|
||||
|
||||
// Audio output must exist and be correctly set up if we're going to process received audio
|
||||
_receivedAudioStream.parseData(*packet, sendingNode);
|
||||
_receivedAudioStream.parseData(*packet);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioClient::handleNoisyMutePacket(QSharedPointer<NLPacket> packet, SharedNodePointer sendingNode) {
|
||||
void AudioClient::handleNoisyMutePacket(QSharedPointer<NLPacket> packet) {
|
||||
if (!_muted) {
|
||||
toggleMute();
|
||||
|
||||
// TODO reimplement on interface side
|
||||
//AudioScriptingInterface::getInstance().mutedByMixer();
|
||||
// have the audio scripting interface emit a signal to say we were muted by the mixer
|
||||
emit mutedByMixer();
|
||||
}
|
||||
}
|
||||
|
||||
void AudioClient::handleMuteEnvironmentPacket(QSharedPointer<NLPacket> packet, SharedNodePointer sendingNode) {
|
||||
void AudioClient::handleMuteEnvironmentPacket(QSharedPointer<NLPacket> packet) {
|
||||
glm::vec3 position;
|
||||
float radius;
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include <NLPacket.h>
|
||||
#include <MixedProcessedAudioStream.h>
|
||||
#include <RingBufferHistory.h>
|
||||
#include <PacketListener.h>
|
||||
#include <SettingHandle.h>
|
||||
#include <Sound.h>
|
||||
#include <StDev.h>
|
||||
|
@ -80,7 +81,7 @@ typedef glm::quat (*AudioOrientationGetter)();
|
|||
|
||||
class NLPacket;
|
||||
|
||||
class AudioClient : public AbstractAudioInterface, public Dependency {
|
||||
class AudioClient : public AbstractAudioInterface, public Dependency, public PacketListener {
|
||||
Q_OBJECT
|
||||
SINGLETON_DEPENDENCY
|
||||
public:
|
||||
|
@ -139,10 +140,10 @@ public slots:
|
|||
void start();
|
||||
void stop();
|
||||
|
||||
void handleAudioEnvironmentDataPacket(QSharedPointer<NLPacket> packet, SharedNodePointer sendingNode);
|
||||
void handleAudioDataPacket(QSharedPointer<NLPacket> packet, SharedNodePointer sendingNode);
|
||||
void handleNoisyMutePacket(QSharedPointer<NLPacket> packet, SharedNodePointer sendingNode);
|
||||
void handleMuteEnvironmentPacket(QSharedPointer<NLPacket> packet, SharedNodePointer sendingNode);
|
||||
void handleAudioEnvironmentDataPacket(QSharedPointer<NLPacket> packet);
|
||||
void handleAudioDataPacket(QSharedPointer<NLPacket> packet);
|
||||
void handleNoisyMutePacket(QSharedPointer<NLPacket> packet);
|
||||
void handleMuteEnvironmentPacket(QSharedPointer<NLPacket> packet);
|
||||
|
||||
void sendDownstreamAudioStatsPacket() { _stats.sendDownstreamAudioStatsPacket(); }
|
||||
void handleAudioInput();
|
||||
|
@ -187,6 +188,7 @@ public slots:
|
|||
|
||||
signals:
|
||||
bool muteToggled();
|
||||
void mutedByMixer();
|
||||
void inputReceived(const QByteArray& inputSamples);
|
||||
void outputBytesToNetwork(int numBytes);
|
||||
void inputBytesFromNetwork(int numBytes);
|
||||
|
|
|
@ -19,10 +19,11 @@
|
|||
#include <AudioStreamStats.h>
|
||||
#include <Node.h>
|
||||
#include <NLPacket.h>
|
||||
#include <PacketListener.h>
|
||||
|
||||
class MixedProcessedAudioStream;
|
||||
|
||||
class AudioIOStats : public QObject {
|
||||
class AudioIOStats : public QObject, public PacketListener {
|
||||
Q_OBJECT
|
||||
public:
|
||||
AudioIOStats(MixedProcessedAudioStream* receivedAudioStream);
|
||||
|
|
|
@ -99,13 +99,13 @@ void InboundAudioStream::perSecondCallbackForUpdatingStats() {
|
|||
_timeGapStatsForStatsPacket.currentIntervalComplete();
|
||||
}
|
||||
|
||||
int InboundAudioStream::parseData(NLPacket& packet, SharedNodePointer sendingNode) {
|
||||
int InboundAudioStream::parseData(NLPacket& packet) {
|
||||
|
||||
// parse sequence number and track it
|
||||
quint16 sequence;
|
||||
packet.readPrimitive(&sequence);
|
||||
SequenceNumberStats::ArrivalInfo arrivalInfo = _incomingSequenceNumberStats.sequenceNumberReceived(sequence,
|
||||
sendingNode->getUUID());
|
||||
packet.getSourceID());
|
||||
|
||||
packetReceivedUpdateTimingStats();
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ public:
|
|||
virtual void resetStats();
|
||||
void clearBuffer();
|
||||
|
||||
virtual int parseData(NLPacket& packet, QSharedPointer<Node> sendingNode);
|
||||
virtual int parseData(NLPacket& packet);
|
||||
|
||||
int popFrames(int maxFrames, bool allOrNothing, bool starveIfNoFramesPopped = true);
|
||||
int popSamples(int maxSamples, bool allOrNothing, bool starveIfNoSamplesPopped = true);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// AvatarHashMap.cpp
|
||||
// libraries/avatars/src
|
||||
//
|
||||
// Created by AndrewMeadows on 1/28/2014.
|
||||
// Created by Andrew Meadows on 1/28/2014.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
|
@ -20,10 +20,10 @@ AvatarHashMap::AvatarHashMap() {
|
|||
connect(DependencyManager::get<NodeList>().data(), &NodeList::uuidChanged, this, &AvatarHashMap::sessionUUIDChanged);
|
||||
|
||||
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
|
||||
packetReceiver.registerPacketListener(PacketType::BulkAvatarData, this, "processAvatarDataPacket");
|
||||
packetReceiver.registerPacketListener(PacketType::KillAvatar, this, "processKillAvatar");
|
||||
packetReceiver.registerPacketListener(PacketType::AvatarIdentity, this, "processAvatarIdentityPacket");
|
||||
packetReceiver.registerPacketListener(PacketType::AvatarBillboard, this, "processAvatarBillboardPacket");
|
||||
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) {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// AvatarHashMap.h
|
||||
// libraries/avatars/src
|
||||
//
|
||||
// Created by Stephen AndrewMeadows on 1/28/2014.
|
||||
// Created by Andrew Meadows on 1/28/2014.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
|
@ -21,11 +21,12 @@
|
|||
#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 {
|
||||
class AvatarHashMap : public QObject, public Dependency, public PacketListener {
|
||||
Q_OBJECT
|
||||
SINGLETON_DEPENDENCY
|
||||
|
||||
|
|
|
@ -19,13 +19,13 @@
|
|||
|
||||
EntityEditPacketSender::EntityEditPacketSender() {
|
||||
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
|
||||
packetReceiver.registerPacketListener(PacketType::EntityEditNack, this, "processEntityEditNackPacket");
|
||||
packetReceiver.registerListener(PacketType::EntityEditNack, this, "processEntityEditNackPacket");
|
||||
}
|
||||
|
||||
void EntityEditPacketSender::processEntityEditNackPacket(QSharedPointer<NLPacket> packet, HifiSockAddr senderSockAddr) {
|
||||
// if (!Menu::getInstance()->isOptionChecked(MenuOption::DisableNackPackets)) {
|
||||
void EntityEditPacketSender::processEntityEditNackPacket(QSharedPointer<NLPacket> packet) {
|
||||
if (_shouldNack) {
|
||||
processNackPacket(QByteArray::fromRawData(packet->getData(), packet->getSizeWithHeader()));
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
void EntityEditPacketSender::adjustEditPacketForClockSkew(PacketType::Value type, QByteArray& buffer, int clockSkew) {
|
||||
|
|
|
@ -14,10 +14,12 @@
|
|||
|
||||
#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 {
|
||||
class EntityEditPacketSender : public OctreeEditPacketSender, public PacketListener {
|
||||
Q_OBJECT
|
||||
public:
|
||||
EntityEditPacketSender();
|
||||
|
@ -30,10 +32,16 @@ public:
|
|||
|
||||
void queueEraseEntityMessage(const EntityItemID& entityItemID);
|
||||
|
||||
void processEntityEditNackPacket(QSharedPointer<NLPacket> packet, HifiSockAddr senderSockAddr);
|
||||
void processEntityEditNackPacket(QSharedPointer<NLPacket> packet);
|
||||
|
||||
// My server type is the model server
|
||||
virtual char getMyNodeType() const { return NodeType::EntityServer; }
|
||||
virtual void adjustEditPacketForClockSkew(PacketType::Value type, QByteArray& buffer, int clockSkew);
|
||||
|
||||
public slots:
|
||||
void toggleNackPackets() { _shouldNack = !_shouldNack; }
|
||||
|
||||
private:
|
||||
bool _shouldNack = false;
|
||||
};
|
||||
#endif // hifi_EntityEditPacketSender_h
|
||||
|
|
|
@ -85,9 +85,6 @@ public:
|
|||
|
||||
const char* getTypeName() const;
|
||||
|
||||
// implement parseData to return 0 so we can be a subclass of NodeData
|
||||
int parseData(NLPacket& packet, SharedNodePointer sendingNode) { return 0; }
|
||||
|
||||
friend QDebug operator<<(QDebug debug, const Assignment& assignment);
|
||||
friend QDataStream& operator<<(QDataStream &out, const Assignment& assignment);
|
||||
friend QDataStream& operator>>(QDataStream &in, Assignment& assignment);
|
||||
|
|
|
@ -38,6 +38,12 @@ DomainHandler::DomainHandler(QObject* parent) :
|
|||
{
|
||||
// if we get a socket that make sure our NetworkPeer ping timer stops
|
||||
connect(this, &DomainHandler::completedSocketDiscovery, &_icePeer, &NetworkPeer::stopPingTimer);
|
||||
|
||||
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
|
||||
|
||||
packetReceiver.registerListener(PacketType::ICEServerPeerInformation, this, "processICEResponsePacket");
|
||||
packetReceiver.registerListener(PacketType::DomainServerRequireDTLS, this, "processDTLSRequirementPacket");
|
||||
packetReceiver.registerListener(PacketType::ICEPingReply, this, "processICEPingReplyPacket");
|
||||
}
|
||||
|
||||
void DomainHandler::clearConnectionInfo() {
|
||||
|
@ -281,6 +287,24 @@ void DomainHandler::settingsRequestFinished() {
|
|||
settingsReply->deleteLater();
|
||||
}
|
||||
|
||||
void DomainHandler::processICEPingReplyPacket(QSharedPointer<NLPacket> packet) {
|
||||
const HifiSockAddr& senderSockAddr = packet->getSenderSockAddr();
|
||||
qCDebug(networking) << "Received reply from domain-server on" << senderSockAddr;
|
||||
|
||||
if (getIP().isNull()) {
|
||||
// for now we're unsafely assuming this came back from the domain
|
||||
if (senderSockAddr == _icePeer.getLocalSocket()) {
|
||||
qCDebug(networking) << "Connecting to domain using local socket";
|
||||
activateICELocalSocket();
|
||||
} else if (senderSockAddr == _icePeer.getPublicSocket()) {
|
||||
qCDebug(networking) << "Conecting to domain using public socket";
|
||||
activateICEPublicSocket();
|
||||
} else {
|
||||
qCDebug(networking) << "Reply does not match either local or public socket for domain. Will not connect.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DomainHandler::processDTLSRequirementPacket(QSharedPointer<NLPacket> dtlsRequirementPacket) {
|
||||
// figure out the port that the DS wants us to use for us to talk to them with DTLS
|
||||
unsigned short dtlsPort;
|
||||
|
|
|
@ -22,13 +22,14 @@
|
|||
#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 {
|
||||
class DomainHandler : public QObject, public PacketListener {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DomainHandler(QObject* parent = 0);
|
||||
|
@ -70,8 +71,6 @@ public:
|
|||
void requestDomainSettings();
|
||||
const QJsonObject& getSettingsObject() const { return _settingsObject; }
|
||||
|
||||
void processDTLSRequirementPacket(QSharedPointer<NLPacket> dtlsRequirementPacket);
|
||||
void processICEResponsePacket(QSharedPointer<NLPacket> icePacket);
|
||||
|
||||
void setPendingPath(const QString& pendingPath) { _pendingPath = pendingPath; }
|
||||
const QString& getPendingPath() { return _pendingPath; }
|
||||
|
@ -84,6 +83,10 @@ public slots:
|
|||
void setHostnameAndPort(const QString& hostname, quint16 port = DEFAULT_DOMAIN_SERVER_PORT);
|
||||
void setIceServerHostnameAndID(const QString& iceServerHostname, const QUuid& id);
|
||||
|
||||
void processICEPingReplyPacket(QSharedPointer<NLPacket> packet);
|
||||
void processDTLSRequirementPacket(QSharedPointer<NLPacket> dtlsRequirementPacket);
|
||||
void processICEResponsePacket(QSharedPointer<NLPacket> icePacket);
|
||||
|
||||
private slots:
|
||||
void completedHostnameLookup(const QHostInfo& hostInfo);
|
||||
void completedIceServerHostnameLookup();
|
||||
|
|
|
@ -100,7 +100,7 @@ LimitedNodeList::LimitedNodeList(unsigned short socketListenPort, unsigned short
|
|||
_packetStatTimer.start();
|
||||
|
||||
// make sure we handle STUN response packets
|
||||
_packetReceiver.registerPacketListener(PacketType::StunResponse, this, "processSTUNResponse");
|
||||
_packetReceiver.registerListener(PacketType::StunResponse, this, "processSTUNResponse");
|
||||
}
|
||||
|
||||
void LimitedNodeList::setSessionUUID(const QUuid& sessionUUID) {
|
||||
|
@ -241,7 +241,7 @@ int LimitedNodeList::updateNodeWithDataFromPacket(QSharedPointer<NLPacket> packe
|
|||
|
||||
if (linkedData) {
|
||||
QMutexLocker linkedDataLocker(&linkedData->getMutex());
|
||||
return linkedData->parseData(*packet, sendingNode);
|
||||
return linkedData->parseData(*packet);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include "NLPacket.h"
|
||||
#include "PacketHeaders.h"
|
||||
#include "PacketReceiver.h"
|
||||
#include "PacketListener.h"
|
||||
#include "NLPacketList.h"
|
||||
#include "UUIDHasher.h"
|
||||
|
||||
|
@ -75,7 +76,7 @@ namespace PingType {
|
|||
const PingType_t Symmetric = 3;
|
||||
}
|
||||
|
||||
class LimitedNodeList : public QObject, public Dependency {
|
||||
class LimitedNodeList : public QObject, public Dependency, public PacketListener {
|
||||
Q_OBJECT
|
||||
SINGLETON_DEPENDENCY
|
||||
public:
|
||||
|
|
|
@ -25,7 +25,7 @@ class NodeData : public QObject {
|
|||
public:
|
||||
NodeData();
|
||||
virtual ~NodeData() = 0;
|
||||
virtual int parseData(NLPacket& packet, QSharedPointer<Node> sendingNode) = 0;
|
||||
virtual int parseData(NLPacket& packet) { return 0; }
|
||||
|
||||
QMutex& getMutex() { return _mutex; }
|
||||
|
||||
|
|
|
@ -92,15 +92,10 @@ NodeList::NodeList(char newOwnerType, unsigned short socketListenPort, unsigned
|
|||
startSTUNPublicSocketUpdate();
|
||||
|
||||
auto& packetReceiver = getPacketReceiver();
|
||||
packetReceiver.registerPacketListener(PacketType::DomainList, this, "processDomainServerList");
|
||||
packetReceiver.registerPacketListener(PacketType::DomainServerAddedNode, this, "processDomainServerAddedNode");
|
||||
packetReceiver.registerPacketListener(PacketType::DomainServerRequireDTLS, &_domainHandler, "processDTLSRequirementPacket");
|
||||
packetReceiver.registerPacketListener(PacketType::DomainServerPathResponse, this, "processDomainServerPathQueryResponse");
|
||||
packetReceiver.registerPacketListener(PacketType::ICEServerPeerInformation, &_domainHandler, "processICEResponsePacket");
|
||||
packetReceiver.registerPacketListener(PacketType::Ping, this, "processPingPacket");
|
||||
packetReceiver.registerPacketListener(PacketType::PingReply, this, "processPingReplyPacket");
|
||||
packetReceiver.registerPacketListener(PacketType::ICEPing, this, "processICEPingPacket");
|
||||
packetReceiver.registerPacketListener(PacketType::ICEPingReply, this, "processICEPingReplyPacket");
|
||||
packetReceiver.registerListener(PacketType::DomainList, this, "processDomainServerList");
|
||||
packetReceiver.registerListener(PacketType::Ping, this, "processPingPacket");
|
||||
packetReceiver.registerListener(PacketType::PingReply, this, "processPingReplyPacket");
|
||||
packetReceiver.registerListener(PacketType::ICEPing, this, "processICEPingPacket");
|
||||
}
|
||||
|
||||
qint64 NodeList::sendStats(const QJsonObject& statsObject, const HifiSockAddr& destination) {
|
||||
|
@ -192,25 +187,6 @@ void NodeList::processICEPingPacket(QSharedPointer<NLPacket> packet) {
|
|||
sendPacket(std::move(replyPacket), packet->getSenderSockAddr());
|
||||
}
|
||||
|
||||
void NodeList::processICEPingReplyPacket(QSharedPointer<NLPacket> packet) {
|
||||
const HifiSockAddr& senderSockAddr = packet->getSenderSockAddr();
|
||||
qCDebug(networking) << "Received reply from domain-server on" << senderSockAddr;
|
||||
|
||||
if (_domainHandler.getIP().isNull()) {
|
||||
// for now we're unsafely assuming this came back from the domain
|
||||
if (senderSockAddr == _domainHandler.getICEPeer().getLocalSocket()) {
|
||||
qCDebug(networking) << "Connecting to domain using local socket";
|
||||
_domainHandler.activateICELocalSocket();
|
||||
} else if (senderSockAddr == _domainHandler.getICEPeer().getPublicSocket()) {
|
||||
qCDebug(networking) << "Conecting to domain using public socket";
|
||||
_domainHandler.activateICEPublicSocket();
|
||||
} else {
|
||||
qCDebug(networking) << "Reply does not match either local or public socket for domain. Will not connect.";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void NodeList::reset() {
|
||||
LimitedNodeList::reset();
|
||||
|
||||
|
|
|
@ -80,7 +80,6 @@ public slots:
|
|||
void processPingReplyPacket(QSharedPointer<NLPacket> packet, SharedNodePointer sendingNode);
|
||||
|
||||
void processICEPingPacket(QSharedPointer<NLPacket> packet);
|
||||
void processICEPingReplyPacket(QSharedPointer<NLPacket> packet);
|
||||
signals:
|
||||
void limitOfSilentDomainCheckInsReached();
|
||||
private slots:
|
||||
|
|
18
libraries/networking/src/PacketListener.cpp
Normal file
18
libraries/networking/src/PacketListener.cpp
Normal file
|
@ -0,0 +1,18 @@
|
|||
//
|
||||
// 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() {
|
||||
DependencyManager::get<NodeList>()->getPacketReceiver().unregisterListener(this);
|
||||
}
|
22
libraries/networking/src/PacketListener.h
Normal file
22
libraries/networking/src/PacketListener.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
//
|
||||
// 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) :
|
|||
|
||||
}
|
||||
|
||||
void PacketReceiver::registerPacketListenerForTypes(const QSet<PacketType::Value>& types, QObject* object, const char* slot) {
|
||||
void PacketReceiver::registerListenerForTypes(const QSet<PacketType::Value>& types, PacketListener* listener, const char* slot) {
|
||||
QSet<PacketType::Value> nonSourcedTypes;
|
||||
QSet<PacketType::Value> sourcedTypes;
|
||||
|
||||
|
@ -36,6 +36,9 @@ void PacketReceiver::registerPacketListenerForTypes(const QSet<PacketType::Value
|
|||
}
|
||||
}
|
||||
|
||||
QObject* object = dynamic_cast<QObject*>(listener);
|
||||
Q_ASSERT(object);
|
||||
|
||||
if (nonSourcedTypes.size() > 0) {
|
||||
QMetaMethod nonSourcedMethod = matchingMethodForListener(*nonSourcedTypes.begin(), object, slot);
|
||||
foreach(PacketType::Value type, nonSourcedTypes) {
|
||||
|
@ -51,8 +54,12 @@ void PacketReceiver::registerPacketListenerForTypes(const QSet<PacketType::Value
|
|||
}
|
||||
}
|
||||
|
||||
void PacketReceiver::registerPacketListener(PacketType::Value type, QObject* object, const char* slot) {
|
||||
void PacketReceiver::registerListener(PacketType::Value type, PacketListener* listener, const char* slot) {
|
||||
QObject* object = dynamic_cast<QObject*>(listener);
|
||||
Q_ASSERT(object);
|
||||
|
||||
QMetaMethod matchingMethod = matchingMethodForListener(type, object, slot);
|
||||
|
||||
if (matchingMethod.isValid()) {
|
||||
registerVerifiedListener(type, object, matchingMethod);
|
||||
}
|
||||
|
@ -62,28 +69,35 @@ QMetaMethod PacketReceiver::matchingMethodForListener(PacketType::Value type, QO
|
|||
Q_ASSERT(object);
|
||||
|
||||
// normalize the slot with the expected parameters
|
||||
QString normalizedSlot;
|
||||
|
||||
if (NON_SOURCED_PACKETS.contains(type)) {
|
||||
const QString NON_SOURCED_PACKET_LISTENER_PARAMETERS = "QSharedPointer<NLPacket>";
|
||||
|
||||
QString nonNormalizedSignature = QString("%1(%2)").arg(slot).arg(NON_SOURCED_PACKET_LISTENER_PARAMETERS);
|
||||
normalizedSlot =
|
||||
QMetaObject::normalizedSignature(nonNormalizedSignature.toStdString().c_str());
|
||||
} else {
|
||||
QSet<QString> possibleSignatures { QString("%1(%2)").arg(slot).arg(NON_SOURCED_PACKET_LISTENER_PARAMETERS) };
|
||||
|
||||
if (!NON_SOURCED_PACKETS.contains(type)) {
|
||||
const QString SOURCED_PACKET_LISTENER_PARAMETERS = "QSharedPointer<NLPacket>,QSharedPointer<Node>";
|
||||
|
||||
QString nonNormalizedSignature = QString("%1(%2)").arg(slot).arg(SOURCED_PACKET_LISTENER_PARAMETERS);
|
||||
normalizedSlot =
|
||||
QMetaObject::normalizedSignature(nonNormalizedSignature.toStdString().c_str());
|
||||
// a sourced packet must take the shared pointer to the packet but optionally could include
|
||||
// a shared pointer to the node
|
||||
|
||||
possibleSignatures << QString("%1(%2)").arg(slot).arg(SOURCED_PACKET_LISTENER_PARAMETERS);
|
||||
}
|
||||
|
||||
int methodIndex = -1;
|
||||
|
||||
foreach(const QString& signature, possibleSignatures) {
|
||||
QByteArray normalizedSlot =
|
||||
QMetaObject::normalizedSignature(signature.toStdString().c_str());
|
||||
|
||||
// does the constructed normalized method exist?
|
||||
int methodIndex = object->metaObject()->indexOfSlot(normalizedSlot.toStdString().c_str());
|
||||
methodIndex = object->metaObject()->indexOfSlot(normalizedSlot.toStdString().c_str());
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (methodIndex < 0) {
|
||||
qDebug() << "PacketReceiver::registerPacketListener expected a method with a normalized signature of"
|
||||
<< normalizedSlot << "but such a method was not found.";
|
||||
qDebug() << "PacketReceiver::registerListener expected a method with one of the following signatures:"
|
||||
<< possibleSignatures << "- but such a method was not found.";
|
||||
}
|
||||
|
||||
Q_ASSERT(methodIndex >= 0);
|
||||
|
@ -107,12 +121,29 @@ void PacketReceiver::registerVerifiedListener(PacketType::Value type, QObject* o
|
|||
}
|
||||
|
||||
// add the mapping
|
||||
_packetListenerMap[type] = ObjectMethodPair(QPointer<QObject>(object), slot);
|
||||
_packetListenerMap[type] = ObjectMethodPair(object, slot);
|
||||
|
||||
_packetListenerLock.unlock();
|
||||
|
||||
}
|
||||
|
||||
void PacketReceiver::unregisterListener(PacketListener* listener) {
|
||||
_packetListenerLock.lock();
|
||||
|
||||
auto it = _packetListenerMap.begin();
|
||||
|
||||
while (it != _packetListenerMap.end()) {
|
||||
if (it.value().first == dynamic_cast<QObject*>(listener)) {
|
||||
// this listener matches - erase it
|
||||
it = _packetListenerMap.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
_packetListenerLock.unlock();
|
||||
}
|
||||
|
||||
bool PacketReceiver::packetVersionMatch(const NLPacket& packet) {
|
||||
|
||||
if (packet.getVersion() != versionForPacketType(packet.getType())
|
||||
|
@ -149,7 +180,7 @@ void PacketReceiver::processDatagrams() {
|
|||
|
||||
auto nodeList = DependencyManager::get<NodeList>();
|
||||
|
||||
while (DependencyManager::get<NodeList>()->getNodeSocket().hasPendingDatagrams()) {
|
||||
while (nodeList->getNodeSocket().hasPendingDatagrams()) {
|
||||
// setup a buffer to read the packet into
|
||||
int packetSizeWithHeader = nodeList->getNodeSocket().pendingDatagramSize();
|
||||
std::unique_ptr<char> buffer = std::unique_ptr<char>(new char[packetSizeWithHeader]);
|
||||
|
@ -186,7 +217,7 @@ void PacketReceiver::processDatagrams() {
|
|||
|
||||
auto listener = it.value();
|
||||
|
||||
if (!listener.first.isNull()) {
|
||||
if (listener.first) {
|
||||
|
||||
if (matchingNode) {
|
||||
emit dataReceived(matchingNode->getType(), packet->getSizeWithHeader());
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#include "NLPacket.h"
|
||||
#include "PacketHeaders.h"
|
||||
|
||||
class PacketListener;
|
||||
|
||||
class PacketReceiver : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
@ -31,16 +33,15 @@ public:
|
|||
PacketReceiver& operator=(const PacketReceiver&) = delete;
|
||||
|
||||
int getInPacketCount() const { return _inPacketCount; }
|
||||
int getOutPacketCount() const { return _outPacketCount; }
|
||||
int getInByteCount() const { return _inByteCount; }
|
||||
int getOutByteCount() const { return _outByteCount; }
|
||||
|
||||
void resetCounters() { _inPacketCount = 0; _outPacketCount = 0; _inByteCount = 0; _outByteCount = 0; }
|
||||
void resetCounters() { _inPacketCount = 0; _inByteCount = 0; }
|
||||
|
||||
void shutdown() { _isShuttingDown = true; }
|
||||
|
||||
void registerPacketListenerForTypes(const QSet<PacketType::Value>& types, QObject* listener, const char* slot);
|
||||
void registerPacketListener(PacketType::Value type, QObject* listener, const char* slot);
|
||||
void registerListenerForTypes(const QSet<PacketType::Value>& types, PacketListener* listener, const char* slot);
|
||||
void registerListener(PacketType::Value type, PacketListener* listener, const char* slot);
|
||||
void unregisterListener(PacketListener* listener);
|
||||
|
||||
public slots:
|
||||
void processDatagrams();
|
||||
|
@ -56,14 +57,12 @@ private:
|
|||
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<QPointer<QObject>, QMetaMethod>;
|
||||
using ObjectMethodPair = std::pair<QObject*, QMetaMethod>;
|
||||
|
||||
QMutex _packetListenerLock;
|
||||
QHash<PacketType::Value, ObjectMethodPair> _packetListenerMap;
|
||||
int _inPacketCount = 0;
|
||||
int _outPacketCount = 0;
|
||||
int _inByteCount = 0;
|
||||
int _outByteCount = 0;
|
||||
bool _isShuttingDown = false;
|
||||
};
|
||||
|
||||
|
|
0
libraries/networking/src/PacketReceiverListener.cpp
Normal file
0
libraries/networking/src/PacketReceiverListener.cpp
Normal file
22
libraries/networking/src/PacketReceiverListener.h
Normal file
22
libraries/networking/src/PacketReceiverListener.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
//
|
||||
// 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
|
|
@ -1,6 +1,6 @@
|
|||
//
|
||||
// ThreadedAssignment.h
|
||||
// libraries/shared/src
|
||||
// libraries/networking/src
|
||||
//
|
||||
// Created by Stephen Birarda on 12/3/2013.
|
||||
// Copyright 2013 High Fidelity, Inc.
|
||||
|
@ -14,9 +14,11 @@
|
|||
|
||||
#include <QtCore/QSharedPointer>
|
||||
|
||||
#include "PacketListener.h"
|
||||
|
||||
#include "Assignment.h"
|
||||
|
||||
class ThreadedAssignment : public Assignment {
|
||||
class ThreadedAssignment : public Assignment, public PacketListener {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ThreadedAssignment(NLPacket& packet);
|
||||
|
|
|
@ -64,7 +64,7 @@ int OctreeQuery::getBroadcastData(unsigned char* destinationBuffer) {
|
|||
}
|
||||
|
||||
// called on the other nodes - assigns it to my views of the others
|
||||
int OctreeQuery::parseData(NLPacket& packet, QSharedPointer<Node> sendingNode) {
|
||||
int OctreeQuery::parseData(NLPacket& packet) {
|
||||
|
||||
const unsigned char* startPosition = reinterpret_cast<const unsigned char*>(packet.getPayload());
|
||||
const unsigned char* sourceBuffer = startPosition;
|
||||
|
|
|
@ -48,7 +48,7 @@ public:
|
|||
virtual ~OctreeQuery() {}
|
||||
|
||||
int getBroadcastData(unsigned char* destinationBuffer);
|
||||
int parseData(NLPacket& packet, QSharedPointer<Node> sendingNode);
|
||||
int parseData(NLPacket& packet);
|
||||
|
||||
// getters for camera details
|
||||
const glm::vec3& getCameraPosition() const { return _cameraPosition; }
|
||||
|
|
Loading…
Reference in a new issue