gliderlabs / gliderlabs/ssh

Add ConnectionClosedCallback

Open
#244 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
4.2k
Forks
509
PR merge metrics
No merged PRs in 30d

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:
```go
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!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.