aboutsummaryrefslogtreecommitdiff
path: root/handle.go
diff options
context:
space:
mode:
Diffstat (limited to 'handle.go')
-rw-r--r--handle.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/handle.go b/handle.go
new file mode 100644
index 0000000..622b68e
--- /dev/null
+++ b/handle.go
@@ -0,0 +1,31 @@
+package main
+
+import (
+ "fmt"
+ "net"
+ "time"
+)
+
+type protoHandler func(net.Conn)
+
+func protocolHandler(proto string) (protoHandler, error) {
+ switch proto {
+ case "ssh":
+ return sshHandler, nil
+ default:
+ return nil, fmt.Errorf("unknown protocol '%s'", proto)
+ }
+}
+
+func logConn(conn net.Conn, msg string) {
+ now := time.Now().UTC()
+ fmt.Printf("%s, %s, %s\n", now.String(), conn.RemoteAddr().String(), msg)
+}
+
+func connHandler(handler protoHandler, conn net.Conn) {
+ defer conn.Close()
+
+ logConn(conn, "handling")
+ handler(conn)
+ logConn(conn, "closing")
+}