peerChangeDiff returns the difference from 'was' to 'n', if possible. It returns (nil, true) if the fields were identical.
(was tailcfg.NodeView, n *tailcfg.Node, onFalse func(string))
| 977 | // |
| 978 | // It returns (nil, true) if the fields were identical. |
| 979 | func peerChangeDiff(was tailcfg.NodeView, n *tailcfg.Node, onFalse func(string)) (_ *tailcfg.PeerChange, ok bool) { |
| 980 | if onFalse == nil { |
| 981 | onFalse = func(string) {} |
| 982 | } |
| 983 | var ret *tailcfg.PeerChange |
| 984 | pc := func() *tailcfg.PeerChange { |
| 985 | if ret == nil { |
| 986 | ret = new(tailcfg.PeerChange) |
| 987 | } |
| 988 | return ret |
| 989 | } |
| 990 | for _, field := range nodeFields() { |
| 991 | switch field { |
| 992 | default: |
| 993 | // The whole point of using reflect in this function is to panic |
| 994 | // here in tests if we forget to handle a new field. |
| 995 | panic("unhandled field: " + field) |
| 996 | case "computedHostIfDifferent", "ComputedName", "ComputedNameWithHost": |
| 997 | // Caller's responsibility to have populated these. |
| 998 | continue |
| 999 | case "DataPlaneAuditLogID": |
| 1000 | // Not sent for peers. |
| 1001 | case "Capabilities": |
| 1002 | // Deprecated; see https://github.com/tailscale/tailscale/issues/11508 |
| 1003 | // And it was never sent by any known control server. |
| 1004 | case "ID": |
| 1005 | if was.ID() != n.ID { |
| 1006 | onFalse(field) |
| 1007 | return nil, false |
| 1008 | } |
| 1009 | case "StableID": |
| 1010 | if was.StableID() != n.StableID { |
| 1011 | onFalse(field) |
| 1012 | return nil, false |
| 1013 | } |
| 1014 | case "Name": |
| 1015 | if was.Name() != n.Name { |
| 1016 | onFalse(field) |
| 1017 | return nil, false |
| 1018 | } |
| 1019 | case "User": |
| 1020 | if was.User() != n.User { |
| 1021 | onFalse(field) |
| 1022 | return nil, false |
| 1023 | } |
| 1024 | case "Sharer": |
| 1025 | if was.Sharer() != n.Sharer { |
| 1026 | onFalse(field) |
| 1027 | return nil, false |
| 1028 | } |
| 1029 | case "Key": |
| 1030 | if was.Key() != n.Key { |
| 1031 | pc().Key = new(n.Key) |
| 1032 | } |
| 1033 | case "KeyExpiry": |
| 1034 | if !was.KeyExpiry().Equal(n.KeyExpiry) { |
| 1035 | pc().KeyExpiry = new(n.KeyExpiry) |
| 1036 | } |
searching dependent graphs…