Skip to content

Commit c92d705

Browse files
committed
feat: add ConnectionCompleteCallback
Signed-off-by: Spike Curtis <spike@coder.com>
1 parent fc6e4b0 commit c92d705

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

server.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ type Server struct {
5151
ServerConfigCallback ServerConfigCallback // callback for configuring detailed SSH options
5252
SessionRequestCallback SessionRequestCallback // callback for allowing or denying SSH sessions
5353

54-
ConnectionFailedCallback ConnectionFailedCallback // callback to report connection failures
54+
// server calls Failed callback for connections that fail initial handshake, and Complete callback for those that
55+
// succeed, never both.
56+
ConnectionFailedCallback ConnectionFailedCallback // callback to report connection failures
57+
ConnectionCompleteCallback ConnectionCompleteCallback // callback to report connection completion
5558

5659
IdleTimeout time.Duration // connection timeout when no activity, none if empty
5760
MaxTimeout time.Duration // absolute connection timeout, none if empty
@@ -295,6 +298,11 @@ func (srv *Server) HandleConn(newConn net.Conn) {
295298
}
296299
return
297300
}
301+
if srv.ConnectionCompleteCallback != nil {
302+
defer func() {
303+
srv.ConnectionCompleteCallback(sshConn, sshConn.Wait())
304+
}()
305+
}
298306

299307
srv.trackConn(sshConn, true)
300308
defer srv.trackConn(sshConn, false)

ssh.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ type ServerConfigCallback func(ctx Context) *gossh.ServerConfig
7171
// Please note: the net.Conn is likely to be closed at this point
7272
type ConnectionFailedCallback func(conn net.Conn, err error)
7373

74+
// ConnectionCompleteCallback is a hook for reporting connections that
75+
// complete. The included error is from the underlying SSH transport
76+
// protocol mux (golang.org/x/crypto/ssh), and is non-nil, even for
77+
// normal termination.
78+
//
79+
// Please note: the ServerConn is closed at this point
80+
type ConnectionCompleteCallback func(conn *gossh.ServerConn, err error)
81+
7482
// Window represents the size of a PTY window.
7583
//
7684
// See https://datatracker.ietf.org/doc/html/rfc4254#section-6.2

0 commit comments

Comments
 (0)