From 56d0fbe2e5749181a94b8a5d7031c24d3e662ed1 Mon Sep 17 00:00:00 2001 From: xtaci Date: Tue, 10 Dec 2024 14:56:52 +0800 Subject: [PATCH] add handling when callback returns nil --- hopper.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hopper.go b/hopper.go index 05a1099..2e9a715 100644 --- a/hopper.go +++ b/hopper.go @@ -178,6 +178,10 @@ func (l *Listener) clientIn(data []byte, raddr net.Addr) { // onClientIn callback if l.onClientIn != nil { data = l.onClientIn(raddr, data) + // blackhole the packet if the callback returns nil + if data == nil { + return + } } // encrypt or re-encrypt the packet if crypterOut is set(with new nonce) @@ -252,6 +256,10 @@ func (l *Listener) switcher() { // onNextHopIn callback if l.onNextHopIn != nil { dataFromProxy = l.onNextHopIn(res.Conn.RemoteAddr(), res.Context.(net.Addr), dataFromProxy) + // blackhole the packet if the callback returns nil. + if dataFromProxy == nil { + continue + } } // re-encrypt data if crypterIn is set.