mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 04:44:11 +02:00
resolve conflicts on merge with Atlante45/protocol
This commit is contained in:
commit
6d502405ef
5 changed files with 59 additions and 45 deletions
|
@ -38,6 +38,7 @@
|
|||
#include "Node.h"
|
||||
#include "NLPacket.h"
|
||||
#include "PacketHeaders.h"
|
||||
#include "PacketList.h"
|
||||
#include "UUIDHasher.h"
|
||||
|
||||
const int MAX_PACKET_SIZE = 1450;
|
||||
|
@ -67,6 +68,7 @@ Q_DECLARE_METATYPE(SharedNodePointer)
|
|||
using namespace tbb;
|
||||
typedef std::pair<QUuid, SharedNodePointer> UUIDNodePair;
|
||||
typedef concurrent_unordered_map<QUuid, SharedNodePointer, UUIDHasher> NodeHash;
|
||||
using NLPacketList = PacketList<NLPacket>;
|
||||
|
||||
typedef quint8 PingType_t;
|
||||
namespace PingType {
|
||||
|
@ -147,8 +149,8 @@ public:
|
|||
qint64 sendUnreliablePacket(std::unique_ptr<NLPacket>& packet, const HifiSockAddr& sockAddr) {};
|
||||
qint64 sendPacket(std::unique_ptr<NLPacket> packet, const SharedNodePointer& destinationNode) {};
|
||||
qint64 sendPacket(std::unique_ptr<NLPacket> packet, const HifiSockAddr& sockAddr) {};
|
||||
qint64 sendPacketList(PacketList& packetList, const SharedNodePointer& destinationNode) {};
|
||||
qint64 sendPacketList(PacketList& packetList, const HifiSockAddr& sockAddr) {};
|
||||
qint64 sendPacketList(NLPacketList& packetList, const SharedNodePointer& destinationNode) {};
|
||||
qint64 sendPacketList(NLPacketList& packetList, const HifiSockAddr& sockAddr) {};
|
||||
|
||||
void (*linkedDataCreateCallback)(Node *);
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
/// Storage of not-yet processed inbound, or not yet sent outbound generic UDP network packet
|
||||
class NetworkPacket {
|
||||
public:
|
||||
NetworkPacket() { }
|
||||
NetworkPacket();
|
||||
NetworkPacket(const NetworkPacket& packet); // copy constructor
|
||||
NetworkPacket& operator= (const NetworkPacket& other); // copy assignment
|
||||
|
||||
|
|
|
@ -38,6 +38,12 @@ std::unique_ptr<Packet> Packet::create(PacketType::Value type, qint64 size) {
|
|||
return std::unique_ptr<Packet>(new Packet(type, size));
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<Packet> Packet::createCopy(const std::unique_ptr<Packet>& other) {
|
||||
Q_ASSERT(other);
|
||||
return std::unique_ptr<Packet>(new Packet(*other));
|
||||
}
|
||||
|
||||
qint64 Packet::totalHeadersSize() const {
|
||||
return localHeaderSize();
|
||||
}
|
||||
|
@ -56,11 +62,11 @@ Packet::Packet(PacketType::Value type, qint64 size) :
|
|||
Q_ASSERT(size <= maxPayloadSize(type));
|
||||
|
||||
// copy packet type and version in header
|
||||
setPacketTypeAndVersion(type);
|
||||
writePacketTypeAndVersion(type);
|
||||
|
||||
// Set control bit and sequence number to 0 if necessary
|
||||
if (SEQUENCE_NUMBERED_PACKETS.contains(type)) {
|
||||
setSequenceNumber(0);
|
||||
writeSequenceNumber(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,7 +80,6 @@ Packet& Packet::operator=(const Packet& other) {
|
|||
memcpy(_packet.get(), other._packet.get(), _packetSize);
|
||||
|
||||
_payloadStart = _packet.get() + (other._payloadStart - other._packet.get());
|
||||
_position = other._position;
|
||||
_capacity = other._capacity;
|
||||
|
||||
_sizeUsed = other._sizeUsed;
|
||||
|
@ -91,7 +96,6 @@ Packet& Packet::operator=(Packet&& other) {
|
|||
_packet = std::move(other._packet);
|
||||
|
||||
_payloadStart = other._payloadStart;
|
||||
_position = other._position;
|
||||
_capacity = other._capacity;
|
||||
|
||||
_sizeUsed = other._sizeUsed;
|
||||
|
@ -99,15 +103,24 @@ Packet& Packet::operator=(Packet&& other) {
|
|||
return *this;
|
||||
}
|
||||
|
||||
PacketType::Value Packet::getPacketType() const {
|
||||
void Packet::setPacketType(PacketType::Value type) {
|
||||
auto currentHeaderSize = totalHeadersSize();
|
||||
_type = type;
|
||||
writePacketTypeAndVersion(_type);
|
||||
|
||||
// Setting new packet type with a different header size not currently supported
|
||||
Q_ASSERT(currentHeaderSize == totalHeadersSize());
|
||||
}
|
||||
|
||||
PacketType::Value Packet::readPacketType() const {
|
||||
return (PacketType::Value)arithmeticCodingValueFromBuffer(_packet.get());
|
||||
}
|
||||
|
||||
PacketVersion Packet::getPacketTypeVersion() const {
|
||||
PacketVersion Packet::readPacketTypeVersion() const {
|
||||
return *reinterpret_cast<PacketVersion*>(_packet.get() + numBytesForArithmeticCodedPacketType(_type));
|
||||
}
|
||||
|
||||
Packet::SequenceNumber Packet::getSequenceNumber() const {
|
||||
Packet::SequenceNumber Packet::readSequenceNumber() const {
|
||||
if (SEQUENCE_NUMBERED_PACKETS.contains(_type)) {
|
||||
SequenceNumber seqNum = *reinterpret_cast<SequenceNumber*>(_packet.get() +
|
||||
numBytesForArithmeticCodedPacketType(_type) +
|
||||
|
@ -117,7 +130,7 @@ Packet::SequenceNumber Packet::getSequenceNumber() const {
|
|||
return -1;
|
||||
}
|
||||
|
||||
bool Packet::isControlPacket() const {
|
||||
bool Packet::readIsControlPacket() const {
|
||||
if (SEQUENCE_NUMBERED_PACKETS.contains(_type)) {
|
||||
SequenceNumber seqNum = *reinterpret_cast<SequenceNumber*>(_packet.get() +
|
||||
numBytesForArithmeticCodedPacketType(_type) +
|
||||
|
@ -127,16 +140,16 @@ bool Packet::isControlPacket() const {
|
|||
return false;
|
||||
}
|
||||
|
||||
void Packet::setPacketTypeAndVersion(PacketType::Value type) {
|
||||
void Packet::writePacketTypeAndVersion(PacketType::Value type) {
|
||||
// Pack the packet type
|
||||
auto offset = packArithmeticallyCodedValue(type, _packet.get());
|
||||
|
||||
// Pack the packet version
|
||||
auto version { versionForPacketType(type) };
|
||||
auto version = versionForPacketType(type);
|
||||
memcpy(_packet.get() + offset, &version, sizeof(version));
|
||||
}
|
||||
|
||||
void Packet::setSequenceNumber(SequenceNumber seqNum) {
|
||||
void Packet::writeSequenceNumber(SequenceNumber seqNum) {
|
||||
// Here we are overriding the control bit to 0.
|
||||
// But that is not an issue since we should only ever set the seqNum
|
||||
// for data packets going out
|
||||
|
@ -144,14 +157,6 @@ void Packet::setSequenceNumber(SequenceNumber seqNum) {
|
|||
&seqNum, sizeof(seqNum));
|
||||
}
|
||||
|
||||
bool Packet::seek(qint64 pos) {
|
||||
bool valid = (pos >= 0) && (pos < size());
|
||||
if (valid) {
|
||||
_position = pos;
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
||||
static const qint64 PACKET_WRITE_ERROR = -1;
|
||||
qint64 Packet::writeData(const char* data, qint64 maxSize) {
|
||||
// make sure we have the space required to write this block
|
||||
|
|
|
@ -23,6 +23,8 @@ public:
|
|||
using SequenceNumber = uint16_t;
|
||||
|
||||
static std::unique_ptr<Packet> create(PacketType::Value type, int64_t size = -1);
|
||||
// Provided for convenience, try to limit use
|
||||
static std::unique_ptr<Packet> createCopy(const std::unique_ptr<Packet>& other);
|
||||
|
||||
static qint64 localHeaderSize(PacketType::Value type);
|
||||
static qint64 maxPayloadSize(PacketType::Value type);
|
||||
|
@ -30,56 +32,59 @@ public:
|
|||
virtual qint64 totalHeadersSize() const; // Cumulated size of all the headers
|
||||
virtual qint64 localHeaderSize() const; // Current level's header size
|
||||
|
||||
// Payload direct access, use responsibly!
|
||||
// Payload direct access to the payload, use responsibly!
|
||||
char* getPayload() { return _payloadStart; }
|
||||
const char* getPayload() const { return _payloadStart; }
|
||||
|
||||
// Return direct access to the entire packet, use responsibly!
|
||||
char* getData() { return _packet.get(); }
|
||||
const char* getData() const { return _packet.get(); }
|
||||
|
||||
PacketType::Value getPacketType() const { return _type; }
|
||||
void setPacketType(PacketType::Value type);
|
||||
|
||||
qint64 getSizeWithHeader() const { return localHeaderSize() + getSizeUsed(); }
|
||||
qint64 getSizeUsed() const { return _sizeUsed; }
|
||||
void setSizeUsed(qint64 sizeUsed) { _sizeUsed = sizeUsed; }
|
||||
|
||||
// Header readers
|
||||
PacketType::Value getPacketType() const;
|
||||
PacketVersion getPacketTypeVersion() const;
|
||||
SequenceNumber getSequenceNumber() const;
|
||||
bool isControlPacket() const;
|
||||
PacketType::Value readPacketType() const;
|
||||
PacketVersion readPacketTypeVersion() const;
|
||||
SequenceNumber readSequenceNumber() const;
|
||||
bool readIsControlPacket() const;
|
||||
|
||||
// QIODevice virtual functions
|
||||
// WARNING: Those methods all refer to the payload ONLY and NOT the entire packet
|
||||
virtual bool atEnd() const { return _position == _capacity; }
|
||||
virtual qint64 bytesAvailable() const { return size() - pos(); }
|
||||
virtual bool canReadLine() const { return false; }
|
||||
virtual bool isSequential() const { return false; }
|
||||
virtual qint64 pos() const { return _position; }
|
||||
virtual bool reset() { return seek(0); }
|
||||
virtual bool seek(qint64 pos);
|
||||
virtual bool reset() { setSizeUsed(0); return QIODevice::reset(); }
|
||||
virtual qint64 size() const { return _capacity; }
|
||||
|
||||
protected:
|
||||
Packet(PacketType::Value type, int64_t size);
|
||||
Packet(const Packet& other);
|
||||
Packet& operator=(const Packet& other);
|
||||
Packet(Packet&& other);
|
||||
Packet& operator=(Packet&& other);
|
||||
|
||||
// QIODevice virtual functions
|
||||
virtual qint64 writeData(const char* data, qint64 maxSize);
|
||||
virtual qint64 readData(char* data, qint64 maxSize);
|
||||
|
||||
// Header writers
|
||||
void setPacketTypeAndVersion(PacketType::Value type);
|
||||
void setSequenceNumber(SequenceNumber seqNum);
|
||||
void writePacketTypeAndVersion(PacketType::Value type);
|
||||
void writeSequenceNumber(SequenceNumber seqNum);
|
||||
|
||||
PacketType::Value _type;
|
||||
PacketType::Value _type; // Packet type
|
||||
|
||||
qint64 _packetSize = 0; // Total size of the allocated memory
|
||||
std::unique_ptr<char> _packet; // Allocated memory
|
||||
|
||||
char* _payloadStart = nullptr; // Start of the payload
|
||||
qint64 _position = 0; // Current position in the payload
|
||||
qint64 _capacity = 0; // Total capacity of the payload
|
||||
|
||||
qint64 _sizeUsed = 0; // How much of the payload is actually used
|
||||
|
||||
private:
|
||||
Packet(const Packet& other);
|
||||
Packet& operator=(const Packet& other);
|
||||
Packet(Packet&& other);
|
||||
Packet& operator=(Packet&& other);
|
||||
};
|
||||
|
||||
#endif // hifi_Packet_h
|
|
@ -12,7 +12,9 @@
|
|||
#ifndef hifi_PacketList_h
|
||||
#define hifi_PacketList_h
|
||||
|
||||
#pragma once
|
||||
#include <QIODevice>
|
||||
|
||||
#include "PacketHeaders.h"
|
||||
|
||||
template <class T> class PacketList : public QIODevice {
|
||||
public:
|
||||
|
@ -20,7 +22,7 @@ public:
|
|||
|
||||
virtual bool isSequential() const { return true; }
|
||||
|
||||
void startSegment() { _segmentStartIndex = currentPacket->payload().pos(); }
|
||||
void startSegment() { _segmentStartIndex = _currentPacket->payload().pos(); }
|
||||
void endSegment() { _segmentStartIndex = -1; }
|
||||
|
||||
void closeCurrentPacket();
|
||||
|
@ -28,7 +30,7 @@ public:
|
|||
void setExtendedHeader(const QByteArray& extendedHeader) { _extendedHeader = extendedHeader; }
|
||||
protected:
|
||||
qint64 writeData(const char* data, qint64 maxSize);
|
||||
qint64 readData(const char* data, qint64 maxSize) { return 0 };
|
||||
qint64 readData(const char* data, qint64 maxSize) { return 0; };
|
||||
private:
|
||||
std::unique_ptr<NLPacket> createPacketWithExtendedHeader();
|
||||
|
||||
|
@ -40,7 +42,7 @@ private:
|
|||
|
||||
int _segmentStartIndex = -1;
|
||||
|
||||
QByteArray _extendedHeader = extendedHeader;
|
||||
QByteArray _extendedHeader;
|
||||
};
|
||||
|
||||
#endif // hifi_PacketList_h
|
||||
|
|
Loading…
Reference in a new issue