package main import ( "encoding/binary" "testing" "github.com/yuanyuanxiang/SimpleRemoter/server/go/protocol" ) // The Linux and Android clients only accept a heartbeat ACK when // `ulLength >= 1 + sizeof(HeartbeatACK)` == 1025 bytes and silently ignore a // shorter packet, so the 60s ACK watchdog never gets fed and the client // reconnects forever. A 33-byte reply here did exactly that on the Go server // (linux/main.cpp:2107 "Heartbeat ACK timeout: 60007 ms ... reconnecting", // once a minute, with the terminal session dying on every reconnect). func TestBuildHeartbeatACKIsFullSize(t *testing.T) { const hbTime = uint64(0x1122334455667788) resp := buildHeartbeatACK(hbTime, 2) if want := 1 + 1024; len(resp) != want { t.Fatalf("ACK length = %d, want %d (shorter packets are ignored by the client)", len(resp), want) } if resp[0] != protocol.CommandHeartbeat { t.Fatalf("cmd byte = %d, want %d", resp[0], protocol.CommandHeartbeat) } if got := binary.LittleEndian.Uint64(resp[1+protocol.HeartbeatACKOffTime:]); got != hbTime { t.Fatalf("echoed Time = %#x, want %#x", got, hbTime) } if got := resp[1+protocol.HeartbeatACKOffAuthorized]; got != 2 { t.Fatalf("Authorized = %d, want 2", got) } if got := binary.LittleEndian.Uint32(resp[1+protocol.HeartbeatACKOffProcessing:]); got != 0 { t.Fatalf("ProcessingMs = %d, want 0 (unknown => plain now-Time RTT)", got) } }