[Nearby Connection] Add webrtc_stub.*, BUILD.bazel and rename webrtc_socket_wrapper.* => webrtc_socket.* & webrtc_socket.* => webrtc_socket_impl.*.

PiperOrigin-RevId: 408278672
This commit is contained in:
suetfei
2021-11-08 01:43:53 -08:00
committed by Copybara-Service
parent 3ad0700559
commit 1b4ae4b28a
25 changed files with 593 additions and 27 deletions
+216
View File
@@ -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",
],
)
+4
View File
@@ -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"
+1 -1
View File
@@ -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 = [
+118
View File
@@ -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",
],
)
+4
View File
@@ -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 {
+1 -1
View File
@@ -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"
+2 -2
View File
@@ -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"
+3 -3
View File
@@ -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.
@@ -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"
@@ -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"
@@ -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"
@@ -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"
@@ -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"
@@ -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 <memory>
@@ -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_
@@ -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 <memory>
@@ -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 <memory>
#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_
@@ -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 <memory>
#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<ByteArray> 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_
+61
View File
@@ -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 <functional>
#include <memory>
#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
+82
View File
@@ -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 <cstddef>
#include <functional>
#include <memory>
#include <string>
#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<void(WebRtcSocketWrapper socket)> accepted_cb =
DefaultCallback<WebRtcSocketWrapper>();
};
// 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_
+1 -1
View File
@@ -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"
@@ -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"
@@ -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"
+1 -2
View File
@@ -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;
+5 -1
View File
@@ -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 {
+5 -1
View File
@@ -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 {