Fix bug "dns timeout, no terrasync servers found"
The existance of a dns entry with a protocol defined caused the naptr callback being terminated early and the request never completed. This patch also adds a unit test for this particular case. test_dns now also accepts up to two command line parameters: first: dns DN to query for NAPTR records (default: terrasync.flightgear.org) second: service to query (default: empty)
This commit is contained in:
@@ -191,11 +191,11 @@ static void dnscbNAPTR(struct dns_ctx *ctx, struct dns_rr_naptr *result, void *d
|
||||
r->ttl = result->dnsnaptr_ttl;
|
||||
for (int i = 0; i < result->dnsnaptr_nrr; i++) {
|
||||
if( !r->qservice.empty() && r->qservice != result->dnsnaptr_naptr[i].service )
|
||||
return;
|
||||
continue;
|
||||
|
||||
//TODO: case ignore and result flags may have more than one flag
|
||||
if( !r->qflags.empty() && r->qflags != result->dnsnaptr_naptr[i].flags )
|
||||
return;
|
||||
continue;
|
||||
|
||||
NAPTRRequest::NAPTR_ptr naptr(new NAPTRRequest::NAPTR);
|
||||
r->entries.push_back(naptr);
|
||||
|
||||
@@ -78,6 +78,9 @@ int main(int argc, char* argv[])
|
||||
{
|
||||
sglog().setLogLevels( SG_ALL, SG_DEBUG );
|
||||
|
||||
const char * EXISTING_RECORD = argc > 1 ? argv[1] : "terrasync.flightgear.org";
|
||||
const char * QSERVICE = argc > 2 ? argv[2] : "https+ws20";
|
||||
|
||||
Watchdog watchdog;
|
||||
watchdog.start(100);
|
||||
|
||||
@@ -98,8 +101,7 @@ int main(int argc, char* argv[])
|
||||
cout << "done" << endl;
|
||||
}
|
||||
|
||||
#define EXISTING_RECORD "terrasync.flightgear.org"
|
||||
cout << "test existing NAPTR: " EXISTING_RECORD << endl;
|
||||
cout << "test existing NAPTR: " << EXISTING_RECORD << endl;
|
||||
{
|
||||
DNS::NAPTRRequest * naptrRequest = new DNS::NAPTRRequest(EXISTING_RECORD);
|
||||
DNS::Request_ptr r(naptrRequest);
|
||||
@@ -110,17 +112,18 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
|
||||
if( r->isTimeout() ) {
|
||||
cerr << "timeout testing existing record " EXISTING_RECORD << endl;
|
||||
cerr << "timeout testing existing record " << EXISTING_RECORD << endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if(naptrRequest->entries.empty()) {
|
||||
cerr << "no results for " EXISTING_RECORD << endl;
|
||||
cerr << "no results for " << EXISTING_RECORD << endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
cout << "test for ascending preference/order" << endl;
|
||||
int order = -1, preference = -1;
|
||||
for( DNS::NAPTRRequest::NAPTR_list::const_iterator it = naptrRequest->entries.begin(); it != naptrRequest->entries.end(); ++it ) {
|
||||
cout << "NAPTR " << (*it)->order << " " << (*it)->preference << " '" << (*it)->service << "' '" << (*it)->regexp << "' '" << (*it)->replacement << "'" << endl;
|
||||
// currently only support "U" which implies empty replacement
|
||||
SG_CHECK_EQUAL((*it)->flags, "U" );
|
||||
SG_CHECK_EQUAL(naptrRequest->entries[0]->replacement, "" );
|
||||
@@ -154,6 +157,29 @@ int main(int argc, char* argv[])
|
||||
|
||||
}
|
||||
}
|
||||
cout << "test existing NAPTR with explicit qservice: " << QSERVICE << endl;
|
||||
{
|
||||
DNS::NAPTRRequest * naptrRequest = new DNS::NAPTRRequest(EXISTING_RECORD);
|
||||
naptrRequest->qservice = QSERVICE;
|
||||
DNS::Request_ptr r(naptrRequest);
|
||||
cl.makeRequest(r);
|
||||
while( !r->isComplete() && !r->isTimeout()) {
|
||||
SGTimeStamp::sleepForMSec(200);
|
||||
cl.update(0);
|
||||
}
|
||||
|
||||
if( r->isTimeout() ) {
|
||||
cerr << "timeout testing existing record " << EXISTING_RECORD << endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if(naptrRequest->entries.empty()) {
|
||||
cerr << "no results for " << EXISTING_RECORD << endl;
|
||||
//return EXIT_FAILURE; // not yet a failure - probably add this for 2017.4 and create DNS entries
|
||||
}
|
||||
for( DNS::NAPTRRequest::NAPTR_list::const_iterator it = naptrRequest->entries.begin(); it != naptrRequest->entries.end(); ++it ) {
|
||||
cout << "NAPTR " << (*it)->order << " " << (*it)->preference << " '" << (*it)->service << "' '" << (*it)->regexp << "' '" << (*it)->replacement << "'" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
cout << "test non-existing NAPTR" << endl;
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user