Skip to content

Commit 5b56a14

Browse files
committed
fix(mesh): expose peer identity in get_peers — populate peerID for non-listener outbound sessions
1 parent fcd9721 commit 5b56a14

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

internal/core/node/peer_management.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ func (s *Service) openPeerSession(ctx context.Context, address domain.PeerAddres
682682
s.mu.RLock()
683683
healthKey := s.resolveHealthAddress(address)
684684
s.mu.RUnlock()
685+
s.addPeerID(healthKey, session.peerIdentity)
685686
s.addPeerVersion(healthKey, welcome.ClientVersion)
686687
s.addPeerBuild(healthKey, welcome.ClientBuild)
687688
if err := s.authenticatePeerSession(session, welcome); err != nil {

internal/core/service/desktop.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ type PendingMessage struct {
120120

121121
type ConsolePeerStatus struct {
122122
Address string `json:"address"`
123+
Identity string `json:"identity,omitempty"`
123124
ConnID uint64 `json:"conn_id,omitempty"`
124125
Network string `json:"network,omitempty"`
125126
Direction string `json:"direction,omitempty"`
@@ -809,6 +810,7 @@ func buildConsolePeersPayload(peers []string, health []PeerHealth) any {
809810

810811
status := ConsolePeerStatus{
811812
Address: address,
813+
Identity: item.PeerID,
812814
ConnID: item.ConnID,
813815
Network: node.ClassifyAddress(address).String(),
814816
Direction: item.Direction,
@@ -849,6 +851,7 @@ func buildConsolePeersPayload(peers []string, health []PeerHealth) any {
849851
item := byAddress[addr]
850852
status := ConsolePeerStatus{
851853
Address: addr,
854+
Identity: item.PeerID,
852855
ConnID: item.ConnID,
853856
Network: node.ClassifyAddress(addr).String(),
854857
Direction: item.Direction,

internal/core/service/desktop_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,40 @@ func TestBuildConsolePeersPayloadIncludesClientBuild(t *testing.T) {
704704
}
705705
}
706706

707+
func TestBuildConsolePeersPayloadIncludesPeerIdentity(t *testing.T) {
708+
t.Parallel()
709+
710+
payload := buildConsolePeersPayload(
711+
[]string{"a:1", "b:2"},
712+
[]PeerHealth{
713+
{Address: "a:1", PeerID: "abc123", State: "healthy", Connected: true},
714+
{Address: "b:2", PeerID: "", State: "healthy", Connected: true},
715+
},
716+
)
717+
718+
type peersPayload struct {
719+
Peers []ConsolePeerStatus `json:"peers"`
720+
}
721+
data, err := json.Marshal(payload)
722+
if err != nil {
723+
t.Fatalf("Marshal returned error: %v", err)
724+
}
725+
var result peersPayload
726+
if err := json.Unmarshal(data, &result); err != nil {
727+
t.Fatalf("Unmarshal returned error: %v", err)
728+
}
729+
730+
if len(result.Peers) != 2 {
731+
t.Fatalf("expected 2 peers, got %d", len(result.Peers))
732+
}
733+
if result.Peers[0].Identity != "abc123" {
734+
t.Errorf("peers[0]: expected identity='abc123', got %q", result.Peers[0].Identity)
735+
}
736+
if result.Peers[1].Identity != "" {
737+
t.Errorf("peers[1]: expected empty identity, got %q", result.Peers[1].Identity)
738+
}
739+
}
740+
707741
func TestConsolePingPayloadShape(t *testing.T) {
708742
t.Parallel()
709743

0 commit comments

Comments
 (0)