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

Unified Diff: net/dns/mdns_cache.h

Issue 14697022: Cache for mDNS records (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@record_parsed_klassbit
Patch Set: Created 7 years, 7 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 | « net/dns/dns_protocol.h ('k') | net/dns/mdns_cache.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/dns/mdns_cache.h
diff --git a/net/dns/mdns_cache.h b/net/dns/mdns_cache.h
new file mode 100644
index 0000000000000000000000000000000000000000..4505b85c632aa0a681f298d138d54815c5ee8aaf
--- /dev/null
+++ b/net/dns/mdns_cache.h
@@ -0,0 +1,108 @@
+// Copyright (c) 2013 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_MDNS_CACHE_H_
+#define NET_DNS_MDNS_CACHE_H_
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include "base/callback.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/time.h"
+#include "net/base/net_export.h"
+
+namespace net {
+
+class ParsedDnsRecord;
+class RecordParsed;
+
+// mDNS Cache
+// This is a cache of mDNS records. It keeps track of expiration times and is
+// guaranteed not to return expired records. It also has facilities for timely
+// record expiration.
+class NET_EXPORT_PRIVATE MDnsCache {
+ public:
+ typedef base::Callback<void(const RecordParsed*)> RecordRemovedCallback;
+
+ enum UpdateType {
+ RecordAdded,
+ RecordChanged,
+ NoChange
+ };
+
+ MDnsCache();
+ ~MDnsCache();
+
+ // Return value indicates whether the record was added, changed
+ // (existed previously with different value) or not changed (existed
+ // previously with same value).
+ UpdateType UpdateDnsRecord(scoped_ptr<const RecordParsed> record);
+
+ // Return records with type |type| and name |name|. Expired records will not
+ // be returned. If |name| is empty, return all records with type |type|.
+ void FindDnsRecords(unsigned type,
+ const std::string& name,
+ std::vector<const RecordParsed*>* records,
+ base::Time now) const;
+
+ // Remove expired records, call |record_removed_callback| for every removed
+ // record.
+ void CleanupRecords(base::Time now,
+ const RecordRemovedCallback& record_removed_callback);
+
+ // Returns a time less than or equal to the next time a record will expire.
+ // Is updated when CleanupRecords or UpdateDnsRecord are called. Returns
+ // base::Time when the cache is empty.
+ base::Time next_expiration() const { return next_expiration_; }
+
+ void Clear();
+
+ private:
+ // Key type for the record map. It is a 3-tuple of type, name and optional
+ // value ordered by type, then name, then optional value. This allows us to
+ // query for all records of a certain type and name, while also allowing us
+ // to set records of a certain type, name and optionally value as unique.
+ class Key {
+ public:
+ Key(unsigned type, const std::string& name, const std::string& optional);
+ Key(const Key&);
+ Key& operator=(const Key&);
+ ~Key();
+ bool operator<(const Key& key) const;
+ bool operator==(const Key& key) const;
+
+ unsigned type() const { return type_; }
+ const std::string& name() const { return name_; }
+ const std::string& optional() const { return optional_; }
+
+ private:
+ unsigned type_;
+ std::string name_;
+ std::string optional_;
+ };
+
+ typedef std::map<Key, const RecordParsed*> RecordMap;
+
+ // Get the effective expiration of a cache entry, based on its creation time
+ // and TTL. Does adjustments so entries with a TTL of zero will have a
+ // nonzero TTL, as explained in RFC 6762 Section 10.1.
+ base::Time GetEffectiveExpiration(const RecordParsed* entry) const;
+
+ // Get optional part of the DNS key for shared records. For example, in PTR
+ // records this is the pointed domain, since multiple PTR records may exist
+ // for the same name.
+ std::string GetOptionalFieldForRecord(const RecordParsed* record) const;
+
+ RecordMap mdns_cache_;
+
+ base::Time next_expiration_;
+
+ DISALLOW_COPY_AND_ASSIGN(MDnsCache);
+};
+
+} // namespace net
+
+#endif // NET_DNS_MDNS_CACHE_H_
« no previous file with comments | « net/dns/dns_protocol.h ('k') | net/dns/mdns_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698