Skip to content

Commit

Permalink
UDPMuxSink for UDPMux allows to inspect packets before being dropped
Browse files Browse the repository at this point in the history
  • Loading branch information
astroza committed Nov 26, 2024
1 parent 35bb3fb commit 589aef2
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions udp_mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ type UDPMux interface {
GetListenAddresses() []net.Addr
}

type UDPMuxSink interface {

Check failure on line 29 in udp_mux.go

View workflow job for this annotation

GitHub Actions / lint / Go

exported: exported type UDPMuxSink should have comment or be unexported (revive)
InspectDroppedPacket(data []byte, addr *net.UDPAddr)
}

// UDPMuxDefault is an implementation of the interface
type UDPMuxDefault struct {
params UDPMuxParams
Expand Down Expand Up @@ -58,6 +62,8 @@ type UDPMuxParams struct {
// in case a un UDPConn is passed which does not
// bind to a specific local address.
Net transport.Net
// Dropped packets are inspected by the Sink
Sink UDPMuxSink
}

// NewUDPMuxDefault creates an implementation of UDPMux
Expand Down Expand Up @@ -343,6 +349,10 @@ func (m *UDPMuxDefault) connWorker() {
}

if destinationConn == nil {
// If sink is enabled the packet is inspected before being dropped
if m.params.Sink != nil {
m.params.Sink.InspectDroppedPacket(buf[:n], netUDPAddr)
}

Check warning on line 355 in udp_mux.go

View check run for this annotation

Codecov / codecov/patch

udp_mux.go#L354-L355

Added lines #L354 - L355 were not covered by tests
m.params.Logger.Tracef("Dropping packet from %s, addr: %s", udpAddr.addr, addr)
continue
}
Expand Down

0 comments on commit 589aef2

Please sign in to comment.