Skip to content

Commit 4204f8c

Browse files
authored
Merge pull request gliderlabs#143 from zeripath/connection-failed-callback
Add ConnectionFailedCallback to enable reporting of failed connection
2 parents 30ec06d + 98ce6bf commit 4204f8c

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

server.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ type Server struct {
4848
ServerConfigCallback ServerConfigCallback // callback for configuring detailed SSH options
4949
SessionRequestCallback SessionRequestCallback // callback for allowing or denying SSH sessions
5050

51+
ConnectionFailedCallback ConnectionFailedCallback // callback to report connection failures
52+
5153
IdleTimeout time.Duration // connection timeout when no activity, none if empty
5254
MaxTimeout time.Duration // absolute connection timeout, none if empty
5355

@@ -278,7 +280,9 @@ func (srv *Server) HandleConn(newConn net.Conn) {
278280
defer conn.Close()
279281
sshConn, chans, reqs, err := gossh.NewServerConn(conn, srv.config(ctx))
280282
if err != nil {
281-
// TODO: trigger event callback
283+
if srv.ConnectionFailedCallback != nil {
284+
srv.ConnectionFailedCallback(conn, err)
285+
}
282286
return
283287
}
284288

ssh.go

+4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ type ReversePortForwardingCallback func(ctx Context, bindHost string, bindPort u
6464
// ServerConfigCallback is a hook for creating custom default server configs
6565
type ServerConfigCallback func(ctx Context) *gossh.ServerConfig
6666

67+
// ConnectionFailedCallback is a hook for reporting failed connections
68+
// Please note: the net.Conn is likely to be closed at this point
69+
type ConnectionFailedCallback func(conn net.Conn, err error)
70+
6771
// Window represents the size of a PTY window.
6872
type Window struct {
6973
Width int

0 commit comments

Comments
 (0)