@@ -47,11 +47,26 @@ type Server struct {
47
47
connWg sync.WaitGroup
48
48
doneChan chan struct {}
49
49
}
50
+
50
51
type RequestHandler interface {
51
- HandleRequest (ctx Context , srv * Server , req * gossh.Request ) (ok bool , payload []byte )
52
+ HandleSSHRequest (ctx Context , srv * Server , req * gossh.Request ) (ok bool , payload []byte )
53
+ }
54
+
55
+ type RequestHandlerFunc func (ctx Context , srv * Server , req * gossh.Request ) (ok bool , payload []byte )
56
+
57
+ func (f RequestHandlerFunc ) HandleSSHRequest (ctx Context , srv * Server , req * gossh.Request ) (ok bool , payload []byte ) {
58
+ return f (ctx , srv , req )
52
59
}
53
60
54
- type ChannelHandler func (srv * Server , conn * gossh.ServerConn , newChan gossh.NewChannel , ctx Context )
61
+ type ChannelHandler interface {
62
+ HandleSSHChannel (srv * Server , conn * gossh.ServerConn , newChan gossh.NewChannel , ctx Context )
63
+ }
64
+
65
+ type ChannelHandlerFunc func (srv * Server , conn * gossh.ServerConn , newChan gossh.NewChannel , ctx Context )
66
+
67
+ func (f ChannelHandlerFunc ) HandleSSHChannel (srv * Server , conn * gossh.ServerConn , newChan gossh.NewChannel , ctx Context ) {
68
+ f (srv , conn , newChan , ctx )
69
+ }
55
70
56
71
func (srv * Server ) ensureHostSigner () error {
57
72
if len (srv .HostSigners ) == 0 {
@@ -75,8 +90,8 @@ func (srv *Server) ensureHandlers() {
75
90
}
76
91
if srv .channelHandlers == nil {
77
92
srv .channelHandlers = map [string ]ChannelHandler {
78
- "session" : sessionHandler ,
79
- "direct-tcpip" : directTcpipHandler ,
93
+ "session" : ChannelHandlerFunc ( sessionHandler ) ,
94
+ "direct-tcpip" : ChannelHandlerFunc ( directTcpipHandler ) ,
80
95
}
81
96
}
82
97
}
@@ -274,7 +289,7 @@ func (srv *Server) handleConn(newConn net.Conn) {
274
289
ch .Reject (gossh .UnknownChannelType , "unsupported channel type" )
275
290
continue
276
291
}
277
- go handler (srv , sshConn , ch , ctx )
292
+ go handler . HandleSSHChannel (srv , sshConn , ch , ctx )
278
293
}
279
294
}
280
295
@@ -289,7 +304,7 @@ func (srv *Server) handleRequests(ctx Context, in <-chan *gossh.Request) {
289
304
}
290
305
/*reqCtx, cancel := context.WithCancel(ctx)
291
306
defer cancel() */
292
- ret , payload := handler .HandleRequest (ctx , srv , req )
307
+ ret , payload := handler .HandleSSHRequest (ctx , srv , req )
293
308
if req .WantReply {
294
309
req .Reply (ret , payload )
295
310
}
0 commit comments