Skip to content

Commit 23050ef

Browse files
committed
Remove the Metrics() method.
1 parent 1dbfa99 commit 23050ef

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

service/udp.go

+13-17
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (h *packetHandler) authenticate(pkt []byte, assoc PacketAssociation) ([]byt
142142
textLazySlice.Release()
143143
h.ssm.AddCipherSearch(keyErr == nil, timeToCipher)
144144

145-
assoc.Metrics().AddAuthentication(keyID)
145+
assoc.AddAuthentication(keyID)
146146
if keyErr != nil {
147147
return nil, keyErr
148148
}
@@ -205,7 +205,7 @@ func (h *packetHandler) Handle(pkt []byte, assoc PacketAssociation, lazySlice sl
205205
debugUDP(l, "Error", slog.String("msg", connError.Message), slog.Any("cause", connError.Cause))
206206
status = connError.Status
207207
}
208-
assoc.Metrics().AddPacketFromClient(status, int64(len(pkt)), int64(proxyTargetBytes))
208+
assoc.AddPacketFromClient(status, int64(len(pkt)), int64(proxyTargetBytes))
209209
}
210210

211211
// Given the decrypted contents of a UDP packet, return
@@ -298,7 +298,7 @@ func (h *packetHandler) handleTarget(pkt []byte, assoc PacketAssociation, crypto
298298
if expired {
299299
return errors.New("target connection has expired")
300300
}
301-
assoc.Metrics().AddPacketFromTarget(status, int64(bodyLen), int64(proxyClientBytes))
301+
assoc.AddPacketFromTarget(status, int64(bodyLen), int64(proxyClientBytes))
302302
return nil
303303
}
304304

@@ -542,6 +542,9 @@ func HandleAssociationTimedCopy(assoc PacketAssociation, handle PacketHandleFunc
542542

543543
// PacketAssociation represents a UDP association.
544544
type PacketAssociation interface {
545+
// TODO(sbruens): Decouple the metrics from the association.
546+
UDPAssociationMetrics
547+
545548
// ReadFromClient reads data from the client side of the association.
546549
ReadFromClient(b []byte) (n int, err error)
547550

@@ -568,10 +571,6 @@ type PacketAssociation interface {
568571

569572
// Closes the target side of the association.
570573
CloseTarget() error
571-
572-
// Returns association metrics.
573-
// TODO(sbruens): Refactor so this isn't needed.
574-
Metrics() UDPAssociationMetrics
575574
}
576575

577576
type association struct {
@@ -581,11 +580,12 @@ type association struct {
581580
once sync.Once
582581
cachedResult any
583582

584-
m UDPAssociationMetrics
583+
UDPAssociationMetrics
585584
doneCh chan struct{}
586585
}
587586

588587
var _ PacketAssociation = (*association)(nil)
588+
var _ UDPAssociationMetrics = (*association)(nil)
589589
var _ slog.LogValuer = (*association)(nil)
590590

591591
// NewPacketAssociation creates a new packet-based association.
@@ -600,10 +600,10 @@ func NewPacketAssociation(conn net.Conn, listener transport.PacketListener, m UD
600600
}
601601

602602
return &association{
603-
clientConn: conn,
604-
targetConn: targetConn,
605-
m: m,
606-
doneCh: make(chan struct{}),
603+
clientConn: conn,
604+
targetConn: targetConn,
605+
UDPAssociationMetrics: m,
606+
doneCh: make(chan struct{}),
607607
}, nil
608608
}
609609

@@ -648,7 +648,7 @@ func (a *association) Close() error {
648648
}
649649

650650
func (a *association) CloseTarget() error {
651-
a.m.AddClose()
651+
a.UDPAssociationMetrics.AddClose()
652652
err := a.targetConn.Close()
653653
if err != nil {
654654
return err
@@ -657,10 +657,6 @@ func (a *association) CloseTarget() error {
657657
return nil
658658
}
659659

660-
func (a *association) Metrics() UDPAssociationMetrics {
661-
return a.m
662-
}
663-
664660
func (a *association) LogValue() slog.Value {
665661
return slog.GroupValue(
666662
slog.Any("client", a.clientConn.RemoteAddr()),

0 commit comments

Comments
 (0)