diff --git a/advLayer/advLayer.go b/advLayer/advLayer.go index 923bfef..1909c1b 100644 --- a/advLayer/advLayer.go +++ b/advLayer/advLayer.go @@ -1,6 +1,6 @@ /*Package advLayer contains definitions and subpackages for Advanced Layer in VSI model. -An advanced layer is based on http layer. It can be websocket, http2, grpc, quic or other customized protocols that based on http and can relay arbitrary length raw []byte data. +An advanced layer is based on http layer. It can be websocket, http2, grpc, quic or other customized protocols that based on http and can relay raw []byte data with arbitrary length. If a protocol is not based on http layer, then maybe it should be on Proxy Layer, rather than Advanced Layer. */ @@ -33,9 +33,8 @@ func PrintAllProtocolNames() { //Creator represents supported features of a advLayer sub-package, and it can create New Client and Server. type Creator interface { ProtocolName() string - PackageID() string //unique for each package, sub packages in v2ray_simple don't need to apply prefix, but if you want to implement your own package, you should use full git path, like github.com/somebody/mypackage + PackageID() string //unique for each package. Sub packages included in v2ray_simple don't need to apply any prefix, but if you want to implement your own package, you should use full git path, like github.com/somebody/mypackage. This is for distinguishing different packages. - //NewClientFromURL(url *url.URL) (Client, error) //todo: support url NewClientFromConf(conf *Conf) (Client, error) NewServerFromConf(conf *Conf) (Server, error) diff --git a/advLayer/quic/quic.go b/advLayer/quic/quic.go index cb91649..9f5ce8b 100644 --- a/advLayer/quic/quic.go +++ b/advLayer/quic/quic.go @@ -142,7 +142,7 @@ func (Creator) NewClientFromConf(conf *advLayer.Conf) (advLayer.Client, error) { var tConf tls.Config if conf.TlsConf != nil { - tConf = *conf.TlsConf + tConf = *conf.TlsConf //tls.Config是包含RWMutex的,正常是不宜直接复制的; 不过这个Config我们只用在quic包中,而该包内部是会直接调用Clone的,并不会直接使用我们的Config,所以没关系。 } tConf.NextProtos = alpn diff --git a/proxy/config_simple.go b/proxy/config_simple.go index 8ec1a30..1114f45 100644 --- a/proxy/config_simple.go +++ b/proxy/config_simple.go @@ -2,7 +2,7 @@ package proxy import ( "encoding/json" - "io/ioutil" + "io" "log" "net/url" "os" @@ -25,7 +25,7 @@ func LoadSimpleConfigFile(fileNamePath string) (config SimpleConf, hasError bool if cf, err := os.Open(fileNamePath); err == nil { defer cf.Close() - bs, _ := ioutil.ReadAll(cf) + bs, _ := io.ReadAll(cf) if err = json.Unmarshal(bs, &config); err != nil { hasError = true E = utils.ErrInErr{ diff --git a/proxy/config_standard.go b/proxy/config_standard.go index b6632f5..274c7ac 100644 --- a/proxy/config_standard.go +++ b/proxy/config_standard.go @@ -2,7 +2,7 @@ package proxy import ( "errors" - "io/ioutil" + "io" "log" "os" "path/filepath" @@ -59,7 +59,7 @@ func LoadTomlConfFile(fileNamePath string) (StandardConf, error) { if cf, err := os.Open(fileNamePath); err == nil { defer cf.Close() - bs, _ := ioutil.ReadAll(cf) + bs, _ := io.ReadAll(cf) return LoadTomlConfStr(string(bs)) } else { return StandardConf{}, utils.ErrInErr{ErrDesc: "can't open config file", ErrDetail: err} diff --git a/proxy/config_url.go b/proxy/config_url.go index 858db3c..d04c5d8 100644 --- a/proxy/config_url.go +++ b/proxy/config_url.go @@ -192,6 +192,17 @@ func URLToCommonConf(u *url.URL, conf *CommonConf) error { if utils.QueryPositive(q, "http") { conf.HttpHeader = &httpLayer.HeaderPreset{} } + + for k, list := range q { + if strings.HasPrefix(k, "extra.") && len(list) > 0 { + k = strings.TrimPrefix(k, "extra.") + if conf.Extra == nil { + conf.Extra = make(map[string]any) + } + conf.Extra[k] = list[0] + } + } + return nil } @@ -208,6 +219,9 @@ func setHeaders(rawq, headers map[string][]string) { //setup conf with vs standard URL format func URLToDialConf(u *url.URL, conf *DialConf) error { e := URLToCommonConf(u, &conf.CommonConf) + if e != nil { + return e + } q := u.Query() @@ -235,6 +249,9 @@ func URLToDialConf(u *url.URL, conf *DialConf) error { //setup conf with vs standard URL format func URLToListenConf(u *url.URL, conf *ListenConf) error { e := URLToCommonConf(u, &conf.CommonConf) + if e != nil { + return e + } q := u.Query() diff --git a/utils/strings_unix.go b/utils/strings_unix.go index 54bcc4e..46c75e4 100644 --- a/utils/strings_unix.go +++ b/utils/strings_unix.go @@ -4,7 +4,7 @@ package utils import ( - "io/ioutil" + "io" "math/rand" "os" "strings" @@ -35,7 +35,7 @@ func readAvailableDictionary() (words []string) { return } - bytes, err := ioutil.ReadAll(file) + bytes, err := io.ReadAll(file) if err != nil { return } diff --git a/utils/user.go b/utils/user.go index 5ebb47a..ce1da50 100644 --- a/utils/user.go +++ b/utils/user.go @@ -73,7 +73,7 @@ func InitRealV2rayUsers(uc []UserConf) (us []V2rayUser) { } //一种专门用于v2ray协议族(vmess/vless)的 用于标识用户的符号 , 实现 User 接口. (其实就是uuid) -type V2rayUser [16]byte +type V2rayUser [UUID_BytesLen]byte func (u V2rayUser) IdentityStr() string { return UUIDToStr(u[:]) @@ -95,7 +95,7 @@ func NewV2rayUser(uuidStr string) (V2rayUser, error) { return V2rayUser{}, err } - return uuid, nil + return V2rayUser(uuid), nil } //used in proxy/socks5 and proxy.http. implements User diff --git a/utils/uuid.go b/utils/uuid.go index 8fd703d..0a86266 100644 --- a/utils/uuid.go +++ b/utils/uuid.go @@ -9,6 +9,8 @@ import ( const UUID_BytesLen int = 16 const ExampleUUID = "a684455c-b14f-11ea-bf0d-42010aaa0003" +type UUID [UUID_BytesLen]byte + func StrToUUID_slice(s string) []byte { bs, err := StrToUUID(s) if err != nil { @@ -17,7 +19,7 @@ func StrToUUID_slice(s string) []byte { return bs[:] } -func StrToUUID(s string) (uuid [UUID_BytesLen]byte, err error) { +func StrToUUID(s string) (uuid UUID, err error) { if len(s) != 36 { return uuid, ErrInErr{ErrDesc: "invalid UUID Str", ErrDetail: ErrInvalidData, Data: s} } @@ -47,7 +49,7 @@ func UUIDToStr(u []byte) string { } //生成完全随机的uuid,不包含任何uuid版本信息 (即不符合rfc,但是更安全) -func GenerateUUID() (r [UUID_BytesLen]byte) { +func GenerateUUID() (r UUID) { rand.Reader.Read(r[:]) return }