Skip to content

Commit bfcf1f1

Browse files
committed
fix when callback returns nil
1 parent a491f7d commit bfcf1f1

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

hopper.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,20 +263,19 @@ func (l *Listener) switcher() {
263263
continue RESULTS_LOOP
264264
}
265265

266-
// onNextHopIn callback
266+
// onNextHopIn callback post processing
267267
if l.onNextHopIn != nil {
268268
dataFromProxy = l.onNextHopIn(res.Conn.RemoteAddr(), res.Context.(net.Addr), dataFromProxy)
269-
// blackhole the packet if the callback returns nil.
270-
if dataFromProxy == nil {
271-
continue RESULTS_LOOP
272-
}
273269
}
274270

275-
// re-encrypt data if crypterIn is set.
276-
dataFromProxy = encryptPacket(l.crypterIn, dataFromProxy)
271+
// forward the data to the client if not nil.
272+
if dataFromProxy != nil {
273+
// re-encrypt data if crypterIn is set.
274+
dataFromProxy = encryptPacket(l.crypterIn, dataFromProxy)
277275

278-
// forward the data to client via the listener.
279-
l.conn.WriteTo(dataFromProxy, res.Context.(net.Addr))
276+
// forward the data to client via the listener.
277+
l.conn.WriteTo(dataFromProxy, res.Context.(net.Addr))
278+
}
280279

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

0 commit comments

Comments
 (0)