Skip to content

Commit ddeaf47

Browse files
author
Delta-Kronecker
committed
Dedup configs by UUID instead of server IP
1 parent eaf3bca commit ddeaf47

1 file changed

Lines changed: 17 additions & 15 deletions

File tree

src/parser.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -771,31 +771,27 @@ func coreIdentity(line, protocol string) string {
771771
if !strings.HasPrefix(data, "{") {
772772
if decoded, err := decodeBase64([]byte(data)); err == nil {
773773
var d struct {
774-
Add string `json:"add"`
775-
Port interface{} `json:"port"`
776-
ID string `json:"id"`
774+
ID string `json:"id"`
777775
}
778-
if json.Unmarshal([]byte(decoded), &d) == nil && d.Add != "" {
779-
return fmt.Sprintf("vmess://%s:%v#%s", d.Add, d.Port, d.ID)
776+
if json.Unmarshal([]byte(decoded), &d) == nil && d.ID != "" {
777+
return "vmess://" + normalizeUUID(d.ID)
780778
}
781779
}
782780
}
783781

784782
if strings.HasPrefix(data, "{") {
785783
var d struct {
786-
Add string `json:"add"`
787-
Port interface{} `json:"port"`
788-
ID string `json:"id"`
784+
ID string `json:"id"`
789785
}
790-
if json.Unmarshal([]byte(data), &d) == nil && d.Add != "" {
791-
return fmt.Sprintf("vmess://%s:%v#%s", d.Add, d.Port, d.ID)
786+
if json.Unmarshal([]byte(data), &d) == nil && d.ID != "" {
787+
return "vmess://" + normalizeUUID(d.ID)
792788
}
793789
}
794790

795791
if atIdx := strings.Index(data, "@"); atIdx != -1 {
796-
u, err := url.Parse("vmess://" + data)
797-
if err == nil && u.Hostname() != "" {
798-
return fmt.Sprintf("vmess://%s:%s#%s", u.Hostname(), u.Port(), u.User.Username())
792+
uuid := normalizeUUID(data[:atIdx])
793+
if uuid != "" {
794+
return "vmess://" + uuid
799795
}
800796
}
801797

@@ -815,11 +811,17 @@ func coreIdentity(line, protocol string) string {
815811
}
816812
return fmt.Sprintf("ssr://%s:%s", parts[0], parts[1])
817813
default:
814+
// vless, trojan, ss, hy, hy2, tuic — identity is the credential
815+
// (uuid/password/auth), not the server IP
818816
u, err := url.Parse(sanitizeProxyURL(line))
819-
if err != nil || u.Hostname() == "" {
817+
if err != nil || u.Hostname() == "" || u.User == nil {
820818
return line
821819
}
822-
return fmt.Sprintf("%s://%s@%s:%s", protocol, u.User.String(), u.Hostname(), u.Port())
820+
cred := normalizeUUID(u.User.Username())
821+
if cred == "" {
822+
return line
823+
}
824+
return fmt.Sprintf("%s://%s", protocol, cred)
823825
}
824826
}
825827

0 commit comments

Comments
 (0)