Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(512)

Unified Diff: net/dns/dns_session.h

Issue 10826229: [net/dns] Reuse pre-connected sockets in DnsTransaction to add entropy to source ports. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/dns/dns_session.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/dns/dns_session.h
diff --git a/net/dns/dns_session.h b/net/dns/dns_session.h
index 70728c7837b8558493776d0dc46a5d398c7bce8e..f61e166cce92e17acb6261fa32858c783df075e2 100644
--- a/net/dns/dns_session.h
+++ b/net/dns/dns_session.h
@@ -5,11 +5,16 @@
#ifndef NET_DNS_DNS_SESSION_H_
#define NET_DNS_DNS_SESSION_H_
+#include <map>
+#include <vector>
+
#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
#include "base/time.h"
#include "net/base/net_export.h"
#include "net/base/rand_callback.h"
#include "net/dns/dns_config_service.h"
+#include "net/udp/datagram_client_socket.h"
namespace net {
@@ -24,6 +29,21 @@ class NET_EXPORT_PRIVATE DnsSession
public:
typedef base::Callback<int()> RandCallback;
+ class SocketLease {
+ public:
+ SocketLease(scoped_refptr<DnsSession> session,
+ int server_index,
+ scoped_ptr<DatagramClientSocket> socket);
+ ~SocketLease();
+
+ DatagramClientSocket* socket() { return socket_.get(); }
+
+ private:
+ scoped_refptr<DnsSession> session_;
+ int server_index_;
+ scoped_ptr<DatagramClientSocket> socket_;
+ };
+
DnsSession(const DnsConfig& config,
ClientSocketFactory* factory,
const RandIntCallback& rand_int_callback,
@@ -32,8 +52,6 @@ class NET_EXPORT_PRIVATE DnsSession
const DnsConfig& config() const { return config_; }
NetLog* net_log() const { return net_log_; }
- ClientSocketFactory* socket_factory() { return socket_factory_; }
-
// Return the next random query ID.
int NextQueryId() const;
@@ -43,21 +61,32 @@ class NET_EXPORT_PRIVATE DnsSession
// Return the timeout for the next query.
base::TimeDelta NextTimeout(int attempt);
+ // Allocate a socket, already connected to the server address.
+ // TODO(szym): add NetLog param?
+ scoped_ptr<SocketLease> AllocateSocket(int server_index);
+
private:
friend class base::RefCounted<DnsSession>;
+ typedef std::vector<DatagramClientSocket*> SocketVector;
+ typedef std::vector<SocketVector> SocketPool;
+
~DnsSession();
+ // Release a socket.
+ void FreeSocket(int server_index, scoped_ptr<DatagramClientSocket> socket);
+
const DnsConfig config_;
ClientSocketFactory* socket_factory_;
RandCallback rand_callback_;
NetLog* net_log_;
+ SocketPool sockets_;
+
// Current index into |config_.nameservers| to begin resolution with.
int server_index_;
// TODO(szym): Add current RTT estimate.
// TODO(szym): Add TCP connection pool to support DNS over TCP.
- // TODO(szym): Add UDP port pool to avoid NAT table overload.
DISALLOW_COPY_AND_ASSIGN(DnsSession);
};
« no previous file with comments | « no previous file | net/dns/dns_session.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698