-
Couldn't load subscription status.
- Fork 474
Open
Description
Hello,
I am trying to implement a MaxConcurrentConnections for the ssh server.
I've notice the library already offers a ConnCallback and ConnectionFailedCallback.
However that seems not to be enough to create a guard around the number of maximum connection because we are missing the ConnectionClosedCallback.
With something like ConnectionClosedCallback I could simply implement my rate limiter by doing:
ssh.Server{
ConnCallback: func(ctx ssh.Context, conn net.Conn) net.Conn {
mux.Lock()
defer mux.Unlock()
if n > maxConnections {
conn.Close()
return conn
}
n ++
return conn
},
ConnectionFailedCallback: func(conn net.Conn, err error) {
mux.Lock()
defer mux.Unlock()
n--
},
ConnectionClosedCallback: func(){
mux.Lock()
defer mux.Unlock()
n--
}
}I'll put a PR up just to show you how I've tried it to implement the ConnectionClosedCallback, but I am of course open to suggestions!
Metadata
Metadata
Assignees
Labels
No labels