diff --git a/cpp/core_v2/internal/bwu_manager.cc b/cpp/core_v2/internal/bwu_manager.cc index 9ab910fe..ab81e570 100644 --- a/cpp/core_v2/internal/bwu_manager.cc +++ b/cpp/core_v2/internal/bwu_manager.cc @@ -30,11 +30,11 @@ BwuManager::BwuManager( if (config_.bandwidth_upgrade_retry_delay == absl::ZeroDuration()) { config_.bandwidth_upgrade_retry_delay = absl::Seconds(5); } - if (config_.bandwidth_upgrade_retry_delay == absl::ZeroDuration()) { - config_.bandwidth_upgrade_retry_delay = absl::Seconds(10); + if (config_.bandwidth_upgrade_retry_max_delay == absl::ZeroDuration()) { + config_.bandwidth_upgrade_retry_max_delay = absl::Seconds(10); } if (config_.allow_upgrade_to.All(false)) { - config.allow_upgrade_to.web_rtc = true; + config_.allow_upgrade_to.web_rtc = true; } if (!handlers.empty()) { handlers_ = std::move(handlers); @@ -43,7 +43,7 @@ BwuManager::BwuManager( } // Register the offline frame processor. - endpoint_manager.RegisterFrameProcessor( + endpoint_manager_->RegisterFrameProcessor( V1Frame::BANDWIDTH_UPGRADE_NEGOTIATION, this); } diff --git a/cpp/core_v2/internal/endpoint_manager.cc b/cpp/core_v2/internal/endpoint_manager.cc index 4e3e5d7a..04bf5890 100644 --- a/cpp/core_v2/internal/endpoint_manager.cc +++ b/cpp/core_v2/internal/endpoint_manager.cc @@ -136,6 +136,9 @@ ExceptionOr EndpointManager::HandleData( // no explicit handler. if (frame_type == V1Frame::KEEP_ALIVE) { NEARBY_LOG(INFO, "KeepAlive message for: id=%s", endpoint_id.c_str()); + } else if (frame_type == V1Frame::DISCONNECTION) { + NEARBY_LOG(INFO, "Disconnect message for: id=%s", endpoint_id.c_str()); + endpoint_channel->Close(); } else { NEARBY_LOG(ERROR, "Unhandled message: id=%s, type=%d", endpoint_id.c_str(), frame_type); diff --git a/cpp/core_v2/internal/offline_frames.cc b/cpp/core_v2/internal/offline_frames.cc index a046486d..9c7f6314 100644 --- a/cpp/core_v2/internal/offline_frames.cc +++ b/cpp/core_v2/internal/offline_frames.cc @@ -254,6 +254,17 @@ ByteArray ForKeepAlive() { return ToBytes(std::move(frame)); } +ByteArray ForDisconnection() { + OfflineFrame frame; + + frame.set_version(OfflineFrame::V1); + auto* v1_frame = frame.mutable_v1(); + v1_frame->set_type(V1Frame::DISCONNECTION); + v1_frame->mutable_disconnection(); + + return ToBytes(std::move(frame)); +} + UpgradePathInfo::Medium MediumToUpgradePathInfoMedium(Medium medium) { switch (medium) { case Medium::MDNS: diff --git a/cpp/core_v2/internal/p2p_point_to_point_pcp_handler.cc b/cpp/core_v2/internal/p2p_point_to_point_pcp_handler.cc index 0b09d8bd..64e05d4a 100644 --- a/cpp/core_v2/internal/p2p_point_to_point_pcp_handler.cc +++ b/cpp/core_v2/internal/p2p_point_to_point_pcp_handler.cc @@ -13,9 +13,18 @@ P2pPointToPointPcpHandler::P2pPointToPointPcpHandler( std::vector P2pPointToPointPcpHandler::GetConnectionMediumsByPriority() { std::vector mediums; + if (mediums_->GetWifiLan().IsAvailable()) { + mediums.push_back(proto::connections::WIFI_LAN); + } + if (mediums_->GetWebRtc().IsAvailable()) { + mediums.push_back(proto::connections::WEB_RTC); + } if (mediums_->GetBluetoothClassic().IsAvailable()) { mediums.push_back(proto::connections::BLUETOOTH); } + if (mediums_->GetBle().IsAvailable()) { + mediums.push_back(proto::connections::BLE); + } return mediums; } diff --git a/cpp/core_v2/internal/p2p_star_pcp_handler.cc b/cpp/core_v2/internal/p2p_star_pcp_handler.cc index 45a20d14..80e773cd 100644 --- a/cpp/core_v2/internal/p2p_star_pcp_handler.cc +++ b/cpp/core_v2/internal/p2p_star_pcp_handler.cc @@ -16,9 +16,18 @@ P2pStarPcpHandler::P2pStarPcpHandler(Mediums& mediums, std::vector P2pStarPcpHandler::GetConnectionMediumsByPriority() { std::vector mediums; + if (mediums_->GetWifiLan().IsAvailable()) { + mediums.push_back(proto::connections::WIFI_LAN); + } + if (mediums_->GetWebRtc().IsAvailable()) { + mediums.push_back(proto::connections::WEB_RTC); + } if (mediums_->GetBluetoothClassic().IsAvailable()) { mediums.push_back(proto::connections::BLUETOOTH); } + if (mediums_->GetBle().IsAvailable()) { + mediums.push_back(proto::connections::BLE); + } return mediums; } diff --git a/proto/connections/offline_wire_formats.proto b/proto/connections/offline_wire_formats.proto index 9cd1728d..f7c1e6dc 100644 --- a/proto/connections/offline_wire_formats.proto +++ b/proto/connections/offline_wire_formats.proto @@ -207,6 +207,7 @@ message BandwidthUpgradeNegotiationFrame { // Accompanies Medium.WEB_RTC message WebRtcCredentials { optional string peer_id = 1; + optional LocationHint location_hint = 2; } optional Medium medium = 1; @@ -261,3 +262,29 @@ message MediumMetadata { // WiFi Lan BSSID optional string bssid = 2; } + +// LocationHint is used to specify a location as well as format. +message LocationHint { + // Location is the location, provided in the format specified by format. + optional string location = 1; + + // the format of location. + optional LocationStandard.Format format = 2; +} + +// Copy from +// https://source.corp.google.com/piper///depot/google3/media/webrtc/server/tachyon/proto/tachyon_enums.proto;rcl=334271491;l=10242 +// These numbers match must match the original definition. +message LocationStandard { + enum Format { + UNKNOWN = 0; + // E164 country codes: + // https://en.wikipedia.org/wiki/List_of_country_calling_codes + // e.g. +1 for USA + E164_CALLING = 1; + + // ISO 3166-1 alpha-2 country codes: + // https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 + ISO_3166_1_ALPHA_2 = 2; + } +} diff --git a/proto/connections_enums.proto b/proto/connections_enums.proto index 742cbb65..ff01cd13 100644 --- a/proto/connections_enums.proto +++ b/proto/connections_enums.proto @@ -147,7 +147,7 @@ enum PayloadStatus { REMOTE_CANCELLATION = 8; } -// next_id: 17 +// next_id: 18 // Result of an upgrade attempt. enum BandwidthUpgradeResult { UNKNOWN_BANDWIDTH_UPGRADE_RESULT = 0; @@ -176,9 +176,6 @@ enum BandwidthUpgradeResult { // record analytics (e.g. the client disconnected). UNFINISHED_ERROR = 10; - // TODO(b/151833661): add a REMOTE_ERROR when we implement a cancellation - // message, for the case when the remote endpoint had an error on their end. - // Error during setting up Bluetooth. BLUETOOTH_MEDIUM_ERROR = 11; @@ -196,6 +193,9 @@ enum BandwidthUpgradeResult { // Error during setting up WebRTC. WEB_RTC_MEDIUM_ERROR = 16; + + // When the remote endpoint had an error on their end. + RESULT_REMOTE_ERROR = 17; } // next_id: 35 @@ -217,6 +217,8 @@ enum BandwidthUpgradeErrorStage { UPGRADE_UNFINISHED = 7; // Upgrade successfully UPGRADE_SUCCESS = 8; + // Upgrade cancel + UPGRADE_CANCEL = 9; // Medium-specific stages. // TODO(xlythe) Make sure each stage maps to one, and only one, possible diff --git a/script/oss.py b/script/oss.py index 1892d64e..85cc555b 100755 --- a/script/oss.py +++ b/script/oss.py @@ -96,7 +96,7 @@ def copy_files_to_oss_project(src_root, dst_root): def detect_file_copy_header_options(fname, lines): if not lines: return None # ignore empty file - suffixes = [".cc", ".cpp", ".cxx", ".c", ".h", ".hpp", ".inc", ".proto"] + suffixes = [".cc", ".cpp", ".cxx", ".c", ".h", ".hpp", ".inc", ".mm", ".proto"] for suffix in suffixes: if fname.endswith(suffix): return ("//", 0)