mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 09:59:20 +02:00
add a verify packet operator to verify packets
This commit is contained in:
parent
796dfee687
commit
cea8e01a01
3 changed files with 14 additions and 6 deletions
|
@ -99,7 +99,7 @@ LimitedNodeList::LimitedNodeList(unsigned short socketListenPort, unsigned short
|
||||||
|
|
||||||
// set &PacketReceiver::handleVerifiedPacket as the verified packet function for the udt::Socket
|
// set &PacketReceiver::handleVerifiedPacket as the verified packet function for the udt::Socket
|
||||||
using std::placeholders::_1;
|
using std::placeholders::_1;
|
||||||
_nodeSocket.setVerifiedPacketFunction(std::bind(&PacketReceiver::handleVerifiedPacket, _packetReceiver, _1));
|
_nodeSocket.setVerifiedPacketCallback(std::bind(&PacketReceiver::handleVerifiedPacket, _packetReceiver, _1));
|
||||||
|
|
||||||
_packetStatTimer.start();
|
_packetStatTimer.start();
|
||||||
|
|
||||||
|
|
|
@ -83,6 +83,11 @@ void Socket::readPendingDatagrams() {
|
||||||
// setup a Packet from the data we just read
|
// setup a Packet from the data we just read
|
||||||
auto packet = Packet::fromReceivedPacket(std::move(buffer), packetSizeWithHeader, senderSockAddr);
|
auto packet = Packet::fromReceivedPacket(std::move(buffer), packetSizeWithHeader, senderSockAddr);
|
||||||
|
|
||||||
|
// call our verification operator to see if this packet is verified
|
||||||
|
if (!_verifyPacketOperator || _verifyPacketOperator(*packet)) {
|
||||||
|
|
||||||
|
// call the verified packet callback to let it handle this packet
|
||||||
|
return _verifiedPacketCallback(std::move(packet));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,8 @@
|
||||||
|
|
||||||
namespace udt {
|
namespace udt {
|
||||||
|
|
||||||
using VerifiedPacketFunction = std::function<void(std::unique_ptr<Packet>)>;
|
using VerifyPacketOperator = std::function<bool(Packet&)>;
|
||||||
|
using VerifiedPacketCallback = std::function<void(std::unique_ptr<Packet>)>;
|
||||||
|
|
||||||
class Socket : public QObject {
|
class Socket : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -40,8 +41,9 @@ public:
|
||||||
void bind(const QHostAddress& address, quint16 port = 0) { _udpSocket.bind(address, port); }
|
void bind(const QHostAddress& address, quint16 port = 0) { _udpSocket.bind(address, port); }
|
||||||
void rebind();
|
void rebind();
|
||||||
|
|
||||||
void setVerifiedPacketFunction(VerifiedPacketFunction verifiedPacketFunction)
|
void setVerifyPacketOperator(VerifyPacketOperator verifyPacketOperator) { _verifyPacketOperator = verifyPacketOperator; }
|
||||||
{ _verifiedPacketFunction = verifiedPacketFunction; }
|
void setVerifiedPacketCallback(VerifiedPacketCallback verifiedPacketCallback)
|
||||||
|
{ _verifiedPacketCallback = verifiedPacketCallback; }
|
||||||
|
|
||||||
void setBufferSizes(int numBytes);
|
void setBufferSizes(int numBytes);
|
||||||
|
|
||||||
|
@ -50,7 +52,8 @@ private slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUdpSocket _udpSocket { this };
|
QUdpSocket _udpSocket { this };
|
||||||
VerifiedPacketFunction _verifiedPacketFunction;
|
VerifyPacketOperator _verifyPacketOperator;
|
||||||
|
VerifiedPacketCallback _verifiedPacketCallback;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue