mirror of
https://github.com/lubosz/overte.git
synced 2025-04-24 18:23:22 +02:00
added code to parse nack packets in OctreeEditPacketSender
This commit is contained in:
parent
14f50f4576
commit
ddfe98ad43
2 changed files with 67 additions and 3 deletions
|
@ -17,6 +17,43 @@
|
|||
#include <PacketHeaders.h>
|
||||
#include "OctreeEditPacketSender.h"
|
||||
|
||||
void NackedPacketHistory::packetSent(const QByteArray& packet) {
|
||||
// extract sequence number for the sent packet history
|
||||
int numBytesPacketHeader = numBytesForPacketHeader(packet);
|
||||
const char* dataAt = reinterpret_cast<const char*>(packet.data());
|
||||
unsigned short int sequence = (*((unsigned short int*)(dataAt + numBytesPacketHeader)));
|
||||
|
||||
// add packet to history
|
||||
_sentPacketHistory.packetSent(sequence, packet);
|
||||
}
|
||||
|
||||
bool NackedPacketHistory::hasNextNackedPacket() const {
|
||||
return !_nackedSequenceNumbers.isEmpty();
|
||||
}
|
||||
|
||||
const QByteArray* NackedPacketHistory::getNextNackedPacket() {
|
||||
if (!_nackedSequenceNumbers.isEmpty()) {
|
||||
// could return null if packet is not in the history
|
||||
return _sentPacketHistory.getPacket(_nackedSequenceNumbers.dequeue());
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void NackedPacketHistory::parseNackPacket(const QByteArray& packet) {
|
||||
int numBytesPacketHeader = numBytesForPacketHeader(packet);
|
||||
const unsigned char* dataAt = reinterpret_cast<const unsigned char*>(packet.data()) + numBytesPacketHeader;
|
||||
|
||||
// read number of sequence numbers
|
||||
uint16_t numSequenceNumbers = (*(uint16_t*)dataAt);
|
||||
dataAt += sizeof(uint16_t);
|
||||
|
||||
// read sequence numbers
|
||||
for (int i = 0; i < numSequenceNumbers; i++) {
|
||||
unsigned short int sequenceNumber = (*(unsigned short int*)dataAt);
|
||||
_nackedSequenceNumbers.enqueue(sequenceNumber);
|
||||
dataAt += sizeof(unsigned short int);
|
||||
}
|
||||
}
|
||||
|
||||
EditPacketBuffer::EditPacketBuffer(PacketType type, unsigned char* buffer, ssize_t length, QUuid nodeUUID) :
|
||||
_nodeUUID(nodeUUID),
|
||||
|
@ -97,9 +134,9 @@ void OctreeEditPacketSender::queuePacketToNode(const QUuid& nodeUUID, unsigned c
|
|||
if (node->getType() == getMyNodeType() &&
|
||||
((node->getUUID() == nodeUUID) || (nodeUUID.isNull()))) {
|
||||
if (node->getActiveSocket()) {
|
||||
queuePacketForSending(node, QByteArray(reinterpret_cast<char*>(buffer), length));
|
||||
|
||||
|
||||
QByteArray packet(reinterpret_cast<char*>(buffer), length);
|
||||
queuePacketForSending(node, packet);
|
||||
_nackedPacketHistories[nodeUUID].packetSent(packet);
|
||||
|
||||
// debugging output...
|
||||
bool wantDebugging = false;
|
||||
|
@ -338,3 +375,9 @@ bool OctreeEditPacketSender::process() {
|
|||
// base class does most of the work.
|
||||
return PacketSender::process();
|
||||
}
|
||||
|
||||
void OctreeEditPacketSender::parseNackPacket(const QByteArray& packet) {
|
||||
// parse sending node from packet
|
||||
QUuid sendingNodeUUID = uuidFromPacketHeader(packet);
|
||||
_nackedPacketHistories[sendingNodeUUID].parseNackPacket(packet);
|
||||
}
|
||||
|
|
|
@ -12,9 +12,24 @@
|
|||
#ifndef hifi_OctreeEditPacketSender_h
|
||||
#define hifi_OctreeEditPacketSender_h
|
||||
|
||||
#include <qqueue.h>
|
||||
#include <PacketSender.h>
|
||||
#include <PacketHeaders.h>
|
||||
#include "JurisdictionMap.h"
|
||||
#include "SentPacketHistory.h"
|
||||
|
||||
class NackedPacketHistory {
|
||||
public:
|
||||
NackedPacketHistory() : _sentPacketHistory(1000), _nackedSequenceNumbers() { }
|
||||
public:
|
||||
void packetSent(const QByteArray& packet);
|
||||
bool hasNextNackedPacket() const;
|
||||
const QByteArray* getNextNackedPacket();
|
||||
void parseNackPacket(const QByteArray& packet);
|
||||
private:
|
||||
SentPacketHistory _sentPacketHistory;
|
||||
QQueue<unsigned short int> _nackedSequenceNumbers;
|
||||
};
|
||||
|
||||
/// Used for construction of edit packets
|
||||
class EditPacketBuffer {
|
||||
|
@ -90,6 +105,9 @@ public:
|
|||
virtual char getMyNodeType() const = 0;
|
||||
virtual void adjustEditPacketForClockSkew(unsigned char* codeColorBuffer, ssize_t length, int clockSkew) { };
|
||||
|
||||
public:
|
||||
void parseNackPacket(const QByteArray& packet);
|
||||
|
||||
protected:
|
||||
bool _shouldSend;
|
||||
void queuePacketToNode(const QUuid& nodeID, unsigned char* buffer, ssize_t length);
|
||||
|
@ -114,5 +132,8 @@ protected:
|
|||
|
||||
unsigned short int _sequenceNumber;
|
||||
int _maxPacketSize;
|
||||
|
||||
// TODO: garbage-collect this
|
||||
QHash<QUuid, NackedPacketHistory> _nackedPacketHistories;
|
||||
};
|
||||
#endif // hifi_OctreeEditPacketSender_h
|
||||
|
|
Loading…
Reference in a new issue