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

Side by Side Diff: net/dns/mdns_client.h

Issue 15733008: Multicast DNS implementation (initial) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mdns_implementation2
Patch Set: Created 7 years, 6 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2013 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_MDNS_CLIENT_H_
6 #define NET_DNS_MDNS_CLIENT_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/callback.h"
12 #include "net/dns/dns_query.h"
13 #include "net/dns/dns_response.h"
14 #include "net/dns/record_parsed.h"
15
16 namespace net {
17
18 class RecordParsed;
19
20 // Used in the MDnsListener delegate to signify what type of change has been
21 // made to a record.
22 enum MDnsUpdateType {
szym 2013/06/12 21:35:41 Perhaps put this nested in MDnsListener::UpdateTyp
Noam Samuel 2013/06/13 01:08:40 Done.
23 kMDnsRecordAdded,
szym 2013/06/12 21:35:41 http://www.chromium.org/developers/coding-style pr
Noam Samuel 2013/06/13 01:08:40 Done.
24 kMDnsRecordChanged,
25 kMDnsRecordRemoved
26 };
27
28 // Used in the MDnsTransaction to signify what type of result the transaction
29 // has recieved.
30 enum MDnsTransactionResult {
szym 2013/06/12 21:35:41 You could move this into MDnsTransaction so that t
Noam Samuel 2013/06/13 01:08:40 Done.
31 // Passed whenever a record is found.
32 kMDnsTransactionRecord,
33 // The transaction is done. Applies to non-single-valued transactions. Is
34 // called when the transaction has finished (this is the last call to the
35 // callback).
36 kMDnsTransactionDone,
37 // No results have been found. Applies to single-valued transactions. Is
38 // called when the transaction has finished without finding any results.
39 // For transactions that use the network, this happens when a timeout occurs,
40 // for transactions that are cache-only, this happens when no results are in
41 // the cache.
42 kMDnsTransactionNoResults,
43 // Called when an NSec record is read for this transaction's query. This means
44 // there cannot possibly be a record of the type and name for this
45 // transaction.
46 kMDnsTransactionNSec
47 };
48
49 // Used when creating an MDnsTransaction.
50 enum MDnsTransactionFlags {
51 // Transaction should return only one result, and stop listening after it.
52 // Note that single result transactions will signal when their timeout is
53 // reached, whereas multi-result transactions will not.
54 kMDnsTransactionSingleResult = 1 << 0,
55 // Query the cache or the network. May both be used. One must be present.
56 kMDnsTransactionQueryCache = 1 << 1,
57 kMDnsTransactionQueryNetwork = 1 << 2,
58 // TODO(noamsml): Add flag for flushing cache when feature is implemented
59 // Mask of all possible flags on MDnsTransaction.
60 kMDnsTransactionFlagMask = (1 << 3) - 1,
61 };
62
63 // Represents a one-time record lookup. A transaction takes one
64 // associated callback (see |MDnsClient::CreateTransaction|) and calls it
65 // whenever a matching record has been found, either from the cache or
66 // by querying the network (it may choose to query either or both based on its
67 // creation flags, see MDnsTransactionFlags). Network-based transactions will
68 // time out after a reasonable number of seconds.
69 class MDnsTransaction {
70 public:
71 typedef base::Callback<void(MDnsTransactionResult, const RecordParsed*)>
72 ResultCallback;
73
74 // Destroying the transaction cancels it.
75 virtual ~MDnsTransaction() {}
76
77 // Start the transaction. Return true on success.
szym 2013/06/12 21:35:41 Add a comment that cache-only transactions execute
Noam Samuel 2013/06/13 01:08:40 Done.
78 virtual bool Start() = 0;
79
80 // Get the host or service name for the transaction.
81 virtual const std::string& GetName() const = 0;
82
83 // Get the type for this transaction (SRV, TXT, A, AAA, etc)
84 virtual uint16 GetType() const = 0;
85 };
86
87 // A listener listens for updates regarding a specific record or set of records.
szym 2013/06/12 21:35:41 Add a short comment explaining the design responsi
Noam Samuel 2013/06/13 01:08:40 Done.
88 class MDnsListener {
89 public:
90 class Delegate {
91 public:
92 virtual ~Delegate() {}
93
94 // Called when a record is added, removed or updated.
95 virtual void OnRecordUpdate(MDnsUpdateType update,
96 const RecordParsed* record) = 0;
97
98 // Called when a record is marked nonexistent by an NSEC record.
99 virtual void OnNsecRecord(const std::string& name, unsigned type) = 0;
100
101 // Called when the cache is purged (due, for example, ot the network
102 // disconnecting).
103 virtual void OnCachePurged() = 0;
104 };
105
106 // Destroying the listener stops listening.
107 virtual ~MDnsListener() {}
108
109 // Start the listener. Return true on success.
110 virtual bool Start() = 0;
111
112 // Get the host or service name for this query.
113 // Return an empty string for no name.
114 virtual const std::string& GetName() const = 0;
115
116 // Get the type for this query (SRV, TXT, A, AAA, etc)
117 virtual uint16 GetType() const = 0;
118 };
119
120 // Listens for Multicast DNS on the local network. You can access
121 // information regarding multicast DNS either by creating an |MDnsListener| to
122 // be notified of new records, or by creating an |MDnsTransaction| to look up
123 // the value of a specific records.
124 class MDnsClient {
125 public:
126 virtual ~MDnsClient() {}
127
128 // Create listener object for RRType |rrtype| and name |name|.
129 // If |name| is an empty string, listen to all notification of type
130 // |rrtype|.
131 virtual scoped_ptr<MDnsListener> CreateListener(
132 uint16 rrtype,
133 const std::string& name,
134 MDnsListener::Delegate* delegate) = 0;
135
136 // Create a transaction that can be used to query either the MDns cache, the
137 // network, or both for records of type |rrtype| and name |name|. |flags| is
138 // defined by MDnsTransactionFlags.
139 virtual scoped_ptr<MDnsTransaction> CreateTransaction(
140 uint16 rrtype,
141 const std::string& name,
142 int flags,
143 const MDnsTransaction::ResultCallback& callback) = 0;
144
145 // Lazily create and return static instance for MDnsClient.
146 static MDnsClient* GetInstance();
147
148 // Set the global instance (for testing). MUST be called before the first call
149 // to GetInstance.
150 static void SetInstance(MDnsClient* instance);
151 };
152
153 } // namespace net
154 #endif // NET_DNS_MDNS_CLIENT_H_
OLDNEW
« no previous file with comments | « net/dns/dns_response.cc ('k') | net/dns/mdns_client.cc » ('j') | net/dns/mdns_client.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698