Merge pull request #122 from Michael9127/pass-ConnCallback-context
Passes Context into ConnCallback
This commit is contained in:
commit
63518b5243
@ -95,7 +95,7 @@ func TestConnWrapping(t *testing.T) {
|
|||||||
HostKeyCallback: gossh.InsecureIgnoreHostKey(),
|
HostKeyCallback: gossh.InsecureIgnoreHostKey(),
|
||||||
}, PasswordAuth(func(ctx Context, password string) bool {
|
}, PasswordAuth(func(ctx Context, password string) bool {
|
||||||
return true
|
return true
|
||||||
}), WrapConn(func(conn net.Conn) net.Conn {
|
}), WrapConn(func(ctx Context, conn net.Conn) net.Conn {
|
||||||
wrapped = &wrappedConn{conn, 0}
|
wrapped = &wrappedConn{conn, 0}
|
||||||
return wrapped
|
return wrapped
|
||||||
}))
|
}))
|
||||||
|
@ -233,15 +233,15 @@ func (srv *Server) Serve(l net.Listener) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) HandleConn(newConn net.Conn) {
|
func (srv *Server) HandleConn(newConn net.Conn) {
|
||||||
|
ctx, cancel := newContext(srv)
|
||||||
if srv.ConnCallback != nil {
|
if srv.ConnCallback != nil {
|
||||||
cbConn := srv.ConnCallback(newConn)
|
cbConn := srv.ConnCallback(ctx, newConn)
|
||||||
if cbConn == nil {
|
if cbConn == nil {
|
||||||
newConn.Close()
|
newConn.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
newConn = cbConn
|
newConn = cbConn
|
||||||
}
|
}
|
||||||
ctx, cancel := newContext(srv)
|
|
||||||
conn := &serverConn{
|
conn := &serverConn{
|
||||||
Conn: newConn,
|
Conn: newConn,
|
||||||
idleTimeout: srv.IdleTimeout,
|
idleTimeout: srv.IdleTimeout,
|
||||||
|
2
ssh.go
2
ssh.go
@ -53,7 +53,7 @@ type SessionRequestCallback func(sess Session, requestType string) bool
|
|||||||
// ConnCallback is a hook for new connections before handling.
|
// ConnCallback is a hook for new connections before handling.
|
||||||
// It allows wrapping for timeouts and limiting by returning
|
// It allows wrapping for timeouts and limiting by returning
|
||||||
// the net.Conn that will be used as the underlying connection.
|
// the net.Conn that will be used as the underlying connection.
|
||||||
type ConnCallback func(conn net.Conn) net.Conn
|
type ConnCallback func(ctx Context, conn net.Conn) net.Conn
|
||||||
|
|
||||||
// LocalPortForwardingCallback is a hook for allowing port forwarding
|
// LocalPortForwardingCallback is a hook for allowing port forwarding
|
||||||
type LocalPortForwardingCallback func(ctx Context, destinationHost string, destinationPort uint32) bool
|
type LocalPortForwardingCallback func(ctx Context, destinationHost string, destinationPort uint32) bool
|
||||||
|
Loading…
Reference in New Issue
Block a user