Skip to content

Commit 63518b5

Browse files
authored
Merge pull request gliderlabs#122 from Michael9127/pass-ConnCallback-context
Passes Context into ConnCallback
2 parents f6d256e + e9ac9d7 commit 63518b5

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

options_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func TestConnWrapping(t *testing.T) {
9595
HostKeyCallback: gossh.InsecureIgnoreHostKey(),
9696
}, PasswordAuth(func(ctx Context, password string) bool {
9797
return true
98-
}), WrapConn(func(conn net.Conn) net.Conn {
98+
}), WrapConn(func(ctx Context, conn net.Conn) net.Conn {
9999
wrapped = &wrappedConn{conn, 0}
100100
return wrapped
101101
}))

server.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,15 @@ func (srv *Server) Serve(l net.Listener) error {
233233
}
234234

235235
func (srv *Server) HandleConn(newConn net.Conn) {
236+
ctx, cancel := newContext(srv)
236237
if srv.ConnCallback != nil {
237-
cbConn := srv.ConnCallback(newConn)
238+
cbConn := srv.ConnCallback(ctx, newConn)
238239
if cbConn == nil {
239240
newConn.Close()
240241
return
241242
}
242243
newConn = cbConn
243244
}
244-
ctx, cancel := newContext(srv)
245245
conn := &serverConn{
246246
Conn: newConn,
247247
idleTimeout: srv.IdleTimeout,

ssh.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type SessionRequestCallback func(sess Session, requestType string) bool
5353
// ConnCallback is a hook for new connections before handling.
5454
// It allows wrapping for timeouts and limiting by returning
5555
// the net.Conn that will be used as the underlying connection.
56-
type ConnCallback func(conn net.Conn) net.Conn
56+
type ConnCallback func(ctx Context, conn net.Conn) net.Conn
5757

5858
// LocalPortForwardingCallback is a hook for allowing port forwarding
5959
type LocalPortForwardingCallback func(ctx Context, destinationHost string, destinationPort uint32) bool

0 commit comments

Comments
 (0)