@@ -142,7 +142,7 @@ func (h *packetHandler) authenticate(pkt []byte, assoc PacketAssociation) ([]byt
142
142
textLazySlice .Release ()
143
143
h .ssm .AddCipherSearch (keyErr == nil , timeToCipher )
144
144
145
- assoc .Metrics (). AddAuthentication (keyID )
145
+ assoc .AddAuthentication (keyID )
146
146
if keyErr != nil {
147
147
return nil , keyErr
148
148
}
@@ -205,7 +205,7 @@ func (h *packetHandler) Handle(pkt []byte, assoc PacketAssociation, lazySlice sl
205
205
debugUDP (l , "Error" , slog .String ("msg" , connError .Message ), slog .Any ("cause" , connError .Cause ))
206
206
status = connError .Status
207
207
}
208
- assoc .Metrics (). AddPacketFromClient (status , int64 (len (pkt )), int64 (proxyTargetBytes ))
208
+ assoc .AddPacketFromClient (status , int64 (len (pkt )), int64 (proxyTargetBytes ))
209
209
}
210
210
211
211
// Given the decrypted contents of a UDP packet, return
@@ -298,7 +298,7 @@ func (h *packetHandler) handleTarget(pkt []byte, assoc PacketAssociation, crypto
298
298
if expired {
299
299
return errors .New ("target connection has expired" )
300
300
}
301
- assoc .Metrics (). AddPacketFromTarget (status , int64 (bodyLen ), int64 (proxyClientBytes ))
301
+ assoc .AddPacketFromTarget (status , int64 (bodyLen ), int64 (proxyClientBytes ))
302
302
return nil
303
303
}
304
304
@@ -542,6 +542,9 @@ func HandleAssociationTimedCopy(assoc PacketAssociation, handle PacketHandleFunc
542
542
543
543
// PacketAssociation represents a UDP association.
544
544
type PacketAssociation interface {
545
+ // TODO(sbruens): Decouple the metrics from the association.
546
+ UDPAssociationMetrics
547
+
545
548
// ReadFromClient reads data from the client side of the association.
546
549
ReadFromClient (b []byte ) (n int , err error )
547
550
@@ -568,10 +571,6 @@ type PacketAssociation interface {
568
571
569
572
// Closes the target side of the association.
570
573
CloseTarget () error
571
-
572
- // Returns association metrics.
573
- // TODO(sbruens): Refactor so this isn't needed.
574
- Metrics () UDPAssociationMetrics
575
574
}
576
575
577
576
type association struct {
@@ -581,11 +580,12 @@ type association struct {
581
580
once sync.Once
582
581
cachedResult any
583
582
584
- m UDPAssociationMetrics
583
+ UDPAssociationMetrics
585
584
doneCh chan struct {}
586
585
}
587
586
588
587
var _ PacketAssociation = (* association )(nil )
588
+ var _ UDPAssociationMetrics = (* association )(nil )
589
589
var _ slog.LogValuer = (* association )(nil )
590
590
591
591
// NewPacketAssociation creates a new packet-based association.
@@ -600,10 +600,10 @@ func NewPacketAssociation(conn net.Conn, listener transport.PacketListener, m UD
600
600
}
601
601
602
602
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 {}),
607
607
}, nil
608
608
}
609
609
@@ -648,7 +648,7 @@ func (a *association) Close() error {
648
648
}
649
649
650
650
func (a * association ) CloseTarget () error {
651
- a .m .AddClose ()
651
+ a .UDPAssociationMetrics .AddClose ()
652
652
err := a .targetConn .Close ()
653
653
if err != nil {
654
654
return err
@@ -657,10 +657,6 @@ func (a *association) CloseTarget() error {
657
657
return nil
658
658
}
659
659
660
- func (a * association ) Metrics () UDPAssociationMetrics {
661
- return a .m
662
- }
663
-
664
660
func (a * association ) LogValue () slog.Value {
665
661
return slog .GroupValue (
666
662
slog .Any ("client" , a .clientConn .RemoteAddr ()),
0 commit comments