Home | History | Annotate | Download | only in dns
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef NET_DNS_DNS_TRANSACTION_H_
      6 #define NET_DNS_DNS_TRANSACTION_H_
      7 
      8 #include <string>
      9 
     10 #include "base/basictypes.h"
     11 #include "base/callback_forward.h"
     12 #include "base/memory/scoped_ptr.h"
     13 #include "net/base/net_export.h"
     14 
     15 namespace net {
     16 
     17 class BoundNetLog;
     18 class DnsResponse;
     19 class DnsSession;
     20 
     21 // DnsTransaction implements a stub DNS resolver as defined in RFC 1034.
     22 // The DnsTransaction takes care of retransmissions, name server fallback (or
     23 // round-robin), suffix search, and simple response validation ("does it match
     24 // the query") to fight poisoning.
     25 //
     26 // Destroying DnsTransaction cancels the underlying network effort.
     27 class NET_EXPORT_PRIVATE DnsTransaction {
     28  public:
     29   virtual ~DnsTransaction() {}
     30 
     31   // Returns the original |hostname|.
     32   virtual const std::string& GetHostname() const = 0;
     33 
     34   // Returns the |qtype|.
     35   virtual uint16 GetType() const = 0;
     36 
     37   // Starts the transaction.  Always completes asynchronously.
     38   virtual void Start() = 0;
     39 };
     40 
     41 // Creates DnsTransaction which performs asynchronous DNS search.
     42 // It does NOT perform caching, aggregation or prioritization of transactions.
     43 //
     44 // Destroying the factory does NOT affect any already created DnsTransactions.
     45 class NET_EXPORT_PRIVATE DnsTransactionFactory {
     46  public:
     47   // Called with the response or NULL if no matching response was received.
     48   // Note that the |GetDottedName()| of the response may be different than the
     49   // original |hostname| as a result of suffix search.
     50   typedef base::Callback<void(DnsTransaction* transaction,
     51                               int neterror,
     52                               const DnsResponse* response)> CallbackType;
     53 
     54   virtual ~DnsTransactionFactory() {}
     55 
     56   // Creates DnsTransaction for the given |hostname| and |qtype| (assuming
     57   // QCLASS is IN). |hostname| should be in the dotted form. A dot at the end
     58   // implies the domain name is fully-qualified and will be exempt from suffix
     59   // search. |hostname| should not be an IP literal.
     60   //
     61   // The transaction will run |callback| upon asynchronous completion.
     62   // The |net_log| is used as the parent log.
     63   virtual scoped_ptr<DnsTransaction> CreateTransaction(
     64       const std::string& hostname,
     65       uint16 qtype,
     66       const CallbackType& callback,
     67       const BoundNetLog& net_log) WARN_UNUSED_RESULT = 0;
     68 
     69   // Creates a DnsTransactionFactory which creates DnsTransactionImpl using the
     70   // |session|.
     71   static scoped_ptr<DnsTransactionFactory> CreateFactory(
     72       DnsSession* session) WARN_UNUSED_RESULT;
     73 };
     74 
     75 }  // namespace net
     76 
     77 #endif  // NET_DNS_DNS_TRANSACTION_H_
     78 
     79