mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 12:04:18 +02:00
remove a peer in domain-server after max connection attempts
This commit is contained in:
parent
63024663b2
commit
d9e0c91e02
3 changed files with 35 additions and 12 deletions
|
@ -1012,17 +1012,31 @@ void DomainServer::sendHearbeatToIceServer() {
|
|||
void DomainServer::sendICEPingPackets() {
|
||||
LimitedNodeList* nodeList = LimitedNodeList::getInstance();
|
||||
|
||||
foreach(const NetworkPeer& peer, _connectingICEPeers) {
|
||||
// send ping packets to this peer's interfaces
|
||||
qDebug() << "Sending ping packets to establish connectivity with ICE peer with ID"
|
||||
<< peer.getUUID();
|
||||
QHash<QUuid, NetworkPeer>::iterator peer = _connectingICEPeers.begin();
|
||||
|
||||
while (peer != _connectingICEPeers.end()) {
|
||||
|
||||
// send the ping packet to the local and public sockets for this node
|
||||
QByteArray localPingPacket = nodeList->constructPingPacket(PingType::Local, false);
|
||||
nodeList->writeUnverifiedDatagram(localPingPacket, peer.getLocalSocket());
|
||||
|
||||
QByteArray publicPingPacket = nodeList->constructPingPacket(PingType::Public, false);
|
||||
nodeList->writeUnverifiedDatagram(publicPingPacket, peer.getPublicSocket());
|
||||
if (peer->getConnectionAttempts() >= MAX_ICE_CONNECTION_ATTEMPTS) {
|
||||
// we've already tried to connect to this peer enough times
|
||||
// remove it from our list - if it wants to re-connect it'll come back through ice-server
|
||||
peer = _connectingICEPeers.erase(peer);
|
||||
} else {
|
||||
// send ping packets to this peer's interfaces
|
||||
qDebug() << "Sending ping packets to establish connectivity with ICE peer with ID"
|
||||
<< peer->getUUID();
|
||||
|
||||
// send the ping packet to the local and public sockets for this node
|
||||
QByteArray localPingPacket = nodeList->constructPingPacket(PingType::Local, false);
|
||||
nodeList->writeUnverifiedDatagram(localPingPacket, peer->getLocalSocket());
|
||||
|
||||
QByteArray publicPingPacket = nodeList->constructPingPacket(PingType::Public, false);
|
||||
nodeList->writeUnverifiedDatagram(publicPingPacket, peer->getPublicSocket());
|
||||
|
||||
peer->incrementConnectionAttempts();
|
||||
|
||||
// go to next peer in hash
|
||||
++peer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,8 @@ NetworkPeer::NetworkPeer() :
|
|||
_publicSocket(),
|
||||
_localSocket(),
|
||||
_wakeTimestamp(QDateTime::currentMSecsSinceEpoch()),
|
||||
_lastHeardMicrostamp(usecTimestampNow())
|
||||
_lastHeardMicrostamp(usecTimestampNow()),
|
||||
_connectionAttempts(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -31,7 +32,8 @@ NetworkPeer::NetworkPeer(const QUuid& uuid, const HifiSockAddr& publicSocket, co
|
|||
_publicSocket(publicSocket),
|
||||
_localSocket(localSocket),
|
||||
_wakeTimestamp(QDateTime::currentMSecsSinceEpoch()),
|
||||
_lastHeardMicrostamp(usecTimestampNow())
|
||||
_lastHeardMicrostamp(usecTimestampNow()),
|
||||
_connectionAttempts(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
const QString ICE_SERVER_HOSTNAME = "localhost";
|
||||
const int ICE_SERVER_DEFAULT_PORT = 7337;
|
||||
const int ICE_HEARBEAT_INTERVAL_MSECS = 2 * 1000;
|
||||
const int MAX_ICE_CONNECTION_ATTEMPTS = 5;
|
||||
|
||||
class NetworkPeer : public QObject {
|
||||
public:
|
||||
|
@ -50,6 +51,10 @@ public:
|
|||
|
||||
QByteArray toByteArray() const;
|
||||
|
||||
int getConnectionAttempts() const { return _connectionAttempts; }
|
||||
void incrementConnectionAttempts() { ++_connectionAttempts; }
|
||||
void resetConnectionAttemps() { _connectionAttempts = 0; }
|
||||
|
||||
friend QDataStream& operator<<(QDataStream& out, const NetworkPeer& peer);
|
||||
friend QDataStream& operator>>(QDataStream& in, NetworkPeer& peer);
|
||||
protected:
|
||||
|
@ -60,6 +65,8 @@ protected:
|
|||
|
||||
quint64 _wakeTimestamp;
|
||||
quint64 _lastHeardMicrostamp;
|
||||
|
||||
int _connectionAttempts;
|
||||
private:
|
||||
void swap(NetworkPeer& otherPeer);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue