Skip to content

Commit c39d84f

Browse files
committed
Address review comments.
1 parent a62e0b6 commit c39d84f

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

Diff for: service/udp.go

+18-18
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func (h *associationHandler) HandleAssociation(ctx context.Context, clientConn n
198198
if err != nil {
199199
return onet.NewConnectionError("ERR_CREATE_SOCKET", "Failed to create a `PacketConn`", err)
200200
}
201-
l = l.With(slog.Any("ltarget", targetConn.LocalAddr()))
201+
l = l.With(slog.Any("tgtListener", targetConn.LocalAddr()))
202202
go relayTargetToClient(targetConn, clientConn, cryptoKey, assocMetrics, l)
203203
} else {
204204
unpackStart := time.Now()
@@ -277,7 +277,7 @@ func PacketServe(clientConn net.PacketConn, assocHandle AssociationHandleFunc, m
277277
lazySlice.Release()
278278
}
279279
}()
280-
n, addr, err := clientConn.ReadFrom(buffer)
280+
n, clientAddr, err := clientConn.ReadFrom(buffer)
281281
if err != nil {
282282
lazySlice.Release()
283283
if errors.Is(err, net.ErrClosed) {
@@ -290,21 +290,21 @@ func PacketServe(clientConn net.PacketConn, assocHandle AssociationHandleFunc, m
290290
pkt := &packet{payload: buffer[:n], done: lazySlice.Release}
291291

292292
// TODO(#19): Include server address in the NAT key as well.
293-
assoc := nm.Get(addr.String())
293+
assoc := nm.Get(clientAddr.String())
294294
if assoc == nil {
295295
assoc = &association{
296-
pc: clientConn,
297-
raddr: addr,
298-
readCh: make(chan *packet, 5),
299-
doneCh: make(chan struct{}),
296+
pc: clientConn,
297+
clientAddr: clientAddr,
298+
readCh: make(chan *packet, 5),
299+
doneCh: make(chan struct{}),
300300
}
301301
if err != nil {
302302
slog.Error("Failed to handle association", slog.Any("err", err))
303303
return
304304
}
305305

306306
var existing bool
307-
assoc, existing = nm.Add(addr.String(), assoc)
307+
assoc, existing = nm.Add(clientAddr.String(), assoc)
308308
if !existing {
309309
metrics.AddNATEntry()
310310
go func() {
@@ -316,7 +316,7 @@ func PacketServe(clientConn net.PacketConn, assocHandle AssociationHandleFunc, m
316316
}
317317
select {
318318
case <-assoc.doneCh:
319-
nm.Del(addr.String())
319+
nm.Del(clientAddr.String())
320320
case assoc.readCh <- pkt:
321321
default:
322322
slog.Debug("Dropping packet due to full read queue")
@@ -340,10 +340,10 @@ type packet struct {
340340

341341
// association wraps a [net.PacketConn] with an address into a [net.Conn].
342342
type association struct {
343-
pc net.PacketConn
344-
raddr net.Addr
345-
readCh chan *packet
346-
doneCh chan struct{}
343+
pc net.PacketConn
344+
clientAddr net.Addr
345+
readCh chan *packet
346+
doneCh chan struct{}
347347
}
348348

349349
var _ net.Conn = (*association)(nil)
@@ -362,7 +362,7 @@ func (c *association) Read(p []byte) (int, error) {
362362
}
363363

364364
func (c *association) Write(b []byte) (n int, err error) {
365-
return c.pc.WriteTo(b, c.raddr)
365+
return c.pc.WriteTo(b, c.clientAddr)
366366
}
367367

368368
func (c *association) Close() error {
@@ -375,19 +375,19 @@ func (c *association) LocalAddr() net.Addr {
375375
}
376376

377377
func (c *association) RemoteAddr() net.Addr {
378-
return c.raddr
378+
return c.clientAddr
379379
}
380380

381381
func (c *association) SetDeadline(t time.Time) error {
382-
return c.pc.SetDeadline(t)
382+
return errors.ErrUnsupported
383383
}
384384

385385
func (c *association) SetReadDeadline(t time.Time) error {
386-
return c.pc.SetReadDeadline(t)
386+
return errors.ErrUnsupported
387387
}
388388

389389
func (c *association) SetWriteDeadline(t time.Time) error {
390-
return c.pc.SetWriteDeadline(t)
390+
return errors.ErrUnsupported
391391
}
392392

393393
func isDNS(addr net.Addr) bool {

0 commit comments

Comments
 (0)