Linux + iPhone Continuity / iMessage / SMS
feat(protocol): correlate send_file completion with optional ID
Nick Pisani904d92babbc3
diff --git a/docs/PROTOCOL.md b/docs/PROTOCOL.mdindex 4eeba1a..d1a69c3 100644--- a/docs/PROTOCOL.md+++ b/docs/PROTOCOL.md@@ -292,8 +292,13 @@ a peer: a node that still trusts it will keep dialling it (see §3).### `send_file` (Local Client -> Daemon)Offloads an entire file transfer to the daemon. The daemon spawns a thread to read the local filesystem and pushes the chunks sequence securely.-**Payload**: `{"command": "send_file", "path": "/absolute/path/to/my_video.mp4"}`-**Response**: `{"command": "file_send_complete", "success": true, "message": "Sent my_video.mp4"}`+**Payload**: `{"command": "send_file", "path": "/absolute/path/to/my_video.mp4", "operation_id": "file-1"}`+The `operation_id` is optional. When supplied, the asynchronous+`file_send_complete` event echoes it, including on failure, so a local client+can match the result to its request. Existing clients may omit it; their result+remains `{"command": "file_send_complete", "success": true, "message": "Sent my_video.mp4"}`.+The ID correlates results and does not authorize the request. The file must+remain available at the path until the terminal result arrives.---diff --git a/src/core/src/net.cpp b/src/core/src/net.cppindex 1b7cc97..ac0ed89 100644--- a/src/core/src/net.cpp+++ b/src/core/src/net.cpp@@ -1665,7 +1665,8 @@ namespace tether {}).detach();} else if (j.contains("command") && j["command"] == "send_file" && j.contains("path")) {std::string path = j["path"];- std::thread([path]() {+ const std::string operation_id = j.value("operation_id", std::string{});+ std::thread([path, operation_id]() {Client local;if (local.connect("", 0)) { // connects correctly via unix socketstd::string err;@@ -1676,6 +1677,8 @@ namespace tether {resp["message"] =ok ? tr_format(_("Sent {}"), std::filesystem::path(path).filename().string()): tr_format(_("Send failed: {}"), err.empty() ? _("unknown error") : err);+ if (!operation_id.empty())+ resp["operation_id"] = operation_id;broadcast_local_event(resp.dump());}diff --git a/test/test_net.cpp b/test/test_net.cppindex 6030b32..04819bd 100644--- a/test/test_net.cpp+++ b/test/test_net.cpp@@ -411,6 +411,64 @@ namespace {EXPECT_EQ(result.value("operation_id", ""), "web-unpair-1");}+ TEST(UnixServerTest, FileSendCompletionEchoesOptionalOperationId) {+ const std::string runtime_dir = unique_test_dir("tether_unix_file_send_test");+ CleanupGuard cleanup_guard(runtime_dir);+ std::filesystem::remove_all(runtime_dir);+ std::filesystem::create_directories(runtime_dir);+ ScopedEnvVar xdg_runtime_dir("XDG_RUNTIME_DIR", runtime_dir);++ tether::EpollEventLoop loop;+ tether::TcpServer tcp_server(loop, 0);+ tether::UnixServer unix_server(loop, tcp_server);+ ASSERT_TRUE(unix_server.start());+ EventLoopGuard loop_guard(loop);++ const int client = socket(AF_UNIX, SOCK_STREAM, 0);+ ASSERT_GE(client, 0);+ timeval timeout{2, 0};+ ASSERT_EQ(setsockopt(client, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)), 0);+ sockaddr_un address{};+ address.sun_family = AF_UNIX;+ std::snprintf(+ address.sun_path, sizeof(address.sun_path), "%s", (tether::get_runtime_dir() + "/tetherd.sock").c_str());+ ASSERT_EQ(connect(client, reinterpret_cast<sockaddr*>(&address), sizeof(address)), 0);++ const std::string subscribe = "{\"command\":\"subscribe\"}\n";+ ASSERT_EQ(write(client, subscribe.data(), subscribe.size()), static_cast<ssize_t>(subscribe.size()));+ ASSERT_FALSE(read_socket_line(client).empty());++ for (const std::string operation_id : {"web-file-1", ""}) {+ nlohmann::json send = {{"command", "send_file"}, {"path", runtime_dir + "/missing.txt"}};+ if (!operation_id.empty())+ send["operation_id"] = operation_id;+ const std::string payload = send.dump() + "\n";+ ASSERT_EQ(write(client, payload.data(), payload.size()), static_cast<ssize_t>(payload.size()));++ nlohmann::json result;+ for (int attempt = 0; attempt < 8; ++attempt) {+ const std::string line = read_socket_line(client);+ if (line.empty())+ break;+ try {+ auto candidate = nlohmann::json::parse(line);+ if (candidate.value("command", "") == "file_send_complete") {+ result = std::move(candidate);+ break;+ }+ } catch (...) {+ }+ }+ ASSERT_FALSE(result.is_null());+ EXPECT_FALSE(result.value("success", true));+ if (operation_id.empty())+ EXPECT_FALSE(result.contains("operation_id"));+ else+ EXPECT_EQ(result.value("operation_id", ""), operation_id);+ }+ close(client);+ }+TEST(ControlProtocolTest, AdvertisesVersionedCapabilities) {const auto info = tether::build_protocol_info();EXPECT_EQ(info.value("command", ""), "protocol_info");