mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 04:53:25 +02:00
Merge pull request #954 from birarda/ds-port
allow setting of custom DS port from DS and clients
This commit is contained in:
commit
a81d5cd9a7
12 changed files with 136 additions and 138 deletions
|
@ -685,9 +685,9 @@ int main(int argc, const char * argv[])
|
||||||
nodeList->setDomainIPToLocalhost();
|
nodeList->setDomainIPToLocalhost();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* domainIP = getCmdOption(argc, argv, "--domain");
|
const char* domainHostname = getCmdOption(argc, argv, "--domain");
|
||||||
if (domainIP) {
|
if (domainHostname) {
|
||||||
NodeList::getInstance()->setDomainIP(domainIP);
|
NodeList::getInstance()->setDomainHostname(domainHostname);
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeList->linkedDataCreateCallback = NULL; // do we need a callback?
|
nodeList->linkedDataCreateCallback = NULL; // do we need a callback?
|
||||||
|
|
|
@ -27,7 +27,7 @@ void Agent::run() {
|
||||||
|
|
||||||
// figure out the URL for the script for this agent assignment
|
// figure out the URL for the script for this agent assignment
|
||||||
QString scriptURLString("http://%1:8080/assignment/%2");
|
QString scriptURLString("http://%1:8080/assignment/%2");
|
||||||
scriptURLString = scriptURLString.arg(NodeList::getInstance()->getDomainIP(),
|
scriptURLString = scriptURLString.arg(NodeList::getInstance()->getDomainIP().toString(),
|
||||||
this->getUUIDStringWithoutCurlyBraces());
|
this->getUUIDStringWithoutCurlyBraces());
|
||||||
QUrl scriptURL(scriptURLString);
|
QUrl scriptURL(scriptURLString);
|
||||||
|
|
||||||
|
|
|
@ -84,19 +84,20 @@ void childClient() {
|
||||||
if (packetData[0] == PACKET_TYPE_CREATE_ASSIGNMENT ||
|
if (packetData[0] == PACKET_TYPE_CREATE_ASSIGNMENT ||
|
||||||
deployedAssignment->getAttachedPublicSocket()->sa_family == AF_INET) {
|
deployedAssignment->getAttachedPublicSocket()->sa_family == AF_INET) {
|
||||||
|
|
||||||
in_addr domainSocketAddr = {};
|
|
||||||
|
sockaddr* domainSocket = NULL;
|
||||||
|
|
||||||
if (packetData[0] == PACKET_TYPE_CREATE_ASSIGNMENT) {
|
if (packetData[0] == PACKET_TYPE_CREATE_ASSIGNMENT) {
|
||||||
// the domain server IP address is the address we got this packet from
|
// the domain server IP address is the address we got this packet from
|
||||||
domainSocketAddr = senderSocket.sin_addr;
|
domainSocket = (sockaddr*) &senderSocket;
|
||||||
} else {
|
} else {
|
||||||
// grab the domain server IP address from the packet from the AS
|
// grab the domain server IP address from the packet from the AS
|
||||||
domainSocketAddr = ((sockaddr_in*) deployedAssignment->getAttachedPublicSocket())->sin_addr;
|
domainSocket = (sockaddr*) deployedAssignment->getAttachedPublicSocket();
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeList->setDomainIP(inet_ntoa(domainSocketAddr));
|
nodeList->setDomainIP(QHostAddress(domainSocket));
|
||||||
|
|
||||||
qDebug("Destination IP for assignment is %s\n", inet_ntoa(domainSocketAddr));
|
qDebug("Destination IP for assignment is %s\n", nodeList->getDomainIP().toString().toStdString().c_str());
|
||||||
|
|
||||||
// run the deployed assignment
|
// run the deployed assignment
|
||||||
deployedAssignment->run();
|
deployedAssignment->run();
|
||||||
|
@ -199,7 +200,7 @@ int main(int argc, const char* argv[]) {
|
||||||
if (customAssignmentServerHostname) {
|
if (customAssignmentServerHostname) {
|
||||||
const char* customAssignmentServerPortString = getCmdOption(argc, argv, CUSTOM_ASSIGNMENT_SERVER_PORT_OPTION);
|
const char* customAssignmentServerPortString = getCmdOption(argc, argv, CUSTOM_ASSIGNMENT_SERVER_PORT_OPTION);
|
||||||
unsigned short assignmentServerPort = customAssignmentServerPortString
|
unsigned short assignmentServerPort = customAssignmentServerPortString
|
||||||
? atoi(customAssignmentServerPortString) : ASSIGNMENT_SERVER_PORT;
|
? atoi(customAssignmentServerPortString) : DEFAULT_DOMAIN_SERVER_PORT;
|
||||||
|
|
||||||
::customAssignmentSocket = socketForHostnameAndHostOrderPort(customAssignmentServerHostname, assignmentServerPort);
|
::customAssignmentSocket = socketForHostnameAndHostOrderPort(customAssignmentServerHostname, assignmentServerPort);
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,11 @@ int main(int argc, const char* argv[]) {
|
||||||
|
|
||||||
qInstallMessageHandler(Logging::verboseMessageHandler);
|
qInstallMessageHandler(Logging::verboseMessageHandler);
|
||||||
|
|
||||||
NodeList* nodeList = NodeList::createInstance(NODE_TYPE_DOMAIN, DOMAIN_LISTEN_PORT);
|
const char CUSTOM_PORT_OPTION[] = "-p";
|
||||||
|
const char* customPortString = getCmdOption(argc, argv, CUSTOM_PORT_OPTION);
|
||||||
|
unsigned short domainServerPort = customPortString ? atoi(customPortString) : DOMAIN_LISTEN_PORT;
|
||||||
|
|
||||||
|
NodeList* nodeList = NodeList::createInstance(NODE_TYPE_DOMAIN, domainServerPort);
|
||||||
|
|
||||||
setvbuf(stdout, NULL, _IOLBF, 0);
|
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||||
|
|
||||||
|
|
|
@ -183,18 +183,6 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
|
||||||
// --domain or --local options
|
// --domain or --local options
|
||||||
NodeList::getInstance()->loadData(_settings);
|
NodeList::getInstance()->loadData(_settings);
|
||||||
|
|
||||||
const char* domainIP = getCmdOption(argc, constArgv, "--domain");
|
|
||||||
if (domainIP) {
|
|
||||||
NodeList::getInstance()->setDomainIP(domainIP);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle Local Domain testing with the --local command line
|
|
||||||
if (cmdOptionExists(argc, constArgv, "--local")) {
|
|
||||||
qDebug("Local Domain MODE!\n");
|
|
||||||
|
|
||||||
NodeList::getInstance()->setDomainIPToLocalhost();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check to see if the user passed in a command line option for loading a local
|
// Check to see if the user passed in a command line option for loading a local
|
||||||
// Voxel File.
|
// Voxel File.
|
||||||
_voxelsFilename = getCmdOption(argc, constArgv, "-i");
|
_voxelsFilename = getCmdOption(argc, constArgv, "-i");
|
||||||
|
|
|
@ -687,6 +687,48 @@ void Menu::aboutApp() {
|
||||||
InfoView::forcedShow();
|
InfoView::forcedShow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateDSHostname(const QString& domainServerHostname) {
|
||||||
|
QString newHostname(DEFAULT_DOMAIN_HOSTNAME);
|
||||||
|
|
||||||
|
if (domainServerHostname.size() > 0) {
|
||||||
|
// the user input a new hostname, use that
|
||||||
|
newHostname = domainServerHostname;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if the domain server hostname is new
|
||||||
|
if (NodeList::getInstance()->getDomainHostname() != newHostname) {
|
||||||
|
|
||||||
|
NodeList::getInstance()->clear();
|
||||||
|
|
||||||
|
// kill the local voxels
|
||||||
|
Application::getInstance()->getVoxels()->killLocalVoxels();
|
||||||
|
|
||||||
|
// reset the environment to default
|
||||||
|
Application::getInstance()->getEnvironment()->resetToDefault();
|
||||||
|
|
||||||
|
// set the new hostname
|
||||||
|
NodeList::getInstance()->setDomainHostname(newHostname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const int QLINE_MINIMUM_WIDTH = 400;
|
||||||
|
|
||||||
|
|
||||||
|
QLineEdit* lineEditForDomainHostname() {
|
||||||
|
QString currentDomainHostname = NodeList::getInstance()->getDomainHostname();
|
||||||
|
|
||||||
|
if (NodeList::getInstance()->getDomainPort() != DEFAULT_DOMAIN_SERVER_PORT) {
|
||||||
|
// add the port to the currentDomainHostname string if it is custom
|
||||||
|
currentDomainHostname.append(QString(":%1").arg(NodeList::getInstance()->getDomainPort()));
|
||||||
|
}
|
||||||
|
|
||||||
|
QLineEdit* domainServerLineEdit = new QLineEdit(currentDomainHostname);
|
||||||
|
domainServerLineEdit->setPlaceholderText(DEFAULT_DOMAIN_HOSTNAME);
|
||||||
|
domainServerLineEdit->setMinimumWidth(QLINE_MINIMUM_WIDTH);
|
||||||
|
|
||||||
|
return domainServerLineEdit;
|
||||||
|
}
|
||||||
|
|
||||||
void Menu::editPreferences() {
|
void Menu::editPreferences() {
|
||||||
Application* applicationInstance = Application::getInstance();
|
Application* applicationInstance = Application::getInstance();
|
||||||
QDialog dialog(applicationInstance->getGLWidget());
|
QDialog dialog(applicationInstance->getGLWidget());
|
||||||
|
@ -697,11 +739,8 @@ void Menu::editPreferences() {
|
||||||
QFormLayout* form = new QFormLayout();
|
QFormLayout* form = new QFormLayout();
|
||||||
layout->addLayout(form, 1);
|
layout->addLayout(form, 1);
|
||||||
|
|
||||||
const int QLINE_MINIMUM_WIDTH = 400;
|
QLineEdit* domainServerLineEdit = lineEditForDomainHostname();
|
||||||
|
form->addRow("Domain server:", domainServerLineEdit);
|
||||||
QLineEdit* domainServerHostname = new QLineEdit(QString(NodeList::getInstance()->getDomainHostname()));
|
|
||||||
domainServerHostname->setMinimumWidth(QLINE_MINIMUM_WIDTH);
|
|
||||||
form->addRow("Domain server:", domainServerHostname);
|
|
||||||
|
|
||||||
QLineEdit* avatarURL = new QLineEdit(applicationInstance->getAvatar()->getVoxels()->getVoxelURL().toString());
|
QLineEdit* avatarURL = new QLineEdit(applicationInstance->getAvatar()->getVoxels()->getVoxelURL().toString());
|
||||||
avatarURL->setMinimumWidth(QLINE_MINIMUM_WIDTH);
|
avatarURL->setMinimumWidth(QLINE_MINIMUM_WIDTH);
|
||||||
|
@ -738,30 +777,7 @@ void Menu::editPreferences() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray newHostname;
|
updateDSHostname(domainServerLineEdit->text());
|
||||||
|
|
||||||
if (domainServerHostname->text().size() > 0) {
|
|
||||||
// the user input a new hostname, use that
|
|
||||||
newHostname = domainServerHostname->text().toLocal8Bit();
|
|
||||||
} else {
|
|
||||||
// the user left the field blank, use the default hostname
|
|
||||||
newHostname = QByteArray(DEFAULT_DOMAIN_HOSTNAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if the domain server hostname is new
|
|
||||||
if (memcmp(NodeList::getInstance()->getDomainHostname(), newHostname.constData(), newHostname.size()) != 0) {
|
|
||||||
|
|
||||||
NodeList::getInstance()->clear();
|
|
||||||
|
|
||||||
// kill the local voxels
|
|
||||||
applicationInstance->getVoxels()->killLocalVoxels();
|
|
||||||
|
|
||||||
// reset the environment to default
|
|
||||||
applicationInstance->getEnvironment()->resetToDefault();
|
|
||||||
|
|
||||||
// set the new hostname
|
|
||||||
NodeList::getInstance()->setDomainHostname(newHostname.constData());
|
|
||||||
}
|
|
||||||
|
|
||||||
QUrl url(avatarURL->text());
|
QUrl url(avatarURL->text());
|
||||||
applicationInstance->getAvatar()->getVoxels()->setVoxelURL(url);
|
applicationInstance->getAvatar()->getVoxels()->setVoxelURL(url);
|
||||||
|
@ -790,12 +806,10 @@ void Menu::goToDomain() {
|
||||||
|
|
||||||
QFormLayout* form = new QFormLayout();
|
QFormLayout* form = new QFormLayout();
|
||||||
layout->addLayout(form, 1);
|
layout->addLayout(form, 1);
|
||||||
|
|
||||||
|
|
||||||
const int QLINE_MINIMUM_WIDTH = 400;
|
QLineEdit* domainServerLineEdit = lineEditForDomainHostname();
|
||||||
|
form->addRow("Domain server:", domainServerLineEdit);
|
||||||
QLineEdit* domainServerHostname = new QLineEdit(QString(NodeList::getInstance()->getDomainHostname()));
|
|
||||||
domainServerHostname->setMinimumWidth(QLINE_MINIMUM_WIDTH);
|
|
||||||
form->addRow("Domain server:", domainServerHostname);
|
|
||||||
|
|
||||||
QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||||
dialog.connect(buttons, SIGNAL(accepted()), SLOT(accept()));
|
dialog.connect(buttons, SIGNAL(accepted()), SLOT(accept()));
|
||||||
|
@ -808,30 +822,7 @@ void Menu::goToDomain() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray newHostname;
|
updateDSHostname(domainServerLineEdit->text());
|
||||||
|
|
||||||
if (domainServerHostname->text().size() > 0) {
|
|
||||||
// the user input a new hostname, use that
|
|
||||||
newHostname = domainServerHostname->text().toLocal8Bit();
|
|
||||||
} else {
|
|
||||||
// the user left the field blank, use the default hostname
|
|
||||||
newHostname = QByteArray(DEFAULT_DOMAIN_HOSTNAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if the domain server hostname is new
|
|
||||||
if (memcmp(NodeList::getInstance()->getDomainHostname(), newHostname.constData(), newHostname.size()) != 0) {
|
|
||||||
|
|
||||||
NodeList::getInstance()->clear();
|
|
||||||
|
|
||||||
// kill the local voxels
|
|
||||||
applicationInstance->getVoxels()->killLocalVoxels();
|
|
||||||
|
|
||||||
// reset the environment to default
|
|
||||||
applicationInstance->getEnvironment()->resetToDefault();
|
|
||||||
|
|
||||||
// set the new hostname
|
|
||||||
NodeList::getInstance()->setDomainHostname(newHostname.constData());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::goToLocation() {
|
void Menu::goToLocation() {
|
||||||
|
|
|
@ -6,9 +6,13 @@ set(MACRO_DIR ${ROOT_DIR}/cmake/macros)
|
||||||
set(TARGET_NAME shared)
|
set(TARGET_NAME shared)
|
||||||
project(${TARGET_NAME})
|
project(${TARGET_NAME})
|
||||||
|
|
||||||
|
find_package(Qt5Network REQUIRED)
|
||||||
|
|
||||||
include(${MACRO_DIR}/SetupHifiLibrary.cmake)
|
include(${MACRO_DIR}/SetupHifiLibrary.cmake)
|
||||||
setup_hifi_library(${TARGET_NAME})
|
setup_hifi_library(${TARGET_NAME})
|
||||||
|
|
||||||
|
qt5_use_modules(${TARGET_NAME} Network)
|
||||||
|
|
||||||
set(EXTERNAL_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external)
|
set(EXTERNAL_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external)
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
|
#include <QtNetwork/QHostInfo>
|
||||||
|
|
||||||
#include "Assignment.h"
|
#include "Assignment.h"
|
||||||
#include "Logging.h"
|
#include "Logging.h"
|
||||||
|
@ -31,9 +32,8 @@ const char SOLO_NODE_TYPES[2] = {
|
||||||
NODE_TYPE_AUDIO_MIXER
|
NODE_TYPE_AUDIO_MIXER
|
||||||
};
|
};
|
||||||
|
|
||||||
const char DEFAULT_DOMAIN_HOSTNAME[MAX_HOSTNAME_BYTES] = "root.highfidelity.io";
|
const QString DEFAULT_DOMAIN_HOSTNAME = "root.highfidelity.io";
|
||||||
const char DEFAULT_DOMAIN_IP[INET_ADDRSTRLEN] = ""; // IP Address will be re-set by lookup on startup
|
const unsigned short DEFAULT_DOMAIN_SERVER_PORT = 40102;
|
||||||
const int DEFAULT_DOMAINSERVER_PORT = 40102;
|
|
||||||
|
|
||||||
bool silentNodeThreadStopFlag = false;
|
bool silentNodeThreadStopFlag = false;
|
||||||
bool pingUnknownNodeThreadStopFlag = false;
|
bool pingUnknownNodeThreadStopFlag = false;
|
||||||
|
@ -59,6 +59,9 @@ NodeList* NodeList::getInstance() {
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeList::NodeList(char newOwnerType, unsigned short int newSocketListenPort) :
|
NodeList::NodeList(char newOwnerType, unsigned short int newSocketListenPort) :
|
||||||
|
_domainHostname(DEFAULT_DOMAIN_HOSTNAME),
|
||||||
|
_domainIP(),
|
||||||
|
_domainPort(DEFAULT_DOMAIN_SERVER_PORT),
|
||||||
_nodeBuckets(),
|
_nodeBuckets(),
|
||||||
_numNodes(0),
|
_numNodes(0),
|
||||||
_nodeSocket(newSocketListenPort),
|
_nodeSocket(newSocketListenPort),
|
||||||
|
@ -69,8 +72,7 @@ NodeList::NodeList(char newOwnerType, unsigned short int newSocketListenPort) :
|
||||||
_numNoReplyDomainCheckIns(0),
|
_numNoReplyDomainCheckIns(0),
|
||||||
_assignmentServerSocket(NULL)
|
_assignmentServerSocket(NULL)
|
||||||
{
|
{
|
||||||
memcpy(_domainHostname, DEFAULT_DOMAIN_HOSTNAME, sizeof(DEFAULT_DOMAIN_HOSTNAME));
|
|
||||||
memcpy(_domainIP, DEFAULT_DOMAIN_IP, sizeof(DEFAULT_DOMAIN_IP));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeList::~NodeList() {
|
NodeList::~NodeList() {
|
||||||
|
@ -82,22 +84,29 @@ NodeList::~NodeList() {
|
||||||
stopSilentNodeRemovalThread();
|
stopSilentNodeRemovalThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeList::setDomainHostname(const char* domainHostname) {
|
void NodeList::setDomainHostname(const QString& domainHostname) {
|
||||||
memset(_domainHostname, 0, sizeof(_domainHostname));
|
|
||||||
memcpy(_domainHostname, domainHostname, strlen(domainHostname));
|
|
||||||
|
|
||||||
// reset the domain IP so the hostname is checked again
|
int colonIndex = domainHostname.indexOf(':');
|
||||||
setDomainIP("");
|
|
||||||
}
|
if (colonIndex > 0) {
|
||||||
|
// the user has included a custom DS port with the hostname
|
||||||
void NodeList::setDomainIP(const char* domainIP) {
|
|
||||||
memset(_domainIP, 0, sizeof(_domainIP));
|
// the new hostname is everything up to the colon
|
||||||
memcpy(_domainIP, domainIP, strlen(domainIP));
|
_domainHostname = domainHostname.left(colonIndex);
|
||||||
}
|
|
||||||
|
// grab the port by reading the string after the colon
|
||||||
void NodeList::setDomainIPToLocalhost() {
|
_domainPort = atoi(domainHostname.mid(colonIndex + 1, domainHostname.size()).toLocal8Bit().constData());
|
||||||
int ip = getLocalAddress();
|
|
||||||
sprintf(_domainIP, "%d.%d.%d.%d", (ip & 0xFF), ((ip >> 8) & 0xFF),((ip >> 16) & 0xFF), ((ip >> 24) & 0xFF));
|
qDebug() << "Updated hostname to" << _domainHostname << "and port to" << _domainPort << "\n";
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// no port included with the hostname, simply set the member variable and reset the domain server port to default
|
||||||
|
_domainHostname = domainHostname;
|
||||||
|
_domainPort = DEFAULT_DOMAIN_SERVER_PORT;
|
||||||
|
}
|
||||||
|
|
||||||
|
// reset our _domainIP to the null address so that a lookup happens on next check in
|
||||||
|
_domainIP = QHostAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeList::timePingReply(sockaddr *nodeAddress, unsigned char *packetData) {
|
void NodeList::timePingReply(sockaddr *nodeAddress, unsigned char *packetData) {
|
||||||
|
@ -117,10 +126,7 @@ void NodeList::processNodeData(sockaddr* senderAddress, unsigned char* packetDat
|
||||||
switch (packetData[0]) {
|
switch (packetData[0]) {
|
||||||
case PACKET_TYPE_DOMAIN: {
|
case PACKET_TYPE_DOMAIN: {
|
||||||
// only process the DS if this is our current domain server
|
// only process the DS if this is our current domain server
|
||||||
sockaddr_in domainServerSocket = *(sockaddr_in*) senderAddress;
|
if (_domainIP == QHostAddress(senderAddress)) {
|
||||||
const char* domainSenderIP = inet_ntoa(domainServerSocket.sin_addr);
|
|
||||||
|
|
||||||
if (memcmp(domainSenderIP, _domainIP, strlen(domainSenderIP)) == 0) {
|
|
||||||
processDomainServerList(packetData, dataBytes);
|
processDomainServerList(packetData, dataBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,19 +278,23 @@ void NodeList::sendDomainServerCheckIn(const char* assignmentUUID) {
|
||||||
static bool printedDomainServerIP = false;
|
static bool printedDomainServerIP = false;
|
||||||
|
|
||||||
// Lookup the IP address of the domain server if we need to
|
// Lookup the IP address of the domain server if we need to
|
||||||
if (atoi(_domainIP) == 0) {
|
if (_domainIP.isNull()) {
|
||||||
printf("Looking up %s\n", _domainHostname);
|
qDebug("Looking up DS hostname %s.\n", _domainHostname.toStdString().c_str());
|
||||||
struct hostent* pHostInfo;
|
|
||||||
if ((pHostInfo = gethostbyname(_domainHostname)) != NULL) {
|
QHostInfo domainServerHostInfo = QHostInfo::fromName(_domainHostname);
|
||||||
sockaddr_in tempAddress;
|
|
||||||
memcpy(&tempAddress.sin_addr, pHostInfo->h_addr_list[0], pHostInfo->h_length);
|
if (!domainServerHostInfo.addresses().isEmpty()) {
|
||||||
strcpy(_domainIP, inet_ntoa(tempAddress.sin_addr));
|
// set our domainIP to the first IP address
|
||||||
qDebug("Domain Server: %s\n", _domainHostname);
|
_domainIP = domainServerHostInfo.addresses().first();
|
||||||
|
|
||||||
|
qDebug("DS at %s is at %s\n", _domainHostname.toStdString().c_str(), _domainIP.toString().toStdString().c_str());
|
||||||
|
|
||||||
|
printedDomainServerIP = true;
|
||||||
} else {
|
} else {
|
||||||
qDebug("Failed domain server lookup\n");
|
qDebug("Failed domain server lookup\n");
|
||||||
}
|
}
|
||||||
} else if (!printedDomainServerIP) {
|
} else if (!printedDomainServerIP) {
|
||||||
qDebug("Domain Server IP: %s\n", _domainIP);
|
qDebug("Domain Server IP: %s\n", _domainIP.toString().toStdString().c_str());
|
||||||
printedDomainServerIP = true;
|
printedDomainServerIP = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -337,7 +347,7 @@ void NodeList::sendDomainServerCheckIn(const char* assignmentUUID) {
|
||||||
checkInPacketSize = packetPosition - checkInPacket;
|
checkInPacketSize = packetPosition - checkInPacket;
|
||||||
}
|
}
|
||||||
|
|
||||||
_nodeSocket.send(_domainIP, DEFAULT_DOMAINSERVER_PORT, checkInPacket, checkInPacketSize);
|
_nodeSocket.send(_domainIP.toString().toStdString().c_str(), _domainPort, checkInPacket, checkInPacketSize);
|
||||||
|
|
||||||
// increment the count of un-replied check-ins
|
// increment the count of un-replied check-ins
|
||||||
_numNoReplyDomainCheckIns++;
|
_numNoReplyDomainCheckIns++;
|
||||||
|
@ -370,7 +380,7 @@ int NodeList::processDomainServerList(unsigned char* packetData, size_t dataByte
|
||||||
// if the public socket address is 0 then it's reachable at the same IP
|
// if the public socket address is 0 then it's reachable at the same IP
|
||||||
// as the domain server
|
// as the domain server
|
||||||
if (nodePublicSocket.sin_addr.s_addr == 0) {
|
if (nodePublicSocket.sin_addr.s_addr == 0) {
|
||||||
inet_aton(_domainIP, &nodePublicSocket.sin_addr);
|
nodePublicSocket.sin_addr.s_addr = _domainIP.toIPv4Address();
|
||||||
}
|
}
|
||||||
|
|
||||||
addOrUpdateNode((sockaddr*) &nodePublicSocket, (sockaddr*) &nodeLocalSocket, nodeType, nodeId);
|
addOrUpdateNode((sockaddr*) &nodePublicSocket, (sockaddr*) &nodeLocalSocket, nodeType, nodeId);
|
||||||
|
@ -382,9 +392,9 @@ int NodeList::processDomainServerList(unsigned char* packetData, size_t dataByte
|
||||||
return readNodes;
|
return readNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char GLOBAL_ASSIGNMENT_SERVER_HOSTNAME[] = "assignment.highfidelity.io";
|
const char LOCAL_ASSIGNMENT_SERVER_HOSTNAME[] = "localhost";
|
||||||
const sockaddr_in GLOBAL_ASSIGNMENT_SOCKET = socketForHostnameAndHostOrderPort(GLOBAL_ASSIGNMENT_SERVER_HOSTNAME,
|
const sockaddr_in DEFAULT_LOCAL_ASSIGNMENT_SOCKET = socketForHostnameAndHostOrderPort(LOCAL_ASSIGNMENT_SERVER_HOSTNAME,
|
||||||
ASSIGNMENT_SERVER_PORT);
|
DEFAULT_DOMAIN_SERVER_PORT);
|
||||||
void NodeList::sendAssignment(Assignment& assignment) {
|
void NodeList::sendAssignment(Assignment& assignment) {
|
||||||
unsigned char assignmentPacket[MAX_PACKET_SIZE];
|
unsigned char assignmentPacket[MAX_PACKET_SIZE];
|
||||||
|
|
||||||
|
@ -396,7 +406,7 @@ void NodeList::sendAssignment(Assignment& assignment) {
|
||||||
int numAssignmentBytes = assignment.packToBuffer(assignmentPacket + numHeaderBytes);
|
int numAssignmentBytes = assignment.packToBuffer(assignmentPacket + numHeaderBytes);
|
||||||
|
|
||||||
sockaddr* assignmentServerSocket = (_assignmentServerSocket == NULL)
|
sockaddr* assignmentServerSocket = (_assignmentServerSocket == NULL)
|
||||||
? (sockaddr*) &GLOBAL_ASSIGNMENT_SOCKET
|
? (sockaddr*) &DEFAULT_LOCAL_ASSIGNMENT_SOCKET
|
||||||
: _assignmentServerSocket;
|
: _assignmentServerSocket;
|
||||||
|
|
||||||
_nodeSocket.send(assignmentServerSocket, assignmentPacket, numHeaderBytes + numAssignmentBytes);
|
_nodeSocket.send(assignmentServerSocket, assignmentPacket, numHeaderBytes + numAssignmentBytes);
|
||||||
|
@ -561,8 +571,7 @@ void NodeList::loadData(QSettings *settings) {
|
||||||
QString domainServerHostname = settings->value(DOMAIN_SERVER_SETTING_KEY).toString();
|
QString domainServerHostname = settings->value(DOMAIN_SERVER_SETTING_KEY).toString();
|
||||||
|
|
||||||
if (domainServerHostname.size() > 0) {
|
if (domainServerHostname.size() > 0) {
|
||||||
memset(_domainHostname, 0, MAX_HOSTNAME_BYTES);
|
_domainHostname = domainServerHostname;
|
||||||
memcpy(_domainHostname, domainServerHostname.toLocal8Bit().constData(), domainServerHostname.size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
settings->endGroup();
|
settings->endGroup();
|
||||||
|
@ -571,7 +580,7 @@ void NodeList::loadData(QSettings *settings) {
|
||||||
void NodeList::saveData(QSettings* settings) {
|
void NodeList::saveData(QSettings* settings) {
|
||||||
settings->beginGroup(DOMAIN_SERVER_SETTING_KEY);
|
settings->beginGroup(DOMAIN_SERVER_SETTING_KEY);
|
||||||
|
|
||||||
if (memcmp(_domainHostname, DEFAULT_DOMAIN_HOSTNAME, strlen(DEFAULT_DOMAIN_HOSTNAME)) != 0) {
|
if (_domainHostname != DEFAULT_DOMAIN_HOSTNAME) {
|
||||||
// the user is using a different hostname, store it
|
// the user is using a different hostname, store it
|
||||||
settings->setValue(DOMAIN_SERVER_SETTING_KEY, QVariant(_domainHostname));
|
settings->setValue(DOMAIN_SERVER_SETTING_KEY, QVariant(_domainHostname));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <QtNetwork/QHostAddress>
|
||||||
#include <QtCore/QSettings>
|
#include <QtCore/QSettings>
|
||||||
|
|
||||||
#include "Node.h"
|
#include "Node.h"
|
||||||
|
@ -36,9 +37,8 @@ extern const char SOLO_NODE_TYPES[2];
|
||||||
|
|
||||||
const int MAX_HOSTNAME_BYTES = 256;
|
const int MAX_HOSTNAME_BYTES = 256;
|
||||||
|
|
||||||
extern const char DEFAULT_DOMAIN_HOSTNAME[MAX_HOSTNAME_BYTES];
|
extern const QString DEFAULT_DOMAIN_HOSTNAME;
|
||||||
extern const char DEFAULT_DOMAIN_IP[INET_ADDRSTRLEN]; // IP Address will be re-set by lookup on startup
|
extern const unsigned short DEFAULT_DOMAIN_SERVER_PORT;
|
||||||
extern const int DEFAULT_DOMAINSERVER_PORT;
|
|
||||||
|
|
||||||
const int UNKNOWN_NODE_ID = 0;
|
const int UNKNOWN_NODE_ID = 0;
|
||||||
|
|
||||||
|
@ -65,16 +65,18 @@ public:
|
||||||
NodeListIterator begin() const;
|
NodeListIterator begin() const;
|
||||||
NodeListIterator end() const;
|
NodeListIterator end() const;
|
||||||
|
|
||||||
|
|
||||||
NODE_TYPE getOwnerType() const { return _ownerType; }
|
NODE_TYPE getOwnerType() const { return _ownerType; }
|
||||||
void setOwnerType(NODE_TYPE ownerType) { _ownerType = ownerType; }
|
void setOwnerType(NODE_TYPE ownerType) { _ownerType = ownerType; }
|
||||||
|
|
||||||
const char* getDomainHostname() const { return _domainHostname; }
|
const QString& getDomainHostname() const { return _domainHostname; }
|
||||||
void setDomainHostname(const char* domainHostname);
|
void setDomainHostname(const QString& domainHostname);
|
||||||
|
|
||||||
const char* getDomainIP() const { return _domainIP; }
|
const QHostAddress& getDomainIP() const { return _domainIP; }
|
||||||
void setDomainIP(const char* domainIP);
|
void setDomainIP(const QHostAddress& domainIP) { _domainIP = domainIP; }
|
||||||
void setDomainIPToLocalhost();
|
void setDomainIPToLocalhost() { _domainIP = QHostAddress(INADDR_LOOPBACK); }
|
||||||
|
|
||||||
|
unsigned short getDomainPort() const { return _domainPort; }
|
||||||
|
void setDomainPort(unsigned short domainPort) { _domainPort = domainPort; }
|
||||||
|
|
||||||
uint16_t getLastNodeID() const { return _lastNodeID; }
|
uint16_t getLastNodeID() const { return _lastNodeID; }
|
||||||
void increaseNodeID() { (++_lastNodeID == UNKNOWN_NODE_ID) ? ++_lastNodeID : _lastNodeID; }
|
void increaseNodeID() { (++_lastNodeID == UNKNOWN_NODE_ID) ? ++_lastNodeID : _lastNodeID; }
|
||||||
|
@ -141,8 +143,9 @@ private:
|
||||||
|
|
||||||
void addNodeToList(Node* newNode);
|
void addNodeToList(Node* newNode);
|
||||||
|
|
||||||
char _domainHostname[MAX_HOSTNAME_BYTES];
|
QString _domainHostname;
|
||||||
char _domainIP[INET_ADDRSTRLEN];
|
QHostAddress _domainIP;
|
||||||
|
unsigned short _domainPort;
|
||||||
Node** _nodeBuckets[MAX_NUM_NODES / NODES_PER_BUCKET];
|
Node** _nodeBuckets[MAX_NUM_NODES / NODES_PER_BUCKET];
|
||||||
int _numNodes;
|
int _numNodes;
|
||||||
UDPSocket _nodeSocket;
|
UDPSocket _nodeSocket;
|
||||||
|
|
|
@ -58,6 +58,4 @@ const int MAX_PACKET_HEADER_BYTES = sizeof(PACKET_TYPE) + sizeof(PACKET_VERSION)
|
||||||
#define ADD_SCENE_COMMAND "add scene"
|
#define ADD_SCENE_COMMAND "add scene"
|
||||||
#define TEST_COMMAND "a message"
|
#define TEST_COMMAND "a message"
|
||||||
|
|
||||||
const unsigned short ASSIGNMENT_SERVER_PORT = 7007;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -275,7 +275,7 @@ int UDPSocket::send(sockaddr* destAddress, const void* data, size_t byteLength)
|
||||||
return sent_bytes;
|
return sent_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
int UDPSocket::send(char* destAddress, int destPort, const void* data, size_t byteLength) const {
|
int UDPSocket::send(const char* destAddress, int destPort, const void* data, size_t byteLength) const {
|
||||||
|
|
||||||
// change address and port on reusable global to passed variables
|
// change address and port on reusable global to passed variables
|
||||||
destSockaddr.sin_addr.s_addr = inet_addr(destAddress);
|
destSockaddr.sin_addr.s_addr = inet_addr(destAddress);
|
||||||
|
|
|
@ -31,7 +31,7 @@ public:
|
||||||
void setBlockingReceiveTimeoutInUsecs(int timeoutUsecs);
|
void setBlockingReceiveTimeoutInUsecs(int timeoutUsecs);
|
||||||
|
|
||||||
int send(sockaddr* destAddress, const void* data, size_t byteLength) const;
|
int send(sockaddr* destAddress, const void* data, size_t byteLength) const;
|
||||||
int send(char* destAddress, int destPort, const void* data, size_t byteLength) const;
|
int send(const char* destAddress, int destPort, const void* data, size_t byteLength) const;
|
||||||
|
|
||||||
bool receive(void* receivedData, ssize_t* receivedBytes) const;
|
bool receive(void* receivedData, ssize_t* receivedBytes) const;
|
||||||
bool receive(sockaddr* recvAddress, void* receivedData, ssize_t* receivedBytes) const;
|
bool receive(sockaddr* recvAddress, void* receivedData, ssize_t* receivedBytes) const;
|
||||||
|
|
Loading…
Reference in a new issue