< Previous by Date Date Index Next by Date >
  Thread Index  

[reSIProcate] Using DnsInterface synchronously in the calling thread


Hi,

I have a multithreaded system that needs to use the reSIProcate RFC 3263
DnsInterface lookup methods.  The testDns program is a great simulation of
my application layer - I just need to duplicate its use of the TestDns
class.

Since my application is already multithreaded, I figured I could cut some
overhead if I changed TestDns to not inherit from ThreadIf.  Instead, I'll
let it do its thing in my calling thread.  I was able to make the required
changes and sure enough it works, but the returned address list comes out in
reverse order to gethostbyname (and nslookup).  For all you DNS gurus, is
this a problem?  I think the RFC says a DNS lookup should return addresses
in descending order of preference, with the best one first.  I don't have
this problem when I use the original testDns.

The output of my test code looks like this:

DNS results for sip:yahoo.com
[ V4 66.94.234.13:5060 UDP target domain=yahoo.com connectionId=0 ]
[ V4 216.109.112.135:5060 UDP target domain=yahoo.com connectionId=0 ]

Now with gethostbyname for yahoo.com
216.109.112.135
66.94.234.13

Here's what I did to TestDns, with IP6 removed.

class TestDns : public DnsInterface
{
   public:
      TestDns(DnsStub& stub) : DnsInterface(stub), mStub(stub)
      {
         addTransportType(TCP, V4);
         addTransportType(UDP, V4);
         addTransportType(TLS, V4);
         delay.tv_sec  = 0;
         delay.tv_nsec = 100000000; // 100 ms
      }

      void collectResults(TestDnsHandler* handler)
      {
         while (!handler->complete())
         {
            FdSet fdset;
            buildFdSet(fdset);
            mStub.buildFdSet(fdset);
            fdset.selectMilliSeconds(1);
            process(fdset);
            mStub.process(fdset);
            nanosleep(&delay, 0);
         }
      }

      DnsStub& mStub;

   private:
      struct timespec delay;
};

Then to access it I do this, running only one query at a time:

   Query query;
   query.handler = new TestDnsHandler;

   cerr << "Creating Uri" << endl;
   uri = Uri("sip:yahoo.com");
   query.uri = uri;
   cerr << "Creating DnsResult" << endl;
   DnsResult* res = dns.createDnsResult(query.handler);
   query.result = res;
   cerr << rf << "Looking up" << ub << endl;

   dns.lookup(res, uri);
   cerr << rf << "Done with lookup" << ub << endl;
   dns.collectResults(query.handler);

   cerr << rf << "DNS results for " << query.uri << ub << endl;
   for (std::vector<Tuple>::iterator i = query.handler->results.begin(); i
!= query.handler->results.end(); ++i)
   {
      cerr << rf << (*i) << ub << endl;
   }

   query.result->destroy();
   delete query.handler;