Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean: remove unused sync.WaitGroup #222

Merged
merged 1 commit into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions service/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ func (h *packetHandler) SetTargetIPValidator(targetIPValidator onet.TargetIPVali
// Listen on addr for encrypted packets and basically do UDP NAT.
// We take the ciphers as a pointer because it gets replaced on config updates.
func (h *packetHandler) Handle(clientConn net.PacketConn) {
var running sync.WaitGroup

nm := newNATmap(h.natTimeout, h.m, &running, h.logger)
nm := newNATmap(h.natTimeout, h.m, h.logger)
defer nm.Close()
cipherBuf := make([]byte, serverUDPBufferSize)
textBuf := make([]byte, serverUDPBufferSize)
Expand Down Expand Up @@ -320,11 +318,10 @@ type natmap struct {
logger *slog.Logger
timeout time.Duration
metrics UDPMetrics
running *sync.WaitGroup
}

func newNATmap(timeout time.Duration, sm UDPMetrics, running *sync.WaitGroup, l *slog.Logger) *natmap {
m := &natmap{logger: l, metrics: sm, running: running}
func newNATmap(timeout time.Duration, sm UDPMetrics, l *slog.Logger) *natmap {
m := &natmap{logger: l, metrics: sm}
m.keyConn = make(map[string]*natconn)
m.timeout = timeout
return m
Expand Down Expand Up @@ -368,14 +365,12 @@ func (m *natmap) Add(clientAddr net.Addr, clientConn net.PacketConn, cryptoKey *
connMetrics := m.metrics.AddUDPNatEntry(clientAddr, keyID)
entry := m.set(clientAddr.String(), targetConn, cryptoKey, keyID, connMetrics)

m.running.Add(1)
go func() {
timedCopy(clientAddr, clientConn, entry, keyID, m.logger)
connMetrics.RemoveNatEntry()
if pc := m.del(clientAddr.String()); pc != nil {
pc.Close()
}
m.running.Done()
}()
return entry
}
Expand Down
5 changes: 2 additions & 3 deletions service/udp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"errors"
"net"
"net/netip"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -207,14 +206,14 @@ func assertAlmostEqual(t *testing.T, a, b time.Time) {
}

func TestNATEmpty(t *testing.T) {
nat := newNATmap(timeout, &natTestMetrics{}, &sync.WaitGroup{}, noopLogger())
nat := newNATmap(timeout, &natTestMetrics{}, noopLogger())
if nat.Get("foo") != nil {
t.Error("Expected nil value from empty NAT map")
}
}

func setupNAT() (*fakePacketConn, *fakePacketConn, *natconn) {
nat := newNATmap(timeout, &natTestMetrics{}, &sync.WaitGroup{}, noopLogger())
nat := newNATmap(timeout, &natTestMetrics{}, noopLogger())
clientConn := makePacketConn()
targetConn := makePacketConn()
nat.Add(&clientAddr, clientConn, natCryptoKey, targetConn, "key id")
Expand Down
Loading