Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type Server struct {
SessionRequestCallback SessionRequestCallback // callback for allowing or denying SSH sessions

ConnectionFailedCallback ConnectionFailedCallback // callback to report connection failures
ConnectionCloseCallback ConnectionCloseCallback // callback to report connection close

HandshakeTimeout time.Duration // connection timeout until successful handshake, none if empty
IdleTimeout time.Duration // connection timeout when no activity, none if empty
Expand Down Expand Up @@ -296,6 +297,12 @@ func (srv *Server) HandleConn(newConn net.Conn) {
}
conn.updateDeadline()
defer conn.Close()
defer func() {
if srv.ConnectionCloseCallback != nil {
srv.ConnectionCloseCallback(conn)
}
}()

sshConn, chans, reqs, err := gossh.NewServerConn(conn, srv.config(ctx))
if err != nil {
if srv.ConnectionFailedCallback != nil {
Expand Down
3 changes: 3 additions & 0 deletions ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ type ServerConfigCallback func(ctx Context) *gossh.ServerConfig
// Please note: the net.Conn is likely to be closed at this point
type ConnectionFailedCallback func(conn net.Conn, err error)

// ConnectionCloseCallback is a hook for reporting closed connections
type ConnectionCloseCallback func(conn net.Conn)

// Window represents the size of a PTY window.
type Window struct {
Width int
Expand Down