Skip to content

Commit

Permalink
add handling when callback returns nil
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed Dec 10, 2024
1 parent 8115fe1 commit 56d0fbe
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions hopper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 56d0fbe

Please sign in to comment.