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 MDNS_SERVICE_PROTOCOL "_tcp"
33#define ADB_FULL_MDNS_SERVICE_TYPE(atype) ("_" atype "." MDNS_SERVICE_PROTOCOL)
34
35#define ADB_SERVICE_TCP ADB_FULL_MDNS_SERVICE_TYPE(ADB_MDNS_SERVICE_TYPE)
36#define ADB_SERVICE_TLS ADB_FULL_MDNS_SERVICE_TYPE(ADB_MDNS_TLS_CONNECT_TYPE)
37#define ADB_SERVICE_PAIR ADB_FULL_MDNS_SERVICE_TYPE(ADB_MDNS_TLS_PAIRING_TYPE)
38
39// Client/service versions are initially defined to be matching,
40// but may go out of sync as different clients and services
41// try to talk to each other.
42#define ADB_SECURE_SERVICE_VERSION 1
43#define ADB_SECURE_CLIENT_VERSION ADB_SECURE_SERVICE_VERSION
44
48constexpr int kNumADBDNSServices = 3;
49
50extern const char* _Nonnull kADBDNSServices[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 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 true if auto-connect is allowed for |service_name| and |instance_name|.
63// See ADB_MDNS_AUTO_CONNECT environment variable for more info.
64bool adb_DNSServiceShouldAutoConnect(std::string_view service_name, std::string_view instance_name);
65
66std::string mdns_check();
68
69// Return the location where adb host stores paired devices
70std::string get_user_known_hosts_path();
71#endif // ADB_HOST
72
73// Returns the index in kADBDNSServices array if |reg_type| matches a service name, otherwise
74// std::nullopt.
75std::optional<int> adb_DNSServiceIndexByName(std::string_view reg_type);
const char *_Nonnull kADBDNSServices[kNumADBDNSServices]
Definition: adb_mdns.cpp:29
constexpr int kNumADBDNSServices
Definition: adb_mdns.h:48
constexpr int kADBTransportServiceRefIndex
Definition: adb_mdns.h:45
constexpr int kADBSecurePairingServiceRefIndex
Definition: adb_mdns.h:46
std::optional< int > adb_DNSServiceIndexByName(std::string_view reg_type)
Definition: adb_mdns.cpp:117
constexpr int kADBSecureConnectServiceRefIndex
Definition: adb_mdns.h:47
Definition: discovered_services.h:78
bool adb_secure_connect_by_service_name(const std::string &instance_name)
Definition: transport_mdns.cpp:135
std::string mdns_check()
Definition: transport_mdns.cpp:143
std::string mdns_list_discovered_services()
Definition: transport_mdns.cpp:147