Original post

Hi, I’m trying to implement a SSH Tarpit. It’s a really simple SSH Server which just writes some data to the client every few seconds.

package main

import (
        "log"
        "net"
        "time"
)

const (
        ADDRESS = ":2222"
        DELAY   = time.Second * 3
)
func main() {
        log.Println("Starting")
        ll, err := net.Listen("tcp", ADDRESS)
        defer close(ll)
        if err != nil {
                log.Println("err in opening socket: ", err)
        }

        for {
                conn, err := ll.Accept()
                defer conn.Close()
                if err != nil {
                        log.Println("err in accepting socket: ", err)
                }
                 handle(conn)
        }
}
func close(ll net.Listener) {
        if err := ll.Close(); err != nil {
                log.Println("err in closing socket: ", err)
        }
}
func handle(conn net.Conn) {
        log.Println("conn from: ", conn.LocalAddr().String())
        for {
                conn.Write([]byte{'a'})
                time.Sleep(DELAY)
        }
}

I’m trying to figure out how memory grows as more clients connect to this. Is it possible to use the testing framework to view the memory of this application as the number of clients go?

The only way I can think of doing this is to create a separate application which just listens to a connection on a new goroutine and run a profiler on the server application.

Any help is appreciated 🙂