chore: better REJECT process

This commit is contained in:
gVisor bot 2023-02-27 09:46:16 +08:00
parent e60ce44e7f
commit b7c2ad2f74

View file

@ -406,29 +406,36 @@ func handleTCPConn(connCtx C.ConnContext) {
ctx, cancel := context.WithTimeout(context.Background(), C.DefaultTCPTimeout) ctx, cancel := context.WithTimeout(context.Background(), C.DefaultTCPTimeout)
defer cancel() defer cancel()
remoteConn, err := retry(ctx, func(ctx context.Context) (C.Conn, error) { remoteConn, err := retry(ctx, func(ctx context.Context) (remoteConn C.Conn, err error) {
remoteConn, err := proxy.DialContext(ctx, dialMetadata) remoteConn, err = proxy.DialContext(ctx, dialMetadata)
if err != nil { if err != nil {
return nil, err return
} }
if N.NeedHandshake(remoteConn) {
defer func() {
for _, chain := range remoteConn.Chains() { for _, chain := range remoteConn.Chains() {
if chain == "REJECT" { if chain == "REJECT" {
return remoteConn, nil err = nil
return
} }
} }
if N.NeedHandshake(remoteConn) { if err != nil {
remoteConn = nil
}
}()
peekMutex.Lock() peekMutex.Lock()
defer peekMutex.Unlock() defer peekMutex.Unlock()
peekBytes, _ = conn.Peek(conn.Buffered()) peekBytes, _ = conn.Peek(conn.Buffered())
_, err = remoteConn.Write(peekBytes) _, err = remoteConn.Write(peekBytes)
if err != nil { if err != nil {
return nil, err return
} }
if peekLen = len(peekBytes); peekLen > 0 { if peekLen = len(peekBytes); peekLen > 0 {
_, _ = conn.Discard(peekLen) _, _ = conn.Discard(peekLen)
} }
} }
return remoteConn, err return
}, func(err error) { }, func(err error) {
if rule == nil { if rule == nil {
log.Warnln( log.Warnln(