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:
1 parent
b466f568ab
commit
63c7cdf588
18 files changed
+1024
-177
No files matched your search
@@ -58,6 +58,14 @@ type Record struct {
|
||||
|
||||
FirstSeen int64 `json:"first_seen"`
|
||||
LastSeen int64 `json:"last_seen"`
|
||||
|
||||
// TransferTo / TransferUntil mark a host that was handed over to another
|
||||
// master (COMMAND_ASSIGN_MASTER): target is "host:port", until is the unix
|
||||
// second the client goes back to its original master on its own. The store
|
||||
// only remembers it for display — it never acts on the deadline, and a
|
||||
// login here clears it because that means the host is back.
|
||||
TransferTo string `json:"transfer_to,omitempty"`
|
||||
TransferUntil int64 `json:"transfer_until,omitempty"`
|
||||
}
|
||||
|
||||
type fileShape struct {
|
||||
@@ -165,6 +173,13 @@ func (s *Store) upsertAt(d hub.DeviceInfo, at time.Time) {
|
||||
rec.IP = d.IP
|
||||
rec.Screen = d.Screen
|
||||
rec.LastSeen = now
|
||||
// A login on this server means the host is here, not at the master it was
|
||||
// handed to: either it came back early (the upgrade finished, or the target
|
||||
// was unreachable) or the deadline passed while this server was down. In
|
||||
// both cases the marker would label an online card as "transferred" and
|
||||
// keep the operator from transferring it again until the deadline.
|
||||
rec.TransferTo = ""
|
||||
rec.TransferUntil = 0
|
||||
s.online[d.ID] = true
|
||||
|
||||
s.pruneLocked()
|
||||
@@ -244,6 +259,59 @@ func (s *Store) Offline(online map[string]struct{}) []hub.DeviceInfo {
|
||||
return out
|
||||
}
|
||||
|
||||
// SetTransfer marks id as handed over to target ("host:port") until the given
|
||||
// unix second. Reports false when the device has no history record — only a
|
||||
// device that logged in at least once can be transferred, and the marker has
|
||||
// nowhere to live otherwise.
|
||||
func (s *Store) SetTransfer(id, target string, until int64) bool {
|
||||
if id == "" || target == "" || until <= 0 {
|
||||
return false
|
||||
}
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
rec, ok := s.devices[id]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
rec.TransferTo = target
|
||||
rec.TransferUntil = until
|
||||
s.markDirtyLocked()
|
||||
return true
|
||||
}
|
||||
|
||||
// ClearTransfer forgets the handover marker and reports whether one was set.
|
||||
func (s *Store) ClearTransfer(id string) bool {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
rec, ok := s.devices[id]
|
||||
if !ok || rec.TransferUntil == 0 {
|
||||
return false
|
||||
}
|
||||
rec.TransferTo = ""
|
||||
rec.TransferUntil = 0
|
||||
s.markDirtyLocked()
|
||||
return true
|
||||
}
|
||||
|
||||
// Transfer returns the current handover marker, dropping it once the deadline
|
||||
// has passed: the client returns to its original master by itself, so an
|
||||
// expired marker would only mislabel the card forever.
|
||||
func (s *Store) Transfer(id string) (target string, until int64, ok bool) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
rec, found := s.devices[id]
|
||||
if !found || rec.TransferUntil == 0 {
|
||||
return "", 0, false
|
||||
}
|
||||
if time.Now().Unix() >= rec.TransferUntil {
|
||||
rec.TransferTo = ""
|
||||
rec.TransferUntil = 0
|
||||
s.markDirtyLocked()
|
||||
return "", 0, false
|
||||
}
|
||||
return rec.TransferTo, rec.TransferUntil, true
|
||||
}
|
||||
|
||||
// Remove deletes the persisted record for id and reports whether one existed.
|
||||
// This is the web UI's explicit "delete" for an offline device: an offline
|
||||
// record has no live agent to uninstall, so forgetting it is all "delete" can
|
||||
|
||||
Reference in new issue
Block a user