Merge branch 'atp' of https://github.com/birarda/hifi into protocol

This commit is contained in:
Atlante45 2015-07-16 14:22:40 -07:00
commit 7cb4afd718
6 changed files with 31 additions and 29 deletions

View file

@ -288,6 +288,7 @@ void DomainServer::setupNodeListAndAssignments(const QUuid& sessionUUID) {
packetReceiver.registerListener(PacketType::NodeJsonStats, this, "processNodeJSONStatsPacket"); packetReceiver.registerListener(PacketType::NodeJsonStats, this, "processNodeJSONStatsPacket");
packetReceiver.registerListener(PacketType::ICEPing, this, "processICEPingPacket"); packetReceiver.registerListener(PacketType::ICEPing, this, "processICEPingPacket");
packetReceiver.registerListener(PacketType::ICEPingReply, this, "processICEPingReplyPacket"); packetReceiver.registerListener(PacketType::ICEPingReply, this, "processICEPingReplyPacket");
packetReceiver.registerListener(PacketType::ICEServerPeerInformation, this, "processICEPeerInformationPacket");
// add whatever static assignments that have been parsed to the queue // add whatever static assignments that have been parsed to the queue
addStaticAssignmentsToQueue(); addStaticAssignmentsToQueue();

View file

@ -46,23 +46,26 @@ IceServer::IceServer(int argc, char* argv[]) :
void IceServer::processDatagrams() { void IceServer::processDatagrams() {
HifiSockAddr sendingSockAddr; HifiSockAddr sendingSockAddr;
QByteArray incomingPacket;
while (_serverSocket.hasPendingDatagrams()) { 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()); sendingSockAddr.getAddressPointer(), sendingSockAddr.getPortPointer());
PacketType::Value packetType = packetTypeForPacket(incomingPacket); auto packet = Packet::fromReceivedPacket(std::move(buffer), packetSizeWithHeader, sendingSockAddr);
PacketType::Value packetType = packet->getType();
if (packetType == PacketType::ICEServerHeartbeat) { 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 // so that we can send packets to the heartbeating peer when we need, we need to activate a socket now
peer->activateMatchingOrNewSymmetricSocket(sendingSockAddr); peer->activateMatchingOrNewSymmetricSocket(sendingSockAddr);
} else if (packetType == PacketType::ICEServerQuery) { } 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? // this is a node hoping to connect to a heartbeating peer - do we have the heartbeating peer?
QUuid senderUUID; QUuid senderUUID;
@ -70,9 +73,6 @@ void IceServer::processDatagrams() {
// pull the public and private sock addrs for this peer // pull the public and private sock addrs for this peer
HifiSockAddr publicSocket, localSocket; HifiSockAddr publicSocket, localSocket;
heartbeatStream.skipRawData(numBytesForPacketHeader(incomingPacket));
heartbeatStream >> publicSocket >> localSocket; heartbeatStream >> publicSocket >> localSocket;
// check if this node also included a UUID that they would like to connect to // check if this node also included a UUID that they would like to connect to
@ -95,16 +95,16 @@ void IceServer::processDatagrams() {
} }
} }
SharedNetworkPeer IceServer::addOrUpdateHeartbeatingPeer(const QByteArray& incomingPacket) { SharedNetworkPeer IceServer::addOrUpdateHeartbeatingPeer(Packet& packet) {
QUuid senderUUID = uuidFromPacketHeader(incomingPacket);
// 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; HifiSockAddr publicSocket, localSocket;
QDataStream hearbeatStream(incomingPacket); QDataStream heartbeatStream(&packet);
hearbeatStream.skipRawData(numBytesForPacketHeader(incomingPacket));
hearbeatStream >> publicSocket >> localSocket; heartbeatStream >> senderUUID;
heartbeatStream >> publicSocket >> localSocket;
// make sure we have this sender in our peer hash // make sure we have this sender in our peer hash
SharedNetworkPeer matchingPeer = _activePeers.value(senderUUID); SharedNetworkPeer matchingPeer = _activePeers.value(senderUUID);

View file

@ -19,6 +19,7 @@
#include <NetworkPeer.h> #include <NetworkPeer.h>
#include <HTTPConnection.h> #include <HTTPConnection.h>
#include <HTTPManager.h> #include <HTTPManager.h>
#include <udt/Packet.h>
typedef QHash<QUuid, SharedNetworkPeer> NetworkPeerHash; typedef QHash<QUuid, SharedNetworkPeer> NetworkPeerHash;
@ -32,7 +33,7 @@ private slots:
void clearInactivePeers(); void clearInactivePeers();
private: private:
SharedNetworkPeer addOrUpdateHeartbeatingPeer(const QByteArray& incomingPacket); SharedNetworkPeer addOrUpdateHeartbeatingPeer(Packet& incomingPacket);
void sendPeerInformationPacket(const NetworkPeer& peer, const HifiSockAddr* destinationSockAddr); void sendPeerInformationPacket(const NetworkPeer& peer, const HifiSockAddr* destinationSockAddr);
QUuid _id; QUuid _id;

View file

@ -137,6 +137,9 @@ void DomainHandler::setIceServerHostnameAndID(const QString& iceServerHostname,
// re-set the domain info to connect to new domain // re-set the domain info to connect to new domain
hardReset(); hardReset();
// refresh our ICE client UUID to something new
_iceClientID = QUuid::createUuid();
_iceDomainID = id; _iceDomainID = id;
HifiSockAddr* replaceableSockAddr = &_iceServerSockAddr; HifiSockAddr* replaceableSockAddr = &_iceServerSockAddr;
@ -154,10 +157,6 @@ void DomainHandler::setIceServerHostnameAndID(const QString& iceServerHostname,
completedIceServerHostnameLookup(); 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; 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) { 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 // bail on processing this packet if our ice peer doesn't have sockets
return; return;
} }