mirror of
https://github.com/overte-org/overte.git
synced 2025-04-11 13:42:38 +02:00
verify packet versions at ice-server
This commit is contained in:
parent
4604bc5a3a
commit
086e4efe44
5 changed files with 34 additions and 13 deletions
|
@ -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();
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue