void NeardHelper::interfacesAdded(const QDBusObjectPath &path, InterfaceList interfaceList) { foreach (const QString &key, interfaceList.keys()) { if (key == QStringLiteral("org.neard.Tag")) { emit tagFound(path); break; } if (key == QStringLiteral("org.neard.Record")) { emit recordFound(path); break; } } }
void Discover::acceptRecords (QList<Record> records, bool removeThem, QString senderScope, QString senderAddress, QString senderPort) { // TODO // This function gets its own copy of records // This loop edits each item so it can be used after for (Record& record : records) { // Preprocess the record before considering it Record::decompressReserved(record); // Set the scope based on the address if included, otherwise scope of sender QHostAddress recordAddress; if (record.has("Address")) recordAddress.setAddress(record["Address"]); if (recordAddress.protocol()!=QAbstractSocket::IPv4Protocol) recordAddress = QHostAddress::Null; if (recordAddress==QHostAddress::Broadcast) recordAddress = QHostAddress::Null; if (recordAddress==QHostAddress::AnyIPv4) recordAddress = QHostAddress::Null; if (recordAddress.isNull()) { record["Scope"] = senderScope; } else { if (recordAddress.isLoopback()) record["Scope"] = "Loopback"; else if (addressIsLocal(recordAddress)) record["Scope"] = "Local"; else record["Scope"] = "Global"; } if (record["Address"].isEmpty()) record["Address"] = senderAddress; // Sender may override these if (record["Port"].isEmpty()) record["Port"] = senderPort; // Sender may override these // TODO Extract a custom expiration duration so each record can have its own if (removeThem) { // See if it's new if (foundRecords.contains(record)) { logDebug(QString("Record Departed: %1").arg(record.toString())); foundRecords.remove(record); emit recordLost(record); } } else { // See if it's new if (not foundRecords.contains(record) and passesFilters(record)) { logDebug(QString("Found Record: %1").arg(record.toString())); emit recordFound(record); } // Reset the timer foundRecords[record] = QDateTime::currentMSecsSinceEpoch() + 2500; // Set the expire time } expireTimer->start(0); // In case the next expiration time was changed } // Server: Forward global departures to other global peers if (mServerMode and removeThem and senderScope == "Global") { QByteArray datagram("DSDD"); datagram += makeDatagram(records, false); for (Record& record : foundRecords.keys()) if (record["Scope"] == "Global") { bool ok; globalSocket->writeDatagram(datagram, QHostAddress(record["Address"]), record["Port"].toUInt(&ok, 10)); } } }