Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First exchange of Vircadia protocol packets with the Vircadia Web SDK. #1259

Merged
merged 14 commits into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions assignment-client/src/AssignmentClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ AssignmentClient::AssignmentClient(Assignment::Type requestAssignmentType, QStri
_assignmentServerHostname = assignmentServerHostname;
}

_assignmentServerSocket = HifiSockAddr(_assignmentServerHostname, assignmentServerPort, true);
_assignmentServerSocket = HifiSockAddr(SocketType::UDP, _assignmentServerHostname, assignmentServerPort, true);
if (_assignmentServerSocket.isNull()) {
qCCritical(assignment_client) << "PAGE: Couldn't resolve domain server address" << _assignmentServerHostname;
}
Expand Down Expand Up @@ -110,7 +110,8 @@ AssignmentClient::AssignmentClient(Assignment::Type requestAssignmentType, QStri

// did we get an assignment-client monitor port?
if (assignmentMonitorPort > 0) {
_assignmentClientMonitorSocket = HifiSockAddr(DEFAULT_ASSIGNMENT_CLIENT_MONITOR_HOSTNAME, assignmentMonitorPort);
_assignmentClientMonitorSocket = HifiSockAddr(SocketType::UDP, DEFAULT_ASSIGNMENT_CLIENT_MONITOR_HOSTNAME,
assignmentMonitorPort);
_assignmentClientMonitorSocket.setObjectName("AssignmentClientMonitor");

qCDebug(assignment_client) << "Assignment-client monitor socket is" << _assignmentClientMonitorSocket;
Expand Down
2 changes: 1 addition & 1 deletion assignment-client/src/AssignmentClientMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ AssignmentClientMonitor::AssignmentClientMonitor(const unsigned int numAssignmen
// create a NodeList so we can receive stats from children
DependencyManager::registerInheritance<LimitedNodeList, NodeList>();
auto addressManager = DependencyManager::set<AddressManager>();
auto nodeList = DependencyManager::set<LimitedNodeList>(listenPort);
auto nodeList = DependencyManager::set<LimitedNodeList>(NodeType::Unassigned, listenPort);

auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
packetReceiver.registerListener(PacketType::AssignmentClientStatus,
Expand Down
11 changes: 5 additions & 6 deletions domain-server/src/DomainServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,6 @@ bool DomainServer::forwardMetaverseAPIRequest(HTTPConnection* connection,
DomainServer::DomainServer(int argc, char* argv[]) :
QCoreApplication(argc, argv),
_gatekeeper(this),
#ifdef WEBRTC_DATA_CHANNEL
_webrtcSignalingServer(QHostAddress::AnyIPv4, DEFAULT_DOMAIN_SERVER_WS_PORT, this),
#endif
_httpManager(QHostAddress::AnyIPv4, DOMAIN_SERVER_HTTP_PORT,
QString("%1/resources/web/").arg(QCoreApplication::applicationDirPath()), this)
{
Expand Down Expand Up @@ -734,10 +731,11 @@ void DomainServer::setupNodeListAndAssignments() {
// check for scripts the user wants to persist from their domain-server config
populateStaticScriptedAssignmentsFromSettings();

auto nodeList = DependencyManager::set<LimitedNodeList>(domainServerPort, domainServerDTLSPort);
auto nodeList = DependencyManager::set<LimitedNodeList>(NodeType::DomainServer, domainServerPort, domainServerDTLSPort);

// no matter the local port, save it to shared mem so that local assignment clients can ask what it is
nodeList->putLocalPortIntoSharedMemory(DOMAIN_SERVER_LOCAL_PORT_SMEM_KEY, this, nodeList->getSocketLocalPort());
nodeList->putLocalPortIntoSharedMemory(DOMAIN_SERVER_LOCAL_PORT_SMEM_KEY, this,
nodeList->getSocketLocalPort(SocketType::UDP));

// store our local http ports in shared memory
quint16 localHttpPort = DOMAIN_SERVER_HTTP_PORT;
Expand Down Expand Up @@ -3044,6 +3042,7 @@ ReplicationServerInfo serverInformationFromSettings(QVariantMap serverMap, Repli

// read the address and port and construct a HifiSockAddr from them
serverInfo.sockAddr = {
SocketType::UDP,
serverMap[REPLICATION_SERVER_ADDRESS].toString(),
(quint16) serverMap[REPLICATION_SERVER_PORT].toString().toInt()
};
Expand Down Expand Up @@ -3624,7 +3623,7 @@ void DomainServer::randomizeICEServerAddress(bool shouldTriggerHostLookup) {
indexToTry = distribution(generator);
}

_iceServerSocket = HifiSockAddr { candidateICEAddresses[indexToTry], ICE_SERVER_DEFAULT_PORT };
_iceServerSocket = HifiSockAddr { SocketType::UDP, candidateICEAddresses[indexToTry], ICE_SERVER_DEFAULT_PORT };
qCInfo(domain_server_ice) << "Set candidate ice-server socket to" << _iceServerSocket;

// clear our number of hearbeat denials, this should be re-set on ice-server change
Expand Down
9 changes: 1 addition & 8 deletions domain-server/src/DomainServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
#include <Assignment.h>
#include <HTTPSConnection.h>
#include <LimitedNodeList.h>
#include <shared/WebRTC.h>
#if defined(WEBRTC_DATA_CHANNEL)
#include <webrtc/WebRTCSignalingServer.h>
#endif

#include "AssetsBackupHandler.h"
#include "DomainGatekeeper.h"
Expand Down Expand Up @@ -145,6 +141,7 @@ private slots:
void updateReplicatedNodes();
void updateDownstreamNodes();
void updateUpstreamNodes();

void initializeExporter();
void initializeMetadataExporter();

Expand Down Expand Up @@ -315,10 +312,6 @@ private slots:
std::unordered_map<int, std::unique_ptr<QTemporaryFile>> _pendingContentFiles;

QThread _assetClientThread;

#ifdef WEBRTC_DATA_CHANNEL
WebRTCSignalingServer _webrtcSignalingServer;
#endif
};


Expand Down
2 changes: 1 addition & 1 deletion ice-server/src/IceServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ IceServer::IceServer(int argc, char* argv[]) :
{
// start the ice-server socket
qDebug() << "ice-server socket is listening on" << ICE_SERVER_DEFAULT_PORT;
_serverSocket.bind(QHostAddress::AnyIPv4, ICE_SERVER_DEFAULT_PORT);
_serverSocket.bind(SocketType::UDP, QHostAddress::AnyIPv4, ICE_SERVER_DEFAULT_PORT);

// set processPacket as the verified packet callback for the udt::Socket
_serverSocket.setPacketHandler([this](std::unique_ptr<udt::Packet> packet) { processPacket(std::move(packet)); });
Expand Down
4 changes: 2 additions & 2 deletions interface/src/ui/PreferencesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,15 +551,15 @@ void setupPreferences() {
auto getter = [nodeListWeak] {
auto nodeList = nodeListWeak.lock();
if (nodeList) {
return static_cast<int>(nodeList->getSocketLocalPort());
return static_cast<int>(nodeList->getSocketLocalPort(SocketType::UDP));
} else {
return -1;
}
};
auto setter = [nodeListWeak](int preset) {
auto nodeList = nodeListWeak.lock();
if (nodeList) {
nodeList->setSocketLocalPort(static_cast<quint16>(preset));
nodeList->setSocketLocalPort(SocketType::UDP, static_cast<quint16>(preset));
}
};
auto preference = new IntSpinnerPreference(NETWORKING, "Listening Port", getter, setter);
Expand Down
3 changes: 2 additions & 1 deletion libraries/networking/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ endif ()

if (WIN32)
# we need ws2_32.lib on windows, but it's static so we don't bubble it up
target_link_libraries(${TARGET_NAME} ws2_32.lib)
# Libraries needed for WebRTC: security.log winmm.lib
target_link_libraries(${TARGET_NAME} ws2_32.lib security.lib winmm.lib)
elseif(APPLE)
# IOKit is needed for getting machine fingerprint
find_library(FRAMEWORK_IOKIT IOKit)
Expand Down
10 changes: 5 additions & 5 deletions libraries/networking/src/AddressManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ public slots:
* <code>"127.0.0.1"</code> or <code>"localhost"</code>), a <code>file:///</code> address, a domain name, a named path
* on a domain (starts with <code>"/"</code>), a position or position and orientation, or a user (starts with
* <code>"@"</code>).
* @param {boolean} [fromSuggestions=false] - Set to <code>true</code> if the address is obtained from the "Goto" dialog.
* Helps ensure that user's location history is correctly maintained.
* @param {boolean} [fromSuggestions=false] - Set to <code>true</code> if the address is obtained from the "Explore" app.
* Helps ensure that the user's location history is correctly maintained.
ctrlaltdavid marked this conversation as resolved.
Show resolved Hide resolved
*/
void handleLookupString(const QString& lookupString, bool fromSuggestions = false);

Expand Down Expand Up @@ -390,10 +390,10 @@ public slots:
void lookupResultIsNotFound();

/*@jsdoc
* Triggered when a request is made to go to an IP address.
* Triggered when a request is made to go to a URL or IP address.
* @function location.possibleDomainChangeRequired
* @param {Url} domainURL - URL for domain
* @param {Uuid} domainID - The UUID of the domain to go to.
* @param {string} domainURL - The URL of the domain.
* @param {Uuid} domainID - The UUID of the domain to go to. May be "{@link Uuid|Uuid.NULL} if not yet known.
* @returns {Signal}
*/
// No example because this function isn't typically used in scripts.
Expand Down
7 changes: 4 additions & 3 deletions libraries/networking/src/DomainHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

DomainHandler::DomainHandler(QObject* parent) :
QObject(parent),
_sockAddr(HifiSockAddr(QHostAddress::Null, DEFAULT_DOMAIN_SERVER_PORT)),
_sockAddr(HifiSockAddr(SocketType::UDP, QHostAddress::Null, DEFAULT_DOMAIN_SERVER_PORT)),
_icePeer(this),
_settingsTimer(this),
_apiRefreshTimer(this)
Expand Down Expand Up @@ -282,7 +282,8 @@ void DomainHandler::setIceServerHostnameAndID(const QString& iceServerHostname,

HifiSockAddr* replaceableSockAddr = &_iceServerSockAddr;
replaceableSockAddr->~HifiSockAddr();
replaceableSockAddr = new (replaceableSockAddr) HifiSockAddr(iceServerHostname, ICE_SERVER_DEFAULT_PORT);
replaceableSockAddr = new (replaceableSockAddr) HifiSockAddr(SocketType::UDP, iceServerHostname,
ICE_SERVER_DEFAULT_PORT);
_iceServerSockAddr.setObjectName("IceServer");

auto nodeList = DependencyManager::get<NodeList>();
Expand Down Expand Up @@ -367,7 +368,7 @@ void DomainHandler::setIsConnected(bool isConnected) {
emit connectedToDomain(_domainURL);

// FIXME: Reinstate the requestDomainSettings() call here in version 2021.2.0 instead of having it in
// NodeList::processDomainServerList().
// NodeList::processDomainList().
/*
if (_domainURL.scheme() == URL_SCHEME_HIFI && !_domainURL.host().isEmpty()) {
// we've connected to new domain - time to ask it for global settings
Expand Down
40 changes: 22 additions & 18 deletions libraries/networking/src/HifiSockAddr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,22 @@
int hifiSockAddrMetaTypeId = qRegisterMetaType<HifiSockAddr>();

HifiSockAddr::HifiSockAddr() :
_socketType(SocketType::Unknown),
_address(),
_port(0)
{

}

HifiSockAddr::HifiSockAddr(const QHostAddress& address, quint16 port) :
HifiSockAddr::HifiSockAddr(SocketType socketType, const QHostAddress& address, quint16 port) :
_socketType(socketType),
_address(address),
_port(port)
{

}

HifiSockAddr::HifiSockAddr(const HifiSockAddr& otherSockAddr) :
QObject(),
_socketType(otherSockAddr._socketType),
_address(otherSockAddr._address),
_port(otherSockAddr._port)
{
Expand All @@ -50,12 +51,14 @@ HifiSockAddr::HifiSockAddr(const HifiSockAddr& otherSockAddr) :

HifiSockAddr& HifiSockAddr::operator=(const HifiSockAddr& rhsSockAddr) {
setObjectName(rhsSockAddr.objectName());
_socketType = rhsSockAddr._socketType;
_address = rhsSockAddr._address;
_port = rhsSockAddr._port;
return *this;
}

HifiSockAddr::HifiSockAddr(const QString& hostname, quint16 hostOrderPort, bool shouldBlockForLookup) :
HifiSockAddr::HifiSockAddr(SocketType socketType, const QString& hostname, quint16 hostOrderPort, bool shouldBlockForLookup) :
_socketType(socketType),
_address(hostname),
_port(hostOrderPort)
{
Expand All @@ -73,19 +76,10 @@ HifiSockAddr::HifiSockAddr(const QString& hostname, quint16 hostOrderPort, bool
}
}

HifiSockAddr::HifiSockAddr(const sockaddr* sockaddr) {
_address = QHostAddress(sockaddr);

if (sockaddr->sa_family == AF_INET) {
_port = ntohs(reinterpret_cast<const sockaddr_in*>(sockaddr)->sin_port);
} else {
_port = ntohs(reinterpret_cast<const sockaddr_in6*>(sockaddr)->sin6_port);
}
}

void HifiSockAddr::swap(HifiSockAddr& otherSockAddr) {
using std::swap;


swap(_socketType, otherSockAddr._socketType);
swap(_address, otherSockAddr._address);
swap(_port, otherSockAddr._port);

Expand All @@ -96,7 +90,7 @@ void HifiSockAddr::swap(HifiSockAddr& otherSockAddr) {
}

bool HifiSockAddr::operator==(const HifiSockAddr& rhsSockAddr) const {
return _address == rhsSockAddr._address && _port == rhsSockAddr._port;
return _socketType == rhsSockAddr._socketType && _address == rhsSockAddr._address && _port == rhsSockAddr._port;
}

void HifiSockAddr::handleLookupResult(const QHostInfo& hostInfo) {
Expand All @@ -118,7 +112,7 @@ void HifiSockAddr::handleLookupResult(const QHostInfo& hostInfo) {
}

QString HifiSockAddr::toString() const {
return _address.toString() + ":" + QString::number(_port);
return socketTypeToString(_socketType) + " " + _address.toString() + ":" + QString::number(_port);
}

bool HifiSockAddr::hasPrivateAddress() const {
Expand All @@ -134,17 +128,27 @@ bool HifiSockAddr::hasPrivateAddress() const {
}

QDebug operator<<(QDebug debug, const HifiSockAddr& sockAddr) {
debug.nospace() << sockAddr._address.toString().toLocal8Bit().constData() << ":" << sockAddr._port;
debug.nospace() << socketTypeToString(sockAddr._socketType).toLocal8Bit().constData() << " "
<< sockAddr._address.toString().toLocal8Bit().constData() << ":" << sockAddr._port;
return debug.space();
}

QDataStream& operator<<(QDataStream& dataStream, const HifiSockAddr& sockAddr) {
// Don't include socketType because it can be implied from the type of connection used.
// WEBRTC TODO: Reconsider this.
dataStream << sockAddr._address << sockAddr._port;
return dataStream;
}

QDataStream& operator>>(QDataStream& dataStream, HifiSockAddr& sockAddr) {
// Don't include socketType because it can be implied from the type of connection used.
// WEBRTC TODO: Reconsider this.
dataStream >> sockAddr._address >> sockAddr._port;

// Set default for non-WebRTC code.
// WEBRTC TODO: Reconsider this.
sockAddr.setSocketType(SocketType::UDP);

return dataStream;
}

Expand Down
14 changes: 11 additions & 3 deletions libraries/networking/src/HifiSockAddr.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ struct sockaddr;

#include <QtNetwork/QHostInfo>

#include "SocketType.h"


class HifiSockAddr : public QObject {
Q_OBJECT
public:
HifiSockAddr();
HifiSockAddr(const QHostAddress& address, quint16 port);
HifiSockAddr(SocketType socketType, const QHostAddress& address, quint16 port);
HifiSockAddr(const HifiSockAddr& otherSockAddr);
HifiSockAddr(const QString& hostname, quint16 hostOrderPort, bool shouldBlockForLookup = false);
HifiSockAddr(const sockaddr* sockaddr);
HifiSockAddr(SocketType socketType, const QString& hostname, quint16 hostOrderPort, bool shouldBlockForLookup = false);

bool isNull() const { return _address.isNull() && _port == 0; }
void clear() { _address.clear(); _port = 0;}
Expand All @@ -37,6 +39,10 @@ class HifiSockAddr : public QObject {
bool operator==(const HifiSockAddr& rhsSockAddr) const;
bool operator!=(const HifiSockAddr& rhsSockAddr) const { return !(*this == rhsSockAddr); }

SocketType getSocketType() const { return _socketType; }
SocketType* getSocketTypePointer() { return &_socketType; }
void setSocketType(const SocketType socketType) { _socketType = socketType; }

const QHostAddress& getAddress() const { return _address; }
QHostAddress* getAddressPointer() { return &_address; }
void setAddress(const QHostAddress& address) { _address = address; }
Expand All @@ -53,6 +59,7 @@ class HifiSockAddr : public QObject {
bool hasPrivateAddress() const; // checks if the address behind this sock addr is private per RFC 1918

friend QDebug operator<<(QDebug debug, const HifiSockAddr& sockAddr);

friend QDataStream& operator<<(QDataStream& dataStream, const HifiSockAddr& sockAddr);
friend QDataStream& operator>>(QDataStream& dataStream, HifiSockAddr& sockAddr);

Expand All @@ -62,6 +69,7 @@ private slots:
void lookupCompleted();
void lookupFailed();
private:
SocketType _socketType { SocketType::Unknown };
QHostAddress _address;
quint16 _port;
};
Expand Down
Loading