mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 18:50:00 +02:00
Merge branch 'atp' of https://github.com/birarda/hifi into protocol
This commit is contained in:
commit
04ece4459c
8 changed files with 26 additions and 19 deletions
|
@ -26,7 +26,7 @@ qint64 NLPacket::maxPayloadSize() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 NLPacket::totalHeadersSize() const {
|
qint64 NLPacket::totalHeadersSize() const {
|
||||||
return localHeaderSize() + Packet::localHeaderSize();
|
return Packet::totalHeadersSize() + localHeaderSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 NLPacket::localHeaderSize() const {
|
qint64 NLPacket::localHeaderSize() const {
|
||||||
|
@ -84,7 +84,7 @@ NLPacket::NLPacket(PacketType type, bool isReliable, bool isPartOfMessage) :
|
||||||
_type(type),
|
_type(type),
|
||||||
_version(versionForPacketType(type))
|
_version(versionForPacketType(type))
|
||||||
{
|
{
|
||||||
adjustPayloadStartAndCapacity();
|
adjustPayloadStartAndCapacity(localHeaderSize());
|
||||||
|
|
||||||
writeTypeAndVersion();
|
writeTypeAndVersion();
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ NLPacket::NLPacket(PacketType type, qint64 size, bool isReliable, bool isPartOfM
|
||||||
{
|
{
|
||||||
Q_ASSERT(size >= 0);
|
Q_ASSERT(size >= 0);
|
||||||
|
|
||||||
adjustPayloadStartAndCapacity();
|
adjustPayloadStartAndCapacity(localHeaderSize());
|
||||||
|
|
||||||
writeTypeAndVersion();
|
writeTypeAndVersion();
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ NLPacket::NLPacket(std::unique_ptr<Packet> packet) :
|
||||||
readVersion();
|
readVersion();
|
||||||
readSourceID();
|
readSourceID();
|
||||||
|
|
||||||
adjustPayloadStartAndCapacity(_payloadSize > 0);
|
adjustPayloadStartAndCapacity(localHeaderSize(), _payloadSize > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
NLPacket::NLPacket(const NLPacket& other) : Packet(other) {
|
NLPacket::NLPacket(const NLPacket& other) : Packet(other) {
|
||||||
|
@ -123,7 +123,7 @@ NLPacket::NLPacket(std::unique_ptr<char> data, qint64 size, const HifiSockAddr&
|
||||||
// sanity check before we decrease the payloadSize with the payloadCapacity
|
// sanity check before we decrease the payloadSize with the payloadCapacity
|
||||||
Q_ASSERT(_payloadSize == _payloadCapacity);
|
Q_ASSERT(_payloadSize == _payloadCapacity);
|
||||||
|
|
||||||
adjustPayloadStartAndCapacity(_payloadSize > 0);
|
adjustPayloadStartAndCapacity(localHeaderSize(), _payloadSize > 0);
|
||||||
|
|
||||||
readType();
|
readType();
|
||||||
readVersion();
|
readVersion();
|
||||||
|
@ -194,7 +194,7 @@ QByteArray NLPacket::hashForPacketAndSecret(const udt::Packet& packet, const QUu
|
||||||
}
|
}
|
||||||
|
|
||||||
void NLPacket::writeTypeAndVersion() {
|
void NLPacket::writeTypeAndVersion() {
|
||||||
auto headerOffset = Packet::totalHeadersSize();
|
auto headerOffset = Packet::localHeaderSize();
|
||||||
|
|
||||||
// Pack the packet type
|
// Pack the packet type
|
||||||
memcpy(_packet.get() + headerOffset, &_type, sizeof(PacketType));
|
memcpy(_packet.get() + headerOffset, &_type, sizeof(PacketType));
|
||||||
|
|
|
@ -252,6 +252,7 @@ void NodeList::sendDomainServerCheckIn() {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto domainPacket = NLPacket::create(domainPacketType);
|
auto domainPacket = NLPacket::create(domainPacketType);
|
||||||
|
|
||||||
QDataStream packetStream(domainPacket.get());
|
QDataStream packetStream(domainPacket.get());
|
||||||
|
|
||||||
if (domainPacketType == PacketType::DomainConnectRequest) {
|
if (domainPacketType == PacketType::DomainConnectRequest) {
|
||||||
|
|
|
@ -177,8 +177,7 @@ qint64 BasePacket::readData(char* dest, qint64 maxSize) {
|
||||||
return numBytesToRead;
|
return numBytesToRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BasePacket::adjustPayloadStartAndCapacity(bool shouldDecreasePayloadSize) {
|
void BasePacket::adjustPayloadStartAndCapacity(qint64 headerSize, bool shouldDecreasePayloadSize) {
|
||||||
qint64 headerSize = localHeaderSize();
|
|
||||||
_payloadStart += headerSize;
|
_payloadStart += headerSize;
|
||||||
_payloadCapacity -= headerSize;
|
_payloadCapacity -= headerSize;
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,7 @@ protected:
|
||||||
virtual qint64 writeData(const char* data, qint64 maxSize);
|
virtual qint64 writeData(const char* data, qint64 maxSize);
|
||||||
virtual qint64 readData(char* data, qint64 maxSize);
|
virtual qint64 readData(char* data, qint64 maxSize);
|
||||||
|
|
||||||
virtual void adjustPayloadStartAndCapacity(bool shouldDecreasePayloadSize = false);
|
virtual void adjustPayloadStartAndCapacity(qint64 headerSize, bool shouldDecreasePayloadSize = false);
|
||||||
|
|
||||||
qint64 _packetSize = 0; // Total size of the allocated memory
|
qint64 _packetSize = 0; // Total size of the allocated memory
|
||||||
std::unique_ptr<char> _packet; // Allocated memory
|
std::unique_ptr<char> _packet; // Allocated memory
|
||||||
|
|
|
@ -25,7 +25,8 @@ namespace udt {
|
||||||
static const int UDP_SEND_BUFFER_SIZE_BYTES = 1048576;
|
static const int UDP_SEND_BUFFER_SIZE_BYTES = 1048576;
|
||||||
static const int UDP_RECEIVE_BUFFER_SIZE_BYTES = 1048576;
|
static const int UDP_RECEIVE_BUFFER_SIZE_BYTES = 1048576;
|
||||||
static const int DEFAULT_SYN_INTERVAL_USECS = 10 * 1000;
|
static const int DEFAULT_SYN_INTERVAL_USECS = 10 * 1000;
|
||||||
static const uint32_t CONTROL_BIT_MASK = 1 << (sizeof(SequenceNumber) - 1);
|
static const int SEQUENCE_NUMBER_BITS = sizeof(SequenceNumber) * 8;
|
||||||
|
static const uint32_t CONTROL_BIT_MASK = uint32_t(1) << (SEQUENCE_NUMBER_BITS - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // hifi_udt_Constants_h
|
#endif // hifi_udt_Constants_h
|
||||||
|
|
|
@ -57,7 +57,7 @@ ControlPacket::ControlPacket(Type type) :
|
||||||
BasePacket(-1),
|
BasePacket(-1),
|
||||||
_type(type)
|
_type(type)
|
||||||
{
|
{
|
||||||
adjustPayloadStartAndCapacity();
|
adjustPayloadStartAndCapacity(localHeaderSize());
|
||||||
|
|
||||||
open(QIODevice::ReadWrite);
|
open(QIODevice::ReadWrite);
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ ControlPacket::ControlPacket(Type type, qint64 size) :
|
||||||
BasePacket(localHeaderSize() + size),
|
BasePacket(localHeaderSize() + size),
|
||||||
_type(type)
|
_type(type)
|
||||||
{
|
{
|
||||||
adjustPayloadStartAndCapacity();
|
adjustPayloadStartAndCapacity(localHeaderSize());
|
||||||
|
|
||||||
open(QIODevice::ReadWrite);
|
open(QIODevice::ReadWrite);
|
||||||
|
|
||||||
|
@ -119,12 +119,14 @@ void ControlPacket::writeType() {
|
||||||
ControlBitAndType* bitAndType = reinterpret_cast<ControlBitAndType*>(_packet.get());
|
ControlBitAndType* bitAndType = reinterpret_cast<ControlBitAndType*>(_packet.get());
|
||||||
|
|
||||||
// write the type by OR'ing the new type with the current value & CONTROL_BIT_MASK
|
// write the type by OR'ing the new type with the current value & CONTROL_BIT_MASK
|
||||||
*bitAndType = (*bitAndType & CONTROL_BIT_MASK) | (_type << sizeof((ControlPacket::Type) - 1));
|
*bitAndType = (*bitAndType & CONTROL_BIT_MASK) | (_type << (sizeof(ControlPacket::Type) * 8 - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ControlPacket::readType() {
|
void ControlPacket::readType() {
|
||||||
ControlBitAndType bitAndType = *reinterpret_cast<ControlBitAndType*>(_packet.get());
|
ControlBitAndType bitAndType = *reinterpret_cast<ControlBitAndType*>(_packet.get());
|
||||||
|
|
||||||
|
Q_ASSERT_X(bitAndType & CONTROL_BIT_MASK, "ControlPacket::readHeader()", "This should be a control packet");
|
||||||
|
|
||||||
// read the type
|
// read the type
|
||||||
uint32_t oversizeType = (uint32_t) (bitAndType & ~CONTROL_BIT_MASK);
|
uint32_t oversizeType = (uint32_t) (bitAndType & ~CONTROL_BIT_MASK);
|
||||||
_type = (Type) oversizeType;
|
_type = (Type) oversizeType;
|
||||||
|
|
|
@ -50,7 +50,7 @@ qint64 Packet::maxPayloadSize() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 Packet::totalHeadersSize() const {
|
qint64 Packet::totalHeadersSize() const {
|
||||||
return BasePacket::localHeaderSize() + localHeaderSize();
|
return BasePacket::totalHeadersSize() + Packet::localHeaderSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 Packet::localHeaderSize() const {
|
qint64 Packet::localHeaderSize() const {
|
||||||
|
@ -62,7 +62,7 @@ Packet::Packet(qint64 size, bool isReliable, bool isPartOfMessage) :
|
||||||
_isReliable(isReliable),
|
_isReliable(isReliable),
|
||||||
_isPartOfMessage(isPartOfMessage)
|
_isPartOfMessage(isPartOfMessage)
|
||||||
{
|
{
|
||||||
adjustPayloadStartAndCapacity();
|
adjustPayloadStartAndCapacity(localHeaderSize());
|
||||||
|
|
||||||
// set the UDT header to default values
|
// set the UDT header to default values
|
||||||
writeHeader();
|
writeHeader();
|
||||||
|
@ -117,14 +117,15 @@ void Packet::writeSequenceNumber(SequenceNumber sequenceNumber) const {
|
||||||
writeHeader();
|
writeHeader();
|
||||||
}
|
}
|
||||||
|
|
||||||
static const uint32_t RELIABILITY_BIT_MASK = 1 << (sizeof(Packet::SequenceNumberAndBitField) - 2);
|
static const uint32_t RELIABILITY_BIT_MASK = uint32_t(1) << (SEQUENCE_NUMBER_BITS - 2);
|
||||||
static const uint32_t MESSAGE_BIT_MASK = 1 << (sizeof(Packet::SequenceNumberAndBitField) - 3);
|
static const uint32_t MESSAGE_BIT_MASK = uint32_t(1) << (SEQUENCE_NUMBER_BITS - 3);
|
||||||
static const uint32_t BIT_FIELD_MASK = CONTROL_BIT_MASK | RELIABILITY_BIT_MASK | MESSAGE_BIT_MASK;
|
static const uint32_t BIT_FIELD_MASK = CONTROL_BIT_MASK | RELIABILITY_BIT_MASK | MESSAGE_BIT_MASK;
|
||||||
|
|
||||||
void Packet::readHeader() const {
|
void Packet::readHeader() const {
|
||||||
SequenceNumberAndBitField seqNumBitField = *reinterpret_cast<SequenceNumberAndBitField*>(_packet.get());
|
SequenceNumberAndBitField seqNumBitField = *reinterpret_cast<SequenceNumberAndBitField*>(_packet.get());
|
||||||
Q_ASSERT_X((bool) (seqNumBitField & CONTROL_BIT_MASK),
|
|
||||||
"Packet::readHeader()", "This should be a data packet");
|
Q_ASSERT_X(!(seqNumBitField & CONTROL_BIT_MASK), "Packet::readHeader()", "This should be a data packet");
|
||||||
|
|
||||||
_isReliable = (bool) (seqNumBitField & RELIABILITY_BIT_MASK); // Only keep reliability bit
|
_isReliable = (bool) (seqNumBitField & RELIABILITY_BIT_MASK); // Only keep reliability bit
|
||||||
_isPartOfMessage = (bool) (seqNumBitField & MESSAGE_BIT_MASK); // Only keep message bit
|
_isPartOfMessage = (bool) (seqNumBitField & MESSAGE_BIT_MASK); // Only keep message bit
|
||||||
_sequenceNumber = SequenceNumber{ seqNumBitField & ~BIT_FIELD_MASK }; // Remove the bit field
|
_sequenceNumber = SequenceNumber{ seqNumBitField & ~BIT_FIELD_MASK }; // Remove the bit field
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "Connection.h"
|
#include "Connection.h"
|
||||||
#include "ControlPacket.h"
|
#include "ControlPacket.h"
|
||||||
#include "Packet.h"
|
#include "Packet.h"
|
||||||
|
#include "../NLPacket.h"
|
||||||
|
|
||||||
using namespace udt;
|
using namespace udt;
|
||||||
|
|
||||||
|
@ -139,6 +140,8 @@ void Socket::readPendingDatagrams() {
|
||||||
// check if this was a control packet or a data packet
|
// check if this was a control packet or a data packet
|
||||||
bool isControlPacket = *buffer & CONTROL_BIT_MASK;
|
bool isControlPacket = *buffer & CONTROL_BIT_MASK;
|
||||||
|
|
||||||
|
qDebug() << "IS CONTROL" << isControlPacket;
|
||||||
|
|
||||||
if (isControlPacket) {
|
if (isControlPacket) {
|
||||||
// setup a control packet from the data we just read
|
// setup a control packet from the data we just read
|
||||||
auto controlPacket = ControlPacket::fromReceivedPacket(std::move(buffer), packetSizeWithHeader, senderSockAddr);
|
auto controlPacket = ControlPacket::fromReceivedPacket(std::move(buffer), packetSizeWithHeader, senderSockAddr);
|
||||||
|
|
Loading…
Reference in a new issue