Skip to content

Commit 844071d

Browse files
committed
Add ping
1 parent c5f91a8 commit 844071d

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

tailnet/tailnet.go

+11-14
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"golang.org/x/xerrors"
1212
"gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
1313
"inet.af/netaddr"
14+
"tailscale.com/hostinfo"
15+
"tailscale.com/ipn/ipnstate"
1416
"tailscale.com/net/dns"
1517
"tailscale.com/net/netns"
1618
"tailscale.com/net/tsdial"
@@ -239,11 +241,11 @@ func (s *Server) SetNodeCallback(callback func(node *Node)) {
239241
fmt.Printf("\n\n\n\nNetwork status: %+v %s\n\n\n\n", s, err)
240242
})
241243

242-
s.wireguardEngine.AddNetworkMapCallback(func(nm *netmap.NetworkMap) {
243-
fmt.Printf("\n\n\n\nNetwork map: %+v\n\n\n\n", nm)
244-
})
244+
// s.wireguardEngine.AddNetworkMapCallback(func(nm *netmap.NetworkMap) {
245+
// fmt.Printf("\n\n\n\nNetwork map: %+v\n\n\n\n", nm)
246+
// })
245247
s.magicConn.SetNetInfoCallback(func(ni *tailcfg.NetInfo) {
246-
fmt.Printf("\n\n\n\n\nUpdating network information: %+v\n\n\n\n\n", ni)
248+
// fmt.Printf("\n\n\n\n\nUpdating network information: %+v\n\n\n\n\n", ni)
247249
callback(&Node{
248250
ID: s.netMap.SelfNode.ID,
249251
Key: s.netMap.SelfNode.Key,
@@ -256,16 +258,6 @@ func (s *Server) SetNodeCallback(callback func(node *Node)) {
256258
})
257259
}
258260

259-
// Once the client disconnects, why not just reset the connection?
260-
// When the agent reconnects it will update itself, in which case
261-
// we should do a `SetNetInfoCallback` to get the personal node info
262-
// again to send on the wire.
263-
//
264-
// On disconnect, we should continually poll the workspace agent to
265-
// update the node to reestablish a connection.
266-
//
267-
// How do we know if we're disconnected?
268-
269261
// UpdateNodes connects with a set of peers. This can be constantly updated,
270262
// and peers will continually be reconnected as necessary.
271263
func (s *Server) UpdateNodes(nodes []*Node) error {
@@ -283,6 +275,7 @@ func (s *Server) UpdateNodes(nodes []*Node) error {
283275
Addresses: node.Addresses,
284276
AllowedIPs: node.AllowedIPs,
285277
DERP: fmt.Sprintf("%s:%d", magicsock.DerpMagicIP, node.PreferredDERP),
278+
Hostinfo: hostinfo.New().View(),
286279
}
287280
}
288281
s.netMap.Peers = make([]*tailcfg.Node, 0, len(peerMap))
@@ -302,6 +295,10 @@ func (s *Server) UpdateNodes(nodes []*Node) error {
302295
return nil
303296
}
304297

298+
func (s *Server) Ping(ip netaddr.IP, pingType tailcfg.PingType, cb func(*ipnstate.PingResult)) {
299+
s.wireguardEngine.Ping(ip, pingType, cb)
300+
}
301+
305302
// Close shuts down the Wireguard connection.
306303
func (s *Server) Close() error {
307304
s.mutex.Lock()

0 commit comments

Comments
 (0)