|
|
@ -3983,30 +3983,6 @@ func simpleDur(d time.Duration) time.Duration {
|
|
|
|
return d.Round(time.Minute)
|
|
|
|
return d.Round(time.Minute)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func sbPrintAddr(sb *strings.Builder, a netip.AddrPort) {
|
|
|
|
|
|
|
|
is6 := a.Addr().Is6()
|
|
|
|
|
|
|
|
if is6 {
|
|
|
|
|
|
|
|
sb.WriteByte('[')
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(sb, "%s", a.Addr())
|
|
|
|
|
|
|
|
if is6 {
|
|
|
|
|
|
|
|
sb.WriteByte(']')
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(sb, ":%d", a.Port())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (c *Conn) derpRegionCodeOfAddrLocked(ipPort string) string {
|
|
|
|
|
|
|
|
_, portStr, err := net.SplitHostPort(ipPort)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return ""
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
regionID, err := strconv.Atoi(portStr)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return ""
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.derpRegionCodeOfIDLocked(regionID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (c *Conn) derpRegionCodeOfIDLocked(regionID int) string {
|
|
|
|
func (c *Conn) derpRegionCodeOfIDLocked(regionID int) string {
|
|
|
|
if c.derpMap == nil {
|
|
|
|
if c.derpMap == nil {
|
|
|
|
return ""
|
|
|
|
return ""
|
|
|
@ -4074,13 +4050,6 @@ func (c *Conn) SetStatistics(stats *connstats.Statistics) {
|
|
|
|
c.stats.Store(stats)
|
|
|
|
c.stats.Store(stats)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func ippDebugString(ua netip.AddrPort) string {
|
|
|
|
|
|
|
|
if ua.Addr() == derpMagicIPAddr {
|
|
|
|
|
|
|
|
return fmt.Sprintf("derp-%d", ua.Port())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return ua.String()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// endpointSendFunc is a func that writes encrypted Wireguard payloads from
|
|
|
|
// endpointSendFunc is a func that writes encrypted Wireguard payloads from
|
|
|
|
// WireGuard to a peer. It might write via UDP, DERP, both, or neither.
|
|
|
|
// WireGuard to a peer. It might write via UDP, DERP, both, or neither.
|
|
|
|
//
|
|
|
|
//
|
|
|
@ -4113,7 +4082,6 @@ type endpoint struct {
|
|
|
|
// atomically accessed; declared first for alignment reasons
|
|
|
|
// atomically accessed; declared first for alignment reasons
|
|
|
|
lastRecv mono.Time
|
|
|
|
lastRecv mono.Time
|
|
|
|
numStopAndResetAtomic int64
|
|
|
|
numStopAndResetAtomic int64
|
|
|
|
sendFunc syncs.AtomicValue[endpointSendFunc] // nil or unset means unused
|
|
|
|
|
|
|
|
debugUpdates *ringbuffer.RingBuffer[EndpointChange]
|
|
|
|
debugUpdates *ringbuffer.RingBuffer[EndpointChange]
|
|
|
|
|
|
|
|
|
|
|
|
// These fields are initialized once and never modified.
|
|
|
|
// These fields are initialized once and never modified.
|
|
|
@ -4146,7 +4114,6 @@ type endpoint struct {
|
|
|
|
// implementation that's a WIP as of 2022-10-20.
|
|
|
|
// implementation that's a WIP as of 2022-10-20.
|
|
|
|
// See #540 for background.
|
|
|
|
// See #540 for background.
|
|
|
|
heartbeatDisabled bool
|
|
|
|
heartbeatDisabled bool
|
|
|
|
pathFinderRunning bool
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expired bool // whether the node has expired
|
|
|
|
expired bool // whether the node has expired
|
|
|
|
isWireguardOnly bool // whether the endpoint is WireGuard only
|
|
|
|
isWireguardOnly bool // whether the endpoint is WireGuard only
|
|
|
@ -4539,23 +4506,12 @@ var (
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func (de *endpoint) send(buffs [][]byte) error {
|
|
|
|
func (de *endpoint) send(buffs [][]byte) error {
|
|
|
|
if fn := de.sendFunc.Load(); fn != nil {
|
|
|
|
|
|
|
|
return fn(buffs)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
de.mu.Lock()
|
|
|
|
de.mu.Lock()
|
|
|
|
if de.expired {
|
|
|
|
if de.expired {
|
|
|
|
de.mu.Unlock()
|
|
|
|
de.mu.Unlock()
|
|
|
|
return errExpired
|
|
|
|
return errExpired
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// if heartbeat disabled, kick off pathfinder
|
|
|
|
|
|
|
|
if de.heartbeatDisabled {
|
|
|
|
|
|
|
|
if !de.pathFinderRunning {
|
|
|
|
|
|
|
|
de.startPathFinder()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
now := mono.Now()
|
|
|
|
now := mono.Now()
|
|
|
|
udpAddr, derpAddr, startWGPing := de.addrForSendLocked(now)
|
|
|
|
udpAddr, derpAddr, startWGPing := de.addrForSendLocked(now)
|
|
|
|
|
|
|
|
|
|
|
@ -4912,9 +4868,6 @@ func (de *endpoint) updateFromNode(n *tailcfg.Node, heartbeatDisabled bool) {
|
|
|
|
de.deleteEndpointLocked("updateFromNode", ep)
|
|
|
|
de.deleteEndpointLocked("updateFromNode", ep)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Node changed. Invalidate its sending fast path, if any.
|
|
|
|
|
|
|
|
de.sendFunc.Store(nil)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// addCandidateEndpoint adds ep as an endpoint to which we should send
|
|
|
|
// addCandidateEndpoint adds ep as an endpoint to which we should send
|
|
|
|