update error logging

This commit is contained in:
xvzc 2022-05-08 19:39:22 +09:00
parent 683eecc01d
commit 9e31ce4337
2 changed files with 6 additions and 17 deletions

View File

@ -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")
}

View File

@ -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 {