mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 18:13:05 +02:00
add ping timer tied to NetworkPeer
This commit is contained in:
parent
757d02a600
commit
0cb67cce2c
9 changed files with 126 additions and 71 deletions
|
@ -472,7 +472,8 @@ void LimitedNodeList::handleNodeKill(const SharedNodePointer& node) {
|
||||||
|
|
||||||
SharedNodePointer LimitedNodeList::addOrUpdateNode(const QUuid& uuid, NodeType_t nodeType,
|
SharedNodePointer LimitedNodeList::addOrUpdateNode(const QUuid& uuid, NodeType_t nodeType,
|
||||||
const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket,
|
const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket,
|
||||||
bool canAdjustLocks, bool canRez) {
|
bool canAdjustLocks, bool canRez,
|
||||||
|
const QUuid& connectionSecret) {
|
||||||
NodeHash::const_iterator it = _nodeHash.find(uuid);
|
NodeHash::const_iterator it = _nodeHash.find(uuid);
|
||||||
|
|
||||||
if (it != _nodeHash.end()) {
|
if (it != _nodeHash.end()) {
|
||||||
|
@ -482,11 +483,13 @@ SharedNodePointer LimitedNodeList::addOrUpdateNode(const QUuid& uuid, NodeType_t
|
||||||
matchingNode->setLocalSocket(localSocket);
|
matchingNode->setLocalSocket(localSocket);
|
||||||
matchingNode->setCanAdjustLocks(canAdjustLocks);
|
matchingNode->setCanAdjustLocks(canAdjustLocks);
|
||||||
matchingNode->setCanRez(canRez);
|
matchingNode->setCanRez(canRez);
|
||||||
|
matchingNode->setConnectionSecret(connectionSecret);
|
||||||
|
|
||||||
return matchingNode;
|
return matchingNode;
|
||||||
} else {
|
} else {
|
||||||
// we didn't have this node, so add them
|
// we didn't have this node, so add them
|
||||||
Node* newNode = new Node(uuid, nodeType, publicSocket, localSocket, canAdjustLocks, canRez);
|
Node* newNode = new Node(uuid, nodeType, publicSocket, localSocket, canAdjustLocks, canRez, connectionSecret);
|
||||||
|
|
||||||
SharedNodePointer newNodePointer(newNode);
|
SharedNodePointer newNodePointer(newNode);
|
||||||
|
|
||||||
_nodeHash.insert(UUIDNodePair(newNode->getUUID(), newNodePointer));
|
_nodeHash.insert(UUIDNodePair(newNode->getUUID(), newNodePointer));
|
||||||
|
|
|
@ -151,7 +151,8 @@ public:
|
||||||
|
|
||||||
SharedNodePointer addOrUpdateNode(const QUuid& uuid, NodeType_t nodeType,
|
SharedNodePointer addOrUpdateNode(const QUuid& uuid, NodeType_t nodeType,
|
||||||
const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket,
|
const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket,
|
||||||
bool canAdjustLocks, bool canRez);
|
bool canAdjustLocks, bool canRez,
|
||||||
|
const QUuid& connectionSecret = QUuid());
|
||||||
|
|
||||||
bool hasCompletedInitialSTUN() const { return _hasCompletedInitialSTUN; }
|
bool hasCompletedInitialSTUN() const { return _hasCompletedInitialSTUN; }
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ NetworkPeer::NetworkPeer() :
|
||||||
_lastHeardMicrostamp(usecTimestampNow()),
|
_lastHeardMicrostamp(usecTimestampNow()),
|
||||||
_connectionAttempts(0)
|
_connectionAttempts(0)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkPeer::NetworkPeer(const QUuid& uuid, const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket) :
|
NetworkPeer::NetworkPeer(const QUuid& uuid, const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket) :
|
||||||
|
@ -36,14 +36,14 @@ NetworkPeer::NetworkPeer(const QUuid& uuid, const HifiSockAddr& publicSocket, co
|
||||||
_lastHeardMicrostamp(usecTimestampNow()),
|
_lastHeardMicrostamp(usecTimestampNow()),
|
||||||
_connectionAttempts(0)
|
_connectionAttempts(0)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkPeer::NetworkPeer(const NetworkPeer& otherPeer) : QObject() {
|
NetworkPeer::NetworkPeer(const NetworkPeer& otherPeer) : QObject() {
|
||||||
_uuid = otherPeer._uuid;
|
_uuid = otherPeer._uuid;
|
||||||
_publicSocket = otherPeer._publicSocket;
|
_publicSocket = otherPeer._publicSocket;
|
||||||
_localSocket = otherPeer._localSocket;
|
_localSocket = otherPeer._localSocket;
|
||||||
|
|
||||||
_wakeTimestamp = otherPeer._wakeTimestamp;
|
_wakeTimestamp = otherPeer._wakeTimestamp;
|
||||||
_lastHeardMicrostamp = otherPeer._lastHeardMicrostamp;
|
_lastHeardMicrostamp = otherPeer._lastHeardMicrostamp;
|
||||||
_connectionAttempts = otherPeer._connectionAttempts;
|
_connectionAttempts = otherPeer._connectionAttempts;
|
||||||
|
@ -57,7 +57,7 @@ NetworkPeer& NetworkPeer::operator=(const NetworkPeer& otherPeer) {
|
||||||
|
|
||||||
void NetworkPeer::swap(NetworkPeer& otherPeer) {
|
void NetworkPeer::swap(NetworkPeer& otherPeer) {
|
||||||
using std::swap;
|
using std::swap;
|
||||||
|
|
||||||
swap(_uuid, otherPeer._uuid);
|
swap(_uuid, otherPeer._uuid);
|
||||||
swap(_publicSocket, otherPeer._publicSocket);
|
swap(_publicSocket, otherPeer._publicSocket);
|
||||||
swap(_localSocket, otherPeer._localSocket);
|
swap(_localSocket, otherPeer._localSocket);
|
||||||
|
@ -71,15 +71,33 @@ QByteArray NetworkPeer::toByteArray() const {
|
||||||
|
|
||||||
QDataStream peerStream(&peerByteArray, QIODevice::Append);
|
QDataStream peerStream(&peerByteArray, QIODevice::Append);
|
||||||
peerStream << *this;
|
peerStream << *this;
|
||||||
|
|
||||||
return peerByteArray;
|
return peerByteArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NetworkPeer::startPingTimer() {
|
||||||
|
if (!_pingTimer) {
|
||||||
|
_pingTimer = new QTimer(this);
|
||||||
|
|
||||||
|
connect(_pingTimer, &QTimer::timeout, this, &NetworkPeer::pingTimerTimeout);
|
||||||
|
|
||||||
|
_pingTimer->start(UDP_PUNCH_PING_INTERVAL_MS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetworkPeer::stopPingTimer() {
|
||||||
|
if (_pingTimer) {
|
||||||
|
_pingTimer->stop();
|
||||||
|
_pingTimer->deleteLater();
|
||||||
|
_pingTimer = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QDataStream& operator<<(QDataStream& out, const NetworkPeer& peer) {
|
QDataStream& operator<<(QDataStream& out, const NetworkPeer& peer) {
|
||||||
out << peer._uuid;
|
out << peer._uuid;
|
||||||
out << peer._publicSocket;
|
out << peer._publicSocket;
|
||||||
out << peer._localSocket;
|
out << peer._localSocket;
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +105,7 @@ QDataStream& operator>>(QDataStream& in, NetworkPeer& peer) {
|
||||||
in >> peer._uuid;
|
in >> peer._uuid;
|
||||||
in >> peer._publicSocket;
|
in >> peer._publicSocket;
|
||||||
in >> peer._localSocket;
|
in >> peer._localSocket;
|
||||||
|
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,9 @@
|
||||||
#ifndef hifi_NetworkPeer_h
|
#ifndef hifi_NetworkPeer_h
|
||||||
#define hifi_NetworkPeer_h
|
#define hifi_NetworkPeer_h
|
||||||
|
|
||||||
#include <qobject.h>
|
#include <QtCore/QObject>
|
||||||
#include <quuid.h>
|
#include <QtCore/QTimer>
|
||||||
|
#include <QtCore/QUuid>
|
||||||
|
|
||||||
#include "HifiSockAddr.h"
|
#include "HifiSockAddr.h"
|
||||||
|
|
||||||
|
@ -22,35 +23,38 @@ const int ICE_SERVER_DEFAULT_PORT = 7337;
|
||||||
const int ICE_HEARBEAT_INTERVAL_MSECS = 2 * 1000;
|
const int ICE_HEARBEAT_INTERVAL_MSECS = 2 * 1000;
|
||||||
const int MAX_ICE_CONNECTION_ATTEMPTS = 5;
|
const int MAX_ICE_CONNECTION_ATTEMPTS = 5;
|
||||||
|
|
||||||
|
const int UDP_PUNCH_PING_INTERVAL_MS = 25;
|
||||||
|
|
||||||
class NetworkPeer : public QObject {
|
class NetworkPeer : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
NetworkPeer();
|
NetworkPeer();
|
||||||
NetworkPeer(const QUuid& uuid, const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket);
|
NetworkPeer(const QUuid& uuid, const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket);
|
||||||
|
|
||||||
// privatize copy and assignment operator to disallow peer copying
|
// privatize copy and assignment operator to disallow peer copying
|
||||||
NetworkPeer(const NetworkPeer &otherPeer);
|
NetworkPeer(const NetworkPeer &otherPeer);
|
||||||
NetworkPeer& operator=(const NetworkPeer& otherPeer);
|
NetworkPeer& operator=(const NetworkPeer& otherPeer);
|
||||||
|
|
||||||
bool isNull() const { return _uuid.isNull(); }
|
bool isNull() const { return _uuid.isNull(); }
|
||||||
|
|
||||||
const QUuid& getUUID() const { return _uuid; }
|
const QUuid& getUUID() const { return _uuid; }
|
||||||
void setUUID(const QUuid& uuid) { _uuid = uuid; }
|
void setUUID(const QUuid& uuid) { _uuid = uuid; }
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
const HifiSockAddr& getPublicSocket() const { return _publicSocket; }
|
const HifiSockAddr& getPublicSocket() const { return _publicSocket; }
|
||||||
virtual void setPublicSocket(const HifiSockAddr& publicSocket) { _publicSocket = publicSocket; }
|
virtual void setPublicSocket(const HifiSockAddr& publicSocket) { _publicSocket = publicSocket; }
|
||||||
const HifiSockAddr& getLocalSocket() const { return _localSocket; }
|
const HifiSockAddr& getLocalSocket() const { return _localSocket; }
|
||||||
virtual void setLocalSocket(const HifiSockAddr& localSocket) { _localSocket = localSocket; }
|
virtual void setLocalSocket(const HifiSockAddr& localSocket) { _localSocket = localSocket; }
|
||||||
|
|
||||||
quint64 getWakeTimestamp() const { return _wakeTimestamp; }
|
quint64 getWakeTimestamp() const { return _wakeTimestamp; }
|
||||||
void setWakeTimestamp(quint64 wakeTimestamp) { _wakeTimestamp = wakeTimestamp; }
|
void setWakeTimestamp(quint64 wakeTimestamp) { _wakeTimestamp = wakeTimestamp; }
|
||||||
|
|
||||||
quint64 getLastHeardMicrostamp() const { return _lastHeardMicrostamp; }
|
quint64 getLastHeardMicrostamp() const { return _lastHeardMicrostamp; }
|
||||||
void setLastHeardMicrostamp(quint64 lastHeardMicrostamp) { _lastHeardMicrostamp = lastHeardMicrostamp; }
|
void setLastHeardMicrostamp(quint64 lastHeardMicrostamp) { _lastHeardMicrostamp = lastHeardMicrostamp; }
|
||||||
|
|
||||||
QByteArray toByteArray() const;
|
QByteArray toByteArray() const;
|
||||||
|
|
||||||
int getConnectionAttempts() const { return _connectionAttempts; }
|
int getConnectionAttempts() const { return _connectionAttempts; }
|
||||||
void incrementConnectionAttempts() { ++_connectionAttempts; }
|
void incrementConnectionAttempts() { ++_connectionAttempts; }
|
||||||
void resetConnectionAttemps() { _connectionAttempts = 0; }
|
void resetConnectionAttemps() { _connectionAttempts = 0; }
|
||||||
|
@ -60,18 +64,25 @@ public:
|
||||||
|
|
||||||
float getOutboundBandwidth(); // in kbps
|
float getOutboundBandwidth(); // in kbps
|
||||||
float getInboundBandwidth(); // in kbps
|
float getInboundBandwidth(); // in kbps
|
||||||
|
|
||||||
|
void startPingTimer();
|
||||||
|
void stopPingTimer();
|
||||||
|
|
||||||
friend QDataStream& operator<<(QDataStream& out, const NetworkPeer& peer);
|
friend QDataStream& operator<<(QDataStream& out, const NetworkPeer& peer);
|
||||||
friend QDataStream& operator>>(QDataStream& in, NetworkPeer& peer);
|
friend QDataStream& operator>>(QDataStream& in, NetworkPeer& peer);
|
||||||
|
signals:
|
||||||
|
void pingTimerTimeout();
|
||||||
protected:
|
protected:
|
||||||
QUuid _uuid;
|
QUuid _uuid;
|
||||||
|
|
||||||
HifiSockAddr _publicSocket;
|
HifiSockAddr _publicSocket;
|
||||||
HifiSockAddr _localSocket;
|
HifiSockAddr _localSocket;
|
||||||
|
|
||||||
quint64 _wakeTimestamp;
|
quint64 _wakeTimestamp;
|
||||||
quint64 _lastHeardMicrostamp;
|
quint64 _lastHeardMicrostamp;
|
||||||
|
|
||||||
|
QTimer* _pingTimer = NULL;
|
||||||
|
|
||||||
int _connectionAttempts;
|
int _connectionAttempts;
|
||||||
private:
|
private:
|
||||||
void swap(NetworkPeer& otherPeer);
|
void swap(NetworkPeer& otherPeer);
|
||||||
|
|
|
@ -42,12 +42,12 @@ const QString& NodeType::getNodeTypeName(NodeType_t nodeType) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Node::Node(const QUuid& uuid, NodeType_t type, const HifiSockAddr& publicSocket,
|
Node::Node(const QUuid& uuid, NodeType_t type, const HifiSockAddr& publicSocket,
|
||||||
const HifiSockAddr& localSocket, bool canAdjustLocks, bool canRez) :
|
const HifiSockAddr& localSocket, bool canAdjustLocks, bool canRez, const QUuid& connectionSecret) :
|
||||||
NetworkPeer(uuid, publicSocket, localSocket),
|
NetworkPeer(uuid, publicSocket, localSocket),
|
||||||
_type(type),
|
_type(type),
|
||||||
_activeSocket(NULL),
|
_activeSocket(NULL),
|
||||||
_symmetricSocket(),
|
_symmetricSocket(),
|
||||||
_connectionSecret(),
|
_connectionSecret(connectionSecret),
|
||||||
_linkedData(NULL),
|
_linkedData(NULL),
|
||||||
_isAlive(true),
|
_isAlive(true),
|
||||||
_pingMs(-1), // "Uninitialized"
|
_pingMs(-1), // "Uninitialized"
|
||||||
|
@ -57,7 +57,7 @@ Node::Node(const QUuid& uuid, NodeType_t type, const HifiSockAddr& publicSocket,
|
||||||
_canAdjustLocks(canAdjustLocks),
|
_canAdjustLocks(canAdjustLocks),
|
||||||
_canRez(canRez)
|
_canRez(canRez)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Node::~Node() {
|
Node::~Node() {
|
||||||
|
@ -75,11 +75,11 @@ void Node::setPublicSocket(const HifiSockAddr& publicSocket) {
|
||||||
// if the active socket was the public socket then reset it to NULL
|
// if the active socket was the public socket then reset it to NULL
|
||||||
_activeSocket = NULL;
|
_activeSocket = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_publicSocket.isNull()) {
|
if (!_publicSocket.isNull()) {
|
||||||
qCDebug(networking) << "Public socket change for node" << *this;
|
qCDebug(networking) << "Public socket change for node" << *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
_publicSocket = publicSocket;
|
_publicSocket = publicSocket;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,11 +90,11 @@ void Node::setLocalSocket(const HifiSockAddr& localSocket) {
|
||||||
// if the active socket was the local socket then reset it to NULL
|
// if the active socket was the local socket then reset it to NULL
|
||||||
_activeSocket = NULL;
|
_activeSocket = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_localSocket.isNull()) {
|
if (!_localSocket.isNull()) {
|
||||||
qCDebug(networking) << "Local socket change for node" << *this;
|
qCDebug(networking) << "Local socket change for node" << *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
_localSocket = localSocket;
|
_localSocket = localSocket;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,32 +105,39 @@ void Node::setSymmetricSocket(const HifiSockAddr& symmetricSocket) {
|
||||||
// if the active socket was the symmetric socket then reset it to NULL
|
// if the active socket was the symmetric socket then reset it to NULL
|
||||||
_activeSocket = NULL;
|
_activeSocket = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_symmetricSocket.isNull()) {
|
if (!_symmetricSocket.isNull()) {
|
||||||
qCDebug(networking) << "Symmetric socket change for node" << *this;
|
qCDebug(networking) << "Symmetric socket change for node" << *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
_symmetricSocket = symmetricSocket;
|
_symmetricSocket = symmetricSocket;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Node::setActiveSocket(HifiSockAddr* discoveredSocket) {
|
||||||
|
_activeSocket = discoveredSocket;
|
||||||
|
|
||||||
|
// we have an active socket, stop our ping timer
|
||||||
|
stopPingTimer();
|
||||||
|
}
|
||||||
|
|
||||||
void Node::activateLocalSocket() {
|
void Node::activateLocalSocket() {
|
||||||
qCDebug(networking) << "Activating local socket for network peer with ID" << uuidStringWithoutCurlyBraces(_uuid);
|
qCDebug(networking) << "Activating local socket for network peer with ID" << uuidStringWithoutCurlyBraces(_uuid);
|
||||||
_activeSocket = &_localSocket;
|
setActiveSocket(&_localSocket);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::activatePublicSocket() {
|
void Node::activatePublicSocket() {
|
||||||
qCDebug(networking) << "Activating public socket for network peer with ID" << uuidStringWithoutCurlyBraces(_uuid);
|
qCDebug(networking) << "Activating public socket for network peer with ID" << uuidStringWithoutCurlyBraces(_uuid);
|
||||||
_activeSocket = &_publicSocket;
|
setActiveSocket(&_publicSocket);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::activateSymmetricSocket() {
|
void Node::activateSymmetricSocket() {
|
||||||
qCDebug(networking) << "Activating symmetric socket for network peer with ID" << uuidStringWithoutCurlyBraces(_uuid);
|
qCDebug(networking) << "Activating symmetric socket for network peer with ID" << uuidStringWithoutCurlyBraces(_uuid);
|
||||||
_activeSocket = &_symmetricSocket;
|
setActiveSocket(&_symmetricSocket);
|
||||||
}
|
}
|
||||||
|
|
||||||
PacketSequenceNumber Node::getLastSequenceNumberForPacketType(PacketType packetType) const {
|
PacketSequenceNumber Node::getLastSequenceNumberForPacketType(PacketType packetType) const {
|
||||||
auto typeMatch = _lastSequenceNumbers.find(packetType);
|
auto typeMatch = _lastSequenceNumbers.find(packetType);
|
||||||
if (typeMatch != _lastSequenceNumbers.end()) {
|
if (typeMatch != _lastSequenceNumbers.end()) {
|
||||||
return typeMatch->second;
|
return typeMatch->second;
|
||||||
} else {
|
} else {
|
||||||
|
@ -145,7 +152,7 @@ QDataStream& operator<<(QDataStream& out, const Node& node) {
|
||||||
out << node._localSocket;
|
out << node._localSocket;
|
||||||
out << node._canAdjustLocks;
|
out << node._canAdjustLocks;
|
||||||
out << node._canRez;
|
out << node._canRez;
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +163,7 @@ QDataStream& operator>>(QDataStream& in, Node& node) {
|
||||||
in >> node._localSocket;
|
in >> node._localSocket;
|
||||||
in >> node._canAdjustLocks;
|
in >> node._canAdjustLocks;
|
||||||
in >> node._canRez;
|
in >> node._canRez;
|
||||||
|
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,16 +37,17 @@ namespace NodeType {
|
||||||
const NodeType_t AudioMixer = 'M';
|
const NodeType_t AudioMixer = 'M';
|
||||||
const NodeType_t AvatarMixer = 'W';
|
const NodeType_t AvatarMixer = 'W';
|
||||||
const NodeType_t Unassigned = 1;
|
const NodeType_t Unassigned = 1;
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
const QString& getNodeTypeName(NodeType_t nodeType);
|
const QString& getNodeTypeName(NodeType_t nodeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
class Node : public NetworkPeer {
|
class Node : public NetworkPeer {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Node(const QUuid& uuid, NodeType_t type,
|
Node(const QUuid& uuid, NodeType_t type,
|
||||||
const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket, bool canAdjustLocks, bool canRez);
|
const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket,
|
||||||
|
bool canAdjustLocks, bool canRez, const QUuid& connectionSecret = QUuid());
|
||||||
~Node();
|
~Node();
|
||||||
|
|
||||||
bool operator==(const Node& otherNode) const { return _uuid == otherNode._uuid; }
|
bool operator==(const Node& otherNode) const { return _uuid == otherNode._uuid; }
|
||||||
|
@ -54,7 +55,7 @@ public:
|
||||||
|
|
||||||
char getType() const { return _type; }
|
char getType() const { return _type; }
|
||||||
void setType(char type) { _type = type; }
|
void setType(char type) { _type = type; }
|
||||||
|
|
||||||
const QUuid& getConnectionSecret() const { return _connectionSecret; }
|
const QUuid& getConnectionSecret() const { return _connectionSecret; }
|
||||||
void setConnectionSecret(const QUuid& connectionSecret) { _connectionSecret = connectionSecret; }
|
void setConnectionSecret(const QUuid& connectionSecret) { _connectionSecret = connectionSecret; }
|
||||||
|
|
||||||
|
@ -70,12 +71,12 @@ public:
|
||||||
int getClockSkewUsec() const { return _clockSkewUsec; }
|
int getClockSkewUsec() const { return _clockSkewUsec; }
|
||||||
void updateClockSkewUsec(int clockSkewSample);
|
void updateClockSkewUsec(int clockSkewSample);
|
||||||
QMutex& getMutex() { return _mutex; }
|
QMutex& getMutex() { return _mutex; }
|
||||||
|
|
||||||
virtual void setPublicSocket(const HifiSockAddr& publicSocket);
|
virtual void setPublicSocket(const HifiSockAddr& publicSocket);
|
||||||
virtual void setLocalSocket(const HifiSockAddr& localSocket);
|
virtual void setLocalSocket(const HifiSockAddr& localSocket);
|
||||||
const HifiSockAddr& getSymmetricSocket() const { return _symmetricSocket; }
|
const HifiSockAddr& getSymmetricSocket() const { return _symmetricSocket; }
|
||||||
virtual void setSymmetricSocket(const HifiSockAddr& symmetricSocket);
|
virtual void setSymmetricSocket(const HifiSockAddr& symmetricSocket);
|
||||||
|
|
||||||
const HifiSockAddr* getActiveSocket() const { return _activeSocket; }
|
const HifiSockAddr* getActiveSocket() const { return _activeSocket; }
|
||||||
|
|
||||||
void setCanAdjustLocks(bool canAdjustLocks) { _canAdjustLocks = canAdjustLocks; }
|
void setCanAdjustLocks(bool canAdjustLocks) { _canAdjustLocks = canAdjustLocks; }
|
||||||
|
@ -83,7 +84,7 @@ public:
|
||||||
|
|
||||||
void setCanRez(bool canRez) { _canRez = canRez; }
|
void setCanRez(bool canRez) { _canRez = canRez; }
|
||||||
bool getCanRez() { return _canRez; }
|
bool getCanRez() { return _canRez; }
|
||||||
|
|
||||||
void activatePublicSocket();
|
void activatePublicSocket();
|
||||||
void activateLocalSocket();
|
void activateLocalSocket();
|
||||||
void activateSymmetricSocket();
|
void activateSymmetricSocket();
|
||||||
|
@ -91,7 +92,7 @@ public:
|
||||||
void setLastSequenceNumberForPacketType(PacketSequenceNumber sequenceNumber, PacketType packetType)
|
void setLastSequenceNumberForPacketType(PacketSequenceNumber sequenceNumber, PacketType packetType)
|
||||||
{ _lastSequenceNumbers[packetType] = sequenceNumber; }
|
{ _lastSequenceNumbers[packetType] = sequenceNumber; }
|
||||||
PacketSequenceNumber getLastSequenceNumberForPacketType(PacketType packetType) const;
|
PacketSequenceNumber getLastSequenceNumberForPacketType(PacketType packetType) const;
|
||||||
|
|
||||||
friend QDataStream& operator<<(QDataStream& out, const Node& node);
|
friend QDataStream& operator<<(QDataStream& out, const Node& node);
|
||||||
friend QDataStream& operator>>(QDataStream& in, Node& node);
|
friend QDataStream& operator>>(QDataStream& in, Node& node);
|
||||||
|
|
||||||
|
@ -100,11 +101,13 @@ private:
|
||||||
Node(const Node &otherNode);
|
Node(const Node &otherNode);
|
||||||
Node& operator=(Node otherNode);
|
Node& operator=(Node otherNode);
|
||||||
|
|
||||||
|
void setActiveSocket(HifiSockAddr* discoveredSocket);
|
||||||
|
|
||||||
NodeType_t _type;
|
NodeType_t _type;
|
||||||
|
|
||||||
HifiSockAddr* _activeSocket;
|
HifiSockAddr* _activeSocket;
|
||||||
HifiSockAddr _symmetricSocket;
|
HifiSockAddr _symmetricSocket;
|
||||||
|
|
||||||
QUuid _connectionSecret;
|
QUuid _connectionSecret;
|
||||||
NodeData* _linkedData;
|
NodeData* _linkedData;
|
||||||
bool _isAlive;
|
bool _isAlive;
|
||||||
|
|
|
@ -82,6 +82,9 @@ NodeList::NodeList(char newOwnerType, unsigned short socketListenPort, unsigned
|
||||||
// clear our NodeList when logout is requested
|
// clear our NodeList when logout is requested
|
||||||
connect(&AccountManager::getInstance(), &AccountManager::logoutComplete , this, &NodeList::reset);
|
connect(&AccountManager::getInstance(), &AccountManager::logoutComplete , this, &NodeList::reset);
|
||||||
|
|
||||||
|
// anytime we get a new node we will want to attempt to punch to it
|
||||||
|
connect(this, &LimitedNodeList::nodeAdded, this, &NodeList::startNodeHolePunch);
|
||||||
|
|
||||||
// we definitely want STUN to update our public socket, so call the LNL to kick that off
|
// we definitely want STUN to update our public socket, so call the LNL to kick that off
|
||||||
startSTUNPublicSocketUpdate();
|
startSTUNPublicSocketUpdate();
|
||||||
}
|
}
|
||||||
|
@ -521,7 +524,7 @@ int NodeList::processDomainServerList(const QByteArray& packet) {
|
||||||
setThisNodeCanRez(thisNodeCanRez);
|
setThisNodeCanRez(thisNodeCanRez);
|
||||||
|
|
||||||
// pull each node in the packet
|
// pull each node in the packet
|
||||||
while(packetStream.device()->pos() < packet.size()) {
|
while (packetStream.device()->pos() < packet.size()) {
|
||||||
// setup variables to read into from QDataStream
|
// setup variables to read into from QDataStream
|
||||||
qint8 nodeType;
|
qint8 nodeType;
|
||||||
QUuid nodeUUID, connectionUUID;
|
QUuid nodeUUID, connectionUUID;
|
||||||
|
@ -537,16 +540,12 @@ int NodeList::processDomainServerList(const QByteArray& packet) {
|
||||||
nodePublicSocket.setAddress(_domainHandler.getIP());
|
nodePublicSocket.setAddress(_domainHandler.getIP());
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedNodePointer node = addOrUpdateNode(nodeUUID, nodeType, nodePublicSocket,
|
|
||||||
nodeLocalSocket, canAdjustLocks, canRez);
|
|
||||||
|
|
||||||
packetStream >> connectionUUID;
|
packetStream >> connectionUUID;
|
||||||
node->setConnectionSecret(connectionUUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ping inactive nodes in conjunction with receipt of list from domain-server
|
SharedNodePointer node = addOrUpdateNode(nodeUUID, nodeType, nodePublicSocket,
|
||||||
// this makes it happen every second and also pings any newly added nodes
|
nodeLocalSocket, canAdjustLocks, canRez,
|
||||||
pingInactiveNodes();
|
connectionUUID);
|
||||||
|
}
|
||||||
|
|
||||||
return readNodes;
|
return readNodes;
|
||||||
}
|
}
|
||||||
|
@ -566,6 +565,10 @@ void NodeList::sendAssignment(Assignment& assignment) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeList::pingPunchForInactiveNode(const SharedNodePointer& node) {
|
void NodeList::pingPunchForInactiveNode(const SharedNodePointer& node) {
|
||||||
|
if (node->getType() == NodeType::AudioMixer) {
|
||||||
|
flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::SendAudioPing);
|
||||||
|
}
|
||||||
|
|
||||||
// send the ping packet to the local and public sockets for this node
|
// send the ping packet to the local and public sockets for this node
|
||||||
QByteArray localPingPacket = constructPingPacket(PingType::Local);
|
QByteArray localPingPacket = constructPingPacket(PingType::Local);
|
||||||
writeDatagram(localPingPacket, node, node->getLocalSocket());
|
writeDatagram(localPingPacket, node, node->getLocalSocket());
|
||||||
|
@ -577,19 +580,27 @@ void NodeList::pingPunchForInactiveNode(const SharedNodePointer& node) {
|
||||||
QByteArray symmetricPingPacket = constructPingPacket(PingType::Symmetric);
|
QByteArray symmetricPingPacket = constructPingPacket(PingType::Symmetric);
|
||||||
writeDatagram(symmetricPingPacket, node, node->getSymmetricSocket());
|
writeDatagram(symmetricPingPacket, node, node->getSymmetricSocket());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
node->incrementConnectionAttempts();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeList::pingInactiveNodes() {
|
void NodeList::startNodeHolePunch(const SharedNodePointer& node) {
|
||||||
eachNode([this](const SharedNodePointer& node){
|
// connect to the correct signal on this node so we know when to ping it
|
||||||
if (!node->getActiveSocket()) {
|
connect(node.data(), &Node::pingTimerTimeout, this, &NodeList::handleNodePingTimeout);
|
||||||
// we don't have an active link to this node, ping it to set that up
|
|
||||||
pingPunchForInactiveNode(node);
|
|
||||||
|
|
||||||
if (node->getType() == NodeType::AudioMixer) {
|
// start the ping timer for this node
|
||||||
flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::SendAudioPing);
|
node->startPingTimer();
|
||||||
}
|
|
||||||
}
|
// ping this node immediately
|
||||||
});
|
pingPunchForInactiveNode(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NodeList::handleNodePingTimeout() {
|
||||||
|
Node* senderNode = qobject_cast<Node*>(sender());
|
||||||
|
|
||||||
|
if (senderNode) {
|
||||||
|
pingPunchForInactiveNode(nodeWithUUID(senderNode->getUUID()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeList::activateSocketFromNodeCommunication(const QByteArray& packet, const SharedNodePointer& sendingNode) {
|
void NodeList::activateSocketFromNodeCommunication(const QByteArray& packet, const SharedNodePointer& sendingNode) {
|
||||||
|
|
|
@ -70,13 +70,15 @@ public:
|
||||||
public slots:
|
public slots:
|
||||||
void reset();
|
void reset();
|
||||||
void sendDomainServerCheckIn();
|
void sendDomainServerCheckIn();
|
||||||
void pingInactiveNodes();
|
|
||||||
void handleDSPathQuery(const QString& newPath);
|
void handleDSPathQuery(const QString& newPath);
|
||||||
signals:
|
signals:
|
||||||
void limitOfSilentDomainCheckInsReached();
|
void limitOfSilentDomainCheckInsReached();
|
||||||
private slots:
|
private slots:
|
||||||
void sendPendingDSPathQuery();
|
void sendPendingDSPathQuery();
|
||||||
void handleICEConnectionToDomainServer();
|
void handleICEConnectionToDomainServer();
|
||||||
|
|
||||||
|
void startNodeHolePunch(const SharedNodePointer& node);
|
||||||
|
void handleNodePingTimeout();
|
||||||
private:
|
private:
|
||||||
NodeList() : LimitedNodeList(0, 0) { assert(false); } // Not implemented, needed for DependencyManager templates compile
|
NodeList() : LimitedNodeList(0, 0) { assert(false); } // Not implemented, needed for DependencyManager templates compile
|
||||||
NodeList(char ownerType, unsigned short socketListenPort = 0, unsigned short dtlsListenPort = 0);
|
NodeList(char ownerType, unsigned short socketListenPort = 0, unsigned short dtlsListenPort = 0);
|
||||||
|
|
|
@ -46,7 +46,6 @@ protected:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void checkInWithDomainServerOrExit();
|
void checkInWithDomainServerOrExit();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef QSharedPointer<ThreadedAssignment> SharedAssignmentPointer;
|
typedef QSharedPointer<ThreadedAssignment> SharedAssignmentPointer;
|
||||||
|
|
Loading…
Reference in a new issue