mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Format all the files in CL786733783
PiperOrigin-RevId: 786873870
This commit is contained in:
@@ -93,8 +93,7 @@ TEST_P(AwdlTest, CanConnect) {
|
||||
.service_discovered_cb =
|
||||
[&discovered_latch, &discovered_service_info](
|
||||
NsdServiceInfo service_info, const std::string& service_id) {
|
||||
LOG(INFO)
|
||||
<< "Discovered service_info=" << &service_info;
|
||||
LOG(INFO) << "Discovered service_info=" << &service_info;
|
||||
discovered_service_info = service_info;
|
||||
discovered_latch.CountDown();
|
||||
},
|
||||
@@ -146,8 +145,7 @@ TEST_P(AwdlTest, CanCancelConnect) {
|
||||
.service_discovered_cb =
|
||||
[&discovered_latch, &discovered_service_info](
|
||||
NsdServiceInfo service_info, const std::string& service_id) {
|
||||
LOG(INFO)
|
||||
<< "Discovered service_info=" << &service_info;
|
||||
LOG(INFO) << "Discovered service_info=" << &service_info;
|
||||
discovered_service_info = service_info;
|
||||
discovered_latch.CountDown();
|
||||
},
|
||||
|
||||
@@ -72,17 +72,15 @@ bool Ble::StartAdvertising(const std::string& service_id,
|
||||
}
|
||||
|
||||
if (advertisement_bytes.size() > kMaxAdvertisementLength) {
|
||||
LOG(INFO)
|
||||
<< "Refusing to start BLE advertising because the advertisement "
|
||||
"was too long. Expected at most "
|
||||
<< kMaxAdvertisementLength << " bytes but received "
|
||||
<< advertisement_bytes.size();
|
||||
LOG(INFO) << "Refusing to start BLE advertising because the advertisement "
|
||||
"was too long. Expected at most "
|
||||
<< kMaxAdvertisementLength << " bytes but received "
|
||||
<< advertisement_bytes.size();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsAdvertisingLocked(service_id)) {
|
||||
LOG(INFO)
|
||||
<< "Failed to BLE advertise because we're already advertising.";
|
||||
LOG(INFO) << "Failed to BLE advertise because we're already advertising.";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -98,10 +96,10 @@ bool Ble::StartAdvertising(const std::string& service_id,
|
||||
}
|
||||
|
||||
LOG(INFO) << "Turning on BLE advertising (advertisement size="
|
||||
<< advertisement_bytes.size() << ")"
|
||||
<< ", service id=" << service_id
|
||||
<< ", fast advertisement service uuid="
|
||||
<< absl::BytesToHexString(fast_advertisement_service_uuid);
|
||||
<< advertisement_bytes.size() << ")"
|
||||
<< ", service id=" << service_id
|
||||
<< ", fast advertisement service uuid="
|
||||
<< absl::BytesToHexString(fast_advertisement_service_uuid);
|
||||
|
||||
// Wrap the connections advertisement to the medium advertisement.
|
||||
const bool fast_advertisement = !fast_advertisement_service_uuid.empty();
|
||||
@@ -114,18 +112,17 @@ bool Ble::StartAdvertising(const std::string& service_id,
|
||||
GenerateDeviceToken()}};
|
||||
if (medium_advertisement_bytes.Empty()) {
|
||||
LOG(INFO) << "Failed to BLE advertise because we could not "
|
||||
"create a medium advertisement.";
|
||||
"create a medium advertisement.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!medium_.StartAdvertising(service_id, medium_advertisement_bytes,
|
||||
fast_advertisement_service_uuid)) {
|
||||
LOG(ERROR)
|
||||
<< "Failed to turn on BLE advertising with advertisement bytes="
|
||||
<< absl::BytesToHexString(advertisement_bytes.data())
|
||||
<< ", size=" << advertisement_bytes.size()
|
||||
<< ", fast advertisement service uuid="
|
||||
<< fast_advertisement_service_uuid;
|
||||
LOG(ERROR) << "Failed to turn on BLE advertising with advertisement bytes="
|
||||
<< absl::BytesToHexString(advertisement_bytes.data())
|
||||
<< ", size=" << advertisement_bytes.size()
|
||||
<< ", fast advertisement service uuid="
|
||||
<< fast_advertisement_service_uuid;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -141,8 +138,7 @@ bool Ble::StopAdvertising(const std::string& service_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
LOG(INFO) << "Turned off BLE advertising with service id="
|
||||
<< service_id;
|
||||
LOG(INFO) << "Turned off BLE advertising with service id=" << service_id;
|
||||
bool ret = medium_.StopAdvertising(service_id);
|
||||
// Reset our bundle of advertising state to mark that we're no longer
|
||||
// advertising.
|
||||
@@ -154,7 +150,7 @@ bool Ble::StartLegacyAdvertising(
|
||||
const std::string& input_service_id, const std::string& local_endpoint_id,
|
||||
const std::string& fast_advertisement_service_uuid) {
|
||||
LOG(INFO) << "StartLegacyAdvertising: " << input_service_id
|
||||
<< ", local_endpoint_id: " << local_endpoint_id;
|
||||
<< ", local_endpoint_id: " << local_endpoint_id;
|
||||
MutexLock lock(&mutex_);
|
||||
std::string service_id = input_service_id + "-Legacy";
|
||||
|
||||
@@ -166,13 +162,12 @@ bool Ble::StartLegacyAdvertising(
|
||||
|
||||
if (!radio_.IsEnabled()) {
|
||||
LOG(INFO) << "Can't start BLE legacy advertising because Bluetooth "
|
||||
"was never turned on";
|
||||
"was never turned on";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsAvailableLocked()) {
|
||||
LOG(INFO)
|
||||
<< "Can't turn on BLE legacy advertising. BLE is not available.";
|
||||
LOG(INFO) << "Can't turn on BLE legacy advertising. BLE is not available.";
|
||||
return false;
|
||||
}
|
||||
// TODO(hais) improve working dummy set to feed proper hash value.
|
||||
@@ -182,20 +177,19 @@ bool Ble::StartLegacyAdvertising(
|
||||
ByteArray encoded_bytes{encoded_legacy_char_array};
|
||||
|
||||
LOG(INFO) << "Turning on BLE advertising (advertisement size="
|
||||
<< encoded_bytes.size()
|
||||
<< "): " << absl::BytesToHexString(encoded_bytes.data())
|
||||
<< ", service id=" << service_id
|
||||
<< ", fast advertisement service uuid="
|
||||
<< fast_advertisement_service_uuid;
|
||||
<< encoded_bytes.size()
|
||||
<< "): " << absl::BytesToHexString(encoded_bytes.data())
|
||||
<< ", service id=" << service_id
|
||||
<< ", fast advertisement service uuid="
|
||||
<< fast_advertisement_service_uuid;
|
||||
|
||||
if (!medium_.StartAdvertising(service_id, encoded_bytes,
|
||||
fast_advertisement_service_uuid)) {
|
||||
LOG(ERROR)
|
||||
<< "Failed to turn on BLE advertising with advertisement bytes="
|
||||
<< absl::BytesToHexString(encoded_bytes.data())
|
||||
<< ", size=" << encoded_bytes.size()
|
||||
<< ", fast advertisement service uuid="
|
||||
<< fast_advertisement_service_uuid;
|
||||
LOG(ERROR) << "Failed to turn on BLE advertising with advertisement bytes="
|
||||
<< absl::BytesToHexString(encoded_bytes.data())
|
||||
<< ", size=" << encoded_bytes.size()
|
||||
<< ", fast advertisement service uuid="
|
||||
<< fast_advertisement_service_uuid;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -209,13 +203,12 @@ bool Ble::StopLegacyAdvertising(const std::string& input_service_id) {
|
||||
|
||||
std::string service_id = input_service_id + "-Legacy";
|
||||
if (!IsAdvertisingLocked(service_id)) {
|
||||
LOG(INFO)
|
||||
<< "Can't turn off BLE legacy advertising; it is already off";
|
||||
LOG(INFO) << "Can't turn off BLE legacy advertising; it is already off";
|
||||
return false;
|
||||
}
|
||||
|
||||
LOG(INFO) << "Turned off BLE legacy advertising with service id="
|
||||
<< service_id;
|
||||
<< service_id;
|
||||
bool ret = medium_.StopAdvertising(service_id);
|
||||
// Reset our bundle of advertising state to mark that we're no longer
|
||||
// advertising.
|
||||
@@ -241,14 +234,13 @@ bool Ble::StartScanning(const std::string& service_id,
|
||||
discovered_peripheral_callback_ = std::move(callback);
|
||||
|
||||
if (service_id.empty()) {
|
||||
LOG(INFO)
|
||||
<< "Refusing to start BLE scanning with empty service id.";
|
||||
LOG(INFO) << "Refusing to start BLE scanning with empty service id.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsScanningLocked(service_id)) {
|
||||
LOG(INFO) << "Refusing to start scan of BLE peripherals because "
|
||||
"another scanning is already in-progress.";
|
||||
"another scanning is already in-progress.";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -259,8 +251,7 @@ bool Ble::StartScanning(const std::string& service_id,
|
||||
}
|
||||
|
||||
if (!IsAvailableLocked()) {
|
||||
LOG(INFO)
|
||||
<< "Can't scan BLE peripherals because BLE isn't available.";
|
||||
LOG(INFO) << "Can't scan BLE peripherals because BLE isn't available.";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -275,7 +266,7 @@ bool Ble::StartScanning(const std::string& service_id,
|
||||
// Don't bother trying to parse zero byte advertisements.
|
||||
if (medium_advertisement_bytes.size() == 0) {
|
||||
LOG(INFO) << "Skipping zero byte advertisement "
|
||||
<< "with service_id: " << service_id;
|
||||
<< "with service_id: " << service_id;
|
||||
return;
|
||||
}
|
||||
// Unwrap connection BleAdvertisement from medium
|
||||
@@ -308,7 +299,7 @@ bool Ble::StopScanning(const std::string& service_id) {
|
||||
|
||||
if (!IsScanningLocked(service_id)) {
|
||||
LOG(INFO) << "Can't turn off BLE scanning because we never "
|
||||
"started scanning.";
|
||||
"started scanning.";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -346,20 +337,20 @@ bool Ble::StartAcceptingConnections(const std::string& service_id,
|
||||
}
|
||||
|
||||
if (!radio_.IsEnabled()) {
|
||||
LOG(INFO) << "Can't start accepting BLE connections for "
|
||||
<< service_id << " because Bluetooth isn't enabled.";
|
||||
LOG(INFO) << "Can't start accepting BLE connections for " << service_id
|
||||
<< " because Bluetooth isn't enabled.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsAvailableLocked()) {
|
||||
LOG(INFO) << "Can't start accepting BLE connections for "
|
||||
<< service_id << " because BLE isn't available.";
|
||||
LOG(INFO) << "Can't start accepting BLE connections for " << service_id
|
||||
<< " because BLE isn't available.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!medium_.StartAcceptingConnections(service_id, std::move(callback))) {
|
||||
LOG(INFO) << "Failed to accept connections callback for "
|
||||
<< service_id << " .";
|
||||
LOG(INFO) << "Failed to accept connections callback for " << service_id
|
||||
<< " .";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -408,13 +399,13 @@ ErrorOr<BleSocket> Ble::Connect(BlePeripheral& peripheral,
|
||||
|
||||
if (!radio_.IsEnabled()) {
|
||||
LOG(INFO) << "Can't create client BLE socket to " << &peripheral
|
||||
<< " because Bluetooth isn't enabled.";
|
||||
<< " because Bluetooth isn't enabled.";
|
||||
return {Error(OperationResultCode::MISCELLEANEOUS_BLE_SYSTEM_SERVICE_NULL)};
|
||||
}
|
||||
|
||||
if (!IsAvailableLocked()) {
|
||||
LOG(INFO) << "Can't create client BLE socket [service_id="
|
||||
<< service_id << "]; BLE isn't available.";
|
||||
LOG(INFO) << "Can't create client BLE socket [service_id=" << service_id
|
||||
<< "]; BLE isn't available.";
|
||||
return {Error(OperationResultCode::MEDIUM_UNAVAILABLE_BLE_NOT_AVAILABLE)};
|
||||
}
|
||||
|
||||
@@ -426,8 +417,7 @@ ErrorOr<BleSocket> Ble::Connect(BlePeripheral& peripheral,
|
||||
|
||||
socket = medium_.Connect(peripheral, service_id, cancellation_flag);
|
||||
if (!socket.IsValid()) {
|
||||
LOG(INFO) << "Failed to Connect via BLE [service=" << service_id
|
||||
<< "]";
|
||||
LOG(INFO) << "Failed to Connect via BLE [service=" << service_id << "]";
|
||||
}
|
||||
|
||||
return socket;
|
||||
|
||||
@@ -88,10 +88,9 @@ TEST_P(BleTest, CanStartAcceptingConnectionsAndConnect) {
|
||||
BlePeripheral& peripheral, const std::string& service_id,
|
||||
const ByteArray& advertisement_bytes,
|
||||
bool fast_advertisement) {
|
||||
LOG(INFO)
|
||||
<< "Discovered peripheral=" << peripheral.GetName()
|
||||
<< ", impl=" << &peripheral.GetImpl()
|
||||
<< ", fast advertisement=" << fast_advertisement;
|
||||
LOG(INFO) << "Discovered peripheral=" << peripheral.GetName()
|
||||
<< ", impl=" << &peripheral.GetImpl()
|
||||
<< ", fast advertisement=" << fast_advertisement;
|
||||
atomic_discovered_peripheral.store(peripheral);
|
||||
found_latch.CountDown();
|
||||
},
|
||||
@@ -141,10 +140,9 @@ TEST_P(BleTest, CanCancelConnect) {
|
||||
BlePeripheral& peripheral, const std::string& service_id,
|
||||
const ByteArray& advertisement_bytes,
|
||||
bool fast_advertisement) {
|
||||
LOG(INFO)
|
||||
<< "Discovered peripheral=" << peripheral.GetName()
|
||||
<< ", impl=" << &peripheral.GetImpl()
|
||||
<< ", fast advertisement=" << fast_advertisement;
|
||||
LOG(INFO) << "Discovered peripheral=" << peripheral.GetName()
|
||||
<< ", impl=" << &peripheral.GetImpl()
|
||||
<< ", fast advertisement=" << fast_advertisement;
|
||||
atomic_discovered_peripheral.store(peripheral);
|
||||
found_latch.CountDown();
|
||||
},
|
||||
|
||||
@@ -69,7 +69,7 @@ BleAdvertisementHeader::BleAdvertisementHeader(
|
||||
advertisement_header_bytes = ble_advertisement_header_bytes;
|
||||
} else {
|
||||
VLOG(1) << "Cannot deserialize BLEAdvertisementHeader. "
|
||||
"Invalid advertising data.";
|
||||
"Invalid advertising data.";
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -39,8 +39,8 @@ BloomFilter::BloomFilter(std::unique_ptr<BitSet> bit_set,
|
||||
// If the size is not matched, fall out.
|
||||
if (bytes.size() * 8 != bit_set_->Size()) {
|
||||
LOG(INFO) << "Cannot construct from bytes since the size is not "
|
||||
"matched. bytes.size(x8) = "
|
||||
<< bytes.size() << ", bit_set.size=" << bit_set_->Size();
|
||||
"matched. bytes.size(x8) = "
|
||||
<< bytes.size() << ", bit_set.size=" << bit_set_->Size();
|
||||
return;
|
||||
}
|
||||
for (size_t byte_index = 0; byte_index < bytes.size(); byte_index++) {
|
||||
|
||||
@@ -64,9 +64,9 @@ InstantOnLostAdvertisement::CreateFromHashes(
|
||||
std::string InstantOnLostAdvertisement::ToBytes() const {
|
||||
if (hashes_.empty() || hashes_.size() > kMaxHashCount) {
|
||||
LOG(ERROR) << __func__
|
||||
<< ": Failed to convert hashes due to hash "
|
||||
"size is not valid, size = "
|
||||
<< hashes_.size();
|
||||
<< ": Failed to convert hashes due to hash "
|
||||
"size is not valid, size = "
|
||||
<< hashes_.size();
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -80,9 +80,9 @@ std::string InstantOnLostAdvertisement::ToBytes() const {
|
||||
for (const auto& hash : hashes_) {
|
||||
if (hash.length() != kAdvertisementHashLength) {
|
||||
LOG(ERROR) << __func__
|
||||
<< ": Failed to convert hashes to advertisement due "
|
||||
"to invalid hash : "
|
||||
<< absl::BytesToHexString(hash);
|
||||
<< ": Failed to convert hashes to advertisement due "
|
||||
"to invalid hash : "
|
||||
<< absl::BytesToHexString(hash);
|
||||
return "";
|
||||
}
|
||||
absl::StrAppend(&result, hash);
|
||||
|
||||
@@ -112,9 +112,8 @@ TEST_P(BleV2Test, CanConnect) {
|
||||
const ByteArray& advertisement_bytes,
|
||||
bool fast_advertisement) {
|
||||
discovered_peripheral = peripheral;
|
||||
LOG(INFO)
|
||||
<< "Discovered peripheral, fast advertisement="
|
||||
<< fast_advertisement;
|
||||
LOG(INFO) << "Discovered peripheral, fast advertisement="
|
||||
<< fast_advertisement;
|
||||
discovered_latch.CountDown();
|
||||
},
|
||||
});
|
||||
@@ -172,9 +171,8 @@ TEST_P(BleV2Test, CanCancelConnect) {
|
||||
const ByteArray& advertisement_bytes,
|
||||
bool fast_advertisement) {
|
||||
discovered_peripheral = peripheral;
|
||||
LOG(INFO)
|
||||
<< "Discovered peripheral, fast advertisement="
|
||||
<< fast_advertisement;
|
||||
LOG(INFO) << "Discovered peripheral, fast advertisement="
|
||||
<< fast_advertisement;
|
||||
discovered_latch.CountDown();
|
||||
},
|
||||
});
|
||||
|
||||
@@ -269,7 +269,7 @@ TEST_P(BluetoothClassicTest, CanConnect) {
|
||||
[&latch, &discovered_device](BluetoothDevice& device) {
|
||||
discovered_device = device;
|
||||
LOG(INFO) << "Discovered device=" << device.GetName()
|
||||
<< ", impl=" << &device.GetImpl();
|
||||
<< ", impl=" << &device.GetImpl();
|
||||
latch.CountDown();
|
||||
},
|
||||
}));
|
||||
@@ -319,7 +319,7 @@ TEST_P(BluetoothClassicTest, CanCancelBeforeConnect) {
|
||||
.device_discovered_cb =
|
||||
[&latch, &discovered_device](BluetoothDevice& device) {
|
||||
LOG(INFO) << "Discovered device=" << device.GetName()
|
||||
<< ", impl=" << &device.GetImpl();
|
||||
<< ", impl=" << &device.GetImpl();
|
||||
discovered_device = device;
|
||||
latch.CountDown();
|
||||
},
|
||||
@@ -387,7 +387,7 @@ TEST_P(BluetoothClassicTest, CanCancelDuringConnect) {
|
||||
[&latch, &discovered_device](BluetoothDevice& device) {
|
||||
discovered_device = device;
|
||||
LOG(INFO) << "Discovered device=" << device.GetName()
|
||||
<< ", impl=" << &device.GetImpl();
|
||||
<< ", impl=" << &device.GetImpl();
|
||||
latch.CountDown();
|
||||
},
|
||||
}));
|
||||
@@ -453,7 +453,7 @@ TEST_P(BluetoothClassicTest, CanCancelDuringConnect_MultipleEndpoints) {
|
||||
[&latch, &discovered_device](BluetoothDevice& device) {
|
||||
discovered_device = device;
|
||||
LOG(INFO) << "Discovered device=" << device.GetName()
|
||||
<< ", impl=" << &device.GetImpl();
|
||||
<< ", impl=" << &device.GetImpl();
|
||||
latch.CountDown();
|
||||
},
|
||||
}));
|
||||
@@ -599,21 +599,21 @@ TEST_F(BluetoothClassicTest, CanDiscoverDeviceChanges) {
|
||||
[&discovered_latch, &discovered_device](BluetoothDevice& device) {
|
||||
discovered_device = device;
|
||||
LOG(INFO) << "Discovered device=" << device.GetName()
|
||||
<< ", impl=" << &device.GetImpl();
|
||||
<< ", impl=" << &device.GetImpl();
|
||||
discovered_latch.CountDown();
|
||||
},
|
||||
.device_name_changed_cb =
|
||||
[&rename_latch, &discovered_device](BluetoothDevice& device) {
|
||||
discovered_device = device;
|
||||
LOG(INFO) << "Rename device=" << device.GetName()
|
||||
<< ", impl=" << &device.GetImpl();
|
||||
<< ", impl=" << &device.GetImpl();
|
||||
rename_latch.CountDown();
|
||||
},
|
||||
.device_lost_cb =
|
||||
[&lost_latch, &discovered_device](BluetoothDevice& device) {
|
||||
discovered_device = device;
|
||||
LOG(INFO) << "Lost device=" << device.GetName()
|
||||
<< ", impl=" << &device.GetImpl();
|
||||
<< ", impl=" << &device.GetImpl();
|
||||
lost_latch.CountDown();
|
||||
},
|
||||
}));
|
||||
@@ -645,7 +645,7 @@ TEST_F(BluetoothClassicTest, CanStartAcceptingConnections) {
|
||||
[&latch, &discovered_device](BluetoothDevice& device) {
|
||||
discovered_device = device;
|
||||
LOG(INFO) << "Discovered device=" << device.GetName()
|
||||
<< ",impl=" << &device.GetImpl();
|
||||
<< ",impl=" << &device.GetImpl();
|
||||
latch.CountDown();
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -23,15 +23,14 @@
|
||||
#include "internal/platform/exception.h"
|
||||
#include "internal/platform/logging.h"
|
||||
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
namespace mediums {
|
||||
namespace multiplex {
|
||||
|
||||
using ::location::nearby::mediums::MultiplexFrame;
|
||||
using ::location::nearby::mediums::MultiplexControlFrame;
|
||||
using ::location::nearby::mediums::ConnectionResponseFrame;
|
||||
using ::location::nearby::mediums::MultiplexControlFrame;
|
||||
using ::location::nearby::mediums::MultiplexFrame;
|
||||
|
||||
ByteArray GenerateServiceIdHash(const std::string& service_id) {
|
||||
return Utils::Sha256Hash(service_id, kServiceIdHashLength);
|
||||
@@ -115,8 +114,7 @@ ByteArray ForDisconnection(const std::string& service_id,
|
||||
header->set_service_id_hash_salt(service_id_hash_salt);
|
||||
|
||||
auto* control_frame = frame.mutable_control_frame();
|
||||
control_frame->set_control_frame_type(
|
||||
MultiplexControlFrame::DISCONNECTION);
|
||||
control_frame->set_control_frame_type(MultiplexControlFrame::DISCONNECTION);
|
||||
|
||||
return ToBytes(std::move(frame));
|
||||
}
|
||||
@@ -140,7 +138,7 @@ ByteArray ForData(const std::string& service_id,
|
||||
return ToBytes(std::move(frame));
|
||||
}
|
||||
|
||||
ExceptionOr<MultiplexFrame> FromBytes(const ByteArray& multiplex_frame_bytes){
|
||||
ExceptionOr<MultiplexFrame> FromBytes(const ByteArray& multiplex_frame_bytes) {
|
||||
MultiplexFrame frame;
|
||||
|
||||
if (frame.ParseFromString(std::string(multiplex_frame_bytes))) {
|
||||
@@ -173,24 +171,24 @@ bool IsValid(const MultiplexFrame& frame) {
|
||||
}
|
||||
|
||||
bool IsValidControlFrame(const MultiplexFrame& frame) {
|
||||
if (!frame.has_control_frame()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (frame.control_frame().control_frame_type()) {
|
||||
case MultiplexControlFrame::CONNECTION_REQUEST:
|
||||
case MultiplexControlFrame::CONNECTION_RESPONSE:
|
||||
case MultiplexControlFrame::DISCONNECTION:
|
||||
if (frame.header().salted_service_id_hash().size() ==
|
||||
kServiceIdHashLength) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!frame.has_control_frame()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (frame.control_frame().control_frame_type()) {
|
||||
case MultiplexControlFrame::CONNECTION_REQUEST:
|
||||
case MultiplexControlFrame::CONNECTION_RESPONSE:
|
||||
case MultiplexControlFrame::DISCONNECTION:
|
||||
if (frame.header().salted_service_id_hash().size() ==
|
||||
kServiceIdHashLength) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IsValidDataFrame(const MultiplexFrame& frame) {
|
||||
@@ -204,8 +202,8 @@ bool IsMultiplexFrame(const ByteArray& data) {
|
||||
return false;
|
||||
} else {
|
||||
LOG(INFO) << "Checked data is a multiplex frame. Is Control ? "
|
||||
<< frame.result().has_control_frame() << ", is data ? "
|
||||
<< frame.result().has_data_frame();
|
||||
<< frame.result().has_control_frame() << ", is data ? "
|
||||
<< frame.result().has_data_frame();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,16 +63,14 @@ Exception MultiplexOutputStream::WaitForResult(const std::string& method_name,
|
||||
.mediums_frame_write_timeout_millis);
|
||||
if (!result.ok()) {
|
||||
LOG(INFO) << "Future:[" << method_name
|
||||
<< "] completed with exception:" << result.exception();
|
||||
<< "] completed with exception:" << result.exception();
|
||||
return {Exception::kFailed};
|
||||
}
|
||||
if (result.result()) {
|
||||
LOG(INFO) << "Future:[" << method_name
|
||||
<< "] completed with success.";
|
||||
LOG(INFO) << "Future:[" << method_name << "] completed with success.";
|
||||
return {Exception::kSuccess};
|
||||
}
|
||||
LOG(INFO) << "Future:[" << method_name
|
||||
<< "] completed with failure.";
|
||||
LOG(INFO) << "Future:[" << method_name << "] completed with failure.";
|
||||
return {Exception::kFailed};
|
||||
}
|
||||
|
||||
@@ -111,8 +109,8 @@ bool MultiplexOutputStream::WriteConnectionResponseFrame(
|
||||
bool MultiplexOutputStream::Close(const std::string& service_id) {
|
||||
auto item = virtual_output_streams_.find(service_id);
|
||||
if (item == virtual_output_streams_.end()) {
|
||||
LOG(INFO) << "Don't need to close VirtualOutputStream("
|
||||
<< service_id << ") because it's already gone.";
|
||||
LOG(INFO) << "Don't need to close VirtualOutputStream(" << service_id
|
||||
<< ") because it's already gone.";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -230,8 +228,7 @@ void MultiplexOutputStream::MultiplexWriter::StartWriting() {
|
||||
LOG(INFO) << "Waiting for data_queue_ has data.";
|
||||
Exception wait_succeeded = is_writing_cond_.Wait();
|
||||
if (!wait_succeeded.Ok()) {
|
||||
LOG(WARNING)
|
||||
<< "Failure waiting to wait: " << wait_succeeded.value;
|
||||
LOG(WARNING) << "Failure waiting to wait: " << wait_succeeded.value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -306,9 +303,8 @@ MultiplexOutputStream::VirtualOutputStream::VirtualOutputStream(
|
||||
Exception MultiplexOutputStream::VirtualOutputStream::Write(
|
||||
const ByteArray& data) {
|
||||
if (is_closed_.Get()) {
|
||||
LOG(WARNING)
|
||||
<< "Failed to write data because the VirtualOutputStream for "
|
||||
<< service_id_ << " closed";
|
||||
LOG(WARNING) << "Failed to write data because the VirtualOutputStream for "
|
||||
<< service_id_ << " closed";
|
||||
return {Exception::kIo};
|
||||
}
|
||||
if (multiplex_output_stream_.is_enabled_.Get()) {
|
||||
@@ -327,7 +323,7 @@ Exception MultiplexOutputStream::VirtualOutputStream::Write(
|
||||
if ((service_id_hash_salt_ == kFakeSalt) && !should_pass_salt) {
|
||||
should_pass_salt = true;
|
||||
LOG(INFO) << "service_idHashSalt is still a fake one and "
|
||||
"not changed yet; continue to pass salt.";
|
||||
"not changed yet; continue to pass salt.";
|
||||
}
|
||||
}
|
||||
ByteArray data_frame =
|
||||
|
||||
@@ -75,8 +75,8 @@ class MultiplexOutputStreamTest : public ::testing::Test {
|
||||
};
|
||||
|
||||
TEST_F(MultiplexOutputStreamTest, SendConnectionRequestFrame) {
|
||||
multiplex_output_stream_ = std::make_unique<MultiplexOutputStream>(
|
||||
writer_.get(), enabled_);
|
||||
multiplex_output_stream_ =
|
||||
std::make_unique<MultiplexOutputStream>(writer_.get(), enabled_);
|
||||
EXPECT_TRUE(multiplex_output_stream_->WriteConnectionRequestFrame(
|
||||
std::string(kServiceId_1), std::string(kNoSalt)));
|
||||
|
||||
@@ -94,8 +94,8 @@ TEST_F(MultiplexOutputStreamTest, SendConnectionRequestFrame) {
|
||||
|
||||
TEST_F(MultiplexOutputStreamTest, SendConnectionRequestFrameDisabled) {
|
||||
enabled_.Set(false);
|
||||
multiplex_output_stream_ = std::make_unique<MultiplexOutputStream>(
|
||||
writer_.get(), enabled_);
|
||||
multiplex_output_stream_ =
|
||||
std::make_unique<MultiplexOutputStream>(writer_.get(), enabled_);
|
||||
EXPECT_FALSE(multiplex_output_stream_->WriteConnectionRequestFrame(
|
||||
std::string(kServiceId_1), std::string(kNoSalt)));
|
||||
|
||||
@@ -103,8 +103,8 @@ TEST_F(MultiplexOutputStreamTest, SendConnectionRequestFrameDisabled) {
|
||||
}
|
||||
|
||||
TEST_F(MultiplexOutputStreamTest, SendConnectionResponseFrame) {
|
||||
multiplex_output_stream_ = std::make_unique<MultiplexOutputStream>(
|
||||
writer_.get(), enabled_);
|
||||
multiplex_output_stream_ =
|
||||
std::make_unique<MultiplexOutputStream>(writer_.get(), enabled_);
|
||||
EXPECT_TRUE(multiplex_output_stream_->WriteConnectionResponseFrame(
|
||||
GenerateServiceIdHash(std::string(kServiceId_1)), std::string(kNoSalt),
|
||||
ConnectionResponseFrame::CONNECTION_ACCEPTED));
|
||||
@@ -127,8 +127,8 @@ TEST_F(MultiplexOutputStreamTest, SendConnectionResponseFrame) {
|
||||
|
||||
TEST_F(MultiplexOutputStreamTest, SendConnectionResponseFrameDisabled) {
|
||||
enabled_.Set(false);
|
||||
multiplex_output_stream_ = std::make_unique<MultiplexOutputStream>(
|
||||
writer_.get(), enabled_);
|
||||
multiplex_output_stream_ =
|
||||
std::make_unique<MultiplexOutputStream>(writer_.get(), enabled_);
|
||||
EXPECT_FALSE(multiplex_output_stream_->WriteConnectionResponseFrame(
|
||||
GenerateServiceIdHash(std::string(kServiceId_1)), std::string(kNoSalt),
|
||||
ConnectionResponseFrame::CONNECTION_ACCEPTED));
|
||||
@@ -137,16 +137,16 @@ TEST_F(MultiplexOutputStreamTest, SendConnectionResponseFrameDisabled) {
|
||||
}
|
||||
|
||||
TEST_F(MultiplexOutputStreamTest, CloseVirtualStreamFailed) {
|
||||
multiplex_output_stream_ = std::make_unique<MultiplexOutputStream>(
|
||||
writer_.get(), enabled_);
|
||||
multiplex_output_stream_ =
|
||||
std::make_unique<MultiplexOutputStream>(writer_.get(), enabled_);
|
||||
EXPECT_FALSE(multiplex_output_stream_->Close(std::string(kServiceId_1)));
|
||||
|
||||
multiplex_output_stream_->Shutdown();
|
||||
}
|
||||
|
||||
TEST_F(MultiplexOutputStreamTest, CloseVirtualStreamSuccess) {
|
||||
multiplex_output_stream_ = std::make_unique<MultiplexOutputStream>(
|
||||
writer_.get(), enabled_);
|
||||
multiplex_output_stream_ =
|
||||
std::make_unique<MultiplexOutputStream>(writer_.get(), enabled_);
|
||||
EXPECT_FALSE(multiplex_output_stream_->Close(std::string(kServiceId_1)));
|
||||
|
||||
multiplex_output_stream_->CreateVirtualOutputStream(std::string(kServiceId_1),
|
||||
@@ -166,8 +166,8 @@ TEST_F(MultiplexOutputStreamTest, CloseVirtualStreamSuccess) {
|
||||
}
|
||||
|
||||
TEST_F(MultiplexOutputStreamTest, CreateVirtualStream_SendData) {
|
||||
multiplex_output_stream_ = std::make_unique<MultiplexOutputStream>(
|
||||
writer_.get(), enabled_);
|
||||
multiplex_output_stream_ =
|
||||
std::make_unique<MultiplexOutputStream>(writer_.get(), enabled_);
|
||||
|
||||
auto virtual_output_stream =
|
||||
multiplex_output_stream_->CreateVirtualOutputStream(
|
||||
@@ -189,8 +189,8 @@ TEST_F(MultiplexOutputStreamTest, CreateVirtualStream_SendData) {
|
||||
}
|
||||
|
||||
TEST_F(MultiplexOutputStreamTest, CreateTwoVirtualStreams_SendData) {
|
||||
multiplex_output_stream_ = std::make_unique<MultiplexOutputStream>(
|
||||
writer_.get(), enabled_);
|
||||
multiplex_output_stream_ =
|
||||
std::make_unique<MultiplexOutputStream>(writer_.get(), enabled_);
|
||||
|
||||
auto virtual_output_stream_1 =
|
||||
multiplex_output_stream_->CreateVirtualOutputStreamForFirstVirtualSocket(
|
||||
@@ -222,14 +222,14 @@ TEST_F(MultiplexOutputStreamTest, CreateTwoVirtualStreams_SendData) {
|
||||
EXPECT_EQ(frame.frame_type(), MultiplexFrame::DATA_FRAME);
|
||||
bool first_frame_is_data_1 = true;
|
||||
if (frame.header().salted_service_id_hash() ==
|
||||
std::string(GenerateServiceIdHashWithSalt(std::string(kServiceId_1),
|
||||
std::string(kSalt_1)))) {
|
||||
std::string(GenerateServiceIdHashWithSalt(std::string(kServiceId_1),
|
||||
std::string(kSalt_1)))) {
|
||||
EXPECT_EQ(frame.data_frame().data(), std::string(data_1));
|
||||
LOG(INFO) << "Read first virtual stream frame first.";
|
||||
} else {
|
||||
EXPECT_EQ(frame.header().salted_service_id_hash(),
|
||||
std::string(GenerateServiceIdHashWithSalt(std::string(kServiceId_2),
|
||||
std::string(kSalt_2))));
|
||||
std::string(GenerateServiceIdHashWithSalt(
|
||||
std::string(kServiceId_2), std::string(kSalt_2))));
|
||||
EXPECT_EQ(frame.data_frame().data(), std::string(data_2));
|
||||
first_frame_is_data_1 = false;
|
||||
LOG(INFO) << "Read second virtual stream frame first.";
|
||||
|
||||
@@ -69,7 +69,7 @@ using ConnectionResponseCode = ConnectionResponseFrame::ConnectionResponseCode;
|
||||
|
||||
// AtomicBoolean is trivial destructible, so it is safe to use it as a static
|
||||
// variable.
|
||||
AtomicBoolean MultiplexSocket::is_shutting_down_{false}; // NOLINT
|
||||
AtomicBoolean MultiplexSocket::is_shutting_down_{false}; // NOLINT
|
||||
|
||||
void MultiplexSocket::ListenForIncomingConnection(
|
||||
const std::string& service_id, Medium type,
|
||||
@@ -131,14 +131,14 @@ MultiplexSocket* MultiplexSocket::CreateIncomingSocket(
|
||||
new (&storage_wlan) MultiplexSocket(physical_socket);
|
||||
break;
|
||||
default:
|
||||
LOG(ERROR) << __func__ << "Unsupported medium: "
|
||||
<< physical_socket->GetMedium();
|
||||
LOG(ERROR) << __func__
|
||||
<< "Unsupported medium: " << physical_socket->GetMedium();
|
||||
multiplex_incoming_socket = nullptr;
|
||||
return multiplex_incoming_socket;
|
||||
}
|
||||
LOG(INFO) << "CreateIncomingSocket with serviceId=" << service_id
|
||||
<< ", serviceIdHashSalt=" << kFakeSalt << " for medium="
|
||||
<< Medium_Name(physical_socket->GetMedium());
|
||||
<< ", serviceIdHashSalt=" << kFakeSalt
|
||||
<< " for medium=" << Medium_Name(physical_socket->GetMedium());
|
||||
|
||||
multiplex_incoming_socket->CreateFirstVirtualSocket(service_id,
|
||||
(std::string)kFakeSalt);
|
||||
@@ -175,14 +175,13 @@ MultiplexSocket* MultiplexSocket::CreateOutgoingSocket(
|
||||
new (&storage_wlan) MultiplexSocket(physical_socket);
|
||||
break;
|
||||
default:
|
||||
LOG(ERROR) << __func__ << "Unsupported medium: "
|
||||
<< physical_socket->GetMedium();
|
||||
LOG(ERROR) << __func__
|
||||
<< "Unsupported medium: " << physical_socket->GetMedium();
|
||||
return multiplex_outgoing_socket;
|
||||
}
|
||||
LOG(INFO) << "CreateOutgoingSocket with serviceId=" << service_id
|
||||
<< ", serviceIdHashSalt=" << service_id_hash_salt
|
||||
<< " for medium="
|
||||
<< Medium_Name(physical_socket->GetMedium());
|
||||
<< ", serviceIdHashSalt=" << service_id_hash_salt
|
||||
<< " for medium=" << Medium_Name(physical_socket->GetMedium());
|
||||
|
||||
multiplex_outgoing_socket->CreateFirstVirtualSocket(service_id,
|
||||
service_id_hash_salt);
|
||||
@@ -207,9 +206,8 @@ MediumSocket* MultiplexSocket::CreateFirstVirtualSocket(
|
||||
std::string salted_service_id_hash_key =
|
||||
GenerateServiceIdHashKeyWithSalt(service_id, service_id_hash_salt);
|
||||
LOG(INFO) << __func__ << " for service_id=" << service_id
|
||||
<< ", salt=" << service_id_hash_salt
|
||||
<< ", salted_service_id_hash_key="
|
||||
<< salted_service_id_hash_key;
|
||||
<< ", salt=" << service_id_hash_salt
|
||||
<< ", salted_service_id_hash_key=" << salted_service_id_hash_key;
|
||||
MediumSocket* virtual_socket = physical_socket_ptr_->CreateVirtualSocket(
|
||||
salted_service_id_hash_key, output_stream, medium_, &virtual_sockets_);
|
||||
|
||||
@@ -234,9 +232,8 @@ MediumSocket* MultiplexSocket::CreateVirtualSocket(
|
||||
GenerateServiceIdHashKeyWithSalt(service_id, service_id_hash_salt);
|
||||
|
||||
LOG(INFO) << __func__ << "service_id=" << service_id
|
||||
<< ", salt=" << service_id_hash_salt
|
||||
<< ", salted_service_id_hash_key="
|
||||
<< salted_service_id_hash_key;
|
||||
<< ", salt=" << service_id_hash_salt
|
||||
<< ", salted_service_id_hash_key=" << salted_service_id_hash_key;
|
||||
|
||||
MediumSocket* virtual_socket = physical_socket_ptr_->CreateVirtualSocket(
|
||||
salted_service_id_hash_key, output_stream, medium_, &virtual_sockets_);
|
||||
@@ -251,8 +248,8 @@ MediumSocket* MultiplexSocket::CreateVirtualSocket(
|
||||
MediumSocket* MultiplexSocket::GetVirtualSocket(const std::string& service_id) {
|
||||
MutexLock lock(&virtual_socket_mutex_);
|
||||
LOG(INFO) << __func__ << " service_id=" << service_id << ", Salt="
|
||||
<< multiplex_output_stream_.GetServiceIdHashSalt(service_id)
|
||||
<< ", virtual_sockets_.size()=" << virtual_sockets_.size();
|
||||
<< multiplex_output_stream_.GetServiceIdHashSalt(service_id)
|
||||
<< ", virtual_sockets_.size()=" << virtual_sockets_.size();
|
||||
auto item = virtual_sockets_.find(GenerateServiceIdHashKeyWithSalt(
|
||||
service_id, multiplex_output_stream_.GetServiceIdHashSalt(service_id)));
|
||||
if (item == virtual_sockets_.end()) {
|
||||
@@ -269,11 +266,10 @@ int MultiplexSocket::GetVirtualSocketCount() {
|
||||
|
||||
void MultiplexSocket::ListVirtualSocket() {
|
||||
LOG(INFO) << __func__
|
||||
<< " virtual_sockets_.size()=" << virtual_sockets_.size();
|
||||
<< " virtual_sockets_.size()=" << virtual_sockets_.size();
|
||||
for (auto& [service_id_hash_key, virtual_socket] : virtual_sockets_) {
|
||||
LOG(INFO) << __func__
|
||||
<< " service_id_hash_key=" << service_id_hash_key
|
||||
<< ", virtual_socket=" << virtual_socket;
|
||||
LOG(INFO) << __func__ << " service_id_hash_key=" << service_id_hash_key
|
||||
<< ", virtual_socket=" << virtual_socket;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,8 +305,8 @@ MediumSocket* MultiplexSocket::EstablishVirtualSocket(
|
||||
.multiplex_socket_connection_response_timeout_millis);
|
||||
if (!result.ok()) {
|
||||
LOG(ERROR) << __func__
|
||||
<< "EstablishVirtualSocket failed with response code="
|
||||
<< result.exception();
|
||||
<< "EstablishVirtualSocket failed with response code="
|
||||
<< result.exception();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -318,21 +314,21 @@ MediumSocket* MultiplexSocket::EstablishVirtualSocket(
|
||||
switch (response_code) {
|
||||
case ConnectionResponseFrame::CONNECTION_ACCEPTED:
|
||||
LOG(INFO) << "EstablishVirtualSocket after remote response to"
|
||||
" accept the connection with service_id="
|
||||
<< service_id
|
||||
<< ", service_id_hash_salt=" << service_id_hash_salt;
|
||||
" accept the connection with service_id="
|
||||
<< service_id
|
||||
<< ", service_id_hash_salt=" << service_id_hash_salt;
|
||||
return CreateVirtualSocket(service_id, service_id_hash_salt);
|
||||
case ConnectionResponseFrame::NOT_LISTENING:
|
||||
LOG(ERROR) << "EstablishVirtualSocket failed for service_id="
|
||||
<< service_id
|
||||
<< ", service_id_hash_salt=" << service_id_hash_salt
|
||||
<< " with response code=NOT_LISTENING";
|
||||
<< service_id
|
||||
<< ", service_id_hash_salt=" << service_id_hash_salt
|
||||
<< " with response code=NOT_LISTENING";
|
||||
break;
|
||||
default:
|
||||
LOG(ERROR) << "EstablishVirtualSocket failed for service_id="
|
||||
<< service_id
|
||||
<< ", service_id_hash_salt=" << service_id_hash_salt
|
||||
<< " with response code=UNKNOWN_RESPONSE_CODE";
|
||||
<< service_id
|
||||
<< ", service_id_hash_salt=" << service_id_hash_salt
|
||||
<< " with response code=UNKNOWN_RESPONSE_CODE";
|
||||
break;
|
||||
}
|
||||
return nullptr;
|
||||
@@ -341,7 +337,7 @@ MediumSocket* MultiplexSocket::EstablishVirtualSocket(
|
||||
void MultiplexSocket::StartReaderThread(std::int32_t first_frame_len) {
|
||||
if (is_shutdown_) {
|
||||
LOG(WARNING) << "Stop to start reader thread since socket is "
|
||||
"shutdown.";
|
||||
"shutdown.";
|
||||
return;
|
||||
}
|
||||
reader_thread_shutdown_barrier_ = std::make_unique<CountDownLatch>(1);
|
||||
@@ -359,8 +355,8 @@ void MultiplexSocket::StartReaderThread(std::int32_t first_frame_len) {
|
||||
read_int = Base64Utils::ReadInt(physical_reader_);
|
||||
}
|
||||
if (!read_int.ok()) {
|
||||
LOG(WARNING)
|
||||
<< __func__ << "Failed to read. Exception:" << read_int.exception();
|
||||
LOG(WARNING) << __func__
|
||||
<< "Failed to read. Exception:" << read_int.exception();
|
||||
fail = true;
|
||||
} else {
|
||||
auto length = read_int.result();
|
||||
@@ -371,16 +367,16 @@ void MultiplexSocket::StartReaderThread(std::int32_t first_frame_len) {
|
||||
.connection_max_frame_length) {
|
||||
// Ignore the failure because not only one client use this
|
||||
// connection.
|
||||
LOG(WARNING)
|
||||
<< __func__ << "Failed to read because received a invalid length "
|
||||
<< length << ", but continue to read.";
|
||||
LOG(WARNING) << __func__
|
||||
<< "Failed to read because received a invalid length "
|
||||
<< length << ", but continue to read.";
|
||||
continue;
|
||||
}
|
||||
|
||||
bytes = physical_reader_->ReadExactly(length);
|
||||
if (!bytes.ok()) {
|
||||
LOG(WARNING)
|
||||
<< __func__ << "Read data exception:" << bytes.exception();
|
||||
LOG(WARNING) << __func__
|
||||
<< "Read data exception:" << bytes.exception();
|
||||
fail = true;
|
||||
}
|
||||
}
|
||||
@@ -402,10 +398,9 @@ void MultiplexSocket::StartReaderThread(std::int32_t first_frame_len) {
|
||||
// the remote, it means that the remote and the local both
|
||||
// support multiplex as well. So it is safe to just turn on
|
||||
// the feature at this point.
|
||||
LOG(INFO)
|
||||
<< __func__
|
||||
<< " Received a multiplex frame while not enabled, enable "
|
||||
"multiplex.";
|
||||
LOG(INFO) << __func__
|
||||
<< " Received a multiplex frame while not enabled, enable "
|
||||
"multiplex.";
|
||||
Enable();
|
||||
}
|
||||
const auto& frame = frame_exc.result();
|
||||
@@ -425,9 +420,9 @@ void MultiplexSocket::StartReaderThread(std::int32_t first_frame_len) {
|
||||
frame.data_frame());
|
||||
break;
|
||||
default:
|
||||
LOG(WARNING)
|
||||
<< __func__ << " Received MultiplexFrame with unknown frame type "
|
||||
<< frame.frame_type();
|
||||
LOG(WARNING) << __func__
|
||||
<< " Received MultiplexFrame with unknown frame type "
|
||||
<< frame.frame_type();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -435,8 +430,7 @@ void MultiplexSocket::StartReaderThread(std::int32_t first_frame_len) {
|
||||
|
||||
void MultiplexSocket::HandleOfflineFrame(const ByteArray& bytes) {
|
||||
MutexLock lock(&virtual_socket_mutex_);
|
||||
LOG(INFO) << __func__
|
||||
<< " Virtual_socket num:" << virtual_sockets_.size();
|
||||
LOG(INFO) << __func__ << " Virtual_socket num:" << virtual_sockets_.size();
|
||||
if (virtual_sockets_.size() == 1) {
|
||||
auto item = virtual_sockets_.begin();
|
||||
if (item->second == nullptr) {
|
||||
@@ -461,12 +455,12 @@ void MultiplexSocket::HandleControlFrame(
|
||||
});
|
||||
break;
|
||||
case MultiplexControlFrame::CONNECTION_RESPONSE:
|
||||
LOG(INFO)
|
||||
<< __func__ << "Received an CONNECTION_RESPONSE frame."
|
||||
<< " salted_service_id_hash: " << std::string(salted_service_id_hash)
|
||||
<< ", service_id_hash_salt: " << service_id_hash_salt
|
||||
<< ", ConnectionResponseCode: "
|
||||
<< frame.connection_response_frame().connection_response_code();
|
||||
LOG(INFO) << __func__ << "Received an CONNECTION_RESPONSE frame."
|
||||
<< " salted_service_id_hash: "
|
||||
<< std::string(salted_service_id_hash)
|
||||
<< ", service_id_hash_salt: " << service_id_hash_salt
|
||||
<< ", ConnectionResponseCode: "
|
||||
<< frame.connection_response_frame().connection_response_code();
|
||||
|
||||
RunOffloadThread("CONNECTION_RESPONSE", [this, salted_service_id_hash,
|
||||
service_id_hash_salt,
|
||||
@@ -482,7 +476,7 @@ void MultiplexSocket::HandleControlFrame(
|
||||
break;
|
||||
default:
|
||||
LOG(WARNING) << __func__ << "Received an unknown frame type "
|
||||
<< frame.control_frame_type();
|
||||
<< frame.control_frame_type();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -492,8 +486,8 @@ void MultiplexSocket::HandleConnectionRequest(
|
||||
const std::string& service_id_hash_salt) {
|
||||
if (!IsEnabled()) {
|
||||
LOG(WARNING) << "Received a CONNECTION_REQUEST frame on medium "
|
||||
<< Medium_Name(medium_)
|
||||
<< " but status is disabled, ignore it.";
|
||||
<< Medium_Name(medium_)
|
||||
<< " but status is disabled, ignore it.";
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -513,12 +507,12 @@ void MultiplexSocket::HandleConnectionRequest(
|
||||
|
||||
if (incoming_connection_callback == nullptr || listening_service_id.empty()) {
|
||||
LOG(INFO) << "There's no client listening for hash salt : "
|
||||
<< service_id_hash_salt
|
||||
<< ", hash key : " << salted_service_id_hash_key
|
||||
<< " on medium " << Medium_Name(medium_);
|
||||
<< service_id_hash_salt
|
||||
<< ", hash key : " << salted_service_id_hash_key << " on medium "
|
||||
<< Medium_Name(medium_);
|
||||
|
||||
LOG(INFO) << "The size of incomingConnectionCallbacks : "
|
||||
<< GetIncomingConnectionCallbacks().size();
|
||||
<< GetIncomingConnectionCallbacks().size();
|
||||
if (!multiplex_output_stream_.WriteConnectionResponseFrame(
|
||||
salted_service_id_hash, service_id_hash_salt,
|
||||
ConnectionResponseFrame::NOT_LISTENING)) {
|
||||
@@ -527,10 +521,9 @@ void MultiplexSocket::HandleConnectionRequest(
|
||||
return;
|
||||
}
|
||||
LOG(INFO) << "Accept new virtual socket request service ID : "
|
||||
<< listening_service_id
|
||||
<< ", hash salt : " << service_id_hash_salt
|
||||
<< ", hash key : " << salted_service_id_hash_key
|
||||
<< " on medium " << Medium_Name(medium_);
|
||||
<< listening_service_id << ", hash salt : " << service_id_hash_salt
|
||||
<< ", hash key : " << salted_service_id_hash_key << " on medium "
|
||||
<< Medium_Name(medium_);
|
||||
|
||||
if (!multiplex_output_stream_.WriteConnectionResponseFrame(
|
||||
salted_service_id_hash, service_id_hash_salt,
|
||||
@@ -539,10 +532,10 @@ void MultiplexSocket::HandleConnectionRequest(
|
||||
return;
|
||||
}
|
||||
|
||||
VLOG(1)
|
||||
<< "EstablishVirtualSocket after local device accept the connection "
|
||||
"with serviceId="
|
||||
<< listening_service_id << ", serviceIdHashSalt=" << service_id_hash_salt;
|
||||
VLOG(1) << "EstablishVirtualSocket after local device accept the connection "
|
||||
"with serviceId="
|
||||
<< listening_service_id
|
||||
<< ", serviceIdHashSalt=" << service_id_hash_salt;
|
||||
MediumSocket* virtual_socket =
|
||||
CreateVirtualSocket(listening_service_id, service_id_hash_salt);
|
||||
(*incoming_connection_callback)(std::move(listening_service_id),
|
||||
@@ -553,18 +546,16 @@ void MultiplexSocket::HandleConnectionResponse(
|
||||
const ByteArray& salted_service_id_hash,
|
||||
const std::string& service_id_hash_salt,
|
||||
const ConnectionResponseFrame& frame) {
|
||||
LOG(INFO) << __func__ << "connection_response_code: "
|
||||
<< frame.connection_response_code();
|
||||
LOG(INFO) << __func__
|
||||
<< "connection_response_code: " << frame.connection_response_code();
|
||||
for (auto& [service_id, future] : connection_response_futures_) {
|
||||
if (GenerateServiceIdHashWithSalt(service_id, service_id_hash_salt) ==
|
||||
salted_service_id_hash) {
|
||||
if (future != nullptr) {
|
||||
future->Set(frame.connection_response_code());
|
||||
LOG(INFO) << __func__
|
||||
<< "Set the future for serviceId=" << service_id
|
||||
<< ", serviceIdHashSalt=" << service_id_hash_salt
|
||||
<< " with response code="
|
||||
<< frame.connection_response_code();
|
||||
LOG(INFO) << __func__ << "Set the future for serviceId=" << service_id
|
||||
<< ", serviceIdHashSalt=" << service_id_hash_salt
|
||||
<< " with response code=" << frame.connection_response_code();
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -639,37 +630,36 @@ void MultiplexSocket::OnVirtualSocketClosed(const std::string& service_id) {
|
||||
LOG(INFO) << __func__ << " for service_id:" << service_id;
|
||||
CountDownLatch latch(1);
|
||||
bool shutdown = false;
|
||||
RunOffloadThread("VirtualSocketClosed", [this, service_id, &latch,
|
||||
&shutdown]() {
|
||||
LOG(INFO) << "Try to close Virtual socket: " << service_id;
|
||||
MediumSocket* virtual_socket = GetVirtualSocket(service_id);
|
||||
{
|
||||
MutexLock lock(&virtual_socket_mutex_);
|
||||
LOG(INFO) << "virtual_socket:" << virtual_socket;
|
||||
if (virtual_socket != nullptr) {
|
||||
auto salted_service_id_hash_key = GenerateServiceIdHashKeyWithSalt(
|
||||
service_id,
|
||||
multiplex_output_stream_.GetServiceIdHashSalt(service_id));
|
||||
multiplex_output_stream_.Close(service_id);
|
||||
virtual_sockets_.erase(salted_service_id_hash_key);
|
||||
LOG(INFO) << "Erase Virtual socket with service_id: "
|
||||
<< service_id
|
||||
<< ", hash_key: " << salted_service_id_hash_key;
|
||||
ListVirtualSocket();
|
||||
RunOffloadThread(
|
||||
"VirtualSocketClosed", [this, service_id, &latch, &shutdown]() {
|
||||
LOG(INFO) << "Try to close Virtual socket: " << service_id;
|
||||
MediumSocket* virtual_socket = GetVirtualSocket(service_id);
|
||||
{
|
||||
MutexLock lock(&virtual_socket_mutex_);
|
||||
LOG(INFO) << "virtual_socket:" << virtual_socket;
|
||||
if (virtual_socket != nullptr) {
|
||||
auto salted_service_id_hash_key = GenerateServiceIdHashKeyWithSalt(
|
||||
service_id,
|
||||
multiplex_output_stream_.GetServiceIdHashSalt(service_id));
|
||||
multiplex_output_stream_.Close(service_id);
|
||||
virtual_sockets_.erase(salted_service_id_hash_key);
|
||||
LOG(INFO) << "Erase Virtual socket with service_id: " << service_id
|
||||
<< ", hash_key: " << salted_service_id_hash_key;
|
||||
ListVirtualSocket();
|
||||
|
||||
if (virtual_sockets_.empty()) {
|
||||
LOG(INFO) << "Close the physical socket because all virtual "
|
||||
"sockets disconnected.";
|
||||
is_shutting_down_.Set(true);
|
||||
Shutdown();
|
||||
shutdown = true;
|
||||
if (virtual_sockets_.empty()) {
|
||||
LOG(INFO) << "Close the physical socket because all virtual "
|
||||
"sockets disconnected.";
|
||||
is_shutting_down_.Set(true);
|
||||
Shutdown();
|
||||
shutdown = true;
|
||||
}
|
||||
} else {
|
||||
LOG(INFO) << "Virtual socket(" << service_id << ") not found";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LOG(INFO) << "Virtual socket(" << service_id << ") not found";
|
||||
}
|
||||
}
|
||||
latch.CountDown();
|
||||
});
|
||||
latch.CountDown();
|
||||
});
|
||||
|
||||
if (!latch.Await(absl::Milliseconds(1000)).result()) {
|
||||
LOG(ERROR) << "Timeout to close virtual socket";
|
||||
@@ -690,8 +680,8 @@ MediumSocket* MultiplexSocket::ReMapAndGetVirtualSocket(
|
||||
std::string salted_service_id_hash_key =
|
||||
GenerateServiceIdHashKey(salted_service_id_hash);
|
||||
VLOG(1) << "ReMapAndGetVirtualSocket with serviceIdHashSalt="
|
||||
<< service_id_hash_salt
|
||||
<< ", saltedServiceIdHashKey=" << salted_service_id_hash_key;
|
||||
<< service_id_hash_salt
|
||||
<< ", saltedServiceIdHashKey=" << salted_service_id_hash_key;
|
||||
{
|
||||
MutexLock lock(&virtual_socket_mutex_);
|
||||
for (auto& [hash_key, virtual_socket] : virtual_sockets_) {
|
||||
@@ -779,8 +769,7 @@ void MultiplexSocket::ShutdownAll() {
|
||||
LOG(ERROR) << "Timeout to close virtual socket";
|
||||
}
|
||||
|
||||
LOG(INFO)
|
||||
<< "Shutdown single_thread_offloader_ and physical_reader_thread_";
|
||||
LOG(INFO) << "Shutdown single_thread_offloader_ and physical_reader_thread_";
|
||||
single_thread_offloader_.Shutdown();
|
||||
physical_reader_thread_.Shutdown();
|
||||
LOG(INFO) << __func__ << " end";
|
||||
|
||||
@@ -50,9 +50,9 @@ namespace multiplex {
|
||||
constexpr absl::string_view SERVICE_ID_1 = "serviceId_1";
|
||||
constexpr absl::string_view SERVICE_ID_2 = "serviceId_2";
|
||||
|
||||
using location::nearby::mediums::MultiplexFrame;
|
||||
using location::nearby::mediums::MultiplexControlFrame;
|
||||
using location::nearby::mediums::ConnectionResponseFrame;
|
||||
using location::nearby::mediums::MultiplexControlFrame;
|
||||
using location::nearby::mediums::MultiplexFrame;
|
||||
using location::nearby::proto::connections::Medium;
|
||||
using location::nearby::proto::connections::Medium_Name;
|
||||
|
||||
@@ -66,8 +66,7 @@ class FakeSocket : public MediumSocket {
|
||||
pipe_2_ = CreatePipe();
|
||||
reader_2_ = std::move(pipe_2_.first);
|
||||
writer_2_ = std::move(pipe_2_.second);
|
||||
LOG(WARNING) << "Physical Socket Medium:"
|
||||
<< Medium_Name(GetMedium());
|
||||
LOG(WARNING) << "Physical Socket Medium:" << Medium_Name(GetMedium());
|
||||
};
|
||||
~FakeSocket() override = default;
|
||||
|
||||
@@ -117,22 +116,21 @@ class FakeSocket : public MediumSocket {
|
||||
|
||||
auto virtual_socket = std::make_shared<FakeSocket>(medium, outputstream);
|
||||
LOG(WARNING) << "Created the virtual socket for Medium: "
|
||||
<< Medium_Name(virtual_socket->GetMedium());
|
||||
<< Medium_Name(virtual_socket->GetMedium());
|
||||
|
||||
if (virtual_sockets_ptr_ == nullptr) {
|
||||
virtual_sockets_ptr_ = virtual_sockets_ptr;
|
||||
}
|
||||
|
||||
(*virtual_sockets_ptr_)[salted_service_id_hash_key] = virtual_socket;
|
||||
LOG(INFO) << "virtual_sockets_ size: "
|
||||
<< virtual_sockets_ptr_->size();
|
||||
LOG(INFO) << "virtual_sockets_ size: " << virtual_sockets_ptr_->size();
|
||||
return virtual_socket.get();
|
||||
}
|
||||
|
||||
void FeedIncomingData(ByteArray data) override {
|
||||
bytes_read_future_.Set(data);
|
||||
LOG(INFO) << "FeedIncomingData. Size of receive data: "
|
||||
<< data.size() << ", bytes content:" << std::string(data);
|
||||
LOG(INFO) << "FeedIncomingData. Size of receive data: " << data.size()
|
||||
<< ", bytes content:" << std::string(data);
|
||||
}
|
||||
|
||||
bool IsVirtualSocket() override { return is_virtual_socket_; }
|
||||
@@ -155,8 +153,7 @@ class FakeSocket : public MediumSocket {
|
||||
};
|
||||
|
||||
TEST(MultiplexSocketTest, CreateSuccessAndReaderThreadStarted) {
|
||||
auto fake_socket_ptr =
|
||||
std::make_shared<FakeSocket>(Medium::BLUETOOTH);
|
||||
auto fake_socket_ptr = std::make_shared<FakeSocket>(Medium::BLUETOOTH);
|
||||
MultiplexSocket::StopListeningForIncomingConnection(std::string(SERVICE_ID_1),
|
||||
Medium::BLUETOOTH);
|
||||
MultiplexSocket* multiplex_socket_incoming =
|
||||
@@ -204,8 +201,7 @@ TEST(MultiplexSocketTest, CreateSuccessAndReaderThreadStarted) {
|
||||
EXPECT_EQ(multiplex_socket_incoming->GetVirtualSocketCount(), 0);
|
||||
}
|
||||
TEST(MultiplexSocketTest, CreateFail_MediumNotSupport) {
|
||||
auto fake_socket_ptr =
|
||||
std::make_shared<FakeSocket>(Medium::WEB_RTC);
|
||||
auto fake_socket_ptr = std::make_shared<FakeSocket>(Medium::WEB_RTC);
|
||||
MultiplexSocket::StopListeningForIncomingConnection(std::string(SERVICE_ID_1),
|
||||
Medium::WEB_RTC);
|
||||
MultiplexSocket* multiplex_socket_incoming =
|
||||
@@ -231,9 +227,8 @@ TEST(MultiplexSocketTest,
|
||||
multiplex_socket->EstablishVirtualSocket(std::string(SERVICE_ID_2));
|
||||
EXPECT_EQ(socket, nullptr);
|
||||
absl::SleepFor(absl::Milliseconds(100));
|
||||
FakeSocket* virtual_socket =
|
||||
(FakeSocket*)multiplex_socket->GetVirtualSocket(
|
||||
std::string(SERVICE_ID_1));
|
||||
FakeSocket* virtual_socket = (FakeSocket*)multiplex_socket->GetVirtualSocket(
|
||||
std::string(SERVICE_ID_1));
|
||||
if (virtual_socket == nullptr) {
|
||||
LOG(INFO) << "Virtual socket not found for " << SERVICE_ID_1;
|
||||
return;
|
||||
@@ -278,8 +273,7 @@ TEST(MultiplexSocketTest,
|
||||
LOG(INFO) << "reader_2_ Read start";
|
||||
ExceptionOr<std::int32_t> read_int = Base64Utils::ReadInt(reader);
|
||||
if (!read_int.ok()) {
|
||||
ADD_FAILURE() << "Failed to read. Exception:"
|
||||
<< read_int.exception();
|
||||
ADD_FAILURE() << "Failed to read. Exception:" << read_int.exception();
|
||||
}
|
||||
auto length = read_int.result();
|
||||
LOG(INFO) << " length:" << length;
|
||||
@@ -294,8 +288,7 @@ TEST(MultiplexSocketTest,
|
||||
EXPECT_EQ(multiplex_socket->GetVirtualSocketCount(), 0);
|
||||
}
|
||||
|
||||
TEST(MultiplexSocketTest,
|
||||
EstablishVirtualSocket_RemoteAccepted) {
|
||||
TEST(MultiplexSocketTest, EstablishVirtualSocket_RemoteAccepted) {
|
||||
auto fake_socket_ptr = std::make_shared<FakeSocket>(Medium::BLUETOOTH);
|
||||
MultiplexSocket::StopListeningForIncomingConnection(std::string(SERVICE_ID_1),
|
||||
Medium::BLUETOOTH);
|
||||
@@ -339,8 +332,7 @@ TEST(MultiplexSocketTest,
|
||||
ADD_FAILURE() << "Invalid frame length:" << length;
|
||||
}
|
||||
|
||||
ExceptionOr<MultiplexFrame> frame_exc =
|
||||
multiplex::FromBytes(bytes.result());
|
||||
ExceptionOr<MultiplexFrame> frame_exc = multiplex::FromBytes(bytes.result());
|
||||
if (!frame_exc.ok()) {
|
||||
ADD_FAILURE() << "Failed to parse MultiplexFrame. Exception:"
|
||||
<< frame_exc.exception();
|
||||
@@ -356,7 +348,7 @@ TEST(MultiplexSocketTest,
|
||||
ASSERT_EQ(control_frame.control_frame_type(),
|
||||
MultiplexControlFrame::CONNECTION_REQUEST);
|
||||
LOG(INFO) << "Recieved MultiplexControlFrame::CONNECTION_REQUEST "
|
||||
"frame, now send CONNECTION_RESPONSE frame.";
|
||||
"frame, now send CONNECTION_RESPONSE frame.";
|
||||
|
||||
ByteArray connection_response_frame =
|
||||
ForConnectionResponse(salted_service_id_hash, service_id_hash_salt,
|
||||
|
||||
@@ -103,14 +103,13 @@ bool WebRtc::StartAcceptingConnections(const std::string& service_id,
|
||||
MutexLock lock(&mutex_);
|
||||
if (!IsAvailable()) {
|
||||
LOG(WARNING) << "Cannot start accepting WebRTC connections because "
|
||||
"WebRTC is not available.";
|
||||
"WebRTC is not available.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsAcceptingConnectionsLocked(service_id)) {
|
||||
LOG(WARNING)
|
||||
<< "Cannot start accepting WebRTC connections because service "
|
||||
<< service_id << "is already accepting WebRTC connections.";
|
||||
LOG(WARNING) << "Cannot start accepting WebRTC connections because service "
|
||||
<< service_id << "is already accepting WebRTC connections.";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -151,16 +150,15 @@ bool WebRtc::StartAcceptingConnections(const std::string& service_id,
|
||||
// a successful result.
|
||||
accepting_connections_info_.emplace(service_id, std::move(info));
|
||||
LOG(INFO) << "Started listening for WebRTC connections as "
|
||||
<< self_peer_id.GetId() << " on service " << service_id;
|
||||
<< self_peer_id.GetId() << " on service " << service_id;
|
||||
return true;
|
||||
}
|
||||
|
||||
void WebRtc::StopAcceptingConnections(const std::string& service_id) {
|
||||
MutexLock lock(&mutex_);
|
||||
if (!IsAcceptingConnectionsLocked(service_id)) {
|
||||
LOG(WARNING)
|
||||
<< "Cannot stop accepting WebRTC connections because service "
|
||||
<< service_id << "is not accepting WebRTC connections.";
|
||||
LOG(WARNING) << "Cannot stop accepting WebRTC connections because service "
|
||||
<< service_id << "is not accepting WebRTC connections.";
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -206,7 +204,7 @@ void WebRtc::StopAcceptingConnections(const std::string& service_id) {
|
||||
// Clean up our state. We're now no longer listening for connections.
|
||||
accepting_connections_info_.erase(service_id);
|
||||
LOG(INFO) << "Stopped listening for WebRTC connections for service "
|
||||
<< service_id;
|
||||
<< service_id;
|
||||
}
|
||||
|
||||
ErrorOr<WebRtcSocketWrapper> WebRtc::Connect(
|
||||
@@ -220,18 +218,17 @@ ErrorOr<WebRtcSocketWrapper> WebRtc::Connect(
|
||||
while (service_id_to_connect_attempts_count_map_[service_id] <=
|
||||
kConnectAttemptsLimit) {
|
||||
if (cancellation_flag->Cancelled()) {
|
||||
LOG(WARNING)
|
||||
<< "Attempt #"
|
||||
<< service_id_to_connect_attempts_count_map_[service_id]
|
||||
<< ": Cannot Connect with WebRtc due to cancel.";
|
||||
LOG(WARNING) << "Attempt #"
|
||||
<< service_id_to_connect_attempts_count_map_[service_id]
|
||||
<< ": Cannot Connect with WebRtc due to cancel.";
|
||||
return {
|
||||
Error(OperationResultCode::
|
||||
CLIENT_CANCELLATION_CANCEL_WEB_RTC_OUTGOING_CONNECTION)};
|
||||
}
|
||||
|
||||
LOG(INFO) << "Attempt #"
|
||||
<< service_id_to_connect_attempts_count_map_[service_id]
|
||||
<< ": Beginning connection.";
|
||||
<< service_id_to_connect_attempts_count_map_[service_id]
|
||||
<< ": Beginning connection.";
|
||||
wrapper_result = AttemptToConnect(service_id, remote_peer_id, location_hint,
|
||||
cancellation_flag);
|
||||
if (wrapper_result.has_value()) {
|
||||
@@ -241,8 +238,7 @@ ErrorOr<WebRtcSocketWrapper> WebRtc::Connect(
|
||||
service_id_to_connect_attempts_count_map_[service_id]++;
|
||||
}
|
||||
|
||||
LOG(WARNING) << "Giving up after " << kConnectAttemptsLimit
|
||||
<< " attempts";
|
||||
LOG(WARNING) << "Giving up after " << kConnectAttemptsLimit << " attempts";
|
||||
return {Error(wrapper_result.error().operation_result_code().value())};
|
||||
}
|
||||
|
||||
@@ -259,19 +255,17 @@ ErrorOr<WebRtcSocketWrapper> WebRtc::AttemptToConnect(
|
||||
// is complete.
|
||||
CancellationFlagListener listener(
|
||||
cancellation_flag, [this, &service_id, &socket_future]() {
|
||||
LOG(WARNING)
|
||||
<< "Attempt # "
|
||||
<< service_id_to_connect_attempts_count_map_[service_id]
|
||||
<< " to connect with WebRtc stopped due to cancel.";
|
||||
LOG(WARNING) << "Attempt # "
|
||||
<< service_id_to_connect_attempts_count_map_[service_id]
|
||||
<< " to connect with WebRtc stopped due to cancel.";
|
||||
socket_future.SetException({Exception::kFailed});
|
||||
});
|
||||
|
||||
{
|
||||
MutexLock lock(&mutex_);
|
||||
if (!IsAvailable()) {
|
||||
LOG(WARNING) << "Cannot connect to WebRTC peer "
|
||||
<< remote_peer_id.GetId()
|
||||
<< " because WebRTC is not available.";
|
||||
LOG(WARNING) << "Cannot connect to WebRTC peer " << remote_peer_id.GetId()
|
||||
<< " because WebRTC is not available.";
|
||||
return {
|
||||
Error(OperationResultCode::MEDIUM_UNAVAILABLE_WEB_RTC_NOT_AVAILABLE)};
|
||||
}
|
||||
@@ -280,9 +274,8 @@ ErrorOr<WebRtcSocketWrapper> WebRtc::AttemptToConnect(
|
||||
std::unique_ptr<ConnectionFlow> connection_flow =
|
||||
CreateConnectionFlow(service_id, remote_peer_id);
|
||||
if (!connection_flow) {
|
||||
LOG(INFO) << "Cannot connect to WebRTC peer "
|
||||
<< remote_peer_id.GetId()
|
||||
<< " because we failed to create a ConnectionFlow.";
|
||||
LOG(INFO) << "Cannot connect to WebRTC peer " << remote_peer_id.GetId()
|
||||
<< " because we failed to create a ConnectionFlow.";
|
||||
return {Error(OperationResultCode::NEARBY_WEB_RTC_CONNECTION_FLOW_NULL)};
|
||||
}
|
||||
|
||||
@@ -290,9 +283,8 @@ ErrorOr<WebRtcSocketWrapper> WebRtc::AttemptToConnect(
|
||||
info.signaling_messenger = medium_->GetSignalingMessenger(
|
||||
info.self_peer_id.GetId(), location_hint);
|
||||
if (!info.signaling_messenger->IsValid()) {
|
||||
LOG(INFO) << "Cannot connect to WebRTC peer "
|
||||
<< remote_peer_id.GetId()
|
||||
<< " because we failed to create a SignalingMessenger.";
|
||||
LOG(INFO) << "Cannot connect to WebRTC peer " << remote_peer_id.GetId()
|
||||
<< " because we failed to create a SignalingMessenger.";
|
||||
return {
|
||||
Error(OperationResultCode::
|
||||
MISCELLEANEOUS_WEB_RTC_TACHYON_SIGNALING_MESSENGER_NULL)};
|
||||
@@ -320,9 +312,8 @@ ErrorOr<WebRtcSocketWrapper> WebRtc::AttemptToConnect(
|
||||
if (!info.signaling_messenger->SendMessage(
|
||||
remote_peer_id.GetId(),
|
||||
webrtc_frames::EncodeReadyForSignalingPoke(info.self_peer_id))) {
|
||||
LOG(INFO) << "Cannot connect to WebRTC peer "
|
||||
<< remote_peer_id.GetId()
|
||||
<< " because we failed to poke the peer over Tachyon.";
|
||||
LOG(INFO) << "Cannot connect to WebRTC peer " << remote_peer_id.GetId()
|
||||
<< " because we failed to poke the peer over Tachyon.";
|
||||
info.signaling_messenger.reset();
|
||||
return {Error(OperationResultCode::
|
||||
CONNECTIVITY_WEB_RTC_CONNECT_TO_TACHYON_FAILURE)};
|
||||
@@ -352,7 +343,7 @@ ErrorOr<WebRtcSocketWrapper> WebRtc::AttemptToConnect(
|
||||
// Verify that the connection went through.
|
||||
if (!socket_result.ok()) {
|
||||
LOG(INFO) << "Failed to connect to WebRTC peer "
|
||||
<< remote_peer_id.GetId();
|
||||
<< remote_peer_id.GetId();
|
||||
RemoveConnectionFlow(remote_peer_id);
|
||||
info.signaling_messenger.reset();
|
||||
requesting_connections_info_.erase(remote_peer_id.GetId());
|
||||
@@ -385,8 +376,7 @@ void WebRtc::ProcessLocalIceCandidate(
|
||||
webrtc_frames::EncodeIceCandidates(
|
||||
connection_request_entry->second.self_peer_id,
|
||||
{ice_candidate}))) {
|
||||
LOG(INFO) << "Failed to send ice candidate to "
|
||||
<< remote_peer_id.GetId();
|
||||
LOG(INFO) << "Failed to send ice candidate to " << remote_peer_id.GetId();
|
||||
}
|
||||
|
||||
LOG(INFO) << "Sent ice candidate to " << remote_peer_id.GetId();
|
||||
@@ -405,8 +395,7 @@ void WebRtc::ProcessLocalIceCandidate(
|
||||
webrtc_frames::EncodeIceCandidates(
|
||||
accepting_connection_entry->second.self_peer_id,
|
||||
{ice_candidate}))) {
|
||||
LOG(INFO) << "Failed to send ice candidate to "
|
||||
<< remote_peer_id.GetId();
|
||||
LOG(INFO) << "Failed to send ice candidate to " << remote_peer_id.GetId();
|
||||
}
|
||||
|
||||
LOG(INFO) << "Sent ice candidate to " << remote_peer_id.GetId();
|
||||
@@ -414,8 +403,8 @@ void WebRtc::ProcessLocalIceCandidate(
|
||||
}
|
||||
|
||||
LOG(INFO) << "Skipping restart listening for tachyon inbox messages "
|
||||
"since we are not accepting connections for service "
|
||||
<< service_id;
|
||||
"since we are not accepting connections for service "
|
||||
<< service_id;
|
||||
}
|
||||
|
||||
void WebRtc::OnSignalingMessage(const std::string& service_id,
|
||||
@@ -508,23 +497,20 @@ void WebRtc::SendOffer(const std::string& service_id,
|
||||
std::unique_ptr<ConnectionFlow> connection_flow =
|
||||
CreateConnectionFlow(service_id, remote_peer_id);
|
||||
if (!connection_flow) {
|
||||
LOG(INFO)
|
||||
<< "Unable to send offer. Failed to create a ConnectionFlow.";
|
||||
LOG(INFO) << "Unable to send offer. Failed to create a ConnectionFlow.";
|
||||
return;
|
||||
}
|
||||
|
||||
SessionDescriptionWrapper offer = connection_flow->CreateOffer();
|
||||
if (!offer.IsValid()) {
|
||||
LOG(INFO)
|
||||
<< "Unable to send offer. Failed to create our offer locally.";
|
||||
LOG(INFO) << "Unable to send offer. Failed to create our offer locally.";
|
||||
RemoveConnectionFlow(remote_peer_id);
|
||||
return;
|
||||
}
|
||||
|
||||
const webrtc::SessionDescriptionInterface& sdp = offer.GetSdp();
|
||||
if (!connection_flow->SetLocalSessionDescription(offer)) {
|
||||
LOG(INFO)
|
||||
<< "Unable to send offer. Failed to register our offer locally.";
|
||||
LOG(INFO) << "Unable to send offer. Failed to register our offer locally.";
|
||||
RemoveConnectionFlow(remote_peer_id);
|
||||
return;
|
||||
}
|
||||
@@ -552,14 +538,12 @@ void WebRtc::ReceiveOffer(const WebrtcPeerId& remote_peer_id,
|
||||
SessionDescriptionWrapper offer) {
|
||||
const auto& entry = connection_flows_.find(remote_peer_id.GetId());
|
||||
if (entry == connection_flows_.end()) {
|
||||
LOG(INFO)
|
||||
<< "Unable to receive offer. Failed to create a ConnectionFlow.";
|
||||
LOG(INFO) << "Unable to receive offer. Failed to create a ConnectionFlow.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!entry->second->OnOfferReceived(offer)) {
|
||||
LOG(INFO)
|
||||
<< "Unable to receive offer. Failed to process the offer.";
|
||||
LOG(INFO) << "Unable to receive offer. Failed to process the offer.";
|
||||
RemoveConnectionFlow(remote_peer_id);
|
||||
}
|
||||
}
|
||||
@@ -567,15 +551,13 @@ void WebRtc::ReceiveOffer(const WebrtcPeerId& remote_peer_id,
|
||||
void WebRtc::SendAnswer(const WebrtcPeerId& remote_peer_id) {
|
||||
const auto& entry = connection_flows_.find(remote_peer_id.GetId());
|
||||
if (entry == connection_flows_.end()) {
|
||||
LOG(INFO)
|
||||
<< "Unable to send answer. Failed to create a ConnectionFlow.";
|
||||
LOG(INFO) << "Unable to send answer. Failed to create a ConnectionFlow.";
|
||||
return;
|
||||
}
|
||||
|
||||
SessionDescriptionWrapper answer = entry->second->CreateAnswer();
|
||||
if (!answer.IsValid()) {
|
||||
LOG(INFO)
|
||||
<< "Unable to send answer. Failed to create our answer locally.";
|
||||
LOG(INFO) << "Unable to send answer. Failed to create our answer locally.";
|
||||
RemoveConnectionFlow(remote_peer_id);
|
||||
return;
|
||||
}
|
||||
@@ -593,7 +575,7 @@ void WebRtc::SendAnswer(const WebrtcPeerId& remote_peer_id) {
|
||||
requesting_connections_info_.find(remote_peer_id.GetId());
|
||||
if (connection_request_entry == requesting_connections_info_.end()) {
|
||||
LOG(INFO) << "Unable to send answer. Failed to find an outgoing "
|
||||
"connection request.";
|
||||
"connection request.";
|
||||
RemoveConnectionFlow(remote_peer_id);
|
||||
return;
|
||||
}
|
||||
@@ -618,14 +600,12 @@ void WebRtc::ReceiveAnswer(const WebrtcPeerId& remote_peer_id,
|
||||
SessionDescriptionWrapper answer) {
|
||||
const auto& entry = connection_flows_.find(remote_peer_id.GetId());
|
||||
if (entry == connection_flows_.end()) {
|
||||
LOG(INFO)
|
||||
<< "Unable to receive answer. Failed to create a ConnectionFlow.";
|
||||
LOG(INFO) << "Unable to receive answer. Failed to create a ConnectionFlow.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!entry->second->OnAnswerReceived(answer)) {
|
||||
LOG(INFO)
|
||||
<< "Unable to receive answer. Failed to process the answer.";
|
||||
LOG(INFO) << "Unable to receive answer. Failed to process the answer.";
|
||||
RemoveConnectionFlow(remote_peer_id);
|
||||
}
|
||||
}
|
||||
@@ -637,7 +617,7 @@ void WebRtc::ReceiveIceCandidates(
|
||||
const auto& entry = connection_flows_.find(remote_peer_id.GetId());
|
||||
if (entry == connection_flows_.end()) {
|
||||
LOG(INFO) << "Unable to receive ice candidates. Failed to create a "
|
||||
"ConnectionFlow.";
|
||||
"ConnectionFlow.";
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -677,8 +657,8 @@ void WebRtc::RestartTachyonReceiveMessages(const std::string& service_id) {
|
||||
}
|
||||
|
||||
LOG(INFO) << "Successfully restarted listening for tachyon inbox "
|
||||
"messages on service "
|
||||
<< service_id;
|
||||
"messages on service "
|
||||
<< service_id;
|
||||
}
|
||||
|
||||
void WebRtc::ProcessDataChannelOpen(const std::string& service_id,
|
||||
@@ -706,15 +686,14 @@ void WebRtc::ProcessDataChannelOpen(const std::string& service_id,
|
||||
// No one to handle the newly created DataChannel, so we'll just close it.
|
||||
socket_wrapper.Close();
|
||||
LOG(INFO) << "Ignoring new DataChannel because we are not accepting "
|
||||
"connections for service "
|
||||
<< service_id;
|
||||
"connections for service "
|
||||
<< service_id;
|
||||
}
|
||||
|
||||
void WebRtc::ProcessDataChannelClosed(const WebrtcPeerId& remote_peer_id) {
|
||||
MutexLock lock(&mutex_);
|
||||
LOG(INFO)
|
||||
<< "Data channel has closed, removing connection flow for peer "
|
||||
<< remote_peer_id.GetId();
|
||||
LOG(INFO) << "Data channel has closed, removing connection flow for peer "
|
||||
<< remote_peer_id.GetId();
|
||||
|
||||
RemoveConnectionFlow(remote_peer_id);
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ class CreateSessionDescriptionObserverImpl
|
||||
|
||||
void OnFailure(webrtc::RTCError error) override {
|
||||
LOG(ERROR) << "Error when creating session description: "
|
||||
<< error.message();
|
||||
<< error.message();
|
||||
settable_future_.SetException({Exception::kFailed});
|
||||
}
|
||||
|
||||
@@ -252,7 +252,7 @@ bool ConnectionFlow::SetLocalSessionDescription(SessionDescriptionWrapper sdp) {
|
||||
bool success = result.ok() && result.result();
|
||||
if (!success) {
|
||||
LOG(ERROR) << "Failed to set local session description: "
|
||||
<< result.exception();
|
||||
<< result.exception();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
@@ -284,8 +284,7 @@ bool ConnectionFlow::SetRemoteSessionDescription(SessionDescriptionWrapper sdp,
|
||||
ExceptionOr<bool> result = observer->GetResult(kTimeout);
|
||||
bool success = result.ok() && result.result();
|
||||
if (!success) {
|
||||
LOG(ERROR) << "Failed to set remote description: "
|
||||
<< result.exception();
|
||||
LOG(ERROR) << "Failed to set remote description: " << result.exception();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
@@ -330,8 +329,7 @@ void ConnectionFlow::AddIceCandidatesOnSignalingThread(
|
||||
ice_candidates) {
|
||||
CHECK(IsRunningOnSignalingThread());
|
||||
if (state_ == State::kEnded) {
|
||||
LOG(WARNING)
|
||||
<< "You cannot add ice candidates to a disconnected session.";
|
||||
LOG(WARNING) << "You cannot add ice candidates to a disconnected session.";
|
||||
return;
|
||||
}
|
||||
if (state_ != State::kWaitingToConnect && state_ != State::kConnected) {
|
||||
@@ -397,8 +395,7 @@ bool ConnectionFlow::InitPeerConnection(WebRtcMedium& webrtc_medium) {
|
||||
bool success = result.ok() && result.result();
|
||||
if (!success) {
|
||||
shutdown_latch_.CountDown();
|
||||
LOG(ERROR) << "Failed to create peer connection: "
|
||||
<< result.exception();
|
||||
LOG(ERROR) << "Failed to create peer connection: " << result.exception();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
@@ -424,7 +421,7 @@ void ConnectionFlow::CreateSocketFromDataChannel(
|
||||
CHECK(IsRunningOnSignalingThread());
|
||||
if (!TransitionState(State::kWaitingToConnect, State::kConnected)) {
|
||||
LOG(ERROR) << "Data channel socket is open but connection "
|
||||
"flow was not in the required state";
|
||||
"flow was not in the required state";
|
||||
socket->Close();
|
||||
return;
|
||||
}
|
||||
@@ -475,7 +472,7 @@ void ConnectionFlow::OnConnectionChange(
|
||||
new_state == PeerConnectionState::kFailed ||
|
||||
new_state == PeerConnectionState::kDisconnected) {
|
||||
LOG(INFO) << "Closing due to peer connection state change: "
|
||||
<< static_cast<int>(new_state);
|
||||
<< static_cast<int>(new_state);
|
||||
CloseOnSignalingThread();
|
||||
}
|
||||
}
|
||||
@@ -499,13 +496,13 @@ bool ConnectionFlow::TransitionState(State current_state, State new_state) {
|
||||
CHECK(IsRunningOnSignalingThread());
|
||||
if (current_state != state_) {
|
||||
LOG(WARNING) << "Invalid state transition to "
|
||||
<< static_cast<int>(new_state) << ": current state is "
|
||||
<< static_cast<int>(state_) << " but expected "
|
||||
<< static_cast<int>(current_state);
|
||||
<< static_cast<int>(new_state) << ": current state is "
|
||||
<< static_cast<int>(state_) << " but expected "
|
||||
<< static_cast<int>(current_state);
|
||||
return false;
|
||||
}
|
||||
LOG(INFO) << "Transition: " << static_cast<int>(state_) << "->"
|
||||
<< static_cast<int>(new_state);
|
||||
<< static_cast<int>(new_state);
|
||||
state_ = new_state;
|
||||
return true;
|
||||
}
|
||||
@@ -540,25 +537,24 @@ bool ConnectionFlow::RunOnSignalingThread(Runnable&& runnable) {
|
||||
CHECK(!IsRunningOnSignalingThread());
|
||||
auto pc = GetPeerConnection();
|
||||
if (!pc) {
|
||||
LOG(WARNING)
|
||||
<< "Peer connection not available. Cannot schedule tasks.";
|
||||
LOG(WARNING) << "Peer connection not available. Cannot schedule tasks.";
|
||||
return false;
|
||||
}
|
||||
// We are off signaling thread, so we can't use peer connection's methods
|
||||
// but we can access the signaling thread handle.
|
||||
pc->signaling_thread()->PostTask([can_run_tasks =
|
||||
std::weak_ptr<void>(can_run_tasks_),
|
||||
task = std::move(runnable)]() mutable {
|
||||
// Don't run the task if the weak_ptr is no longer valid.
|
||||
// shared_ptr |can_run_tasks_| is destroyed on the same thread
|
||||
// (signaling thread). This guarantees that if the weak_ptr is valid
|
||||
// when this task starts, it will stay valid until the task ends.
|
||||
if (!can_run_tasks.lock()) {
|
||||
LOG(INFO) << "Peer connection already closed. Cannot run tasks.";
|
||||
return;
|
||||
}
|
||||
task();
|
||||
});
|
||||
pc->signaling_thread()->PostTask(
|
||||
[can_run_tasks = std::weak_ptr<void>(can_run_tasks_),
|
||||
task = std::move(runnable)]() mutable {
|
||||
// Don't run the task if the weak_ptr is no longer valid.
|
||||
// shared_ptr |can_run_tasks_| is destroyed on the same thread
|
||||
// (signaling thread). This guarantees that if the weak_ptr is valid
|
||||
// when this task starts, it will stay valid until the task ends.
|
||||
if (!can_run_tasks.lock()) {
|
||||
LOG(INFO) << "Peer connection already closed. Cannot run tasks.";
|
||||
return;
|
||||
}
|
||||
task();
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,23 +67,21 @@ WebRtcSocket::WebRtcSocket(
|
||||
const std::string& name,
|
||||
webrtc::scoped_refptr<webrtc::DataChannelInterface> data_channel)
|
||||
: name_(name), data_channel_(std::move(data_channel)) {
|
||||
LOG(INFO) << "WebRtcSocket::WebRtcSocket(" << name_
|
||||
<< ") this: " << this;
|
||||
LOG(INFO) << "WebRtcSocket::WebRtcSocket(" << name_ << ") this: " << this;
|
||||
std::tie(pipe_input_, pipe_output_) = CreatePipe();
|
||||
data_channel_->RegisterObserver(this);
|
||||
}
|
||||
|
||||
WebRtcSocket::~WebRtcSocket() {
|
||||
LOG(INFO) << "WebRtcSocket::~WebRtcSocket(" << name_
|
||||
<< ") this: " << this;
|
||||
LOG(INFO) << "WebRtcSocket::~WebRtcSocket(" << name_ << ") this: " << this;
|
||||
|
||||
if (!IsClosed()) {
|
||||
data_channel_->UnregisterObserver();
|
||||
Close();
|
||||
}
|
||||
|
||||
LOG(INFO) << "WebRtcSocket::~WebRtcSocket(" << name_
|
||||
<< ") this: " << this << " done";
|
||||
LOG(INFO) << "WebRtcSocket::~WebRtcSocket(" << name_ << ") this: " << this
|
||||
<< " done";
|
||||
}
|
||||
|
||||
InputStream& WebRtcSocket::GetInputStream() { return *pipe_input_; }
|
||||
@@ -99,16 +97,15 @@ Exception WebRtcSocket::Close() {
|
||||
// to 'closing' but does not block until 'closed' is sent so the data channel
|
||||
// is not fully closed when this call is done.
|
||||
data_channel_->Close();
|
||||
LOG(INFO) << "WebRtcSocket::Close(" << name_ << ") this: " << this
|
||||
<< " done";
|
||||
LOG(INFO) << "WebRtcSocket::Close(" << name_ << ") this: " << this << " done";
|
||||
return {Exception::kSuccess};
|
||||
}
|
||||
|
||||
void WebRtcSocket::OnStateChange() {
|
||||
// Running on the signaling thread right now.
|
||||
LOG(ERROR)
|
||||
<< "WebRtcSocket::OnStateChange() webrtc data channel state: "
|
||||
<< webrtc::DataChannelInterface::DataStateString(data_channel_->state());
|
||||
LOG(ERROR) << "WebRtcSocket::OnStateChange() webrtc data channel state: "
|
||||
<< webrtc::DataChannelInterface::DataStateString(
|
||||
data_channel_->state());
|
||||
switch (data_channel_->state()) {
|
||||
case webrtc::DataChannelInterface::DataState::kConnecting:
|
||||
break;
|
||||
@@ -121,7 +118,7 @@ void WebRtcSocket::OnStateChange() {
|
||||
break;
|
||||
case webrtc::DataChannelInterface::DataState::kClosed:
|
||||
LOG(ERROR) << "WebRtcSocket::OnStateChange() unregistering data "
|
||||
"channel observer.";
|
||||
"channel observer.";
|
||||
// This will trigger a destruction of the owning connection flow
|
||||
// We implicitly depend on the |socket_listener_| to offload from
|
||||
// the signaling thread so it does not get blocked.
|
||||
@@ -163,8 +160,7 @@ bool WebRtcSocket::SendMessage(const ByteArray& data) {
|
||||
bool WebRtcSocket::IsClosed() { return closed_.Get(); }
|
||||
|
||||
void WebRtcSocket::ClosePipe() {
|
||||
LOG(INFO) << "WebRtcSocket::ClosePipe(" << name_
|
||||
<< ") this: " << this;
|
||||
LOG(INFO) << "WebRtcSocket::ClosePipe(" << name_ << ") this: " << this;
|
||||
// This is thread-safe to close these sockets even if a read or write is in
|
||||
// process on another thread, Close will wait for the exclusive mutex before
|
||||
// setting state.
|
||||
@@ -172,7 +168,7 @@ void WebRtcSocket::ClosePipe() {
|
||||
pipe_output_->Close();
|
||||
WakeUpWriter();
|
||||
LOG(INFO) << "WebRtcSocket::ClosePipe(" << name_ << ") this: " << this
|
||||
<< " done";
|
||||
<< " done";
|
||||
}
|
||||
|
||||
// Must not be called on signalling thread.
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
#include "internal/platform/expected.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/mutex_lock.h"
|
||||
#include "internal/platform/wifi_direct.h"
|
||||
#include "internal/platform/wifi_credential.h"
|
||||
#include "internal/platform/wifi_direct.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
@@ -106,8 +106,7 @@ bool WifiDirect::ConnectWifiDirect(const std::string& ssid,
|
||||
const std::string& password) {
|
||||
MutexLock lock(&mutex_);
|
||||
if (is_connected_to_go_) {
|
||||
LOG(INFO)
|
||||
<< "No need to connect to GO because it is already connected.";
|
||||
LOG(INFO) << "No need to connect to GO because it is already connected.";
|
||||
return true;
|
||||
}
|
||||
is_connected_to_go_ = medium_.ConnectWifiDirect(ssid, password);
|
||||
@@ -117,8 +116,7 @@ bool WifiDirect::ConnectWifiDirect(const std::string& ssid,
|
||||
bool WifiDirect::DisconnectWifiDirect() {
|
||||
MutexLock lock(&mutex_);
|
||||
if (!is_connected_to_go_) {
|
||||
LOG(INFO)
|
||||
<< "No need to disconnect to GO because it is not connected.";
|
||||
LOG(INFO) << "No need to disconnect to GO because it is not connected.";
|
||||
return true;
|
||||
}
|
||||
is_connected_to_go_ = false;
|
||||
@@ -134,7 +132,7 @@ WifiDirectCredentials* WifiDirect::GetCredentials(
|
||||
const auto& it = server_sockets_.find(service_id);
|
||||
if (it == server_sockets_.end()) {
|
||||
LOG(INFO) << "No server socket found for service_id:" << service_id
|
||||
<< ". Use default credentials";
|
||||
<< ". Use default credentials";
|
||||
return crendential;
|
||||
}
|
||||
crendential->SetGateway(it->second.GetIPAddress());
|
||||
@@ -149,9 +147,8 @@ bool WifiDirect::StartAcceptingConnections(
|
||||
MutexLock lock(&mutex_);
|
||||
|
||||
if (service_id.empty()) {
|
||||
LOG(INFO)
|
||||
<< "Can not to start accepting WifiDirect GC's connections; "
|
||||
"service_id is empty.";
|
||||
LOG(INFO) << "Can not to start accepting WifiDirect GC's connections; "
|
||||
"service_id is empty.";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -211,16 +208,15 @@ bool WifiDirect::StopAcceptingConnections(const std::string& service_id) {
|
||||
MutexLock lock(&mutex_);
|
||||
|
||||
if (service_id.empty()) {
|
||||
LOG(INFO)
|
||||
<< "Unable to stop accepting WifiDirect GC's connections because "
|
||||
"the service_id is empty.";
|
||||
LOG(INFO) << "Unable to stop accepting WifiDirect GC's connections because "
|
||||
"the service_id is empty.";
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto& it = server_sockets_.find(service_id);
|
||||
if (it == server_sockets_.end()) {
|
||||
LOG(INFO) << "Can't stop accepting WifiDirect GC's connections for "
|
||||
<< service_id << " because it was never started.";
|
||||
<< service_id << " because it was never started.";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -241,9 +237,8 @@ bool WifiDirect::StopAcceptingConnections(const std::string& service_id) {
|
||||
|
||||
// Finally, close the WifiDirectServerSocket.
|
||||
if (!listening_socket.Close().Ok()) {
|
||||
LOG(INFO)
|
||||
<< "Failed to close WifiDirect server socket for service_id:"
|
||||
<< service_id;
|
||||
LOG(INFO) << "Failed to close WifiDirect server socket for service_id:"
|
||||
<< service_id;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -268,13 +263,13 @@ ErrorOr<WifiDirectSocket> WifiDirect::Connect(
|
||||
|
||||
if (service_id.empty()) {
|
||||
LOG(INFO) << "Refusing to create client WifiDirect socket because "
|
||||
"service_id is empty.";
|
||||
"service_id is empty.";
|
||||
return {Error(OperationResultCode::NEARBY_LOCAL_CLIENT_STATE_WRONG)};
|
||||
}
|
||||
|
||||
if (!IsGCAvailableLocked()) {
|
||||
LOG(INFO) << "Can't create WifiDirect client socket [service_id="
|
||||
<< service_id << "]; WifiDirect GC isn't available.";
|
||||
<< service_id << "]; WifiDirect GC isn't available.";
|
||||
return {Error(
|
||||
OperationResultCode::MEDIUM_UNAVAILABLE_WIFI_DIRECT_NOT_AVAILABLE)};
|
||||
}
|
||||
@@ -289,7 +284,7 @@ ErrorOr<WifiDirectSocket> WifiDirect::Connect(
|
||||
socket = medium_.ConnectToService(ip_address, port, cancellation_flag);
|
||||
if (!socket.IsValid()) {
|
||||
LOG(INFO) << "Failed to Connect via WifiDirect Server [service_id="
|
||||
<< service_id << "]";
|
||||
<< service_id << "]";
|
||||
return {Error(OperationResultCode::
|
||||
CONNECTIVITY_WIFI_DIRECT_CLIENT_SOCKET_CREATION_FAILURE)};
|
||||
}
|
||||
|
||||
@@ -75,8 +75,7 @@ bool WifiHotspot::IsHotspotStarted() {
|
||||
bool WifiHotspot::StartWifiHotspot() {
|
||||
MutexLock lock(&mutex_);
|
||||
if (is_hotspot_started_) {
|
||||
LOG(INFO)
|
||||
<< "No need to start Hotspot because it is already started.";
|
||||
LOG(INFO) << "No need to start Hotspot because it is already started.";
|
||||
return true;
|
||||
}
|
||||
is_hotspot_started_ = medium_.StartWifiHotspot();
|
||||
@@ -132,7 +131,7 @@ HotspotCredentials* WifiHotspot::GetCredentials(absl::string_view service_id) {
|
||||
const auto& it = server_sockets_.find(service_id);
|
||||
if (it == server_sockets_.end()) {
|
||||
LOG(INFO) << "No server socket found for service_id:" << service_id
|
||||
<< ". Use default credentials";
|
||||
<< ". Use default credentials";
|
||||
return crendential;
|
||||
}
|
||||
crendential->SetGateway(it->second.GetIPAddress());
|
||||
@@ -148,14 +147,13 @@ bool WifiHotspot::StartAcceptingConnections(
|
||||
|
||||
if (service_id.empty()) {
|
||||
LOG(INFO) << "Can not to start accepting WifiHotspot connections; "
|
||||
"service_id is empty.";
|
||||
"service_id is empty.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsAPAvailableLocked()) {
|
||||
LOG(INFO)
|
||||
<< "Can't start accepting WifiHotspot connections [service_id="
|
||||
<< service_id << "]; WifiHotspot not available.";
|
||||
LOG(INFO) << "Can't start accepting WifiHotspot connections [service_id="
|
||||
<< service_id << "]; WifiHotspot not available.";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -208,16 +206,15 @@ bool WifiHotspot::StopAcceptingConnections(const std::string& service_id) {
|
||||
MutexLock lock(&mutex_);
|
||||
|
||||
if (service_id.empty()) {
|
||||
LOG(INFO)
|
||||
<< "Unable to stop accepting WifiHotspot connections because "
|
||||
"the service_id is empty.";
|
||||
LOG(INFO) << "Unable to stop accepting WifiHotspot connections because "
|
||||
"the service_id is empty.";
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto& it = server_sockets_.find(service_id);
|
||||
if (it == server_sockets_.end()) {
|
||||
LOG(INFO) << "Can't stop accepting WifiHotspot connections for "
|
||||
<< service_id << " because it was never started.";
|
||||
<< service_id << " because it was never started.";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -238,9 +235,8 @@ bool WifiHotspot::StopAcceptingConnections(const std::string& service_id) {
|
||||
|
||||
// Finally, close the WifiHotspotServerSocket.
|
||||
if (!listening_socket.Close().Ok()) {
|
||||
LOG(INFO)
|
||||
<< "Failed to close WifiHotspot server socket for service_id:"
|
||||
<< service_id;
|
||||
LOG(INFO) << "Failed to close WifiHotspot server socket for service_id:"
|
||||
<< service_id;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -265,13 +261,13 @@ ErrorOr<WifiHotspotSocket> WifiHotspot::Connect(
|
||||
|
||||
if (service_id.empty()) {
|
||||
LOG(INFO) << "Refusing to create client WifiHotspot socket because "
|
||||
"service_id is empty.";
|
||||
"service_id is empty.";
|
||||
return {Error(OperationResultCode::NEARBY_LOCAL_CLIENT_STATE_WRONG)};
|
||||
}
|
||||
|
||||
if (!IsClientAvailableLocked()) {
|
||||
LOG(INFO) << "Can't create client WifiHotspot socket [service_id="
|
||||
<< service_id << "]; WifiHotspot isn't available.";
|
||||
<< service_id << "]; WifiHotspot isn't available.";
|
||||
return {Error(
|
||||
OperationResultCode::MEDIUM_UNAVAILABLE_WIFI_HOTSPOT_NOT_AVAILABLE)};
|
||||
}
|
||||
@@ -285,8 +281,8 @@ ErrorOr<WifiHotspotSocket> WifiHotspot::Connect(
|
||||
|
||||
socket = medium_.ConnectToService(ip_address, port, cancellation_flag);
|
||||
if (!socket.IsValid()) {
|
||||
LOG(INFO) << "Failed to Connect via WifiHotspot [service_id="
|
||||
<< service_id << "]";
|
||||
LOG(INFO) << "Failed to Connect via WifiHotspot [service_id=" << service_id
|
||||
<< "]";
|
||||
return {
|
||||
Error(OperationResultCode::
|
||||
CONNECTIVITY_WIFI_HOTSPOT_CLIENT_SOCKET_CREATION_FAILURE)};
|
||||
|
||||
@@ -59,8 +59,8 @@ WifiLan::~WifiLan() {
|
||||
{
|
||||
MutexLock lock(&mutex_);
|
||||
if (is_multiplex_enabled_) {
|
||||
LOG(INFO) << "Closing multiplex sockets for "
|
||||
<< multiplex_sockets_.size() << " IPs";
|
||||
LOG(INFO) << "Closing multiplex sockets for " << multiplex_sockets_.size()
|
||||
<< " IPs";
|
||||
for (auto& [ip_addr, multiplex_socket] : multiplex_sockets_) {
|
||||
LOG(INFO) << "Closing multiplex sockets for: " << ip_addr;
|
||||
multiplex_socket->~MultiplexSocket();
|
||||
@@ -87,8 +87,7 @@ ErrorOr<bool> WifiLan::StartAdvertising(const std::string& service_id,
|
||||
MutexLock lock(&mutex_);
|
||||
|
||||
if (!IsAvailableLocked()) {
|
||||
LOG(INFO)
|
||||
<< "Can't turn on WifiLan advertising. WifiLan is not available.";
|
||||
LOG(INFO) << "Can't turn on WifiLan advertising. WifiLan is not available.";
|
||||
return {Error(OperationResultCode::MEDIUM_UNAVAILABLE_LAN_NOT_AVAILABLE)};
|
||||
}
|
||||
|
||||
@@ -106,12 +105,11 @@ ErrorOr<bool> WifiLan::StartAdvertising(const std::string& service_id,
|
||||
}
|
||||
|
||||
if (!IsAcceptingConnectionsLocked(service_id)) {
|
||||
LOG(INFO)
|
||||
<< "Failed to turn on WifiLan advertising with nsd_service_info="
|
||||
<< &nsd_service_info
|
||||
<< ", service_name=" << nsd_service_info.GetServiceName()
|
||||
<< ", service_id=" << service_id
|
||||
<< ". Should accept connections before advertising.";
|
||||
LOG(INFO) << "Failed to turn on WifiLan advertising with nsd_service_info="
|
||||
<< &nsd_service_info
|
||||
<< ", service_name=" << nsd_service_info.GetServiceName()
|
||||
<< ", service_id=" << service_id
|
||||
<< ". Should accept connections before advertising.";
|
||||
return {Error(OperationResultCode::
|
||||
CLIENT_DUPLICATE_ACCEPTING_LAN_CONNECTION_REQUEST)};
|
||||
}
|
||||
@@ -123,19 +121,18 @@ ErrorOr<bool> WifiLan::StartAdvertising(const std::string& service_id,
|
||||
nsd_service_info.SetPort(it->second.GetPort());
|
||||
}
|
||||
if (!medium_.StartAdvertising(nsd_service_info)) {
|
||||
LOG(INFO)
|
||||
<< "Failed to turn on WifiLan advertising with nsd_service_info="
|
||||
<< &nsd_service_info
|
||||
<< ", service_name=" << nsd_service_info.GetServiceName()
|
||||
<< ", service_id=" << service_id;
|
||||
LOG(INFO) << "Failed to turn on WifiLan advertising with nsd_service_info="
|
||||
<< &nsd_service_info
|
||||
<< ", service_name=" << nsd_service_info.GetServiceName()
|
||||
<< ", service_id=" << service_id;
|
||||
return {Error(
|
||||
OperationResultCode::CONNECTIVITY_WIFI_LAN_START_ADVERTISING_FAILURE)};
|
||||
}
|
||||
|
||||
LOG(INFO) << "Turned on WifiLan advertising with nsd_service_info="
|
||||
<< &nsd_service_info
|
||||
<< ", service_name=" << nsd_service_info.GetServiceName()
|
||||
<< ", service_id=" << service_id;
|
||||
<< &nsd_service_info
|
||||
<< ", service_name=" << nsd_service_info.GetServiceName()
|
||||
<< ", service_id=" << service_id;
|
||||
advertising_info_.Add(service_id, std::move(nsd_service_info));
|
||||
return {true};
|
||||
}
|
||||
@@ -144,13 +141,11 @@ bool WifiLan::StopAdvertising(const std::string& service_id) {
|
||||
MutexLock lock(&mutex_);
|
||||
|
||||
if (!IsAdvertisingLocked(service_id)) {
|
||||
LOG(INFO)
|
||||
<< "Can't turn off WifiLan advertising; it is already off";
|
||||
LOG(INFO) << "Can't turn off WifiLan advertising; it is already off";
|
||||
return false;
|
||||
}
|
||||
|
||||
LOG(INFO) << "Turned off WifiLan advertising with service_id="
|
||||
<< service_id;
|
||||
LOG(INFO) << "Turned off WifiLan advertising with service_id=" << service_id;
|
||||
bool ret =
|
||||
medium_.StopAdvertising(*advertising_info_.GetServiceInfo(service_id));
|
||||
// Reset our bundle of advertising state to mark that we're no longer
|
||||
@@ -174,8 +169,7 @@ ErrorOr<bool> WifiLan::StartDiscovery(const std::string& service_id,
|
||||
MutexLock lock(&mutex_);
|
||||
|
||||
if (service_id.empty()) {
|
||||
LOG(INFO)
|
||||
<< "Refusing to start WifiLan discovering with empty service_id.";
|
||||
LOG(INFO) << "Refusing to start WifiLan discovering with empty service_id.";
|
||||
return {Error(OperationResultCode::NEARBY_LOCAL_CLIENT_STATE_WRONG)};
|
||||
}
|
||||
|
||||
@@ -202,8 +196,7 @@ ErrorOr<bool> WifiLan::StartDiscovery(const std::string& service_id,
|
||||
OperationResultCode::CONNECTIVITY_WIFI_LAN_START_DISCOVERY_FAILURE)};
|
||||
}
|
||||
|
||||
LOG(INFO) << "Turned on WifiLan discovering with service_id="
|
||||
<< service_id;
|
||||
LOG(INFO) << "Turned on WifiLan discovering with service_id=" << service_id;
|
||||
// Mark the fact that we're currently performing a WifiLan discovering.
|
||||
discovering_info_.Add(service_id);
|
||||
return {true};
|
||||
@@ -213,15 +206,14 @@ bool WifiLan::StopDiscovery(const std::string& service_id) {
|
||||
MutexLock lock(&mutex_);
|
||||
|
||||
if (!IsDiscoveringLocked(service_id)) {
|
||||
LOG(INFO)
|
||||
<< "Can't turn off WifiLan discovering because we never started "
|
||||
"discovering.";
|
||||
LOG(INFO) << "Can't turn off WifiLan discovering because we never started "
|
||||
"discovering.";
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string service_type = GenerateServiceType(service_id);
|
||||
LOG(INFO) << "Turned off WifiLan discovering with service_id="
|
||||
<< service_id << ", service_type=" << service_type;
|
||||
LOG(INFO) << "Turned off WifiLan discovering with service_id=" << service_id
|
||||
<< ", service_type=" << service_type;
|
||||
bool ret = medium_.StopDiscovery(service_type);
|
||||
discovering_info_.Remove(service_id);
|
||||
return ret;
|
||||
@@ -242,23 +234,21 @@ ErrorOr<bool> WifiLan::StartAcceptingConnections(
|
||||
|
||||
if (service_id.empty()) {
|
||||
LOG(INFO) << "Refusing to start accepting WifiLan connections; "
|
||||
"service_id is empty.";
|
||||
"service_id is empty.";
|
||||
return {Error(OperationResultCode::NEARBY_LOCAL_CLIENT_STATE_WRONG)};
|
||||
}
|
||||
|
||||
if (!IsAvailableLocked()) {
|
||||
LOG(INFO)
|
||||
<< "Can't start accepting WifiLan connections [service_id="
|
||||
<< service_id << "]; WifiLan not available.";
|
||||
LOG(INFO) << "Can't start accepting WifiLan connections [service_id="
|
||||
<< service_id << "]; WifiLan not available.";
|
||||
return {Error(
|
||||
OperationResultCode::MEDIUM_UNAVAILABLE_WIFI_AWARE_NOT_AVAILABLE)};
|
||||
}
|
||||
|
||||
if (IsAcceptingConnectionsLocked(service_id)) {
|
||||
LOG(INFO)
|
||||
<< "Refusing to start accepting WifiLan connections [service="
|
||||
<< service_id
|
||||
<< "]; WifiLan server is already in-progress with the same name.";
|
||||
LOG(INFO) << "Refusing to start accepting WifiLan connections [service="
|
||||
<< service_id
|
||||
<< "]; WifiLan server is already in-progress with the same name.";
|
||||
return {Error(OperationResultCode::
|
||||
CLIENT_DUPLICATE_ACCEPTING_LAN_CONNECTION_REQUEST)};
|
||||
}
|
||||
@@ -275,9 +265,8 @@ ErrorOr<bool> WifiLan::StartAcceptingConnections(
|
||||
}
|
||||
WifiLanServerSocket server_socket = medium_.ListenForService(port);
|
||||
if (!server_socket.IsValid()) {
|
||||
LOG(INFO)
|
||||
<< "Failed to start accepting WifiLan connections for service_id="
|
||||
<< service_id;
|
||||
LOG(INFO) << "Failed to start accepting WifiLan connections for service_id="
|
||||
<< service_id;
|
||||
return {Error(OperationResultCode::
|
||||
CLIENT_CANCELLATION_WIFI_LAN_SERVER_SOCKET_CREATION)};
|
||||
}
|
||||
@@ -351,7 +340,7 @@ ErrorOr<bool> WifiLan::StartAcceptingConnections(
|
||||
MultiplexSocket::StopListeningForIncomingConnection(
|
||||
service_id, Medium::WIFI_LAN);
|
||||
LOG(INFO) << "Multiplex virtaul socket created for "
|
||||
<< server_socket.GetIPAddress();
|
||||
<< server_socket.GetIPAddress();
|
||||
if (callback) {
|
||||
callback(
|
||||
service_id,
|
||||
@@ -377,14 +366,14 @@ bool WifiLan::StopAcceptingConnections(const std::string& service_id) {
|
||||
|
||||
if (service_id.empty()) {
|
||||
LOG(INFO) << "Unable to stop accepting WifiLan connections because "
|
||||
"the service_id is empty.";
|
||||
"the service_id is empty.";
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto& it = server_sockets_.find(service_id);
|
||||
if (it == server_sockets_.end()) {
|
||||
LOG(INFO) << "Can't stop accepting WifiLan connections for "
|
||||
<< service_id << " because it was never started.";
|
||||
LOG(INFO) << "Can't stop accepting WifiLan connections for " << service_id
|
||||
<< " because it was never started.";
|
||||
return false;
|
||||
}
|
||||
if (is_multiplex_enabled_) {
|
||||
@@ -410,7 +399,7 @@ bool WifiLan::StopAcceptingConnections(const std::string& service_id) {
|
||||
// Finally, close the WifiLanServerSocket.
|
||||
if (!listening_socket.Close().Ok()) {
|
||||
LOG(INFO) << "Failed to close WifiLan server socket for service_id="
|
||||
<< service_id;
|
||||
<< service_id;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -435,13 +424,13 @@ ErrorOr<WifiLanSocket> WifiLan::Connect(const std::string& service_id,
|
||||
|
||||
if (service_id.empty()) {
|
||||
LOG(INFO) << "Refusing to create client WifiLan socket because "
|
||||
"service_id is empty.";
|
||||
"service_id is empty.";
|
||||
return {Error(OperationResultCode::NEARBY_LOCAL_CLIENT_STATE_WRONG)};
|
||||
}
|
||||
|
||||
if (!IsAvailableLocked()) {
|
||||
LOG(INFO) << "Can't create client WifiLan socket [service_id="
|
||||
<< service_id << "]; WifiLan isn't available.";
|
||||
LOG(INFO) << "Can't create client WifiLan socket [service_id=" << service_id
|
||||
<< "]; WifiLan isn't available.";
|
||||
return {Error(OperationResultCode::MEDIUM_UNAVAILABLE_LAN_NOT_AVAILABLE)};
|
||||
}
|
||||
|
||||
@@ -459,8 +448,8 @@ ErrorOr<WifiLanSocket> WifiLan::Connect(const std::string& service_id,
|
||||
|
||||
socket = medium_.ConnectToService(service_info, cancellation_flag);
|
||||
if (!socket.IsValid()) {
|
||||
LOG(INFO) << "Failed to Connect via WifiLan [service_id="
|
||||
<< service_id << "]";
|
||||
LOG(INFO) << "Failed to Connect via WifiLan [service_id=" << service_id
|
||||
<< "]";
|
||||
return {Error(
|
||||
OperationResultCode::CONNECTIVITY_LAN_CLIENT_SOCKET_CREATION_FAILURE)};
|
||||
} else {
|
||||
@@ -468,15 +457,14 @@ ErrorOr<WifiLanSocket> WifiLan::Connect(const std::string& service_id,
|
||||
CreateOutgoingMultiplexSocketLocked(socket, service_id,
|
||||
service_info.GetIPAddress());
|
||||
if (virtual_socket.ok()) {
|
||||
LOG(INFO)
|
||||
<< "Successfully connected via Multiplex WifiLan [service_id="
|
||||
<< service_id << "]";
|
||||
LOG(INFO) << "Successfully connected via Multiplex WifiLan [service_id="
|
||||
<< service_id << "]";
|
||||
return virtual_socket.result();
|
||||
}
|
||||
}
|
||||
|
||||
LOG(INFO) << "Successfully connected via WifiLan [service_id="
|
||||
<< service_id << "]";
|
||||
LOG(INFO) << "Successfully connected via WifiLan [service_id=" << service_id
|
||||
<< "]";
|
||||
return socket;
|
||||
}
|
||||
|
||||
@@ -489,13 +477,13 @@ ErrorOr<WifiLanSocket> WifiLan::Connect(const std::string& service_id,
|
||||
|
||||
if (service_id.empty()) {
|
||||
LOG(INFO) << "Refusing to create client WifiLan socket because "
|
||||
"service_id is empty.";
|
||||
"service_id is empty.";
|
||||
return {Error(OperationResultCode::NEARBY_LOCAL_CLIENT_STATE_WRONG)};
|
||||
}
|
||||
|
||||
if (!IsAvailableLocked()) {
|
||||
LOG(INFO) << "Can't create client WifiLan socket [service_id="
|
||||
<< service_id << "]; WifiLan isn't available.";
|
||||
LOG(INFO) << "Can't create client WifiLan socket [service_id=" << service_id
|
||||
<< "]; WifiLan isn't available.";
|
||||
return {Error(OperationResultCode::MEDIUM_UNAVAILABLE_LAN_NOT_AVAILABLE)};
|
||||
}
|
||||
|
||||
@@ -513,38 +501,35 @@ ErrorOr<WifiLanSocket> WifiLan::Connect(const std::string& service_id,
|
||||
|
||||
socket = medium_.ConnectToService(ip_address, port, cancellation_flag);
|
||||
if (!socket.IsValid()) {
|
||||
LOG(INFO) << "Failed to Connect via WifiLan [service_id="
|
||||
<< service_id << "]";
|
||||
LOG(INFO) << "Failed to Connect via WifiLan [service_id=" << service_id
|
||||
<< "]";
|
||||
return {Error(
|
||||
OperationResultCode::CONNECTIVITY_LAN_CLIENT_SOCKET_CREATION_FAILURE)};
|
||||
} else {
|
||||
ExceptionOr<WifiLanSocket> virtual_socket =
|
||||
CreateOutgoingMultiplexSocketLocked(socket, service_id, ip_address);
|
||||
if (virtual_socket.ok()) {
|
||||
LOG(INFO)
|
||||
<< "Successfully connected via Multiplex WifiLan [service_id="
|
||||
<< service_id << "]";
|
||||
LOG(INFO) << "Successfully connected via Multiplex WifiLan [service_id="
|
||||
<< service_id << "]";
|
||||
return virtual_socket.result();
|
||||
}
|
||||
}
|
||||
|
||||
LOG(INFO) << "Successfully connected via WifiLan [service_id="
|
||||
<< service_id << "]";
|
||||
LOG(INFO) << "Successfully connected via WifiLan [service_id=" << service_id
|
||||
<< "]";
|
||||
return socket;
|
||||
}
|
||||
|
||||
ExceptionOr<WifiLanSocket> WifiLan::ConnectWithMultiplexSocketLocked(
|
||||
const std::string& service_id, const std::string& ip_address) {
|
||||
if (is_multiplex_enabled_) {
|
||||
LOG(INFO) << "multiplex_sockets_ size:"
|
||||
<< multiplex_sockets_.size();
|
||||
LOG(INFO) << "multiplex_sockets_ size:" << multiplex_sockets_.size();
|
||||
auto it = multiplex_sockets_.find(ip_address);
|
||||
if (it != multiplex_sockets_.end()) {
|
||||
MultiplexSocket* multiplex_socket = it->second;
|
||||
if (multiplex_socket->IsShutdown()) {
|
||||
LOG(INFO)
|
||||
<< "Erase multiplex_socket(already shutdown) for ip_address: "
|
||||
<< WifiUtils::GetHumanReadableIpAddress(ip_address);
|
||||
LOG(INFO) << "Erase multiplex_socket(already shutdown) for ip_address: "
|
||||
<< WifiUtils::GetHumanReadableIpAddress(ip_address);
|
||||
multiplex_socket->~MultiplexSocket();
|
||||
multiplex_sockets_.erase(it);
|
||||
return ExceptionOr<WifiLanSocket>(Exception::kFailed);
|
||||
@@ -555,9 +540,9 @@ ExceptionOr<WifiLanSocket> WifiLan::ConnectWithMultiplexSocketLocked(
|
||||
// Should not happen.
|
||||
auto* wlan_socket = down_cast<WifiLanSocket*>(virtual_socket);
|
||||
if (wlan_socket == nullptr) {
|
||||
LOG(INFO) << "Failed to cast to WifiLanSocket for "
|
||||
<< service_id << " with ip_address: "
|
||||
<< WifiUtils::GetHumanReadableIpAddress(ip_address);
|
||||
LOG(INFO) << "Failed to cast to WifiLanSocket for " << service_id
|
||||
<< " with ip_address: "
|
||||
<< WifiUtils::GetHumanReadableIpAddress(ip_address);
|
||||
return ExceptionOr<WifiLanSocket>(Exception::kFailed);
|
||||
}
|
||||
return ExceptionOr<WifiLanSocket>(*wlan_socket);
|
||||
@@ -582,12 +567,12 @@ ExceptionOr<WifiLanSocket> WifiLan::CreateOutgoingMultiplexSocketLocked(
|
||||
auto* wlan_socket = down_cast<WifiLanSocket*>(virtual_socket);
|
||||
if (wlan_socket == nullptr) {
|
||||
LOG(INFO) << "Failed to cast to WifiLanSocket for " << service_id
|
||||
<< " with ip_address: "
|
||||
<< WifiUtils::GetHumanReadableIpAddress(ip_address);
|
||||
<< " with ip_address: "
|
||||
<< WifiUtils::GetHumanReadableIpAddress(ip_address);
|
||||
return ExceptionOr<WifiLanSocket>(Exception::kFailed);
|
||||
}
|
||||
LOG(INFO) << "Multiplex socket created for ip_address: "
|
||||
<< WifiUtils::GetHumanReadableIpAddress(ip_address);
|
||||
<< WifiUtils::GetHumanReadableIpAddress(ip_address);
|
||||
multiplex_sockets_.emplace(ip_address, multiplex_socket);
|
||||
return ExceptionOr<WifiLanSocket>(*wlan_socket);
|
||||
}
|
||||
|
||||
@@ -93,8 +93,7 @@ TEST_P(WifiLanTest, CanConnect) {
|
||||
.service_discovered_cb =
|
||||
[&discovered_latch, &discovered_service_info](
|
||||
NsdServiceInfo service_info, const std::string& service_id) {
|
||||
LOG(INFO)
|
||||
<< "Discovered service_info=" << &service_info;
|
||||
LOG(INFO) << "Discovered service_info=" << &service_info;
|
||||
discovered_service_info = service_info;
|
||||
discovered_latch.CountDown();
|
||||
},
|
||||
@@ -162,7 +161,7 @@ TEST_P(WifiLanTest, CanConnectWithMultiplex) {
|
||||
NsdServiceInfo service_info,
|
||||
const std::string& service_id) {
|
||||
LOG(INFO) << "Discovered service_info="
|
||||
<< &service_info;
|
||||
<< &service_info;
|
||||
discovered_service_info = service_info;
|
||||
discovered_latch.CountDown();
|
||||
},
|
||||
@@ -224,8 +223,7 @@ TEST_P(WifiLanTest, CanCancelConnect) {
|
||||
.service_discovered_cb =
|
||||
[&discovered_latch, &discovered_service_info](
|
||||
NsdServiceInfo service_info, const std::string& service_id) {
|
||||
LOG(INFO)
|
||||
<< "Discovered service_info=" << &service_info;
|
||||
LOG(INFO) << "Discovered service_info=" << &service_info;
|
||||
discovered_service_info = service_info;
|
||||
discovered_latch.CountDown();
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user