add a timeout for ICE server DNS lookup

This commit is contained in:
Stephen Birarda 2017-08-24 16:40:16 -07:00
parent afce8b547a
commit c7affea411
2 changed files with 23 additions and 2 deletions

View file

@ -711,8 +711,25 @@ void DomainServer::setupICEHeartbeatForFullNetworking() {
} }
void DomainServer::updateICEServerAddresses() { void DomainServer::updateICEServerAddresses() {
if (_iceAddressLookupID == -1) { if (_iceAddressLookupID == INVALID_ICE_LOOKUP_ID) {
_iceAddressLookupID = QHostInfo::lookupHost(_iceServerAddr, this, SLOT(handleICEHostInfo(QHostInfo))); _iceAddressLookupID = QHostInfo::lookupHost(_iceServerAddr, this, SLOT(handleICEHostInfo(QHostInfo)));
// there seems to be a 5.9 bug where lookupHost never calls our slot
// so we add a single shot manual "timeout" to fire it off again if it hasn't called back yet
static const int ICE_ADDRESS_LOOKUP_TIMEOUT_MS = 5000;
QTimer::singleShot(ICE_ADDRESS_LOOKUP_TIMEOUT_MS, this, &DomainServer::timeoutICEAddressLookup);
}
}
void DomainServer::timeoutICEAddressLookup() {
if (_iceAddressLookupID != INVALID_ICE_LOOKUP_ID) {
// we waited 5s and didn't hear back for our ICE DNS lookup
// so time that one out and kick off another
QHostInfo::abortHostLookup(_iceAddressLookupID);
_iceAddressLookupID = INVALID_ICE_LOOKUP_ID;
updateICEServerAddresses();
} }
} }

View file

@ -39,6 +39,8 @@ typedef QMultiHash<QUuid, WalletTransaction*> TransactionHash;
using Subnet = QPair<QHostAddress, int>; using Subnet = QPair<QHostAddress, int>;
using SubnetList = std::vector<Subnet>; using SubnetList = std::vector<Subnet>;
const int INVALID_ICE_LOOKUP_ID = -1;
enum ReplicationServerDirection { enum ReplicationServerDirection {
Upstream, Upstream,
Downstream Downstream
@ -114,6 +116,8 @@ private slots:
void tokenGrantFinished(); void tokenGrantFinished();
void profileRequestFinished(); void profileRequestFinished();
void timeoutICEAddressLookup();
signals: signals:
void iceServerChanged(); void iceServerChanged();
void userConnected(); void userConnected();
@ -223,7 +227,7 @@ private:
QList<QHostAddress> _iceServerAddresses; QList<QHostAddress> _iceServerAddresses;
QSet<QHostAddress> _failedIceServerAddresses; QSet<QHostAddress> _failedIceServerAddresses;
int _iceAddressLookupID { -1 }; int _iceAddressLookupID { INVALID_ICE_LOOKUP_ID };
int _noReplyICEHeartbeats { 0 }; int _noReplyICEHeartbeats { 0 };
int _numHeartbeatDenials { 0 }; int _numHeartbeatDenials { 0 };
bool _connectedToICEServer { false }; bool _connectedToICEServer { false };