mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 02:17:11 +02:00
116 lines
3.8 KiB
C++
116 lines
3.8 KiB
C++
//
|
|
// NodeList.h
|
|
// hifi
|
|
//
|
|
// Created by Stephen Birarda on 2/15/13.
|
|
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
|
//
|
|
|
|
#ifndef __hifi__NodeList__
|
|
#define __hifi__NodeList__
|
|
|
|
#ifdef _WIN32
|
|
#include "Syssocket.h"
|
|
#else
|
|
#include <netinet/in.h>
|
|
#endif
|
|
#include <stdint.h>
|
|
#include <iterator>
|
|
|
|
#ifndef _WIN32
|
|
#include <unistd.h> // not on windows, not needed for mac or windows
|
|
#endif
|
|
|
|
#include <QtCore/QElapsedTimer>
|
|
#include <QtCore/QMutex>
|
|
#include <QtCore/QSet>
|
|
#include <QtCore/QSettings>
|
|
#include <QtCore/QSharedPointer>
|
|
#include <QtNetwork/QHostAddress>
|
|
#include <QtNetwork/QUdpSocket>
|
|
|
|
#include <gnutls/gnutls.h>
|
|
|
|
#include "DomainHandler.h"
|
|
#include "LimitedNodeList.h"
|
|
#include "Node.h"
|
|
|
|
const quint64 DOMAIN_SERVER_CHECK_IN_USECS = 1 * 1000000;
|
|
|
|
const int MAX_SILENT_DOMAIN_SERVER_CHECK_INS = 5;
|
|
|
|
class Assignment;
|
|
|
|
typedef quint8 PingType_t;
|
|
namespace PingType {
|
|
const PingType_t Agnostic = 0;
|
|
const PingType_t Local = 1;
|
|
const PingType_t Public = 2;
|
|
}
|
|
|
|
class NodeList : public LimitedNodeList {
|
|
Q_OBJECT
|
|
public:
|
|
static NodeList* createInstance(char ownerType, unsigned short socketListenPort = 0, unsigned short dtlsPort = 0);
|
|
static NodeList* getInstance();
|
|
NodeType_t getOwnerType() const { return _ownerType; }
|
|
void setOwnerType(NodeType_t ownerType) { _ownerType = ownerType; }
|
|
|
|
const QUuid& getSessionUUID() const { return _sessionUUID; }
|
|
void setSessionUUID(const QUuid& sessionUUID);
|
|
|
|
qint64 sendStatsToDomainServer(const QJsonObject& statsObject);
|
|
|
|
int getNumNoReplyDomainCheckIns() const { return _numNoReplyDomainCheckIns; }
|
|
DomainHandler& getDomainHandler() { return _DomainHandler; }
|
|
|
|
const NodeSet& getNodeInterestSet() const { return _nodeTypesOfInterest; }
|
|
void addNodeTypeToInterestSet(NodeType_t nodeTypeToAdd);
|
|
void addSetOfNodeTypesToNodeInterestSet(const NodeSet& setOfNodeTypes);
|
|
void resetNodeInterestSet() { _nodeTypesOfInterest.clear(); }
|
|
|
|
void processNodeData(const HifiSockAddr& senderSockAddr, const QByteArray& packet);
|
|
int processDomainServerList(const QByteArray& packet);
|
|
|
|
void setAssignmentServerSocket(const HifiSockAddr& serverSocket) { _assignmentServerSocket = serverSocket; }
|
|
void sendAssignment(Assignment& assignment);
|
|
|
|
QByteArray constructPingPacket(PingType_t pingType = PingType::Agnostic);
|
|
QByteArray constructPingReplyPacket(const QByteArray& pingPacket);
|
|
void pingPublicAndLocalSocketsForInactiveNode(const SharedNodePointer& node);
|
|
|
|
void loadData(QSettings* settings);
|
|
void saveData(QSettings* settings);
|
|
public slots:
|
|
void reset();
|
|
void sendDomainServerCheckIn();
|
|
void pingInactiveNodes();
|
|
signals:
|
|
void uuidChanged(const QUuid& ownerUUID);
|
|
void limitOfSilentDomainCheckInsReached();
|
|
private:
|
|
static NodeList* _sharedInstance;
|
|
|
|
NodeList(char ownerType, unsigned short socketListenPort, unsigned short dtlsListenPort);
|
|
NodeList(NodeList const&); // Don't implement, needed to avoid copies of singleton
|
|
void operator=(NodeList const&); // Don't implement, needed to avoid copies of singleton
|
|
void sendSTUNRequest();
|
|
void processSTUNResponse(const QByteArray& packet);
|
|
|
|
void processDomainServerAuthRequest(const QByteArray& packet);
|
|
void requestAuthForDomainServer();
|
|
void activateSocketFromNodeCommunication(const QByteArray& packet, const SharedNodePointer& sendingNode);
|
|
void timePingReply(const QByteArray& packet, const SharedNodePointer& sendingNode);
|
|
|
|
NodeType_t _ownerType;
|
|
NodeSet _nodeTypesOfInterest;
|
|
DomainHandler _DomainHandler;
|
|
QUuid _sessionUUID;
|
|
int _numNoReplyDomainCheckIns;
|
|
HifiSockAddr _assignmentServerSocket;
|
|
HifiSockAddr _publicSockAddr;
|
|
bool _hasCompletedInitialSTUNFailure;
|
|
unsigned int _stunRequestsSinceSuccess;
|
|
};
|
|
|
|
#endif /* defined(__hifi__NodeList__) */
|