verify packet versions at ice-server

This commit is contained in:
Stephen Birarda 2015-07-21 13:03:39 -07:00
parent 4604bc5a3a
commit 086e4efe44
5 changed files with 34 additions and 13 deletions

View file

@ -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<udt::Packet> packet) {
PacketType::Value packetType = packet->getType();

View file

@ -32,6 +32,7 @@ public:
private slots:
void clearInactivePeers();
private:
bool packetVersionMatch(const udt::Packet& packet);
void processPacket(std::unique_ptr<udt::Packet> packet);
SharedNetworkPeer addOrUpdateHeartbeatingPeer(udt::Packet& incomingPacket);

View file

@ -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();

View file

@ -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;
}
}

View file

@ -24,7 +24,7 @@
namespace udt {
using VerifyPacketOperator = std::function<bool(Packet&)>;
using VerifyPacketOperator = std::function<bool(const Packet&)>;
using VerifiedPacketCallback = std::function<void(std::unique_ptr<Packet>)>;
class Socket : public QObject {