From 49d081088a2727b8f6898c64a5675e0ab9835903 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 3 Oct 2014 08:58:03 -0700 Subject: [PATCH] mode nodes to connected hash upon ping reply receipt --- domain-server/src/DomainServer.cpp | 28 +++++++++++++++++++++++---- libraries/networking/src/NodeList.cpp | 19 ++++++++++++------ 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index b0fdb61ed5..13490b3c7b 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -581,9 +581,17 @@ void DomainServer::handleConnectRequest(const QByteArray& packet, const HifiSock if ((!isAssignment && !STATICALLY_ASSIGNED_NODES.contains(nodeType)) || (isAssignment && matchingQueuedAssignment)) { // this was either not a static assignment or it was and we had a matching one in the queue + + QUuid nodeUUID; - // create a new session UUID for this node - QUuid nodeUUID = QUuid::createUuid(); + if (_connectingICEPeers.contains(packetUUID) || _connectedICEPeers.contains(packetUUID)) { + // this user negotiated a connection with us via ICE, so re-use their ICE client ID + nodeUUID = packetUUID; + } else { + // we got a packetUUID we didn't recognize, just add the node + nodeUUID = QUuid::createUuid(); + } + SharedNodePointer newNode = LimitedNodeList::getInstance()->addOrUpdateNode(nodeUUID, nodeType, publicSockAddr, localSockAddr); @@ -1022,7 +1030,7 @@ void DomainServer::processICEHeartbeatResponse(const QByteArray& packet) { while (!iceResponseStream.atEnd()) { iceResponseStream >> receivedPeer; - if (!_connectingICEPeers.contains(receivedPeer.getUUID())) { + if (!_connectingICEPeers.contains(receivedPeer.getUUID()) && _connectedICEPeers.contains(receivedPeer.getUUID())) { qDebug() << "New peer requesting connection being added to hash -" << receivedPeer; } @@ -1031,7 +1039,19 @@ void DomainServer::processICEHeartbeatResponse(const QByteArray& packet) { } void DomainServer::processICEPingReply(const QByteArray& packet, const HifiSockAddr& senderSockAddr) { - qDebug() << "looking for a node with ID" << uuidFromPacketHeader(packet) << "in connecting hash"; + QUuid nodeUUID = uuidFromPacketHeader(packet); + NetworkPeer sendingPeer = _connectingICEPeers.take(nodeUUID); + + if (!sendingPeer.isNull()) { + // we had this NetworkPeer in our connecting list - add the right sock addr to our connected list + if (senderSockAddr == sendingPeer.getLocalSocket()) { + qDebug() << "Activating local socket for communication with network peer -" << sendingPeer; + _connectedICEPeers.insert(nodeUUID, sendingPeer.getLocalSocket()); + } else if (senderSockAddr == sendingPeer.getPublicSocket()) { + qDebug() << "Activating public socket for communication with network peer -" << sendingPeer; + _connectedICEPeers.insert(nodeUUID, sendingPeer.getPublicSocket()); + } + } } void DomainServer::processDatagram(const QByteArray& receivedPacket, const HifiSockAddr& senderSockAddr) { diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index da11684ada..de586f3d36 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -276,7 +276,7 @@ void NodeList::sendDomainServerCheckIn() { bool isUsingDTLS = false; PacketType domainPacketType = !_domainHandler.isConnected() - ? PacketTypeDomainConnectRequest : PacketTypeDomainListRequest; + ? PacketTypeDomainConnectRequest : PacketTypeDomainListRequest; if (!_domainHandler.isConnected()) { qDebug() << "Sending connect request to domain-server at" << _domainHandler.getHostname(); @@ -285,10 +285,17 @@ void NodeList::sendDomainServerCheckIn() { // construct the DS check in packet QUuid packetUUID = _sessionUUID; - if (!_domainHandler.getAssignmentUUID().isNull() && domainPacketType == PacketTypeDomainConnectRequest) { - // this is a connect request and we're an assigned node - // so set our packetUUID as the assignment UUID - packetUUID = _domainHandler.getAssignmentUUID(); + if (domainPacketType == PacketTypeDomainConnectRequest) { + if (!_domainHandler.getAssignmentUUID().isNull()) { + // this is a connect request and we're an assigned node + // so set our packetUUID as the assignment UUID + packetUUID = _domainHandler.getAssignmentUUID(); + } else if (_domainHandler.requiresICE()) { + // this is a connect request and we're an interface client + // that used ice to discover the DS + // so send our ICE client UUID with the connect request + packetUUID = _domainHandler.getICEClientID(); + } } QByteArray domainServerPacket = byteArrayWithPopulatedHeader(domainPacketType, packetUUID); @@ -336,7 +343,7 @@ void NodeList::handleICEConnectionToDomainServer() { qDebug() << "Sending ping packets to establish connectivity with domain-server with ID" << 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 nodfe QByteArray localPingPacket = constructPingPacket(PingType::Local, false, _domainHandler.getICEClientID()); writeUnverifiedDatagram(localPingPacket, _domainHandler.getICEPeer().getLocalSocket());