@@ -15,6 +15,16 @@ import (
1515// and ListenAndServeTLS methods after a call to Shutdown or Close.
1616var ErrServerClosed = errors .New ("ssh: Server closed" )
1717
18+ type RequestHandler func (ctx Context , srv * Server , req * gossh.Request ) (ok bool , payload []byte )
19+
20+ var DefaultRequestHandlers = map [string ]RequestHandler {}
21+
22+ type ChannelHandler func (srv * Server , conn * gossh.ServerConn , newChan gossh.NewChannel , ctx Context )
23+
24+ var DefaultChannelHandlers = map [string ]ChannelHandler {
25+ "session" : DefaultSessionHandler ,
26+ }
27+
1828// Server defines parameters for running an SSH server. The zero value for
1929// Server is a valid configuration. When both PasswordHandler and
2030// PublicKeyHandler are nil, no client authentication is performed.
@@ -55,32 +65,6 @@ type Server struct {
5565 doneChan chan struct {}
5666}
5767
58- type RequestHandler interface {
59- HandleSSHRequest (ctx Context , srv * Server , req * gossh.Request ) (ok bool , payload []byte )
60- }
61-
62- type RequestHandlerFunc func (ctx Context , srv * Server , req * gossh.Request ) (ok bool , payload []byte )
63-
64- func (f RequestHandlerFunc ) HandleSSHRequest (ctx Context , srv * Server , req * gossh.Request ) (ok bool , payload []byte ) {
65- return f (ctx , srv , req )
66- }
67-
68- var DefaultRequestHandlers = map [string ]RequestHandler {}
69-
70- type ChannelHandler interface {
71- HandleSSHChannel (srv * Server , conn * gossh.ServerConn , newChan gossh.NewChannel , ctx Context )
72- }
73-
74- type ChannelHandlerFunc func (srv * Server , conn * gossh.ServerConn , newChan gossh.NewChannel , ctx Context )
75-
76- func (f ChannelHandlerFunc ) HandleSSHChannel (srv * Server , conn * gossh.ServerConn , newChan gossh.NewChannel , ctx Context ) {
77- f (srv , conn , newChan , ctx )
78- }
79-
80- var DefaultChannelHandlers = map [string ]ChannelHandler {
81- "session" : ChannelHandlerFunc (DefaultSessionHandler ),
82- }
83-
8468func (srv * Server ) ensureHostSigner () error {
8569 if len (srv .HostSigners ) == 0 {
8670 signer , err := generateSigner ()
@@ -288,7 +272,7 @@ func (srv *Server) handleConn(newConn net.Conn) {
288272 ch .Reject (gossh .UnknownChannelType , "unsupported channel type" )
289273 continue
290274 }
291- go handler . HandleSSHChannel (srv , sshConn , ch , ctx )
275+ go handler (srv , sshConn , ch , ctx )
292276 }
293277}
294278
@@ -304,7 +288,7 @@ func (srv *Server) handleRequests(ctx Context, in <-chan *gossh.Request) {
304288 }
305289 /*reqCtx, cancel := context.WithCancel(ctx)
306290 defer cancel() */
307- ret , payload := handler . HandleSSHRequest (ctx , srv , req )
291+ ret , payload := handler (ctx , srv , req )
308292 req .Reply (ret , payload )
309293 }
310294}
0 commit comments