From 7ea772b0c58771b39d20af47a111da58a8fb3642 Mon Sep 17 00:00:00 2001 From: Daniel Mangum Date: Tue, 5 Sep 2023 07:50:53 -0400 Subject: [PATCH 1/2] Use atomic.Value to maintain Go 1.13 compatibility Updates to use atomic.Value in place of atomic.Bool such that older Go versions can continue to be supported. Signed-off-by: Daniel Mangum --- internal/net/udp/packet_conn.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/net/udp/packet_conn.go b/internal/net/udp/packet_conn.go index 7ddde13d3..58e685fd7 100644 --- a/internal/net/udp/packet_conn.go +++ b/internal/net/udp/packet_conn.go @@ -101,7 +101,7 @@ func (l *listener) Close() error { } // If we haven't already removed the remote address, remove it // from the connection map. - if !c.rmraddr.Load() { + if c.rmraddr.Load() == nil { delete(l.conns, c.raddr.String()) c.rmraddr.Store(true) } @@ -268,7 +268,7 @@ type PacketConn struct { listener *listener raddr net.Addr - rmraddr atomic.Bool + rmraddr atomic.Value // bool id atomic.Value buffer *idtlsnet.PacketBuffer @@ -327,7 +327,7 @@ func (c *PacketConn) WriteTo(p []byte, addr net.Addr) (n int, err error) { // resulting in the remote address entry being dropped prior to the // "real" client transitioning to sending using the alternate // identifier. - if id != nil && !c.rmraddr.Load() && addr.String() != c.raddr.String() { + if id != nil && c.rmraddr.Load() == nil && addr.String() != c.raddr.String() { c.listener.connLock.Lock() delete(c.listener.conns, c.raddr.String()) c.rmraddr.Store(true) @@ -357,7 +357,7 @@ func (c *PacketConn) Close() error { } // If we haven't already removed the remote address, remove it from the // connection map. - if !c.rmraddr.Load() { + if c.rmraddr.Load() == nil { delete(c.listener.conns, c.raddr.String()) c.rmraddr.Store(true) } From ebe2dc6fa63de5701073f53b6cf992efe3ea440e Mon Sep 17 00:00:00 2001 From: Daniel Mangum Date: Tue, 5 Sep 2023 07:52:23 -0400 Subject: [PATCH 2/2] Specifying underlying type of conn ID atomic.Value Adds comment to indicate that conn ID should always be a string. Signed-off-by: Daniel Mangum --- internal/net/udp/packet_conn.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/net/udp/packet_conn.go b/internal/net/udp/packet_conn.go index 58e685fd7..7dafbe23e 100644 --- a/internal/net/udp/packet_conn.go +++ b/internal/net/udp/packet_conn.go @@ -269,7 +269,7 @@ type PacketConn struct { raddr net.Addr rmraddr atomic.Value // bool - id atomic.Value + id atomic.Value // string buffer *idtlsnet.PacketBuffer