mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-15 21:36:59 +02:00
Moved LimitedNodeList into DM
This commit is contained in:
parent
0bd9ed469e
commit
aa0998dc7d
6 changed files with 42 additions and 62 deletions
|
@ -237,7 +237,8 @@ void DomainServer::setupNodeListAndAssignments(const QUuid& sessionUUID) {
|
|||
// check for scripts the user wants to persist from their domain-server config
|
||||
populateStaticScriptedAssignmentsFromSettings();
|
||||
|
||||
LimitedNodeList* nodeList = LimitedNodeList::createInstance(domainServerPort, domainServerDTLSPort);
|
||||
auto nodeList = DependencyManager::set<LimitedNodeList, unsigned short, unsigned short>(domainServerPort,
|
||||
domainServerDTLSPort);
|
||||
|
||||
// no matter the local port, save it to shared mem so that local assignment clients can ask what it is
|
||||
QSharedMemory* sharedPortMem = new QSharedMemory(DOMAIN_SERVER_LOCAL_PORT_SMEM_KEY, this);
|
||||
|
@ -346,8 +347,7 @@ bool DomainServer::optionallySetupAssignmentPayment() {
|
|||
}
|
||||
|
||||
void DomainServer::setupAutomaticNetworking() {
|
||||
|
||||
LimitedNodeList* nodeList = LimitedNodeList::getInstance();
|
||||
auto nodeList = DependencyManager::get<LimitedNodeList>();
|
||||
|
||||
const int STUN_REFLEXIVE_KEEPALIVE_INTERVAL_MSECS = 10 * 1000;
|
||||
const int STUN_IP_ADDRESS_CHECK_INTERVAL_MSECS = 30 * 1000;
|
||||
|
@ -617,7 +617,7 @@ void DomainServer::handleConnectRequest(const QByteArray& packet, const HifiSock
|
|||
QByteArray usernameRequestByteArray = byteArrayWithPopulatedHeader(PacketTypeDomainConnectionDenied);
|
||||
|
||||
// send this oauth request datagram back to the client
|
||||
LimitedNodeList::getInstance()->writeUnverifiedDatagram(usernameRequestByteArray, senderSockAddr);
|
||||
DependencyManager::get<LimitedNodeList>()->writeUnverifiedDatagram(usernameRequestByteArray, senderSockAddr);
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -637,7 +637,7 @@ void DomainServer::handleConnectRequest(const QByteArray& packet, const HifiSock
|
|||
}
|
||||
|
||||
|
||||
SharedNodePointer newNode = LimitedNodeList::getInstance()->addOrUpdateNode(nodeUUID, nodeType,
|
||||
SharedNodePointer newNode = DependencyManager::get<LimitedNodeList>()->addOrUpdateNode(nodeUUID, nodeType,
|
||||
publicSockAddr, localSockAddr);
|
||||
// when the newNode is created the linked data is also created
|
||||
// if this was a static assignment set the UUID, set the sendingSockAddr
|
||||
|
@ -670,7 +670,7 @@ bool DomainServer::shouldAllowConnectionFromNode(const QString& username,
|
|||
QStringList allowedUsers = allowedUsersVariant ? allowedUsersVariant->toStringList() : QStringList();
|
||||
|
||||
// we always let in a user who is sending a packet from our local socket or from the localhost address
|
||||
if (senderSockAddr.getAddress() == LimitedNodeList::getInstance()->getLocalSockAddr().getAddress()
|
||||
if (senderSockAddr.getAddress() == DependencyManager::get<LimitedNodeList>()->getLocalSockAddr().getAddress()
|
||||
|| senderSockAddr.getAddress() == QHostAddress::LocalHost) {
|
||||
return true;
|
||||
}
|
||||
|
@ -843,8 +843,8 @@ void DomainServer::sendDomainListToNode(const SharedNodePointer& node, const Hif
|
|||
int numBroadcastPacketLeadBytes = broadcastDataStream.device()->pos();
|
||||
|
||||
DomainServerNodeData* nodeData = reinterpret_cast<DomainServerNodeData*>(node->getLinkedData());
|
||||
|
||||
LimitedNodeList* nodeList = LimitedNodeList::getInstance();
|
||||
|
||||
auto nodeList = DependencyManager::get<LimitedNodeList>();
|
||||
|
||||
// if we've established a connection via ICE with this peer, use that socket
|
||||
// otherwise just try to reply back to them on their sending socket (although that may not work)
|
||||
|
@ -910,7 +910,7 @@ void DomainServer::sendDomainListToNode(const SharedNodePointer& node, const Hif
|
|||
}
|
||||
|
||||
void DomainServer::readAvailableDatagrams() {
|
||||
LimitedNodeList* nodeList = LimitedNodeList::getInstance();
|
||||
auto nodeList = DependencyManager::get<LimitedNodeList>();
|
||||
|
||||
HifiSockAddr senderSockAddr;
|
||||
QByteArray receivedPacket;
|
||||
|
@ -1112,7 +1112,7 @@ void DomainServer::transactionJSONCallback(const QJsonObject& data) {
|
|||
}
|
||||
|
||||
void DomainServer::requestCurrentPublicSocketViaSTUN() {
|
||||
LimitedNodeList::getInstance()->sendSTUNRequest();
|
||||
DependencyManager::get<LimitedNodeList>()->sendSTUNRequest();
|
||||
}
|
||||
|
||||
QJsonObject jsonForDomainSocketUpdate(const HifiSockAddr& socket) {
|
||||
|
@ -1134,7 +1134,7 @@ void DomainServer::performIPAddressUpdate(const HifiSockAddr& newPublicSockAddr)
|
|||
|
||||
void DomainServer::sendHeartbeatToDataServer(const QString& networkAddress) {
|
||||
const QString DOMAIN_UPDATE = "/api/v1/domains/%1";
|
||||
const QUuid& domainID = LimitedNodeList::getInstance()->getSessionUUID();
|
||||
const QUuid& domainID = DependencyManager::get<LimitedNodeList>()->getSessionUUID();
|
||||
|
||||
// setup the domain object to send to the data server
|
||||
const QString PUBLIC_NETWORK_ADDRESS_KEY = "network_address";
|
||||
|
@ -1187,11 +1187,11 @@ void DomainServer::performICEUpdates() {
|
|||
}
|
||||
|
||||
void DomainServer::sendHeartbeatToIceServer() {
|
||||
LimitedNodeList::getInstance()->sendHeartbeatToIceServer(_iceServerSocket);
|
||||
DependencyManager::get<LimitedNodeList>()->sendHeartbeatToIceServer(_iceServerSocket);
|
||||
}
|
||||
|
||||
void DomainServer::sendICEPingPackets() {
|
||||
LimitedNodeList* nodeList = LimitedNodeList::getInstance();
|
||||
auto nodeList = DependencyManager::get<LimitedNodeList>();
|
||||
|
||||
QHash<QUuid, NetworkPeer>::iterator peer = _connectingICEPeers.begin();
|
||||
|
||||
|
@ -1259,7 +1259,7 @@ void DomainServer::processICEPingReply(const QByteArray& packet, const HifiSockA
|
|||
}
|
||||
|
||||
void DomainServer::processDatagram(const QByteArray& receivedPacket, const HifiSockAddr& senderSockAddr) {
|
||||
LimitedNodeList* nodeList = LimitedNodeList::getInstance();
|
||||
auto nodeList = DependencyManager::get<LimitedNodeList>();
|
||||
|
||||
if (nodeList->packetVersionAndHashMatch(receivedPacket)) {
|
||||
PacketType requestType = packetTypeForPacket(receivedPacket);
|
||||
|
@ -1410,6 +1410,8 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
|||
|
||||
const QString UUID_REGEX_STRING = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
||||
|
||||
auto nodeList = DependencyManager::get<LimitedNodeList>();
|
||||
|
||||
// allow sub-handlers to handle requests that do not require authentication
|
||||
if (_settingsManager.handlePublicHTTPRequest(connection, url)) {
|
||||
return true;
|
||||
|
@ -1452,7 +1454,7 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
|||
const QString URI_ID = "/id";
|
||||
if (connection->requestOperation() == QNetworkAccessManager::GetOperation
|
||||
&& url.path() == URI_ID) {
|
||||
QUuid domainID = LimitedNodeList::getInstance()->getSessionUUID();
|
||||
QUuid domainID = nodeList->getSessionUUID();
|
||||
|
||||
connection->respond(HTTPConnection::StatusCode200, uuidStringWithoutCurlyBraces(domainID).toLocal8Bit());
|
||||
return true;
|
||||
|
@ -1536,7 +1538,7 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
|||
QJsonArray nodesJSONArray;
|
||||
|
||||
// enumerate the NodeList to find the assigned nodes
|
||||
LimitedNodeList::getInstance()->eachNode([this, &nodesJSONArray](const SharedNodePointer& node){
|
||||
nodeList->eachNode([this, &nodesJSONArray](const SharedNodePointer& node){
|
||||
// add the node using the UUID as the key
|
||||
nodesJSONArray.append(jsonObjectForNode(node));
|
||||
});
|
||||
|
@ -1559,7 +1561,7 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
|||
QUuid matchingUUID = QUuid(nodeShowRegex.cap(1));
|
||||
|
||||
// see if we have a node that matches this ID
|
||||
SharedNodePointer matchingNode = LimitedNodeList::getInstance()->nodeWithUUID(matchingUUID);
|
||||
SharedNodePointer matchingNode = nodeList->nodeWithUUID(matchingUUID);
|
||||
if (matchingNode) {
|
||||
// create a QJsonDocument with the stats QJsonObject
|
||||
QJsonObject statsObject =
|
||||
|
@ -1653,14 +1655,14 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
|||
// pull the captured string, if it exists
|
||||
QUuid deleteUUID = QUuid(nodeDeleteRegex.cap(1));
|
||||
|
||||
SharedNodePointer nodeToKill = LimitedNodeList::getInstance()->nodeWithUUID(deleteUUID);
|
||||
SharedNodePointer nodeToKill = nodeList->nodeWithUUID(deleteUUID);
|
||||
|
||||
if (nodeToKill) {
|
||||
// start with a 200 response
|
||||
connection->respond(HTTPConnection::StatusCode200);
|
||||
|
||||
// we have a valid UUID and node - kill the node that has this assignment
|
||||
QMetaObject::invokeMethod(LimitedNodeList::getInstance(), "killNodeWithUUID", Q_ARG(const QUuid&, deleteUUID));
|
||||
QMetaObject::invokeMethod(nodeList.data(), "killNodeWithUUID", Q_ARG(const QUuid&, deleteUUID));
|
||||
|
||||
// successfully processed request
|
||||
return true;
|
||||
|
@ -1669,7 +1671,7 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
|||
return true;
|
||||
} else if (allNodesDeleteRegex.indexIn(url.path()) != -1) {
|
||||
qDebug() << "Received request to kill all nodes.";
|
||||
LimitedNodeList::getInstance()->eraseAllNodes();
|
||||
nodeList->eraseAllNodes();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -38,35 +38,6 @@ const char SOLO_NODE_TYPES[2] = {
|
|||
|
||||
const QUrl DEFAULT_NODE_AUTH_URL = QUrl("https://data.highfidelity.io");
|
||||
|
||||
std::auto_ptr<LimitedNodeList> LimitedNodeList::_sharedInstance;
|
||||
|
||||
LimitedNodeList* LimitedNodeList::createInstance(unsigned short socketListenPort, unsigned short dtlsPort) {
|
||||
NodeType::init();
|
||||
|
||||
if (_sharedInstance.get()) {
|
||||
qDebug() << "LimitedNodeList called with existing instance." <<
|
||||
"Releasing auto_ptr, deleting existing instance and creating a new one.";
|
||||
|
||||
delete _sharedInstance.release();
|
||||
}
|
||||
|
||||
_sharedInstance = std::auto_ptr<LimitedNodeList>(new LimitedNodeList(socketListenPort, dtlsPort));
|
||||
|
||||
// register the SharedNodePointer meta-type for signals/slots
|
||||
qRegisterMetaType<SharedNodePointer>();
|
||||
|
||||
return _sharedInstance.get();
|
||||
}
|
||||
|
||||
LimitedNodeList* LimitedNodeList::getInstance() {
|
||||
if (!_sharedInstance.get()) {
|
||||
qDebug("LimitedNodeList getInstance called before call to createInstance. Returning NULL pointer.");
|
||||
}
|
||||
|
||||
return _sharedInstance.get();
|
||||
}
|
||||
|
||||
|
||||
LimitedNodeList::LimitedNodeList(unsigned short socketListenPort, unsigned short dtlsListenPort) :
|
||||
_sessionUUID(),
|
||||
_nodeHash(),
|
||||
|
@ -79,6 +50,15 @@ LimitedNodeList::LimitedNodeList(unsigned short socketListenPort, unsigned short
|
|||
_numCollectedBytes(0),
|
||||
_packetStatTimer()
|
||||
{
|
||||
static bool firstCall = true;
|
||||
if (firstCall) {
|
||||
NodeType::init();
|
||||
|
||||
// register the SharedNodePointer meta-type for signals/slots
|
||||
qRegisterMetaType<SharedNodePointer>();
|
||||
firstCall = false;
|
||||
}
|
||||
|
||||
_nodeSocket.bind(QHostAddress::AnyIPv4, socketListenPort);
|
||||
qDebug() << "NodeList socket is listening on" << _nodeSocket.localPort();
|
||||
|
||||
|
|
|
@ -69,10 +69,9 @@ namespace PingType {
|
|||
|
||||
class LimitedNodeList : public QObject {
|
||||
Q_OBJECT
|
||||
SINGLETON_DEPENDENCY(LimitedNodeList, true);
|
||||
|
||||
public:
|
||||
static LimitedNodeList* createInstance(unsigned short socketListenPort = 0, unsigned short dtlsPort = 0);
|
||||
static LimitedNodeList* getInstance();
|
||||
|
||||
const QUuid& getSessionUUID() const { return _sessionUUID; }
|
||||
void setSessionUUID(const QUuid& sessionUUID);
|
||||
|
||||
|
@ -179,10 +178,9 @@ signals:
|
|||
|
||||
void localSockAddrChanged(const HifiSockAddr& localSockAddr);
|
||||
void publicSockAddrChanged(const HifiSockAddr& publicSockAddr);
|
||||
|
||||
protected:
|
||||
static std::auto_ptr<LimitedNodeList> _sharedInstance;
|
||||
|
||||
LimitedNodeList(unsigned short socketListenPort, unsigned short dtlsListenPort);
|
||||
LimitedNodeList(unsigned short socketListenPort = 0, unsigned short dtlsListenPort = 0);
|
||||
LimitedNodeList(LimitedNodeList const&); // Don't implement, needed to avoid copies of singleton
|
||||
void operator=(LimitedNodeList const&); // Don't implement, needed to avoid copies of singleton
|
||||
|
||||
|
|
|
@ -170,7 +170,7 @@ int populatePacketHeader(char* packet, PacketType type, const QUuid& connectionU
|
|||
|
||||
char* position = packet + numTypeBytes + sizeof(PacketVersion);
|
||||
|
||||
QUuid packUUID = connectionUUID.isNull() ? LimitedNodeList::getInstance()->getSessionUUID() : connectionUUID;
|
||||
QUuid packUUID = connectionUUID.isNull() ? DependencyManager::get<LimitedNodeList>()->getSessionUUID() : connectionUUID;
|
||||
|
||||
QByteArray rfcUUID = packUUID.toRfc4122();
|
||||
memcpy(position, rfcUUID.constData(), NUM_BYTES_RFC4122_UUID);
|
||||
|
|
|
@ -21,7 +21,7 @@ public:\
|
|||
typedef QSharedPointer<T> SharedPointer;\
|
||||
typedef QWeakPointer<T> WeakPointer;\
|
||||
private:\
|
||||
static constexpr bool REQUIRE_SET = NEED_SET;\
|
||||
static const bool REQUIRE_SET = NEED_SET;\
|
||||
void customDeleter() {\
|
||||
QObject* thisObject = dynamic_cast<QObject*>(this);\
|
||||
if (thisObject) {\
|
||||
|
@ -34,12 +34,12 @@ private:\
|
|||
|
||||
class QObject;
|
||||
|
||||
// usage:
|
||||
// T* instance = DependencyManager::get<T>();
|
||||
// T* instance = DependencyManager::set<T, Type1, Type2, ...>(Args... args);
|
||||
// T* instance = DependencyManager::destroy<T>();
|
||||
class DependencyManager {
|
||||
public:
|
||||
// usage:
|
||||
// T* instance = DependencyManager::get<T>();
|
||||
// T* instance = DependencyManager::set<T>(Args... args);
|
||||
// T* instance = DependencyManager::destroy<T>();
|
||||
template<typename T>
|
||||
static QSharedPointer<T> get();
|
||||
|
||||
|
|
|
@ -440,7 +440,7 @@ static bool testSerialization(Bitstream::MetadataType metadataType) {
|
|||
}
|
||||
|
||||
bool MetavoxelTests::run() {
|
||||
LimitedNodeList::createInstance();
|
||||
DependencyManager::set<LimitedNodeList>();
|
||||
|
||||
// seed the random number generator so that our tests are reproducible
|
||||
srand(0xBAAAAABE);
|
||||
|
|
Loading…
Reference in a new issue