wgengine/magicsock: use derp-region-as-magic-AddrPort hack in fewer places

And fix up a bogus comment and flesh out some other comments.

Updates #cleanup

Change-Id: Ia60a1c04b0f5e44e8d9587914af819df8e8f442a
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2024-07-06 19:20:15 -07:00
committed by Brad Fitzpatrick
parent e181f12a7b
commit 9df107f4f0
2 changed files with 19 additions and 22 deletions

View File

@@ -7,6 +7,7 @@ package magicsock
import (
"bufio"
"bytes"
"context"
"errors"
"fmt"
@@ -1154,7 +1155,8 @@ func (c *Conn) sendAddr(addr netip.AddrPort, pubKey key.NodePublic, b []byte) (s
return c.sendUDP(addr, b)
}
ch := c.derpWriteChanOfAddr(addr, pubKey)
regionID := int(addr.Port())
ch := c.derpWriteChanForRegion(regionID, pubKey)
if ch == nil {
metricSendDERPErrorChan.Add(1)
return false, nil
@@ -1165,8 +1167,7 @@ func (c *Conn) sendAddr(addr netip.AddrPort, pubKey key.NodePublic, b []byte) (s
// to derpWriteRequest and waited for derphttp.Client.Send to
// complete, but that's too slow while holding wireguard-go
// internal locks.
pkt := make([]byte, len(b))
copy(pkt, b)
pkt := bytes.Clone(b)
select {
case <-c.donec: