mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 10:37:35 +02:00
repair usage of DS as STUN server
This commit is contained in:
parent
113ef1b386
commit
330eff72ce
9 changed files with 24 additions and 20 deletions
|
@ -95,7 +95,7 @@ void AssignmentClient::readPendingDatagrams() {
|
||||||
// start the deployed assignment
|
// start the deployed assignment
|
||||||
QThread *workerThread = new QThread(this);
|
QThread *workerThread = new QThread(this);
|
||||||
|
|
||||||
connect(workerThread, SIGNAL(started()), _currentAssignment, SLOT(run()));
|
connect(workerThread, SIGNAL(started()), _currentAssignment, SLOT(setup()));
|
||||||
|
|
||||||
connect(_currentAssignment, SIGNAL(finished()), this, SLOT(assignmentCompleted()));
|
connect(_currentAssignment, SIGNAL(finished()), this, SLOT(assignmentCompleted()));
|
||||||
connect(_currentAssignment, SIGNAL(finished()), workerThread, SLOT(quit()));
|
connect(_currentAssignment, SIGNAL(finished()), workerThread, SLOT(quit()));
|
||||||
|
|
|
@ -293,7 +293,7 @@ void AudioMixer::sendClientMixes() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AudioMixer::run() {
|
void AudioMixer::setup() {
|
||||||
// change the logging target name while this is running
|
// change the logging target name while this is running
|
||||||
Logging::setTargetName(AUDIO_MIXER_LOGGING_TARGET_NAME);
|
Logging::setTargetName(AUDIO_MIXER_LOGGING_TARGET_NAME);
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,8 @@ class AudioMixer : public Assignment {
|
||||||
public:
|
public:
|
||||||
AudioMixer(const unsigned char* dataBuffer, int numBytes);
|
AudioMixer(const unsigned char* dataBuffer, int numBytes);
|
||||||
public slots:
|
public slots:
|
||||||
/// runs the audio mixer
|
/// performs setup for the audio mixer
|
||||||
void run();
|
void setup();
|
||||||
|
|
||||||
void processDatagram(const QByteArray& dataByteArray, const HifiSockAddr& senderSockAddr);
|
void processDatagram(const QByteArray& dataByteArray, const HifiSockAddr& senderSockAddr);
|
||||||
signals:
|
signals:
|
||||||
|
|
|
@ -628,16 +628,16 @@ int DomainServer::run() {
|
||||||
int numBytesPrivateSocket = HifiSockAddr::unpackSockAddr(packetData + packetIndex, nodePublicAddress);
|
int numBytesPrivateSocket = HifiSockAddr::unpackSockAddr(packetData + packetIndex, nodePublicAddress);
|
||||||
packetIndex += numBytesPrivateSocket;
|
packetIndex += numBytesPrivateSocket;
|
||||||
|
|
||||||
if (nodePublicAddress.getAddress().isNull() == 0) {
|
if (nodePublicAddress.getAddress().isNull()) {
|
||||||
// this node wants to use us its STUN server
|
// this node wants to use us its STUN server
|
||||||
// so set the node public address to whatever we perceive the public address to be
|
// so set the node public address to whatever we perceive the public address to be
|
||||||
|
|
||||||
nodePublicAddress.setAddress(senderAddress);
|
|
||||||
|
|
||||||
// if the sender is on our box then leave its public address to 0 so that
|
// if the sender is on our box then leave its public address to 0 so that
|
||||||
// other users attempt to reach it on the same address they have for the domain-server
|
// other users attempt to reach it on the same address they have for the domain-server
|
||||||
if (senderAddress.isLoopback()) {
|
if (senderAddress.isLoopback()) {
|
||||||
nodePublicAddress.setAddress(QHostAddress());
|
nodePublicAddress.setAddress(QHostAddress());
|
||||||
|
} else {
|
||||||
|
nodePublicAddress.setAddress(senderAddress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ void PairingHandler::sendPairRequest() {
|
||||||
NodeList* nodeList = NodeList::getInstance();
|
NodeList* nodeList = NodeList::getInstance();
|
||||||
|
|
||||||
// use the getLocalAddress helper to get this client's listening address
|
// use the getLocalAddress helper to get this client's listening address
|
||||||
quint32 localAddress = getLocalAddress();
|
quint32 localAddress = htonl(getHostOrderLocalAddress());
|
||||||
|
|
||||||
char pairPacket[24] = {};
|
char pairPacket[24] = {};
|
||||||
sprintf(pairPacket, "Find %d.%d.%d.%d:%hu",
|
sprintf(pairPacket, "Find %d.%d.%d.%d:%hu",
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include <QtNetwork/QNetworkInterface>
|
#include <QtNetwork/QNetworkInterface>
|
||||||
|
|
||||||
HifiSockAddr::HifiSockAddr() :
|
HifiSockAddr::HifiSockAddr() :
|
||||||
_address(QHostAddress::Null),
|
_address(),
|
||||||
_port(0)
|
_port(0)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -55,15 +55,16 @@ void HifiSockAddr::swap(HifiSockAddr& otherSockAddr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int HifiSockAddr::packSockAddr(unsigned char* packetData, const HifiSockAddr& packSockAddr) {
|
int HifiSockAddr::packSockAddr(unsigned char* packetData, const HifiSockAddr& packSockAddr) {
|
||||||
unsigned int addressToPack = packSockAddr._address.toIPv4Address();
|
quint32 addressToPack = packSockAddr._address.isNull() ? 0 : packSockAddr._address.toIPv4Address();
|
||||||
memcpy(packetData, &addressToPack, sizeof(packSockAddr._address.toIPv4Address()));
|
memcpy(packetData, &addressToPack, sizeof(addressToPack));
|
||||||
memcpy(packetData, &packSockAddr._port, sizeof(packSockAddr._port));
|
memcpy(packetData + sizeof(addressToPack), &packSockAddr._port, sizeof(packSockAddr._port));
|
||||||
|
|
||||||
return sizeof(addressToPack) + sizeof(packSockAddr._port);
|
return sizeof(addressToPack) + sizeof(packSockAddr._port);
|
||||||
}
|
}
|
||||||
|
|
||||||
int HifiSockAddr::unpackSockAddr(const unsigned char* packetData, HifiSockAddr& unpackDestSockAddr) {
|
int HifiSockAddr::unpackSockAddr(const unsigned char* packetData, HifiSockAddr& unpackDestSockAddr) {
|
||||||
unpackDestSockAddr._address = QHostAddress(*((quint32*) packetData));
|
quint32* address = (quint32*) packetData;
|
||||||
|
unpackDestSockAddr._address = *address == 0 ? QHostAddress() : QHostAddress(*address);
|
||||||
unpackDestSockAddr._port = *((quint16*) (packetData + sizeof(quint32)));
|
unpackDestSockAddr._port = *((quint16*) (packetData + sizeof(quint32)));
|
||||||
|
|
||||||
return sizeof(quint32) + sizeof(quint16);
|
return sizeof(quint32) + sizeof(quint16);
|
||||||
|
@ -74,11 +75,11 @@ bool HifiSockAddr::operator==(const HifiSockAddr &rhsSockAddr) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
QDebug operator<<(QDebug debug, const HifiSockAddr &hifiSockAddr) {
|
QDebug operator<<(QDebug debug, const HifiSockAddr &hifiSockAddr) {
|
||||||
debug.nospace() << hifiSockAddr._address.toString() << ":" << hifiSockAddr._port;
|
debug.nospace() << hifiSockAddr._address.toString().toLocal8Bit().constData() << ":" << hifiSockAddr._port;
|
||||||
return debug;
|
return debug;
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 getLocalAddress() {
|
quint32 getHostOrderLocalAddress() {
|
||||||
|
|
||||||
static int localAddress = 0;
|
static int localAddress = 0;
|
||||||
|
|
||||||
|
@ -95,7 +96,7 @@ quint32 getLocalAddress() {
|
||||||
qDebug("Node's local address is %s\n", entry.ip().toString().toLocal8Bit().constData());
|
qDebug("Node's local address is %s\n", entry.ip().toString().toLocal8Bit().constData());
|
||||||
|
|
||||||
// set our localAddress and break out
|
// set our localAddress and break out
|
||||||
localAddress = htonl(entry.ip().toIPv4Address());
|
localAddress = entry.ip().toIPv4Address();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ private:
|
||||||
quint16 _port;
|
quint16 _port;
|
||||||
};
|
};
|
||||||
|
|
||||||
quint32 getLocalAddress();
|
quint32 getHostOrderLocalAddress();
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(HifiSockAddr)
|
Q_DECLARE_METATYPE(HifiSockAddr)
|
||||||
|
|
||||||
|
|
|
@ -136,6 +136,6 @@ float Node::getAverageKilobitsPerSecond() {
|
||||||
QDebug operator<<(QDebug debug, const Node &node) {
|
QDebug operator<<(QDebug debug, const Node &node) {
|
||||||
debug.nospace() << node.getTypeName() << " (" << node.getType() << ")";
|
debug.nospace() << node.getTypeName() << " (" << node.getType() << ")";
|
||||||
debug << " " << node.getUUID().toString().toLocal8Bit().constData() << " ";
|
debug << " " << node.getUUID().toString().toLocal8Bit().constData() << " ";
|
||||||
debug.nospace() << node.getLocalSocket() << "/" << node.getPublicSocket();
|
debug.nospace() << node.getPublicSocket() << "/" << node.getLocalSocket();
|
||||||
return debug.nospace();
|
return debug.nospace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,6 +76,7 @@ NodeList::NodeList(char newOwnerType, unsigned short int newSocketListenPort) :
|
||||||
_stunRequestsSinceSuccess(0)
|
_stunRequestsSinceSuccess(0)
|
||||||
{
|
{
|
||||||
_nodeSocket.bind(QHostAddress::AnyIPv4, newSocketListenPort);
|
_nodeSocket.bind(QHostAddress::AnyIPv4, newSocketListenPort);
|
||||||
|
qDebug() << "NodeList socket is listening on" << _nodeSocket.localPort() << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeList::~NodeList() {
|
NodeList::~NodeList() {
|
||||||
|
@ -361,7 +362,8 @@ void NodeList::sendSTUNRequest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset the public address and port
|
// reset the public address and port
|
||||||
_publicSockAddr = HifiSockAddr();
|
// use 0 so the DS knows to act as out STUN server
|
||||||
|
_publicSockAddr = HifiSockAddr(QHostAddress(), _nodeSocket.localPort());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -539,7 +541,8 @@ void NodeList::sendDomainServerCheckIn() {
|
||||||
|
|
||||||
// pack our local address to send to domain-server
|
// pack our local address to send to domain-server
|
||||||
packetPosition += HifiSockAddr::packSockAddr(checkInPacket + (packetPosition - checkInPacket),
|
packetPosition += HifiSockAddr::packSockAddr(checkInPacket + (packetPosition - checkInPacket),
|
||||||
HifiSockAddr(_nodeSocket.localAddress(), _nodeSocket.localPort()));
|
HifiSockAddr(QHostAddress(getHostOrderLocalAddress()),
|
||||||
|
_nodeSocket.localPort()));
|
||||||
|
|
||||||
// add the number of bytes for node types of interest
|
// add the number of bytes for node types of interest
|
||||||
*(packetPosition++) = numBytesNodesOfInterest;
|
*(packetPosition++) = numBytesNodesOfInterest;
|
||||||
|
|
Loading…
Reference in a new issue