From 14100c0985ae520e039fa3b9ed9e71e06077e901 Mon Sep 17 00:00:00 2001 From: Joe Tsai Date: Mon, 17 Oct 2022 13:22:48 -0700 Subject: [PATCH] wgengine/magicsock: restore allocation-free endpoint.DstToString (#5971) The wireguard-go code unfortunately calls this unconditionally even when verbose logging is disabled. Partial revert of #5911. Signed-off-by: Joe Tsai --- wgengine/magicsock/magicsock.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index 4ef750b20..ff2d93f31 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -2400,6 +2400,7 @@ func (c *Conn) SetNetworkMap(nm *netmap.NetworkMap) { ep := &endpoint{ c: c, publicKey: n.Key, + publicKeyHex: n.Key.UntypedHexString(), sentPing: map[stun.TxID]sentPing{}, endpointState: map[netip.AddrPort]*endpointState{}, heartbeatDisabled: heartbeatDisabled, @@ -3312,9 +3313,10 @@ type endpoint struct { numStopAndResetAtomic int64 // These fields are initialized once and never modified. - c *Conn - publicKey key.NodePublic // peer public key (for WireGuard + DERP) - fakeWGAddr netip.AddrPort // the UDP address we tell wireguard-go we're using + c *Conn + publicKey key.NodePublic // peer public key (for WireGuard + DERP) + publicKeyHex string // cached output of publicKey.UntypedHexString + fakeWGAddr netip.AddrPort // the UDP address we tell wireguard-go we're using // mu protects all following fields. mu sync.Mutex // Lock ordering: Conn.mu, then endpoint.mu @@ -3496,7 +3498,7 @@ func (de *endpoint) String() string { func (de *endpoint) ClearSrc() {} func (de *endpoint) SrcToString() string { panic("unused") } // unused by wireguard-go func (de *endpoint) SrcIP() netip.Addr { panic("unused") } // unused by wireguard-go -func (de *endpoint) DstToString() string { return de.publicKey.UntypedHexString() } +func (de *endpoint) DstToString() string { return de.publicKeyHex } func (de *endpoint) DstIP() netip.Addr { panic("unused") } func (de *endpoint) DstToBytes() []byte { return packIPPort(de.fakeWGAddr) }