mirror of
https://github.com/juanfont/headscale.git
synced 2025-06-05 01:20:21 +02:00
mapper: make online non-ptr
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
parent
62b489dc68
commit
a360c98f1b
@ -544,6 +544,7 @@ func nodesToProto(polMan policy.PolicyManager, isLikelyConnected *xsync.MapOf[ty
|
|||||||
// currently connected nodes.
|
// currently connected nodes.
|
||||||
if val, ok := isLikelyConnected.Load(node.ID); ok && val {
|
if val, ok := isLikelyConnected.Load(node.ID); ok && val {
|
||||||
resp.Online = true
|
resp.Online = true
|
||||||
|
resp.LastSeen = timestamppb.New(time.Now())
|
||||||
}
|
}
|
||||||
|
|
||||||
var tags []string
|
var tags []string
|
||||||
|
@ -504,7 +504,7 @@ func (m *Mapper) ListPeers(nodeID types.NodeID, peerIDs ...types.NodeID) (types.
|
|||||||
|
|
||||||
for _, peer := range peers {
|
for _, peer := range peers {
|
||||||
online := m.notif.IsLikelyConnected(peer.ID)
|
online := m.notif.IsLikelyConnected(peer.ID)
|
||||||
peer.IsOnline = &online
|
peer.IsOnline = online
|
||||||
}
|
}
|
||||||
|
|
||||||
return peers, nil
|
return peers, nil
|
||||||
@ -520,7 +520,7 @@ func (m *Mapper) ListNodes(nodeIDs ...types.NodeID) (types.Nodes, error) {
|
|||||||
|
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
online := m.notif.IsLikelyConnected(node.ID)
|
online := m.notif.IsLikelyConnected(node.ID)
|
||||||
node.IsOnline = &online
|
node.IsOnline = online
|
||||||
}
|
}
|
||||||
|
|
||||||
return nodes, nil
|
return nodes, nil
|
||||||
|
@ -17,6 +17,7 @@ import (
|
|||||||
"tailscale.com/tailcfg"
|
"tailscale.com/tailcfg"
|
||||||
"tailscale.com/types/dnstype"
|
"tailscale.com/types/dnstype"
|
||||||
"tailscale.com/types/key"
|
"tailscale.com/types/key"
|
||||||
|
"tailscale.com/types/ptr"
|
||||||
)
|
)
|
||||||
|
|
||||||
var iap = func(ipStr string) *netip.Addr {
|
var iap = func(ipStr string) *netip.Addr {
|
||||||
@ -184,6 +185,7 @@ func Test_fullMapResponse(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
Created: created,
|
Created: created,
|
||||||
Tags: []string{},
|
Tags: []string{},
|
||||||
|
Online: ptr.To(false),
|
||||||
LastSeen: &lastSeen,
|
LastSeen: &lastSeen,
|
||||||
MachineAuthorized: true,
|
MachineAuthorized: true,
|
||||||
|
|
||||||
@ -239,6 +241,7 @@ func Test_fullMapResponse(t *testing.T) {
|
|||||||
Hostinfo: hiview(tailcfg.Hostinfo{}),
|
Hostinfo: hiview(tailcfg.Hostinfo{}),
|
||||||
Created: created,
|
Created: created,
|
||||||
Tags: []string{},
|
Tags: []string{},
|
||||||
|
Online: ptr.To(false),
|
||||||
LastSeen: &lastSeen,
|
LastSeen: &lastSeen,
|
||||||
MachineAuthorized: true,
|
MachineAuthorized: true,
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
"tailscale.com/net/tsaddr"
|
"tailscale.com/net/tsaddr"
|
||||||
"tailscale.com/tailcfg"
|
"tailscale.com/tailcfg"
|
||||||
|
"tailscale.com/types/ptr"
|
||||||
)
|
)
|
||||||
|
|
||||||
func tailNodes(
|
func tailNodes(
|
||||||
@ -107,7 +108,7 @@ func tailNode(
|
|||||||
Hostinfo: node.Hostinfo.View(),
|
Hostinfo: node.Hostinfo.View(),
|
||||||
Created: node.CreatedAt.UTC(),
|
Created: node.CreatedAt.UTC(),
|
||||||
|
|
||||||
Online: node.IsOnline,
|
Online: ptr.To(node.IsOnline),
|
||||||
|
|
||||||
Tags: tags,
|
Tags: tags,
|
||||||
|
|
||||||
@ -125,7 +126,10 @@ func tailNode(
|
|||||||
tNode.CapMap[tailcfg.NodeAttrRandomizeClientPort] = []tailcfg.RawMessage{}
|
tNode.CapMap[tailcfg.NodeAttrRandomizeClientPort] = []tailcfg.RawMessage{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if node.IsOnline == nil || !*node.IsOnline {
|
if node.IsOnline {
|
||||||
|
// If the node is online, return the current time.
|
||||||
|
tNode.LastSeen = ptr.To(time.Now())
|
||||||
|
} else {
|
||||||
// LastSeen is only set when node is
|
// LastSeen is only set when node is
|
||||||
// not connected to the control server.
|
// not connected to the control server.
|
||||||
tNode.LastSeen = node.LastSeen
|
tNode.LastSeen = node.LastSeen
|
||||||
|
@ -15,6 +15,7 @@ import (
|
|||||||
"tailscale.com/net/tsaddr"
|
"tailscale.com/net/tsaddr"
|
||||||
"tailscale.com/tailcfg"
|
"tailscale.com/tailcfg"
|
||||||
"tailscale.com/types/key"
|
"tailscale.com/types/key"
|
||||||
|
"tailscale.com/types/ptr"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTailNode(t *testing.T) {
|
func TestTailNode(t *testing.T) {
|
||||||
@ -73,6 +74,7 @@ func TestTailNode(t *testing.T) {
|
|||||||
Tags: []string{},
|
Tags: []string{},
|
||||||
MachineAuthorized: true,
|
MachineAuthorized: true,
|
||||||
|
|
||||||
|
Online: ptr.To(false),
|
||||||
CapMap: tailcfg.NodeCapMap{
|
CapMap: tailcfg.NodeCapMap{
|
||||||
tailcfg.CapabilityFileSharing: []tailcfg.RawMessage{},
|
tailcfg.CapabilityFileSharing: []tailcfg.RawMessage{},
|
||||||
tailcfg.CapabilityAdmin: []tailcfg.RawMessage{},
|
tailcfg.CapabilityAdmin: []tailcfg.RawMessage{},
|
||||||
@ -158,6 +160,7 @@ func TestTailNode(t *testing.T) {
|
|||||||
|
|
||||||
Tags: []string{},
|
Tags: []string{},
|
||||||
|
|
||||||
|
Online: ptr.To(false),
|
||||||
LastSeen: &lastSeen,
|
LastSeen: &lastSeen,
|
||||||
MachineAuthorized: true,
|
MachineAuthorized: true,
|
||||||
|
|
||||||
@ -186,6 +189,7 @@ func TestTailNode(t *testing.T) {
|
|||||||
Hostinfo: hiview(tailcfg.Hostinfo{}),
|
Hostinfo: hiview(tailcfg.Hostinfo{}),
|
||||||
Tags: []string{},
|
Tags: []string{},
|
||||||
MachineAuthorized: true,
|
MachineAuthorized: true,
|
||||||
|
Online: ptr.To(false),
|
||||||
|
|
||||||
CapMap: tailcfg.NodeCapMap{
|
CapMap: tailcfg.NodeCapMap{
|
||||||
tailcfg.CapabilityFileSharing: []tailcfg.RawMessage{},
|
tailcfg.CapabilityFileSharing: []tailcfg.RawMessage{},
|
||||||
|
@ -110,7 +110,7 @@ type Node struct {
|
|||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
DeletedAt *time.Time
|
DeletedAt *time.Time
|
||||||
|
|
||||||
IsOnline *bool `gorm:"-"`
|
IsOnline bool `gorm:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Nodes []*Node
|
type Nodes []*Node
|
||||||
@ -512,7 +512,7 @@ func (node *Node) ApplyPeerChange(change *tailcfg.PeerChange) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if change.Online != nil {
|
if change.Online != nil {
|
||||||
node.IsOnline = change.Online
|
node.IsOnline = *change.Online
|
||||||
}
|
}
|
||||||
|
|
||||||
if change.Endpoints != nil {
|
if change.Endpoints != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user