OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_DNS_MDNS_CLIENT_H_ | 5 #ifndef NET_DNS_MDNS_CLIENT_H_ |
6 #define NET_DNS_MDNS_CLIENT_H_ | 6 #define NET_DNS_MDNS_CLIENT_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "net/base/ip_endpoint.h" | 12 #include "net/base/ip_endpoint.h" |
13 #include "net/dns/dns_query.h" | 13 #include "net/dns/dns_query.h" |
14 #include "net/dns/dns_response.h" | 14 #include "net/dns/dns_response.h" |
15 #include "net/dns/record_parsed.h" | 15 #include "net/dns/record_parsed.h" |
16 | 16 |
17 namespace net { | 17 namespace net { |
18 | 18 |
| 19 class DatagramServerSocket; |
19 class RecordParsed; | 20 class RecordParsed; |
20 | 21 |
21 // Represents a one-time record lookup. A transaction takes one | 22 // Represents a one-time record lookup. A transaction takes one |
22 // associated callback (see |MDnsClient::CreateTransaction|) and calls it | 23 // associated callback (see |MDnsClient::CreateTransaction|) and calls it |
23 // whenever a matching record has been found, either from the cache or | 24 // whenever a matching record has been found, either from the cache or |
24 // by querying the network (it may choose to query either or both based on its | 25 // by querying the network (it may choose to query either or both based on its |
25 // creation flags, see MDnsTransactionFlags). Network-based transactions will | 26 // creation flags, see MDnsTransactionFlags). Network-based transactions will |
26 // time out after a reasonable number of seconds. | 27 // time out after a reasonable number of seconds. |
27 class NET_EXPORT MDnsTransaction { | 28 class NET_EXPORT MDnsTransaction { |
28 public: | 29 public: |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 virtual bool Start() = 0; | 114 virtual bool Start() = 0; |
114 | 115 |
115 // Get the host or service name for this query. | 116 // Get the host or service name for this query. |
116 // Return an empty string for no name. | 117 // Return an empty string for no name. |
117 virtual const std::string& GetName() const = 0; | 118 virtual const std::string& GetName() const = 0; |
118 | 119 |
119 // Get the type for this query (SRV, TXT, A, AAA, etc) | 120 // Get the type for this query (SRV, TXT, A, AAA, etc) |
120 virtual uint16 GetType() const = 0; | 121 virtual uint16 GetType() const = 0; |
121 }; | 122 }; |
122 | 123 |
| 124 // Creates bound datagram sockets ready to use by MDnsClient. |
| 125 class NET_EXPORT MDnsSocketFactory { |
| 126 public: |
| 127 virtual ~MDnsSocketFactory() {} |
| 128 virtual void CreateSockets(ScopedVector<DatagramServerSocket>* sockets) = 0; |
| 129 |
| 130 static scoped_ptr<MDnsSocketFactory> CreateDefault(); |
| 131 }; |
| 132 |
123 // Listens for Multicast DNS on the local network. You can access information | 133 // Listens for Multicast DNS on the local network. You can access information |
124 // regarding multicast DNS either by creating an |MDnsListener| to be notified | 134 // regarding multicast DNS either by creating an |MDnsListener| to be notified |
125 // of new records, or by creating an |MDnsTransaction| to look up the value of a | 135 // of new records, or by creating an |MDnsTransaction| to look up the value of a |
126 // specific records. When all listeners and active transactions are destroyed, | 136 // specific records. When all listeners and active transactions are destroyed, |
127 // the client stops listening on the network and destroys the cache. | 137 // the client stops listening on the network and destroys the cache. |
128 class NET_EXPORT MDnsClient { | 138 class NET_EXPORT MDnsClient { |
129 public: | 139 public: |
130 virtual ~MDnsClient() {} | 140 virtual ~MDnsClient() {} |
131 | 141 |
132 // Create listener object for RRType |rrtype| and name |name|. | 142 // Create listener object for RRType |rrtype| and name |name|. |
133 virtual scoped_ptr<MDnsListener> CreateListener( | 143 virtual scoped_ptr<MDnsListener> CreateListener( |
134 uint16 rrtype, | 144 uint16 rrtype, |
135 const std::string& name, | 145 const std::string& name, |
136 MDnsListener::Delegate* delegate) = 0; | 146 MDnsListener::Delegate* delegate) = 0; |
137 | 147 |
138 // Create a transaction that can be used to query either the MDns cache, the | 148 // Create a transaction that can be used to query either the MDns cache, the |
139 // network, or both for records of type |rrtype| and name |name|. |flags| is | 149 // network, or both for records of type |rrtype| and name |name|. |flags| is |
140 // defined by MDnsTransactionFlags. | 150 // defined by MDnsTransactionFlags. |
141 virtual scoped_ptr<MDnsTransaction> CreateTransaction( | 151 virtual scoped_ptr<MDnsTransaction> CreateTransaction( |
142 uint16 rrtype, | 152 uint16 rrtype, |
143 const std::string& name, | 153 const std::string& name, |
144 int flags, | 154 int flags, |
145 const MDnsTransaction::ResultCallback& callback) = 0; | 155 const MDnsTransaction::ResultCallback& callback) = 0; |
146 | 156 |
147 virtual bool StartListening() = 0; | 157 virtual bool StartListening(MDnsSocketFactory* factory) = 0; |
148 | 158 |
149 // Do not call this inside callbacks from related MDnsListener and | 159 // Do not call this inside callbacks from related MDnsListener and |
150 // MDnsTransaction objects. | 160 // MDnsTransaction objects. |
151 virtual void StopListening() = 0; | 161 virtual void StopListening() = 0; |
152 virtual bool IsListening() const = 0; | 162 virtual bool IsListening() const = 0; |
153 | 163 |
154 // Create the default MDnsClient | 164 // Create the default MDnsClient |
155 static scoped_ptr<MDnsClient> CreateDefault(); | 165 static scoped_ptr<MDnsClient> CreateDefault(); |
156 }; | 166 }; |
157 | 167 |
158 IPEndPoint NET_EXPORT GetMDnsIPEndPoint(AddressFamily address_family); | 168 IPEndPoint NET_EXPORT GetMDnsIPEndPoint(AddressFamily address_family); |
159 | 169 |
160 } // namespace net | 170 } // namespace net |
161 #endif // NET_DNS_MDNS_CLIENT_H_ | 171 #endif // NET_DNS_MDNS_CLIENT_H_ |
OLD | NEW |