diff --git a/proxy/stratum.go b/proxy/stratum.go index 6ea714a..af14b15 100644 --- a/proxy/stratum.go +++ b/proxy/stratum.go @@ -76,16 +76,26 @@ func (s *ProxyServer) ListenTCP() { accept <- n go func(cs *Session) { - err = s.handleTCPClient(cs) - if err != nil { - s.removeSession(cs) - conn.Close() - } + s.logConnectionTime(cs) <-accept }(cs) } } +func (s *ProxyServer) logConnectionTime(cs *Session) { + start := time.Now() + defer func() { + duration := time.Since(start) + log.Printf("Connection time for %s: %s", cs.ip, duration) + }() + err := s.handleTCPClient(cs) + if err != nil { + log.Printf("Error handling TCP client %s: %v", cs.ip, err) + s.removeSession(cs) + cs.conn.Close() + } +} + func (s *ProxyServer) handleTCPClient(cs *Session) error { cs.enc = json.NewEncoder(cs.conn) connbuff := bufio.NewReaderSize(cs.conn, MaxReqSize)