Files
SimpleRemoter/android/app
yuanyuanxiangandDeepSeek-V4.1-Flash 1401ff0a4c Feat(android): support the assign-master command
The Android client now handles COMMAND_ASSIGN_MASTER (SHARE_TYPE_YAMA_FOREVER)
and reuses common/host_transfer.h for the parsing and for the on-disk record -
the same code the Linux and macOS clients already use.

Windows and Linux keep the main link where it is and spawn a second instance so
the new master sees the host right away, moving the main link only on the next
reconnect. Android cannot do that: the login state (ClientAuth verification,
the heartbeat ACK watchdog, the main client handle, g_bExit) is process-wide,
so a second login connection would reset the first one's verification and make
it drop every command it receives. Sharing has the same problem and stays
unimplemented. Android therefore switches immediately: change the target,
disconnect, reconnect. The new master sees the host at once and the old one
loses it at once.

Four cases, each exercised against two real masters:

  not transferred, target elsewhere        transfer
  not transferred, target is the original  ignored - it would only cost a
                                           reconnect and leave a record that
                                           "expires back to itself"
  transferred, target elsewhere            refused with a ClientMsg; this is
                                           what stops B from chaining the host
                                           to C, which would orphan the middle
                                           hop because expiry always restores
                                           to A
  transferred, target is the original      early return: the expiry time is set
                                           to now and the verified expiry path
                                           does the restore, so a master can
                                           hand the host back instead of
                                           waiting out the term

The record lives in filesDir/yama_transfer; the original master is captured
once at init and never written back, because restoring from a record that
points at the transfer target is a no-op loop. A target that stays unreachable
for 60 s (and at least 3 attempts) reverts to the original master so a typo
does not lose the host; the 60 s floor exists because a Wi-Fi hiccup would
otherwise cancel a perfectly good transfer.

Both the switch and the expiry are checked once a second rather than once per
heartbeat. With the 30 s cycle a 0.001 day (86 s) transfer took effect 14 s
late and restored 20 s late, measured; now both are under a second.

g_serverIp/g_serverPort moved behind a mutex and every connect site takes a
snapshot first: the transfer rewrites them at runtime while the screen, log,
chat, audio and terminal threads read them to connect, and assigning a
std::string frees the buffer another thread may still be holding.

ClientMsg titles are ASCII. The controller decodes title/text as ANSI/GBK, so a
Chinese literal from this UTF-8 source reaches the message pane as mojibake.

Verified on an API 35 x86_64 emulator: 443 -> 6543 -> back, refused chaining,
unreachable-target revert, natural expiry, and restart from a record.
host_transfer.h is covered by a standalone test (24 assertions: with and
without the transport field, share type rejected, port 0 / days 0 / empty IP /
bad transport, record round-trip, expiry). Sharing is answered with "Android
client does not support sharing a host" instead of being ignored.

Co-Authored-By: DeepSeek-V4.1-Flash
2026-11-15 17:51:44 +01:00
..