chage read method to io.copy

This commit is contained in:
xvzc 2022-05-08 16:55:13 +09:00
parent dd80adb448
commit 683eecc01d
2 changed files with 22 additions and 9 deletions

View File

@ -2,6 +2,7 @@ package net
import (
"errors"
"io"
"net"
"time"
@ -91,6 +92,7 @@ func (conn *Conn) ReadBytes() ([]byte, error) {
}
func (lConn *Conn) HandleHttp(p packet.HttpPacket) {
defer lConn.Close()
p.Tidy()
log.Debug("[HTTP] request: \n\n" + string(p.Raw()))
@ -104,8 +106,6 @@ func (lConn *Conn) HandleHttp(p packet.HttpPacket) {
lConn.Close()
return
}
log.Info(string(lConn.RemoteAddr().String()))
log.Debug("[DOH] Found ", ip, " with ", p.Domain())
@ -121,11 +121,13 @@ func (lConn *Conn) HandleHttp(p packet.HttpPacket) {
lConn.Close()
return
}
defer rConn.Close()
log.Debug("[HTTP] Connected to ", p.Domain())
go lConn.Serve(rConn, "[HTTP]", "localhost", p.Domain())
go rConn.Serve(lConn, "[HTTP]", p.Domain(), "localhost")
// 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 {
@ -136,9 +138,15 @@ func (lConn *Conn) HandleHttp(p packet.HttpPacket) {
}
log.Debug("[HTTP] Sent a request to ", p.Domain())
io.Copy(rConn, lConn)
log.Debug("[HTTP] Closing Connection..", p.Domain())
}
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())
@ -163,6 +171,7 @@ func (lConn *Conn) HandleHttps(p packet.HttpPacket) {
lConn.Close()
return
}
defer rConn.Close()
log.Debug("[HTTPS] Connected to ", p.Domain())
@ -188,8 +197,7 @@ 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 lConn.Serve(rConn, "[HTTPS]", "localhost", p.Domain())
go rConn.Serve(lConn, "[HTTPS]", p.Domain(), "localhost")
go io.Copy(lConn, rConn)
pkt := packet.NewHttpsPacket(clientHello)
@ -202,6 +210,12 @@ func (lConn *Conn) HandleHttps(p packet.HttpPacket) {
return
}
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")
}
func (from *Conn) Serve(to *Conn, proto string, fd string, td string) {

View File

@ -2,7 +2,6 @@ package proxy
import (
"os"
"time"
log "github.com/sirupsen/logrus"
"github.com/xvzc/SpoofDPI/net"
@ -44,8 +43,8 @@ func (p *Proxy) Start() {
log.Fatal("Error accepting connection: ", err)
continue
}
conn.SetDeadLine(time.Now().Add(3 * time.Second))
conn.SetKeepAlive(false)
// conn.SetDeadLine(time.Now().Add(3 * time.Second))
// conn.SetKeepAlive(false)
log.Debug("[PROXY] Accepted a new connection from ", conn.RemoteAddr())