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

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: Renamed files from "listener" to "client" 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 {
21 kMDnsRecordAdded,
22 kMDnsRecordChanged,
23 kMDnsRecordRemoved
24 };
25
26 enum MDnsTransactionResult {
27 kMDnsTransactionSuccess,
28 kMDnsTransactionTimeout,
29 kMDnsTransactionNsec
30 };
31
32 // A class representing a one-time unique-record lookup. A transaction takes one
33 // associated callback (see |MDnsClient::CreateTransaction|) and calls it when
34 // a matching record has been found, either from the cache or by querying the
35 // network. Transactions will time out after a reasonable number of seconds.
36 class MDnsTransaction {
37 public:
38 typedef base::Callback<void(MDnsTransactionResult, const RecordParsed*)>
39 ResultCallback;
40
41 // Destroying the transaction cancels it.
42 virtual ~MDnsTransaction() {}
43
44 // Get the host or service name for the transaction.
45 virtual const std::string& GetName() const = 0;
46
47 // Get the type for this transaction (SRV, TXT, A, AAA, etc)
48 virtual uint16 GetType() const = 0;
49 };
50
51 // A listener listens for updates regarding a specific record or set of records.
52 // If a listener is active (determined at its creation) it will send queries
53 // when appropriate.
54 class MDnsListener {
55 public:
56 class Delegate {
57 public:
58 virtual ~Delegate() {}
59
60 // Called when a record is added, removed or updated.
61 virtual void OnRecordUpdate(MDnsUpdateType update,
62 const RecordParsed* record) = 0;
63
64 // Called when a record is marked nonexistent by an NSEC record.
65 virtual void OnNsecRecord(const std::string& name, unsigned type) = 0;
66 };
67
68 // Destroying the listener stops listening.
69 virtual ~MDnsListener() {}
70
71 // Get the host or service name for this query.
72 // Return an empty string for no name.
73 virtual const std::string& GetName() const = 0;
74
75 // Get the type for this query (SRV, TXT, A, AAA, etc)
76 virtual uint16 GetType() const = 0;
77
78 // Whether this listener is active (true) or passive (false)
79 virtual bool IsActive() const = 0;
80
81 // Applies only to listeners with names. Will send out a query for new
82 // information. |force_refresh_cache| will force a refresh of all cached
83 // entities.
84 virtual bool SendQuery(bool force_refresh_cache) = 0;
85
86 // Applies only to listeners with names. Query mDNS cache synchronously for
87 // either single- or multi- valued records.
88 virtual bool QueryCache(std::vector<const RecordParsed*>* records) const = 0;
89 };
90
91 // This class listens for Multicast DNS on the local network. You can access
92 // information regarding multicast DNS either by creating an |MDnsListener| to
93 // be notified of new records, or by creating an |MDnsTransaction| to look up
94 // the value of a specific records.
95 class MDnsClient {
96 public:
97 virtual ~MDnsClient() {}
98
99 // Create listener object for RRType |rrtype| and name |name|.
100 // If |name| is an empty string, listen to all notification of type
101 // |rrtype|. If a listener is |active|, it will send queries when the client
102 // thinks they are needed. If |alert_existing_records| is true, a listener's
103 // delegate will be alerted for records already in the cache when it is
104 // created.
105 virtual scoped_ptr<MDnsListener> CreateListener(
106 uint16 rrtype,
107 const std::string& name,
108 bool active,
109 bool alert_existing_records,
110 MDnsListener::Delegate* delegate) = 0;
111
112 // Create a transaction to Query MDNS for a single-value query
113 // (A, AAAA, TXT, and SRV) asynchronously. May defer to cache.
114 virtual scoped_ptr<MDnsTransaction> CreateTransaction(
115 uint16 rrtype,
116 const std::string& name,
117 const MDnsTransaction::ResultCallback& callback) = 0;
118
119 // Lazily create and return static instance for MDnsClient.
120 static MDnsClient* GetInstance();
121
122 // Set the global instance (for testing). MUST be called before the first call
123 // to GetInstance.
124 static void SetInstance(MDnsClient* instance);
125 };
126
127 } // net
128 #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