// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef SERVICES_NETWORK_MDNS_RESPONDER_H_ #define SERVICES_NETWORK_MDNS_RESPONDER_H_ #include <map> #include <memory> #include <optional> #include <set> #include <string> #include <vector> #include "base/containers/flat_set.h" #include "base/containers/unique_ptr_adapters.h" #include "base/functional/callback.h" #include "base/memory/raw_ptr.h" #include "base/memory/weak_ptr.h" #include "base/time/default_tick_clock.h" #include "base/time/time.h" #include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/receiver.h" #include "net/dns/dns_query.h" #include "net/dns/dns_response.h" #include "services/network/public/mojom/mdns_responder.mojom.h" namespace net { class IOBufferWithSize; class IPAddress; class MDnsSocketFactory; } // namespace net namespace network { class MdnsResponder; namespace mdns_helper { // Creates an mDNS response, of which the Answer section contains the address // records for |name_addr_map|, and the Additional section contains the // corresponding NSEC records that assert the existence of only address // records in the Answer section. COMPONENT_EXPORT(NETWORK_SERVICE) scoped_refptr<net::IOBufferWithSize> CreateResolutionResponse( const base::TimeDelta& ttl, const std::map<std::string, net::IPAddress>& name_addr_map); // Creates an mDNS response, of which the Answer section contains NSEC records // that assert the existence of only address records for |name_addr_map|, and // the Additional section contains the corresponding address records. COMPONENT_EXPORT(NETWORK_SERVICE) scoped_refptr<net::IOBufferWithSize> CreateNegativeResponse( const std::map<std::string, net::IPAddress>& name_addr_map); // Creates an mDNS response to an mDNS name generator service query. // // An mDNS name generator service query is a query for TXT records associated // with the name "Generated-Names._mdns_name_generator._udp.local". It is // similar to the service query defined in DNS-SD but is not an implementation // of the specification in RFC 6763. The Answer section of the response contains // a TXT record for the list of |mdns_names|. The cache-flush bit is set in the // TXT record if |cached_flush| is true. COMPONENT_EXPORT(NETWORK_SERVICE) scoped_refptr<net::IOBufferWithSize> CreateResponseToMdnsNameGeneratorServiceQuery( const base::TimeDelta& ttl, const std::set<std::string>& mdns_names); } // namespace mdns_helper // Options to configure the transmission of mDNS responses. struct COMPONENT_EXPORT(NETWORK_SERVICE) MdnsResponseSendOption : public base::RefCounted<MdnsResponseSendOption> { … }; // The responder manager creates and manages responder instances spawned for // each Mojo binding. It also manages the underlying network IO by delegating // the IO task to socket handlers of each interface. When there is a network // stack error or a Mojo binding error, the manager also offers the // corresponding error handling. class COMPONENT_EXPORT(NETWORK_SERVICE) MdnsResponderManager { … }; // Implementation of the mDNS service that can provide utilities of an mDNS // responder. class COMPONENT_EXPORT(NETWORK_SERVICE) MdnsResponder : public mojom::MdnsResponder { … }; } // namespace network #endif // SERVICES_NETWORK_MDNS_RESPONDER_H_