Configurable rate limiting for sshd

This commit is contained in:
Andrey Petrov 2015-01-16 12:35:57 -08:00
parent b99083ee6e
commit cc25d17bdc
2 changed files with 9 additions and 3 deletions

1
cmd.go
View File

@ -102,6 +102,7 @@ func main() {
os.Exit(4)
}
defer s.Close()
s.RateLimit = true
fmt.Printf("Listening for connections on %v\n", s.Addr().String())

View File

@ -11,7 +11,8 @@ import (
// Container for the connection and ssh-related configuration
type SSHListener struct {
net.Listener
config *ssh.ServerConfig
config *ssh.ServerConfig
RateLimit bool
}
// Make an SSH listener socket
@ -20,13 +21,17 @@ func ListenSSH(laddr string, config *ssh.ServerConfig) (*SSHListener, error) {
if err != nil {
return nil, err
}
l := SSHListener{socket, config}
l := SSHListener{Listener: socket, config: config}
return &l, nil
}
func (l *SSHListener) handleConn(conn net.Conn) (*Terminal, error) {
if l.RateLimit {
// TODO: Configurable Limiter?
conn = ReadLimitConn(conn, rateio.NewGracefulLimiter(1000, time.Minute*2, time.Second*3))
}
// Upgrade TCP connection to SSH connection
conn = ReadLimitConn(conn, rateio.NewGracefulLimiter(1000, time.Minute*2, time.Second*3))
sshConn, channels, requests, err := ssh.NewServerConn(conn, l.config)
if err != nil {
return nil, err