mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-07 03:22:27 +02:00
fix ice-server packets
This commit is contained in:
parent
ed928e8a6b
commit
f31675c4c6
6 changed files with 31 additions and 29 deletions
|
@ -288,7 +288,8 @@ void DomainServer::setupNodeListAndAssignments(const QUuid& sessionUUID) {
|
|||
packetReceiver.registerListener(PacketType::NodeJsonStats, this, "processNodeJSONStatsPacket");
|
||||
packetReceiver.registerListener(PacketType::ICEPing, this, "processICEPingPacket");
|
||||
packetReceiver.registerListener(PacketType::ICEPingReply, this, "processICEPingReplyPacket");
|
||||
|
||||
packetReceiver.registerListener(PacketType::ICEServerPeerInformation, this, "processICEPeerInformationPacket");
|
||||
|
||||
// add whatever static assignments that have been parsed to the queue
|
||||
addStaticAssignmentsToQueue();
|
||||
}
|
||||
|
|
|
@ -46,23 +46,26 @@ IceServer::IceServer(int argc, char* argv[]) :
|
|||
|
||||
void IceServer::processDatagrams() {
|
||||
HifiSockAddr sendingSockAddr;
|
||||
QByteArray incomingPacket;
|
||||
|
||||
while (_serverSocket.hasPendingDatagrams()) {
|
||||
incomingPacket.resize(_serverSocket.pendingDatagramSize());
|
||||
// setup a buffer to read the packet into
|
||||
int packetSizeWithHeader = _serverSocket.pendingDatagramSize();
|
||||
std::unique_ptr<char> buffer = std::unique_ptr<char>(new char[packetSizeWithHeader]);
|
||||
|
||||
_serverSocket.readDatagram(incomingPacket.data(), incomingPacket.size(),
|
||||
_serverSocket.readDatagram(buffer.get(), packetSizeWithHeader,
|
||||
sendingSockAddr.getAddressPointer(), sendingSockAddr.getPortPointer());
|
||||
|
||||
auto packet = Packet::fromReceivedPacket(std::move(buffer), packetSizeWithHeader, sendingSockAddr);
|
||||
|
||||
PacketType::Value packetType = packetTypeForPacket(incomingPacket);
|
||||
PacketType::Value packetType = packet->getType();
|
||||
|
||||
if (packetType == PacketType::ICEServerHeartbeat) {
|
||||
SharedNetworkPeer peer = addOrUpdateHeartbeatingPeer(incomingPacket);
|
||||
SharedNetworkPeer peer = addOrUpdateHeartbeatingPeer(*packet);
|
||||
|
||||
// so that we can send packets to the heartbeating peer when we need, we need to activate a socket now
|
||||
peer->activateMatchingOrNewSymmetricSocket(sendingSockAddr);
|
||||
} else if (packetType == PacketType::ICEServerQuery) {
|
||||
QDataStream heartbeatStream(incomingPacket);
|
||||
QDataStream heartbeatStream(packet.get());
|
||||
|
||||
// this is a node hoping to connect to a heartbeating peer - do we have the heartbeating peer?
|
||||
QUuid senderUUID;
|
||||
|
@ -70,15 +73,12 @@ void IceServer::processDatagrams() {
|
|||
|
||||
// pull the public and private sock addrs for this peer
|
||||
HifiSockAddr publicSocket, localSocket;
|
||||
|
||||
heartbeatStream.skipRawData(numBytesForPacketHeader(incomingPacket));
|
||||
|
||||
heartbeatStream >> publicSocket >> localSocket;
|
||||
|
||||
// check if this node also included a UUID that they would like to connect to
|
||||
QUuid connectRequestID;
|
||||
heartbeatStream >> connectRequestID;
|
||||
|
||||
|
||||
SharedNetworkPeer matchingPeer = _activePeers.value(connectRequestID);
|
||||
|
||||
if (matchingPeer) {
|
||||
|
@ -95,16 +95,16 @@ void IceServer::processDatagrams() {
|
|||
}
|
||||
}
|
||||
|
||||
SharedNetworkPeer IceServer::addOrUpdateHeartbeatingPeer(const QByteArray& incomingPacket) {
|
||||
QUuid senderUUID = uuidFromPacketHeader(incomingPacket);
|
||||
SharedNetworkPeer IceServer::addOrUpdateHeartbeatingPeer(Packet& packet) {
|
||||
|
||||
// pull the public and private sock addrs for this peer
|
||||
// pull the UUID, public and private sock addrs for this peer
|
||||
QUuid senderUUID;
|
||||
HifiSockAddr publicSocket, localSocket;
|
||||
|
||||
QDataStream hearbeatStream(incomingPacket);
|
||||
hearbeatStream.skipRawData(numBytesForPacketHeader(incomingPacket));
|
||||
|
||||
hearbeatStream >> publicSocket >> localSocket;
|
||||
QDataStream heartbeatStream(&packet);
|
||||
|
||||
heartbeatStream >> senderUUID;
|
||||
heartbeatStream >> publicSocket >> localSocket;
|
||||
|
||||
// make sure we have this sender in our peer hash
|
||||
SharedNetworkPeer matchingPeer = _activePeers.value(senderUUID);
|
||||
|
@ -132,7 +132,7 @@ void IceServer::sendPeerInformationPacket(const NetworkPeer& peer, const HifiSoc
|
|||
|
||||
// get the byte array for this peer
|
||||
peerPacket->write(peer.toByteArray());
|
||||
|
||||
|
||||
// write the current packet
|
||||
_serverSocket.writeDatagram(peerPacket->getData(), peerPacket->getDataSize(),
|
||||
destinationSockAddr->getAddress(), destinationSockAddr->getPort());
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <NetworkPeer.h>
|
||||
#include <HTTPConnection.h>
|
||||
#include <HTTPManager.h>
|
||||
#include <udt/Packet.h>
|
||||
|
||||
typedef QHash<QUuid, SharedNetworkPeer> NetworkPeerHash;
|
||||
|
||||
|
@ -32,7 +33,7 @@ private slots:
|
|||
void clearInactivePeers();
|
||||
private:
|
||||
|
||||
SharedNetworkPeer addOrUpdateHeartbeatingPeer(const QByteArray& incomingPacket);
|
||||
SharedNetworkPeer addOrUpdateHeartbeatingPeer(Packet& incomingPacket);
|
||||
void sendPeerInformationPacket(const NetworkPeer& peer, const HifiSockAddr* destinationSockAddr);
|
||||
|
||||
QUuid _id;
|
||||
|
|
|
@ -136,7 +136,10 @@ void DomainHandler::setIceServerHostnameAndID(const QString& iceServerHostname,
|
|||
if (id != _uuid) {
|
||||
// re-set the domain info to connect to new domain
|
||||
hardReset();
|
||||
|
||||
|
||||
// refresh our ICE client UUID to something new
|
||||
_iceClientID = QUuid::createUuid();
|
||||
|
||||
_iceDomainID = id;
|
||||
|
||||
HifiSockAddr* replaceableSockAddr = &_iceServerSockAddr;
|
||||
|
@ -154,10 +157,6 @@ void DomainHandler::setIceServerHostnameAndID(const QString& iceServerHostname,
|
|||
completedIceServerHostnameLookup();
|
||||
}
|
||||
|
||||
|
||||
// refresh our ICE client UUID to something new
|
||||
_iceClientID = QUuid::createUuid();
|
||||
|
||||
qCDebug(networking) << "ICE required to connect to domain via ice server at" << iceServerHostname;
|
||||
}
|
||||
}
|
||||
|
@ -313,7 +312,8 @@ void DomainHandler::processDTLSRequirementPacket(QSharedPointer<NLPacket> dtlsRe
|
|||
}
|
||||
|
||||
void DomainHandler::processICEResponsePacket(QSharedPointer<NLPacket> icePacket) {
|
||||
if (!_icePeer.hasSockets()) {
|
||||
if (_icePeer.hasSockets()) {
|
||||
qDebug() << "Received an ICE peer packet for domain-server but we already have sockets. Not processing.";
|
||||
// bail on processing this packet if our ice peer doesn't have sockets
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -788,7 +788,7 @@ void LimitedNodeList::sendPacketToIceServer(PacketType::Value packetType, const
|
|||
|
||||
QDataStream iceDataStream(icePacket.get());
|
||||
iceDataStream << clientID << _publicSockAddr << _localSockAddr;
|
||||
|
||||
|
||||
if (packetType == PacketType::ICEServerQuery) {
|
||||
assert(!peerID.isNull());
|
||||
|
||||
|
|
|
@ -235,7 +235,7 @@ void PacketReceiver::processDatagrams() {
|
|||
|
||||
// setup an NLPacket from the data we just read
|
||||
auto packet = NLPacket::fromReceivedPacket(std::move(buffer), packetSizeWithHeader, senderSockAddr);
|
||||
|
||||
|
||||
_inPacketCount++;
|
||||
_inByteCount += packetSizeWithHeader;
|
||||
|
||||
|
@ -271,7 +271,7 @@ void PacketReceiver::processDatagrams() {
|
|||
_directConnectSetMutex.unlock();
|
||||
|
||||
PacketType::Value packetType = packet->getType();
|
||||
|
||||
|
||||
if (matchingNode) {
|
||||
// if this was a sequence numbered packet we should store the last seq number for
|
||||
// a packet of this type for this node
|
||||
|
|
Loading…
Reference in a new issue