diff options
| author | Adriano Sela Aviles <adriano@tailscale.com> | 2026-04-03 00:46:35 -0700 |
|---|---|---|
| committer | Adriano Sela Aviles <adriano@tailscale.com> | 2026-04-10 22:13:12 -0700 |
| commit | 1f6a4389b6dd64aff6e3fd8f5c6e61495fe00563 (patch) | |
| tree | af23385affa9c8f459bd9aa7f1efbd8d29913ff4 /types/netmap | |
| parent | 0e8ae9d60c92ec578bc0ff7c2be0334df6908c8b (diff) | |
| download | tailscale-adrianosela/visible-services.tar.xz tailscale-adrianosela/visible-services.zip | |
tailcfg,types/netmap: visible services in netmapadrianosela/visible-services
ipn/localapi: serve service list over localapi
cmd/tailscale: new service list command
Updates <FIXME(@adrianosela)>
Diffstat (limited to 'types/netmap')
| -rw-r--r-- | types/netmap/netmap.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/types/netmap/netmap.go b/types/netmap/netmap.go index ac95254da..90ed9b3fc 100644 --- a/types/netmap/netmap.go +++ b/types/netmap/netmap.go @@ -146,6 +146,27 @@ func (nm *NetworkMap) GetIPVIPServiceMap() IPServiceMappings { return res } +// Services returns the Services visible (accessible) to this node, +// decoded from [tailcfg.NodeAttrPrefixServices]+serviceName entries in the +// self node's CapMap. Returns nil if nm is nil or SelfNode is invalid. +func (nm *NetworkMap) Services() map[tailcfg.ServiceName]tailcfg.ServiceDetails { + if nm == nil || !nm.SelfNode.Valid() { + return nil + } + result := make(map[tailcfg.ServiceName]tailcfg.ServiceDetails) + for cap := range nm.SelfNode.CapMap().All() { + if !strings.HasPrefix(string(cap), string(tailcfg.NodeAttrPrefixServices)) { + continue + } + svcs, err := tailcfg.UnmarshalNodeCapViewJSON[tailcfg.ServiceDetails](nm.SelfNode.CapMap(), cap) + if err != nil || len(svcs) < 1 { + continue + } + result[svcs[0].Name] = svcs[0] + } + return result +} + // SelfNodeOrZero returns the self node, or a zero value if nm is nil. func (nm *NetworkMap) SelfNodeOrZero() tailcfg.NodeView { if nm == nil { |
