An open-source cross-platform alternative to AirDrop
docs: protocol v2.2
Tien Do Nam5d23cc8d5f68
diff --git a/AGENTS.md b/AGENTS.mdindex f7ee95d1..e16a5bef 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -116,7 +116,7 @@ Web assets for the browser download page are embedded from `packages/core/assets### Multicast discovery (Rust)-`packages/core/src/multicast/` (feature `multicast`, independent of `http`) implements UDP multicast discovery for protocol v2.1 — v1 messages are not parsed.+`packages/core/src/multicast/` (feature `multicast`, independent of `http`) implements UDP multicast discovery for protocol v2.2 — v1 messages are not parsed.Integration mirrors the HTTP server: `multicast::start` takes a `MulticastConfig { group, group_v6, port, interface_filter, device, event_tx }` and emits `MulticastEvent::Discovered { ip, message }`; the returned `MulticastHandle` offers `announce` (the announcement burst) and `wait_stopped`.UDP is **announce-only**: responses go back over HTTP as a unicast register request to the announcing device.diff --git a/packages/core/src/discovery/store.rs b/packages/core/src/discovery/store.rsindex 81f0898f..364e4e3f 100644--- a/packages/core/src/discovery/store.rs+++ b/packages/core/src/discovery/store.rs@@ -265,7 +265,7 @@ mod tests {fn device(fingerprint: &str, host: &str) -> DiscoveredDevice {DiscoveredDevice {alias: format!("Alias of {fingerprint}"),- version: "2.1".to_string(),+ version: "2.2".to_string(),device_model: None,device_type: Some(DeviceType::Desktop),fingerprint: fingerprint.to_string(),diff --git a/packages/core/src/http/client/v2.rs b/packages/core/src/http/client/v2.rsindex d7c8f6ed..6f86829f 100644--- a/packages/core/src/http/client/v2.rs+++ b/packages/core/src/http/client/v2.rs@@ -10,13 +10,13 @@ use reqwest::{Response, StatusCode};use tokio::io::AsyncWriteExt;use tokio_util::sync::CancellationToken;-/// HTTP client for LocalSend Protocol v2.1.+/// HTTP client for LocalSend Protocol v2.2.pub struct LsHttpClientV2 {client: reqwest::Client,}impl LsHttpClientV2 {- /// Creates a new HTTP client for v2.1 protocol.+ /// Creates a new HTTP client for v2.2 protocol.////// # Arguments/// * `private_key` - PEM-encoded private key for client certificatediff --git a/packages/core/src/http/dto_v2.rs b/packages/core/src/http/dto_v2.rsindex 5ed22bfa..9f959821 100644--- a/packages/core/src/http/dto_v2.rs+++ b/packages/core/src/http/dto_v2.rs@@ -9,7 +9,7 @@ use std::collections::HashMap;use crate::model::discovery::ProtocolType;use crate::model::discovery::{device_type_v2, protocol_type_v2};-/// Register request DTO for v2.1 protocol.+/// Register request DTO for v2.2 protocol.////// Sent to POST /api/localsend/v2/register for device discovery.#[derive(Debug, Clone, Serialize, Deserialize)]@@ -18,7 +18,7 @@ pub struct RegisterDtoV2 {/// The display name of the device.pub alias: String,- /// Protocol version (e.g., "2.0", "2.1").+ /// Protocol version (e.g., "2.0", "2.2").pub version: String,/// Device model (e.g., "Samsung", "Windows"). Optional.@@ -49,7 +49,7 @@ pub struct RegisterDtoV2 {pub download: bool,}-/// Register response DTO for v2.1 protocol.+/// Register response DTO for v2.2 protocol.////// Response from POST /api/localsend/v2/register.#[derive(Debug, Clone, Serialize, Deserialize)]@@ -58,7 +58,7 @@ pub struct RegisterResponseDtoV2 {/// The display name of the device.pub alias: String,- /// Protocol version (e.g., "2.0", "2.1").+ /// Protocol version (e.g., "2.0", "2.2").pub version: String,/// Device model. Optional.@@ -83,7 +83,7 @@ pub struct RegisterResponseDtoV2 {pub download: bool,}-/// Prepare upload request DTO for v2.1 protocol.+/// Prepare upload request DTO for v2.2 protocol.////// Sent to POST /api/localsend/v2/prepare-upload to initiate a file transfer.#[derive(Debug, Clone, Serialize, Deserialize)]@@ -96,7 +96,7 @@ pub struct PrepareUploadRequestDtoV2 {pub files: HashMap<String, FileDto>,}-/// Prepare upload response DTO for v2.1 protocol.+/// Prepare upload response DTO for v2.2 protocol.////// Response from POST /api/localsend/v2/prepare-upload.#[derive(Debug, Clone, Serialize, Deserialize)]@@ -115,7 +115,7 @@ pub struct PrepareUploadResultV2 {pub response: Option<PrepareUploadResponseDtoV2>,}-/// Prepare download response DTO for v2.1 protocol (Download API).+/// Prepare download response DTO for v2.2 protocol (Download API).////// Response from POST /api/localsend/v2/prepare-download./// Used when the sender provides files for others to download.@@ -132,7 +132,7 @@ pub struct PrepareDownloadResponseDtoV2 {pub files: HashMap<String, FileDto>,}-/// Info response DTO for v2.1 protocol.+/// Info response DTO for v2.2 protocol.////// Response from GET /api/localsend/v2/info./// Also used as the `info` field in PrepareDownloadResponseDtoV2.@@ -142,7 +142,7 @@ pub struct InfoResponseDtoV2 {/// The display name of the device.pub alias: String,- /// Protocol version (e.g., "2.0", "2.1").+ /// Protocol version (e.g., "2.0", "2.2").pub version: String,/// Device model. Optional.@@ -228,7 +228,7 @@ mod tests {let request = PrepareUploadRequestDtoV2 {info: RegisterDtoV2 {alias: "Sender".to_string(),- version: "2.1".to_string(),+ version: "2.2".to_string(),device_model: None,device_type: None,fingerprint: "sender-fingerprint".to_string(),diff --git a/packages/core/src/http/server/common/session.rs b/packages/core/src/http/server/common/session.rsindex 9c7efb47..c909a311 100644--- a/packages/core/src/http/server/common/session.rs+++ b/packages/core/src/http/server/common/session.rs@@ -14,7 +14,7 @@ pub(crate) enum SessionStateV2 {/// A prepare-upload request that is waiting for the application's decision.///-/// Senders on protocol 2.0/2.1 do not know the session ID before the+/// Senders on protocol 2.0/2.1/2.2 do not know the session ID before the/// prepare-upload response, so they cancel the pending request with a/// session-less `POST /cancel` from the same address; `cancel` interrupts/// the waiting request handler.diff --git a/packages/core/src/model/discovery.rs b/packages/core/src/model/discovery.rsindex 30cb08a5..050aa14f 100644--- a/packages/core/src/model/discovery.rs+++ b/packages/core/src/model/discovery.rs@@ -1,7 +1,7 @@use serde::{Deserialize, Serialize};/// The protocol version (major.minor) implemented by this crate for the v2 protocol.-pub const PROTOCOL_VERSION_V2: &str = "2.1";+pub const PROTOCOL_VERSION_V2: &str = "2.2";#[derive(Clone, Debug, Deserialize, Eq, Serialize, PartialEq)]#[serde(rename_all = "SCREAMING_SNAKE_CASE")]@@ -98,7 +98,7 @@ pub(crate) mod device_type_v2 {}}-/// Multicast announcement message for UDP discovery (v2.1).+/// Multicast announcement message for UDP discovery (v2.2).////// Devices that receive an announcement respond over HTTP, so this message is/// only ever an announcement and never a response.@@ -108,7 +108,7 @@ pub struct MulticastMessageV2 {/// The display name of the device.pub alias: String,- /// Protocol version (e.g., "2.1").+ /// Protocol version (e.g., "2.2").pub version: String,/// Device model (e.g., "Samsung", "Windows"). Optional.@@ -148,7 +148,7 @@ mod tests {fn test_multicast_message_serialization() {let msg = MulticastMessageV2 {alias: "Nice Orange".to_string(),- version: "2.1".to_string(),+ version: "2.2".to_string(),device_model: Some("Samsung".to_string()),device_type: Some(DeviceType::Mobile),fingerprint: "random string".to_string(),@@ -159,7 +159,7 @@ mod tests {let json = serde_json::to_string(&msg).unwrap();assert!(json.contains("\"alias\":\"Nice Orange\""));- assert!(json.contains("\"version\":\"2.1\""));+ assert!(json.contains("\"version\":\"2.2\""));assert!(json.contains("\"fingerprint\":\"random string\""));assert!(json.contains("\"download\":true"));assert!(json.contains("\"protocol\":\"https\""));@@ -170,7 +170,7 @@ mod tests {fn test_multicast_message_deserialization() {let json = r#"{"alias": "Secret Banana",- "version": "2.1",+ "version": "2.2","deviceModel": "Windows","deviceType": "desktop","fingerprint": "random string",@@ -181,7 +181,7 @@ mod tests {let msg: MulticastMessageV2 = serde_json::from_str(json).unwrap();assert_eq!(msg.alias, "Secret Banana");- assert_eq!(msg.version, "2.1");+ assert_eq!(msg.version, "2.2");assert_eq!(msg.device_model, Some("Windows".to_string()));assert_eq!(msg.device_type, Some(DeviceType::Desktop));assert_eq!(msg.port, 53317);@@ -193,7 +193,7 @@ mod tests {fn test_multicast_message_without_optional_fields() {let json = r#"{"alias": "Secret Banana",- "version": "2.1",+ "version": "2.2","fingerprint": "random string","port": 53317,"protocol": "http"diff --git a/packages/core/src/multicast/mod.rs b/packages/core/src/multicast/mod.rsindex 101af1f7..760c3e1f 100644--- a/packages/core/src/multicast/mod.rs+++ b/packages/core/src/multicast/mod.rs@@ -1,4 +1,4 @@-//! UDP multicast discovery for the LocalSend protocol (v2.1).+//! UDP multicast discovery for the LocalSend protocol (v2.2).//!//! Devices announce themselves by sending a [`MulticastMessageV2`] to the//! multicast group. Announcements are only ever sent, never answered over UDP:@@ -32,7 +32,7 @@ pub const DEFAULT_MULTICAST_GROUP: Ipv4Addr = Ipv4Addr::new(224, 0, 0, 167);/// The IPv6 multicast group used by LocalSend, a transient (`ff1x::`) group/// with link-local scope.///-/// IPv6 discovery is a LocalSend extension on top of protocol v2.1, so IPv4+/// IPv6 discovery is a LocalSend extension on top of protocol v2.2, so IPv4/// remains the baseline and IPv6 is announced in parallel.pub const DEFAULT_MULTICAST_GROUP_V6: Ipv6Addr =Ipv6Addr::new(0xff12, 0, 0, 0, 0, 0, 0xfd3a, 0xe420);@@ -390,7 +390,7 @@ mod tests {fn test_sent_message_carries_legacy_announce_flag() {let device = MulticastDevice {alias: "Nice Orange".to_string(),- version: "2.1".to_string(),+ version: "2.2".to_string(),device_model: None,device_type: Some(DeviceType::Desktop),fingerprint: "my-fingerprint".to_string(),diff --git a/packages/core/tests/internal_server.rs b/packages/core/tests/internal_server.rsindex a27cf214..dd7cefc6 100644--- a/packages/core/tests/internal_server.rs+++ b/packages/core/tests/internal_server.rs@@ -42,7 +42,7 @@ async fn start_test_server(internal_enabled: bool) -> TestServer {None,ClientInfo {alias: "Test Server".to_string(),- version: "2.1".to_string(),+ version: "2.2".to_string(),device_model: Some("Rust".to_string()),device_type: None,token: "server-fingerprint".to_string(),diff --git a/packages/core/tests/v2_server.rs b/packages/core/tests/v2_server.rsindex c96be5e3..fb3b16e6 100644--- a/packages/core/tests/v2_server.rs+++ b/packages/core/tests/v2_server.rs@@ -129,7 +129,7 @@ async fn start_test_server_with_verification(None, // plain HTTPClientInfo {alias: "Test Server".to_string(),- version: "2.1".to_string(),+ version: "2.2".to_string(),device_model: Some("Rust".to_string()),device_type: None,token: "server-fingerprint".to_string(),@@ -187,7 +187,7 @@ async fn wait_until_reachable(port: u16) {fn sender_info() -> RegisterDtoV2 {RegisterDtoV2 {alias: "Test Sender".to_string(),- version: "2.1".to_string(),+ version: "2.2".to_string(),device_model: Some("Rust".to_string()),device_type: None,fingerprint: "sender-fingerprint".to_string(),@@ -972,7 +972,7 @@ async fn test_prepare_upload_aborted_by_sender_disconnect() {None, // plain HTTPClientInfo {alias: "Test Server".to_string(),- version: "2.1".to_string(),+ version: "2.2".to_string(),device_model: Some("Rust".to_string()),device_type: None,token: "server-fingerprint".to_string(),@@ -1075,7 +1075,7 @@ async fn test_prepare_upload_cancelled_by_session_less_cancel() {None, // plain HTTPClientInfo {alias: "Test Server".to_string(),- version: "2.1".to_string(),+ version: "2.2".to_string(),device_model: Some("Rust".to_string()),device_type: None,token: "server-fingerprint".to_string(),@@ -1211,7 +1211,7 @@ async fn test_prepare_upload_aborted_by_sender_disconnect_tls() {}),ClientInfo {alias: "Test Server".to_string(),- version: "2.1".to_string(),+ version: "2.2".to_string(),device_model: Some("Rust".to_string()),device_type: None,token: "server-fingerprint".to_string(),diff --git a/packages/core/tests/v2_tls_pinning.rs b/packages/core/tests/v2_tls_pinning.rsindex 2ee10129..87c1feae 100644--- a/packages/core/tests/v2_tls_pinning.rs+++ b/packages/core/tests/v2_tls_pinning.rs@@ -115,7 +115,7 @@ async fn start_tls_server_with_web(identity: &Identity, web: Option<WebConfig>)}),ClientInfo {alias: "Test Server".to_string(),- version: "2.1".to_string(),+ version: "2.2".to_string(),device_model: Some("Rust".to_string()),device_type: None,token: identity.fingerprint.clone(),@@ -180,7 +180,7 @@ fn client(sender: &Identity, expected_fingerprint: Option<&str>) -> LsHttpClientfn sender_info(fingerprint: &str) -> RegisterDtoV2 {RegisterDtoV2 {alias: "Test Sender".to_string(),- version: "2.1".to_string(),+ version: "2.2".to_string(),device_model: Some("Rust".to_string()),device_type: None,fingerprint: fingerprint.to_string(),diff --git a/packages/core/tests/v2_web_send.rs b/packages/core/tests/v2_web_send.rsindex 3829f3e9..48dfc277 100644--- a/packages/core/tests/v2_web_send.rs+++ b/packages/core/tests/v2_web_send.rs@@ -132,7 +132,7 @@ async fn start_test_server(None, // plain HTTPClientInfo {alias: "Test Server".to_string(),- version: "2.1".to_string(),+ version: "2.2".to_string(),device_model: Some("Rust".to_string()),device_type: None,token: "server-fingerprint".to_string(),@@ -333,7 +333,7 @@ async fn test_upload_page() {None, // plain HTTPClientInfo {alias: "Test Server".to_string(),- version: "2.1".to_string(),+ version: "2.2".to_string(),device_model: Some("Rust".to_string()),device_type: None,token: "server-fingerprint".to_string(),diff --git a/packages/localsend_isolates/lib/constants.dart b/packages/localsend_isolates/lib/constants.dartindex 1bc13e3b..7115ad16 100644--- a/packages/localsend_isolates/lib/constants.dart+++ b/packages/localsend_isolates/lib/constants.dart@@ -6,16 +6,8 @@/// 1.0 | 1.0.0 - 1.8.0/// 1.0, 2.0 | 1.9.0 - 1.14.0/// 1.0, 2.1 | 1.15.0 - 1.17.0-/// 2.1 | 1.18.0-const protocolVersion = '2.1';--/// Assumed protocol version of peers for first handshake.-/// Generally this should be slightly lower than the current protocol version.-const peerProtocolVersion = '1.0';--/// The protocol version when no version is specified.-/// Prior v2, the protocol version was not specified.-const fallbackProtocolVersion = '1.0';+/// 2.2 | 1.18.0+const protocolVersion = '2.2';/// The default http server port and/// and multicast port.diff --git a/packages/localsend_isolates/test/task/server/cancel_session_repro_test.dart b/packages/localsend_isolates/test/task/server/cancel_session_repro_test.dartindex 3ac0d9ab..6bd14320 100644--- a/packages/localsend_isolates/test/task/server/cancel_session_repro_test.dart+++ b/packages/localsend_isolates/test/task/server/cancel_session_repro_test.dart@@ -47,7 +47,7 @@ void main() {port: _port,tls: null,alias: 'Receiver',- version: '2.1',+ version: '2.2',deviceModel: 'Test',deviceType: null,fingerprint: 'RECEIVER-FINGERPRINT',@@ -129,7 +129,7 @@ void main() {jsonEncode({'info': {'alias': 'Sender',- 'version': '2.1',+ 'version': '2.2','fingerprint': 'SENDER-FINGERPRINT','port': 1,'protocol': 'http',