don't read packets that are too small

This commit is contained in:
Stephen Birarda 2015-08-27 15:34:53 -07:00
parent d0db56a4a6
commit b4e624a64d

View file

@ -55,46 +55,50 @@ void IceServer::processDatagrams() {
_serverSocket.readDatagram(buffer.get(), packetSizeWithHeader, _serverSocket.readDatagram(buffer.get(), packetSizeWithHeader,
sendingSockAddr.getAddressPointer(), sendingSockAddr.getPortPointer()); sendingSockAddr.getAddressPointer(), sendingSockAddr.getPortPointer());
auto packet = Packet::fromReceivedPacket(std::move(buffer), packetSizeWithHeader, sendingSockAddr); // make sure that this packet at least looks like something we can read
if (packetSizeWithHeader >= Packet::localHeaderSize(PacketType::ICEServerHeartbeat)) {
PacketType::Value packetType = packet->getType(); auto packet = Packet::fromReceivedPacket(std::move(buffer), packetSizeWithHeader, sendingSockAddr);
if (packetType == PacketType::ICEServerHeartbeat) { PacketType::Value packetType = packet->getType();
SharedNetworkPeer peer = addOrUpdateHeartbeatingPeer(*packet);
// so that we can send packets to the heartbeating peer when we need, we need to activate a socket now if (packetType == PacketType::ICEServerHeartbeat) {
peer->activateMatchingOrNewSymmetricSocket(sendingSockAddr); SharedNetworkPeer peer = addOrUpdateHeartbeatingPeer(*packet);
} else if (packetType == PacketType::ICEServerQuery) {
QDataStream heartbeatStream(packet.get());
// this is a node hoping to connect to a heartbeating peer - do we have the heartbeating peer? // so that we can send packets to the heartbeating peer when we need, we need to activate a socket now
QUuid senderUUID; peer->activateMatchingOrNewSymmetricSocket(sendingSockAddr);
heartbeatStream >> senderUUID; } else if (packetType == PacketType::ICEServerQuery) {
QDataStream heartbeatStream(packet.get());
// pull the public and private sock addrs for this peer // this is a node hoping to connect to a heartbeating peer - do we have the heartbeating peer?
HifiSockAddr publicSocket, localSocket; QUuid senderUUID;
heartbeatStream >> publicSocket >> localSocket; heartbeatStream >> senderUUID;
// check if this node also included a UUID that they would like to connect to // pull the public and private sock addrs for this peer
QUuid connectRequestID; HifiSockAddr publicSocket, localSocket;
heartbeatStream >> connectRequestID; heartbeatStream >> publicSocket >> localSocket;
SharedNetworkPeer matchingPeer = _activePeers.value(connectRequestID); // check if this node also included a UUID that they would like to connect to
QUuid connectRequestID;
heartbeatStream >> connectRequestID;
if (matchingPeer) { SharedNetworkPeer matchingPeer = _activePeers.value(connectRequestID);
qDebug() << "Sending information for peer" << connectRequestID << "to peer" << senderUUID; if (matchingPeer) {
// we have the peer they want to connect to - send them pack the information for that peer qDebug() << "Sending information for peer" << connectRequestID << "to peer" << senderUUID;
sendPeerInformationPacket(*(matchingPeer.data()), &sendingSockAddr);
// we also need to send them to the active peer they are hoping to connect to // we have the peer they want to connect to - send them pack the information for that peer
// create a dummy peer object we can pass to sendPeerInformationPacket sendPeerInformationPacket(*(matchingPeer.data()), &sendingSockAddr);
NetworkPeer dummyPeer(senderUUID, publicSocket, localSocket); // we also need to send them to the active peer they are hoping to connect to
sendPeerInformationPacket(dummyPeer, matchingPeer->getActiveSocket()); // create a dummy peer object we can pass to sendPeerInformationPacket
} else {
qDebug() << "Peer" << senderUUID << "asked for" << connectRequestID << "but no matching peer found"; NetworkPeer dummyPeer(senderUUID, publicSocket, localSocket);
sendPeerInformationPacket(dummyPeer, matchingPeer->getActiveSocket());
} else {
qDebug() << "Peer" << senderUUID << "asked for" << connectRequestID << "but no matching peer found";
}
} }
} }
} }