Feature: transfer a Go-managed host to the MFC master from the web console

A Go-managed host cannot receive the client upgrade that only the MFC master
can push. Transfer moves its main link there and brings it back after N days;
MFC has no reason to return it.

Transfer is not share: ASSIGN writes the target and drops the current
connection, so the old master sees the host go offline and the new master gets
a normal main link it can remote control and upgrade. While a transfer is live
the client refuses a second transfer and any share, so no host is handed to a
third master that expiry would orphan.

Server: admin-only `transfer_device` WS command, COMMAND_ASSIGN_MASTER +
SHARE_TYPE_YAMA_FOREVER as `host:port:days::transport\0`, byte-compatible with
the MFC dialog. The transport segment is always present (YAMA_TRANSFER_TRANSPORT,
default 0/TCP) because clients keep their current link when it is missing: a
WSS-managed host would otherwise retry WSS against the MFC master's raw TCP
port and never connect. The empty shine segment keeps the host's header
encryption. The button only renders when `device_list.transfer` is present,
which MFC never sends, so no MFC change is needed. devicehistory keeps
transfer_to/transfer_until for the card badge and drops the marker on expiry or
on a fresh login here.

Client: KernelManager.cpp writes the registry and disconnects; ClientDll.cpp
re-reads the registry at the top of every reconnect, so a mid-session transfer
lands on the next round. Expiry is checked before every connect attempt as well
as inside the heartbeat loop, so an unreachable target cannot pin the host to
an expired address until a restart; restoring rebuilds the link captured on
entry (address, header encryption, transport). linux/main.cpp applies the
transfer on the main loop and restores the captured endpoint at expiry; Android
does the same; macOS has neither share nor transfer.
This commit is contained in:
yuanyuanxiang committed 2026-11-20 12:23:08 +01:00
1 parent b466f568ab
commit 63c7cdf588
18 files changed
+1024 -177

No files matched your search

+41
View File
@@ -155,6 +155,21 @@ const (
CommandBye byte = 204 // COMMAND_BYE - disconnect
CommandHeartbeat byte = 216 // CMD_HEARTBEAT_ACK
// CommandAssignMaster moves a host to another master (COMMAND_ASSIGN_MASTER).
// Payload: [cmd][ShareTypeYamaForever]host:port:days[:shine[:transport]]\0
// The client stores the target plus a deadline and goes back to the master it
// captured at startup when the deadline passes — the Go server does not take
// part in the restore. See common/host_transfer.h.
CommandAssignMaster byte = 207
ShareTypeYamaForever byte = 100 // SHARE_TYPE_YAMA_FOREVER — "transfer", not "share"
// TransferTransport* are the clients' CONNECT_ADDRESS.protoType values
// (common/commands.h): PROTO_TCP=0, PROTO_WS=5, PROTO_WSS=6. They travel in
// the assign-master payload's transport segment.
TransferTransportTCP int = 0
TransferTransportWS int = 5
TransferTransportWSS int = 6
// Client -> Server tokens
TokenAuth byte = 100 // TOKEN_AUTH - authorization required
TokenHeartbeat byte = 101 // TOKEN_HEARTBEAT
@@ -705,3 +720,29 @@ func BuildValidation(days float64, admin string, port int, maxDepth uint16) []by
return data
}
// BuildAssignMasterPacket encodes a "transfer this host to another master"
// command, byte-compatible with the MFC server's assignFunction
// (server/2015Remote/2015RemoteDlg.cpp):
//
// [COMMAND_ASSIGN_MASTER][SHARE_TYPE_YAMA_FOREVER]host:port:days::transport\0
//
// The shine segment stays empty: the header-encryption variant is not
// something this server can know better than the host, and clients rotate it
// when a login is rejected (client/IOCPClient.h). The transport segment is
// always sent, because an absent segment does **not** mean "plain TCP" to the
// clients — they keep the link they run today (client/ClientDll.cpp
// ApplyAssignedMaster, common/host_endpoint.h ApplyEndpoint). A host that
// talks WSS to this server would then try WSS against the MFC master's raw TCP
// port and never connect. The caller picks the transport; TCP (0) matches what
// an MFC master listens on. days is formatted without trailing zeros so "0.5"
// survives the round trip.
func BuildAssignMasterPacket(host string, port int, days float64, transport int) []byte {
payload := host + ":" + strconv.Itoa(port) + ":" + strconv.FormatFloat(days, 'f', -1, 64) +
"::" + strconv.Itoa(transport)
pkt := make([]byte, 0, 2+len(payload)+1)
pkt = append(pkt, CommandAssignMaster, ShareTypeYamaForever)
pkt = append(pkt, payload...)
pkt = append(pkt, 0) // clients parse the payload as a C string
return pkt
}
+32
View File
@@ -103,3 +103,35 @@ func isCommandTokenName(name string) bool {
strings.HasPrefix(name, "Token") ||
strings.HasPrefix(name, "Cmd")
}
// The assign-master payload must stay byte-compatible with the MFC master's
// assignFunction, otherwise the client parses the wrong fields: days keeps
// fractions ("0.5" for a half-day handover) and the string is NUL-terminated
// because both clients read it as a C string. The shine segment is empty
// (clients then keep their header-encryption variant) while the transport
// segment is always present — without it the clients would keep the link they
// run today, which is exactly the WSS-vs-TCP mismatch that made the transfer
// unreachable.
func TestBuildAssignMasterPacket(t *testing.T) {
cases := []struct {
host string
port int
days float64
transport int
want string
}{
{"mfc.example", 6544, 1, TransferTransportTCP, "mfc.example:6544:1::0\x00"},
{"10.0.0.5", 6543, 0.5, TransferTransportTCP, "10.0.0.5:6543:0.5::0\x00"},
{"mfc.example", 6544, 2.25, TransferTransportWS, "mfc.example:6544:2.25::5\x00"},
{"mfc.example", 6544, 1, TransferTransportWSS, "mfc.example:6544:1::6\x00"},
}
for _, tc := range cases {
got := BuildAssignMasterPacket(tc.host, tc.port, tc.days, tc.transport)
if len(got) < 2 || got[0] != CommandAssignMaster || got[1] != ShareTypeYamaForever {
t.Fatalf("header = %v, want [%d %d]", got[:2], CommandAssignMaster, ShareTypeYamaForever)
}
if string(got[2:]) != tc.want {
t.Fatalf("payload = %q, want %q", got[2:], tc.want)
}
}
}