Skip to content

Commit

Permalink
ipn/ipnlocal: populate peers' capabilities
Browse files Browse the repository at this point in the history
Populates capabilties field of peers in ipn status.
Updates tailscale/corp#17516
  • Loading branch information
clairew committed Mar 7, 2024
1 parent 6f66f5a commit e13ba13
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions ipn/ipnlocal/local.go
Expand Up @@ -877,6 +877,7 @@ func (b *LocalBackend) populatePeerStatusLocked(sb *ipnstate.StatusBuilder) {
ExitNode: p.StableID() != "" && p.StableID() == exitNodeID,
SSH_HostKeys: p.Hostinfo().SSH_HostKeys().AsSlice(),
Location: p.Hostinfo().Location(),
Capabilities: p.Capabilities().AsSlice(),
}
peerStatusFromNode(ps, p)

Expand Down
49 changes: 49 additions & 0 deletions ipn/ipnlocal/local_test.go
Expand Up @@ -729,6 +729,55 @@ func TestStatusWithoutPeers(t *testing.T) {
}
}

func TestStatusPeerCapabilities(t *testing.T) {
b := newTestLocalBackend(t)

var cc *mockControl
b.SetControlClientGetterForTesting(func(opts controlclient.Options) (controlclient.Client, error) {
cc = newClient(t, opts)

t.Logf("ccGen: new mockControl.")
cc.called("New")
return cc, nil
})
b.Start(ipn.Options{})
b.Login(nil)
cc.send(nil, "", false, &netmap.NetworkMap{
SelfNode: (&tailcfg.Node{
MachineAuthorized: true,
Addresses: ipps("100.101.101.101"),
}).View(),
Peers: []tailcfg.NodeView{
(&tailcfg.Node{
ID: 1,
StableID: "foo",
IsWireGuardOnly: true,
Hostinfo: (&tailcfg.Hostinfo{}).View(),
Capabilities: []tailcfg.NodeCapability{tailcfg.CapabilitySSH},
}).View(),
(&tailcfg.Node{
ID: 2,
StableID: "bar",
Hostinfo: (&tailcfg.Hostinfo{}).View(),
Capabilities: []tailcfg.NodeCapability{tailcfg.CapabilitySSH},
}).View(),
},
})
got := b.Status()
if got.TailscaleIPs == nil {
t.Errorf("got nil, expected TailscaleIPs value to not be nil")
}
if !reflect.DeepEqual(got.TailscaleIPs, got.Self.TailscaleIPs) {
t.Errorf("got %v, expected %v", got.TailscaleIPs, got.Self.TailscaleIPs)
}

for _, peer := range got.Peer {
if peer.Capabilities == nil {
t.Errorf("expected populated capabilities field")
}
}
}

// legacyBackend was the interface between Tailscale frontends
// (e.g. cmd/tailscale, iOS/MacOS/Windows GUIs) and the tailscale
// backend (e.g. cmd/tailscaled) running on the same machine.
Expand Down

0 comments on commit e13ba13

Please sign in to comment.