remove unneccesary go routines

This commit is contained in:
xvzc 2022-03-05 00:46:33 +09:00
parent 68c1633995
commit ce40143581
2 changed files with 10 additions and 9 deletions

View File

@ -91,15 +91,16 @@ func (lConn *Conn) HandleHttp(p packet.HttpPacket) {
log.Debug("[HTTP] Connected to the server.") log.Debug("[HTTP] Connected to the server.")
go rConn.Serve(lConn, "[HTTP]")
go lConn.Serve(rConn, "[HTTP]")
_, err = rConn.Write(p.Raw()) _, err = rConn.Write(p.Raw())
if err != nil { if err != nil {
log.Debug("[HTTP] Error sending request to the server: ", err) log.Debug("[HTTP] Error sending request to the server: ", err)
return return
} }
log.Debug("[HTTP] Sent a request to the server") log.Debug("[HTTP] Sent a request to the server")
go rConn.Serve(lConn, "[HTTP]")
lConn.Serve(rConn, "[HTTP]")
} }
func (lConn *Conn) HandleHttps(p packet.HttpPacket) { func (lConn *Conn) HandleHttps(p packet.HttpPacket) {
@ -135,10 +136,6 @@ func (lConn *Conn) HandleHttps(p packet.HttpPacket) {
log.Debug("[HTTPS] Client "+lConn.RemoteAddr().String()+" sent hello: ", len(clientHello), "bytes") log.Debug("[HTTPS] Client "+lConn.RemoteAddr().String()+" sent hello: ", len(clientHello), "bytes")
// Generate a go routine that reads from the server
go rConn.Serve(lConn, "[HTTPS]")
go lConn.Serve(rConn, "[HTTPS]")
pkt := packet.NewHttpsPacket(clientHello) pkt := packet.NewHttpsPacket(clientHello)
chunks := pkt.SplitInChunks() chunks := pkt.SplitInChunks()
@ -147,6 +144,10 @@ func (lConn *Conn) HandleHttps(p packet.HttpPacket) {
log.Debug("[HTTPS] Error writing client hello: ", err) log.Debug("[HTTPS] Error writing client hello: ", err)
return return
} }
// Generate a go routine that reads from the server
go rConn.Serve(lConn, "[HTTPS]")
lConn.Serve(rConn, "[HTTPS]")
} }
func (from *Conn) Serve(to *Conn, proto string) { func (from *Conn) Serve(to *Conn, proto string) {

View File

@ -56,10 +56,10 @@ func (p *Proxy) Start() {
if pkt.IsConnectMethod() { if pkt.IsConnectMethod() {
log.Debug("[HTTPS] Start") log.Debug("[HTTPS] Start")
go conn.HandleHttps(pkt) conn.HandleHttps(pkt)
} else { } else {
log.Debug("[HTTP] Start") log.Debug("[HTTP] Start")
go conn.HandleHttp(pkt) conn.HandleHttp(pkt)
} }
}() }()
} }