chore: add early conn interface to decrease unneeded write

This commit is contained in:
wwqgtxx
2023-02-27 00:26:49 +08:00
parent c8c078e78a
commit c1199f1a8a
14 changed files with 144 additions and 62 deletions

View File

@ -6,6 +6,7 @@ import (
"math/rand"
"net/http"
"strings"
"time"
"github.com/gofrs/uuid"
)
@ -317,6 +318,6 @@ func SetUserAgent(header http.Header) {
}
func VerifyMethod(cipher, password string) (err error) {
_, err = shadowimpl.FetchMethod(cipher, password)
_, err = shadowimpl.FetchMethod(cipher, password, time.Now)
return
}

View File

@ -4,6 +4,7 @@ import (
"context"
"net"
"github.com/sagernet/sing/common"
"github.com/sagernet/sing/common/bufio"
"github.com/sagernet/sing/common/network"
)
@ -16,6 +17,13 @@ type ExtendedConn = network.ExtendedConn
type ExtendedWriter = network.ExtendedWriter
type ExtendedReader = network.ExtendedReader
func NeedHandshake(conn any) bool {
if earlyConn, isEarlyConn := common.Cast[network.EarlyConn](conn); isEarlyConn && earlyConn.NeedHandshake() {
return true
}
return false
}
// Relay copies between left and right bidirectionally.
func Relay(leftConn, rightConn net.Conn) {
_ = bufio.CopyConn(context.TODO(), leftConn, rightConn)