mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 12:49:34 +02:00
udt namespace fixes and NLPacket operator fixes
This commit is contained in:
parent
9556fecbe2
commit
796dfee687
14 changed files with 59 additions and 16 deletions
|
@ -55,7 +55,7 @@ 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);
|
auto packet = udt::Packet::fromReceivedPacket(std::move(buffer), packetSizeWithHeader, sendingSockAddr);
|
||||||
|
|
||||||
PacketType::Value packetType = packet->getType();
|
PacketType::Value packetType = packet->getType();
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ void IceServer::processDatagrams() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedNetworkPeer IceServer::addOrUpdateHeartbeatingPeer(Packet& packet) {
|
SharedNetworkPeer IceServer::addOrUpdateHeartbeatingPeer(udt::Packet& packet) {
|
||||||
|
|
||||||
// pull the UUID, public and private sock addrs for this peer
|
// pull the UUID, public and private sock addrs for this peer
|
||||||
QUuid senderUUID;
|
QUuid senderUUID;
|
||||||
|
@ -133,7 +133,7 @@ SharedNetworkPeer IceServer::addOrUpdateHeartbeatingPeer(Packet& packet) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void IceServer::sendPeerInformationPacket(const NetworkPeer& peer, const HifiSockAddr* destinationSockAddr) {
|
void IceServer::sendPeerInformationPacket(const NetworkPeer& peer, const HifiSockAddr* destinationSockAddr) {
|
||||||
auto peerPacket = Packet::create(PacketType::ICEServerPeerInformation);
|
auto peerPacket = udt::Packet::create(PacketType::ICEServerPeerInformation);
|
||||||
|
|
||||||
// get the byte array for this peer
|
// get the byte array for this peer
|
||||||
peerPacket->write(peer.toByteArray());
|
peerPacket->write(peer.toByteArray());
|
||||||
|
|
|
@ -33,7 +33,7 @@ private slots:
|
||||||
void clearInactivePeers();
|
void clearInactivePeers();
|
||||||
private:
|
private:
|
||||||
|
|
||||||
SharedNetworkPeer addOrUpdateHeartbeatingPeer(Packet& incomingPacket);
|
SharedNetworkPeer addOrUpdateHeartbeatingPeer(udt::Packet& incomingPacket);
|
||||||
void sendPeerInformationPacket(const NetworkPeer& peer, const HifiSockAddr* destinationSockAddr);
|
void sendPeerInformationPacket(const NetworkPeer& peer, const HifiSockAddr* destinationSockAddr);
|
||||||
|
|
||||||
QUuid _id;
|
QUuid _id;
|
||||||
|
|
|
@ -99,7 +99,8 @@ NLPacket::NLPacket(std::unique_ptr<Packet> packet) :
|
||||||
}
|
}
|
||||||
|
|
||||||
NLPacket::NLPacket(const NLPacket& other) : Packet(other) {
|
NLPacket::NLPacket(const NLPacket& other) : Packet(other) {
|
||||||
*this = other;
|
_sourceID = other._sourceID;
|
||||||
|
_verificationHash = other._verificationHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
NLPacket& NLPacket::operator=(const NLPacket& other) {
|
NLPacket& NLPacket::operator=(const NLPacket& other) {
|
||||||
|
@ -123,10 +124,14 @@ NLPacket::NLPacket(std::unique_ptr<char> data, qint64 size, const HifiSockAddr&
|
||||||
NLPacket::NLPacket(NLPacket&& other) :
|
NLPacket::NLPacket(NLPacket&& other) :
|
||||||
Packet(other)
|
Packet(other)
|
||||||
{
|
{
|
||||||
*this = std::move(other);
|
_sourceID = std::move(other._sourceID);
|
||||||
|
_verificationHash = std::move(other._verificationHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
NLPacket& NLPacket::operator=(NLPacket&& other) {
|
NLPacket& NLPacket::operator=(NLPacket&& other) {
|
||||||
|
|
||||||
|
Packet::operator=(other);
|
||||||
|
|
||||||
_sourceID = std::move(other._sourceID);
|
_sourceID = std::move(other._sourceID);
|
||||||
_verificationHash = std::move(other._verificationHash);
|
_verificationHash = std::move(other._verificationHash);
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
#include "udt/Packet.h"
|
#include "udt/Packet.h"
|
||||||
|
|
||||||
class NLPacket : public Packet {
|
class NLPacket : public udt::Packet {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
static std::unique_ptr<NLPacket> create(PacketType::Value type, qint64 size = -1);
|
static std::unique_ptr<NLPacket> create(PacketType::Value type, qint64 size = -1);
|
||||||
|
|
|
@ -19,7 +19,7 @@ NLPacketList::NLPacketList(PacketType::Value packetType, QByteArray extendedHead
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Packet> NLPacketList::createPacket() {
|
std::unique_ptr<udt::Packet> NLPacketList::createPacket() {
|
||||||
return NLPacket::create(getType());
|
return NLPacket::create(getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
#include "udt/PacketList.h"
|
#include "udt/PacketList.h"
|
||||||
|
|
||||||
class NLPacketList : public PacketList {
|
class NLPacketList : public udt::PacketList {
|
||||||
public:
|
public:
|
||||||
NLPacketList(PacketType::Value packetType, QByteArray extendedHeader = QByteArray());
|
NLPacketList(PacketType::Value packetType, QByteArray extendedHeader = QByteArray());
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ private:
|
||||||
NLPacketList(const NLPacketList& other) = delete;
|
NLPacketList(const NLPacketList& other) = delete;
|
||||||
NLPacketList& operator=(const NLPacketList& other) = delete;
|
NLPacketList& operator=(const NLPacketList& other) = delete;
|
||||||
|
|
||||||
virtual std::unique_ptr<Packet> createPacket();
|
virtual std::unique_ptr<udt::Packet> createPacket();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_PacketList_h
|
#endif // hifi_PacketList_h
|
||||||
|
|
|
@ -234,7 +234,7 @@ bool PacketReceiver::packetVersionMatch(const NLPacket& packet) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PacketReceiver::handleVerifiedPacket(std::unique_ptr<Packet> packet) {
|
void PacketReceiver::handleVerifiedPacket(std::unique_ptr<udt::Packet> packet) {
|
||||||
|
|
||||||
// if we're supposed to drop this packet then break out here
|
// if we're supposed to drop this packet then break out here
|
||||||
if (_shouldDropPackets) {
|
if (_shouldDropPackets) {
|
||||||
|
|
|
@ -45,7 +45,7 @@ public:
|
||||||
bool registerListener(PacketType::Value type, QObject* listener, const char* slot);
|
bool registerListener(PacketType::Value type, QObject* listener, const char* slot);
|
||||||
void unregisterListener(QObject* listener);
|
void unregisterListener(QObject* listener);
|
||||||
|
|
||||||
void handleVerifiedPacket(std::unique_ptr<Packet> packet);
|
void handleVerifiedPacket(std::unique_ptr<udt::Packet> packet);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void dataReceived(quint8 channelType, int bytes);
|
void dataReceived(quint8 channelType, int bytes);
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
|
|
||||||
#include "Packet.h"
|
#include "Packet.h"
|
||||||
|
|
||||||
|
using namespace udt;
|
||||||
|
|
||||||
const qint64 Packet::PACKET_WRITE_ERROR = -1;
|
const qint64 Packet::PACKET_WRITE_ERROR = -1;
|
||||||
|
|
||||||
qint64 Packet::localHeaderSize(PacketType::Value type) {
|
qint64 Packet::localHeaderSize(PacketType::Value type) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//
|
//
|
||||||
// Packet.h
|
// Packet.h
|
||||||
// libraries/networking/src
|
// libraries/networking/src/udt
|
||||||
//
|
//
|
||||||
// Created by Clement on 7/2/15.
|
// Created by Clement on 7/2/15.
|
||||||
// Copyright 2015 High Fidelity, Inc.
|
// Copyright 2015 High Fidelity, Inc.
|
||||||
|
@ -19,6 +19,8 @@
|
||||||
#include "../HifiSockAddr.h"
|
#include "../HifiSockAddr.h"
|
||||||
#include "PacketHeaders.h"
|
#include "PacketHeaders.h"
|
||||||
|
|
||||||
|
namespace udt {
|
||||||
|
|
||||||
class Packet : public QIODevice {
|
class Packet : public QIODevice {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
@ -132,4 +134,6 @@ template<typename T> qint64 Packet::writePrimitive(const T& data) {
|
||||||
return QIODevice::write(reinterpret_cast<const char*>(&data), sizeof(T));
|
return QIODevice::write(reinterpret_cast<const char*>(&data), sizeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace udt
|
||||||
|
|
||||||
#endif // hifi_Packet_h
|
#endif // hifi_Packet_h
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
|
|
||||||
#include "Packet.h"
|
#include "Packet.h"
|
||||||
|
|
||||||
|
using namespace udt;
|
||||||
|
|
||||||
PacketList::PacketList(PacketType::Value packetType, QByteArray extendedHeader) :
|
PacketList::PacketList(PacketType::Value packetType, QByteArray extendedHeader) :
|
||||||
_packetType(packetType),
|
_packetType(packetType),
|
||||||
_extendedHeader(extendedHeader)
|
_extendedHeader(extendedHeader)
|
||||||
|
|
|
@ -18,6 +18,10 @@
|
||||||
|
|
||||||
#include "PacketHeaders.h"
|
#include "PacketHeaders.h"
|
||||||
|
|
||||||
|
class LimitedNodeList;
|
||||||
|
|
||||||
|
namespace udt {
|
||||||
|
|
||||||
class Packet;
|
class Packet;
|
||||||
|
|
||||||
class PacketList : public QIODevice {
|
class PacketList : public QIODevice {
|
||||||
|
@ -42,7 +46,7 @@ protected:
|
||||||
virtual qint64 readData(char* data, qint64 maxSize) { return 0; }
|
virtual qint64 readData(char* data, qint64 maxSize) { return 0; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class LimitedNodeList;
|
friend class ::LimitedNodeList;
|
||||||
|
|
||||||
PacketList(const PacketList& other) = delete;
|
PacketList(const PacketList& other) = delete;
|
||||||
PacketList& operator=(const PacketList& other) = delete;
|
PacketList& operator=(const PacketList& other) = delete;
|
||||||
|
@ -83,4 +87,6 @@ template<typename T> std::unique_ptr<T> PacketList::takeFront() {
|
||||||
return std::unique_ptr<T>(dynamic_cast<T*>(packet.release()));
|
return std::unique_ptr<T>(dynamic_cast<T*>(packet.release()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif // hifi_PacketList_h
|
#endif // hifi_PacketList_h
|
||||||
|
|
|
@ -18,7 +18,7 @@ using namespace udt;
|
||||||
Socket::Socket(QObject* parent) :
|
Socket::Socket(QObject* parent) :
|
||||||
QObject(parent)
|
QObject(parent)
|
||||||
{
|
{
|
||||||
|
connect(&_udpSocket, &QUdpSocket::readyRead, this, &Socket::readPendingDatagrams);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Socket::rebind() {
|
void Socket::rebind() {
|
||||||
|
@ -66,3 +66,23 @@ qint64 Socket::writeDatagram(const QByteArray& datagram, const HifiSockAddr& soc
|
||||||
|
|
||||||
return bytesWritten;
|
return bytesWritten;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Socket::readPendingDatagrams() {
|
||||||
|
while (_udpSocket.hasPendingDatagrams()) {
|
||||||
|
// setup a HifiSockAddr to read into
|
||||||
|
HifiSockAddr senderSockAddr;
|
||||||
|
|
||||||
|
// setup a buffer to read the packet into
|
||||||
|
int packetSizeWithHeader = _udpSocket.pendingDatagramSize();
|
||||||
|
std::unique_ptr<char> buffer = std::unique_ptr<char>(new char[packetSizeWithHeader]);
|
||||||
|
|
||||||
|
// pull the datagram
|
||||||
|
_udpSocket.readDatagram(buffer.get(), packetSizeWithHeader,
|
||||||
|
senderSockAddr.getAddressPointer(), senderSockAddr.getPortPointer());
|
||||||
|
|
||||||
|
// setup a Packet from the data we just read
|
||||||
|
auto packet = Packet::fromReceivedPacket(std::move(buffer), packetSizeWithHeader, senderSockAddr);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -44,6 +44,10 @@ public:
|
||||||
{ _verifiedPacketFunction = verifiedPacketFunction; }
|
{ _verifiedPacketFunction = verifiedPacketFunction; }
|
||||||
|
|
||||||
void setBufferSizes(int numBytes);
|
void setBufferSizes(int numBytes);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void readPendingDatagrams();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUdpSocket _udpSocket { this };
|
QUdpSocket _udpSocket { this };
|
||||||
VerifiedPacketFunction _verifiedPacketFunction;
|
VerifiedPacketFunction _verifiedPacketFunction;
|
||||||
|
|
Loading…
Reference in a new issue