Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ConnectionClosedCallback #244

Open
SimoneDutto opened this issue Jan 17, 2025 · 0 comments
Open

Add ConnectionClosedCallback #244

SimoneDutto opened this issue Jan 17, 2025 · 0 comments

Comments

@SimoneDutto
Copy link

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!

@SimoneDutto SimoneDutto changed the title Add CloseConnectionCallBack Add ClosedConnectionCallBack Jan 17, 2025
@SimoneDutto SimoneDutto changed the title Add ClosedConnectionCallBack Add ClosedConnectionCallback Jan 17, 2025
@SimoneDutto SimoneDutto changed the title Add ClosedConnectionCallback Add ConnectionClosedCallback Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant