diff options
author | szym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-06 23:32:58 +0000 |
---|---|---|
committer | szym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-06 23:32:58 +0000 |
commit | ad24b1827fe58c4a22c0cddb5791a95f2ab1b21b (patch) | |
tree | 7e5e4727d7ab5e3a96bc95ee890aebb1b6c2d608 /net/dns/dns_client.h | |
parent | d7de57877613a63e36facbd485245918c1131f61 (diff) | |
download | chromium_src-ad24b1827fe58c4a22c0cddb5791a95f2ab1b21b.zip chromium_src-ad24b1827fe58c4a22c0cddb5791a95f2ab1b21b.tar.gz chromium_src-ad24b1827fe58c4a22c0cddb5791a95f2ab1b21b.tar.bz2 |
Isolates generic DnsClient from AsyncHostResolver.
DnsClient provides a generic DNS client that allows fetching resource records.
DnsClient is very lightweight and does not support aggregation, queuing or
prioritization of requests.
This is the first CL in a series to merge AsyncHostResolver into
HostResolverImpl.
Also introduces general-purpose BigEndianReader/Writer.
BUG=90881
TEST=./net_unittests
Review URL: http://codereview.chromium.org/8762001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113282 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/dns/dns_client.h')
-rw-r--r-- | net/dns/dns_client.h | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/net/dns/dns_client.h b/net/dns/dns_client.h new file mode 100644 index 0000000..af75cf6 --- /dev/null +++ b/net/dns/dns_client.h @@ -0,0 +1,93 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_DNS_DNS_CLIENT_H_ +#define NET_DNS_DNS_CLIENT_H_ +#pragma once + +#include <string> + +#include "base/basictypes.h" +#include "base/callback.h" +#include "base/memory/weak_ptr.h" +#include "net/base/net_export.h" + +namespace base { +class StringPiece; +} + +namespace net { + +class BoundNetLog; +class ClientSocketFactory; +class DnsResponse; +class DnsSession; + +// DnsClient performs asynchronous DNS queries. DnsClient takes care of +// retransmissions, DNS server fallback (or round-robin), suffix search, and +// simple response validation ("does it match the query") to fight poisoning. +// It does NOT perform caching, aggregation or prioritization of requests. +// +// Destroying DnsClient does NOT affect any already created Requests. +// +// TODO(szym): consider adding flags to MakeRequest to indicate options: +// -- don't perform suffix search +// -- query both A and AAAA at once +// -- accept truncated response (and/or forbid TCP) +class NET_EXPORT_PRIVATE DnsClient { + public: + class Request; + // Callback for complete requests. Note that DnsResponse might be NULL if + // the DNS server(s) could not be reached. + typedef base::Callback<void(Request* req, + int result, + const DnsResponse* resp)> RequestCallback; + + // A data-holder for a request made to the DnsClient. + // Destroying the request cancels the underlying network effort. + class NET_EXPORT_PRIVATE Request { + public: + Request(const base::StringPiece& qname, + uint16 qtype, + const RequestCallback& callback); + virtual ~Request(); + + const std::string& qname() const { return qname_; } + + uint16 qtype() const { return qtype_; } + + virtual int Start() = 0; + + void DoCallback(int result, const DnsResponse* response) { + callback_.Run(this, result, response); + } + + private: + std::string qname_; + uint16 qtype_; + RequestCallback callback_; + + DISALLOW_COPY_AND_ASSIGN(Request); + }; + + virtual ~DnsClient() {} + + // Makes asynchronous DNS query for the given |qname| and |qtype| (assuming + // QCLASS == IN). The caller is responsible for destroying the returned + // request whether to cancel it or after its completion. + // (Destroying DnsClient does not abort the requests.) + virtual Request* CreateRequest( + const base::StringPiece& qname, + uint16 qtype, + const RequestCallback& callback, + const BoundNetLog& source_net_log) WARN_UNUSED_RESULT = 0; + + // Creates a socket-based DnsClient using the |session|. + static DnsClient* CreateClient(DnsSession* session) WARN_UNUSED_RESULT; +}; + +} // namespace net + +#endif // NET_DNS_DNS_CLIENT_H_ + |