Allow specifing TerraSync DNS nameserver

This commit is contained in:
James Turner 2022-06-07 22:40:24 +01:00
parent 8f940ed4f2
commit a74181ded9
3 changed files with 27 additions and 8 deletions

View File

@ -37,8 +37,8 @@ namespace DNS {
class Client::ClientPrivate { class Client::ClientPrivate {
public: public:
ClientPrivate() { ClientPrivate(const std::string& nameserver)
{
if( instanceCounter++ == 0 ) if( instanceCounter++ == 0 )
if (dns_init(NULL, 0) < 0) if (dns_init(NULL, 0) < 0)
SG_LOG(SG_IO, SG_ALERT, "Can't init udns library" ); SG_LOG(SG_IO, SG_ALERT, "Can't init udns library" );
@ -48,6 +48,11 @@ public:
if (dns_init(ctx, 0) < 0) if (dns_init(ctx, 0) < 0)
SG_LOG(SG_IO, SG_ALERT, "Can't create udns context" ); SG_LOG(SG_IO, SG_ALERT, "Can't create udns context" );
if (!nameserver.empty()) {
dns_add_serv(ctx, nullptr);
dns_add_serv(ctx, nameserver.c_str());
}
if( dns_open(ctx) < 0 ) if( dns_open(ctx) < 0 )
SG_LOG(SG_IO, SG_ALERT, "Can't open udns context" ); SG_LOG(SG_IO, SG_ALERT, "Can't open udns context" );
} }
@ -254,13 +259,11 @@ void NAPTRRequest::submit( Client * client )
_query = q; _query = q;
} }
Client::Client(const std::string& nameserver) : d(new ClientPrivate{nameserver})
Client::~Client()
{ {
} }
Client::Client() : Client::~Client()
d(new ClientPrivate)
{ {
} }

View File

@ -133,7 +133,7 @@ public:
class Client class Client
{ {
public: public:
Client(); Client(const std::string& nameserver = {});
~Client(); ~Client();
void update(int waitTimeout = 0); void update(int waitTimeout = 0);

View File

@ -317,6 +317,11 @@ public:
_isAutomaticServer = (server == "automatic"); _isAutomaticServer = (server == "automatic");
} }
void setDNSServer(const std::string& nameserver)
{
_dnsNameserver = nameserver;
}
void setDNSDN( const std::string & dn ) void setDNSDN( const std::string & dn )
{ {
_dnsdn = simgear::strutils::strip(dn); _dnsdn = simgear::strutils::strip(dn);
@ -414,6 +419,7 @@ public:
string _sceneryVersion; string _sceneryVersion;
string _protocol; string _protocol;
string _dnsdn; string _dnsdn;
string _dnsNameserver;
TerrasyncThreadState _state; TerrasyncThreadState _state;
mutable std::mutex _stateLock; mutable std::mutex _stateLock;
@ -537,7 +543,7 @@ std::string SGTerraSync::WorkerThread::dnsSelectServerForService(const std::stri
naptrRequest->qflags = "U"; naptrRequest->qflags = "U";
DNS::Request_ptr r(naptrRequest); DNS::Request_ptr r(naptrRequest);
DNS::Client dnsClient; DNS::Client dnsClient{_dnsNameserver};
dnsClient.makeRequest(r); dnsClient.makeRequest(r);
SG_LOG(SG_TERRASYNC,SG_DEBUG,"DNS NAPTR query for '" << _dnsdn << "' '" << naptrRequest->qservice << "'" ); SG_LOG(SG_TERRASYNC,SG_DEBUG,"DNS NAPTR query for '" << _dnsdn << "' '" << naptrRequest->qservice << "'" );
while (!r->isComplete() && !r->isTimeout()) { while (!r->isComplete() && !r->isTimeout()) {
@ -1170,6 +1176,16 @@ void SGTerraSync::reinit()
_workerThread->setSceneryVersion( _terraRoot->getStringValue("scenery-version","ws20") ); _workerThread->setSceneryVersion( _terraRoot->getStringValue("scenery-version","ws20") );
_workerThread->setOSMCityVersion(_terraRoot->getStringValue("osm2city-version", "o2c")); _workerThread->setOSMCityVersion(_terraRoot->getStringValue("osm2city-version", "o2c"));
_workerThread->setProtocol( _terraRoot->getStringValue("protocol","") ); _workerThread->setProtocol( _terraRoot->getStringValue("protocol","") );
if (_terraRoot->hasChild("dns-server")) {
auto ns = _terraRoot->getStringValue("dns-server");
if (ns == "google") {
ns = "8.8.8.8";
}
SG_LOG(SG_TERRASYNC,SG_INFO,"DNS server override:" << ns);
_workerThread->setDNSServer(ns);
}
#if 1 #if 1
// leave it hardcoded for now, not sure about the security implications for now // leave it hardcoded for now, not sure about the security implications for now
_workerThread->setDNSDN( "terrasync.flightgear.org"); _workerThread->setDNSDN( "terrasync.flightgear.org");