blob: 14ef9a202df1eb0f04798dd096e8f214ff78860c [file] [log] [blame]
Qingsi Wang09619332018-09-12 22:51:55 -07001/*
2 * Copyright 2018 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef RTC_BASE_MDNS_RESPONDER_INTERFACE_H_
12#define RTC_BASE_MDNS_RESPONDER_INTERFACE_H_
13
14#include <functional>
Qingsi Wang09619332018-09-12 22:51:55 -070015#include <string>
16
Ali Tofigh7fa90572022-03-17 15:47:49 +010017#include "absl/strings/string_view.h"
Steve Anton10542f22019-01-11 09:11:00 -080018#include "rtc_base/ip_address.h"
Qingsi Wang09619332018-09-12 22:51:55 -070019
20namespace webrtc {
21
22// Defines an mDNS responder that can be used in ICE candidate gathering, where
Qingsi Wang7852d292018-10-31 11:17:07 -070023// the local IP addresses of host candidates are replaced by mDNS hostnames.
24class MdnsResponderInterface {
Qingsi Wang09619332018-09-12 22:51:55 -070025 public:
26 using NameCreatedCallback =
Ali Tofigh7fa90572022-03-17 15:47:49 +010027 std::function<void(const rtc::IPAddress&, absl::string_view)>;
Qingsi Wang09619332018-09-12 22:51:55 -070028 using NameRemovedCallback = std::function<void(bool)>;
29
Qingsi Wang7852d292018-10-31 11:17:07 -070030 MdnsResponderInterface() = default;
31 virtual ~MdnsResponderInterface() = default;
Qingsi Wang09619332018-09-12 22:51:55 -070032
Artem Titov96e3b992021-07-26 16:03:14 +020033 // Asynchronously creates and returns a new name via `callback` for `addr` if
Qingsi Wang7852d292018-10-31 11:17:07 -070034 // there is no name mapped to it by this responder, and initializes the
35 // reference count of this name to one. Otherwise the existing name mapped to
Artem Titov96e3b992021-07-26 16:03:14 +020036 // `addr` is returned and its reference count is incremented by one.
Qingsi Wang09619332018-09-12 22:51:55 -070037 virtual void CreateNameForAddress(const rtc::IPAddress& addr,
38 NameCreatedCallback callback) = 0;
Artem Titov96e3b992021-07-26 16:03:14 +020039 // Decrements the reference count of the mapped name of `addr`, if
Qingsi Wang7852d292018-10-31 11:17:07 -070040 // there is a map created previously via CreateNameForAddress; asynchronously
Artem Titov96e3b992021-07-26 16:03:14 +020041 // removes the association between `addr` and its mapped name, and returns
42 // true via `callback` if the decremented reference count reaches zero.
43 // Otherwise no operation is done and false is returned via `callback`
Qingsi Wang7852d292018-10-31 11:17:07 -070044 // asynchronously.
Qingsi Wang09619332018-09-12 22:51:55 -070045 virtual void RemoveNameForAddress(const rtc::IPAddress& addr,
46 NameRemovedCallback callback) = 0;
47};
48
49} // namespace webrtc
50
51#endif // RTC_BASE_MDNS_RESPONDER_INTERFACE_H_