diff --git a/cpp/core_v2/internal/base_pcp_handler.cc b/cpp/core_v2/internal/base_pcp_handler.cc index b2eb73f9..1d77ca79 100644 --- a/cpp/core_v2/internal/base_pcp_handler.cc +++ b/cpp/core_v2/internal/base_pcp_handler.cc @@ -310,26 +310,18 @@ Status BasePcpHandler::RequestConnection(ClientProxy* client, return; } - if (discovery_options_.allowed.web_rtc) { - auto webrtc_endpoint = std::make_shared( - DiscoveredEndpoint{endpoint->endpoint_id, endpoint->endpoint_info, - endpoint->service_id, - proto::connections::Medium::WEB_RTC}, - CreatePeerIdFromAdvertisement(endpoint->service_id, - endpoint->endpoint_id, - endpoint->endpoint_info)); - OnEndpointFound(client, webrtc_endpoint); - } - auto remote_bluetooth_mac_address = BluetoothUtils::ToString(options.remote_bluetooth_mac_address); if (!remote_bluetooth_mac_address.empty()) { - if (AddRemoteBluetoothMacAddressEndpoint(endpoint_id, + if (AppendRemoteBluetoothMacAddressEndpoint(endpoint_id, remote_bluetooth_mac_address)) NEARBY_LOGS(INFO) << "Appended remote Bluetooth MAC Address endpoint " << "[" << remote_bluetooth_mac_address << "]"; } + if (AppendWebRTCEndpoint(endpoint_id)) + NEARBY_LOGS(INFO) << "Appended Web RTC endpoint."; + auto discovered_endpoints = GetDiscoveredEndpoints(endpoint_id); std::unique_ptr channel; ConnectImplResult connect_impl_result; @@ -988,23 +980,20 @@ proto::connections::Medium BasePcpHandler::ChooseBestUpgradeMedium( return proto::connections::Medium::UNKNOWN_MEDIUM; } -bool BasePcpHandler::AddRemoteBluetoothMacAddressEndpoint( - std::string endpoint_id, std::string remote_bluetooth_mac_address) { +bool BasePcpHandler::AppendRemoteBluetoothMacAddressEndpoint( + const std::string& endpoint_id, + const std::string& remote_bluetooth_mac_address) { if (!discovery_options_.allowed.bluetooth) { return false; } - auto endpoints = GetDiscoveredEndpoints(endpoint_id); - if (endpoints.empty()) { - NEARBY_LOGS(INFO) << "Cannot append remote Bluetooth MAC Address endpoint, " - "because endpointId " - << endpoint_id << " has not been discovered " - << "[" << remote_bluetooth_mac_address << "]"; + auto it = discovered_endpoints_.equal_range(endpoint_id); + if (it.first == it.second) { return false; } - - for (auto endpoint : endpoints) { - if (endpoint->medium == proto::connections::Medium::BLUETOOTH) { + auto endpoint = it.first->second.get(); + for (auto item = it.first; item != it.second; item++) { + if (item->second->medium == proto::connections::Medium::BLUETOOTH) { NEARBY_LOGS(INFO) << "Cannot append remote Bluetooth MAC Address endpoint, because the " "endpoint has already been found over Bluetooth " @@ -1028,9 +1017,10 @@ bool BasePcpHandler::AddRemoteBluetoothMacAddressEndpoint( std::make_shared(BluetoothEndpoint{ { endpoint_id, - endpoints[0]->endpoint_info, - endpoints[0]->service_id, + endpoint->endpoint_info, + endpoint->service_id, proto::connections::Medium::BLUETOOTH, + WebRtcState::kUnconnectable }, remote_bluetooth_device, }); @@ -1039,6 +1029,42 @@ bool BasePcpHandler::AddRemoteBluetoothMacAddressEndpoint( return true; } +bool BasePcpHandler::AppendWebRTCEndpoint(const std::string& endpoint_id) { + if (!discovery_options_.allowed.web_rtc) { + return false; + } + + bool should_connect_web_rtc = false; + auto it = discovered_endpoints_.equal_range(endpoint_id); + if (it.first == it.second) return false; + auto endpoint = it.first->second.get(); + for (auto item = it.first; item != it.second; item++) { + if (item->second->web_rtc_state != WebRtcState::kUnconnectable) { + should_connect_web_rtc = true; + break; + } + } + if (!should_connect_web_rtc) return false; + + auto webrtc_endpoint = + std::make_shared(WebRtcEndpoint{ + { + endpoint_id, + endpoint->endpoint_info, + endpoint->service_id, + proto::connections::Medium::WEB_RTC, + WebRtcState::kConnectable + }, + CreatePeerIdFromAdvertisement( + endpoint->service_id, + endpoint->endpoint_id, + endpoint->endpoint_info), + }); + + discovered_endpoints_.emplace(endpoint_id, std::move(webrtc_endpoint)); + return true; +} + void BasePcpHandler::EvaluateConnectionResult(ClientProxy* client, const std::string& endpoint_id, bool can_close_immediately) { diff --git a/cpp/core_v2/internal/base_pcp_handler.h b/cpp/core_v2/internal/base_pcp_handler.h index 7bc24478..9ed68a08 100644 --- a/cpp/core_v2/internal/base_pcp_handler.h +++ b/cpp/core_v2/internal/base_pcp_handler.h @@ -178,17 +178,20 @@ class BasePcpHandler : public PcpHandler, struct DiscoveredEndpoint { DiscoveredEndpoint(std::string endpoint_id, ByteArray endpoint_info, std::string service_id, - proto::connections::Medium medium) + proto::connections::Medium medium, + WebRtcState web_rtc_state) : endpoint_id(std::move(endpoint_id)), endpoint_info(std::move(endpoint_info)), service_id(std::move(service_id)), - medium(medium) {} + medium(medium), + web_rtc_state(web_rtc_state) {} virtual ~DiscoveredEndpoint() = default; std::string endpoint_id; ByteArray endpoint_info; std::string service_id; proto::connections::Medium medium; + WebRtcState web_rtc_state; }; struct BluetoothEndpoint : public DiscoveredEndpoint { @@ -407,10 +410,15 @@ class BasePcpHandler : public PcpHandler, const std::vector& supported_mediums); // Returns true if the bluetooth endpoint based on remote bluetooth mac - // address is created and added into discovered_endpoints_ with key + // address is created and appended into discovered_endpoints_ with key // endpoint_id. - bool AddRemoteBluetoothMacAddressEndpoint( - std::string endpoint_id, std::string remote_bluetooth_mac_address); + bool AppendRemoteBluetoothMacAddressEndpoint( + const std::string& endpoint_id, + const std::string& remote_bluetooth_mac_address); + + // Returns true if the webrtc endpoint is created and appended into + // discovered_endpoints_ with key endpoint_id. + bool AppendWebRTCEndpoint(const std::string& endpoint_id); void ProcessPreConnectionInitiationFailure(const std::string& endpoint_id, EndpointChannel* channel, diff --git a/cpp/core_v2/internal/base_pcp_handler_test.cc b/cpp/core_v2/internal/base_pcp_handler_test.cc index e939fda2..49175362 100644 --- a/cpp/core_v2/internal/base_pcp_handler_test.cc +++ b/cpp/core_v2/internal/base_pcp_handler_test.cc @@ -324,6 +324,7 @@ class BasePcpHandlerTest info.endpoint_info, "service", discovered_medium, + WebRtcState::kUndefined, }, MockContext{flag}, })); diff --git a/cpp/core_v2/internal/ble_advertisement.cc b/cpp/core_v2/internal/ble_advertisement.cc index 303d2e81..ed3bee6b 100644 --- a/cpp/core_v2/internal/ble_advertisement.cc +++ b/cpp/core_v2/internal/ble_advertisement.cc @@ -160,32 +160,35 @@ BleAdvertisement::BleAdvertisement(bool fast_advertisement, BluetoothUtils::ToString(bluetooth_mac_address_bytes); } - // The next 1 byte is supposed to be the length of the uwb_address. - std::uint32_t expected_uwb_address_length = base_input_stream.ReadUint8(); - // If the length of uwb_address is not zero, then retrieve it. - if (expected_uwb_address_length != 0) { - uwb_address_ = base_input_stream.ReadBytes(expected_uwb_address_length); - if (uwb_address_.Empty() || - uwb_address_.size() != expected_uwb_address_length) { - NEARBY_LOG(INFO, - "Cannot deserialize BleAdvertisement: " - "expected uwbAddress size to be %d bytes, got %" PRIu64, - expected_uwb_address_length, uwb_address_.size()); + // The next 1 byte is supposed to be the length of the uwb_address. If the + // next byte is not available then it should be a fast advertisement and skip + // it for remaining bytes. + if (base_input_stream.IsAvailable(1)) { + std::uint32_t expected_uwb_address_length = base_input_stream.ReadUint8(); + // If the length of uwb_address is not zero, then retrieve it. + if (expected_uwb_address_length != 0) { + uwb_address_ = base_input_stream.ReadBytes(expected_uwb_address_length); + if (uwb_address_.Empty() || + uwb_address_.size() != expected_uwb_address_length) { + NEARBY_LOG(INFO, + "Cannot deserialize BleAdvertisement: " + "expected uwbAddress size to be %d bytes, got %" PRIu64, + expected_uwb_address_length, uwb_address_.size()); - // Clear enpoint_id for validity. - endpoint_id_.clear(); - return; + // Clear enpoint_id for validity. + endpoint_id_.clear(); + return; + } } - } - // The next 1 byte is extra field. - web_rtc_state_ = WebRtcState::kUndefined; - if (!fast_advertisement_) { - if (base_input_stream.IsAvailable(kExtraFieldLength)) { - auto extra_field = static_cast(base_input_stream.ReadUint8()); - web_rtc_state_ = (extra_field & kWebRtcConnectableFlagBitmask) == 1 - ? WebRtcState::kConnectable - : WebRtcState::kUnconnectable; + // The next 1 byte is extra field. + if (!fast_advertisement_) { + if (base_input_stream.IsAvailable(kExtraFieldLength)) { + auto extra_field = static_cast(base_input_stream.ReadUint8()); + web_rtc_state_ = (extra_field & kWebRtcConnectableFlagBitmask) == 1 + ? WebRtcState::kConnectable + : WebRtcState::kUnconnectable; + } } } @@ -233,7 +236,7 @@ BleAdvertisement::operator ByteArray() const { if (!uwb_address_.Empty()) { absl::StrAppend(&out, std::string(1, uwb_address_.size())); absl::StrAppend(&out, std::string(uwb_address_)); - } else { + } else if (!fast_advertisement_) { // Write UWB address with length 0 to be able to read the next field when // decode. absl::StrAppend(&out, std::string(1, uwb_address_.size())); diff --git a/cpp/core_v2/internal/bwu_handler.h b/cpp/core_v2/internal/bwu_handler.h index 8e926a8c..d042f6ce 100644 --- a/cpp/core_v2/internal/bwu_handler.h +++ b/cpp/core_v2/internal/bwu_handler.h @@ -62,7 +62,7 @@ class BwuHandler { struct BwuNotifications { std::function + std::unique_ptr connection)> incoming_connection_cb; }; }; diff --git a/cpp/core_v2/internal/bwu_manager.cc b/cpp/core_v2/internal/bwu_manager.cc index cd4c9c38..ed17899b 100644 --- a/cpp/core_v2/internal/bwu_manager.cc +++ b/cpp/core_v2/internal/bwu_manager.cc @@ -262,9 +262,9 @@ void BwuManager::OnBwuNegotiationFrame(ClientProxy* client, void BwuManager::OnIncomingConnection( ClientProxy* client, - BwuHandler::IncomingSocketConnection* mutable_connection) { - auto connection = std::make_shared( - std::move(*mutable_connection)); + std::unique_ptr mutable_connection) { + std::shared_ptr connection( + mutable_connection.release()); RunOnBwuManagerThread([this, client, connection]() { EndpointChannel* channel = connection->channel.get(); if (channel == nullptr) { diff --git a/cpp/core_v2/internal/bwu_manager.h b/cpp/core_v2/internal/bwu_manager.h index ed0252dd..0cb94df9 100644 --- a/cpp/core_v2/internal/bwu_manager.h +++ b/cpp/core_v2/internal/bwu_manager.h @@ -1,6 +1,7 @@ #ifndef CORE_V2_INTERNAL_BWU_MANAGER_H_ #define CORE_V2_INTERNAL_BWU_MANAGER_H_ +#include #include #include @@ -107,8 +108,9 @@ class BwuManager : public EndpointManager::FrameProcessor { // Common functionality to take an incoming connection and go through the // upgrade process. This is a callback, invoked by concrete handlers, once // connection is available. - void OnIncomingConnection(ClientProxy* client, - BwuHandler::IncomingSocketConnection* connection); + void OnIncomingConnection( + ClientProxy* client, + std::unique_ptr mutable_connection); void RunUpgradeProtocol(ClientProxy* client, const std::string& endpoint_id, std::unique_ptr new_channel); diff --git a/cpp/core_v2/internal/p2p_cluster_pcp_handler.cc b/cpp/core_v2/internal/p2p_cluster_pcp_handler.cc index 039b7bdc..eb6f0773 100644 --- a/cpp/core_v2/internal/p2p_cluster_pcp_handler.cc +++ b/cpp/core_v2/internal/p2p_cluster_pcp_handler.cc @@ -77,19 +77,7 @@ BasePcpHandler::StartOperationResult P2pClusterPcpHandler::StartAdvertisingImpl( const ConnectionOptions& options) { std::vector mediums_started_successfully; - if (options.allowed.wifi_lan) { - const ByteArray wifi_lan_hash = - GenerateHash(service_id, WifiLanServiceInfo::kServiceIdHashLength); - proto::connections::Medium wifi_lan_medium = - StartWifiLanAdvertising(client, service_id, wifi_lan_hash, - local_endpoint_id, local_endpoint_info); - if (wifi_lan_medium != proto::connections::UNKNOWN_MEDIUM) { - NEARBY_LOG(INFO, - "P2pClusterPcpHandler::StartAdvertisingImpl: WifiLan added"); - mediums_started_successfully.push_back(wifi_lan_medium); - } - } - + WebRtcState web_rtc_state{WebRtcState::kUnconnectable}; if (options.allowed.web_rtc) { proto::connections::Medium webrtc_medium = StartListeningForWebRtcConnections( @@ -98,15 +86,29 @@ BasePcpHandler::StartOperationResult P2pClusterPcpHandler::StartAdvertisingImpl( NEARBY_LOG(INFO, "P2pClusterPcpHandler::StartAdvertisingImpl: WebRtc added"); mediums_started_successfully.push_back(webrtc_medium); + web_rtc_state = WebRtcState::kConnectable; + } + } + + if (options.allowed.wifi_lan) { + const ByteArray wifi_lan_hash = + GenerateHash(service_id, WifiLanServiceInfo::kServiceIdHashLength); + proto::connections::Medium wifi_lan_medium = StartWifiLanAdvertising( + client, service_id, wifi_lan_hash, local_endpoint_id, + local_endpoint_info, web_rtc_state); + if (wifi_lan_medium != proto::connections::UNKNOWN_MEDIUM) { + NEARBY_LOG(INFO, + "P2pClusterPcpHandler::StartAdvertisingImpl: WifiLan added"); + mediums_started_successfully.push_back(wifi_lan_medium); } } if (options.allowed.bluetooth) { const ByteArray bluetooth_hash = GenerateHash(service_id, BluetoothDeviceName::kServiceIdHashLength); - proto::connections::Medium bluetooth_medium = - StartBluetoothAdvertising(client, service_id, bluetooth_hash, - local_endpoint_id, local_endpoint_info); + proto::connections::Medium bluetooth_medium = StartBluetoothAdvertising( + client, service_id, bluetooth_hash, local_endpoint_id, + local_endpoint_info, web_rtc_state); if (bluetooth_medium != proto::connections::UNKNOWN_MEDIUM) { NEARBY_LOG(INFO, "P2pClusterPcpHandler::StartAdvertisingImpl: BT added"); mediums_started_successfully.push_back(bluetooth_medium); @@ -114,8 +116,9 @@ BasePcpHandler::StartOperationResult P2pClusterPcpHandler::StartAdvertisingImpl( } if (options.allowed.ble) { - proto::connections::Medium ble_medium = StartBleAdvertising( - client, service_id, local_endpoint_id, local_endpoint_info, options); + proto::connections::Medium ble_medium = + StartBleAdvertising(client, service_id, local_endpoint_id, + local_endpoint_info, options, web_rtc_state); if (ble_medium != proto::connections::UNKNOWN_MEDIUM) { NEARBY_LOG(INFO, "P2pClusterPcpHandler::StartAdvertisingImpl: Ble added"); mediums_started_successfully.push_back(ble_medium); @@ -222,6 +225,7 @@ void P2pClusterPcpHandler::BluetoothDeviceDiscoveredHandler( device_name.GetEndpointInfo(), service_id, proto::connections::Medium::BLUETOOTH, + device_name.GetWebRtcState() }, device, })); @@ -261,6 +265,7 @@ void P2pClusterPcpHandler::BluetoothDeviceLostHandler( device_name.GetEndpointInfo(), service_id, proto::connections::Medium::BLUETOOTH, + WebRtcState::kUndefined }); }); } @@ -353,6 +358,7 @@ void P2pClusterPcpHandler::BlePeripheralDiscoveredHandler( advertisement.GetEndpointInfo(), service_id, proto::connections::Medium::BLE, + advertisement.GetWebRtcState() }, peripheral, })); @@ -382,6 +388,7 @@ void P2pClusterPcpHandler::BlePeripheralDiscoveredHandler( advertisement.GetEndpointInfo(), service_id, proto::connections::Medium::BLUETOOTH, + advertisement.GetWebRtcState(), }, remote_bluetooth_device, })); @@ -421,6 +428,7 @@ void P2pClusterPcpHandler::BlePeripheralLostHandler( ble_endpoint_state.endpoint_info, service_id, proto::connections::Medium::BLE, + WebRtcState::kUndefined, }); } }); @@ -495,6 +503,7 @@ void P2pClusterPcpHandler::WifiLanServiceDiscoveredHandler( service_info.GetEndpointInfo(), service_id, proto::connections::Medium::WIFI_LAN, + service_info.GetWebRtcState(), }, service, })); @@ -536,6 +545,7 @@ void P2pClusterPcpHandler::WifiLanServiceLostHandler( service_info.GetEndpointInfo(), service_id, proto::connections::Medium::WIFI_LAN, + WebRtcState::kUndefined, }); }); } @@ -666,7 +676,7 @@ BasePcpHandler::ConnectImplResult P2pClusterPcpHandler::ConnectImpl( proto::connections::Medium P2pClusterPcpHandler::StartBluetoothAdvertising( ClientProxy* client, const std::string& service_id, const ByteArray& service_id_hash, const std::string& local_endpoint_id, - const ByteArray& local_endpoint_info) { + const ByteArray& local_endpoint_info, WebRtcState web_rtc_state) { // Start listening for connections before advertising in case a connection // request comes in very quickly. NEARBY_LOG( @@ -718,10 +728,9 @@ proto::connections::Medium P2pClusterPcpHandler::StartBluetoothAdvertising( absl::BytesToHexString(local_endpoint_info.data()).c_str()); // Generate a BluetoothDeviceName with which to become Bluetooth discoverable. // TODO(b/169550050): Implement UWBAddress. - // TODO(b/169303359): Implement WebRtcState. std::string device_name(BluetoothDeviceName( kBluetoothDeviceNameVersion, GetPcp(), local_endpoint_id, service_id_hash, - local_endpoint_info, ByteArray{}, WebRtcState::kUnconnectable)); + local_endpoint_info, ByteArray{}, web_rtc_state)); if (device_name.empty()) { NEARBY_LOG(INFO, "P2pClusterPcpHandler::StartBluetoothAdvertising: generate " @@ -797,7 +806,7 @@ BasePcpHandler::ConnectImplResult P2pClusterPcpHandler::BluetoothConnectImpl( proto::connections::Medium P2pClusterPcpHandler::StartBleAdvertising( ClientProxy* client, const std::string& service_id, const std::string& local_endpoint_id, const ByteArray& local_endpoint_info, - const ConnectionOptions& options) { + const ConnectionOptions& options, WebRtcState web_rtc_state) { bool fast_advertisement = !options.fast_advertisement_service_uuid.empty(); PowerLevel power_level = options.low_power ? PowerLevel::kLowPower : PowerLevel::kHighPower; @@ -905,11 +914,10 @@ proto::connections::Medium P2pClusterPcpHandler::StartBleAdvertising( ShouldAdvertiseBluetoothMacOverBle(power_level)) bluetooth_mac_address = bluetooth_medium_.GetMacAddress(); - // TODO(b/169303359): Implement WebRtcState. - advertisement_bytes = ByteArray(BleAdvertisement( - kBleAdvertisementVersion, GetPcp(), service_id_hash, local_endpoint_id, - local_endpoint_info, bluetooth_mac_address, ByteArray{}, - WebRtcState::kUnconnectable)); + advertisement_bytes = ByteArray( + BleAdvertisement(kBleAdvertisementVersion, GetPcp(), service_id_hash, + local_endpoint_id, local_endpoint_info, + bluetooth_mac_address, ByteArray{}, web_rtc_state)); } if (advertisement_bytes.Empty()) { NEARBY_LOG(INFO, @@ -979,7 +987,7 @@ BasePcpHandler::ConnectImplResult P2pClusterPcpHandler::BleConnectImpl( proto::connections::Medium P2pClusterPcpHandler::StartWifiLanAdvertising( ClientProxy* client, const std::string& service_id, const ByteArray& service_id_hash, const std::string& local_endpoint_id, - const ByteArray& local_endpoint_info) { + const ByteArray& local_endpoint_info, WebRtcState web_rtc_state) { // Start listening for connections before advertising in case a connection // request comes in very quickly. NEARBY_LOG(INFO, @@ -1031,10 +1039,9 @@ proto::connections::Medium P2pClusterPcpHandler::StartWifiLanAdvertising( absl::BytesToHexString(local_endpoint_info.data()).c_str()); // Generate a WifiLanServiceInfo with which to become WifiLan discoverable. // TODO(b/169550050): Implement UWBAddress. - // TODO(b/169303359): Implement WebRtcState. std::string service_info_name(WifiLanServiceInfo( kWifiLanServiceInfoVersion, GetPcp(), local_endpoint_id, service_id_hash, - local_endpoint_info, ByteArray{}, WebRtcState::kUnconnectable)); + local_endpoint_info, ByteArray{}, web_rtc_state)); if (service_info_name.empty()) { NEARBY_LOG(INFO, "P2pClusterPcpHandler::StartWifiLanAdvertising: generate " diff --git a/cpp/core_v2/internal/p2p_cluster_pcp_handler.h b/cpp/core_v2/internal/p2p_cluster_pcp_handler.h index 50ea90ef..26fc6464 100644 --- a/cpp/core_v2/internal/p2p_cluster_pcp_handler.h +++ b/cpp/core_v2/internal/p2p_cluster_pcp_handler.h @@ -136,7 +136,7 @@ class P2pClusterPcpHandler : public BasePcpHandler { proto::connections::Medium StartBluetoothAdvertising( ClientProxy* client, const std::string& service_id, const ByteArray& service_id_hash, const std::string& local_endpoint_id, - const ByteArray& local_endpoint_info); + const ByteArray& local_endpoint_info, WebRtcState web_rtc_state); proto::connections::Medium StartBluetoothDiscovery( BluetoothDiscoveredDeviceCallback callback, ClientProxy* client, const std::string& service_id); @@ -158,7 +158,8 @@ class P2pClusterPcpHandler : public BasePcpHandler { proto::connections::Medium StartBleAdvertising( ClientProxy* client, const std::string& service_id, const std::string& local_endpoint_id, - const ByteArray& local_endpoint_info, const ConnectionOptions& options); + const ByteArray& local_endpoint_info, const ConnectionOptions& options, + WebRtcState web_rtc_state); proto::connections::Medium StartBleScanning( BleDiscoveredPeripheralCallback callback, ClientProxy* client, const std::string& service_id, @@ -178,7 +179,7 @@ class P2pClusterPcpHandler : public BasePcpHandler { proto::connections::Medium StartWifiLanAdvertising( ClientProxy* client, const std::string& service_id, const ByteArray& service_id_hash, const std::string& local_endpoint_id, - const ByteArray& local_endpoint_info); + const ByteArray& local_endpoint_info, WebRtcState web_rtc_state); proto::connections::Medium StartWifiLanDiscovery( WifiLanDiscoveredServiceCallback callback, ClientProxy* client, const std::string& service_id); diff --git a/cpp/core_v2/internal/webrtc_bwu_handler.cc b/cpp/core_v2/internal/webrtc_bwu_handler.cc index 2ba1d9ef..c55e7bad 100644 --- a/cpp/core_v2/internal/webrtc_bwu_handler.cc +++ b/cpp/core_v2/internal/webrtc_bwu_handler.cc @@ -39,11 +39,13 @@ void WebrtcBwuHandler::OnIncomingWebrtcConnection( mediums::WebRtcSocketWrapper socket) { std::string service_id = Utils::UnwrapUpgradeServiceId(upgrade_service_id); auto channel = std::make_unique(service_id, socket); - IncomingSocketConnection connection{ - std::make_unique(service_id, socket), - std::move(channel)}; + auto webrtc_socket = + std::make_unique(service_id, socket); + std::unique_ptr connection( + new IncomingSocketConnection{std::move(webrtc_socket), + std::move(channel)}); - bwu_notifications_.incoming_connection_cb(client, &connection); + bwu_notifications_.incoming_connection_cb(client, std::move(connection)); } // Called by BWU initiator. BT Medium is set up, and BWU request is prepared, diff --git a/proto/sharing_enums.proto b/proto/sharing_enums.proto index a2246b35..3ac536a5 100644 --- a/proto/sharing_enums.proto +++ b/proto/sharing_enums.proto @@ -182,9 +182,10 @@ enum AttachmentTransmissionStatus { COMPLETE_ATTACHMENT_TRANSMISSION_STATUS = 1; CANCELED_ATTACHMENT_TRANSMISSION_STATUS = 2; FAILED_ATTACHMENT_TRANSMISSION_STATUS = 3; + REJECTED_ATTACHMENT = 4; TIMED_OUT_ATTACHMENT = 5; - AWAITING_REMOTE_ACCEPTANCE_FAILED_ATTACHMENT = 6; + AWAITING_REMOTE_ACCEPTANCE_FAILED_ATTACHMENT = 6 [deprecated = true]; NOT_ENOUGH_SPACE_ATTACHMENT = 7; FAILED_NO_TRANSFER_UPDATE_CALLBACK = 8; MEDIA_UNAVAILABLE_ATTACHMENT = 9; diff --git a/script/oss.py b/script/oss.py index 980680d4..3ad3835b 100755 --- a/script/oss.py +++ b/script/oss.py @@ -202,10 +202,12 @@ def post_process_oss_files(path, args): modified = True if modified: - os.chmod(fname, os.stat(fname).st_mode | stat.S_IWRITE) + old_mode = os.stat(fname).st_mode + os.chmod(fname, old_mode | stat.S_IWRITE) with open(fname, "w") as f: for line in lines: f.write(line) + os.chmod(fname, old_mode) modified_total += 1 if args.no_recurse: break