refactor(node): remove legacy AX aliases
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
79591c3635
commit
390e60860e
13 changed files with 147 additions and 207 deletions
|
|
@ -36,7 +36,7 @@ func BenchmarkDeriveSharedSecret(b *testing.B) {
|
|||
nm2, _ := NewNodeManagerFromPaths(testJoinPath(dir2, "k"), testJoinPath(dir2, "n"))
|
||||
nm2.GenerateIdentity("node2", RoleDual)
|
||||
|
||||
peerPubKey := nm2.Identity().PublicKey
|
||||
peerPubKey := nm2.GetIdentity().PublicKey
|
||||
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
|
|
@ -151,7 +151,7 @@ func BenchmarkSMSGEncryptDecrypt(b *testing.B) {
|
|||
nm2, _ := NewNodeManagerFromPaths(testJoinPath(dir2, "k"), testJoinPath(dir2, "n"))
|
||||
nm2.GenerateIdentity("node2", RoleDual)
|
||||
|
||||
sharedSecret, _ := nm1.DeriveSharedSecret(nm2.Identity().PublicKey)
|
||||
sharedSecret, _ := nm1.DeriveSharedSecret(nm2.GetIdentity().PublicKey)
|
||||
password := base64.StdEncoding.EncodeToString(sharedSecret)
|
||||
|
||||
// Prepare a message to encrypt
|
||||
|
|
|
|||
|
|
@ -146,11 +146,6 @@ func (c *Controller) GetRemoteStats(peerID string) (*StatsPayload, error) {
|
|||
return &stats, nil
|
||||
}
|
||||
|
||||
// RemoteStats is a deprecated compatibility alias for GetRemoteStats.
|
||||
func (c *Controller) RemoteStats(peerID string) (*StatsPayload, error) {
|
||||
return c.GetRemoteStats(peerID)
|
||||
}
|
||||
|
||||
// StartRemoteMiner requests a remote peer to start a miner with a given profile.
|
||||
//
|
||||
// err := controller.StartRemoteMiner("worker-1", "xmrig", "profile-1", nil)
|
||||
|
|
@ -259,11 +254,6 @@ func (c *Controller) GetRemoteLogs(peerID, minerName string, lines int) ([]strin
|
|||
return logs.Lines, nil
|
||||
}
|
||||
|
||||
// RemoteLogs is a deprecated compatibility alias for GetRemoteLogs.
|
||||
func (c *Controller) RemoteLogs(peerID, minerName string, lines int) ([]string, error) {
|
||||
return c.GetRemoteLogs(peerID, minerName, lines)
|
||||
}
|
||||
|
||||
// GetAllStats fetches stats from all connected peers.
|
||||
//
|
||||
// statsByPeerID := controller.GetAllStats()
|
||||
|
|
@ -295,11 +285,6 @@ func (c *Controller) GetAllStats() map[string]*StatsPayload {
|
|||
return results
|
||||
}
|
||||
|
||||
// AllStats is a deprecated compatibility alias for GetAllStats.
|
||||
func (c *Controller) AllStats() map[string]*StatsPayload {
|
||||
return c.GetAllStats()
|
||||
}
|
||||
|
||||
// PingPeer sends a ping to a peer and refreshes that peer's metrics.
|
||||
//
|
||||
// rttMS, err := controller.PingPeer("worker-1")
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ func makeWorkerServer(t *testing.T) (*NodeManager, string, *Transport) {
|
|||
|
||||
func TestController_RequestResponseCorrelation_Good(t *testing.T) {
|
||||
controller, _, tp := setupControllerPair(t)
|
||||
serverID := tp.ServerNode.Identity().ID
|
||||
serverID := tp.ServerNode.GetIdentity().ID
|
||||
|
||||
// Send a ping request via the controller; the server-side worker
|
||||
// replies with MessagePong, setting ReplyTo to the original message ID.
|
||||
|
|
@ -97,8 +97,8 @@ func TestController_RequestTimeout_Bad(t *testing.T) {
|
|||
tp.connectClient(t)
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
||||
serverID := tp.ServerNode.Identity().ID
|
||||
clientID := tp.ClientNode.Identity().ID
|
||||
serverID := tp.ServerNode.GetIdentity().ID
|
||||
clientID := tp.ClientNode.GetIdentity().ID
|
||||
|
||||
// Use sendRequest directly with a short deadline (PingPeer uses 5s internally).
|
||||
msg, err := NewMessage(MessagePing, clientID, serverID, PingPayload{
|
||||
|
|
@ -126,7 +126,7 @@ func TestController_AutoConnect_Good(t *testing.T) {
|
|||
controller := NewController(tp.ClientNode, tp.ClientReg, tp.Client)
|
||||
|
||||
// Add the server peer to the client registry so auto-connect can resolve it.
|
||||
serverIdentity := tp.ServerNode.Identity()
|
||||
serverIdentity := tp.ServerNode.GetIdentity()
|
||||
peer := &Peer{
|
||||
ID: serverIdentity.ID,
|
||||
Name: "server",
|
||||
|
|
@ -159,7 +159,7 @@ func TestController_AllStats_Good(t *testing.T) {
|
|||
|
||||
for i := range numWorkers {
|
||||
nm, addr, _ := makeWorkerServer(t)
|
||||
wID := nm.Identity().ID
|
||||
wID := nm.GetIdentity().ID
|
||||
workerIDs[i] = wID
|
||||
|
||||
peer := &Peer{
|
||||
|
|
@ -179,7 +179,7 @@ func TestController_AllStats_Good(t *testing.T) {
|
|||
controller := NewController(controllerNM, controllerReg, controllerTransport)
|
||||
|
||||
// AllStats fetches stats from all connected peers in parallel.
|
||||
stats := controller.AllStats()
|
||||
stats := controller.GetAllStats()
|
||||
assert.Len(t, stats, numWorkers, "should get stats from all connected workers")
|
||||
|
||||
for _, wID := range workerIDs {
|
||||
|
|
@ -194,10 +194,10 @@ func TestController_AllStats_Good(t *testing.T) {
|
|||
|
||||
func TestController_PingPeerRTT_Good(t *testing.T) {
|
||||
controller, _, tp := setupControllerPair(t)
|
||||
serverID := tp.ServerNode.Identity().ID
|
||||
serverID := tp.ServerNode.GetIdentity().ID
|
||||
|
||||
// Record initial peer metrics.
|
||||
peerBefore := tp.ClientReg.Peer(serverID)
|
||||
peerBefore := tp.ClientReg.GetPeer(serverID)
|
||||
require.NotNil(t, peerBefore, "server peer should exist in the client registry")
|
||||
initialPingMS := peerBefore.PingMS
|
||||
|
||||
|
|
@ -208,7 +208,7 @@ func TestController_PingPeerRTT_Good(t *testing.T) {
|
|||
assert.Less(t, rtt, 1000.0, "RTT on loopback should be well under 1000ms")
|
||||
|
||||
// Verify the peer registry was updated with the measured latency.
|
||||
peerAfter := tp.ClientReg.Peer(serverID)
|
||||
peerAfter := tp.ClientReg.GetPeer(serverID)
|
||||
require.NotNil(t, peerAfter, "server peer should still exist after ping")
|
||||
assert.NotEqual(t, initialPingMS, peerAfter.PingMS,
|
||||
"PingMS should be updated after a successful ping")
|
||||
|
|
@ -228,7 +228,7 @@ func TestController_ConcurrentRequests_Ugly(t *testing.T) {
|
|||
|
||||
for i := range numPeers {
|
||||
nm, addr, _ := makeWorkerServer(t)
|
||||
pID := nm.Identity().ID
|
||||
pID := nm.GetIdentity().ID
|
||||
peerIDs[i] = pID
|
||||
|
||||
peer := &Peer{
|
||||
|
|
@ -279,8 +279,8 @@ func TestController_DeadPeerCleanup_Good(t *testing.T) {
|
|||
tp.connectClient(t)
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
||||
serverID := tp.ServerNode.Identity().ID
|
||||
clientID := tp.ClientNode.Identity().ID
|
||||
serverID := tp.ServerNode.GetIdentity().ID
|
||||
clientID := tp.ClientNode.GetIdentity().ID
|
||||
|
||||
// Fire off a request that will time out.
|
||||
msg, err := NewMessage(MessagePing, clientID, serverID, PingPayload{
|
||||
|
|
@ -308,7 +308,7 @@ func TestController_DeadPeerCleanup_Good(t *testing.T) {
|
|||
func TestController_MultipleSequentialPings_Good(t *testing.T) {
|
||||
// Ensures sequential requests to the same peer are correctly correlated.
|
||||
controller, _, tp := setupControllerPair(t)
|
||||
serverID := tp.ServerNode.Identity().ID
|
||||
serverID := tp.ServerNode.GetIdentity().ID
|
||||
|
||||
for i := range 5 {
|
||||
rtt, err := controller.PingPeer(serverID)
|
||||
|
|
@ -321,7 +321,7 @@ func TestController_ConcurrentRequestsSamePeer_Ugly(t *testing.T) {
|
|||
// Multiple goroutines sending requests to the SAME peer simultaneously.
|
||||
// Tests concurrent pending-map insertions/deletions under contention.
|
||||
controller, _, tp := setupControllerPair(t)
|
||||
serverID := tp.ServerNode.Identity().ID
|
||||
serverID := tp.ServerNode.GetIdentity().ID
|
||||
|
||||
const goroutines = 10
|
||||
var wg sync.WaitGroup
|
||||
|
|
@ -343,9 +343,9 @@ func TestController_ConcurrentRequestsSamePeer_Ugly(t *testing.T) {
|
|||
|
||||
func TestController_RemoteStats_Good(t *testing.T) {
|
||||
controller, _, tp := setupControllerPair(t)
|
||||
serverID := tp.ServerNode.Identity().ID
|
||||
serverID := tp.ServerNode.GetIdentity().ID
|
||||
|
||||
stats, err := controller.RemoteStats(serverID)
|
||||
stats, err := controller.GetRemoteStats(serverID)
|
||||
require.NoError(t, err, "RemoteStats should succeed")
|
||||
require.NotNil(t, stats)
|
||||
|
||||
|
|
@ -366,7 +366,7 @@ func TestController_ConnectToPeerUnknown_Bad(t *testing.T) {
|
|||
|
||||
func TestController_DisconnectFromPeer_Good(t *testing.T) {
|
||||
controller, _, tp := setupControllerPair(t)
|
||||
serverID := tp.ServerNode.Identity().ID
|
||||
serverID := tp.ServerNode.GetIdentity().ID
|
||||
|
||||
assert.Equal(t, 1, tp.Client.ConnectedPeerCount(), "should have 1 connection")
|
||||
|
||||
|
|
@ -387,7 +387,7 @@ func TestController_SendRequestPeerNotFound_Bad(t *testing.T) {
|
|||
tp := setupTestTransportPair(t)
|
||||
controller := NewController(tp.ClientNode, tp.ClientReg, tp.Client)
|
||||
|
||||
clientID := tp.ClientNode.Identity().ID
|
||||
clientID := tp.ClientNode.GetIdentity().ID
|
||||
msg, err := NewMessage(MessagePing, clientID, "ghost-peer", PingPayload{
|
||||
SentAt: time.Now().UnixMilli(),
|
||||
})
|
||||
|
|
@ -530,7 +530,7 @@ func (m *mockMinerFull) ConsoleHistory(lines int) []string { return m.GetConsole
|
|||
|
||||
func TestController_StartRemoteMiner_Good(t *testing.T) {
|
||||
controller, _, tp := setupControllerPairWithMiner(t)
|
||||
serverID := tp.ServerNode.Identity().ID
|
||||
serverID := tp.ServerNode.GetIdentity().ID
|
||||
configOverride := RawMessage(`{"pool":"pool.example.com:3333"}`)
|
||||
err := controller.StartRemoteMiner(serverID, "xmrig", "profile-1", configOverride)
|
||||
|
||||
|
|
@ -539,7 +539,7 @@ func TestController_StartRemoteMiner_Good(t *testing.T) {
|
|||
|
||||
func TestController_StartRemoteMiner_WithConfig_Good(t *testing.T) {
|
||||
controller, _, tp := setupControllerPairWithMiner(t)
|
||||
serverID := tp.ServerNode.Identity().ID
|
||||
serverID := tp.ServerNode.GetIdentity().ID
|
||||
|
||||
configOverride := RawMessage(`{"pool":"custom-pool:3333","threads":4}`)
|
||||
err := controller.StartRemoteMiner(serverID, "xmrig", "", configOverride)
|
||||
|
|
@ -548,7 +548,7 @@ func TestController_StartRemoteMiner_WithConfig_Good(t *testing.T) {
|
|||
|
||||
func TestController_StartRemoteMiner_EmptyType_Bad(t *testing.T) {
|
||||
controller, _, tp := setupControllerPairWithMiner(t)
|
||||
serverID := tp.ServerNode.Identity().ID
|
||||
serverID := tp.ServerNode.GetIdentity().ID
|
||||
|
||||
err := controller.StartRemoteMiner(serverID, "", "profile-1", nil)
|
||||
require.Error(t, err, "StartRemoteMiner with empty miner type should fail")
|
||||
|
|
@ -572,7 +572,7 @@ func TestController_StartRemoteMiner_NoIdentity_Bad(t *testing.T) {
|
|||
|
||||
func TestController_StopRemoteMiner_Good(t *testing.T) {
|
||||
controller, _, tp := setupControllerPairWithMiner(t)
|
||||
serverID := tp.ServerNode.Identity().ID
|
||||
serverID := tp.ServerNode.GetIdentity().ID
|
||||
|
||||
err := controller.StopRemoteMiner(serverID, "running-miner")
|
||||
require.NoError(t, err, "StopRemoteMiner should succeed for existing miner")
|
||||
|
|
@ -580,7 +580,7 @@ func TestController_StopRemoteMiner_Good(t *testing.T) {
|
|||
|
||||
func TestController_StopRemoteMiner_NotFound_Bad(t *testing.T) {
|
||||
controller, _, tp := setupControllerPairWithMiner(t)
|
||||
serverID := tp.ServerNode.Identity().ID
|
||||
serverID := tp.ServerNode.GetIdentity().ID
|
||||
|
||||
err := controller.StopRemoteMiner(serverID, "non-existent-miner")
|
||||
require.Error(t, err, "StopRemoteMiner should fail for non-existent miner")
|
||||
|
|
@ -601,9 +601,9 @@ func TestController_StopRemoteMiner_NoIdentity_Bad(t *testing.T) {
|
|||
|
||||
func TestController_RemoteLogs_Good(t *testing.T) {
|
||||
controller, _, tp := setupControllerPairWithMiner(t)
|
||||
serverID := tp.ServerNode.Identity().ID
|
||||
serverID := tp.ServerNode.GetIdentity().ID
|
||||
|
||||
lines, err := controller.RemoteLogs(serverID, "running-miner", 10)
|
||||
lines, err := controller.GetRemoteLogs(serverID, "running-miner", 10)
|
||||
require.NoError(t, err, "RemoteLogs should succeed")
|
||||
require.NotNil(t, lines)
|
||||
assert.Len(t, lines, 3, "should return all 3 console history lines")
|
||||
|
|
@ -612,9 +612,9 @@ func TestController_RemoteLogs_Good(t *testing.T) {
|
|||
|
||||
func TestController_RemoteLogs_LimitedLines_Good(t *testing.T) {
|
||||
controller, _, tp := setupControllerPairWithMiner(t)
|
||||
serverID := tp.ServerNode.Identity().ID
|
||||
serverID := tp.ServerNode.GetIdentity().ID
|
||||
|
||||
lines, err := controller.RemoteLogs(serverID, "running-miner", 1)
|
||||
lines, err := controller.GetRemoteLogs(serverID, "running-miner", 1)
|
||||
require.NoError(t, err, "RemoteLogs with limited lines should succeed")
|
||||
assert.Len(t, lines, 1, "should return only 1 line")
|
||||
}
|
||||
|
|
@ -627,16 +627,16 @@ func TestController_RemoteLogs_NoIdentity_Bad(t *testing.T) {
|
|||
|
||||
controller := NewController(nmNoID, tp.ClientReg, tp.Client)
|
||||
|
||||
_, err = controller.RemoteLogs("some-peer", "any-miner", 10)
|
||||
_, err = controller.GetRemoteLogs("some-peer", "any-miner", 10)
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "identity not initialized")
|
||||
}
|
||||
|
||||
func TestController_RemoteStats_WithMiners_Good(t *testing.T) {
|
||||
controller, _, tp := setupControllerPairWithMiner(t)
|
||||
serverID := tp.ServerNode.Identity().ID
|
||||
serverID := tp.ServerNode.GetIdentity().ID
|
||||
|
||||
stats, err := controller.RemoteStats(serverID)
|
||||
stats, err := controller.GetRemoteStats(serverID)
|
||||
require.NoError(t, err, "RemoteStats should succeed")
|
||||
require.NotNil(t, stats)
|
||||
assert.NotEmpty(t, stats.NodeID)
|
||||
|
|
@ -654,7 +654,7 @@ func TestController_RemoteStats_NoIdentity_Bad(t *testing.T) {
|
|||
|
||||
controller := NewController(nmNoID, tp.ClientReg, tp.Client)
|
||||
|
||||
_, err = controller.RemoteStats("some-peer")
|
||||
_, err = controller.GetRemoteStats("some-peer")
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "identity not initialized")
|
||||
}
|
||||
|
|
@ -668,7 +668,7 @@ func TestController_ConnectToPeer_Success_Good(t *testing.T) {
|
|||
controller := NewController(tp.ClientNode, tp.ClientReg, tp.Client)
|
||||
|
||||
// Add the server peer to the client registry.
|
||||
serverIdentity := tp.ServerNode.Identity()
|
||||
serverIdentity := tp.ServerNode.GetIdentity()
|
||||
peer := &Peer{
|
||||
ID: serverIdentity.ID,
|
||||
Name: "server",
|
||||
|
|
|
|||
|
|
@ -147,11 +147,6 @@ func (n *NodeManager) GetIdentity() *NodeIdentity {
|
|||
return &identity
|
||||
}
|
||||
|
||||
// Identity is a deprecated compatibility alias for GetIdentity.
|
||||
func (n *NodeManager) Identity() *NodeIdentity {
|
||||
return n.GetIdentity()
|
||||
}
|
||||
|
||||
// GenerateIdentity writes a new node identity for the given name and role.
|
||||
//
|
||||
// err := nodeManager.GenerateIdentity("worker-1", RoleWorker)
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ func TestIdentity_NodeIdentity_Good(t *testing.T) {
|
|||
t.Error("node manager should have identity after generation")
|
||||
}
|
||||
|
||||
identity := nm.Identity()
|
||||
identity := nm.GetIdentity()
|
||||
if identity == nil {
|
||||
t.Fatal("identity should not be nil")
|
||||
}
|
||||
|
|
@ -72,8 +72,8 @@ func TestIdentity_NodeIdentity_Good(t *testing.T) {
|
|||
t.Fatalf("failed to generate identity: %v", err)
|
||||
}
|
||||
|
||||
originalID := nm1.Identity().ID
|
||||
originalPubKey := nm1.Identity().PublicKey
|
||||
originalID := nm1.GetIdentity().ID
|
||||
originalPubKey := nm1.GetIdentity().PublicKey
|
||||
|
||||
// Create a new manager - should load existing identity
|
||||
nm2, err := NewNodeManagerFromPaths(keyPath, configPath)
|
||||
|
|
@ -85,7 +85,7 @@ func TestIdentity_NodeIdentity_Good(t *testing.T) {
|
|||
t.Error("second node manager should have loaded existing identity")
|
||||
}
|
||||
|
||||
identity := nm2.Identity()
|
||||
identity := nm2.GetIdentity()
|
||||
if identity.ID != originalID {
|
||||
t.Errorf("expected ID '%s', got '%s'", originalID, identity.ID)
|
||||
}
|
||||
|
|
@ -121,12 +121,12 @@ func TestIdentity_NodeIdentity_Good(t *testing.T) {
|
|||
}
|
||||
|
||||
// Derive shared secrets - should be identical
|
||||
secret1, err := nm1.DeriveSharedSecret(nm2.Identity().PublicKey)
|
||||
secret1, err := nm1.DeriveSharedSecret(nm2.GetIdentity().PublicKey)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to derive shared secret from node 1: %v", err)
|
||||
}
|
||||
|
||||
secret2, err := nm2.DeriveSharedSecret(nm1.Identity().PublicKey)
|
||||
secret2, err := nm2.DeriveSharedSecret(nm1.GetIdentity().PublicKey)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to derive shared secret from node 2: %v", err)
|
||||
}
|
||||
|
|
@ -315,8 +315,8 @@ func TestIdentity_ChallengeResponse_Good(t *testing.T) {
|
|||
}
|
||||
|
||||
// Both derive the same shared secret
|
||||
secret1, _ := nm1.DeriveSharedSecret(nm2.Identity().PublicKey)
|
||||
secret2, _ := nm2.DeriveSharedSecret(nm1.Identity().PublicKey)
|
||||
secret1, _ := nm1.DeriveSharedSecret(nm2.GetIdentity().PublicKey)
|
||||
secret2, _ := nm2.DeriveSharedSecret(nm1.GetIdentity().PublicKey)
|
||||
|
||||
// Responder signs challenge with their derived secret
|
||||
response := SignChallenge(challenge, secret2)
|
||||
|
|
@ -341,7 +341,7 @@ func TestIdentity_NodeManager_DeriveSharedSecret_NoIdentity_Bad(t *testing.T) {
|
|||
func TestIdentity_NodeManager_Identity_NilWhenNoIdentity_Bad(t *testing.T) {
|
||||
nm := newTestNodeManagerWithoutIdentity(t)
|
||||
|
||||
identity := nm.Identity()
|
||||
identity := nm.GetIdentity()
|
||||
if identity != nil {
|
||||
t.Error("expected nil identity before generation")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@ func TestIntegration_FullNodeLifecycle_Good(t *testing.T) {
|
|||
controllerNM := newTestNodeManager(t, "integration-controller", RoleController)
|
||||
workerNM := newTestNodeManager(t, "integration-worker", RoleWorker)
|
||||
|
||||
controllerIdentity := controllerNM.Identity()
|
||||
workerIdentity := workerNM.Identity()
|
||||
controllerIdentity := controllerNM.GetIdentity()
|
||||
workerIdentity := workerNM.GetIdentity()
|
||||
require.NotNil(t, controllerIdentity, "controller identity should be initialised")
|
||||
require.NotNil(t, workerIdentity, "worker identity should be initialised")
|
||||
assert.NotEmpty(t, controllerIdentity.ID, "controller ID should be non-empty")
|
||||
|
|
@ -122,8 +122,8 @@ func TestIntegration_FullNodeLifecycle_Good(t *testing.T) {
|
|||
"worker should have 1 connected peer")
|
||||
|
||||
// Verify the peer's real identity is stored.
|
||||
serverPeerID := workerNM.Identity().ID
|
||||
conn := controllerTransport.Connection(serverPeerID)
|
||||
serverPeerID := workerNM.GetIdentity().ID
|
||||
conn := controllerTransport.GetConnection(serverPeerID)
|
||||
require.NotNil(t, conn, "controller should hold a connection keyed by server's real ID")
|
||||
assert.Equal(t, "integration-worker", conn.Peer.Name)
|
||||
|
||||
|
|
@ -136,14 +136,14 @@ func TestIntegration_FullNodeLifecycle_Good(t *testing.T) {
|
|||
assert.Less(t, rtt, 1000.0, "RTT on loopback should be well under 1s")
|
||||
|
||||
// Verify registry metrics were updated.
|
||||
peerAfterPing := controllerReg.Peer(serverPeerID)
|
||||
peerAfterPing := controllerReg.GetPeer(serverPeerID)
|
||||
require.NotNil(t, peerAfterPing)
|
||||
assert.Greater(t, peerAfterPing.PingMS, 0.0, "PingMS should be updated")
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// Step 5: Encrypted message exchange — RemoteStats
|
||||
// ----------------------------------------------------------------
|
||||
stats, err := controller.RemoteStats(serverPeerID)
|
||||
stats, err := controller.GetRemoteStats(serverPeerID)
|
||||
require.NoError(t, err, "RemoteStats should succeed")
|
||||
require.NotNil(t, stats)
|
||||
assert.Equal(t, workerIdentity.ID, stats.NodeID)
|
||||
|
|
@ -242,8 +242,8 @@ func TestIntegration_SharedSecretAgreement_Good(t *testing.T) {
|
|||
nodeA := newTestNodeManager(t, "secret-node-a", RoleDual)
|
||||
nodeB := newTestNodeManager(t, "secret-node-b", RoleDual)
|
||||
|
||||
pubKeyA := nodeA.Identity().PublicKey
|
||||
pubKeyB := nodeB.Identity().PublicKey
|
||||
pubKeyA := nodeA.GetIdentity().PublicKey
|
||||
pubKeyB := nodeB.GetIdentity().PublicKey
|
||||
|
||||
secretFromA, err := nodeA.DeriveSharedSecret(pubKeyB)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -260,7 +260,7 @@ func TestIntegration_SharedSecretAgreement_Good(t *testing.T) {
|
|||
// can send and receive encrypted messages after the handshake.
|
||||
func TestIntegration_TwoNodeBidirectionalMessages_Good(t *testing.T) {
|
||||
controller, _, tp := setupControllerPair(t)
|
||||
serverID := tp.ServerNode.Identity().ID
|
||||
serverID := tp.ServerNode.GetIdentity().ID
|
||||
|
||||
// Controller -> Worker: Ping
|
||||
rtt, err := controller.PingPeer(serverID)
|
||||
|
|
@ -268,7 +268,7 @@ func TestIntegration_TwoNodeBidirectionalMessages_Good(t *testing.T) {
|
|||
assert.Greater(t, rtt, 0.0)
|
||||
|
||||
// Controller -> Worker: GetStats
|
||||
stats, err := controller.RemoteStats(serverID)
|
||||
stats, err := controller.GetRemoteStats(serverID)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, stats)
|
||||
assert.NotEmpty(t, stats.NodeID)
|
||||
|
|
@ -294,7 +294,7 @@ func TestIntegration_MultiPeerTopology_Good(t *testing.T) {
|
|||
|
||||
for i := range numWorkers {
|
||||
nm, addr, _ := makeWorkerServer(t)
|
||||
wID := nm.Identity().ID
|
||||
wID := nm.GetIdentity().ID
|
||||
workerIDs[i] = wID
|
||||
|
||||
peer := &Peer{
|
||||
|
|
@ -335,7 +335,7 @@ func TestIntegration_MultiPeerTopology_Good(t *testing.T) {
|
|||
}
|
||||
|
||||
// Fetch stats from all workers in parallel.
|
||||
allStats := controller.AllStats()
|
||||
allStats := controller.GetAllStats()
|
||||
assert.Len(t, allStats, numWorkers, "should get stats from all workers")
|
||||
}
|
||||
|
||||
|
|
@ -350,7 +350,7 @@ func TestIntegration_IdentityPersistenceAndReload_Good(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.NoError(t, nm1.GenerateIdentity("persistent-node", RoleDual))
|
||||
|
||||
original := nm1.Identity()
|
||||
original := nm1.GetIdentity()
|
||||
require.NotNil(t, original)
|
||||
|
||||
// Reload from disk.
|
||||
|
|
@ -358,7 +358,7 @@ func TestIntegration_IdentityPersistenceAndReload_Good(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.True(t, nm2.HasIdentity(), "identity should be loaded from disk")
|
||||
|
||||
reloaded := nm2.Identity()
|
||||
reloaded := nm2.GetIdentity()
|
||||
require.NotNil(t, reloaded)
|
||||
|
||||
assert.Equal(t, original.ID, reloaded.ID, "ID should persist")
|
||||
|
|
@ -390,7 +390,7 @@ func stmfGenerateKeyPair(dir string) (string, error) {
|
|||
if err := nm.GenerateIdentity("temp-peer", RoleWorker); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return nm.Identity().PublicKey, nil
|
||||
return nm.GetIdentity().PublicKey, nil
|
||||
}
|
||||
|
||||
// TestIntegration_UEPSFullRoundTrip exercises a complete UEPS packet
|
||||
|
|
@ -399,7 +399,7 @@ func TestIntegration_UEPSFullRoundTrip_Ugly(t *testing.T) {
|
|||
nodeA := newTestNodeManager(t, "ueps-node-a", RoleController)
|
||||
nodeB := newTestNodeManager(t, "ueps-node-b", RoleWorker)
|
||||
|
||||
bPubKey := nodeB.Identity().PublicKey
|
||||
bPubKey := nodeB.GetIdentity().PublicKey
|
||||
sharedSecret, err := nodeA.DeriveSharedSecret(bPubKey)
|
||||
require.NoError(t, err, "shared secret derivation should succeed")
|
||||
require.Len(t, sharedSecret, 32, "shared secret should be 32 bytes (SHA-256)")
|
||||
|
|
@ -414,7 +414,7 @@ func TestIntegration_UEPSFullRoundTrip_Ugly(t *testing.T) {
|
|||
require.NotEmpty(t, wireData)
|
||||
|
||||
// Node B derives the same shared secret from A's public key.
|
||||
aPubKey := nodeA.Identity().PublicKey
|
||||
aPubKey := nodeA.GetIdentity().PublicKey
|
||||
sharedSecretB, err := nodeB.DeriveSharedSecret(aPubKey)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, sharedSecret, sharedSecretB,
|
||||
|
|
@ -450,7 +450,7 @@ func TestIntegration_UEPSIntegrityFailure_Bad(t *testing.T) {
|
|||
nodeA := newTestNodeManager(t, "integrity-a", RoleController)
|
||||
nodeB := newTestNodeManager(t, "integrity-b", RoleWorker)
|
||||
|
||||
bPubKey := nodeB.Identity().PublicKey
|
||||
bPubKey := nodeB.GetIdentity().PublicKey
|
||||
sharedSecret, err := nodeA.DeriveSharedSecret(bPubKey)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
@ -463,7 +463,7 @@ func TestIntegration_UEPSIntegrityFailure_Bad(t *testing.T) {
|
|||
copy(tampered, wireData)
|
||||
tampered[len(tampered)-1] ^= 0xFF
|
||||
|
||||
aPubKey := nodeA.Identity().PublicKey
|
||||
aPubKey := nodeA.GetIdentity().PublicKey
|
||||
sharedSecretB, err := nodeB.DeriveSharedSecret(aPubKey)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
@ -500,7 +500,7 @@ func TestIntegration_AllowlistHandshakeRejection_Bad(t *testing.T) {
|
|||
t.Cleanup(func() { controllerTransport.Stop() })
|
||||
|
||||
peer := &Peer{
|
||||
ID: workerNM.Identity().ID,
|
||||
ID: workerNM.GetIdentity().ID,
|
||||
Name: "worker",
|
||||
Address: u.Host,
|
||||
Role: RoleWorker,
|
||||
|
|
@ -522,7 +522,7 @@ func TestIntegration_AllowlistHandshakeAccepted_Good(t *testing.T) {
|
|||
controllerNM := newTestNodeManager(t, "allowed-controller", RoleController)
|
||||
controllerReg := newTestPeerRegistry(t)
|
||||
|
||||
workerReg.AllowPublicKey(controllerNM.Identity().PublicKey)
|
||||
workerReg.AllowPublicKey(controllerNM.GetIdentity().PublicKey)
|
||||
|
||||
workerTransport := NewTransport(workerNM, workerReg, DefaultTransportConfig())
|
||||
worker := NewWorker(workerNM, workerTransport)
|
||||
|
|
@ -542,7 +542,7 @@ func TestIntegration_AllowlistHandshakeAccepted_Good(t *testing.T) {
|
|||
t.Cleanup(func() { controllerTransport.Stop() })
|
||||
|
||||
peer := &Peer{
|
||||
ID: workerNM.Identity().ID,
|
||||
ID: workerNM.GetIdentity().ID,
|
||||
Name: "worker",
|
||||
Address: u.Host,
|
||||
Role: RoleWorker,
|
||||
|
|
@ -611,7 +611,7 @@ func TestIntegration_MessageSerialiseDeserialise_Good(t *testing.T) {
|
|||
tp := setupTestTransportPair(t)
|
||||
pc := tp.connectClient(t)
|
||||
|
||||
original, err := NewMessage(MessageStats, tp.ClientNode.Identity().ID, tp.ServerNode.Identity().ID, StatsPayload{
|
||||
original, err := NewMessage(MessageStats, tp.ClientNode.GetIdentity().ID, tp.ServerNode.GetIdentity().ID, StatsPayload{
|
||||
NodeID: "test-node",
|
||||
NodeName: "test-name",
|
||||
Miners: []MinerStatsItem{
|
||||
|
|
@ -664,9 +664,9 @@ func TestIntegration_RemoteStats_EndToEnd_Good(t *testing.T) {
|
|||
tp.connectClient(t)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
serverID := tp.ServerNode.Identity().ID
|
||||
serverID := tp.ServerNode.GetIdentity().ID
|
||||
|
||||
stats, err := controller.RemoteStats(serverID)
|
||||
stats, err := controller.GetRemoteStats(serverID)
|
||||
require.NoError(t, err, "RemoteStats should succeed end-to-end")
|
||||
require.NotNil(t, stats)
|
||||
assert.Equal(t, serverID, stats.NodeID)
|
||||
|
|
|
|||
25
node/peer.go
25
node/peer.go
|
|
@ -179,11 +179,6 @@ func (r *PeerRegistry) GetAuthMode() PeerAuthMode {
|
|||
return r.authMode
|
||||
}
|
||||
|
||||
// AuthMode is a deprecated compatibility alias for GetAuthMode.
|
||||
func (r *PeerRegistry) AuthMode() PeerAuthMode {
|
||||
return r.GetAuthMode()
|
||||
}
|
||||
|
||||
// AllowPublicKey adds a public key to the allowlist.
|
||||
func (r *PeerRegistry) AllowPublicKey(publicKey string) {
|
||||
r.allowedPublicKeyMu.Lock()
|
||||
|
|
@ -345,11 +340,6 @@ func (r *PeerRegistry) GetPeer(id string) *Peer {
|
|||
return &peerCopy
|
||||
}
|
||||
|
||||
// Peer is a deprecated compatibility alias for GetPeer.
|
||||
func (r *PeerRegistry) Peer(id string) *Peer {
|
||||
return r.GetPeer(id)
|
||||
}
|
||||
|
||||
// ListPeers returns all registered peers.
|
||||
func (r *PeerRegistry) ListPeers() []*Peer {
|
||||
return slices.Collect(r.Peers())
|
||||
|
|
@ -431,11 +421,6 @@ func (r *PeerRegistry) SetConnected(id string, connected bool) {
|
|||
}
|
||||
}
|
||||
|
||||
// MarkConnected is a deprecated compatibility alias for SetConnected.
|
||||
func (r *PeerRegistry) MarkConnected(id string, connected bool) {
|
||||
r.SetConnected(id, connected)
|
||||
}
|
||||
|
||||
// Score adjustment constants
|
||||
const (
|
||||
ScoreSuccessIncrement = 1.0 // Increment for successful interaction
|
||||
|
|
@ -526,11 +511,6 @@ func (r *PeerRegistry) GetPeersByScore() []*Peer {
|
|||
return peers
|
||||
}
|
||||
|
||||
// PeersSortedByScore is a deprecated compatibility alias for GetPeersByScore.
|
||||
func (r *PeerRegistry) PeersSortedByScore() []*Peer {
|
||||
return r.GetPeersByScore()
|
||||
}
|
||||
|
||||
// PeersByScore returns an iterator over peers sorted by score (highest first).
|
||||
func (r *PeerRegistry) PeersByScore() iter.Seq[*Peer] {
|
||||
return func(yield func(*Peer) bool) {
|
||||
|
|
@ -603,11 +583,6 @@ func (r *PeerRegistry) GetConnectedPeers() []*Peer {
|
|||
return slices.Collect(r.ConnectedPeers())
|
||||
}
|
||||
|
||||
// ConnectedPeerList is a deprecated compatibility alias for GetConnectedPeers.
|
||||
func (r *PeerRegistry) ConnectedPeerList() []*Peer {
|
||||
return r.GetConnectedPeers()
|
||||
}
|
||||
|
||||
// ConnectedPeers returns an iterator over all currently connected peers.
|
||||
// Each peer is a copy to prevent mutation.
|
||||
func (r *PeerRegistry) ConnectedPeers() iter.Seq[*Peer] {
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ func TestPeer_Registry_Peer_Good(t *testing.T) {
|
|||
|
||||
pr.AddPeer(peer)
|
||||
|
||||
retrieved := pr.Peer("get-test-peer")
|
||||
retrieved := pr.GetPeer("get-test-peer")
|
||||
if retrieved == nil {
|
||||
t.Fatal("failed to retrieve peer")
|
||||
}
|
||||
|
|
@ -96,7 +96,7 @@ func TestPeer_Registry_Peer_Good(t *testing.T) {
|
|||
}
|
||||
|
||||
// Non-existent peer
|
||||
nonExistent := pr.Peer("non-existent")
|
||||
nonExistent := pr.GetPeer("non-existent")
|
||||
if nonExistent != nil {
|
||||
t.Error("expected nil for non-existent peer")
|
||||
}
|
||||
|
|
@ -173,7 +173,7 @@ func TestPeer_Registry_UpdateMetrics_Good(t *testing.T) {
|
|||
t.Fatalf("failed to update metrics: %v", err)
|
||||
}
|
||||
|
||||
updated := pr.Peer("metrics-test")
|
||||
updated := pr.GetPeer("metrics-test")
|
||||
if updated == nil {
|
||||
t.Fatal("expected peer to exist")
|
||||
}
|
||||
|
|
@ -205,7 +205,7 @@ func TestPeer_Registry_UpdateScore_Good(t *testing.T) {
|
|||
t.Fatalf("failed to update score: %v", err)
|
||||
}
|
||||
|
||||
updated := pr.Peer("score-test")
|
||||
updated := pr.GetPeer("score-test")
|
||||
if updated == nil {
|
||||
t.Fatal("expected peer to exist")
|
||||
}
|
||||
|
|
@ -219,7 +219,7 @@ func TestPeer_Registry_UpdateScore_Good(t *testing.T) {
|
|||
t.Fatalf("failed to update score: %v", err)
|
||||
}
|
||||
|
||||
updated = pr.Peer("score-test")
|
||||
updated = pr.GetPeer("score-test")
|
||||
if updated == nil {
|
||||
t.Fatal("expected peer to exist")
|
||||
}
|
||||
|
|
@ -233,7 +233,7 @@ func TestPeer_Registry_UpdateScore_Good(t *testing.T) {
|
|||
t.Fatalf("failed to update score: %v", err)
|
||||
}
|
||||
|
||||
updated = pr.Peer("score-test")
|
||||
updated = pr.GetPeer("score-test")
|
||||
if updated == nil {
|
||||
t.Fatal("expected peer to exist")
|
||||
}
|
||||
|
|
@ -254,9 +254,9 @@ func TestPeer_Registry_MarkConnected_Good(t *testing.T) {
|
|||
|
||||
pr.AddPeer(peer)
|
||||
|
||||
pr.MarkConnected("connect-test", true)
|
||||
pr.SetConnected("connect-test", true)
|
||||
|
||||
updated := pr.Peer("connect-test")
|
||||
updated := pr.GetPeer("connect-test")
|
||||
if updated == nil {
|
||||
t.Fatal("expected peer to exist")
|
||||
}
|
||||
|
|
@ -267,8 +267,8 @@ func TestPeer_Registry_MarkConnected_Good(t *testing.T) {
|
|||
t.Error("LastSeen should be set when connected")
|
||||
}
|
||||
|
||||
pr.MarkConnected("connect-test", false)
|
||||
updated = pr.Peer("connect-test")
|
||||
pr.SetConnected("connect-test", false)
|
||||
updated = pr.GetPeer("connect-test")
|
||||
if updated == nil {
|
||||
t.Fatal("expected peer to exist")
|
||||
}
|
||||
|
|
@ -291,10 +291,10 @@ func TestPeer_Registry_ConnectedPeerList_Good(t *testing.T) {
|
|||
pr.AddPeer(p)
|
||||
}
|
||||
|
||||
pr.MarkConnected("conn-1", true)
|
||||
pr.MarkConnected("conn-3", true)
|
||||
pr.SetConnected("conn-1", true)
|
||||
pr.SetConnected("conn-3", true)
|
||||
|
||||
connected := pr.ConnectedPeerList()
|
||||
connected := pr.GetConnectedPeers()
|
||||
if len(connected) != 2 {
|
||||
t.Errorf("expected 2 connected peers, got %d", len(connected))
|
||||
}
|
||||
|
|
@ -382,7 +382,7 @@ func TestPeer_Registry_Persistence_Good(t *testing.T) {
|
|||
t.Errorf("expected 1 peer after reload, got %d", pr2.Count())
|
||||
}
|
||||
|
||||
loaded := pr2.Peer("persist-test")
|
||||
loaded := pr2.GetPeer("persist-test")
|
||||
if loaded == nil {
|
||||
t.Fatal("peer should exist after reload")
|
||||
}
|
||||
|
|
@ -399,20 +399,20 @@ func TestPeer_Registry_AuthMode_Good(t *testing.T) {
|
|||
defer cleanup()
|
||||
|
||||
// Default should be Open
|
||||
if pr.AuthMode() != PeerAuthOpen {
|
||||
t.Errorf("expected default auth mode to be Open, got %d", pr.AuthMode())
|
||||
if pr.GetAuthMode() != PeerAuthOpen {
|
||||
t.Errorf("expected default auth mode to be Open, got %d", pr.GetAuthMode())
|
||||
}
|
||||
|
||||
// Set to Allowlist
|
||||
pr.SetAuthMode(PeerAuthAllowlist)
|
||||
if pr.AuthMode() != PeerAuthAllowlist {
|
||||
t.Errorf("expected auth mode to be Allowlist after setting, got %d", pr.AuthMode())
|
||||
if pr.GetAuthMode() != PeerAuthAllowlist {
|
||||
t.Errorf("expected auth mode to be Allowlist after setting, got %d", pr.GetAuthMode())
|
||||
}
|
||||
|
||||
// Set back to Open
|
||||
pr.SetAuthMode(PeerAuthOpen)
|
||||
if pr.AuthMode() != PeerAuthOpen {
|
||||
t.Errorf("expected auth mode to be Open after resetting, got %d", pr.AuthMode())
|
||||
if pr.GetAuthMode() != PeerAuthOpen {
|
||||
t.Errorf("expected auth mode to be Open after resetting, got %d", pr.GetAuthMode())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -563,7 +563,7 @@ func TestPeer_Registry_ScoreRecording_Good(t *testing.T) {
|
|||
for range 5 {
|
||||
pr.RecordSuccess("score-record-test")
|
||||
}
|
||||
updated := pr.Peer("score-record-test")
|
||||
updated := pr.GetPeer("score-record-test")
|
||||
if updated.Score <= 50 {
|
||||
t.Errorf("score should increase after successes, got %f", updated.Score)
|
||||
}
|
||||
|
|
@ -573,7 +573,7 @@ func TestPeer_Registry_ScoreRecording_Good(t *testing.T) {
|
|||
for range 3 {
|
||||
pr.RecordFailure("score-record-test")
|
||||
}
|
||||
updated = pr.Peer("score-record-test")
|
||||
updated = pr.GetPeer("score-record-test")
|
||||
if updated.Score >= initialScore {
|
||||
t.Errorf("score should decrease after failures, got %f (was %f)", updated.Score, initialScore)
|
||||
}
|
||||
|
|
@ -581,7 +581,7 @@ func TestPeer_Registry_ScoreRecording_Good(t *testing.T) {
|
|||
// Record timeouts - score should decrease
|
||||
initialScore = updated.Score
|
||||
pr.RecordTimeout("score-record-test")
|
||||
updated = pr.Peer("score-record-test")
|
||||
updated = pr.GetPeer("score-record-test")
|
||||
if updated.Score >= initialScore {
|
||||
t.Errorf("score should decrease after timeout, got %f (was %f)", updated.Score, initialScore)
|
||||
}
|
||||
|
|
@ -590,7 +590,7 @@ func TestPeer_Registry_ScoreRecording_Good(t *testing.T) {
|
|||
for range 100 {
|
||||
pr.RecordSuccess("score-record-test")
|
||||
}
|
||||
updated = pr.Peer("score-record-test")
|
||||
updated = pr.GetPeer("score-record-test")
|
||||
if updated.Score > ScoreMaximum {
|
||||
t.Errorf("score should be clamped to max %f, got %f", ScoreMaximum, updated.Score)
|
||||
}
|
||||
|
|
@ -598,7 +598,7 @@ func TestPeer_Registry_ScoreRecording_Good(t *testing.T) {
|
|||
for range 100 {
|
||||
pr.RecordFailure("score-record-test")
|
||||
}
|
||||
updated = pr.Peer("score-record-test")
|
||||
updated = pr.GetPeer("score-record-test")
|
||||
if updated.Score < ScoreMinimum {
|
||||
t.Errorf("score should be clamped to min %f, got %f", ScoreMinimum, updated.Score)
|
||||
}
|
||||
|
|
@ -619,7 +619,7 @@ func TestPeer_Registry_PeersSortedByScore_Good(t *testing.T) {
|
|||
pr.AddPeer(p)
|
||||
}
|
||||
|
||||
sorted := pr.PeersSortedByScore()
|
||||
sorted := pr.GetPeersByScore()
|
||||
if len(sorted) != 3 {
|
||||
t.Fatalf("expected 3 peers, got %d", len(sorted))
|
||||
}
|
||||
|
|
@ -726,7 +726,7 @@ func TestPeer_Registry_UpdatePeer_Good(t *testing.T) {
|
|||
t.Fatalf("failed to update peer: %v", err)
|
||||
}
|
||||
|
||||
updated := pr.Peer("update-test")
|
||||
updated := pr.GetPeer("update-test")
|
||||
if updated == nil {
|
||||
t.Fatal("expected peer to exist after update")
|
||||
}
|
||||
|
|
@ -805,7 +805,7 @@ func TestPeer_Registry_MarkConnected_NonExistent_Bad(t *testing.T) {
|
|||
defer cleanup()
|
||||
|
||||
// Should not panic for non-existent peer
|
||||
pr.MarkConnected("ghost-peer", true)
|
||||
pr.SetConnected("ghost-peer", true)
|
||||
}
|
||||
|
||||
func TestPeer_Registry_Close_NoDirtyData_Ugly(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -97,8 +97,3 @@ func GetProtocolErrorCode(err error) int {
|
|||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// ProtocolErrorCode is a deprecated compatibility alias for GetProtocolErrorCode.
|
||||
func ProtocolErrorCode(err error) int {
|
||||
return GetProtocolErrorCode(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ func TestProtocol_ResponseHandler_ValidateResponse_Good(t *testing.T) {
|
|||
t.Errorf("Expected ProtocolError, got %T", err)
|
||||
}
|
||||
|
||||
if ProtocolErrorCode(err) != ErrorCodeOperationFailed {
|
||||
t.Errorf("Expected code %d, got %d", ErrorCodeOperationFailed, ProtocolErrorCode(err))
|
||||
if GetProtocolErrorCode(err) != ErrorCodeOperationFailed {
|
||||
t.Errorf("Expected code %d, got %d", ErrorCodeOperationFailed, GetProtocolErrorCode(err))
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -131,8 +131,8 @@ func TestProtocol_Error_Bad(t *testing.T) {
|
|||
t.Error("IsProtocolError should return true")
|
||||
}
|
||||
|
||||
if ProtocolErrorCode(err) != 1001 {
|
||||
t.Errorf("Expected code 1001, got %d", ProtocolErrorCode(err))
|
||||
if GetProtocolErrorCode(err) != 1001 {
|
||||
t.Errorf("Expected code 1001, got %d", GetProtocolErrorCode(err))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -156,7 +156,7 @@ func TestProtocol_ConvenienceFunctions_Good(t *testing.T) {
|
|||
|
||||
func TestProtocol_ProtocolErrorCode_NonProtocolError_Bad(t *testing.T) {
|
||||
err := core.NewError("regular error")
|
||||
if ProtocolErrorCode(err) != 0 {
|
||||
if GetProtocolErrorCode(err) != 0 {
|
||||
t.Error("Expected 0 for non-ProtocolError")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -533,11 +533,6 @@ func (t *Transport) GetConnection(peerID string) *PeerConnection {
|
|||
return t.connections[peerID]
|
||||
}
|
||||
|
||||
// Connection is a deprecated compatibility alias for GetConnection.
|
||||
func (t *Transport) Connection(peerID string) *PeerConnection {
|
||||
return t.GetConnection(peerID)
|
||||
}
|
||||
|
||||
// handleWSUpgrade handles incoming WebSocket connections.
|
||||
func (t *Transport) handleWSUpgrade(w http.ResponseWriter, r *http.Request) {
|
||||
userAgent := r.Header.Get("User-Agent")
|
||||
|
|
@ -1085,8 +1080,3 @@ func (t *Transport) ConnectedPeerCount() int {
|
|||
defer t.mutex.RUnlock()
|
||||
return len(t.connections)
|
||||
}
|
||||
|
||||
// ConnectedPeers is a deprecated compatibility alias for ConnectedPeerCount.
|
||||
func (t *Transport) ConnectedPeers() int {
|
||||
return t.ConnectedPeerCount()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ func (tp *testTransportPair) connectClient(t *testing.T) *PeerConnection {
|
|||
t.Helper()
|
||||
|
||||
peer := &Peer{
|
||||
ID: tp.ServerNode.Identity().ID,
|
||||
ID: tp.ServerNode.GetIdentity().ID,
|
||||
Name: "server",
|
||||
Address: tp.ServerAddr,
|
||||
Role: RoleWorker,
|
||||
|
|
@ -227,8 +227,8 @@ func TestTransport_FullHandshake_Good(t *testing.T) {
|
|||
}
|
||||
|
||||
// Verify peer identity was exchanged correctly
|
||||
serverID := tp.ServerNode.Identity().ID
|
||||
serverConn := tp.Client.Connection(serverID)
|
||||
serverID := tp.ServerNode.GetIdentity().ID
|
||||
serverConn := tp.Client.GetConnection(serverID)
|
||||
if serverConn == nil {
|
||||
t.Fatal("client should have connection to server by server ID")
|
||||
}
|
||||
|
|
@ -267,7 +267,7 @@ func TestTransport_ConnectSendsAgentUserAgent_Good(t *testing.T) {
|
|||
serverAddr := u.Host
|
||||
|
||||
peer := &Peer{
|
||||
ID: serverNM.Identity().ID,
|
||||
ID: serverNM.GetIdentity().ID,
|
||||
Name: "server",
|
||||
Address: serverAddr,
|
||||
Role: RoleWorker,
|
||||
|
|
@ -286,14 +286,14 @@ func TestTransport_ConnectSendsAgentUserAgent_Good(t *testing.T) {
|
|||
if !strings.HasPrefix(ua, agentUserAgentPrefix) {
|
||||
t.Fatalf("user-agent prefix: got %q, want prefix %q", ua, agentUserAgentPrefix)
|
||||
}
|
||||
if !strings.Contains(ua, "id="+clientNM.Identity().ID) {
|
||||
if !strings.Contains(ua, "id="+clientNM.GetIdentity().ID) {
|
||||
t.Fatalf("user-agent should include client identity, got %q", ua)
|
||||
}
|
||||
if pc.UserAgent != ua {
|
||||
t.Fatalf("client connection user-agent: got %q, want %q", pc.UserAgent, ua)
|
||||
}
|
||||
|
||||
serverConn := serverTransport.Connection(clientNM.Identity().ID)
|
||||
serverConn := serverTransport.GetConnection(clientNM.GetIdentity().ID)
|
||||
if serverConn == nil {
|
||||
t.Fatal("server should retain the accepted connection")
|
||||
}
|
||||
|
|
@ -313,7 +313,7 @@ func TestTransport_HandshakeRejectWrongVersion_Bad(t *testing.T) {
|
|||
}
|
||||
defer conn.Close()
|
||||
|
||||
clientIdentity := tp.ClientNode.Identity()
|
||||
clientIdentity := tp.ClientNode.GetIdentity()
|
||||
payload := HandshakePayload{
|
||||
Identity: *clientIdentity,
|
||||
Version: "99.99", // Unsupported
|
||||
|
|
@ -351,7 +351,7 @@ func TestTransport_HandshakeRejectAllowlist_Bad(t *testing.T) {
|
|||
tp.ServerReg.SetAuthMode(PeerAuthAllowlist)
|
||||
|
||||
peer := &Peer{
|
||||
ID: tp.ServerNode.Identity().ID,
|
||||
ID: tp.ServerNode.GetIdentity().ID,
|
||||
Name: "server",
|
||||
Address: tp.ServerAddr,
|
||||
Role: RoleWorker,
|
||||
|
|
@ -378,8 +378,8 @@ func TestTransport_EncryptedMessageRoundTrip_Ugly(t *testing.T) {
|
|||
pc := tp.connectClient(t)
|
||||
|
||||
// Send an encrypted message from client to server
|
||||
clientID := tp.ClientNode.Identity().ID
|
||||
serverID := tp.ServerNode.Identity().ID
|
||||
clientID := tp.ClientNode.GetIdentity().ID
|
||||
serverID := tp.ServerNode.GetIdentity().ID
|
||||
sentMsg, _ := NewMessage(MessagePing, clientID, serverID, PingPayload{
|
||||
SentAt: time.Now().UnixMilli(),
|
||||
})
|
||||
|
|
@ -420,8 +420,8 @@ func TestTransport_MessageDedup_Good(t *testing.T) {
|
|||
|
||||
pc := tp.connectClient(t)
|
||||
|
||||
clientID := tp.ClientNode.Identity().ID
|
||||
serverID := tp.ServerNode.Identity().ID
|
||||
clientID := tp.ClientNode.GetIdentity().ID
|
||||
serverID := tp.ServerNode.GetIdentity().ID
|
||||
msg, _ := NewMessage(MessagePing, clientID, serverID, PingPayload{SentAt: time.Now().UnixMilli()})
|
||||
|
||||
// Send the same message twice
|
||||
|
|
@ -450,8 +450,8 @@ func TestTransport_RateLimiting_Good(t *testing.T) {
|
|||
|
||||
pc := tp.connectClient(t)
|
||||
|
||||
clientID := tp.ClientNode.Identity().ID
|
||||
serverID := tp.ServerNode.Identity().ID
|
||||
clientID := tp.ClientNode.GetIdentity().ID
|
||||
serverID := tp.ServerNode.GetIdentity().ID
|
||||
|
||||
// Send 150 messages rapidly (rate limiter burst = 100)
|
||||
for range 150 {
|
||||
|
|
@ -498,7 +498,7 @@ func TestTransport_MaxConnectionsEnforcement_Good(t *testing.T) {
|
|||
client1Transport := NewTransport(client1NM, client1Reg, DefaultTransportConfig())
|
||||
t.Cleanup(func() { client1Transport.Stop() })
|
||||
|
||||
peer1 := &Peer{ID: serverNM.Identity().ID, Name: "server", Address: serverAddr, Role: RoleWorker}
|
||||
peer1 := &Peer{ID: serverNM.GetIdentity().ID, Name: "server", Address: serverAddr, Role: RoleWorker}
|
||||
client1Reg.AddPeer(peer1)
|
||||
|
||||
_, err := client1Transport.Connect(peer1)
|
||||
|
|
@ -515,7 +515,7 @@ func TestTransport_MaxConnectionsEnforcement_Good(t *testing.T) {
|
|||
client2Transport := NewTransport(client2NM, client2Reg, DefaultTransportConfig())
|
||||
t.Cleanup(func() { client2Transport.Stop() })
|
||||
|
||||
peer2 := &Peer{ID: serverNM.Identity().ID, Name: "server", Address: serverAddr, Role: RoleWorker}
|
||||
peer2 := &Peer{ID: serverNM.GetIdentity().ID, Name: "server", Address: serverAddr, Role: RoleWorker}
|
||||
client2Reg.AddPeer(peer2)
|
||||
|
||||
_, err = client2Transport.Connect(peer2)
|
||||
|
|
@ -545,9 +545,9 @@ func TestTransport_KeepaliveTimeout_Bad(t *testing.T) {
|
|||
|
||||
// Close the underlying WebSocket on the client side to simulate network failure.
|
||||
// The server's readLoop will detect the broken connection and clean up.
|
||||
clientID := tp.ClientNode.Identity().ID
|
||||
serverPeerID := tp.ServerNode.Identity().ID
|
||||
clientConn := tp.Client.Connection(serverPeerID)
|
||||
clientID := tp.ClientNode.GetIdentity().ID
|
||||
serverPeerID := tp.ServerNode.GetIdentity().ID
|
||||
clientConn := tp.Client.GetConnection(serverPeerID)
|
||||
if clientConn == nil {
|
||||
t.Fatal("client should have connection to server")
|
||||
}
|
||||
|
|
@ -562,7 +562,7 @@ func TestTransport_KeepaliveTimeout_Bad(t *testing.T) {
|
|||
default:
|
||||
if tp.Server.ConnectedPeerCount() == 0 {
|
||||
// Verify registry updated
|
||||
peer := tp.ServerReg.Peer(clientID)
|
||||
peer := tp.ServerReg.GetPeer(clientID)
|
||||
if peer != nil && peer.Connected {
|
||||
t.Error("registry should show peer as disconnected")
|
||||
}
|
||||
|
|
@ -618,8 +618,8 @@ func TestTransport_ConcurrentSends_Ugly(t *testing.T) {
|
|||
|
||||
pc := tp.connectClient(t)
|
||||
|
||||
clientID := tp.ClientNode.Identity().ID
|
||||
serverID := tp.ServerNode.Identity().ID
|
||||
clientID := tp.ClientNode.GetIdentity().ID
|
||||
serverID := tp.ServerNode.GetIdentity().ID
|
||||
|
||||
// Spawn 10 goroutines each sending 5 messages concurrently
|
||||
const goroutines = 10
|
||||
|
|
@ -667,7 +667,7 @@ func TestTransport_Broadcast_Good(t *testing.T) {
|
|||
counter.Add(1)
|
||||
})
|
||||
|
||||
wID := nm.Identity().ID
|
||||
wID := nm.GetIdentity().ID
|
||||
peer := &Peer{
|
||||
ID: wID,
|
||||
Name: "worker",
|
||||
|
|
@ -685,7 +685,7 @@ func TestTransport_Broadcast_Good(t *testing.T) {
|
|||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
// Broadcast a message from the controller
|
||||
controllerID := controllerNM.Identity().ID
|
||||
controllerID := controllerNM.GetIdentity().ID
|
||||
msg, _ := NewMessage(MessagePing, controllerID, "", PingPayload{
|
||||
SentAt: time.Now().UnixMilli(),
|
||||
})
|
||||
|
|
@ -721,7 +721,7 @@ func TestTransport_BroadcastExcludesSender_Good(t *testing.T) {
|
|||
// The server has a connection to the client, but msg.From matches the client's
|
||||
// connection peer ID check, not the server's own ID. Let's verify sender exclusion
|
||||
// by broadcasting from the server with its own ID.
|
||||
serverID := tp.ServerNode.Identity().ID
|
||||
serverID := tp.ServerNode.GetIdentity().ID
|
||||
msg, _ := NewMessage(MessagePing, serverID, "", PingPayload{SentAt: time.Now().UnixMilli()})
|
||||
|
||||
// This broadcasts from server to all connected peers (the client).
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ func TestWorker_HandlePing_Good(t *testing.T) {
|
|||
worker.DeploymentDirectory = t.TempDir()
|
||||
|
||||
// Create a ping message
|
||||
identity := nm.Identity()
|
||||
identity := nm.GetIdentity()
|
||||
if identity == nil {
|
||||
t.Fatal("expected identity to be generated")
|
||||
}
|
||||
|
|
@ -192,7 +192,7 @@ func TestWorker_HandleStats_Good(t *testing.T) {
|
|||
worker.DeploymentDirectory = t.TempDir()
|
||||
|
||||
// Create a stats request message.
|
||||
identity := nm.Identity()
|
||||
identity := nm.GetIdentity()
|
||||
if identity == nil {
|
||||
t.Fatal("expected identity to be generated")
|
||||
}
|
||||
|
|
@ -252,7 +252,7 @@ func TestWorker_HandleStartMiner_NoManager_Bad(t *testing.T) {
|
|||
worker.DeploymentDirectory = t.TempDir()
|
||||
|
||||
// Create a start_miner message
|
||||
identity := nm.Identity()
|
||||
identity := nm.GetIdentity()
|
||||
if identity == nil {
|
||||
t.Fatal("expected identity to be generated")
|
||||
}
|
||||
|
|
@ -292,7 +292,7 @@ func TestWorker_HandleStopMiner_NoManager_Bad(t *testing.T) {
|
|||
worker.DeploymentDirectory = t.TempDir()
|
||||
|
||||
// Create a stop_miner message
|
||||
identity := nm.Identity()
|
||||
identity := nm.GetIdentity()
|
||||
if identity == nil {
|
||||
t.Fatal("expected identity to be generated")
|
||||
}
|
||||
|
|
@ -332,7 +332,7 @@ func TestWorker_HandleLogs_NoManager_Bad(t *testing.T) {
|
|||
worker.DeploymentDirectory = t.TempDir()
|
||||
|
||||
// Create a logs request message.
|
||||
identity := nm.Identity()
|
||||
identity := nm.GetIdentity()
|
||||
if identity == nil {
|
||||
t.Fatal("expected identity to be generated")
|
||||
}
|
||||
|
|
@ -372,7 +372,7 @@ func TestWorker_HandleDeploy_Profile_Good(t *testing.T) {
|
|||
worker.DeploymentDirectory = t.TempDir()
|
||||
|
||||
// Create a deploy message for profile
|
||||
identity := nm.Identity()
|
||||
identity := nm.GetIdentity()
|
||||
if identity == nil {
|
||||
t.Fatal("expected identity to be generated")
|
||||
}
|
||||
|
|
@ -416,7 +416,7 @@ func TestWorker_HandleDeploy_UnknownType_Bad(t *testing.T) {
|
|||
worker.DeploymentDirectory = t.TempDir()
|
||||
|
||||
// Create a deploy message with unknown type
|
||||
identity := nm.Identity()
|
||||
identity := nm.GetIdentity()
|
||||
if identity == nil {
|
||||
t.Fatal("expected identity to be generated")
|
||||
}
|
||||
|
|
@ -629,7 +629,7 @@ func TestWorker_HandleStartMiner_WithManager_Good(t *testing.T) {
|
|||
mmFull := &mockMinerManagerWithStart{}
|
||||
worker.SetMinerManager(mmFull)
|
||||
|
||||
identity := nm.Identity()
|
||||
identity := nm.GetIdentity()
|
||||
|
||||
t.Run("ConfigOverride", func(t *testing.T) {
|
||||
payload := StartMinerPayload{
|
||||
|
|
@ -788,7 +788,7 @@ func TestWorker_HandleStopMiner_WithManager_Good(t *testing.T) {
|
|||
transport := NewTransport(nm, pr, DefaultTransportConfig())
|
||||
worker := NewWorker(nm, transport)
|
||||
worker.DeploymentDirectory = t.TempDir()
|
||||
identity := nm.Identity()
|
||||
identity := nm.GetIdentity()
|
||||
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
worker.SetMinerManager(&mockMinerManager{})
|
||||
|
|
@ -852,7 +852,7 @@ func TestWorker_HandleLogs_WithManager_Good(t *testing.T) {
|
|||
transport := NewTransport(nm, pr, DefaultTransportConfig())
|
||||
worker := NewWorker(nm, transport)
|
||||
worker.DeploymentDirectory = t.TempDir()
|
||||
identity := nm.Identity()
|
||||
identity := nm.GetIdentity()
|
||||
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
mm := &mockMinerManager{
|
||||
|
|
@ -959,7 +959,7 @@ func TestWorker_HandleStats_WithMinerManager_Good(t *testing.T) {
|
|||
transport := NewTransport(nm, pr, DefaultTransportConfig())
|
||||
worker := NewWorker(nm, transport)
|
||||
worker.DeploymentDirectory = t.TempDir()
|
||||
identity := nm.Identity()
|
||||
identity := nm.GetIdentity()
|
||||
|
||||
// Set miner manager with miners that have real stats
|
||||
mm := &mockMinerManager{
|
||||
|
|
@ -1021,7 +1021,7 @@ func TestWorker_HandleMessage_UnknownType_Bad(t *testing.T) {
|
|||
worker := NewWorker(nm, transport)
|
||||
worker.DeploymentDirectory = t.TempDir()
|
||||
|
||||
identity := nm.Identity()
|
||||
identity := nm.GetIdentity()
|
||||
msg, _ := NewMessage("unknown_type", "sender-id", identity.ID, nil)
|
||||
|
||||
// HandleMessage with unknown type should return silently (no panic)
|
||||
|
|
@ -1051,7 +1051,7 @@ func TestWorker_HandleDeploy_ProfileWithManager_Good(t *testing.T) {
|
|||
pm := &mockProfileManagerFull{profiles: make(map[string]any)}
|
||||
worker.SetProfileManager(pm)
|
||||
|
||||
identity := nm.Identity()
|
||||
identity := nm.GetIdentity()
|
||||
|
||||
// Create an unencrypted profile bundle for deploy
|
||||
profileJSON := []byte(`{"id": "deploy-test", "name": "Test Profile"}`)
|
||||
|
|
@ -1104,7 +1104,7 @@ func TestWorker_HandleDeploy_ProfileSaveFails_Bad(t *testing.T) {
|
|||
worker.DeploymentDirectory = t.TempDir()
|
||||
worker.SetProfileManager(&mockProfileManagerFailing{})
|
||||
|
||||
identity := nm.Identity()
|
||||
identity := nm.GetIdentity()
|
||||
|
||||
profileJSON := []byte(`{"id": "fail-test"}`)
|
||||
bundle, _ := CreateProfileBundleUnencrypted(profileJSON, "fail-test")
|
||||
|
|
@ -1151,7 +1151,7 @@ func TestWorker_HandleDeploy_MinerBundle_Good(t *testing.T) {
|
|||
pm := &mockProfileManagerFull{profiles: make(map[string]any)}
|
||||
worker.SetProfileManager(pm)
|
||||
|
||||
identity := nm.Identity()
|
||||
identity := nm.GetIdentity()
|
||||
|
||||
tmpDir := t.TempDir()
|
||||
minerPath := testJoinPath(tmpDir, "test-miner")
|
||||
|
|
@ -1213,7 +1213,7 @@ func TestWorker_HandleDeploy_FullBundle_Good(t *testing.T) {
|
|||
worker := NewWorker(nm, transport)
|
||||
worker.DeploymentDirectory = t.TempDir()
|
||||
|
||||
identity := nm.Identity()
|
||||
identity := nm.GetIdentity()
|
||||
|
||||
tmpDir := t.TempDir()
|
||||
minerPath := testJoinPath(tmpDir, "test-miner")
|
||||
|
|
@ -1272,7 +1272,7 @@ func TestWorker_HandleDeploy_MinerBundle_ProfileManager_Good(t *testing.T) {
|
|||
// Set a failing profile manager to exercise the warn-and-continue path
|
||||
worker.SetProfileManager(&mockProfileManagerFailing{})
|
||||
|
||||
identity := nm.Identity()
|
||||
identity := nm.GetIdentity()
|
||||
|
||||
tmpDir := t.TempDir()
|
||||
minerPath := testJoinPath(tmpDir, "test-miner")
|
||||
|
|
@ -1321,7 +1321,7 @@ func TestWorker_HandleDeploy_InvalidPayload_Bad(t *testing.T) {
|
|||
transport := NewTransport(nm, pr, DefaultTransportConfig())
|
||||
worker := NewWorker(nm, transport)
|
||||
worker.DeploymentDirectory = t.TempDir()
|
||||
identity := nm.Identity()
|
||||
identity := nm.GetIdentity()
|
||||
|
||||
// Create a message with invalid payload
|
||||
msg, _ := NewMessage(MessageDeploy, "sender-id", identity.ID, "invalid-payload-not-struct")
|
||||
|
|
@ -1366,7 +1366,7 @@ func TestWorker_HandleMessage_IntegrationViaWebSocket_Good(t *testing.T) {
|
|||
tp.connectClient(t)
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
||||
serverID := tp.ServerNode.Identity().ID
|
||||
serverID := tp.ServerNode.GetIdentity().ID
|
||||
|
||||
// Send start_miner which will fail because no manager is set.
|
||||
// The worker should send an error response via the connection.
|
||||
|
|
@ -1405,9 +1405,9 @@ func TestWorker_HandleMessage_Stats_IntegrationViaWebSocket_Good(t *testing.T) {
|
|||
tp.connectClient(t)
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
||||
serverID := tp.ServerNode.Identity().ID
|
||||
serverID := tp.ServerNode.GetIdentity().ID
|
||||
|
||||
stats, err := controller.RemoteStats(serverID)
|
||||
stats, err := controller.GetRemoteStats(serverID)
|
||||
if err != nil {
|
||||
t.Fatalf("RemoteStats failed: %v", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue