diff --git a/connections/implementation/BUILD b/connections/implementation/BUILD index 480f23d6..36ed7544 100644 --- a/connections/implementation/BUILD +++ b/connections/implementation/BUILD @@ -315,6 +315,7 @@ cc_test( "//connections/implementation/mediums:webrtc_utils", "//connections/implementation/proto:offline_wire_formats_cc_proto", "//connections/v3:v3_types", + "//internal/analytics:mock_event_logger", "//internal/flags:nearby_flags", "//internal/interop:authentication_status", "//internal/interop:authentication_transport_interface", @@ -324,8 +325,8 @@ cc_test( "//internal/platform:mac_address", "//internal/platform:test_util", "//internal/platform:types", - "//internal/platform/implementation:comm", "//internal/platform/implementation/g3", # build_cleaner: keep + "//internal/proto/analytics:connections_log_cc_proto", "//proto:connections_enums_cc_proto", "@com_github_protobuf_matchers//protobuf-matchers", "@com_google_absl//absl/base:core_headers", diff --git a/connections/implementation/base_endpoint_channel.cc b/connections/implementation/base_endpoint_channel.cc index b18db1d4..f4a5578c 100644 --- a/connections/implementation/base_endpoint_channel.cc +++ b/connections/implementation/base_endpoint_channel.cc @@ -30,6 +30,7 @@ #include "connections/implementation/flags/nearby_connections_feature_flags.h" #include "connections/implementation/offline_frames.h" #include "internal/flags/nearby_flags.h" +#include "internal/platform/base64_utils.h" #include "internal/platform/byte_array.h" #include "internal/platform/byte_utils.h" #include "internal/platform/exception.h" @@ -50,15 +51,6 @@ using ::location::nearby::proto::connections::Medium::BLE_L2CAP; using DisconnectionReason = ::location::nearby::proto::connections::DisconnectionReason; -ExceptionOr ReadInt(InputStream* reader) { - ExceptionOr read_bytes = reader->ReadExactly(sizeof(std::int32_t)); - if (!read_bytes.ok()) { - return ExceptionOr(read_bytes.exception()); - } - return ExceptionOr( - byte_utils::BytesToInt(std::move(read_bytes.result()))); -} - Exception WriteInt(OutputStream* writer, std::int32_t value) { return writer->Write(byte_utils::IntToBytes(value)); } @@ -123,10 +115,10 @@ ExceptionOr BaseEndpointChannel::Read( return ExceptionOr(read_control_block_bytes.exception()); } - read_int = - (GetMedium() == BLE_L2CAP) ? ReadPayloadLength() : ReadInt(reader_); + read_int = (GetMedium() == BLE_L2CAP) ? ReadPayloadLength() + : Base64Utils::ReadInt(reader_); } else { - read_int = ReadInt(reader_); + read_int = Base64Utils::ReadInt(reader_); } if (!read_int.ok()) { return ExceptionOr(read_int.exception()); diff --git a/connections/implementation/base_endpoint_channel_test.cc b/connections/implementation/base_endpoint_channel_test.cc index 4e8fa93e..984354ac 100644 --- a/connections/implementation/base_endpoint_channel_test.cc +++ b/connections/implementation/base_endpoint_channel_test.cc @@ -473,11 +473,11 @@ TEST_F(BaseEndpointChannelTest, ReadAfterInputStreamClosed) { // Close the output stream before trying to read from the input. output->Close(); - // Trying to read should fail gracefully with an IO error. + // Trying to read should fail gracefully with an kNoData error. ExceptionOr read_data = test_channel.Read(); ASSERT_FALSE(read_data.ok()); - ASSERT_TRUE(read_data.GetException().Raised(Exception::kIo)); + EXPECT_EQ(read_data.exception(), Exception::kNoData); } TEST_F(BaseEndpointChannelTest, ReadUnencryptedFrameOnEncryptedChannel) { diff --git a/connections/implementation/base_pcp_handler.cc b/connections/implementation/base_pcp_handler.cc index deb5a341..3fee41cd 100644 --- a/connections/implementation/base_pcp_handler.cc +++ b/connections/implementation/base_pcp_handler.cc @@ -701,8 +701,8 @@ void BasePcpHandler::OnEncryptionSuccessRunnableV3( ProcessPreConnectionInitiationFailure( pending_connection_info.client, pending_connection_info.medium, remote_device.GetEndpointId(), pending_connection_info.channel.get(), - pending_connection_info.is_incoming, pending_connection_info.start_time, - {Status::kEndpointIoError}, + pending_connection_info.is_incoming, /*log_failure=*/true, + pending_connection_info.start_time, {Status::kEndpointIoError}, OperationResultCode::NEARBY_AUTHENTICATION_FAILURE, pending_connection_info.result.lock().get()); return; @@ -763,8 +763,8 @@ void BasePcpHandler::OnEncryptionSuccessRunnable( ProcessPreConnectionInitiationFailure( pending_connection_info.client, pending_connection_info.medium, endpoint_id, pending_connection_info.channel.get(), - pending_connection_info.is_incoming, pending_connection_info.start_time, - {Status::kEndpointIoError}, + pending_connection_info.is_incoming, /*log_failure=*/true, + pending_connection_info.start_time, {Status::kEndpointIoError}, OperationResultCode::NEARBY_AUTHENTICATION_FAILURE, pending_connection_info.result.lock().get()); return; @@ -848,8 +848,8 @@ void BasePcpHandler::OnEncryptionFailureRunnable( ProcessPreConnectionInitiationFailure( pending_connection_info.client, pending_connection_info.medium, endpoint_id, pending_connection_info.channel.get(), - pending_connection_info.is_incoming, pending_connection_info.start_time, - {Status::kEndpointIoError}, + pending_connection_info.is_incoming, /*log_failure=*/true, + pending_connection_info.start_time, {Status::kEndpointIoError}, OperationResultCode::NEARBY_ENCRYPTION_FAILURE, pending_connection_info.result.lock().get()); } @@ -971,7 +971,8 @@ Status BasePcpHandler::RequestConnection( << endpoint_id; ProcessPreConnectionInitiationFailure( client, channel_medium, endpoint_id, channel.get(), - /* is_incoming = */ false, start_time, connect_impl_result.status, + /*is_incoming=*/false, /*log_failure=*/true, start_time, + connect_impl_result.status, connect_impl_result.operation_result_code, result.get()); return; } @@ -995,7 +996,8 @@ Status BasePcpHandler::RequestConnection( << endpoint_id; ProcessPreConnectionInitiationFailure( client, channel_medium, endpoint_id, channel.get(), - /* is_incoming = */ false, start_time, {Status::kEndpointIoError}, + /*is_incoming=*/false, /*log_failure=*/true, start_time, + {Status::kEndpointIoError}, client->GetAnalyticsRecorder() .GetChannelIoErrorResultCodeFromMedium(channel_medium), result.get()); @@ -1115,7 +1117,8 @@ Status BasePcpHandler::RequestConnectionV3( << endpoint_id; ProcessPreConnectionInitiationFailure( client, channel_medium, endpoint_id, channel.get(), - /* is_incoming = */ false, start_time, connect_impl_result.status, + /*is_incoming=*/false, /*log_failure=*/true, start_time, + connect_impl_result.status, connect_impl_result.operation_result_code, result.get()); return; } @@ -1140,7 +1143,8 @@ Status BasePcpHandler::RequestConnectionV3( << endpoint_id; ProcessPreConnectionInitiationFailure( client, channel_medium, endpoint_id, channel.get(), - /* is_incoming = */ false, start_time, {Status::kEndpointIoError}, + /*is_incoming=*/false, /*log_failure=*/true, start_time, + {Status::kEndpointIoError}, client->GetAnalyticsRecorder() .GetChannelIoErrorResultCodeFromMedium(channel_medium), result.get()); @@ -1462,9 +1466,9 @@ Exception BasePcpHandler::WriteConnectionRequestFrame( void BasePcpHandler::ProcessPreConnectionInitiationFailure( ClientProxy* client, Medium medium, const std::string& endpoint_id, - EndpointChannel* channel, bool is_incoming, absl::Time start_time, - Status status, OperationResultCode operation_result_code, - Future* result) { + EndpointChannel* channel, bool is_incoming, bool log_failure, + absl::Time start_time, Status status, + OperationResultCode operation_result_code, Future* result) { if (channel != nullptr) { channel->Close(); } @@ -1474,8 +1478,10 @@ void BasePcpHandler::ProcessPreConnectionInitiationFailure( result->Set(status); } - LogConnectionAttemptFailure(client, medium, endpoint_id, is_incoming, - start_time, channel, operation_result_code); + if (log_failure) { + LogConnectionAttemptFailure(client, medium, endpoint_id, is_incoming, + start_time, channel, operation_result_code); + } // result is hold inside a swapper, and saved in PendingConnectionInfo. // PendingConnectionInfo destructor will clear the memory of SettableFuture // shared_ptr for result. @@ -1978,9 +1984,14 @@ Exception BasePcpHandler::OnIncomingConnection( << client->GetClientId() << "; device=" << absl::BytesToHexString(remote_endpoint_info.data()) << "with error: " << wrapped_frame.exception(); + // Do not log connection failure if no data is received from the channel. + // This prevents logging Wifi connection failure when mDNS client connects + // to test the connection. ProcessPreConnectionInitiationFailure( client, medium, /*endpoint_id=*/"", channel.get(), - /*is_incoming=*/true, start_time, {Status::kError}, + /*is_incoming=*/true, + /*log_failure=*/wrapped_frame.exception() != Exception::kNoData, + start_time, {Status::kError}, client->GetAnalyticsRecorder().GetChannelIoErrorResultCodeFromMedium( medium), nullptr); @@ -2254,8 +2265,8 @@ void BasePcpHandler::ProcessTieBreakLoss( ProcessPreConnectionInitiationFailure( client, pending_connection_info->medium, endpoint_id, pending_connection_info->channel.get(), - pending_connection_info->is_incoming, pending_connection_info->start_time, - {Status::kEndpointIoError}, + pending_connection_info->is_incoming, /*log_failure=*/true, + pending_connection_info->start_time, {Status::kEndpointIoError}, OperationResultCode::CLIENT_PROCESS_TIE_BREAK_LOSS, pending_connection_info->result.lock().get()); ProcessPreConnectionResultFailure(client, endpoint_id, diff --git a/connections/implementation/base_pcp_handler.h b/connections/implementation/base_pcp_handler.h index 7a83de3d..a1c3db7c 100644 --- a/connections/implementation/base_pcp_handler.h +++ b/connections/implementation/base_pcp_handler.h @@ -576,8 +576,8 @@ class BasePcpHandler : public PcpHandler, void ProcessPreConnectionInitiationFailure( ClientProxy* client, Medium medium, const std::string& endpoint_id, - EndpointChannel* channel, bool is_incoming, absl::Time start_time, - Status status, + EndpointChannel* channel, bool is_incoming, bool log_failure, + absl::Time start_time, Status status, location::nearby::proto::connections::OperationResultCode operation_result_code, Future* result); diff --git a/connections/implementation/base_pcp_handler_test.cc b/connections/implementation/base_pcp_handler_test.cc index bc9385e5..901f794e 100644 --- a/connections/implementation/base_pcp_handler_test.cc +++ b/connections/implementation/base_pcp_handler_test.cc @@ -55,6 +55,8 @@ #include "connections/status.h" #include "connections/strategy.h" #include "connections/v3/connection_listening_options.h" +#include "internal/analytics/mock_event_logger.h" +#include "internal/analytics/sharing_log_matchers.h" #include "internal/flags/nearby_flags.h" #include "internal/interop/authentication_status.h" #include "internal/interop/authentication_transport.h" @@ -70,6 +72,7 @@ #include "internal/platform/medium_environment.h" #include "internal/platform/output_stream.h" #include "internal/platform/pipe.h" +#include "internal/proto/analytics/connections_log.pb.h" #include "proto/connections_enums.pb.h" #include "proto/connections_enums.proto.h" @@ -77,15 +80,21 @@ namespace nearby { namespace connections { namespace { +using ::location::nearby::analytics::proto::ConnectionsLog; using ::location::nearby::connections::OsInfo; +using ::location::nearby::proto::connections::EventType; using ::location::nearby::proto::connections::Medium; +using ::nearby::analytics::HasEventType; using ::testing::_; using ::testing::AtLeast; +using ::protobuf_matchers::EqualsProto; using ::testing::Invoke; +using ::testing::Matcher; using ::testing::MockFunction; using ::testing::NiceMock; using ::testing::Return; using ::testing::StrictMock; +using ::testing::proto::Partially; constexpr absl::string_view kTestEndpointId = "REMOTETEST"; @@ -444,6 +453,10 @@ class BasePcpHandlerTest endpoint_distance_changed_cb; }; + BasePcpHandlerTest() { + client_ = std::make_unique(&mock_event_logger_); + } + void SetUp() override { // Disable instant on lost for all tests by default. NearbyFlags::GetInstance().OverrideBoolFlagValue( @@ -452,6 +465,10 @@ class BasePcpHandlerTest MacAddress::FromString("12:34:56:78:9a:bc", remote_mac_address_); } + void TearDown() override { + env_.Stop(); + } + void StartAdvertising(ClientProxy* client, MockPcpHandler* pcp_handler, BooleanMediumSelector allowed = GetParam()) { AdvertisingOptions advertising_options{ @@ -894,6 +911,8 @@ class BasePcpHandlerTest MediumEnvironment& env_ = MediumEnvironment::Instance(); NiceMock mock_device_; MacAddress remote_mac_address_; + nearby::analytics::MockEventLogger mock_event_logger_; + std::unique_ptr client_; }; TEST_P(BasePcpHandlerTest, ConstructorDestructorWorks) { @@ -912,50 +931,46 @@ TEST_P(BasePcpHandlerTest, StartAdvertisingChangesState) { NearbyFlags::GetInstance().OverrideBoolFlagValue( config_package_nearby::nearby_connections_feature::kEnableDct, true); env_.Start(); - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); BwuManager bwu(m, em, ecm, {}, {}); MockPcpHandler pcp_handler(&m, &em, &ecm, &bwu); - StartAdvertising(&client, &pcp_handler); + StartAdvertising(client_.get(), &pcp_handler); bwu.Shutdown(); env_.Stop(); } TEST_P(BasePcpHandlerTest, StopAdvertisingChangesState) { env_.Start(); - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); BwuManager bwu(m, em, ecm, {}, {}); MockPcpHandler pcp_handler(&m, &em, &ecm, &bwu); - StartAdvertising(&client, &pcp_handler); - EXPECT_CALL(pcp_handler, StopAdvertisingImpl(&client)).Times(1); - EXPECT_TRUE(client.IsAdvertising()); - pcp_handler.StopAdvertising(&client); - EXPECT_FALSE(client.IsAdvertising()); + StartAdvertising(client_.get(), &pcp_handler); + EXPECT_CALL(pcp_handler, StopAdvertisingImpl(client_.get())).Times(1); + EXPECT_TRUE(client_->IsAdvertising()); + pcp_handler.StopAdvertising(client_.get()); + EXPECT_FALSE(client_->IsAdvertising()); bwu.Shutdown(); env_.Stop(); } TEST_P(BasePcpHandlerTest, StartDiscoveryChangesState) { env_.Start(); - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); BwuManager bwu(m, em, ecm, {}, {}); MockPcpHandler pcp_handler(&m, &em, &ecm, &bwu); - StartDiscovery(&client, &pcp_handler); + StartDiscovery(client_.get(), &pcp_handler); bwu.Shutdown(); env_.Stop(); } TEST_P(BasePcpHandlerTest, StartDiscoveryFails) { env_.Start(); - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); @@ -974,57 +989,57 @@ TEST_P(BasePcpHandlerTest, StartDiscoveryFails) { .status = {Status::kError}, .mediums = {}, })); - EXPECT_EQ(pcp_handler.StartDiscovery(&client, "service", discovery_options, - GetDiscoveryListener()), - Status{Status::kError}); + EXPECT_EQ( + pcp_handler.StartDiscovery(client_.get(), "service", discovery_options, + GetDiscoveryListener()), + Status{Status::kError}); bwu.Shutdown(); env_.Stop(); } TEST_P(BasePcpHandlerTest, StopDiscoveryChangesState) { env_.Start(); - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); BwuManager bwu(m, em, ecm, {}, {}); MockPcpHandler pcp_handler(&m, &em, &ecm, &bwu); - StartDiscovery(&client, &pcp_handler); - EXPECT_CALL(pcp_handler, StopDiscoveryImpl(&client)).Times(1); - EXPECT_TRUE(client.IsDiscovering()); - pcp_handler.StopDiscovery(&client); - EXPECT_FALSE(client.IsDiscovering()); + StartDiscovery(client_.get(), &pcp_handler); + EXPECT_CALL(pcp_handler, StopDiscoveryImpl(client_.get())).Times(1); + EXPECT_TRUE(client_->IsDiscovering()); + pcp_handler.StopDiscovery(client_.get()); + EXPECT_FALSE(client_->IsDiscovering()); bwu.Shutdown(); env_.Stop(); } TEST_P(BasePcpHandlerTest, StartStopStartDiscoveryClearsEndpoints) { env_.Start(); - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); BwuManager bwu(m, em, ecm, {}, {}); MockPcpHandler pcp_handler(&m, &em, &ecm, &bwu); - StartDiscovery(&client, &pcp_handler); - auto mediums = pcp_handler.GetDiscoveryMediums(&client); + StartDiscovery(client_.get(), &pcp_handler); + auto mediums = pcp_handler.GetDiscoveryMediums(client_.get()); auto connect_medium = mediums[mediums.size() - 1]; EXPECT_CALL(mock_discovery_listener_.endpoint_found_cb, Call); pcp_handler.OnEndpointFound( - &client, std::make_shared(MockDiscoveredEndpoint{ - { - "DEFG", - ByteArray("1"), - "service", - connect_medium, - WebRtcState::kUndefined, - }, - MockContext{nullptr}, - })); - EXPECT_CALL(pcp_handler, StopDiscoveryImpl(&client)).Times(1); - pcp_handler.StopDiscovery(&client); - EXPECT_FALSE(client.IsDiscovering()); - StartDiscovery(&client, &pcp_handler); + client_.get(), + std::make_shared(MockDiscoveredEndpoint{ + { + "DEFG", + ByteArray("1"), + "service", + connect_medium, + WebRtcState::kUndefined, + }, + MockContext{nullptr}, + })); + EXPECT_CALL(pcp_handler, StopDiscoveryImpl(client_.get())).Times(1); + pcp_handler.StopDiscovery(client_.get()); + EXPECT_FALSE(client_->IsDiscovering()); + StartDiscovery(client_.get(), &pcp_handler); bwu.Shutdown(); env_.Stop(); } @@ -1043,21 +1058,20 @@ TEST_F(BasePcpHandlerTest, ShouldLostEndpointWhenReportInstantLost) { WebRtcState::kUndefined}, MockContext{nullptr}}); - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); BwuManager bwu(m, em, ecm, {}, {}); MockPcpHandler pcp_handler(&m, &em, &ecm, &bwu); - StartDiscovery(&client, &pcp_handler, allowed); + StartDiscovery(client_.get(), &pcp_handler, allowed); EXPECT_CALL(mock_discovery_listener_.endpoint_found_cb, Call); - pcp_handler.OnEndpointFound(&client, endpoint); + pcp_handler.OnEndpointFound(client_.get(), endpoint); EXPECT_EQ(pcp_handler.GetDiscoveredEndpoints("ABCD").size(), 1); EXPECT_CALL(mock_discovery_listener_.endpoint_lost_cb, Call); - pcp_handler.OnInstantLost(&client, endpoint); + pcp_handler.OnInstantLost(client_.get(), endpoint); EXPECT_EQ(pcp_handler.GetDiscoveredEndpoints("ABCD").size(), 0); - EXPECT_CALL(pcp_handler, StopDiscoveryImpl(&client)).Times(1); - pcp_handler.StopDiscovery(&client); + EXPECT_CALL(pcp_handler, StopDiscoveryImpl(client_.get())).Times(1); + pcp_handler.StopDiscovery(client_.get()); bwu.Shutdown(); env_.Stop(); } @@ -1080,22 +1094,21 @@ TEST_F(BasePcpHandlerTest, ShouldLostAllEndpointsWhenReportInstantLost) { Medium::BLUETOOTH, WebRtcState::kUndefined}, MockContext{nullptr}}); - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); BwuManager bwu(m, em, ecm, {}, {}); MockPcpHandler pcp_handler(&m, &em, &ecm, &bwu); - StartDiscovery(&client, &pcp_handler, allowed); + StartDiscovery(client_.get(), &pcp_handler, allowed); EXPECT_CALL(mock_discovery_listener_.endpoint_found_cb, Call); - pcp_handler.OnEndpointFound(&client, endpoint); - pcp_handler.OnEndpointFound(&client, endpoint_bluetooth); + pcp_handler.OnEndpointFound(client_.get(), endpoint); + pcp_handler.OnEndpointFound(client_.get(), endpoint_bluetooth); EXPECT_EQ(pcp_handler.GetDiscoveredEndpoints("ABCD").size(), 2); EXPECT_CALL(mock_discovery_listener_.endpoint_lost_cb, Call); - pcp_handler.OnInstantLost(&client, endpoint); + pcp_handler.OnInstantLost(client_.get(), endpoint); EXPECT_EQ(pcp_handler.GetDiscoveredEndpoints("ABCD").size(), 0); - EXPECT_CALL(pcp_handler, StopDiscoveryImpl(&client)).Times(1); - pcp_handler.StopDiscovery(&client); + EXPECT_CALL(pcp_handler, StopDiscoveryImpl(client_.get())).Times(1); + pcp_handler.StopDiscovery(client_.get()); bwu.Shutdown(); env_.Stop(); } @@ -1104,7 +1117,6 @@ TEST_F(BasePcpHandlerTest, WifiMediumFailFallBackToBT) { env_.Start(); std::string service_id{"service"}; std::string endpoint_id{"ABCD"}; - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); @@ -1122,18 +1134,19 @@ TEST_F(BasePcpHandlerTest, WifiMediumFailFallBackToBT) { false, // auto_upgrade_bandwidth; false, // enforce_topology_constraints; }; - EXPECT_CALL(pcp_handler, StartDiscoveryImpl(&client, service_id, _)) + EXPECT_CALL(pcp_handler, StartDiscoveryImpl(client_.get(), service_id, _)) .WillOnce(Return(MockPcpHandler::StartOperationResult{ .status = {Status::kSuccess}, .mediums = allowed.GetMediums(true), })); - EXPECT_EQ(pcp_handler.StartDiscovery(&client, service_id, discovery_options, - GetDiscoveryListener()), - Status{Status::kSuccess}); - EXPECT_TRUE(client.IsDiscovering()); + EXPECT_EQ( + pcp_handler.StartDiscovery(client_.get(), service_id, discovery_options, + GetDiscoveryListener()), + Status{Status::kSuccess}); + EXPECT_TRUE(client_->IsDiscovering()); - auto mediums = pcp_handler.GetDiscoveryMediums(&client); + auto mediums = pcp_handler.GetDiscoveryMediums(client_.get()); auto connect_medium = mediums[mediums.size() - 1]; auto channel_pair = SetupConnection(connect_medium); auto& channel_a = channel_pair.first; @@ -1142,7 +1155,7 @@ TEST_F(BasePcpHandlerTest, WifiMediumFailFallBackToBT) { EXPECT_CALL(*channel_b, CloseImpl).Times(1); EXPECT_CALL(mock_connection_listener_.rejected_cb, Call).Times(AtLeast(0)); RequestConnectionWifiLanFail(endpoint_id, std::move(channel_a), - channel_b.get(), &client, &pcp_handler); + channel_b.get(), client_.get(), &pcp_handler); LOG(INFO) << "RequestConnection complete"; channel_b->Close(); bwu.Shutdown(); @@ -1152,14 +1165,13 @@ TEST_F(BasePcpHandlerTest, WifiMediumFailFallBackToBT) { TEST_P(BasePcpHandlerTest, RequestConnectionChangesState) { env_.Start(); - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); BwuManager bwu(m, em, ecm, {}, {}); MockPcpHandler pcp_handler(&m, &em, &ecm, &bwu); - StartDiscovery(&client, &pcp_handler); - auto mediums = pcp_handler.GetDiscoveryMediums(&client); + StartDiscovery(client_.get(), &pcp_handler); + auto mediums = pcp_handler.GetDiscoveryMediums(client_.get()); auto connect_medium = mediums[mediums.size() - 1]; auto channel_pair = SetupConnection(connect_medium); auto& channel_a = channel_pair.first; @@ -1167,11 +1179,11 @@ TEST_P(BasePcpHandlerTest, RequestConnectionChangesState) { EXPECT_CALL(*channel_a, CloseImpl).Times(1); EXPECT_CALL(*channel_b, CloseImpl).Times(1); EXPECT_CALL(mock_connection_listener_.rejected_cb, Call).Times(AtLeast(0)); - RequestConnection("1234", std::move(channel_a), channel_b.get(), &client, - &pcp_handler, connect_medium); + RequestConnection("1234", std::move(channel_a), channel_b.get(), + client_.get(), &pcp_handler, connect_medium); LOG(INFO) << "RequestConnection complete"; - EXPECT_TRUE(pcp_handler.HasOutgoingConnections(&client)); - EXPECT_FALSE(pcp_handler.HasIncomingConnections(&client)); + EXPECT_TRUE(pcp_handler.HasOutgoingConnections(client_.get())); + EXPECT_FALSE(pcp_handler.HasIncomingConnections(client_.get())); channel_b->Close(); bwu.Shutdown(); pcp_handler.DisconnectFromEndpointManager(); @@ -1180,7 +1192,6 @@ TEST_P(BasePcpHandlerTest, RequestConnectionChangesState) { TEST_P(BasePcpHandlerTest, CanRequestConnectionPresence) { env_.Start(); - ClientProxy client; FakePresenceDeviceProvider provider; EXPECT_CALL(provider.local_device_, GetType) .WillRepeatedly(Return(NearbyDevice::Type::kPresenceDevice)); @@ -1199,14 +1210,14 @@ TEST_P(BasePcpHandlerTest, CanRequestConnectionPresence) { EXPECT_FALSE(serialized.empty()); return serialized; }); - client.RegisterDeviceProvider(&provider); + client_->RegisterDeviceProvider(&provider); Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); BwuManager bwu(m, em, ecm, {}, {}); MockPcpHandler pcp_handler(&m, &em, &ecm, &bwu); - StartDiscovery(&client, &pcp_handler); - auto mediums = pcp_handler.GetDiscoveryMediums(&client); + StartDiscovery(client_.get(), &pcp_handler); + auto mediums = pcp_handler.GetDiscoveryMediums(client_.get()); auto connect_medium = mediums[mediums.size() - 1]; auto channel_pair = SetupConnection(connect_medium); auto& channel_a = channel_pair.first; @@ -1214,8 +1225,8 @@ TEST_P(BasePcpHandlerTest, CanRequestConnectionPresence) { EXPECT_CALL(*channel_a, CloseImpl).Times(1); EXPECT_CALL(*channel_b, CloseImpl).Times(1); EXPECT_CALL(mock_connection_listener_.rejected_cb, Call).Times(AtLeast(0)); - RequestConnection("1234", std::move(channel_a), channel_b.get(), &client, - &pcp_handler, connect_medium); + RequestConnection("1234", std::move(channel_a), channel_b.get(), + client_.get(), &pcp_handler, connect_medium); LOG(INFO) << "RequestConnection complete"; channel_b->Close(); bwu.Shutdown(); @@ -1224,19 +1235,18 @@ TEST_P(BasePcpHandlerTest, CanRequestConnectionPresence) { TEST_P(BasePcpHandlerTest, CanRequestConnectionLegacy) { env_.Start(); - ClientProxy client; FakePresenceDeviceProvider provider; EXPECT_CALL(provider.local_device_, GetType) .WillRepeatedly(Return(NearbyDevice::Type::kUnknownDevice)); EXPECT_CALL(provider.local_device_, ToProtoBytes); - client.RegisterDeviceProvider(&provider); + client_->RegisterDeviceProvider(&provider); Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); BwuManager bwu(m, em, ecm, {}, {}); MockPcpHandler pcp_handler(&m, &em, &ecm, &bwu); - StartDiscovery(&client, &pcp_handler); - auto mediums = pcp_handler.GetDiscoveryMediums(&client); + StartDiscovery(client_.get(), &pcp_handler); + auto mediums = pcp_handler.GetDiscoveryMediums(client_.get()); auto connect_medium = mediums[mediums.size() - 1]; auto channel_pair = SetupConnection(connect_medium); auto& channel_a = channel_pair.first; @@ -1244,8 +1254,8 @@ TEST_P(BasePcpHandlerTest, CanRequestConnectionLegacy) { EXPECT_CALL(*channel_a, CloseImpl).Times(1); EXPECT_CALL(*channel_b, CloseImpl).Times(1); EXPECT_CALL(mock_connection_listener_.rejected_cb, Call).Times(AtLeast(0)); - RequestConnection("1234", std::move(channel_a), channel_b.get(), &client, - &pcp_handler, connect_medium); + RequestConnection("1234", std::move(channel_a), channel_b.get(), + client_.get(), &pcp_handler, connect_medium); LOG(INFO) << "RequestConnection complete"; channel_b->Close(); bwu.Shutdown(); @@ -1255,19 +1265,18 @@ TEST_P(BasePcpHandlerTest, CanRequestConnectionLegacy) { TEST_P(BasePcpHandlerTest, RequestConnectionV3) { env_.Start(); - ClientProxy client; FakePresenceDeviceProvider provider; EXPECT_CALL(provider.local_device_, GetType) .WillRepeatedly(Return(NearbyDevice::Type::kUnknownDevice)); EXPECT_CALL(provider.local_device_, ToProtoBytes); - client.RegisterDeviceProvider(&provider); + client_->RegisterDeviceProvider(&provider); Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); BwuManager bwu(m, em, ecm, {}, {}); MockPcpHandler pcp_handler(&m, &em, &ecm, &bwu); - StartDiscovery(&client, &pcp_handler); - auto mediums = pcp_handler.GetDiscoveryMediums(&client); + StartDiscovery(client_.get(), &pcp_handler); + auto mediums = pcp_handler.GetDiscoveryMediums(client_.get()); auto connect_medium = mediums[mediums.size() - 1]; auto channel_pair = SetupConnection(connect_medium); auto& channel_a = channel_pair.first; @@ -1276,7 +1285,7 @@ TEST_P(BasePcpHandlerTest, RequestConnectionV3) { EXPECT_CALL(*channel_b, CloseImpl).Times(1); EXPECT_CALL(mock_connection_listener_.rejected_cb, Call).Times(AtLeast(0)); RequestConnectionV3(mock_device_, std::move(channel_a), channel_b.get(), - &client, &pcp_handler, connect_medium, &provider); + client_.get(), &pcp_handler, connect_medium, &provider); LOG(INFO) << "RequestConnectionV3 complete"; channel_b->Close(); bwu.Shutdown(); @@ -1286,20 +1295,19 @@ TEST_P(BasePcpHandlerTest, RequestConnectionV3) { TEST_P(BasePcpHandlerTest, RequestConnectionV3_AuthenticationFailure) { env_.Start(); - ClientProxy client; FakePresenceDeviceProvider provider; provider.SetAuthenticationStatus(AuthenticationStatus::kFailure); EXPECT_CALL(provider.local_device_, GetType) .WillRepeatedly(Return(NearbyDevice::Type::kUnknownDevice)); EXPECT_CALL(provider.local_device_, ToProtoBytes); - client.RegisterDeviceProvider(&provider); + client_->RegisterDeviceProvider(&provider); Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); BwuManager bwu(m, em, ecm, {}, {}); MockPcpHandler pcp_handler(&m, &em, &ecm, &bwu); - StartDiscovery(&client, &pcp_handler); - auto mediums = pcp_handler.GetDiscoveryMediums(&client); + StartDiscovery(client_.get(), &pcp_handler); + auto mediums = pcp_handler.GetDiscoveryMediums(client_.get()); auto connect_medium = mediums[mediums.size() - 1]; auto channel_pair = SetupConnection(connect_medium); auto& channel_a = channel_pair.first; @@ -1308,7 +1316,7 @@ TEST_P(BasePcpHandlerTest, RequestConnectionV3_AuthenticationFailure) { EXPECT_CALL(*channel_b, CloseImpl).Times(1); EXPECT_CALL(mock_connection_listener_.rejected_cb, Call).Times(AtLeast(0)); RequestConnectionV3( - mock_device_, std::move(channel_a), channel_b.get(), &client, + mock_device_, std::move(channel_a), channel_b.get(), client_.get(), &pcp_handler, connect_medium, &provider, /*flag=*/nullptr, /*expected_result=*/{Status::kSuccess}, /*expected_authentication_status=*/AuthenticationStatus::kFailure); @@ -1321,18 +1329,17 @@ TEST_P(BasePcpHandlerTest, RequestConnectionV3_AuthenticationFailure) { TEST_P(BasePcpHandlerTest, RequestConnectionV3_ConnectImplFailure) { env_.Start(); - ClientProxy client; FakePresenceDeviceProvider provider; EXPECT_CALL(provider.local_device_, GetType) .WillRepeatedly(Return(NearbyDevice::Type::kUnknownDevice)); - client.RegisterDeviceProvider(&provider); + client_->RegisterDeviceProvider(&provider); Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); BwuManager bwu(m, em, ecm, {}, {}); MockPcpHandler pcp_handler(&m, &em, &ecm, &bwu); - StartDiscovery(&client, &pcp_handler); - auto mediums = pcp_handler.GetDiscoveryMediums(&client); + StartDiscovery(client_.get(), &pcp_handler); + auto mediums = pcp_handler.GetDiscoveryMediums(client_.get()); auto connect_medium = mediums[mediums.size() - 1]; auto channel_pair = SetupConnectionForConnectFailure(connect_medium); const auto& channel_b = channel_pair.second; @@ -1356,7 +1363,7 @@ TEST_P(BasePcpHandlerTest, RequestConnectionV3_ConnectImplFailure) { .WillRepeatedly(Return(Strategy::kP2pCluster)); // Simulate successful discovery. auto encryption_runner = std::make_unique(); - auto allowed_mediums = pcp_handler.GetDiscoveryMediums(&client); + auto allowed_mediums = pcp_handler.GetDiscoveryMediums(client_.get()); EXPECT_CALL(pcp_handler, ConnectImpl) .WillRepeatedly(Invoke( @@ -1371,7 +1378,7 @@ TEST_P(BasePcpHandlerTest, RequestConnectionV3_ConnectImplFailure) { for (const auto& discovered_medium : allowed_mediums) { pcp_handler.OnEndpointFound( - &client, + client_.get(), std::make_shared(MockDiscoveredEndpoint{ { mock_device_.GetEndpointId(), @@ -1385,7 +1392,7 @@ TEST_P(BasePcpHandlerTest, RequestConnectionV3_ConnectImplFailure) { } Status expected_result = {Status::kError}; - EXPECT_EQ(pcp_handler.RequestConnectionV3(&client, mock_device_, info, + EXPECT_EQ(pcp_handler.RequestConnectionV3(client_.get(), mock_device_, info, connection_options), expected_result); LOG(INFO) << "RequestConnectionV3 complete"; @@ -1397,18 +1404,17 @@ TEST_P(BasePcpHandlerTest, RequestConnectionV3_ConnectImplFailure) { TEST_P(BasePcpHandlerTest, RequestConnection_ConnectImplFailure) { env_.Start(); - ClientProxy client; FakePresenceDeviceProvider provider; EXPECT_CALL(provider.local_device_, GetType) .WillRepeatedly(Return(NearbyDevice::Type::kUnknownDevice)); - client.RegisterDeviceProvider(&provider); + client_->RegisterDeviceProvider(&provider); Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); BwuManager bwu(m, em, ecm, {}, {}); MockPcpHandler pcp_handler(&m, &em, &ecm, &bwu); - StartDiscovery(&client, &pcp_handler); - auto mediums = pcp_handler.GetDiscoveryMediums(&client); + StartDiscovery(client_.get(), &pcp_handler); + auto mediums = pcp_handler.GetDiscoveryMediums(client_.get()); auto connect_medium = mediums[mediums.size() - 1]; auto channel_pair = SetupConnectionForConnectFailure(connect_medium); const auto& channel_b = channel_pair.second; @@ -1432,7 +1438,7 @@ TEST_P(BasePcpHandlerTest, RequestConnection_ConnectImplFailure) { .WillRepeatedly(Return(Strategy::kP2pCluster)); // Simulate successful discovery. auto encryption_runner = std::make_unique(); - auto allowed_mediums = pcp_handler.GetDiscoveryMediums(&client); + auto allowed_mediums = pcp_handler.GetDiscoveryMediums(client_.get()); EXPECT_CALL(pcp_handler, ConnectImpl) .WillRepeatedly(Invoke( @@ -1447,7 +1453,7 @@ TEST_P(BasePcpHandlerTest, RequestConnection_ConnectImplFailure) { for (const auto& discovered_medium : allowed_mediums) { pcp_handler.OnEndpointFound( - &client, + client_.get(), std::make_shared(MockDiscoveredEndpoint{ { std::string(kTestEndpointId), @@ -1460,9 +1466,10 @@ TEST_P(BasePcpHandlerTest, RequestConnection_ConnectImplFailure) { })); } Status expected_result = {Status::kError}; - EXPECT_EQ(pcp_handler.RequestConnection(&client, std::string(kTestEndpointId), - info, connection_options), - expected_result); + EXPECT_EQ( + pcp_handler.RequestConnection(client_.get(), std::string(kTestEndpointId), + info, connection_options), + expected_result); LOG(INFO) << "RequestConnection complete"; channel_b->Close(); bwu.Shutdown(); @@ -1472,14 +1479,13 @@ TEST_P(BasePcpHandlerTest, RequestConnection_ConnectImplFailure) { TEST_P(BasePcpHandlerTest, IoError_RequestConnectionV3Fails) { env_.Start(); - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); BwuManager bwu(m, em, ecm, {}, {}); MockPcpHandler pcp_handler(&m, &em, &ecm, &bwu); - StartDiscovery(&client, &pcp_handler); - auto mediums = pcp_handler.GetDiscoveryMediums(&client); + StartDiscovery(client_.get(), &pcp_handler); + auto mediums = pcp_handler.GetDiscoveryMediums(client_.get()); auto connect_medium = mediums[mediums.size() - 1]; auto channel_pair = SetupConnection(connect_medium); auto& channel_a = channel_pair.first; @@ -1489,8 +1495,8 @@ TEST_P(BasePcpHandlerTest, IoError_RequestConnectionV3Fails) { channel_b->broken_write_ = true; EXPECT_CALL(mock_connection_listener_.rejected_cb, Call).Times(AtLeast(0)); RequestConnectionV3(mock_device_, std::move(channel_a), channel_b.get(), - &client, &pcp_handler, connect_medium, nullptr, nullptr, - {Status::kEndpointIoError}); + client_.get(), &pcp_handler, connect_medium, nullptr, + nullptr, {Status::kEndpointIoError}); LOG(INFO) << "RequestConnectionV3 complete"; channel_b->Close(); bwu.Shutdown(); @@ -1501,14 +1507,13 @@ TEST_P(BasePcpHandlerTest, IoError_RequestConnectionV3Fails) { TEST_P(BasePcpHandlerTest, IoError_RequestConnectionFails) { env_.Start(); std::string endpoint_id{"1234"}; - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); BwuManager bwu(m, em, ecm, {}, {}); MockPcpHandler pcp_handler(&m, &em, &ecm, &bwu); - StartDiscovery(&client, &pcp_handler); - auto mediums = pcp_handler.GetDiscoveryMediums(&client); + StartDiscovery(client_.get(), &pcp_handler); + auto mediums = pcp_handler.GetDiscoveryMediums(client_.get()); auto connect_medium = mediums[mediums.size() - 1]; auto channel_pair = SetupConnection(connect_medium); auto& channel_a = channel_pair.first; @@ -1517,8 +1522,8 @@ TEST_P(BasePcpHandlerTest, IoError_RequestConnectionFails) { EXPECT_CALL(*channel_b, CloseImpl).Times(AtLeast(1)); channel_b->broken_write_ = true; EXPECT_CALL(mock_connection_listener_.rejected_cb, Call).Times(AtLeast(0)); - RequestConnection(endpoint_id, std::move(channel_a), channel_b.get(), &client, - &pcp_handler, connect_medium, nullptr, + RequestConnection(endpoint_id, std::move(channel_a), channel_b.get(), + client_.get(), &pcp_handler, connect_medium, nullptr, {Status::kEndpointIoError}); LOG(INFO) << "RequestConnection complete"; channel_b->Close(); @@ -1530,24 +1535,23 @@ TEST_P(BasePcpHandlerTest, IoError_RequestConnectionFails) { TEST_P(BasePcpHandlerTest, AcceptConnectionChangesState) { env_.Start(); std::string endpoint_id{"1234"}; - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); BwuManager bwu(m, em, ecm, {}, {}); MockPcpHandler pcp_handler(&m, &em, &ecm, &bwu); - StartDiscovery(&client, &pcp_handler); - auto mediums = pcp_handler.GetDiscoveryMediums(&client); + StartDiscovery(client_.get(), &pcp_handler); + auto mediums = pcp_handler.GetDiscoveryMediums(client_.get()); auto connect_medium = mediums[mediums.size() - 1]; auto channel_pair = SetupConnection(connect_medium); auto& channel_a = channel_pair.first; auto& channel_b = channel_pair.second; EXPECT_CALL(*channel_a, CloseImpl).Times(1); EXPECT_CALL(*channel_b, CloseImpl).Times(1); - RequestConnection(endpoint_id, std::move(channel_a), channel_b.get(), &client, - &pcp_handler, connect_medium); + RequestConnection(endpoint_id, std::move(channel_a), channel_b.get(), + client_.get(), &pcp_handler, connect_medium); LOG(INFO) << "Attempting to accept connection: id=" << endpoint_id; - EXPECT_EQ(pcp_handler.AcceptConnection(&client, endpoint_id, {}), + EXPECT_EQ(pcp_handler.AcceptConnection(client_.get(), endpoint_id, {}), Status{Status::kSuccess}); EXPECT_CALL(mock_connection_listener_.rejected_cb, Call).Times(AtLeast(0)); LOG(INFO) << "Closing connection: id=" << endpoint_id; @@ -1560,22 +1564,21 @@ TEST_P(BasePcpHandlerTest, AcceptConnectionChangesState) { TEST_P(BasePcpHandlerTest, RejectConnectionChangesState) { env_.Start(); std::string endpoint_id{"1234"}; - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); BwuManager bwu(m, em, ecm, {}, {}); MockPcpHandler pcp_handler(&m, &em, &ecm, &bwu); - StartDiscovery(&client, &pcp_handler); - auto mediums = pcp_handler.GetDiscoveryMediums(&client); + StartDiscovery(client_.get(), &pcp_handler); + auto mediums = pcp_handler.GetDiscoveryMediums(client_.get()); auto connect_medium = mediums[mediums.size() - 1]; auto channel_pair = SetupConnection(connect_medium); auto& channel_b = channel_pair.second; EXPECT_CALL(mock_connection_listener_.rejected_cb, Call).Times(1); RequestConnection(endpoint_id, std::move(channel_pair.first), channel_b.get(), - &client, &pcp_handler, connect_medium); + client_.get(), &pcp_handler, connect_medium); LOG(INFO) << "Attempting to reject connection: id=" << endpoint_id; - EXPECT_EQ(pcp_handler.RejectConnection(&client, endpoint_id), + EXPECT_EQ(pcp_handler.RejectConnection(client_.get(), endpoint_id), Status{Status::kSuccess}); LOG(INFO) << "Closing connection: id=" << endpoint_id; channel_b->Close(); @@ -1587,35 +1590,34 @@ TEST_P(BasePcpHandlerTest, RejectConnectionChangesState) { TEST_P(BasePcpHandlerTest, OnIncomingFrameChangesState) { env_.Start(); std::string endpoint_id{"1234"}; - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); BwuManager bwu(m, em, ecm, {}, {}); MockPcpHandler pcp_handler(&m, &em, &ecm, &bwu); analytics::PacketMetaData packet_meta_data; - StartDiscovery(&client, &pcp_handler); - auto mediums = pcp_handler.GetDiscoveryMediums(&client); + StartDiscovery(client_.get(), &pcp_handler); + auto mediums = pcp_handler.GetDiscoveryMediums(client_.get()); auto connect_medium = mediums[mediums.size() - 1]; auto channel_pair = SetupConnection(connect_medium); auto& channel_a = channel_pair.first; auto& channel_b = channel_pair.second; EXPECT_CALL(*channel_a, CloseImpl).Times(1); EXPECT_CALL(*channel_b, CloseImpl).Times(1); - RequestConnection(endpoint_id, std::move(channel_a), channel_b.get(), &client, - &pcp_handler, connect_medium); + RequestConnection(endpoint_id, std::move(channel_a), channel_b.get(), + client_.get(), &pcp_handler, connect_medium); LOG(INFO) << "Attempting to accept connection: id=" << endpoint_id; EXPECT_CALL(mock_connection_listener_.accepted_cb, Call).Times(1); EXPECT_CALL(mock_connection_listener_.disconnected_cb, Call) .Times(AtLeast(0)); - EXPECT_EQ(pcp_handler.AcceptConnection(&client, endpoint_id, {}), + EXPECT_EQ(pcp_handler.AcceptConnection(client_.get(), endpoint_id, {}), Status{Status::kSuccess}); LOG(INFO) << "Simulating remote accept: id=" << endpoint_id; OsInfo os_info; auto frame = parser::FromBytes(parser::ForConnectionResponse( Status::kSuccess, os_info, /*multiplex_socket_bitmask=*/0)); EXPECT_CALL(mock_connection_listener_.bandwidth_changed_cb, Call).Times(1); - pcp_handler.OnIncomingFrame(frame.result(), endpoint_id, &client, + pcp_handler.OnIncomingFrame(frame.result(), endpoint_id, client_.get(), connect_medium, packet_meta_data); LOG(INFO) << "Closing connection: id=" << endpoint_id; channel_b->Close(); @@ -1630,14 +1632,13 @@ TEST_P(BasePcpHandlerTest, DestructorIsCalledOnProtocolEndpoint) { int mediums_count = 0; { std::string endpoint_id{"1234"}; - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); BwuManager bwu(m, em, ecm, {}, {}); MockPcpHandler pcp_handler(&m, &em, &ecm, &bwu); - StartDiscovery(&client, &pcp_handler); - auto mediums = pcp_handler.GetDiscoveryMediums(&client); + StartDiscovery(client_.get(), &pcp_handler); + auto mediums = pcp_handler.GetDiscoveryMediums(client_.get()); auto connect_medium = mediums[mediums.size() - 1]; auto channel_pair = SetupConnection(connect_medium); auto& channel_a = channel_pair.first; @@ -1645,10 +1646,11 @@ TEST_P(BasePcpHandlerTest, DestructorIsCalledOnProtocolEndpoint) { EXPECT_CALL(*channel_a, CloseImpl).Times(1); EXPECT_CALL(*channel_b, CloseImpl).Times(1); RequestConnection(endpoint_id, std::move(channel_a), channel_b.get(), - &client, &pcp_handler, connect_medium, &destroyed_flag); + client_.get(), &pcp_handler, connect_medium, + &destroyed_flag); mediums_count = mediums.size(); LOG(INFO) << "Attempting to accept connection: id=" << endpoint_id; - EXPECT_EQ(pcp_handler.AcceptConnection(&client, endpoint_id, {}), + EXPECT_EQ(pcp_handler.AcceptConnection(client_.get(), endpoint_id, {}), Status{Status::kSuccess}); EXPECT_CALL(mock_connection_listener_.rejected_cb, Call).Times(AtLeast(0)); LOG(INFO) << "Closing connection: id=" << endpoint_id; @@ -1672,14 +1674,13 @@ TEST_P(BasePcpHandlerTest, MultipleMediumsProduceSingleEndpointLostEvent) { int mediums_count = 0; { std::string endpoint_id{"1234"}; - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); BwuManager bwu(m, em, ecm, {}, {}); MockPcpHandler pcp_handler(&m, &em, &ecm, &bwu); - StartDiscovery(&client, &pcp_handler); - auto mediums = pcp_handler.GetDiscoveryMediums(&client); + StartDiscovery(client_.get(), &pcp_handler); + auto mediums = pcp_handler.GetDiscoveryMediums(client_.get()); auto connect_medium = mediums[mediums.size() - 1]; auto channel_pair = SetupConnection(connect_medium); auto& channel_a = channel_pair.first; @@ -1688,22 +1689,23 @@ TEST_P(BasePcpHandlerTest, MultipleMediumsProduceSingleEndpointLostEvent) { EXPECT_CALL(*channel_b, CloseImpl).Times(1); EXPECT_CALL(mock_discovery_listener_.endpoint_lost_cb, Call).Times(1); RequestConnection(endpoint_id, std::move(channel_a), channel_b.get(), - &client, &pcp_handler, connect_medium, &destroyed_flag); - auto allowed_mediums = pcp_handler.GetDiscoveryMediums(&client); + client_.get(), &pcp_handler, connect_medium, + &destroyed_flag); + auto allowed_mediums = pcp_handler.GetDiscoveryMediums(client_.get()); mediums_count = allowed_mediums.size(); LOG(INFO) << "Attempting to accept connection: id=" << endpoint_id; - EXPECT_EQ(pcp_handler.AcceptConnection(&client, endpoint_id, {}), + EXPECT_EQ(pcp_handler.AcceptConnection(client_.get(), endpoint_id, {}), Status{Status::kSuccess}); EXPECT_CALL(mock_connection_listener_.rejected_cb, Call).Times(AtLeast(0)); auto endpoint_disc = pcp_handler.GetDiscoveredEndpoint(endpoint_id); - pcp_handler.OnEndpointLost(&client, *endpoint_disc); + pcp_handler.OnEndpointLost(client_.get(), *endpoint_disc); EXPECT_NE(pcp_handler.GetDiscoveredEndpoint(endpoint_id), nullptr); for (const auto* endpoint : pcp_handler.GetDiscoveredEndpoints(endpoint_id)) { - pcp_handler.OnEndpointLost(&client, *endpoint); + pcp_handler.OnEndpointLost(client_.get(), *endpoint); } EXPECT_EQ(pcp_handler.GetDiscoveredEndpoint(endpoint_id), nullptr); - EXPECT_FALSE(client.IsConnectedToEndpoint(endpoint_id)); + EXPECT_FALSE(client_->IsConnectedToEndpoint(endpoint_id)); LOG(INFO) << "Closing connection: id=" << endpoint_id; channel_b->Close(); bwu.Shutdown(); @@ -1769,7 +1771,6 @@ TEST_F(BasePcpHandlerTest, InjectEndpoint) { env_.Start(); std::string service_id{"service"}; std::string endpoint_id{"ABCD"}; - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); @@ -1787,17 +1788,18 @@ TEST_F(BasePcpHandlerTest, InjectEndpoint) { false, // enforce_topology_constraints; }; EXPECT_CALL(mock_discovery_listener_.endpoint_found_cb, Call); - EXPECT_CALL(pcp_handler, StartDiscoveryImpl(&client, service_id, _)) + EXPECT_CALL(pcp_handler, StartDiscoveryImpl(client_.get(), service_id, _)) .WillOnce(Return(MockPcpHandler::StartOperationResult{ .status = {Status::kSuccess}, .mediums = allowed.GetMediums(true), })); - EXPECT_EQ(pcp_handler.StartDiscovery(&client, service_id, discovery_options, - GetDiscoveryListener()), - Status{Status::kSuccess}); - EXPECT_TRUE(client.IsDiscovering()); + EXPECT_EQ( + pcp_handler.StartDiscovery(client_.get(), service_id, discovery_options, + GetDiscoveryListener()), + Status{Status::kSuccess}); + EXPECT_TRUE(client_->IsDiscovering()); - EXPECT_CALL(pcp_handler, InjectEndpointImpl(&client, service_id, _)) + EXPECT_CALL(pcp_handler, InjectEndpointImpl(client_.get(), service_id, _)) .WillOnce(Invoke([&pcp_handler, &endpoint_id]( ClientProxy* client, const std::string& service_id, const OutOfBandConnectionMetadata& metadata) { @@ -1816,7 +1818,7 @@ TEST_F(BasePcpHandlerTest, InjectEndpoint) { return Status{Status::kSuccess}; })); pcp_handler.InjectEndpoint( - &client, service_id, + client_.get(), service_id, OutOfBandConnectionMetadata{ .medium = Medium::BLUETOOTH, .remote_bluetooth_mac_address = ByteArray(kFakeMacAddress), @@ -1830,7 +1832,6 @@ TEST_F(BasePcpHandlerTest, env_.Start(); std::string service_id{"service"}; std::string endpoint_id{"ABCD"}; - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); @@ -1855,10 +1856,11 @@ TEST_F(BasePcpHandlerTest, .mediums = allowed.GetMediums(true), })); - EXPECT_EQ(pcp_handler.StartDiscovery(&client, service_id, discovery_options, - GetDiscoveryListener()), - Status{Status::kSuccess}); - EXPECT_TRUE(client.IsDiscovering()); + EXPECT_EQ( + pcp_handler.StartDiscovery(client_.get(), service_id, discovery_options, + GetDiscoveryListener()), + Status{Status::kSuccess}); + EXPECT_TRUE(client_->IsDiscovering()); ::testing::InSequence seq; EXPECT_CALL(mock_discovery_listener_.endpoint_found_cb, Call) @@ -1889,43 +1891,46 @@ TEST_F(BasePcpHandlerTest, // Found endpoint on Bluetooth pcp_handler.OnEndpointFound( - &client, std::make_shared(MockDiscoveredEndpoint{ - { - endpoint_id, - /*endpoint_info=*/ByteArray{"ABCD"}, - service_id, - Medium::BLUETOOTH, - WebRtcState::kUndefined, - }, - MockContext{nullptr}, - })); + client_.get(), + std::make_shared(MockDiscoveredEndpoint{ + { + endpoint_id, + /*endpoint_info=*/ByteArray{"ABCD"}, + service_id, + Medium::BLUETOOTH, + WebRtcState::kUndefined, + }, + MockContext{nullptr}, + })); // Found endpoint on BLE pcp_handler.OnEndpointFound( - &client, std::make_shared(MockDiscoveredEndpoint{ - { - endpoint_id, - /*endpoint_info=*/ByteArray{"ABCD"}, - service_id, - Medium::BLE, - WebRtcState::kUndefined, - }, - MockContext{nullptr}, - })); + client_.get(), + std::make_shared(MockDiscoveredEndpoint{ + { + endpoint_id, + /*endpoint_info=*/ByteArray{"ABCD"}, + service_id, + Medium::BLE, + WebRtcState::kUndefined, + }, + MockContext{nullptr}, + })); // Endpoint info changed on BLE pcp_handler.OnEndpointFound( - &client, std::make_shared(MockDiscoveredEndpoint{ - { - endpoint_id, - /*endpoint_info=*/ByteArray{"ABCDEF"}, - service_id, - Medium::BLE, - WebRtcState::kUndefined, - }, - MockContext{nullptr}, - })); + client_.get(), + std::make_shared(MockDiscoveredEndpoint{ + { + endpoint_id, + /*endpoint_info=*/ByteArray{"ABCDEF"}, + service_id, + Medium::BLE, + WebRtcState::kUndefined, + }, + MockContext{nullptr}, + })); - pcp_handler.OnEndpointLost(&client, + pcp_handler.OnEndpointLost(client_.get(), MockDiscoveredEndpoint{ { endpoint_id, @@ -1945,7 +1950,6 @@ TEST_F(BasePcpHandlerTest, TestStartStopEndpointLostAlarm) { env_.Start(); std::string service_id{"service"}; std::string endpoint_id{"ABCD"}; - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); @@ -1967,10 +1971,10 @@ TEST_F(BasePcpHandlerTest, TestStartStopEndpointLostAlarm) { .status = {Status::kSuccess}, .mediums = allowed.GetMediums(true), })); - EXPECT_EQ( - pcp_handler.StartDiscovery(&client, service_id, discovery_options, {}), - Status{Status::kSuccess}); - EXPECT_TRUE(client.IsDiscovering()); + EXPECT_EQ(pcp_handler.StartDiscovery(client_.get(), service_id, + discovery_options, {}), + Status{Status::kSuccess}); + EXPECT_TRUE(client_->IsDiscovering()); EXPECT_CALL(pcp_handler, InjectEndpointImpl) .WillOnce(Invoke([&pcp_handler, &endpoint_id]( @@ -1991,14 +1995,14 @@ TEST_F(BasePcpHandlerTest, TestStartStopEndpointLostAlarm) { return Status{Status::kSuccess}; })); pcp_handler.InjectEndpoint( - &client, service_id, + client_.get(), service_id, OutOfBandConnectionMetadata{ .medium = Medium::BLUETOOTH, .remote_bluetooth_mac_address = ByteArray(kFakeMacAddress), }); EXPECT_EQ(pcp_handler.GetDiscoveredEndpoints(Medium::BLUETOOTH).size(), 1); EXPECT_EQ(pcp_handler.GetEndpointLostByMediumAlarmsCount(), 0); - pcp_handler.StartEndpointLostByMediumAlarms(&client, Medium::BLUETOOTH); + pcp_handler.StartEndpointLostByMediumAlarms(client_.get(), Medium::BLUETOOTH); EXPECT_EQ(pcp_handler.GetEndpointLostByMediumAlarmsCount(), 1); pcp_handler.StopEndpointLostByMediumAlarm(endpoint_id, Medium::BLUETOOTH); EXPECT_EQ(pcp_handler.GetEndpointLostByMediumAlarmsCount(), 0); @@ -2009,7 +2013,6 @@ TEST_F(BasePcpHandlerTest, TestStartEndpointLostByMediumAlarms) { env_.Start(); std::string service_id{"service"}; std::string endpoint_id{"ABCD"}; - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); @@ -2031,10 +2034,10 @@ TEST_F(BasePcpHandlerTest, TestStartEndpointLostByMediumAlarms) { .status = {Status::kSuccess}, .mediums = allowed.GetMediums(true), })); - EXPECT_EQ( - pcp_handler.StartDiscovery(&client, service_id, discovery_options, {}), - Status{Status::kSuccess}); - EXPECT_TRUE(client.IsDiscovering()); + EXPECT_EQ(pcp_handler.StartDiscovery(client_.get(), service_id, + discovery_options, {}), + Status{Status::kSuccess}); + EXPECT_TRUE(client_->IsDiscovering()); EXPECT_CALL(pcp_handler, InjectEndpointImpl) .WillOnce(Invoke([&pcp_handler, &endpoint_id]( @@ -2055,14 +2058,14 @@ TEST_F(BasePcpHandlerTest, TestStartEndpointLostByMediumAlarms) { return Status{Status::kSuccess}; })); pcp_handler.InjectEndpoint( - &client, service_id, + client_.get(), service_id, OutOfBandConnectionMetadata{ .medium = Medium::BLUETOOTH, .remote_bluetooth_mac_address = ByteArray(kFakeMacAddress), }); EXPECT_EQ(pcp_handler.GetDiscoveredEndpoints(Medium::BLUETOOTH).size(), 1); EXPECT_EQ(pcp_handler.GetEndpointLostByMediumAlarmsCount(), 0); - pcp_handler.StartEndpointLostByMediumAlarms(&client, Medium::BLUETOOTH); + pcp_handler.StartEndpointLostByMediumAlarms(client_.get(), Medium::BLUETOOTH); EXPECT_EQ(pcp_handler.GetEndpointLostByMediumAlarmsCount(), 1); absl::SleepFor(absl::Seconds(11)); EXPECT_EQ(pcp_handler.GetDiscoveredEndpoints(Medium::BLUETOOTH).size(), 0); @@ -2074,7 +2077,6 @@ TEST_F(BasePcpHandlerTest, TestEndpointFoundStopsAlarm) { env_.Start(); std::string service_id{"service"}; std::string endpoint_id{"ABCD"}; - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); @@ -2096,10 +2098,10 @@ TEST_F(BasePcpHandlerTest, TestEndpointFoundStopsAlarm) { .status = {Status::kSuccess}, .mediums = allowed.GetMediums(true), })); - EXPECT_EQ( - pcp_handler.StartDiscovery(&client, service_id, discovery_options, {}), - Status{Status::kSuccess}); - EXPECT_TRUE(client.IsDiscovering()); + EXPECT_EQ(pcp_handler.StartDiscovery(client_.get(), service_id, + discovery_options, {}), + Status{Status::kSuccess}); + EXPECT_TRUE(client_->IsDiscovering()); bool first_call = true; EXPECT_CALL(pcp_handler, InjectEndpointImpl) @@ -2130,17 +2132,17 @@ TEST_F(BasePcpHandlerTest, TestEndpointFoundStopsAlarm) { return Status{Status::kSuccess}; })); pcp_handler.InjectEndpoint( - &client, service_id, + client_.get(), service_id, OutOfBandConnectionMetadata{ .medium = Medium::BLUETOOTH, .remote_bluetooth_mac_address = ByteArray(kFakeMacAddress), }); EXPECT_EQ(pcp_handler.GetDiscoveredEndpoints(Medium::BLUETOOTH).size(), 1); EXPECT_EQ(pcp_handler.GetEndpointLostByMediumAlarmsCount(), 0); - pcp_handler.StartEndpointLostByMediumAlarms(&client, Medium::BLUETOOTH); + pcp_handler.StartEndpointLostByMediumAlarms(client_.get(), Medium::BLUETOOTH); EXPECT_EQ(pcp_handler.GetEndpointLostByMediumAlarmsCount(), 1); pcp_handler.InjectEndpoint( - &client, service_id, + client_.get(), service_id, OutOfBandConnectionMetadata{ .medium = Medium::BLUETOOTH, .remote_bluetooth_mac_address = ByteArray(kFakeMacAddress), @@ -2171,7 +2173,6 @@ TEST_P(BasePcpHandlerTest, TestGetConnectionInfosFromMediums) { TEST_F(BasePcpHandlerTest, TestCanStartListeningForIncomingConnections) { env_.Start(); - ClientProxy client; Mediums mediums; EndpointChannelManager endpoint_channel_manager; EndpointManager endpoint_manager(&endpoint_channel_manager); @@ -2187,14 +2188,13 @@ TEST_F(BasePcpHandlerTest, TestCanStartListeningForIncomingConnections) { .enable_ble_listening = true, .enable_bluetooth_listening = true, .enable_wlan_listening = true}; - pcp_handler.StartListeningForIncomingConnections(&client, "service", options, - {}); - EXPECT_TRUE(client.IsListeningForIncomingConnections()); + pcp_handler.StartListeningForIncomingConnections(client_.get(), "service", + options, {}); + EXPECT_TRUE(client_->IsListeningForIncomingConnections()); } TEST_F(BasePcpHandlerTest, TestStartListeningForIncomingConnectionsBadStatus) { env_.Start(); - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); @@ -2208,14 +2208,13 @@ TEST_F(BasePcpHandlerTest, TestStartListeningForIncomingConnectionsBadStatus) { .enable_ble_listening = true, .enable_bluetooth_listening = true, .enable_wlan_listening = true}; - pcp_handler.StartListeningForIncomingConnections(&client, "service", options, - {}); - EXPECT_FALSE(client.IsListeningForIncomingConnections()); + pcp_handler.StartListeningForIncomingConnections(client_.get(), "service", + options, {}); + EXPECT_FALSE(client_->IsListeningForIncomingConnections()); } TEST_F(BasePcpHandlerTest, TestCanStopListeningForIncomingConnections) { env_.Start(); - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); @@ -2230,16 +2229,15 @@ TEST_F(BasePcpHandlerTest, TestCanStopListeningForIncomingConnections) { .enable_ble_listening = true, .enable_bluetooth_listening = true, .enable_wlan_listening = true}; - pcp_handler.StartListeningForIncomingConnections(&client, "service", options, - {}); - pcp_handler.StopListeningForIncomingConnections(&client); - EXPECT_FALSE(client.IsListeningForIncomingConnections()); + pcp_handler.StartListeningForIncomingConnections(client_.get(), "service", + options, {}); + pcp_handler.StopListeningForIncomingConnections(client_.get()); + EXPECT_FALSE(client_->IsListeningForIncomingConnections()); } TEST_F(BasePcpHandlerTest, TestWifiLanStopListeningForIncomingConnectionsSuccessWhenStopped) { env_.Start(); - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); @@ -2254,16 +2252,15 @@ TEST_F(BasePcpHandlerTest, .enable_ble_listening = true, .enable_bluetooth_listening = true, .enable_wlan_listening = true}; - pcp_handler.StartListeningForIncomingConnections(&client, "service", options, - {}); + pcp_handler.StartListeningForIncomingConnections(client_.get(), "service", + options, {}); m.GetWifiLan().StopAcceptingConnections("service"); - pcp_handler.StopListeningForIncomingConnections(&client); - EXPECT_FALSE(client.IsListeningForIncomingConnections()); + pcp_handler.StopListeningForIncomingConnections(client_.get()); + EXPECT_FALSE(client_->IsListeningForIncomingConnections()); } TEST_F(BasePcpHandlerTest, TestDeviceFilterForConnectionsWithUnknown) { env_.Start(); - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); @@ -2280,12 +2277,12 @@ TEST_F(BasePcpHandlerTest, TestDeviceFilterForConnectionsWithUnknown) { MockPcpHandler::StartOperationResult{.status = {Status::kSuccess}})); EXPECT_CALL(pcp_handler, CanReceiveIncomingConnection) .WillRepeatedly(Return(true)); - EXPECT_TRUE( - pcp_handler - .StartListeningForIncomingConnections(&client, "service", options, {}) - .first.Ok()); - ASSERT_TRUE(client.IsListeningForIncomingConnections()); - ASSERT_TRUE(pcp_handler.CanReceiveIncomingConnection(&client)); + EXPECT_TRUE(pcp_handler + .StartListeningForIncomingConnections(client_.get(), + "service", options, {}) + .first.Ok()); + ASSERT_TRUE(client_->IsListeningForIncomingConnections()); + ASSERT_TRUE(pcp_handler.CanReceiveIncomingConnection(client_.get())); auto channel_pair = SetupConnection(Medium::BLUETOOTH); ByteArray serialized_frame = parser::ForConnectionRequestConnections( {}, { @@ -2302,19 +2299,18 @@ TEST_F(BasePcpHandlerTest, TestDeviceFilterForConnectionsWithUnknown) { channel_pair.first->Write(ByteArray()); channel_pair.first->Write(ByteArray(frame.SerializeAsString())); EXPECT_TRUE(pcp_handler - .OnIncomingConnection(&client, ByteArray("remote endpoint"), - std::move(channel_pair.second), - Medium::BLUETOOTH, - NearbyDevice::Type::kConnectionsDevice) + .OnIncomingConnection( + client_.get(), ByteArray("remote endpoint"), + std::move(channel_pair.second), Medium::BLUETOOTH, + NearbyDevice::Type::kConnectionsDevice) .Ok()); - EXPECT_TRUE(pcp_handler.HasIncomingConnections(&client)); - EXPECT_FALSE(pcp_handler.HasOutgoingConnections(&client)); + EXPECT_TRUE(pcp_handler.HasIncomingConnections(client_.get())); + EXPECT_FALSE(pcp_handler.HasOutgoingConnections(client_.get())); env_.Stop(); } TEST_F(BasePcpHandlerTest, TestDeviceFilterForPresenceWithUnknown) { env_.Start(); - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); @@ -2331,12 +2327,12 @@ TEST_F(BasePcpHandlerTest, TestDeviceFilterForPresenceWithUnknown) { MockPcpHandler::StartOperationResult{.status = {Status::kSuccess}})); EXPECT_CALL(pcp_handler, CanReceiveIncomingConnection) .WillRepeatedly(Return(true)); - EXPECT_TRUE( - pcp_handler - .StartListeningForIncomingConnections(&client, "service", options, {}) - .first.Ok()); - ASSERT_TRUE(client.IsListeningForIncomingConnections()); - ASSERT_TRUE(pcp_handler.CanReceiveIncomingConnection(&client)); + EXPECT_TRUE(pcp_handler + .StartListeningForIncomingConnections(client_.get(), + "service", options, {}) + .first.Ok()); + ASSERT_TRUE(client_->IsListeningForIncomingConnections()); + ASSERT_TRUE(pcp_handler.CanReceiveIncomingConnection(client_.get())); auto channel_pair = SetupConnection(Medium::BLUETOOTH); ByteArray serialized_frame = parser::ForConnectionRequestConnections( {}, { @@ -2353,10 +2349,10 @@ TEST_F(BasePcpHandlerTest, TestDeviceFilterForPresenceWithUnknown) { channel_pair.first->Write(ByteArray()); channel_pair.first->Write(ByteArray(frame.SerializeAsString())); EXPECT_EQ(pcp_handler - .OnIncomingConnection(&client, ByteArray("remote endpoint"), - std::move(channel_pair.second), - Medium::BLUETOOTH, - NearbyDevice::Type::kPresenceDevice) + .OnIncomingConnection( + client_.get(), ByteArray("remote endpoint"), + std::move(channel_pair.second), Medium::BLUETOOTH, + NearbyDevice::Type::kPresenceDevice) .value, Exception::Value::kIo); env_.Stop(); @@ -2364,7 +2360,6 @@ TEST_F(BasePcpHandlerTest, TestDeviceFilterForPresenceWithUnknown) { TEST_F(BasePcpHandlerTest, TestDeviceFilterForPresenceWithConnections) { env_.Start(); - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); @@ -2381,12 +2376,12 @@ TEST_F(BasePcpHandlerTest, TestDeviceFilterForPresenceWithConnections) { MockPcpHandler::StartOperationResult{.status = {Status::kSuccess}})); EXPECT_CALL(pcp_handler, CanReceiveIncomingConnection) .WillRepeatedly(Return(true)); - EXPECT_TRUE( - pcp_handler - .StartListeningForIncomingConnections(&client, "service", options, {}) - .first.Ok()); - ASSERT_TRUE(client.IsListeningForIncomingConnections()); - ASSERT_TRUE(pcp_handler.CanReceiveIncomingConnection(&client)); + EXPECT_TRUE(pcp_handler + .StartListeningForIncomingConnections(client_.get(), + "service", options, {}) + .first.Ok()); + ASSERT_TRUE(client_->IsListeningForIncomingConnections()); + ASSERT_TRUE(pcp_handler.CanReceiveIncomingConnection(client_.get())); auto channel_pair = SetupConnection(Medium::BLUETOOTH); ByteArray serialized_frame = parser::ForConnectionRequestConnections( {}, { @@ -2404,10 +2399,10 @@ TEST_F(BasePcpHandlerTest, TestDeviceFilterForPresenceWithConnections) { channel_pair.first->Write(ByteArray()); channel_pair.first->Write(ByteArray(frame.SerializeAsString())); EXPECT_EQ(pcp_handler - .OnIncomingConnection(&client, ByteArray("remote endpoint"), - std::move(channel_pair.second), - Medium::BLUETOOTH, - NearbyDevice::Type::kPresenceDevice) + .OnIncomingConnection( + client_.get(), ByteArray("remote endpoint"), + std::move(channel_pair.second), Medium::BLUETOOTH, + NearbyDevice::Type::kPresenceDevice) .value, Exception::Value::kIo); env_.Stop(); @@ -2415,7 +2410,6 @@ TEST_F(BasePcpHandlerTest, TestDeviceFilterForPresenceWithConnections) { TEST_F(BasePcpHandlerTest, TestDeviceFilterForPresenceWithPresence) { env_.Start(); - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); @@ -2432,12 +2426,12 @@ TEST_F(BasePcpHandlerTest, TestDeviceFilterForPresenceWithPresence) { MockPcpHandler::StartOperationResult{.status = {Status::kSuccess}})); EXPECT_CALL(pcp_handler, CanReceiveIncomingConnection) .WillRepeatedly(Return(true)); - EXPECT_TRUE( - pcp_handler - .StartListeningForIncomingConnections(&client, "service", options, {}) - .first.Ok()); - ASSERT_TRUE(client.IsListeningForIncomingConnections()); - ASSERT_TRUE(pcp_handler.CanReceiveIncomingConnection(&client)); + EXPECT_TRUE(pcp_handler + .StartListeningForIncomingConnections(client_.get(), + "service", options, {}) + .first.Ok()); + ASSERT_TRUE(client_->IsListeningForIncomingConnections()); + ASSERT_TRUE(pcp_handler.CanReceiveIncomingConnection(client_.get())); auto channel_pair = SetupConnection(Medium::BLUETOOTH); ByteArray serialized_frame = parser::ForConnectionRequestConnections( {}, { @@ -2455,17 +2449,16 @@ TEST_F(BasePcpHandlerTest, TestDeviceFilterForPresenceWithPresence) { channel_pair.first->Write(ByteArray()); channel_pair.first->Write(ByteArray(frame.SerializeAsString())); EXPECT_TRUE(pcp_handler - .OnIncomingConnection(&client, ByteArray("remote endpoint"), - std::move(channel_pair.second), - Medium::BLUETOOTH, - NearbyDevice::Type::kPresenceDevice) + .OnIncomingConnection( + client_.get(), ByteArray("remote endpoint"), + std::move(channel_pair.second), Medium::BLUETOOTH, + NearbyDevice::Type::kPresenceDevice) .Ok()); env_.Stop(); } TEST_F(BasePcpHandlerTest, TestDeviceFilterForConnectionsWithConnections) { env_.Start(); - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); @@ -2482,12 +2475,12 @@ TEST_F(BasePcpHandlerTest, TestDeviceFilterForConnectionsWithConnections) { MockPcpHandler::StartOperationResult{.status = {Status::kSuccess}})); EXPECT_CALL(pcp_handler, CanReceiveIncomingConnection) .WillRepeatedly(Return(true)); - EXPECT_TRUE( - pcp_handler - .StartListeningForIncomingConnections(&client, "service", options, {}) - .first.Ok()); - ASSERT_TRUE(client.IsListeningForIncomingConnections()); - ASSERT_TRUE(pcp_handler.CanReceiveIncomingConnection(&client)); + EXPECT_TRUE(pcp_handler + .StartListeningForIncomingConnections(client_.get(), + "service", options, {}) + .first.Ok()); + ASSERT_TRUE(client_->IsListeningForIncomingConnections()); + ASSERT_TRUE(pcp_handler.CanReceiveIncomingConnection(client_.get())); auto channel_pair = SetupConnection(Medium::BLUETOOTH); ByteArray serialized_frame = parser::ForConnectionRequestConnections( {}, { @@ -2505,17 +2498,16 @@ TEST_F(BasePcpHandlerTest, TestDeviceFilterForConnectionsWithConnections) { channel_pair.first->Write(ByteArray()); channel_pair.first->Write(ByteArray(frame.SerializeAsString())); EXPECT_TRUE(pcp_handler - .OnIncomingConnection(&client, ByteArray("remote endpoint"), - std::move(channel_pair.second), - Medium::BLUETOOTH, - NearbyDevice::Type::kConnectionsDevice) + .OnIncomingConnection( + client_.get(), ByteArray("remote endpoint"), + std::move(channel_pair.second), Medium::BLUETOOTH, + NearbyDevice::Type::kConnectionsDevice) .Ok()); env_.Stop(); } TEST_F(BasePcpHandlerTest, TestDeviceFilterForConnectionsWithPresence) { env_.Start(); - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); @@ -2532,12 +2524,12 @@ TEST_F(BasePcpHandlerTest, TestDeviceFilterForConnectionsWithPresence) { MockPcpHandler::StartOperationResult{.status = {Status::kSuccess}})); EXPECT_CALL(pcp_handler, CanReceiveIncomingConnection) .WillRepeatedly(Return(true)); - EXPECT_TRUE( - pcp_handler - .StartListeningForIncomingConnections(&client, "service", options, {}) - .first.Ok()); - ASSERT_TRUE(client.IsListeningForIncomingConnections()); - ASSERT_TRUE(pcp_handler.CanReceiveIncomingConnection(&client)); + EXPECT_TRUE(pcp_handler + .StartListeningForIncomingConnections(client_.get(), + "service", options, {}) + .first.Ok()); + ASSERT_TRUE(client_->IsListeningForIncomingConnections()); + ASSERT_TRUE(pcp_handler.CanReceiveIncomingConnection(client_.get())); auto channel_pair = SetupConnection(Medium::BLUETOOTH); ByteArray serialized_frame = parser::ForConnectionRequestConnections( {}, { @@ -2555,10 +2547,10 @@ TEST_F(BasePcpHandlerTest, TestDeviceFilterForConnectionsWithPresence) { channel_pair.first->Write(ByteArray()); channel_pair.first->Write(ByteArray(frame.SerializeAsString())); EXPECT_EQ(pcp_handler - .OnIncomingConnection(&client, ByteArray("remote endpoint"), - std::move(channel_pair.second), - Medium::BLUETOOTH, - NearbyDevice::Type::kConnectionsDevice) + .OnIncomingConnection( + client_.get(), ByteArray("remote endpoint"), + std::move(channel_pair.second), Medium::BLUETOOTH, + NearbyDevice::Type::kConnectionsDevice) .value, Exception::Value::kIo); env_.Stop(); @@ -2566,7 +2558,6 @@ TEST_F(BasePcpHandlerTest, TestDeviceFilterForConnectionsWithPresence) { TEST_F(BasePcpHandlerTest, IncomingConnectionFailsWithEmptyEndpointId) { env_.Start(); - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); @@ -2583,12 +2574,12 @@ TEST_F(BasePcpHandlerTest, IncomingConnectionFailsWithEmptyEndpointId) { MockPcpHandler::StartOperationResult{.status = {Status::kSuccess}})); EXPECT_CALL(pcp_handler, CanReceiveIncomingConnection) .WillRepeatedly(Return(true)); - EXPECT_TRUE( - pcp_handler - .StartListeningForIncomingConnections(&client, "service", options, {}) - .first.Ok()); - ASSERT_TRUE(client.IsListeningForIncomingConnections()); - ASSERT_TRUE(pcp_handler.CanReceiveIncomingConnection(&client)); + EXPECT_TRUE(pcp_handler + .StartListeningForIncomingConnections(client_.get(), + "service", options, {}) + .first.Ok()); + ASSERT_TRUE(client_->IsListeningForIncomingConnections()); + ASSERT_TRUE(pcp_handler.CanReceiveIncomingConnection(client_.get())); auto channel_pair = SetupConnection(Medium::BLUETOOTH); ByteArray serialized_frame = parser::ForConnectionRequestConnections( {}, { @@ -2604,16 +2595,152 @@ TEST_F(BasePcpHandlerTest, IncomingConnectionFailsWithEmptyEndpointId) { // do a dummy write to get to the actual write. channel_pair.first->Write(ByteArray()); channel_pair.first->Write(ByteArray(frame.SerializeAsString())); + absl::string_view expected_log = R"pb( + event_type: CLIENT_SESSION + client_session { + strategy_session { + connection_attempt { + type: INITIAL + direction: INCOMING + medium: BLUETOOTH + attempt_result: RESULT_ERROR + operation_result { + result_category: CATEGORY_CONNECTIVITY_ERROR + result_code: CONNECTIVITY_CHANNEL_IO_ERROR_ON_BT + } + } + } + } + )pb"; + absl::string_view client_session_log = R"pb( + event_type: CLIENT_SESSION + client_session { duration_millis: 0 } + version: "v1.5.0" + )pb"; + EXPECT_CALL(mock_event_logger_, + Log(Matcher( + HasEventType(EventType::STOP_STRATEGY_SESSION)))) + .Times(1); + EXPECT_CALL(mock_event_logger_, + Log(Matcher( + HasEventType(EventType::STOP_CLIENT_SESSION)))) + .Times(3); + EXPECT_CALL(mock_event_logger_, + Log(Matcher( + HasEventType(EventType::START_CLIENT_SESSION)))) + .Times(3); + EXPECT_CALL( + mock_event_logger_, + Log(Matcher(EqualsProto(client_session_log)))) + .Times(2); + EXPECT_CALL(mock_event_logger_, Log(Matcher( + Partially(EqualsProto(expected_log))))); + EXPECT_EQ(pcp_handler - .OnIncomingConnection(&client, ByteArray("remote endpoint"), - std::move(channel_pair.second), - Medium::BLUETOOTH, - NearbyDevice::Type::kConnectionsDevice) + .OnIncomingConnection( + client_.get(), ByteArray("remote endpoint"), + std::move(channel_pair.second), Medium::BLUETOOTH, + NearbyDevice::Type::kConnectionsDevice) .value, Exception::Value::kIo); env_.Stop(); } +TEST_F(BasePcpHandlerTest, IncomingConnectionWithNoDataFailsWithoutLogging) { + env_.Start({.use_simulated_clock = true}); + // Recreate ClientProxy so that AnalyticRecorder uses simulated clock. + client_ = std::make_unique(&mock_event_logger_); + Mediums m; + EndpointChannelManager ecm; + EndpointManager em(&ecm); + BwuManager bwu(m, em, ecm, {}, {}); + MockPcpHandler pcp_handler(&m, &em, &ecm, &bwu); + v3::ConnectionListeningOptions options = { + .strategy = Strategy::kP2pCluster, + .enable_ble_listening = true, + .enable_bluetooth_listening = true, + .enable_wlan_listening = true, + .listening_endpoint_type = NearbyDevice::Type::kConnectionsDevice}; + EXPECT_CALL(pcp_handler, StartListeningForIncomingConnectionsImpl) + .WillOnce(Return( + MockPcpHandler::StartOperationResult{.status = {Status::kSuccess}})); + EXPECT_CALL(pcp_handler, CanReceiveIncomingConnection) + .WillRepeatedly(Return(true)); + EXPECT_TRUE(pcp_handler + .StartListeningForIncomingConnections(client_.get(), + "service", options, {}) + .first.Ok()); + ASSERT_TRUE(client_->IsListeningForIncomingConnections()); + ASSERT_TRUE(pcp_handler.CanReceiveIncomingConnection(client_.get())); + auto [input_a, output_a] = CreatePipe(); + auto input_channel = std::make_unique( + std::move(input_a), std::move(output_a)); + EXPECT_CALL(*input_channel, Read()) + .WillRepeatedly(Return(ExceptionOr(Exception::kNoData))); + absl::string_view expected_log = R"pb( + event_type: CLIENT_SESSION + client_session { + strategy_session { + connection_attempt { + type: INITIAL + direction: INCOMING + attempt_result: RESULT_ERROR + } + } + } + )pb"; + absl::string_view client_session_log = R"pb( + event_type: CLIENT_SESSION + client_session { duration_millis: 0 } + version: "v1.5.0" + )pb"; + absl::string_view client_session_log2 = R"pb( + event_type: CLIENT_SESSION + client_session { + duration_millis: 0 + strategy_session { + duration_millis: 0 + strategy: UNKNOWN_STRATEGY + role: ADVERTISER + } + } + version: "v1.5.0" + )pb"; + EXPECT_CALL(mock_event_logger_, + Log(Matcher( + HasEventType(EventType::STOP_STRATEGY_SESSION)))) + .Times(1); + EXPECT_CALL(mock_event_logger_, + Log(Matcher( + HasEventType(EventType::STOP_CLIENT_SESSION)))) + .Times(3); + EXPECT_CALL(mock_event_logger_, + Log(Matcher( + HasEventType(EventType::START_CLIENT_SESSION)))) + .Times(3); + EXPECT_CALL( + mock_event_logger_, + Log(Matcher(EqualsProto(client_session_log)))) + .Times(2); + EXPECT_CALL( + mock_event_logger_, + Log(Matcher(EqualsProto(client_session_log2)))); + EXPECT_CALL( + mock_event_logger_, + Log(Matcher(Partially(EqualsProto(expected_log))))) + .Times(0); + + EXPECT_EQ( + pcp_handler + .OnIncomingConnection(client_.get(), ByteArray("remote endpoint"), + std::move(input_channel), Medium::BLUETOOTH, + NearbyDevice::Type::kConnectionsDevice) + .value, + Exception::Value::kNoData); + client_.reset(); + env_.Stop(); +} + TEST_F(BasePcpHandlerTest, TestNeedsToTurnOffAdvertisingMedium) { Mediums m; EndpointChannelManager ecm; @@ -2660,15 +2787,14 @@ TEST_F(BasePcpHandlerTest, TestUpdateAdvertisingOptionsWorks) { false, // low_power true, // enable_bluetooth_listening }; - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); BwuManager bwu(m, em, ecm, {}, {}); MockPcpHandler pcp_handler(&m, &em, &ecm, &bwu); - StartAdvertisingWithOptions(&client, &pcp_handler, old_options); - EXPECT_TRUE(client.IsAdvertising()); - auto current_client_opts = client.GetAdvertisingOptions(); + StartAdvertisingWithOptions(client_.get(), &pcp_handler, old_options); + EXPECT_TRUE(client_->IsAdvertising()); + auto current_client_opts = client_->GetAdvertisingOptions(); // check custom option parameters EXPECT_EQ(current_client_opts.auto_upgrade_bandwidth, old_options.auto_upgrade_bandwidth); @@ -2677,10 +2803,10 @@ TEST_F(BasePcpHandlerTest, TestUpdateAdvertisingOptionsWorks) { EXPECT_EQ(current_client_opts.low_power, old_options.low_power); EXPECT_EQ(current_client_opts.enable_bluetooth_listening, old_options.enable_bluetooth_listening); - UpdateAdvertisingOptions(&client, &pcp_handler, new_options, + UpdateAdvertisingOptions(client_.get(), &pcp_handler, new_options, {Status::kSuccess}); - EXPECT_TRUE(client.IsAdvertising()); - current_client_opts = client.GetAdvertisingOptions(); + EXPECT_TRUE(client_->IsAdvertising()); + current_client_opts = client_->GetAdvertisingOptions(); // check new option parameters EXPECT_EQ(current_client_opts.auto_upgrade_bandwidth, new_options.auto_upgrade_bandwidth); @@ -2708,15 +2834,14 @@ TEST_F(BasePcpHandlerTest, TestUpdateAdvertisingOptionsFailsWithBadStatus) { false, // low_power true, // enable_bluetooth_listening }; - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); BwuManager bwu(m, em, ecm, {}, {}); MockPcpHandler pcp_handler(&m, &em, &ecm, &bwu); - StartAdvertisingWithOptions(&client, &pcp_handler, old_options); - EXPECT_TRUE(client.IsAdvertising()); - auto current_client_opts = client.GetAdvertisingOptions(); + StartAdvertisingWithOptions(client_.get(), &pcp_handler, old_options); + EXPECT_TRUE(client_->IsAdvertising()); + auto current_client_opts = client_->GetAdvertisingOptions(); // check custom option parameters EXPECT_EQ(current_client_opts.auto_upgrade_bandwidth, old_options.auto_upgrade_bandwidth); @@ -2725,10 +2850,10 @@ TEST_F(BasePcpHandlerTest, TestUpdateAdvertisingOptionsFailsWithBadStatus) { EXPECT_EQ(current_client_opts.low_power, old_options.low_power); EXPECT_EQ(current_client_opts.enable_bluetooth_listening, old_options.enable_bluetooth_listening); - UpdateAdvertisingOptions(&client, &pcp_handler, new_options, + UpdateAdvertisingOptions(client_.get(), &pcp_handler, new_options, {Status::kBleError}); - EXPECT_TRUE(client.IsAdvertising()); - current_client_opts = client.GetAdvertisingOptions(); + EXPECT_TRUE(client_->IsAdvertising()); + current_client_opts = client_->GetAdvertisingOptions(); // check new option parameters EXPECT_EQ(current_client_opts.auto_upgrade_bandwidth, old_options.auto_upgrade_bandwidth); @@ -2785,15 +2910,14 @@ TEST_F(BasePcpHandlerTest, TestUpdateDiscoveryOptionsWorks) { "", // fast_advertisement_service_uuid true, // low_power }; - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); BwuManager bwu(m, em, ecm, {}, {}); MockPcpHandler pcp_handler(&m, &em, &ecm, &bwu); - StartDiscoveryWithOptions(&client, &pcp_handler, old_options); - EXPECT_TRUE(client.IsDiscovering()); - auto current_client_opts = client.GetDiscoveryOptions(); + StartDiscoveryWithOptions(client_.get(), &pcp_handler, old_options); + EXPECT_TRUE(client_->IsDiscovering()); + auto current_client_opts = client_->GetDiscoveryOptions(); // check custom option parameters EXPECT_EQ(current_client_opts.auto_upgrade_bandwidth, old_options.auto_upgrade_bandwidth); @@ -2804,10 +2928,10 @@ TEST_F(BasePcpHandlerTest, TestUpdateDiscoveryOptionsWorks) { old_options.is_out_of_band_connection); EXPECT_EQ(current_client_opts.fast_advertisement_service_uuid, old_options.fast_advertisement_service_uuid); - UpdateDiscoveryOptions(&client, &pcp_handler, new_options, + UpdateDiscoveryOptions(client_.get(), &pcp_handler, new_options, {Status::kSuccess}); - EXPECT_TRUE(client.IsDiscovering()); - current_client_opts = client.GetDiscoveryOptions(); + EXPECT_TRUE(client_->IsDiscovering()); + current_client_opts = client_->GetDiscoveryOptions(); // check new option parameters EXPECT_EQ(current_client_opts.auto_upgrade_bandwidth, new_options.auto_upgrade_bandwidth); @@ -2839,15 +2963,14 @@ TEST_F(BasePcpHandlerTest, TestUpdateDiscoveryOptionsFailsWithBadStatus) { "", // fast_advertisement_service_uuid true, // low_power }; - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); BwuManager bwu(m, em, ecm, {}, {}); MockPcpHandler pcp_handler(&m, &em, &ecm, &bwu); - StartDiscoveryWithOptions(&client, &pcp_handler, old_options); - EXPECT_TRUE(client.IsDiscovering()); - auto current_client_opts = client.GetDiscoveryOptions(); + StartDiscoveryWithOptions(client_.get(), &pcp_handler, old_options); + EXPECT_TRUE(client_->IsDiscovering()); + auto current_client_opts = client_->GetDiscoveryOptions(); // check custom option parameters EXPECT_EQ(current_client_opts.auto_upgrade_bandwidth, old_options.auto_upgrade_bandwidth); @@ -2858,10 +2981,10 @@ TEST_F(BasePcpHandlerTest, TestUpdateDiscoveryOptionsFailsWithBadStatus) { old_options.is_out_of_band_connection); EXPECT_EQ(current_client_opts.fast_advertisement_service_uuid, old_options.fast_advertisement_service_uuid); - UpdateDiscoveryOptions(&client, &pcp_handler, new_options, + UpdateDiscoveryOptions(client_.get(), &pcp_handler, new_options, {Status::kBleError}); - EXPECT_TRUE(client.IsDiscovering()); - current_client_opts = client.GetDiscoveryOptions(); + EXPECT_TRUE(client_->IsDiscovering()); + current_client_opts = client_->GetDiscoveryOptions(); // check new option parameters EXPECT_EQ(current_client_opts.auto_upgrade_bandwidth, old_options.auto_upgrade_bandwidth); @@ -2891,25 +3014,24 @@ TEST_F(BasePcpHandlerTest, TestForceUpdateEndpointIdAdvertisingOption) { .enable_bluetooth_listening = false, .force_new_endpoint_id = true, }; - ClientProxy client; Mediums m; EndpointChannelManager ecm; EndpointManager em(&ecm); BwuManager bwu(m, em, ecm, {}, {}); - std::string old_endpoint_id = client.GetLocalEndpointId(); + std::string old_endpoint_id = client_->GetLocalEndpointId(); MockPcpHandler pcp_handler(&m, &em, &ecm, &bwu); - StartAdvertisingWithOptions(&client, &pcp_handler, + StartAdvertisingWithOptions(client_.get(), &pcp_handler, use_old_endpoint_id_options); - EXPECT_TRUE(client.IsAdvertising()); - EXPECT_EQ(client.GetLocalEndpointId(), old_endpoint_id); + EXPECT_TRUE(client_->IsAdvertising()); + EXPECT_EQ(client_->GetLocalEndpointId(), old_endpoint_id); - pcp_handler.StopAdvertising(&client); - EXPECT_FALSE(client.IsAdvertising()); + pcp_handler.StopAdvertising(client_.get()); + EXPECT_FALSE(client_->IsAdvertising()); - StartAdvertisingWithOptions(&client, &pcp_handler, + StartAdvertisingWithOptions(client_.get(), &pcp_handler, use_new_endpoint_id_options); - EXPECT_TRUE(client.IsAdvertising()); - EXPECT_NE(client.GetLocalEndpointId(), old_endpoint_id); + EXPECT_TRUE(client_->IsAdvertising()); + EXPECT_NE(client_->GetLocalEndpointId(), old_endpoint_id); env_.Stop(); } diff --git a/connections/implementation/endpoint_manager.cc b/connections/implementation/endpoint_manager.cc index 7712e269..fec20138 100644 --- a/connections/implementation/endpoint_manager.cc +++ b/connections/implementation/endpoint_manager.cc @@ -239,6 +239,10 @@ ExceptionOr EndpointManager::HandleData( ExceptionOr bytes = endpoint_channel->Read(packet_meta_data); if (!bytes.ok()) { LOG(INFO) << "Stop reading on read-time exception: " << bytes.exception(); + // Treat kNoData as kIo. + if (bytes.exception() == Exception::kNoData) { + return ExceptionOr(Exception::kIo); + } return ExceptionOr(bytes.exception()); } ExceptionOr wrapped_frame = parser::FromBytes(bytes.result()); diff --git a/internal/platform/exception.h b/internal/platform/exception.h index d5abd4cd..08345971 100644 --- a/internal/platform/exception.h +++ b/internal/platform/exception.h @@ -32,6 +32,7 @@ struct Exception { kTimeout = 5, // Operation did not finish within specified time. kIllegalCharacters = 6, // File name or parent path contained // illegal chars + kNoData = 7, // No data available. }; bool Ok() const { return value == kSuccess; } explicit operator bool() const { return Ok(); } diff --git a/internal/platform/implementation/windows/nearby_client_socket.cc b/internal/platform/implementation/windows/nearby_client_socket.cc index cf7ac9cf..c3eee84a 100644 --- a/internal/platform/implementation/windows/nearby_client_socket.cc +++ b/internal/platform/implementation/windows/nearby_client_socket.cc @@ -182,9 +182,11 @@ ExceptionOr NearbyClientSocket::Read(std::int64_t size) { // Successfully read some bytes. total_bytes_read += bytes_read; } else if (bytes_read == 0) { - // The peer has performed a graceful shutdown. - LOG(INFO) << "Socket closed gracefully by peer before all data was read."; - return {Exception::kIo}; + // The peer has performed a graceful shutdown. Return any data already + // read. + buffer.resize(total_bytes_read); + LOG(INFO) << "Socket closed by peer, data size: " << buffer.size(); + return ExceptionOr(ByteArray(std::move(buffer))); } else { // bytes_read == SOCKET_ERROR if (WSAGetLastError() == WSAEINTR) { VLOG(1) << "Interrupted while reading from socket."; diff --git a/internal/platform/implementation/windows/socket_address.cc b/internal/platform/implementation/windows/socket_address.cc index 2f1d5de2..cca05264 100644 --- a/internal/platform/implementation/windows/socket_address.cc +++ b/internal/platform/implementation/windows/socket_address.cc @@ -210,14 +210,13 @@ ServiceAddress SocketAddress::ToServiceAddress(uint16_t port) const { ipv4_address()->sin_addr.S_un.S_un_b.s_b4}, .port = port, }; - } else { - return ServiceAddress{ - .address = - std::vector(ipv6_address()->sin6_addr.u.Byte, - ipv6_address()->sin6_addr.u.Byte + 16), - .port = port, - }; } + return ServiceAddress{ + .address = + std::vector(ipv6_address()->sin6_addr.u.Byte, + ipv6_address()->sin6_addr.u.Byte + 16), + .port = port, + }; } diff --git a/internal/platform/input_stream.cc b/internal/platform/input_stream.cc index 0d18cfa4..73f91c8d 100644 --- a/internal/platform/input_stream.cc +++ b/internal/platform/input_stream.cc @@ -16,7 +16,6 @@ #include #include -#include #include #include "internal/platform/byte_array.h" @@ -56,7 +55,7 @@ ExceptionOr InputStream::ReadExactly(std::size_t size) { const ByteArray& result = read_bytes.result(); if (result.Empty()) { - return ExceptionOr(Exception::kIo); + return ExceptionOr(Exception::kNoData); } if (current_pos == 0) { if (result.size() == size) { diff --git a/internal/test/BUILD b/internal/test/BUILD index adc83216..da7d9bcf 100644 --- a/internal/test/BUILD +++ b/internal/test/BUILD @@ -73,6 +73,7 @@ cc_library( "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/functional:any_invocable", + "@com_google_absl//absl/log", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings",