func (t *Tunnel) handlePublic(publicConn conn.Conn) { defer publicConn.Close() defer t.recoverPanic("Tunnel.handlePublic") publicConn.Info("New connection from %v", publicConn.RemoteAddr()) // connection hook if err := t.hooks.OnConnectionOpen(t, publicConn); err != nil { t.Error("OnConnectionOpen hook failed: %v", err) return } startTime := time.Now() // open a proxy stream proxyConn, err := t.sess.openProxy(publicConn.RemoteAddr().String(), t.url) if err != nil { t.Error("Failed to open proxy connection: %v", err) return } defer proxyConn.Close() // join the public and proxy connections bytesIn, bytesOut := conn.Join(publicConn, proxyConn) if err = t.hooks.OnConnectionClose(t, publicConn, time.Now().Sub(startTime), bytesIn, bytesOut); err != nil { t.Error("OnConnectionClose hook failed: %v", err) return } }