Skip to content

Commit

Permalink
fix write ctx
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed Dec 10, 2024
1 parent f0b0d92 commit df0364f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions hopper.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,9 @@ func (l *Listener) clientIn(data []byte, raddr net.Addr) {
conn, ok := l.incomingConnections[raddr.String()]
l.incomingConnectionsLock.Unlock()

ctx := raddr
if ok { // existing connection
l.watcher.WriteTimeout(nil, conn, data, time.Now().Add(l.timeout))
l.watcher.WriteTimeout(ctx, conn, data, time.Now().Add(l.timeout))
} else { // new connection
// pick random next hop
nextHop := l.nextHops[mrand.Intn(len(l.nextHops))]
Expand All @@ -219,7 +220,6 @@ func (l *Listener) clientIn(data []byte, raddr net.Addr) {

// watch the connection
// the context is the address of incoming packet
ctx := raddr
l.watcher.ReadTimeout(ctx, conn, make([]byte, mtuLimit), time.Now().Add(l.timeout))
l.watcher.WriteTimeout(ctx, conn, data, time.Now().Add(l.timeout))
}
Expand Down

0 comments on commit df0364f

Please sign in to comment.