Skip to content

Commit

Permalink
small optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
uoosef committed Nov 23, 2023
1 parent 9fe25fb commit 543cd64
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func serveSniProxy() {
for {
conn, err := l.Accept()
if err != nil {
log.Print(err)
log.Println(err)
continue
}
go handleConnection(conn)
Expand Down Expand Up @@ -259,18 +259,23 @@ func handleConnection(clientConn net.Conn) {
defer clientConn.Close()

if err := clientConn.SetReadDeadline(time.Now().Add(5 * time.Second)); err != nil {
log.Print(err)
log.Println(err)
return
}

clientHello, clientHelloBytes, err := peekClientHello(clientConn)
if err != nil {
log.Print(err)
log.Println(err)
return
}

if clientHello.ServerName == null || strings.TrimSpace(clientHello.ServerName) == "" {
log.Println("null server name not allowed")
return
}

if err := clientConn.SetReadDeadline(time.Time{}); err != nil {
log.Print(err)
log.Println(err)
return
}

Expand All @@ -284,7 +289,7 @@ func handleConnection(clientConn net.Conn) {

backendConn, err := net.DialTimeout("tcp", targetHost, 5*time.Second)
if err != nil {
log.Print(err)
log.Println(err)
return
}
defer backendConn.Close()
Expand Down

0 comments on commit 543cd64

Please sign in to comment.