From 086e4efe4490ed6a19ef472ba8b5fc81d0c3e666 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 21 Jul 2015 13:03:39 -0700 Subject: [PATCH] verify packet versions at ice-server --- ice-server/src/IceServer.cpp | 14 ++++++++++++ ice-server/src/IceServer.h | 1 + interface/src/Application.cpp | 2 +- libraries/networking/src/NetworkPeer.cpp | 28 ++++++++++++++---------- libraries/networking/src/udt/Socket.h | 2 +- 5 files changed, 34 insertions(+), 13 deletions(-) diff --git a/ice-server/src/IceServer.cpp b/ice-server/src/IceServer.cpp index fb7433aa10..e86ed0b4ea 100644 --- a/ice-server/src/IceServer.cpp +++ b/ice-server/src/IceServer.cpp @@ -37,6 +37,9 @@ IceServer::IceServer(int argc, char* argv[]) : // set processPacket as the verified packet callback for the udt::Socket using std::placeholders::_1; _serverSocket.setVerifiedPacketCallback(std::bind(&IceServer::processPacket, this, _1)); + + // set packetVersionMatch as the verify packet operator for the udt::Socket + _serverSocket.setVerifyPacketOperator(std::bind(&IceServer::packetVersionMatch, this, _1)); // setup our timer to clear inactive peers QTimer* inactivePeerTimer = new QTimer(this); @@ -45,6 +48,17 @@ IceServer::IceServer(int argc, char* argv[]) : } +bool IceServer::packetVersionMatch(const udt::Packet& packet) { + if (packet.getVersion() == versionForPacketType(packet.getType())) { + return true; + } else { + qDebug() << "Packet version mismatch for packet" << packet.getType() + << "(" << nameForPacketType(packet.getType()) << ") from" << packet.getSenderSockAddr(); + + return false; + } +} + void IceServer::processPacket(std::unique_ptr packet) { PacketType::Value packetType = packet->getType(); diff --git a/ice-server/src/IceServer.h b/ice-server/src/IceServer.h index 092ece6c3f..3ab6df9044 100644 --- a/ice-server/src/IceServer.h +++ b/ice-server/src/IceServer.h @@ -32,6 +32,7 @@ public: private slots: void clearInactivePeers(); private: + bool packetVersionMatch(const udt::Packet& packet); void processPacket(std::unique_ptr packet); SharedNetworkPeer addOrUpdateHeartbeatingPeer(udt::Packet& incomingPacket); diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index e920c760ba..652d12ade0 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -452,7 +452,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : connect(nodeList.data(), &NodeList::uuidChanged, _myAvatar, &MyAvatar::setSessionUUID); connect(nodeList.data(), &NodeList::uuidChanged, this, &Application::setSessionUUID); connect(nodeList.data(), &NodeList::limitOfSilentDomainCheckInsReached, nodeList.data(), &NodeList::reset); - connect(&nodeList.data(), &NodeList::packetVersionMismatch, this, &Application::notifyPacketVersionMismatch); + connect(nodeList.data(), &NodeList::packetVersionMismatch, this, &Application::notifyPacketVersionMismatch); // connect to appropriate slots on AccountManager AccountManager& accountManager = AccountManager::getInstance(); diff --git a/libraries/networking/src/NetworkPeer.cpp b/libraries/networking/src/NetworkPeer.cpp index 398d4106c1..28f19d4f60 100644 --- a/libraries/networking/src/NetworkPeer.cpp +++ b/libraries/networking/src/NetworkPeer.cpp @@ -54,12 +54,14 @@ void NetworkPeer::setPublicSocket(const HifiSockAddr& publicSocket) { // if the active socket was the public socket then reset it to NULL _activeSocket = NULL; } - - if (!_publicSocket.isNull()) { - qCDebug(networking) << "Public socket change for node" << *this; - } + + bool wasOldSocketNull = _publicSocket.isNull(); _publicSocket = publicSocket; + + if (!wasOldSocketNull) { + qCDebug(networking) << "Public socket change for node" << *this; + } } } @@ -69,12 +71,14 @@ void NetworkPeer::setLocalSocket(const HifiSockAddr& localSocket) { // if the active socket was the local socket then reset it to NULL _activeSocket = NULL; } + + bool wasOldSocketNull = _localSocket.isNull(); + + _localSocket = localSocket; - if (!_localSocket.isNull()) { + if (!wasOldSocketNull) { qCDebug(networking) << "Local socket change for node" << *this; } - - _localSocket = localSocket; } } @@ -84,12 +88,14 @@ void NetworkPeer::setSymmetricSocket(const HifiSockAddr& symmetricSocket) { // if the active socket was the symmetric socket then reset it to NULL _activeSocket = NULL; } - - if (!_symmetricSocket.isNull()) { + + bool wasOldSocketNull = _symmetricSocket.isNull(); + + _symmetricSocket = symmetricSocket; + + if (!wasOldSocketNull) { qCDebug(networking) << "Symmetric socket change for node" << *this; } - - _symmetricSocket = symmetricSocket; } } diff --git a/libraries/networking/src/udt/Socket.h b/libraries/networking/src/udt/Socket.h index 6997986e91..2ebeb179bc 100644 --- a/libraries/networking/src/udt/Socket.h +++ b/libraries/networking/src/udt/Socket.h @@ -24,7 +24,7 @@ namespace udt { -using VerifyPacketOperator = std::function; +using VerifyPacketOperator = std::function; using VerifiedPacketCallback = std::function)>; class Socket : public QObject {