mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 00:36:47 +02:00
handle domain connection via ICE from NodeList
This commit is contained in:
parent
c7aaf0ce4a
commit
63877b0756
7 changed files with 46 additions and 15 deletions
|
@ -983,8 +983,10 @@ void DomainServer::updateNetworkingInfoWithDataServer(const QString& newSetting,
|
||||||
domainUpdateJSON.toUtf8());
|
domainUpdateJSON.toUtf8());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const HifiSockAddr ICE_SERVER_SOCK_ADDR = HifiSockAddr(QHostAddress::LocalHost, ICE_SERVER_DEFAULT_PORT);
|
||||||
|
|
||||||
void DomainServer::sendHearbeatToIceServer() {
|
void DomainServer::sendHearbeatToIceServer() {
|
||||||
LimitedNodeList::getInstance()->sendHeartbeatToIceServer();
|
LimitedNodeList::getInstance()->sendHeartbeatToIceServer(ICE_SERVER_SOCK_ADDR);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DomainServer::processDatagram(const QByteArray& receivedPacket, const HifiSockAddr& senderSockAddr) {
|
void DomainServer::processDatagram(const QByteArray& receivedPacket, const HifiSockAddr& senderSockAddr) {
|
||||||
|
@ -1028,7 +1030,7 @@ void DomainServer::processDatagram(const QByteArray& receivedPacket, const HifiS
|
||||||
case PacketTypeStunResponse:
|
case PacketTypeStunResponse:
|
||||||
nodeList->processSTUNResponse(receivedPacket);
|
nodeList->processSTUNResponse(receivedPacket);
|
||||||
break;
|
break;
|
||||||
case PacketTypePing: {
|
case PacketTypeUnverifiedPing: {
|
||||||
QByteArray pingReplyPacket = nodeList->constructPingReplyPacket(receivedPacket);
|
QByteArray pingReplyPacket = nodeList->constructPingReplyPacket(receivedPacket);
|
||||||
nodeList->writeUnverifiedDatagram(pingReplyPacket, senderSockAddr);
|
nodeList->writeUnverifiedDatagram(pingReplyPacket, senderSockAddr);
|
||||||
|
|
||||||
|
|
|
@ -138,11 +138,20 @@ void DomainHandler::setIceServerHostnameAndID(const QString& iceServerHostname,
|
||||||
setUUID(id);
|
setUUID(id);
|
||||||
_iceServerSockAddr = HifiSockAddr(iceServerHostname, ICE_SERVER_DEFAULT_PORT);
|
_iceServerSockAddr = HifiSockAddr(iceServerHostname, ICE_SERVER_DEFAULT_PORT);
|
||||||
|
|
||||||
qDebug() << "Domain ID changed to" << uuidStringWithoutCurlyBraces(_uuid)
|
qDebug() << "ICE required to connect to domain via ice server at" << iceServerHostname;
|
||||||
<< "- ICE required via ice server at" << iceServerHostname;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DomainHandler::activateICELocalSocket() {
|
||||||
|
_sockAddr = _icePeer.getLocalSocket();
|
||||||
|
_hostname = _sockAddr.getAddress().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DomainHandler::activateICEPublicSocket() {
|
||||||
|
_sockAddr = _icePeer.getPublicSocket();
|
||||||
|
_hostname = _sockAddr.getAddress().toString();
|
||||||
|
}
|
||||||
|
|
||||||
void DomainHandler::completedHostnameLookup(const QHostInfo& hostInfo) {
|
void DomainHandler::completedHostnameLookup(const QHostInfo& hostInfo) {
|
||||||
for (int i = 0; i < hostInfo.addresses().size(); i++) {
|
for (int i = 0; i < hostInfo.addresses().size(); i++) {
|
||||||
if (hostInfo.addresses()[i].protocol() == QAbstractSocket::IPv4Protocol) {
|
if (hostInfo.addresses()[i].protocol() == QAbstractSocket::IPv4Protocol) {
|
||||||
|
|
|
@ -58,6 +58,8 @@ public:
|
||||||
bool requiresICE() const { return !_iceServerSockAddr.isNull(); }
|
bool requiresICE() const { return !_iceServerSockAddr.isNull(); }
|
||||||
const HifiSockAddr& getICEServerSockAddr() const { return _iceServerSockAddr; }
|
const HifiSockAddr& getICEServerSockAddr() const { return _iceServerSockAddr; }
|
||||||
const NetworkPeer& getICEPeer() const { return _icePeer; }
|
const NetworkPeer& getICEPeer() const { return _icePeer; }
|
||||||
|
void activateICELocalSocket();
|
||||||
|
void activateICEPublicSocket();
|
||||||
|
|
||||||
bool isConnected() const { return _isConnected; }
|
bool isConnected() const { return _isConnected; }
|
||||||
void setIsConnected(bool isConnected);
|
void setIsConnected(bool isConnected);
|
||||||
|
|
|
@ -459,8 +459,8 @@ unsigned LimitedNodeList::broadcastToNodes(const QByteArray& packet, const NodeS
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray LimitedNodeList::constructPingPacket(PingType_t pingType) {
|
QByteArray LimitedNodeList::constructPingPacket(PingType_t pingType, bool isVerified) {
|
||||||
QByteArray pingPacket = byteArrayWithPopulatedHeader(PacketTypePing);
|
QByteArray pingPacket = byteArrayWithPopulatedHeader(isVerified ? PacketTypePing : PacketTypeUnverifiedPing);
|
||||||
|
|
||||||
QDataStream packetStream(&pingPacket, QIODevice::Append);
|
QDataStream packetStream(&pingPacket, QIODevice::Append);
|
||||||
|
|
||||||
|
@ -480,7 +480,10 @@ QByteArray LimitedNodeList::constructPingReplyPacket(const QByteArray& pingPacke
|
||||||
quint64 timeFromOriginalPing;
|
quint64 timeFromOriginalPing;
|
||||||
pingPacketStream >> timeFromOriginalPing;
|
pingPacketStream >> timeFromOriginalPing;
|
||||||
|
|
||||||
QByteArray replyPacket = byteArrayWithPopulatedHeader(PacketTypePingReply);
|
PacketType replyType = (packetTypeForPacket(pingPacket) == PacketTypePing)
|
||||||
|
? PacketTypePingReply : PacketTypeUnverifiedPingReply;
|
||||||
|
|
||||||
|
QByteArray replyPacket = byteArrayWithPopulatedHeader(replyType);
|
||||||
QDataStream packetStream(&replyPacket, QIODevice::Append);
|
QDataStream packetStream(&replyPacket, QIODevice::Append);
|
||||||
|
|
||||||
packetStream << typeFromOriginalPing << timeFromOriginalPing << usecTimestampNow();
|
packetStream << typeFromOriginalPing << timeFromOriginalPing << usecTimestampNow();
|
||||||
|
|
|
@ -112,7 +112,7 @@ public:
|
||||||
void getPacketStats(float &packetsPerSecond, float &bytesPerSecond);
|
void getPacketStats(float &packetsPerSecond, float &bytesPerSecond);
|
||||||
void resetPacketStats();
|
void resetPacketStats();
|
||||||
|
|
||||||
QByteArray constructPingPacket(PingType_t pingType = PingType::Agnostic);
|
QByteArray constructPingPacket(PingType_t pingType = PingType::Agnostic, bool isVerified = true);
|
||||||
QByteArray constructPingReplyPacket(const QByteArray& pingPacket);
|
QByteArray constructPingReplyPacket(const QByteArray& pingPacket);
|
||||||
|
|
||||||
virtual void sendSTUNRequest();
|
virtual void sendSTUNRequest();
|
||||||
|
|
|
@ -161,12 +161,24 @@ void NodeList::processNodeData(const HifiSockAddr& senderSockAddr, const QByteAr
|
||||||
|
|
||||||
// set the ping time for this node for stat collection
|
// set the ping time for this node for stat collection
|
||||||
timePingReply(packet, sendingNode);
|
timePingReply(packet, sendingNode);
|
||||||
} else if (uuidFromPacketHeader(packet) == _domainHandler.getUUID()) {
|
|
||||||
qDebug() << "RECEIVED A REPLY FROM DOMAIN";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case PacketTypeUnverifiedPingReply: {
|
||||||
|
qDebug() << "Received reply from domain-server on" << senderSockAddr;
|
||||||
|
|
||||||
|
// for now we're unsafely assuming this came back from the domain
|
||||||
|
if (senderSockAddr == _domainHandler.getICEPeer().getLocalSocket()) {
|
||||||
|
qDebug() << "Connecting to domain using local socket";
|
||||||
|
_domainHandler.activateICELocalSocket();
|
||||||
|
} else if (senderSockAddr == _domainHandler.getICEPeer().getPublicSocket()) {
|
||||||
|
qDebug() << "Conecting to domain using public socket";
|
||||||
|
_domainHandler.activateICEPublicSocket();
|
||||||
|
} else {
|
||||||
|
qDebug() << "Reply does not match either local or public socket for domain. Will not connect.";
|
||||||
|
}
|
||||||
|
}
|
||||||
case PacketTypeStunResponse: {
|
case PacketTypeStunResponse: {
|
||||||
// a STUN packet begins with 00, we've checked the second zero with packetVersionMatch
|
// a STUN packet begins with 00, we've checked the second zero with packetVersionMatch
|
||||||
// pass it along so it can be processed into our public address and port
|
// pass it along so it can be processed into our public address and port
|
||||||
|
@ -251,7 +263,7 @@ void NodeList::sendDomainServerCheckIn() {
|
||||||
// we don't know our public socket and we need to send it to the domain server
|
// we don't know our public socket and we need to send it to the domain server
|
||||||
// send a STUN request to figure it out
|
// send a STUN request to figure it out
|
||||||
sendSTUNRequest();
|
sendSTUNRequest();
|
||||||
} else if (!_domainHandler.isConnected() && _domainHandler.requiresICE()) {
|
} else if (_domainHandler.getIP().isNull() && _domainHandler.requiresICE()) {
|
||||||
handleICEConnectionToDomainServer();
|
handleICEConnectionToDomainServer();
|
||||||
} else if (!_domainHandler.getIP().isNull()) {
|
} else if (!_domainHandler.getIP().isNull()) {
|
||||||
|
|
||||||
|
@ -319,10 +331,10 @@ void NodeList::handleICEConnectionToDomainServer() {
|
||||||
<< uuidStringWithoutCurlyBraces(_domainHandler.getUUID());
|
<< uuidStringWithoutCurlyBraces(_domainHandler.getUUID());
|
||||||
|
|
||||||
// send the ping packet to the local and public sockets for this node
|
// send the ping packet to the local and public sockets for this node
|
||||||
QByteArray localPingPacket = constructPingPacket(PingType::Local);
|
QByteArray localPingPacket = constructPingPacket(PingType::Local, false);
|
||||||
writeDatagram(localPingPacket, _domainHandler.getICEPeer().getLocalSocket(), iceUUID);
|
writeDatagram(localPingPacket, _domainHandler.getICEPeer().getLocalSocket(), iceUUID);
|
||||||
|
|
||||||
QByteArray publicPingPacket = constructPingPacket(PingType::Public);
|
QByteArray publicPingPacket = constructPingPacket(PingType::Public, false);
|
||||||
writeDatagram(publicPingPacket, _domainHandler.getICEPeer().getPublicSocket(), iceUUID);
|
writeDatagram(publicPingPacket, _domainHandler.getICEPeer().getPublicSocket(), iceUUID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,9 @@ enum PacketType {
|
||||||
PacketTypeEntityEditNack, // 48
|
PacketTypeEntityEditNack, // 48
|
||||||
PacketTypeSignedTransactionPayment,
|
PacketTypeSignedTransactionPayment,
|
||||||
PacketTypeIceServerHeartbeat,
|
PacketTypeIceServerHeartbeat,
|
||||||
PacketTypeIceServerHeartbeatResponse
|
PacketTypeIceServerHeartbeatResponse,
|
||||||
|
PacketTypeUnverifiedPing,
|
||||||
|
PacketTypeUnverifiedPingReply
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef char PacketVersion;
|
typedef char PacketVersion;
|
||||||
|
@ -83,7 +85,8 @@ const QSet<PacketType> NON_VERIFIED_PACKETS = QSet<PacketType>()
|
||||||
<< PacketTypeCreateAssignment << PacketTypeRequestAssignment << PacketTypeStunResponse
|
<< PacketTypeCreateAssignment << PacketTypeRequestAssignment << PacketTypeStunResponse
|
||||||
<< PacketTypeNodeJsonStats << PacketTypeVoxelQuery << PacketTypeParticleQuery << PacketTypeEntityQuery
|
<< PacketTypeNodeJsonStats << PacketTypeVoxelQuery << PacketTypeParticleQuery << PacketTypeEntityQuery
|
||||||
<< PacketTypeOctreeDataNack << PacketTypeVoxelEditNack << PacketTypeParticleEditNack << PacketTypeEntityEditNack
|
<< PacketTypeOctreeDataNack << PacketTypeVoxelEditNack << PacketTypeParticleEditNack << PacketTypeEntityEditNack
|
||||||
<< PacketTypeIceServerHeartbeat << PacketTypeIceServerHeartbeatResponse;
|
<< PacketTypeIceServerHeartbeat << PacketTypeIceServerHeartbeatResponse
|
||||||
|
<< PacketTypeUnverifiedPing << PacketTypeUnverifiedPingReply;
|
||||||
|
|
||||||
const int NUM_BYTES_MD5_HASH = 16;
|
const int NUM_BYTES_MD5_HASH = 16;
|
||||||
const int NUM_STATIC_HEADER_BYTES = sizeof(PacketVersion) + NUM_BYTES_RFC4122_UUID;
|
const int NUM_STATIC_HEADER_BYTES = sizeof(PacketVersion) + NUM_BYTES_RFC4122_UUID;
|
||||||
|
|
Loading…
Reference in a new issue