From 9e31ce433749c117a326f293a12ed9a06435d889 Mon Sep 17 00:00:00 2001 From: xvzc Date: Sun, 8 May 2022 19:39:22 +0900 Subject: [PATCH] update error logging --- net/conn.go | 18 ++++-------------- proxy/proxy.go | 5 ++--- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/net/conn.go b/net/conn.go index 02c3d2d..cd53e1b 100644 --- a/net/conn.go +++ b/net/conn.go @@ -95,13 +95,9 @@ func (lConn *Conn) HandleHttp(p packet.HttpPacket) { defer lConn.Close() p.Tidy() - log.Debug("[HTTP] request: \n\n" + string(p.Raw())) - ip, err := doh.Lookup(p.Domain()) if err != nil { - // log.Error("[HTTP DOH] Error looking up for domain with ", p.Domain() , " ", err) - log.Error(lConn.RemoteAddr().String()) - // log.Error(string(p.Raw())) + log.Error("[HTTP DOH] Error looking up for domain with ", p.Domain() , " ", err) lConn.Write([]byte(p.Version() + " 502 Bad Gateway\r\n\r\n")) lConn.Close() return @@ -117,7 +113,7 @@ func (lConn *Conn) HandleHttp(p packet.HttpPacket) { rConn, err := Dial("tcp", ip + port) if err != nil { - log.Debug("[HTTPS] ", err) + log.Debug("[HTTP] ", err) lConn.Close() return } @@ -125,10 +121,6 @@ func (lConn *Conn) HandleHttp(p packet.HttpPacket) { log.Debug("[HTTP] Connected to ", p.Domain()) - // go lConn.Serve(rConn, "[HTTP]", "localhost", p.Domain()) - // go rConn.Serve(lConn, "[HTTP]", p.Domain(), "localhost") - go io.Copy(lConn, rConn) - _, err = rConn.Write(p.Raw()) if err != nil { log.Debug("[HTTP] Error sending request to ", p.Domain(), err) @@ -139,6 +131,7 @@ func (lConn *Conn) HandleHttp(p packet.HttpPacket) { log.Debug("[HTTP] Sent a request to ", p.Domain()) + go io.Copy(lConn, rConn) io.Copy(rConn, lConn) log.Debug("[HTTP] Closing Connection..", p.Domain()) @@ -147,7 +140,6 @@ func (lConn *Conn) HandleHttp(p packet.HttpPacket) { func (lConn *Conn) HandleHttps(p packet.HttpPacket) { defer lConn.Close() - log.Debug("[HTTPS] request: \n\n" + string(p.Raw())) ip, err := doh.Lookup(p.Domain()) if err != nil { @@ -197,7 +189,6 @@ func (lConn *Conn) HandleHttps(p packet.HttpPacket) { log.Debug("[HTTPS] Client sent hello ", len(clientHello), "bytes") // Generate a go routine that reads from the server - go io.Copy(lConn, rConn) pkt := packet.NewHttpsPacket(clientHello) @@ -210,11 +201,10 @@ func (lConn *Conn) HandleHttps(p packet.HttpPacket) { return } + go io.Copy(lConn, rConn) io.Copy(rConn, lConn) log.Debug("[HTTPS] Closing Connection..", p.Domain()) - // go lConn.Serve(rConn, "[HTTPS]", "localhost", p.Domain()) - // go rConn.Serve(lConn, "[HTTPS]", p.Domain(), "localhost") } diff --git a/proxy/proxy.go b/proxy/proxy.go index e16a369..97ce557 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -46,14 +46,13 @@ func (p *Proxy) Start() { // conn.SetDeadLine(time.Now().Add(3 * time.Second)) // conn.SetKeepAlive(false) - log.Debug("[PROXY] Accepted a new connection from ", conn.RemoteAddr()) - go func() { b, err := conn.ReadBytes() if err != nil { return } - // log.Debug("[PROXY] Client sent a request") + + log.Debug("[PROXY] Request from ", conn.RemoteAddr(), "\n\n", string(b)) pkt, err := packet.NewHttpPacket(b) if err != nil {