Skip to content

Commit

Permalink
fix when callback returns nil
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed Dec 11, 2024
1 parent a491f7d commit bfcf1f1
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions hopper.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,20 +263,19 @@ func (l *Listener) switcher() {
continue RESULTS_LOOP
}

// onNextHopIn callback
// onNextHopIn callback post processing
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 RESULTS_LOOP
}
}

// re-encrypt data if crypterIn is set.
dataFromProxy = encryptPacket(l.crypterIn, dataFromProxy)
// forward the data to the client if not nil.
if dataFromProxy != nil {
// re-encrypt data if crypterIn is set.
dataFromProxy = encryptPacket(l.crypterIn, dataFromProxy)

// forward the data to client via the listener.
l.conn.WriteTo(dataFromProxy, res.Context.(net.Addr))
// forward the data to client via the listener.
l.conn.WriteTo(dataFromProxy, res.Context.(net.Addr))
}

// fire next read-request to the proxy connection.
l.watcher.ReadTimeout(res.Context, res.Conn, make([]byte, mtuLimit), time.Now().Add(l.timeout))
Expand Down

0 comments on commit bfcf1f1

Please sign in to comment.