• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 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 DISCOVERY_MDNS_PUBLIC_MDNS_SERVICE_H_
6 #define DISCOVERY_MDNS_PUBLIC_MDNS_SERVICE_H_
7 
8 #include <functional>
9 #include <memory>
10 
11 #include "discovery/common/config.h"
12 #include "discovery/mdns/public/mdns_constants.h"
13 #include "platform/base/error.h"
14 #include "platform/base/interface_info.h"
15 #include "platform/base/ip_address.h"
16 
17 namespace openscreen {
18 
19 class TaskRunner;
20 
21 namespace discovery {
22 
23 class DomainName;
24 class MdnsDomainConfirmedProvider;
25 class MdnsRecord;
26 class MdnsRecordChangedCallback;
27 class ReportingClient;
28 
29 class MdnsService {
30  public:
31   MdnsService();
32   virtual ~MdnsService();
33 
34   // Creates a new MdnsService instance, to be owned by the caller. On failure,
35   // returns nullptr. |task_runner|, |reporting_client|, and |config| must exist
36   // for the duration of the resulting instance's life.
37   static std::unique_ptr<MdnsService> Create(TaskRunner* task_runner,
38                                              ReportingClient* reporting_client,
39                                              const Config& config,
40                                              const InterfaceInfo& network_info);
41 
42   // Starts an mDNS query with the given properties. Updated records are passed
43   // to |callback|.  The caller must ensure |callback| remains alive while it is
44   // registered with a query.
45   virtual void StartQuery(const DomainName& name,
46                           DnsType dns_type,
47                           DnsClass dns_class,
48                           MdnsRecordChangedCallback* callback) = 0;
49 
50   // Stops an mDNS query with the given properties. |callback| must be the same
51   // callback pointer that was previously passed to StartQuery.
52   virtual void StopQuery(const DomainName& name,
53                          DnsType dns_type,
54                          DnsClass dns_class,
55                          MdnsRecordChangedCallback* callback) = 0;
56 
57   // Re-initializes the process of service discovery for the provided domain
58   // name. All ongoing queries for this domain are restarted and any previously
59   // received query results are discarded.
60   virtual void ReinitializeQueries(const DomainName& name) = 0;
61 
62   // Starts probing for a valid domain name based on the given one. |callback|
63   // will be called once a valid domain is found, and the instance must persist
64   // until that call is received.
65   virtual Error StartProbe(MdnsDomainConfirmedProvider* callback,
66                            DomainName requested_name,
67                            IPAddress address) = 0;
68 
69   // Registers a new mDNS record for advertisement by this service. For A, AAAA,
70   // SRV, and TXT records, the domain name must have already been claimed by the
71   // ClaimExclusiveOwnership() method and for PTR records the name being pointed
72   // to must have been claimed in the same fashion, but the domain name in the
73   // top-level MdnsRecord entity does not.
74   virtual Error RegisterRecord(const MdnsRecord& record) = 0;
75 
76   // Updates the existing record with name matching the name of the new record.
77   // NOTE: This method is not valid for PTR records.
78   virtual Error UpdateRegisteredRecord(const MdnsRecord& old_record,
79                                        const MdnsRecord& new_record) = 0;
80 
81   // Stops advertising the provided record. If no more records with the provided
82   // name are bing advertised after this call's completion, then ownership of
83   // the name is released.
84   virtual Error UnregisterRecord(const MdnsRecord& record) = 0;
85 };
86 
87 }  // namespace discovery
88 }  // namespace openscreen
89 
90 #endif  // DISCOVERY_MDNS_PUBLIC_MDNS_SERVICE_H_
91