mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-12-20 00:50:06 +08:00
chore: code cleanup
This commit is contained in:
parent
089766b285
commit
946b4025df
@ -105,11 +105,6 @@ func (vc *Conn) sendRequest(p []byte) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var buffer *buf.Buffer
|
|
||||||
if vc.IsXTLSVisionEnabled() {
|
|
||||||
buffer = buf.New()
|
|
||||||
defer buffer.Release()
|
|
||||||
} else {
|
|
||||||
requestLen := 1 // protocol version
|
requestLen := 1 // protocol version
|
||||||
requestLen += 16 // UUID
|
requestLen += 16 // UUID
|
||||||
requestLen += 1 // addons length
|
requestLen += 1 // addons length
|
||||||
@ -122,9 +117,8 @@ func (vc *Conn) sendRequest(p []byte) bool {
|
|||||||
}
|
}
|
||||||
requestLen += len(p)
|
requestLen += len(p)
|
||||||
|
|
||||||
buffer = buf.NewSize(requestLen)
|
buffer := buf.NewSize(requestLen)
|
||||||
defer buffer.Release()
|
defer buffer.Release()
|
||||||
}
|
|
||||||
|
|
||||||
buf.Must(
|
buf.Must(
|
||||||
buffer.WriteByte(Version), // protocol version
|
buffer.WriteByte(Version), // protocol version
|
||||||
@ -182,10 +176,6 @@ func (vc *Conn) NeedHandshake() bool {
|
|||||||
return vc.needHandshake
|
return vc.needHandshake
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vc *Conn) IsXTLSVisionEnabled() bool {
|
|
||||||
return vc.addons != nil && vc.addons.Flow == XRV
|
|
||||||
}
|
|
||||||
|
|
||||||
// newConn return a Conn instance
|
// newConn return a Conn instance
|
||||||
func newConn(conn net.Conn, client *Client, dst *DstAddr) (net.Conn, error) {
|
func newConn(conn net.Conn, client *Client, dst *DstAddr) (net.Conn, error) {
|
||||||
c := &Conn{
|
c := &Conn{
|
||||||
|
|||||||
@ -3,7 +3,6 @@ package vision
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/subtle"
|
"crypto/subtle"
|
||||||
gotls "crypto/tls"
|
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -12,7 +11,6 @@ import (
|
|||||||
|
|
||||||
"github.com/metacubex/mihomo/common/buf"
|
"github.com/metacubex/mihomo/common/buf"
|
||||||
N "github.com/metacubex/mihomo/common/net"
|
N "github.com/metacubex/mihomo/common/net"
|
||||||
tlsC "github.com/metacubex/mihomo/component/tls"
|
|
||||||
"github.com/metacubex/mihomo/log"
|
"github.com/metacubex/mihomo/log"
|
||||||
|
|
||||||
"github.com/gofrs/uuid/v5"
|
"github.com/gofrs/uuid/v5"
|
||||||
@ -181,17 +179,10 @@ func (vc *Conn) WriteBuffer(buffer *buf.Buffer) (err error) {
|
|||||||
buffer.Release()
|
buffer.Release()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
switch underlying := vc.tlsConn.(type) {
|
err = vc.checkTLSVersion()
|
||||||
case *gotls.Conn:
|
if err != nil {
|
||||||
if underlying.ConnectionState().Version != gotls.VersionTLS13 {
|
|
||||||
buffer.Release()
|
buffer.Release()
|
||||||
return ErrNotTLS13
|
return err
|
||||||
}
|
|
||||||
case *tlsC.UConn:
|
|
||||||
if underlying.ConnectionState().Version != tlsC.VersionTLS13 {
|
|
||||||
buffer.Release()
|
|
||||||
return ErrNotTLS13
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
vc.tlsConn = nil
|
vc.tlsConn = nil
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@ -67,3 +67,21 @@ func NewConn(conn connWithUpstream, userUUID *uuid.UUID) (*Conn, error) {
|
|||||||
c.rawInput = (*bytes.Buffer)(unsafe.Add(p, r.Offset))
|
c.rawInput = (*bytes.Buffer)(unsafe.Add(p, r.Offset))
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (vc *Conn) checkTLSVersion() error {
|
||||||
|
switch underlying := vc.tlsConn.(type) {
|
||||||
|
case *gotls.Conn:
|
||||||
|
if underlying.ConnectionState().Version != gotls.VersionTLS13 {
|
||||||
|
return ErrNotTLS13
|
||||||
|
}
|
||||||
|
case *tlsC.Conn:
|
||||||
|
if underlying.ConnectionState().Version != tlsC.VersionTLS13 {
|
||||||
|
return ErrNotTLS13
|
||||||
|
}
|
||||||
|
case *tlsC.UConn:
|
||||||
|
if underlying.ConnectionState().Version != tlsC.VersionTLS13 {
|
||||||
|
return ErrNotTLS13
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user