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

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 enum MDnsUpdateType {
szym 2013/06/07 16:40:02 nit: Needs a comment on what it is used for.
Noam Samuel 2013/06/07 23:54:43 Done.
21 kMDnsRecordAdded,
22 kMDnsRecordChanged,
23 kMDnsRecordRemoved
24 };
25
26 enum MDnsTransactionResult {
szym 2013/06/07 16:40:02 nit: Needs a comment on what it is used for.
Noam Samuel 2013/06/07 23:54:43 Done.
27 // Called whenever a record is found.
szym 2013/06/07 16:40:02 Nit: "Passed" would be better than "called".
Noam Samuel 2013/06/07 23:54:43 Done.
28 kMDnsTransactionRecord,
29 // The transaction is done. Applies to non-single-valued transactions. Is
30 // called when the transaction has finished (this is the last call to the
31 // callback).
32 kMDnsTransactionDone,
33 // No results have been found. Applies to single-valued transactions. Is
34 // called when the transaction has finished without finding any results.
szym 2013/06/07 16:40:02 nit: Would make sense to mention that this is the
Noam Samuel 2013/06/07 23:54:43 Done.
35 kMDnsTransactionNoResults,
36 // Called when an NSec record is read for this transaction's query. This means
37 // there cannot possibly be a record of the type and name for this
38 // transaction.
39 kMDnsTransactionNSec
40 };
41
42 enum MDnsTransactionFlags {
szym 2013/06/07 16:40:02 nit: Needs a comment on what it is used for.
Noam Samuel 2013/06/07 23:54:43 Done.
43 // Transaction should return only one result, and stop listening after it.
44 // Note that single result transactions will signal when their timeout is
45 // reached, whereas multi-result transactions will not.
46 kMDnsTransactionSingleResult = 0x1,
szym 2013/06/07 16:40:02 nit: Use 1 << 0 instead of 0x1. Same below.
Noam Samuel 2013/06/07 23:54:43 Done.
47 // Query the cache or the network. May both be used. One must be present.
48 kMDnsTransactionQueryCache = 0x2,
49 kMDnsTransactionQueryNetwork = 0x4,
50 // TODO(noamsml): Add flag for flushing cache when feature is implemented
51 // Mask of all possible flags on MDnsTransaction.
52 kMDnsTransactionFlagMask = 0x7,
szym 2013/06/07 16:40:02 Never used. Remove.
Noam Samuel 2013/06/07 23:54:43 This is used in a DCHECK to warn users who pass no
53 };
54
55 // A class representing a one-time record lookup. A transaction takes one
szym 2013/06/07 16:40:02 nit: "A class" is redundant. "Represents a one-tim
Noam Samuel 2013/06/07 23:54:43 Done.
56 // associated callback (see |MDnsClient::CreateTransaction|) and calls it
57 // whenever a matching record has been found, either from the cache or
58 // by querying the network (it may choose to query either or both based on its
59 // creation flags, see MDnsTransactionFlags). Network-based transactions will
60 // time out after a reasonable number of seconds.
61 class MDnsTransaction {
62 public:
63 typedef base::Callback<void(MDnsTransactionResult, const RecordParsed*)>
64 ResultCallback;
65
66 // Destroying the transaction cancels it.
67 virtual ~MDnsTransaction() {}
68
69 // Start the transaction.
szym 2013/06/07 16:40:02 nit: Return what?
Noam Samuel 2013/06/07 23:54:43 Done.
70 virtual bool Start() = 0;
71
72 // Get the host or service name for the transaction.
73 virtual const std::string& GetName() const = 0;
74
75 // Get the type for this transaction (SRV, TXT, A, AAA, etc)
76 virtual uint16 GetType() const = 0;
77 };
78
79 // A listener listens for updates regarding a specific record or set of records.
80 class MDnsListener {
81 public:
82 class Delegate {
83 public:
84 virtual ~Delegate() {}
85
86 // Called when a record is added, removed or updated.
87 virtual void OnRecordUpdate(MDnsUpdateType update,
88 const RecordParsed* record) = 0;
89
90 // Called when a record is marked nonexistent by an NSEC record.
91 virtual void OnNsecRecord(const std::string& name, unsigned type) = 0;
92
93 // Called when the cache is purged (due, for example, ot the network
94 // disconnecting).
95 virtual void OnCachePurged() = 0;
96 };
97
98 // Destroying the listener stops listening.
99 virtual ~MDnsListener() {}
100
101 // Start the listener.
102 virtual bool Start() = 0;
103
104 // Get the host or service name for this query.
105 // Return an empty string for no name.
106 virtual const std::string& GetName() const = 0;
107
108 // Get the type for this query (SRV, TXT, A, AAA, etc)
109 virtual uint16 GetType() const = 0;
110 };
111
112 // This class listens for Multicast DNS on the local network. You can access
szym 2013/06/07 16:40:02 nit: No need for "This class".
Noam Samuel 2013/06/07 23:54:43 Done.
113 // information regarding multicast DNS either by creating an |MDnsListener| to
114 // be notified of new records, or by creating an |MDnsTransaction| to look up
115 // the value of a specific records.
116 class MDnsClient {
117 public:
118 virtual ~MDnsClient() {}
119
120 // Create listener object for RRType |rrtype| and name |name|.
121 // If |name| is an empty string, listen to all notification of type
122 // |rrtype|. If a listener is |active|, it will send queries when the client
123 // thinks they are needed. If |alert_existing_records| is true, a listener's
124 // delegate will be alerted for records already in the cache when it is
125 // created.
szym 2013/06/07 16:40:02 Update comment to reflect change in interface.
Noam Samuel 2013/06/07 23:54:43 Done.
126 virtual scoped_ptr<MDnsListener> CreateListener(
127 uint16 rrtype,
128 const std::string& name,
129 MDnsListener::Delegate* delegate) = 0;
130
131 // Create a transaction to Query MDNS for a query to the cache, to the
szym 2013/06/07 16:40:02 Confusing grammar.
Noam Samuel 2013/06/07 23:54:43 Done.
132 // network, or to both, it completes via a callback that may be called
133 // synchronously.
134 virtual scoped_ptr<MDnsTransaction> CreateTransaction(
135 uint16 rrtype,
136 const std::string& name,
137 int flags, // See MDnsTransactionFlags
138 const MDnsTransaction::ResultCallback& callback) = 0;
139
140 // Lazily create and return static instance for MDnsClient.
141 static MDnsClient* GetInstance();
142
143 // Set the global instance (for testing). MUST be called before the first call
144 // to GetInstance.
145 static void SetInstance(MDnsClient* instance);
146 };
147
148 } // net
149 #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_impl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698