ippdiscovery: resolve unknown targets

If a target entry was included in an answer, but not its IP,
query about that target.
This commit is contained in:
Anton Thomasson 2020-04-30 18:45:43 +02:00
parent de1d88686f
commit 218f74d41e

View file

@ -150,7 +150,8 @@ void IppDiscovery::readPendingDatagrams()
QHostAddress sender; QHostAddress sender;
quint16 senderPort; quint16 senderPort;
QStringList ipp_ptrs; QStringList new_ipp_ptrs;
QStringList new_targets;
socket->readDatagram((char*)(resp.raw()), size, &sender, &senderPort); socket->readDatagram((char*)(resp.raw()), size, &sender, &senderPort);
sender = QHostAddress(sender.toIPv4Address()); sender = QHostAddress(sender.toIPv4Address());
@ -182,7 +183,7 @@ void IppDiscovery::readPendingDatagrams()
QString tmpname = get_addr(resp).join("."); QString tmpname = get_addr(resp).join(".");
if(aaddr.endsWith("_ipp._tcp.local")) if(aaddr.endsWith("_ipp._tcp.local"))
{ {
ipp_ptrs.append(tmpname); new_ipp_ptrs.append(tmpname);
} }
} }
else if(atype == TXT) else if(atype == TXT)
@ -206,6 +207,7 @@ void IppDiscovery::readPendingDatagrams()
QString target = get_addr(resp).join("."); QString target = get_addr(resp).join(".");
_ports[aaddr] = port; _ports[aaddr] = port;
_targets[aaddr] = target; _targets[aaddr] = target;
new_targets.append(target);
} }
else if(atype == A) else if(atype == A)
{ {
@ -227,25 +229,35 @@ void IppDiscovery::readPendingDatagrams()
qDebug() << e.what(); qDebug() << e.what();
return; return;
} }
qDebug() << "new ipp ptrs" << ipp_ptrs; qDebug() << "new ipp ptrs" << new_ipp_ptrs;
qDebug() << "ipp ptrs" << _ipp; qDebug() << "ipp ptrs" << _ipp;
qDebug() << "rps" << _rps; qDebug() << "rps" << _rps;
qDebug() << "ports" << _ports; qDebug() << "ports" << _ports;
qDebug() << "new targets" << new_targets;
qDebug() << "targets" << _targets; qDebug() << "targets" << _targets;
qDebug() << "AAs" << _AAs; qDebug() << "AAs" << _AAs;
qDebug() << "AAAAs" << _AAAAs; qDebug() << "AAAAs" << _AAAAs;
for(QStringList::Iterator it = ipp_ptrs.begin(); it != ipp_ptrs.end(); it++) for(QStringList::Iterator it = new_ipp_ptrs.begin(); it != new_ipp_ptrs.end(); it++)
{ {
if(!_ipp.contains(*it)) if(!_ipp.contains(*it))
{ {
_ipp.append(*it); _ipp.append(*it);
} }
if(!_ports.contains(*it) || !_targets.contains(*it) || !_rps.contains(*it)) // If pointer does not resolve to a target or is missing information, query about it
if( !_targets.contains(*it) || !_ports.contains(*it) || !_rps.contains(*it))
{ // if the PTR doesn't already resolve, ask for everything about it { // if the PTR doesn't already resolve, ask for everything about it
sendQuery(ALL, it->split('.')); sendQuery(ALL, it->split('.'));
} }
} }
for(QStringList::Iterator it = new_targets.begin(); it != new_targets.end(); it++)
{
// If target does not resolve to an address, query about it
if(!_AAs.contains(*it))
{
sendQuery(ALL, it->split('.'));
}
}
} }
this->update(); this->update();