Merge pull request #3 from xvzc/refactor

Refactor
This commit is contained in:
Kwanghoo Park 2022-01-03 17:33:20 +09:00 committed by GitHub
commit c8167effb4
2 changed files with 8 additions and 25 deletions

View File

@ -2,7 +2,6 @@ package proxy
import ( import (
"fmt" "fmt"
"io"
"net" "net"
// "time" // "time"
@ -26,13 +25,7 @@ func HandleHttps(clientConn net.Conn, ip string) {
for { for {
buf, err := util.ReadMessage(remoteConn) buf, err := util.ReadMessage(remoteConn)
if err != nil { if err != nil {
if err != io.EOF { util.Debug("Error reading from the server", err, " Closing connection ", remoteConn.RemoteAddr())
util.Debug("Error reading from the server:", err)
} else {
util.Debug("Remote connection Closed: ", err)
}
util.Debug("Closing connection: ", remoteConn.RemoteAddr())
return return
} }
@ -40,7 +33,7 @@ func HandleHttps(clientConn net.Conn, ip string) {
_, write_err := clientConn.Write(buf) _, write_err := clientConn.Write(buf)
if write_err != nil { if write_err != nil {
util.Debug("Error writing to client:", write_err) util.Debug("Error sending data to the client:", write_err)
return return
} }
} }
@ -51,17 +44,12 @@ func HandleHttps(clientConn net.Conn, ip string) {
clientHello, err := util.ReadMessage(clientConn) clientHello, err := util.ReadMessage(clientConn)
if err != nil { if err != nil {
if err != io.EOF { util.Debug("Error reading client hello", err, " Closing connection ", clientConn.RemoteAddr())
util.Debug("Error reading from the client:", err)
} else {
util.Debug("Client connection Closed: ", err)
}
util.Debug("Closing connection: ", clientConn.RemoteAddr())
} }
util.Debug(clientConn.RemoteAddr(), "Client sent hello", len(clientHello)) util.Debug(clientConn.RemoteAddr(), "Client sent hello", len(clientHello))
chunks, err := util.SplitSliceInChunks(clientHello, config.GetConfig().MTU) chunks, err := util.SplitInChunks(clientHello, config.GetConfig().MTU)
if err != nil { if err != nil {
util.Debug("Error chunking client hello: ", err) util.Debug("Error chunking client hello: ", err)
} }
@ -77,15 +65,10 @@ func HandleHttps(clientConn net.Conn, ip string) {
for { for {
buf, err := util.ReadMessage(clientConn) buf, err := util.ReadMessage(clientConn)
if err != nil { if err != nil {
if err != io.EOF { util.Debug("Error reading from the client", err, " Closing connection ", clientConn.RemoteAddr())
util.Debug("Error reading from the client:", err)
} else {
util.Debug("Client connection Closed: ", err)
}
util.Debug("Closing connection: ", clientConn.RemoteAddr())
break break
} }
util.Debug(clientConn.RemoteAddr(), "Client sent data", len(buf)) util.Debug(clientConn.RemoteAddr(), "Client sent data", len(buf))
_, write_err := remoteConn.Write(buf) _, write_err := remoteConn.Write(buf)

View File

@ -109,7 +109,7 @@ func ExtractMethod(message *[]byte) (string) {
return strings.ToUpper(method) return strings.ToUpper(method)
} }
func SplitSliceInChunks(a []byte, size int) ([][]byte, error) { func SplitInChunks(a []byte, size int) ([][]byte, error) {
if size < 1 { if size < 1 {
return nil, errors.New("chuckSize must be greater than zero") return nil, errors.New("chuckSize must be greater than zero")
} }