Android-cuttlefish cvd tool
adb_mdns.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <functional>
20#include <optional>
21#include <string>
22#include <string_view>
23
24// The rules for Service Names [RFC6335] state that they may be no more
25// than fifteen characters long (not counting the mandatory underscore),
26// consisting of only letters, digits, and hyphens, must begin and end
27// with a letter or digit, must not contain consecutive hyphens, and
28// must contain at least one letter.
29#define ADB_MDNS_SERVICE_TYPE "adb"
30#define ADB_MDNS_TLS_PAIRING_TYPE "adb-tls-pairing"
31#define ADB_MDNS_TLS_CONNECT_TYPE "adb-tls-connect"
32#define ADB_FULL_MDNS_SERVICE_TYPE(atype) ("_" atype "._tcp")
33
34#define ADB_SERVICE_TCP ADB_FULL_MDNS_SERVICE_TYPE(ADB_MDNS_SERVICE_TYPE)
35#define ADB_SERVICE_TLS ADB_FULL_MDNS_SERVICE_TYPE(ADB_MDNS_TLS_CONNECT_TYPE)
36#define ADB_SERVICE_PAIR ADB_FULL_MDNS_SERVICE_TYPE(ADB_MDNS_TLS_PAIRING_TYPE)
37
38// Client/service versions are initially defined to be matching,
39// but may go out of sync as different clients and services
40// try to talk to each other.
41#define ADB_SECURE_SERVICE_VERSION 1
42#define ADB_SECURE_CLIENT_VERSION ADB_SECURE_SERVICE_VERSION
43
47constexpr int kNumADBDNSServices = 3;
48
49extern const char* _Nonnull kADBDNSServices[kNumADBDNSServices];
50extern const char* _Nonnull kADBDNSServiceTxtRecords[kNumADBDNSServices];
51
52#if ADB_HOST
54// ADB Secure DNS service interface. Used to query what ADB Secure DNS services have been
55// resolved, and to run some kind of callback for each one.
56using adb_secure_foreach_service_callback = std::function<void(const mdns::ServiceInfo& si)>;
57
58// Tries to connect to a |service_name| if found. Returns true if found and
59// connected, false otherwise.
60bool adb_secure_connect_by_service_name(const std::string& instance_name);
61
62// Returns the index in kADBDNSServices array if |reg_type| matches a service name, otherwise
63// std::nullopt.
64std::optional<int> adb_DNSServiceIndexByName(std::string_view reg_type);
65// Returns true if auto-connect is allowed for |service_name| and |instance_name|.
66// See ADB_MDNS_AUTO_CONNECT environment variable for more info.
67bool adb_DNSServiceShouldAutoConnect(std::string_view service_name, std::string_view instance_name);
68
69std::string mdns_check();
71
72std::optional<mdns::ServiceInfo> mdns_get_connect_service_info(const std::string& name);
73std::optional<mdns::ServiceInfo> mdns_get_pairing_service_info(const std::string& name);
74
75// Return the location where adb host stores paired devices
76std::string get_user_known_hosts_path();
77#endif // ADB_HOST
const char *_Nonnull kADBDNSServices[kNumADBDNSServices]
Definition: adb_mdns.cpp:29
const char *_Nonnull kADBDNSServiceTxtRecords[kNumADBDNSServices]
constexpr int kNumADBDNSServices
Definition: adb_mdns.h:47
constexpr int kADBTransportServiceRefIndex
Definition: adb_mdns.h:44
constexpr int kADBSecurePairingServiceRefIndex
Definition: adb_mdns.h:45
constexpr int kADBSecureConnectServiceRefIndex
Definition: adb_mdns.h:46
std::string get_user_known_hosts_path()
Definition: adb_wifi.cpp:97
Definition: mdns_service_info.h:29
std::optional< ServiceInfo > mdns_get_pairing_service_info(const std::string &name)
Definition: transport_mdns.cpp:289
std::optional< ServiceInfo > mdns_get_connect_service_info(const std::string &name)
Definition: transport_mdns.cpp:275
bool adb_secure_connect_by_service_name(const std::string &instance_name)
Definition: transport_mdns.cpp:240
std::string mdns_check()
Definition: transport_mdns.cpp:253
std::string mdns_list_discovered_services()
Definition: transport_mdns.cpp:261