util/eventbus: add debugger methods to list pub/sub types

This lets debug tools list the types that clients are wielding, so
that they can build a dataflow graph and other debugging views.

Updates #15160

Signed-off-by: David Anderson <dave@tailscale.com>
This commit is contained in:
David Anderson
2025-03-07 08:16:53 -08:00
committed by Dave Anderson
parent e71e95b841
commit 346a35f612
3 changed files with 50 additions and 0 deletions

View File

@@ -59,6 +59,20 @@ func (c *Client) peekSubscribeState() *subscribeState {
return c.sub
}
func (c *Client) publishTypes() []reflect.Type {
c.mu.Lock()
defer c.mu.Unlock()
ret := make([]reflect.Type, 0, len(c.pub))
for pub := range c.pub {
ret = append(ret, pub.publishType())
}
return ret
}
func (c *Client) subscribeTypes() []reflect.Type {
return c.peekSubscribeState().subscribeTypes()
}
func (c *Client) subscribeState() *subscribeState {
c.mu.Lock()
defer c.mu.Unlock()