Merge branch 'atp' of https://github.com/birarda/hifi into protocol

This commit is contained in:
Atlante45 2015-07-28 15:48:55 -07:00
commit 8ebdb6d154
3 changed files with 4 additions and 175 deletions

View file

@ -1,29 +0,0 @@
//
// SeqNum.cpp
// libraries/networking/src/udt
//
// Created by Clement on 7/23/15.
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "SeqNum.h"
int udt::seqlen(const SeqNum& seq1, const SeqNum& seq2) {
return (seq1._value <= seq2._value) ? (seq2._value - seq1._value + 1)
: (seq2._value - seq1._value + SeqNum::MAX + 2);
}
int udt::seqoff(const SeqNum& seq1, const SeqNum& seq2) {
if (glm::abs(seq1._value - seq2._value) < SeqNum::THRESHOLD) {
return seq2._value - seq1._value;
}
if (seq1._value < seq2._value) {
return seq2._value - seq1._value - SeqNum::MAX - 1;
}
return seq2._value - seq1._value + SeqNum::MAX + 1;
}

View file

@ -1,145 +0,0 @@
//
// SeqNum.h
// libraries/networking/src/udt
//
// Created by Clement on 7/23/15.
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_SeqNum_h
#define hifi_SeqNum_h
#include <functional>
#include <glm/detail/func_common.hpp>
namespace udt {
class SeqNum {
public:
// Base type of sequence numbers
using Type = uint32_t;
// Values are for 29 bit SeqNum
static const Type THRESHOLD = 0x0FFFFFFF; // threshold for comparing sequence numbers
static const Type MAX = 0x1FFFFFFF; // maximum sequence number used in UDT
SeqNum() = default;
SeqNum(const SeqNum& other) : _value(other._value) {}
// Only explicit conversions
explicit SeqNum(char* value) { _value = (*reinterpret_cast<int32_t*>(value)) & MAX; }
explicit SeqNum(Type value) { _value = (value <= MAX) ? value : MAX; }
explicit operator Type() { return _value; }
inline SeqNum& operator++() {
_value = (_value == MAX) ? 0 : ++_value;
return *this;
}
inline SeqNum& operator--() {
_value = (_value == 0) ? MAX : --_value;
return *this;
}
inline SeqNum operator++(int) {
SeqNum before = *this;
(*this)++;
return before;
}
inline SeqNum operator--(int) {
SeqNum before = *this;
(*this)--;
return before;
}
inline SeqNum& operator=(const SeqNum& other) {
_value = other._value;
return *this;
}
inline SeqNum& operator+=(Type inc) {
_value = (_value + inc > MAX) ? _value + inc - (MAX + 1) : _value + inc;
return *this;
}
inline SeqNum& operator-=(Type dec) {
_value = (_value < dec) ? MAX - (dec - _value + 1) : _value - dec;
return *this;
}
inline bool operator==(const SeqNum& other) const {
return _value == other._value;
}
inline bool operator!=(const SeqNum& other) const {
return _value != other._value;
}
friend bool operator<(const SeqNum& a, const SeqNum& b);
friend bool operator>(const SeqNum& a, const SeqNum& b);
friend bool operator<=(const SeqNum& a, const SeqNum& b);
friend bool operator>=(const SeqNum& a, const SeqNum& b);
friend SeqNum operator+(const SeqNum a, const Type& b);
friend SeqNum operator+(const Type& a, const SeqNum b);
friend SeqNum operator-(const SeqNum a, const Type& b);
friend SeqNum operator-(const Type& a, const SeqNum b);
friend int seqlen(const SeqNum& seq1, const SeqNum& seq2);
friend int seqoff(const SeqNum& seq1, const SeqNum& seq2);
private:
Type _value { 0 };
friend struct std::hash<SeqNum>;
};
inline bool operator<(const SeqNum& a, const SeqNum& b) {
return (glm::abs(a._value - b._value) < SeqNum::THRESHOLD) ? a._value < b._value : b._value < a._value;
}
inline bool operator>(const SeqNum& a, const SeqNum& b) {
return (glm::abs(a._value - b._value) < SeqNum::THRESHOLD) ? a._value > b._value : b._value > a._value;
}
inline bool operator<=(const SeqNum& a, const SeqNum& b) {
return (glm::abs(a._value - b._value) < SeqNum::THRESHOLD) ? a._value <= b._value : b._value <= a._value;
}
inline bool operator>=(const SeqNum& a, const SeqNum& b) {
return (glm::abs(a._value - b._value) < SeqNum::THRESHOLD) ? a._value >= b._value : b._value >= a._value;
}
inline SeqNum operator+(SeqNum a, const SeqNum::Type& b) {
a += b;
return a;
}
inline SeqNum operator+(const SeqNum::Type& a, SeqNum b) {
b += a;
return b;
}
inline SeqNum operator-(SeqNum a, const SeqNum::Type& b) {
a -= b;
return a;
}
inline SeqNum operator-(const SeqNum::Type& a, SeqNum b) {
b -= a;
return b;
}
int seqlen(const SeqNum& seq1, const SeqNum& seq2);
int seqoff(const SeqNum& seq1, const SeqNum& seq2);
}
template<> struct std::hash<udt::SeqNum> {
size_t operator()(const udt::SeqNum& seqNum) const {
return std::hash<unsigned long>()(seqNum._value);
}
};
#endif // hifi_SeqNum_h

View file

@ -144,7 +144,10 @@ void Socket::readPendingDatagrams() {
void Socket::rateControlSync() {
// TODO: enumerate our list of connections and ask each of them to send off periodic ACK packet for rate control
// enumerate our list of connections and ask each of them to send off periodic ACK packet for rate control
for (auto& connection : _connectionsHash) {
connection.second->sendACK();
}
if (_synTimer.interval() != _synInterval) {
// if the _synTimer interval doesn't match the current _synInterval (changes when the CC factory is changed)