mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2024-12-22 14:26:31 +00:00
chage read method to io.copy
This commit is contained in:
parent
dd80adb448
commit
683eecc01d
26
net/conn.go
26
net/conn.go
@ -2,6 +2,7 @@ package net
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -91,6 +92,7 @@ func (conn *Conn) ReadBytes() ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (lConn *Conn) HandleHttp(p packet.HttpPacket) {
|
func (lConn *Conn) HandleHttp(p packet.HttpPacket) {
|
||||||
|
defer lConn.Close()
|
||||||
p.Tidy()
|
p.Tidy()
|
||||||
|
|
||||||
log.Debug("[HTTP] request: \n\n" + string(p.Raw()))
|
log.Debug("[HTTP] request: \n\n" + string(p.Raw()))
|
||||||
@ -104,8 +106,6 @@ func (lConn *Conn) HandleHttp(p packet.HttpPacket) {
|
|||||||
lConn.Close()
|
lConn.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Info(string(lConn.RemoteAddr().String()))
|
|
||||||
|
|
||||||
|
|
||||||
log.Debug("[DOH] Found ", ip, " with ", p.Domain())
|
log.Debug("[DOH] Found ", ip, " with ", p.Domain())
|
||||||
|
|
||||||
@ -121,11 +121,13 @@ func (lConn *Conn) HandleHttp(p packet.HttpPacket) {
|
|||||||
lConn.Close()
|
lConn.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer rConn.Close()
|
||||||
|
|
||||||
log.Debug("[HTTP] Connected to ", p.Domain())
|
log.Debug("[HTTP] Connected to ", p.Domain())
|
||||||
|
|
||||||
go lConn.Serve(rConn, "[HTTP]", "localhost", p.Domain())
|
// go lConn.Serve(rConn, "[HTTP]", "localhost", p.Domain())
|
||||||
go rConn.Serve(lConn, "[HTTP]", p.Domain(), "localhost")
|
// go rConn.Serve(lConn, "[HTTP]", p.Domain(), "localhost")
|
||||||
|
go io.Copy(lConn, rConn)
|
||||||
|
|
||||||
_, err = rConn.Write(p.Raw())
|
_, err = rConn.Write(p.Raw())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -136,9 +138,15 @@ func (lConn *Conn) HandleHttp(p packet.HttpPacket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Debug("[HTTP] Sent a request to ", p.Domain())
|
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) {
|
func (lConn *Conn) HandleHttps(p packet.HttpPacket) {
|
||||||
|
defer lConn.Close()
|
||||||
log.Debug("[HTTPS] request: \n\n" + string(p.Raw()))
|
log.Debug("[HTTPS] request: \n\n" + string(p.Raw()))
|
||||||
|
|
||||||
ip, err := doh.Lookup(p.Domain())
|
ip, err := doh.Lookup(p.Domain())
|
||||||
@ -163,6 +171,7 @@ func (lConn *Conn) HandleHttps(p packet.HttpPacket) {
|
|||||||
lConn.Close()
|
lConn.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer rConn.Close()
|
||||||
|
|
||||||
log.Debug("[HTTPS] Connected to ", p.Domain())
|
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")
|
log.Debug("[HTTPS] Client sent hello ", len(clientHello), "bytes")
|
||||||
|
|
||||||
// Generate a go routine that reads from the server
|
// Generate a go routine that reads from the server
|
||||||
go lConn.Serve(rConn, "[HTTPS]", "localhost", p.Domain())
|
go io.Copy(lConn, rConn)
|
||||||
go rConn.Serve(lConn, "[HTTPS]", p.Domain(), "localhost")
|
|
||||||
|
|
||||||
pkt := packet.NewHttpsPacket(clientHello)
|
pkt := packet.NewHttpsPacket(clientHello)
|
||||||
|
|
||||||
@ -202,6 +210,12 @@ func (lConn *Conn) HandleHttps(p packet.HttpPacket) {
|
|||||||
return
|
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) {
|
func (from *Conn) Serve(to *Conn, proto string, fd string, td string) {
|
||||||
|
@ -2,7 +2,6 @@ package proxy
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"time"
|
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/xvzc/SpoofDPI/net"
|
"github.com/xvzc/SpoofDPI/net"
|
||||||
@ -44,8 +43,8 @@ func (p *Proxy) Start() {
|
|||||||
log.Fatal("Error accepting connection: ", err)
|
log.Fatal("Error accepting connection: ", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
conn.SetDeadLine(time.Now().Add(3 * time.Second))
|
// conn.SetDeadLine(time.Now().Add(3 * time.Second))
|
||||||
conn.SetKeepAlive(false)
|
// conn.SetKeepAlive(false)
|
||||||
|
|
||||||
log.Debug("[PROXY] Accepted a new connection from ", conn.RemoteAddr())
|
log.Debug("[PROXY] Accepted a new connection from ", conn.RemoteAddr())
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user