chore: the uuid-map is transferred to the protocol

This commit is contained in:
Skyxim
2022-05-06 13:28:09 +08:00
parent a08e39faec
commit a95d439852
7 changed files with 111 additions and 33 deletions

View File

@ -2,16 +2,12 @@ package outbound
import (
"context"
"crypto/sha1"
"encoding/hex"
"encoding/json"
"errors"
"net"
"github.com/Dreamacro/clash/component/dialer"
C "github.com/Dreamacro/clash/constant"
"github.com/gofrs/uuid"
)
type Base struct {
@ -150,28 +146,3 @@ func (c *packetConn) AppendToChains(a C.ProxyAdapter) {
func newPacketConn(pc net.PacketConn, a C.ProxyAdapter) C.PacketConn {
return &packetConn{pc, []string{a.Name()}}
}
func uuidMap(str string) string {
_, err := uuid.FromString(str)
if err != nil {
var Nil [16]byte
h := sha1.New()
h.Write(Nil[:])
h.Write([]byte(str))
u := h.Sum(nil)[:16]
u[6] = (u[6] & 0x0f) | (5 << 4)
u[8] = u[8]&(0xff>>2) | (0x02 << 6)
buf := make([]byte, 36)
hex.Encode(buf[0:8], u[0:4])
buf[8] = '-'
hex.Encode(buf[9:13], u[4:6])
buf[13] = '-'
hex.Encode(buf[14:18], u[6:8])
buf[18] = '-'
hex.Encode(buf[19:23], u[8:10])
buf[23] = '-'
hex.Encode(buf[24:], u[10:])
return string(buf)
}
return str
}

View File

@ -394,7 +394,7 @@ func NewVless(option VlessOption) (*Vless, error) {
}
}
client, err := vless.NewClient(uuidMap(option.UUID), addons, option.FlowShow)
client, err := vless.NewClient(option.UUID, addons, option.FlowShow)
if err != nil {
return nil, err
}

View File

@ -274,7 +274,7 @@ func (v *Vmess) SupportUOT() bool {
func NewVmess(option VmessOption) (*Vmess, error) {
security := strings.ToLower(option.Cipher)
client, err := vmess.NewClient(vmess.Config{
UUID: uuidMap(option.UUID),
UUID: option.UUID,
AlterID: uint16(option.AlterID),
Security: security,
HostName: option.Server,