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

UDPMuxSink for UDPMux allows to inspect packets before being dropped #746

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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 @@
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 @@
// 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 @@
}

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
Loading