mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2025-01-10 16:18:34 +00:00
refactor
This commit is contained in:
parent
6a9bc1616d
commit
8893af16d3
62
net/conn.go
62
net/conn.go
@ -92,14 +92,17 @@ func (conn *Conn) ReadBytes() ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (lConn *Conn) HandleHttp(p *packet.HttpPacket) {
|
func (lConn *Conn) HandleHttp(p *packet.HttpPacket) {
|
||||||
defer lConn.Close()
|
defer func() {
|
||||||
|
lConn.Close()
|
||||||
|
log.Debug("[HTTP] Closing client Connection.. ", lConn.RemoteAddr())
|
||||||
|
}()
|
||||||
|
|
||||||
p.Tidy()
|
p.Tidy()
|
||||||
|
|
||||||
ip, err := doh.Lookup(p.Domain())
|
ip, err := doh.Lookup(p.Domain())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("[HTTP DOH] Error looking up for domain with ", p.Domain() , " ", err)
|
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.Write([]byte(p.Version() + " 502 Bad Gateway\r\n\r\n"))
|
||||||
lConn.Close()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,18 +117,18 @@ func (lConn *Conn) HandleHttp(p *packet.HttpPacket) {
|
|||||||
rConn, err := Dial("tcp", ip + port)
|
rConn, err := Dial("tcp", ip + port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("[HTTP] ", err)
|
log.Debug("[HTTP] ", err)
|
||||||
lConn.Close()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer rConn.Close()
|
defer func() {
|
||||||
|
defer rConn.Close()
|
||||||
|
log.Debug("[HTTP] Closing server Connection.. ", p.Domain(), " ", rConn.LocalAddr())
|
||||||
|
}()
|
||||||
|
|
||||||
log.Debug("[HTTP] Connected to ", p.Domain())
|
log.Debug("[HTTP] New connection to the server ", p.Domain(), " ", rConn.LocalAddr())
|
||||||
|
|
||||||
_, err = rConn.Write(p.Raw())
|
_, err = rConn.Write(p.Raw())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("[HTTP] Error sending request to ", p.Domain(), err)
|
log.Debug("[HTTP] Error sending request to ", p.Domain(), err)
|
||||||
lConn.Close()
|
|
||||||
rConn.Close()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,18 +137,18 @@ func (lConn *Conn) HandleHttp(p *packet.HttpPacket) {
|
|||||||
go io.Copy(lConn, rConn)
|
go io.Copy(lConn, rConn)
|
||||||
io.Copy(rConn, lConn)
|
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()
|
defer func() {
|
||||||
|
lConn.Close()
|
||||||
|
log.Debug("[HTTPS] Closing client Connection.. ", lConn.RemoteAddr())
|
||||||
|
}()
|
||||||
|
|
||||||
ip, err := doh.Lookup(p.Domain())
|
ip, err := doh.Lookup(p.Domain())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("[HTTPS DOH] Error looking up for domain: ", p.Domain(), " ", err)
|
log.Error("[HTTPS DOH] Error looking up for domain: ", p.Domain(), " ", err)
|
||||||
lConn.Write([]byte(p.Version() + " 502 Bad Gateway\r\n\r\n"))
|
lConn.Write([]byte(p.Version() + " 502 Bad Gateway\r\n\r\n"))
|
||||||
lConn.Close()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,18 +163,18 @@ func (lConn *Conn) HandleHttps(p *packet.HttpPacket) {
|
|||||||
rConn, err := Dial("tcp", ip + port)
|
rConn, err := Dial("tcp", ip + port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("[HTTPS] ", err)
|
log.Debug("[HTTPS] ", err)
|
||||||
lConn.Close()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer rConn.Close()
|
defer func() {
|
||||||
|
defer rConn.Close()
|
||||||
|
log.Debug("[HTTPS] Closing server Connection.. ", p.Domain(), " ", rConn.LocalAddr())
|
||||||
|
}()
|
||||||
|
|
||||||
log.Debug("[HTTPS] Connected to ", p.Domain())
|
log.Debug("[HTTPS] New connection to the server ", p.Domain(), " ", rConn.LocalAddr())
|
||||||
|
|
||||||
_, err = lConn.Write([]byte(p.Version() + " 200 Connection Established\r\n\r\n"))
|
_, err = lConn.Write([]byte(p.Version() + " 200 Connection Established\r\n\r\n"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("[HTTPS] Error sending 200 Connection Established to the client", err)
|
log.Debug("[HTTPS] Error sending 200 Connection Established to the client", err)
|
||||||
lConn.Close()
|
|
||||||
rConn.Close()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Debug("[HTTPS] Sent 200 Connection Estabalished to the client")
|
log.Debug("[HTTPS] Sent 200 Connection Estabalished to the client")
|
||||||
@ -180,9 +183,6 @@ func (lConn *Conn) HandleHttps(p *packet.HttpPacket) {
|
|||||||
clientHello, err := lConn.ReadBytes()
|
clientHello, err := lConn.ReadBytes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("[HTTPS] Error reading client hello from the client", err)
|
log.Debug("[HTTPS] Error reading client hello from the client", err)
|
||||||
log.Debug("[HTTPS] Closing local connection..")
|
|
||||||
lConn.Close()
|
|
||||||
rConn.Close()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,36 +196,32 @@ func (lConn *Conn) HandleHttps(p *packet.HttpPacket) {
|
|||||||
|
|
||||||
if _, err := rConn.WriteChunks(chunks); err != nil {
|
if _, err := rConn.WriteChunks(chunks); err != nil {
|
||||||
log.Debug("[HTTPS] Error writing client hello to ", p.Domain(), err)
|
log.Debug("[HTTPS] Error writing client hello to ", p.Domain(), err)
|
||||||
lConn.Close()
|
|
||||||
rConn.Close()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
go io.Copy(lConn, rConn)
|
// go io.Copy(lConn, rConn)
|
||||||
io.Copy(rConn, lConn)
|
// io.Copy(rConn, lConn)
|
||||||
|
go lConn.Serve(rConn, "[HTTPS]", "client", p.Domain())
|
||||||
log.Debug("[HTTPS] Closing Connection..", p.Domain())
|
rConn.Serve(lConn, "[HTTPS]", p.Domain(), "client")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (from *Conn) Serve(to *Conn, proto string, fd string, td string) {
|
func (from *Conn) Serve(to *Conn, proto string, fd string, td string) {
|
||||||
defer from.Close()
|
|
||||||
defer to.Close()
|
|
||||||
|
|
||||||
proto += " "
|
proto += " "
|
||||||
|
|
||||||
for {
|
for {
|
||||||
buf, err := from.ReadBytes()
|
buf, err := from.ReadBytes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug(proto, "Error reading from ", fd, " ", err)
|
log.Debug(proto, "Error reading from ", fd, " ", err)
|
||||||
break
|
return
|
||||||
}
|
} else {
|
||||||
|
}
|
||||||
|
|
||||||
// log.Debug(proto, fd, " sent data: ", len(buf), "bytes")
|
// log.Debug(proto, fd, " sent data: ", len(buf), "bytes")
|
||||||
|
|
||||||
if _, err := to.Write(buf); err != nil {
|
if _, err := to.Write(buf); err != nil {
|
||||||
log.Debug(proto, "Error Writing to ", td)
|
log.Debug(proto, "Error Writing to ", td)
|
||||||
break
|
return
|
||||||
}
|
} else {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user