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

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
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..973ccb3fda1a33b5c0d16bdd097262bd02d435f6
--- /dev/null
+++ b/net/dns/mdns_cache.h
@@ -0,0 +1,112 @@
+// 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);
+
+ // 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 DnsRecordCacheKey {
szym 2013/05/20 19:35:15 I'd just call this |Key|.
Noam Samuel 2013/05/20 21:07:02 Done.
+ public:
+ DnsRecordCacheKey(unsigned type,
+ const std::string& name,
+ const std::string& optional);
+ DnsRecordCacheKey(const DnsRecordCacheKey&);
+ DnsRecordCacheKey& operator=(const DnsRecordCacheKey&);
+ ~DnsRecordCacheKey();
+ bool operator<(const DnsRecordCacheKey& key) const;
+ bool operator==(const DnsRecordCacheKey& 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<DnsRecordCacheKey, const RecordParsed*>
+ MDnsCacheMap;
szym 2013/05/20 19:35:15 I'd just call this |RecordMap|.
Noam Samuel 2013/05/20 21:07:02 Done.
+
+ // 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);
+
+ // 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);
+
+ MDnsCacheMap 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') | net/dns/mdns_cache.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698