blob: 7b62bc47d3972bc34d99975921802f0846489a31 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#include "../beaconserver.h"
void BeaconServer::onUplinkTimer()
{
// get uplinks from settings
QListIterator<SyncServer> syncServers(_coreObject->Settings.SyncerSettings.syncServers);
while ( syncServers.hasNext() )
{
// get next item
SyncServer thisUplink = syncServers.next();
QString remoteHostname = thisUplink.remoteAddress;
unsigned short remotePort = thisUplink.beaconPort;
// resolve (async) uplink address and let callback perform the uplink
QHostInfo::lookupHost(remoteHostname, this, [this, remoteHostname, remotePort] (const QHostInfo &host)
{
// errors during lookup?
if ( host.error() == QHostInfo::NoError and ! host.addresses().empty() )
{
// create and send heartbeat
QNetworkDatagram udpDatagram( _uplinkData.toLatin1(), host.addresses().first(), remotePort );
_udpSocket.writeDatagram( udpDatagram );
// add to log
_coreObject->Log.logEvent("uplink", QStringLiteral("sending uplink to %1 (%2:%3)")
.arg(remoteHostname,
host.addresses().first().toString(),
QString::number(remotePort)));
// function this->onUdpRead() will handle any responses (secure/basic/status)
}
else
{
// log failure to resolve
_coreObject->Log.logEvent("uplink", QStringLiteral("cannot resolve %1: %2")
.arg( remoteHostname, host.errorString()));
}
}); // end QHostInfo
} // end while
}
|