From 1b4ae4b28a2e2f76e73c96c348212a7230b752b9 Mon Sep 17 00:00:00 2001 From: suetfei Date: Mon, 8 Nov 2021 01:43:16 -0800 Subject: [PATCH] [Nearby Connection] Add webrtc_stub.*, BUILD.bazel and rename webrtc_socket_wrapper.* => webrtc_socket.* & webrtc_socket.* => webrtc_socket_impl.*. PiperOrigin-RevId: 408278672 --- cpp/core/internal/BUILD.bazel | 216 ++++++++++++++++++ cpp/core/internal/base_pcp_handler.h | 4 + cpp/core/internal/mediums/BUILD | 2 +- cpp/core/internal/mediums/BUILD.bazel | 118 ++++++++++ cpp/core/internal/mediums/mediums.h | 4 + cpp/core/internal/mediums/webrtc.cc | 2 +- cpp/core/internal/mediums/webrtc.h | 4 +- cpp/core/internal/mediums/webrtc/BUILD | 6 +- .../mediums/webrtc/connection_flow.cc | 4 +- .../internal/mediums/webrtc/connection_flow.h | 2 +- .../mediums/webrtc/connection_flow_test.cc | 2 +- .../mediums/webrtc/data_channel_listener.h | 2 +- ...webrtc_socket.cc => webrtc_socket_impl.cc} | 2 +- .../{webrtc_socket.h => webrtc_socket_impl.h} | 6 +- ...ket_test.cc => webrtc_socket_impl_test.cc} | 2 +- ...ebrtc_socket_wrapper.h => webrtc_socket.h} | 8 +- .../internal/mediums/webrtc_socket_stub.h | 69 ++++++ cpp/core/internal/mediums/webrtc_stub.cc | 61 +++++ cpp/core/internal/mediums/webrtc_stub.h | 82 +++++++ cpp/core/internal/mediums/webrtc_test.cc | 2 +- cpp/core/internal/p2p_cluster_pcp_handler.cc | 1 - cpp/core/internal/p2p_cluster_pcp_handler.h | 6 + cpp/core/internal/webrtc_bwu_handler.cc | 3 +- cpp/core/internal/webrtc_bwu_handler.h | 6 +- cpp/core/internal/webrtc_endpoint_channel.h | 6 +- 25 files changed, 593 insertions(+), 27 deletions(-) create mode 100644 cpp/core/internal/BUILD.bazel create mode 100644 cpp/core/internal/mediums/BUILD.bazel rename cpp/core/internal/mediums/webrtc/{webrtc_socket.cc => webrtc_socket_impl.cc} (99%) rename cpp/core/internal/mediums/webrtc/{webrtc_socket.h => webrtc_socket_impl.h} (95%) rename cpp/core/internal/mediums/webrtc/{webrtc_socket_test.cc => webrtc_socket_impl_test.cc} (99%) rename cpp/core/internal/mediums/{webrtc_socket_wrapper.h => webrtc_socket.h} (86%) create mode 100644 cpp/core/internal/mediums/webrtc_socket_stub.h create mode 100644 cpp/core/internal/mediums/webrtc_stub.cc create mode 100644 cpp/core/internal/mediums/webrtc_stub.h diff --git a/cpp/core/internal/BUILD.bazel b/cpp/core/internal/BUILD.bazel new file mode 100644 index 00000000..2e9b6119 --- /dev/null +++ b/cpp/core/internal/BUILD.bazel @@ -0,0 +1,216 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +licenses(["notice"]) + +cc_library( + name = "internal", + srcs = [ + "base_endpoint_channel.cc", + "base_pcp_handler.cc", + "ble_advertisement.cc", + "ble_endpoint_channel.cc", + "bluetooth_bwu_handler.cc", + "bluetooth_device_name.cc", + "bluetooth_endpoint_channel.cc", + "bwu_manager.cc", + "client_proxy.cc", + "encryption_runner.cc", + "endpoint_channel_manager.cc", + "endpoint_manager.cc", + "injected_bluetooth_device_store.cc", + "internal_payload.cc", + "internal_payload_factory.cc", + "offline_frames.cc", + "offline_frames_validator.cc", + "offline_service_controller.cc", + "p2p_cluster_pcp_handler.cc", + "p2p_point_to_point_pcp_handler.cc", + "p2p_star_pcp_handler.cc", + "payload_manager.cc", + "pcp_manager.cc", + "service_controller_router.cc", + "webrtc_bwu_handler.cc", + "webrtc_endpoint_channel.cc", + "wifi_lan_bwu_handler.cc", + "wifi_lan_endpoint_channel.cc", + "wifi_lan_service_info.cc", + ], + hdrs = [ + "base_bwu_handler.h", + "base_endpoint_channel.h", + "base_pcp_handler.h", + "ble_advertisement.h", + "ble_endpoint_channel.h", + "bluetooth_bwu_handler.h", + "bluetooth_device_name.h", + "bluetooth_endpoint_channel.h", + "bwu_handler.h", + "bwu_manager.h", + "client_proxy.h", + "encryption_runner.h", + "endpoint_channel.h", + "endpoint_channel_manager.h", + "endpoint_manager.h", + "injected_bluetooth_device_store.h", + "internal_payload.h", + "internal_payload_factory.h", + "offline_frames.h", + "offline_frames_validator.h", + "offline_service_controller.h", + "p2p_cluster_pcp_handler.h", + "p2p_point_to_point_pcp_handler.h", + "p2p_star_pcp_handler.h", + "payload_manager.h", + "pcp.h", + "pcp_handler.h", + "pcp_manager.h", + "service_controller.h", + "service_controller_router.h", + "webrtc_bwu_handler.h", + "webrtc_endpoint_channel.h", + "wifi_lan_bwu_handler.h", + "wifi_lan_endpoint_channel.h", + "wifi_lan_service_info.h", + ], + compatible_with = ["//buildenv/target:non_prod"], + copts = ["-DCORE_ADAPTER_DLL"], + defines = ["NO_WEBRTC"], + visibility = [ + "//third_party/nearby_connections/cpp/core:__pkg__", + "//third_party/nearby_connections/cpp/core/internal/fuzzers:__pkg__", + ], + deps = [ + ":message_lite", + "//third_party/absl/base:core_headers", + "//third_party/absl/container:btree", + "//third_party/absl/container:flat_hash_map", + "//third_party/absl/container:flat_hash_set", + "//third_party/absl/functional:bind_front", + "//third_party/absl/memory", + "//third_party/absl/strings", + "//third_party/absl/time", + "//third_party/absl/types:span", + "//third_party/nearby_connections/cpp/analytics", + "//third_party/nearby_connections/cpp/core:core_types", + "//third_party/nearby_connections/cpp/core/internal/mediums", + "//third_party/nearby_connections/cpp/core/internal/mediums:utils", + "//third_party/nearby_connections/cpp/platform/api:comm", + "//third_party/nearby_connections/cpp/platform/base", + "//third_party/nearby_connections/cpp/platform/base:cancellation_flag", + "//third_party/nearby_connections/cpp/platform/base:error_code_recorder", + "//third_party/nearby_connections/cpp/platform/base:util", + "//third_party/nearby_connections/cpp/platform/public:comm", + "//third_party/nearby_connections/cpp/platform/public:logging", + "//third_party/nearby_connections/cpp/platform/public:types", + "//third_party/nearby_connections/proto:connections_enums_portable_proto", + "//third_party/nearby_connections/proto/connections:offline_wire_formats_portable_proto", + "//third_party/ukey2", + ], +) + +cc_library( + name = "message_lite", + hdrs = [ + "message_lite.h", + ], + compatible_with = ["//buildenv/target:non_prod"], + visibility = [ + "//third_party/nearby_connections/cpp/core:__subpackages__", + ], + deps = [ + "//net/proto2/public:proto2_lite", + ], +) + +cc_library( + name = "internal_test", + testonly = True, + srcs = [ + "offline_simulation_user.cc", + "simulation_user.cc", + ], + hdrs = [ + "mock_service_controller.h", + "mock_service_controller_router.h", + "offline_simulation_user.h", + "simulation_user.h", + ], + defines = ["NO_WEBRTC"], + visibility = [ + "//third_party/nearby_connections/cpp/core:__subpackages__", + ], + deps = [ + ":internal", + "//testing/base/public:gunit_for_library_testonly", + "//third_party/absl/functional:bind_front", + "//third_party/absl/strings", + "//third_party/nearby_connections/cpp/core:core_types", + "//third_party/nearby_connections/cpp/platform/base", + "//third_party/nearby_connections/cpp/platform/base:test_util", + "//third_party/nearby_connections/cpp/platform/public:types", + ], +) + +cc_test( + name = "core_internal_test", + size = "small", + timeout = "moderate", + srcs = [ + "base_endpoint_channel_test.cc", + "base_pcp_handler_test.cc", + "ble_advertisement_test.cc", + "bluetooth_device_name_test.cc", + "bwu_manager_test.cc", + "client_proxy_test.cc", + "encryption_runner_test.cc", + "endpoint_channel_manager_test.cc", + "endpoint_manager_test.cc", + "injected_bluetooth_device_store_test.cc", + "internal_payload_factory_test.cc", + "offline_frames_test.cc", + "offline_frames_validator_test.cc", + "offline_service_controller_test.cc", + "p2p_cluster_pcp_handler_test.cc", + "payload_manager_test.cc", + "pcp_manager_test.cc", + "service_controller_router_test.cc", + "wifi_lan_service_info_test.cc", + ], + defines = ["NO_WEBRTC"], + shard_count = 16, + deps = [ + ":internal", + ":internal_test", + "//testing/base/public:gunit", + "//testing/base/public:gunit_main", + "//third_party/absl/container:flat_hash_set", + "//third_party/absl/strings", + "//third_party/absl/synchronization", + "//third_party/absl/time", + "//third_party/absl/types:span", + "//third_party/nearby_connections/cpp/analytics", + "//third_party/nearby_connections/cpp/core:core_types", + "//third_party/nearby_connections/cpp/core/internal/mediums", + "//third_party/nearby_connections/cpp/core/internal/mediums:utils", + "//third_party/nearby_connections/cpp/platform/base", + "//third_party/nearby_connections/cpp/platform/base:test_util", + "//third_party/nearby_connections/cpp/platform/impl/g3", # build_cleaner: keep + "//third_party/nearby_connections/cpp/platform/public:comm", + "//third_party/nearby_connections/cpp/platform/public:logging", + "//third_party/nearby_connections/cpp/platform/public:types", + "//third_party/nearby_connections/proto:connections_enums_portable_proto", + "//third_party/nearby_connections/proto/connections:offline_wire_formats_portable_proto", + "//third_party/ukey2", + ], +) diff --git a/cpp/core/internal/base_pcp_handler.h b/cpp/core/internal/base_pcp_handler.h index 896d03c4..59dee01d 100644 --- a/cpp/core/internal/base_pcp_handler.h +++ b/cpp/core/internal/base_pcp_handler.h @@ -31,7 +31,11 @@ #include "core/internal/endpoint_channel_manager.h" #include "core/internal/endpoint_manager.h" #include "core/internal/mediums/mediums.h" +#ifdef NO_WEBRTC +#include "core/internal/mediums/webrtc_stub.h" +#else #include "core/internal/mediums/webrtc.h" +#endif #include "core/internal/pcp.h" #include "core/internal/pcp_handler.h" #include "core/listeners.h" diff --git a/cpp/core/internal/mediums/BUILD b/cpp/core/internal/mediums/BUILD index 7f530723..685f1f2e 100644 --- a/cpp/core/internal/mediums/BUILD +++ b/cpp/core/internal/mediums/BUILD @@ -74,7 +74,7 @@ cc_library( hdrs = [ "utils.h", "webrtc_peer_id.h", - "webrtc_socket_wrapper.h", + "webrtc_socket.h", ], compatible_with = ["//buildenv/target:non_prod"], visibility = [ diff --git a/cpp/core/internal/mediums/BUILD.bazel b/cpp/core/internal/mediums/BUILD.bazel new file mode 100644 index 00000000..797b3889 --- /dev/null +++ b/cpp/core/internal/mediums/BUILD.bazel @@ -0,0 +1,118 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +licenses(["notice"]) + +cc_library( + name = "mediums", + srcs = [ + "ble.cc", + "bloom_filter.cc", + "bluetooth_classic.cc", + "bluetooth_radio.cc", + "mediums.cc", + "uuid.cc", + "webrtc_stub.cc", + "wifi_lan.cc", + ], + hdrs = [ + "ble.h", + "bloom_filter.h", + "bluetooth_classic.h", + "bluetooth_radio.h", + "lost_entity_tracker.h", + "mediums.h", + "uuid.h", + "webrtc_stub.h", + "wifi_lan.h", + ], + compatible_with = ["//buildenv/target:non_prod"], + defines = ["NO_WEBRTC"], + visibility = [ + "//third_party/nearby_connections/cpp/core/internal:__subpackages__", + ], + deps = [ + ":utils", + "//third_party/absl/container:flat_hash_map", + "//third_party/absl/container:flat_hash_set", + "//third_party/absl/functional:bind_front", + "//third_party/absl/numeric:int128", + "//third_party/absl/strings", + "//third_party/absl/strings:str_format", + "//third_party/absl/time", + "//third_party/nearby_connections/cpp/core:core_types", + "//third_party/nearby_connections/cpp/core/internal/mediums/ble_v2", + "//third_party/nearby_connections/cpp/platform/base", + "//third_party/nearby_connections/cpp/platform/base:cancellation_flag", + "//third_party/nearby_connections/cpp/platform/public:comm", + "//third_party/nearby_connections/cpp/platform/public:logging", + "//third_party/nearby_connections/cpp/platform/public:types", + "//third_party/nearby_connections/proto/connections:offline_wire_formats_portable_proto", + "//third_party/nearby_connections/proto/mediums:web_rtc_signaling_frames_cc_proto", + "//third_party/smhasher:libmurmur3", + ], +) + +cc_library( + name = "utils", + srcs = [ + "utils.cc", + "webrtc_peer_id.cc", + ], + hdrs = [ + "utils.h", + "webrtc_peer_id.h", + "webrtc_socket_stub.h", + ], + compatible_with = ["//buildenv/target:non_prod"], + defines = ["NO_WEBRTC"], + visibility = [ + "//third_party/nearby_connections/cpp/core/internal:__pkg__", + "//third_party/nearby_connections/cpp/core/internal/mediums:__pkg__", + ], + deps = [ + "//third_party/absl/strings", + "//third_party/nearby_connections/cpp/platform/base", + "//third_party/nearby_connections/cpp/platform/public:types", + "//third_party/nearby_connections/proto/connections:offline_wire_formats_portable_proto", + ], +) + +cc_test( + name = "core_internal_mediums_test", + size = "small", + srcs = [ + "ble_test.cc", + "bloom_filter_test.cc", + "bluetooth_classic_test.cc", + "bluetooth_radio_test.cc", + "lost_entity_tracker_test.cc", + "uuid_test.cc", + "webrtc_peer_id_test.cc", + "wifi_lan_test.cc", + ], + defines = ["NO_WEBRTC"], + shard_count = 16, + deps = [ + ":mediums", + ":utils", + "//testing/base/public:gunit_main", + "//third_party/absl/strings", + "//third_party/absl/time", + "//third_party/nearby_connections/cpp/platform/base", + "//third_party/nearby_connections/cpp/platform/base:test_util", + "//third_party/nearby_connections/cpp/platform/impl/g3", # build_cleaner: keep + "//third_party/nearby_connections/cpp/platform/public:comm", + "//third_party/nearby_connections/cpp/platform/public:types", + ], +) diff --git a/cpp/core/internal/mediums/mediums.h b/cpp/core/internal/mediums/mediums.h index 4c6127eb..7e39cd33 100644 --- a/cpp/core/internal/mediums/mediums.h +++ b/cpp/core/internal/mediums/mediums.h @@ -18,7 +18,11 @@ #include "core/internal/mediums/ble.h" #include "core/internal/mediums/bluetooth_classic.h" #include "core/internal/mediums/bluetooth_radio.h" +#ifdef NO_WEBRTC +#include "core/internal/mediums/webrtc_stub.h" +#else #include "core/internal/mediums/webrtc.h" +#endif #include "core/internal/mediums/wifi_lan.h" namespace location { diff --git a/cpp/core/internal/mediums/webrtc.cc b/cpp/core/internal/mediums/webrtc.cc index 1edcf639..25f18fd7 100644 --- a/cpp/core/internal/mediums/webrtc.cc +++ b/cpp/core/internal/mediums/webrtc.cc @@ -22,7 +22,7 @@ #include "absl/time/time.h" #include "core/internal/mediums/webrtc/session_description_wrapper.h" #include "core/internal/mediums/webrtc/signaling_frames.h" -#include "core/internal/mediums/webrtc_socket_wrapper.h" +#include "core/internal/mediums/webrtc_socket.h" #include "platform/base/byte_array.h" #include "platform/base/listeners.h" #include "platform/public/cancelable_alarm.h" diff --git a/cpp/core/internal/mediums/webrtc.h b/cpp/core/internal/mediums/webrtc.h index b5fb959a..ccc6b5d5 100644 --- a/cpp/core/internal/mediums/webrtc.h +++ b/cpp/core/internal/mediums/webrtc.h @@ -25,9 +25,9 @@ #include "core/internal/mediums/webrtc/connection_flow.h" #include "core/internal/mediums/webrtc/data_channel_listener.h" #include "core/internal/mediums/webrtc/local_ice_candidate_listener.h" -#include "core/internal/mediums/webrtc/webrtc_socket.h" +#include "core/internal/mediums/webrtc/webrtc_socket_impl.h" #include "core/internal/mediums/webrtc_peer_id.h" -#include "core/internal/mediums/webrtc_socket_wrapper.h" +#include "core/internal/mediums/webrtc_socket.h" #include "platform/base/byte_array.h" #include "platform/base/cancellation_flag.h" #include "platform/base/listeners.h" diff --git a/cpp/core/internal/mediums/webrtc/BUILD b/cpp/core/internal/mediums/webrtc/BUILD index 9e13e8b8..3a664425 100644 --- a/cpp/core/internal/mediums/webrtc/BUILD +++ b/cpp/core/internal/mediums/webrtc/BUILD @@ -50,10 +50,10 @@ cc_library( cc_library( name = "data_types", srcs = [ - "webrtc_socket.cc", + "webrtc_socket_impl.cc", ], hdrs = [ - "webrtc_socket.h", + "webrtc_socket_impl.h", ], compatible_with = ["//buildenv/target:non_prod"], copts = ["-DCORE_ADAPTER_DLL"], @@ -74,7 +74,7 @@ cc_test( srcs = [ "connection_flow_test.cc", "signaling_frames_test.cc", - "webrtc_socket_test.cc", + "webrtc_socket_impl_test.cc", ], tags = [ "notsan", # NOTE(b/139734036): known data race in usrsctplib. diff --git a/cpp/core/internal/mediums/webrtc/connection_flow.cc b/cpp/core/internal/mediums/webrtc/connection_flow.cc index 29066453..a048f854 100644 --- a/cpp/core/internal/mediums/webrtc/connection_flow.cc +++ b/cpp/core/internal/mediums/webrtc/connection_flow.cc @@ -20,8 +20,8 @@ #include "absl/memory/memory.h" #include "absl/time/time.h" #include "core/internal/mediums/webrtc/session_description_wrapper.h" -#include "core/internal/mediums/webrtc/webrtc_socket.h" -#include "core/internal/mediums/webrtc_socket_wrapper.h" +#include "core/internal/mediums/webrtc/webrtc_socket_impl.h" +#include "core/internal/mediums/webrtc_socket.h" #include "platform/public/logging.h" #include "platform/public/mutex_lock.h" #include "platform/public/webrtc.h" diff --git a/cpp/core/internal/mediums/webrtc/connection_flow.h b/cpp/core/internal/mediums/webrtc/connection_flow.h index 474a1829..cdfaa9b1 100644 --- a/cpp/core/internal/mediums/webrtc/connection_flow.h +++ b/cpp/core/internal/mediums/webrtc/connection_flow.h @@ -20,7 +20,7 @@ #include "core/internal/mediums/webrtc/data_channel_listener.h" #include "core/internal/mediums/webrtc/local_ice_candidate_listener.h" #include "core/internal/mediums/webrtc/session_description_wrapper.h" -#include "core/internal/mediums/webrtc_socket_wrapper.h" +#include "core/internal/mediums/webrtc_socket.h" #include "platform/base/runnable.h" #include "platform/public/count_down_latch.h" #include "platform/public/single_thread_executor.h" diff --git a/cpp/core/internal/mediums/webrtc/connection_flow_test.cc b/cpp/core/internal/mediums/webrtc/connection_flow_test.cc index dfc98d71..0412a118 100644 --- a/cpp/core/internal/mediums/webrtc/connection_flow_test.cc +++ b/cpp/core/internal/mediums/webrtc/connection_flow_test.cc @@ -21,7 +21,7 @@ #include "gtest/gtest.h" #include "absl/time/time.h" #include "core/internal/mediums/webrtc/session_description_wrapper.h" -#include "core/internal/mediums/webrtc_socket_wrapper.h" +#include "core/internal/mediums/webrtc_socket.h" #include "platform/base/byte_array.h" #include "platform/base/medium_environment.h" #include "platform/public/count_down_latch.h" diff --git a/cpp/core/internal/mediums/webrtc/data_channel_listener.h b/cpp/core/internal/mediums/webrtc/data_channel_listener.h index 13e6bb5a..32cde9dd 100644 --- a/cpp/core/internal/mediums/webrtc/data_channel_listener.h +++ b/cpp/core/internal/mediums/webrtc/data_channel_listener.h @@ -15,7 +15,7 @@ #ifndef CORE_INTERNAL_MEDIUMS_WEBRTC_DATA_CHANNEL_LISTENER_H_ #define CORE_INTERNAL_MEDIUMS_WEBRTC_DATA_CHANNEL_LISTENER_H_ -#include "core/internal/mediums/webrtc_socket_wrapper.h" +#include "core/internal/mediums/webrtc_socket.h" #include "core/listeners.h" #include "platform/base/byte_array.h" diff --git a/cpp/core/internal/mediums/webrtc/webrtc_socket.cc b/cpp/core/internal/mediums/webrtc/webrtc_socket_impl.cc similarity index 99% rename from cpp/core/internal/mediums/webrtc/webrtc_socket.cc rename to cpp/core/internal/mediums/webrtc/webrtc_socket_impl.cc index 0e4f34ba..b1af8dbc 100644 --- a/cpp/core/internal/mediums/webrtc/webrtc_socket.cc +++ b/cpp/core/internal/mediums/webrtc/webrtc_socket_impl.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "core/internal/mediums/webrtc/webrtc_socket.h" +#include "core/internal/mediums/webrtc/webrtc_socket_impl.h" #include "platform/public/logging.h" #include "platform/public/mutex_lock.h" diff --git a/cpp/core/internal/mediums/webrtc/webrtc_socket.h b/cpp/core/internal/mediums/webrtc/webrtc_socket_impl.h similarity index 95% rename from cpp/core/internal/mediums/webrtc/webrtc_socket.h rename to cpp/core/internal/mediums/webrtc/webrtc_socket_impl.h index a65f2d5d..c60990c7 100644 --- a/cpp/core/internal/mediums/webrtc/webrtc_socket.h +++ b/cpp/core/internal/mediums/webrtc/webrtc_socket_impl.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef CORE_INTERNAL_MEDIUMS_WEBRTC_WEBRTC_SOCKET_H_ -#define CORE_INTERNAL_MEDIUMS_WEBRTC_WEBRTC_SOCKET_H_ +#ifndef CORE_INTERNAL_MEDIUMS_WEBRTC_WEBRTC_SOCKET_IMPL_H_ +#define CORE_INTERNAL_MEDIUMS_WEBRTC_WEBRTC_SOCKET_IMPL_H_ #include @@ -120,4 +120,4 @@ class WebRtcSocket : public Socket, public webrtc::DataChannelObserver { } // namespace nearby } // namespace location -#endif // CORE_INTERNAL_MEDIUMS_WEBRTC_WEBRTC_SOCKET_H_ +#endif // CORE_INTERNAL_MEDIUMS_WEBRTC_WEBRTC_SOCKET_IMPL_H_ diff --git a/cpp/core/internal/mediums/webrtc/webrtc_socket_test.cc b/cpp/core/internal/mediums/webrtc/webrtc_socket_impl_test.cc similarity index 99% rename from cpp/core/internal/mediums/webrtc/webrtc_socket_test.cc rename to cpp/core/internal/mediums/webrtc/webrtc_socket_impl_test.cc index 135a6334..b88ce0bb 100644 --- a/cpp/core/internal/mediums/webrtc/webrtc_socket_test.cc +++ b/cpp/core/internal/mediums/webrtc/webrtc_socket_impl_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "core/internal/mediums/webrtc/webrtc_socket.h" +#include "core/internal/mediums/webrtc/webrtc_socket_impl.h" #include diff --git a/cpp/core/internal/mediums/webrtc_socket_wrapper.h b/cpp/core/internal/mediums/webrtc_socket.h similarity index 86% rename from cpp/core/internal/mediums/webrtc_socket_wrapper.h rename to cpp/core/internal/mediums/webrtc_socket.h index bc467113..b6293814 100644 --- a/cpp/core/internal/mediums/webrtc_socket_wrapper.h +++ b/cpp/core/internal/mediums/webrtc_socket.h @@ -12,12 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef CORE_INTERNAL_MEDIUMS_WEBRTC_SOCKET_WRAPPER_H_ -#define CORE_INTERNAL_MEDIUMS_WEBRTC_SOCKET_WRAPPER_H_ +#ifndef CORE_INTERNAL_MEDIUMS_WEBRTC_SOCKET_H_ +#define CORE_INTERNAL_MEDIUMS_WEBRTC_SOCKET_H_ #include -#include "core/internal/mediums/webrtc/webrtc_socket.h" +#include "core/internal/mediums/webrtc/webrtc_socket_impl.h" namespace location { namespace nearby { @@ -52,4 +52,4 @@ class WebRtcSocketWrapper final { } // namespace nearby } // namespace location -#endif // CORE_INTERNAL_MEDIUMS_WEBRTC_WEBRTC_SOCKET_WRAPPER_H_ +#endif // CORE_INTERNAL_MEDIUMS_WEBRTC_WEBRTC_SOCKET_H_ diff --git a/cpp/core/internal/mediums/webrtc_socket_stub.h b/cpp/core/internal/mediums/webrtc_socket_stub.h new file mode 100644 index 00000000..c806f82e --- /dev/null +++ b/cpp/core/internal/mediums/webrtc_socket_stub.h @@ -0,0 +1,69 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef CORE_INTERNAL_MEDIUMS_WEBRTC_SOCKET_STUB_H_ +#define CORE_INTERNAL_MEDIUMS_WEBRTC_SOCKET_STUB_H_ + +#include + +#include "platform/base/input_stream.h" +#include "platform/base/output_stream.h" + +namespace location { +namespace nearby { +namespace connections { +namespace mediums { +class FakeInputStream : public InputStream { + public: + ExceptionOr Read(std::int64_t size) { + return {Exception::kSuccess}; + } + Exception Close() { return {Exception::kSuccess}; } +}; + +class FakeOutputStream : public OutputStream { + public: + Exception Write(const ByteArray& data) override { + return {Exception::kSuccess}; + } + Exception Flush() override { return {Exception::kSuccess}; } + Exception Close() override { return {Exception::kSuccess}; } +}; + +class WebRtcSocketWrapper final { + public: + WebRtcSocketWrapper() = default; + WebRtcSocketWrapper(const WebRtcSocketWrapper&) = default; + WebRtcSocketWrapper& operator=(const WebRtcSocketWrapper&) = default; + ~WebRtcSocketWrapper() = default; + + InputStream& GetInputStream() { return fake_input_stream_; } + + OutputStream& GetOutputStream() { return fake_output_stream_; } + + void Close() {} + + bool IsValid() const { return false; } + + private: + FakeInputStream fake_input_stream_; + FakeOutputStream fake_output_stream_; +}; + +} // namespace mediums +} // namespace connections +} // namespace nearby +} // namespace location + +#endif // CORE_INTERNAL_MEDIUMS_WEBRTC_SOCKET_STUB_H_ diff --git a/cpp/core/internal/mediums/webrtc_stub.cc b/cpp/core/internal/mediums/webrtc_stub.cc new file mode 100644 index 00000000..23be9bc9 --- /dev/null +++ b/cpp/core/internal/mediums/webrtc_stub.cc @@ -0,0 +1,61 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "core/internal/mediums/webrtc_stub.h" + +#include +#include + +#include "core/internal/mediums/webrtc_socket_stub.h" +#include "platform/base/listeners.h" +#include "platform/public/cancelable_alarm.h" +#include "platform/public/future.h" + +namespace location { +namespace nearby { +namespace connections { +namespace mediums { + +WebRtc::WebRtc() = default; + +WebRtc::~WebRtc() {} + +const std::string WebRtc::GetDefaultCountryCode() { return "US"; } + +bool WebRtc::IsAvailable() { return false; } + +bool WebRtc::IsAcceptingConnections(const std::string& service_id) { + return false; +} + +bool WebRtc::StartAcceptingConnections(const std::string& service_id, + const WebrtcPeerId& self_peer_id, + const LocationHint& location_hint, + AcceptedConnectionCallback callback) { + return false; +} + +void WebRtc::StopAcceptingConnections(const std::string& service_id) {} + +WebRtcSocketWrapper WebRtc::Connect(const std::string& service_id, + const WebrtcPeerId& remote_peer_id, + const LocationHint& location_hint, + CancellationFlag* cancellation_flag) { + return WebRtcSocketWrapper(); +} + +} // namespace mediums +} // namespace connections +} // namespace nearby +} // namespace location diff --git a/cpp/core/internal/mediums/webrtc_stub.h b/cpp/core/internal/mediums/webrtc_stub.h new file mode 100644 index 00000000..2dc8a69e --- /dev/null +++ b/cpp/core/internal/mediums/webrtc_stub.h @@ -0,0 +1,82 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef CORE_INTERNAL_MEDIUMS_WEBRTC_STUB_H_ +#define CORE_INTERNAL_MEDIUMS_WEBRTC_STUB_H_ + +#include +#include +#include +#include + +#include "core/internal/mediums/webrtc_peer_id.h" +#include "core/internal/mediums/webrtc_socket_stub.h" +#include "platform/base/cancellation_flag.h" +#include "platform/base/listeners.h" +#include "proto/connections/offline_wire_formats.pb.h" + +namespace location { +namespace nearby { +namespace connections { +namespace mediums { +// Callback that is invoked when a new connection is accepted. +struct AcceptedConnectionCallback { + std::function accepted_cb = + DefaultCallback(); +}; +// Entry point for connecting a data channel between two devices via WebRtc. +class WebRtc { + public: + WebRtc(); + ~WebRtc(); + + // Gets the default two-letter country code associated with current locale. + // For example, en_US locale resolves to "US". + const std::string GetDefaultCountryCode(); + + // Returns if WebRtc is available as a medium for nearby to transport data. + // Runs on @MainThread. + bool IsAvailable(); + + // Returns if the device is accepting connection with specific service id. + // Runs on @MainThread. + bool IsAcceptingConnections(const std::string& service_id); + + // Prepares the device to accept incoming WebRtc connections. Returns a + // boolean value indicating if the device has started accepting connections. + // Runs on @MainThread. + bool StartAcceptingConnections(const std::string& service_id, + const WebrtcPeerId& self_peer_id, + const LocationHint& location_hint, + AcceptedConnectionCallback callback); + + // Try to stop (accepting) the specific connection with provided service id. + // Runs on @MainThread + void StopAcceptingConnections(const std::string& service_id); + + // Initiates a WebRtc connection with peer device identified by |peer_id| + // with internal retry for maximum attempts of kConnectAttemptsLimit. + // Runs on @MainThread. + WebRtcSocketWrapper Connect(const std::string& service_id, + const WebrtcPeerId& peer_id, + const LocationHint& location_hint, + CancellationFlag* cancellation_flag); +}; + +} // namespace mediums +} // namespace connections +} // namespace nearby +} // namespace location + +#endif // CORE_INTERNAL_MEDIUMS_WEBRTC_STUB_H_ diff --git a/cpp/core/internal/mediums/webrtc_test.cc b/cpp/core/internal/mediums/webrtc_test.cc index 863e6ef7..727c34e1 100644 --- a/cpp/core/internal/mediums/webrtc_test.cc +++ b/cpp/core/internal/mediums/webrtc_test.cc @@ -16,7 +16,7 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -#include "core/internal/mediums/webrtc_socket_wrapper.h" +#include "core/internal/mediums/webrtc_socket.h" #include "platform/base/listeners.h" #include "platform/base/medium_environment.h" #include "platform/public/mutex_lock.h" diff --git a/cpp/core/internal/p2p_cluster_pcp_handler.cc b/cpp/core/internal/p2p_cluster_pcp_handler.cc index 1bcc5999..3a6e3db7 100644 --- a/cpp/core/internal/p2p_cluster_pcp_handler.cc +++ b/cpp/core/internal/p2p_cluster_pcp_handler.cc @@ -22,7 +22,6 @@ #include "core/internal/bluetooth_endpoint_channel.h" #include "core/internal/bwu_manager.h" #include "core/internal/mediums/utils.h" -#include "core/internal/mediums/webrtc_socket_wrapper.h" #include "core/internal/webrtc_endpoint_channel.h" #include "core/internal/wifi_lan_endpoint_channel.h" #include "platform/base/nsd_service_info.h" diff --git a/cpp/core/internal/p2p_cluster_pcp_handler.h b/cpp/core/internal/p2p_cluster_pcp_handler.h index 6fe0178b..16af3a30 100644 --- a/cpp/core/internal/p2p_cluster_pcp_handler.h +++ b/cpp/core/internal/p2p_cluster_pcp_handler.h @@ -28,7 +28,13 @@ #include "core/internal/injected_bluetooth_device_store.h" #include "core/internal/mediums/bluetooth_classic.h" #include "core/internal/mediums/mediums.h" +#ifdef NO_WEBRTC +#include "core/internal/mediums/webrtc_stub.h" +#include "core/internal/mediums/webrtc_socket_stub.h" +#else #include "core/internal/mediums/webrtc.h" +#include "core/internal/mediums/webrtc_socket.h" +#endif #include "core/internal/pcp.h" #include "core/internal/wifi_lan_service_info.h" #include "core/options.h" diff --git a/cpp/core/internal/webrtc_bwu_handler.cc b/cpp/core/internal/webrtc_bwu_handler.cc index c3b536de..cd6d6a74 100644 --- a/cpp/core/internal/webrtc_bwu_handler.cc +++ b/cpp/core/internal/webrtc_bwu_handler.cc @@ -144,8 +144,7 @@ WebrtcBwuHandler::CreateUpgradedEndpointChannel( socket.Close(); NEARBY_LOG(ERROR, "WebRtcBwuHandler failed to create new EndpointChannel for " - "outgoing socket %p, aborting upgrade.", - &socket.GetImpl()); + "outgoing socket, aborting upgrade."); } return channel; diff --git a/cpp/core/internal/webrtc_bwu_handler.h b/cpp/core/internal/webrtc_bwu_handler.h index 6587b643..d68c4449 100644 --- a/cpp/core/internal/webrtc_bwu_handler.h +++ b/cpp/core/internal/webrtc_bwu_handler.h @@ -19,7 +19,11 @@ #include "core/internal/client_proxy.h" #include "core/internal/endpoint_channel_manager.h" #include "core/internal/mediums/mediums.h" -#include "core/internal/mediums/webrtc_socket_wrapper.h" +#ifdef NO_WEBRTC +#include "core/internal/mediums/webrtc_socket_stub.h" +#else +#include "core/internal/mediums/webrtc_socket.h" +#endif namespace location { namespace nearby { diff --git a/cpp/core/internal/webrtc_endpoint_channel.h b/cpp/core/internal/webrtc_endpoint_channel.h index 5515ab6e..db8db918 100644 --- a/cpp/core/internal/webrtc_endpoint_channel.h +++ b/cpp/core/internal/webrtc_endpoint_channel.h @@ -16,7 +16,11 @@ #define CORE_INTERNAL_WEBRTC_ENDPOINT_CHANNEL_H_ #include "core/internal/base_endpoint_channel.h" -#include "core/internal/mediums/webrtc_socket_wrapper.h" +#ifdef NO_WEBRTC +#include "core/internal/mediums/webrtc_socket_stub.h" +#else +#include "core/internal/mediums/webrtc_socket.h" +#endif namespace location { namespace nearby {