mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
Reordering testing.
This commit is contained in:
parent
ee2984ce6d
commit
e9579feef5
4 changed files with 40 additions and 4 deletions
|
@ -20,7 +20,8 @@ const int MAX_DATAGRAM_SIZE = MAX_PACKET_SIZE;
|
||||||
|
|
||||||
const int DEFAULT_MAX_PACKET_SIZE = 3000;
|
const int DEFAULT_MAX_PACKET_SIZE = 3000;
|
||||||
|
|
||||||
DatagramSequencer::DatagramSequencer(const QByteArray& datagramHeader) :
|
DatagramSequencer::DatagramSequencer(const QByteArray& datagramHeader, QObject* parent) :
|
||||||
|
QObject(parent),
|
||||||
_outgoingPacketStream(&_outgoingPacketData, QIODevice::WriteOnly),
|
_outgoingPacketStream(&_outgoingPacketData, QIODevice::WriteOnly),
|
||||||
_outputStream(_outgoingPacketStream),
|
_outputStream(_outgoingPacketStream),
|
||||||
_incomingDatagramStream(&_incomingDatagramBuffer),
|
_incomingDatagramStream(&_incomingDatagramBuffer),
|
||||||
|
@ -397,6 +398,10 @@ bool CircularBuffer::atEnd() const {
|
||||||
return _offset >= _size;
|
return _offset >= _size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qint64 CircularBuffer::bytesAvailable() const {
|
||||||
|
return _size - _offset + QIODevice::bytesAvailable();
|
||||||
|
}
|
||||||
|
|
||||||
bool CircularBuffer::canReadLine() const {
|
bool CircularBuffer::canReadLine() const {
|
||||||
for (int offset = _offset; offset < _size; offset++) {
|
for (int offset = _offset; offset < _size; offset++) {
|
||||||
if (_data.at((_position + offset) % _data.size()) == '\n') {
|
if (_data.at((_position + offset) % _data.size()) == '\n') {
|
||||||
|
|
|
@ -32,7 +32,7 @@ public:
|
||||||
int firstPacketNumber;
|
int firstPacketNumber;
|
||||||
};
|
};
|
||||||
|
|
||||||
DatagramSequencer(const QByteArray& datagramHeader = QByteArray());
|
DatagramSequencer(const QByteArray& datagramHeader = QByteArray(), QObject* parent = NULL);
|
||||||
|
|
||||||
/// Returns the packet number of the last packet sent.
|
/// Returns the packet number of the last packet sent.
|
||||||
int getOutgoingPacketNumber() const { return _outgoingPacketNumber; }
|
int getOutgoingPacketNumber() const { return _outgoingPacketNumber; }
|
||||||
|
@ -195,6 +195,7 @@ public:
|
||||||
void appendToBuffer(int offset, int length, CircularBuffer& buffer) const;
|
void appendToBuffer(int offset, int length, CircularBuffer& buffer) const;
|
||||||
|
|
||||||
virtual bool atEnd() const;
|
virtual bool atEnd() const;
|
||||||
|
virtual qint64 bytesAvailable() const;
|
||||||
virtual bool canReadLine() const;
|
virtual bool canReadLine() const;
|
||||||
virtual bool open(OpenMode flags);
|
virtual bool open(OpenMode flags);
|
||||||
virtual qint64 pos() const;
|
virtual qint64 pos() const;
|
||||||
|
|
|
@ -76,7 +76,7 @@ static QByteArray createRandomBytes() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Endpoint::Endpoint(const QByteArray& datagramHeader) :
|
Endpoint::Endpoint(const QByteArray& datagramHeader) :
|
||||||
_sequencer(new DatagramSequencer(datagramHeader)),
|
_sequencer(new DatagramSequencer(datagramHeader, this)),
|
||||||
_highPriorityMessagesToSend(0.0f) {
|
_highPriorityMessagesToSend(0.0f) {
|
||||||
|
|
||||||
connect(_sequencer, SIGNAL(readyToWrite(const QByteArray&)), SLOT(sendDatagram(const QByteArray&)));
|
connect(_sequencer, SIGNAL(readyToWrite(const QByteArray&)), SLOT(sendDatagram(const QByteArray&)));
|
||||||
|
@ -136,6 +136,18 @@ static bool messagesEqual(const QVariant& firstMessage, const QVariant& secondMe
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Endpoint::simulate(int iterationNumber) {
|
bool Endpoint::simulate(int iterationNumber) {
|
||||||
|
// update/send our delayed datagrams
|
||||||
|
for (QList<QPair<QByteArray, int> >::iterator it = _delayedDatagrams.begin(); it != _delayedDatagrams.end(); ) {
|
||||||
|
if (it->second-- == 1) {
|
||||||
|
_other->_sequencer->receivedDatagram(it->first);
|
||||||
|
datagramsReceived++;
|
||||||
|
it = _delayedDatagrams.erase(it);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// enqueue some number of high priority messages
|
// enqueue some number of high priority messages
|
||||||
const float MIN_HIGH_PRIORITY_MESSAGES = 0.0f;
|
const float MIN_HIGH_PRIORITY_MESSAGES = 0.0f;
|
||||||
const float MAX_HIGH_PRIORITY_MESSAGES = 2.0f;
|
const float MAX_HIGH_PRIORITY_MESSAGES = 2.0f;
|
||||||
|
@ -177,10 +189,27 @@ void Endpoint::sendDatagram(const QByteArray& datagram) {
|
||||||
datagramsSent++;
|
datagramsSent++;
|
||||||
|
|
||||||
// some datagrams are dropped
|
// some datagrams are dropped
|
||||||
const float DROP_PROBABILITY = 0.25f;
|
const float DROP_PROBABILITY = 0.1f;
|
||||||
if (randFloat() < DROP_PROBABILITY) {
|
if (randFloat() < DROP_PROBABILITY) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// some are received out of order
|
||||||
|
const float REORDER_PROBABILITY = 0.1f;
|
||||||
|
if (randFloat() < REORDER_PROBABILITY) {
|
||||||
|
const int MIN_DELAY = 1;
|
||||||
|
const int MAX_DELAY = 5;
|
||||||
|
// have to copy the datagram; the one we're passed is a reference to a shared buffer
|
||||||
|
_delayedDatagrams.append(QPair<QByteArray, int>(QByteArray(datagram.constData(), datagram.size()),
|
||||||
|
randIntInRange(MIN_DELAY, MAX_DELAY)));
|
||||||
|
|
||||||
|
// and some are duplicated
|
||||||
|
const float DUPLICATE_PROBABILITY = 0.01f;
|
||||||
|
if (randFloat() > DUPLICATE_PROBABILITY) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_other->_sequencer->receivedDatagram(datagram);
|
_other->_sequencer->receivedDatagram(datagram);
|
||||||
datagramsReceived++;
|
datagramsReceived++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,7 @@ private:
|
||||||
|
|
||||||
DatagramSequencer* _sequencer;
|
DatagramSequencer* _sequencer;
|
||||||
Endpoint* _other;
|
Endpoint* _other;
|
||||||
|
QList<QPair<QByteArray, int> > _delayedDatagrams;
|
||||||
float _highPriorityMessagesToSend;
|
float _highPriorityMessagesToSend;
|
||||||
QVariantList _highPriorityMessagesSent;
|
QVariantList _highPriorityMessagesSent;
|
||||||
QList<SequencedTestMessage> _unreliableMessagesSent;
|
QList<SequencedTestMessage> _unreliableMessagesSent;
|
||||||
|
|
Loading…
Reference in a new issue