@@ -13,6 +13,7 @@ import (
1313 "unicode/utf8"
1414
1515 "tailscale.com/tailcfg"
16+ "tailscale.com/types/bools"
1617 "tailscale.com/types/netlogtype"
1718 "tailscale.com/util/set"
1819)
@@ -134,17 +135,31 @@ func compareConnCnts(x, y netlogtype.ConnectionCounts) int {
134135}
135136
136137// jsonLen computes an upper-bound on the size of the JSON representation.
137- func (nu nodeUser ) jsonLen () int {
138+ func (nu nodeUser ) jsonLen () ( n int ) {
138139 if ! nu .Valid () {
139140 return len (`{"nodeId":""}` )
140141 }
141- n := netlogtype .MinNodeJSONSize + jsonQuotedLen (nu .Name ())
142+ n += len (`{}` )
143+ n += len (`"nodeId":` ) + jsonQuotedLen (string (nu .StableID ())) + len (`,` )
144+ if len (nu .Name ()) > 0 {
145+ n += len (`"name":` ) + jsonQuotedLen (nu .Name ()) + len (`,` )
146+ }
147+ if nu .Addresses ().Len () > 0 {
148+ n += len (`"addresses":[]` )
149+ for _ , addr := range nu .Addresses ().All () {
150+ n += bools .IfElse (addr .Addr ().Is4 (), len (`"255.255.255.255"` ), len (`"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"` )) + len ("," )
151+ }
152+ }
153+ if nu .Hostinfo ().Valid () && len (nu .Hostinfo ().OS ()) > 0 {
154+ n += len (`"os":` ) + jsonQuotedLen (nu .Hostinfo ().OS ()) + len (`,` )
155+ }
142156 if nu .Tags ().Len () > 0 {
157+ n += len (`"tags":[]` )
143158 for _ , tag := range nu .Tags ().All () {
144159 n += jsonQuotedLen (tag ) + len ("," )
145160 }
146- } else if nu .user .Valid () && nu .user .ID () == nu .User () {
147- n += jsonQuotedLen (nu .user .LoginName ())
161+ } else if nu .user .Valid () && nu .user .ID () == nu .User () && len ( nu . user . LoginName ()) > 0 {
162+ n += len ( `"user":` ) + jsonQuotedLen (nu .user .LoginName ()) + len ( "," )
148163 }
149164 return n
150165}
@@ -166,6 +181,9 @@ func (nu nodeUser) toNode() netlogtype.Node {
166181 }
167182 n .Addresses = []netip.Addr {ipv4 , ipv6 }
168183 n .Addresses = slices .DeleteFunc (n .Addresses , func (a netip.Addr ) bool { return ! a .IsValid () })
184+ if nu .Hostinfo ().Valid () {
185+ n .OS = nu .Hostinfo ().OS ()
186+ }
169187 if nu .Tags ().Len () > 0 {
170188 n .Tags = nu .Tags ().AsSlice ()
171189 slices .Sort (n .Tags )
0 commit comments