From 833af7dc74e09417f15ef835278ca853ad16cbcb Mon Sep 17 00:00:00 2001 From: Zakk Date: Sun, 20 Sep 2026 16:40:34 +1000 Subject: [PATCH] refactor: use what the dependencies already provide A read of the tree for home-grown code that a dependency or the platform covers. Each item names what replaces it. - IPv4 CIDR membership was a binary-string trie (infra/dataStructure/trie) fed with CIDRs rendered as bit strings; net.IPNet.Contains, which the same file already used for IPv6, does it. The trie package is gone. - The response replay cache was an LRU with its own linked list, indexes and timeout strategy (infra/dataStructure/lru), of which one fixed-size instance existed; hashicorp/golang-lru/v2, already in go.mod, is that cache, typed. go mod tidy also dropped go-nanoid, which nothing imported. - The HTTP client for subscription updates through the local proxy carried a CONNECT dialer of its own (pkg/util/proxyWithHttp); http.Transport's Proxy handles socks5:// and http:// URLs, resolves hostnames on the SOCKS proxy and uses CONNECT for https. Verified on the VM: a subscription update succeeds in both "pac" and "proxy" modes. - core/dns/qtype.go listed nine type names in two switches before falling back to miekg/dns tables that contain the same names; dns.Type.String and dns.StringToType are the tables. - The GUI tracked prefers-color-scheme with its own media query and toggled a theme-dark class nothing reads any more; Vuetify's "system" theme follows the OS itself. Verified in headless Chrome: auto follows the OS in both directions, an explicit choice overrides it. - The AUR packages carried .INSTALL hooks whose only content was a coloured "Completed!" banner, duplicated in the deb/rpm after-install scripts; pacman and apt report that themselves. The hooks are gone, the release workflow stops copying them, and after_install/after_upgrade keep only daemon-reload and the restart. - The tap release job downloaded eight artifacts in eight steps; actions/download-artifact takes a pattern with merge-multiple. --- .github/workflows/_release.yml | 51 ++----- core/dns/qtype.go | 76 +---------- gui/src/AppShell.vue | 15 +- gui/src/stores/app.ts | 5 - install/aur/v2raya-bin/.INSTALL | 27 ---- install/aur/v2raya-bin/PKGBUILD | 1 - install/aur/v2raya/.INSTALL | 27 ---- install/aur/v2raya/PKGBUILD | 1 - install/universal/after_install.sh | 11 -- install/universal/after_upgrade.sh | 13 -- service/common/httpClient/httpClient.go | 13 +- service/common/netTools/ipaddress.go | 46 +------ service/common/response.go | 17 +-- service/go.mod | 3 +- service/go.sum | 2 - service/infra/dataStructure/lru/lru.go | 112 --------------- service/infra/dataStructure/trie/trie.go | 128 ------------------ service/infra/dataStructure/trie/trie_test.go | 35 ----- service/pkg/server/reqCache/reqCache.go | 6 +- .../pkg/util/proxyWithHttp/proxyWithHttp.go | 127 ----------------- 20 files changed, 32 insertions(+), 684 deletions(-) delete mode 100755 install/aur/v2raya-bin/.INSTALL delete mode 100755 install/aur/v2raya/.INSTALL delete mode 100644 service/infra/dataStructure/lru/lru.go delete mode 100644 service/infra/dataStructure/trie/trie.go delete mode 100644 service/infra/dataStructure/trie/trie_test.go delete mode 100644 service/pkg/util/proxyWithHttp/proxyWithHttp.go diff --git a/.github/workflows/_release.yml b/.github/workflows/_release.yml index d0108a85..0ad3f392 100644 --- a/.github/workflows/_release.yml +++ b/.github/workflows/_release.yml @@ -121,45 +121,11 @@ jobs: version=$(echo $tag | sed 's/v//g') echo "VERSION=$version" >> $GITHUB_OUTPUT echo "VERSION=$version" >> $GITHUB_ENV - - name: Download Artifact Linux x64 + - name: Download Artifacts uses: actions/download-artifact@v8 with: - name: v2raya_linux_x64_${{ steps.prep.outputs.VERSION }} - path: Downloads - - name: Download Core Artifact Linux x64 - uses: actions/download-artifact@v8 - with: - name: v2raya_core_linux_x64_${{ steps.prep.outputs.VERSION }} - path: Downloads - - name: Download Artifact Linux arm64 - uses: actions/download-artifact@v8 - with: - name: v2raya_linux_arm64_${{ steps.prep.outputs.VERSION }} - path: Downloads - - name: Download Core Artifact Linux arm64 - uses: actions/download-artifact@v8 - with: - name: v2raya_core_linux_arm64_${{ steps.prep.outputs.VERSION }} - path: Downloads - - name: Download Artifact macOS x64 - uses: actions/download-artifact@v8 - with: - name: v2raya_darwin_x64_${{ steps.prep.outputs.VERSION }} - path: Downloads - - name: Download Core Artifact macOS x64 - uses: actions/download-artifact@v8 - with: - name: v2raya_core_darwin_x64_${{ steps.prep.outputs.VERSION }} - path: Downloads - - name: Download Artifact macOS arm64 - uses: actions/download-artifact@v8 - with: - name: v2raya_darwin_arm64_${{ steps.prep.outputs.VERSION }} - path: Downloads - - name: Download Core Artifact macOS arm64 - uses: actions/download-artifact@v8 - with: - name: v2raya_core_darwin_arm64_${{ steps.prep.outputs.VERSION }} + pattern: v2raya{,_core}_{linux,darwin}_{x64,arm64}_${{ steps.prep.outputs.VERSION }} + merge-multiple: true path: Downloads - name: Compress to Zip Files run: | @@ -347,8 +313,7 @@ jobs: mkdir -p aur git clone https://aur.archlinux.org/v2raya.git aur/v2raya git clone https://aur.archlinux.org/v2raya-bin.git aur/v2raya-bin - cp install/aur/v2raya/.INSTALL aur/v2raya/.INSTALL - cp install/aur/v2raya-bin/.INSTALL aur/v2raya-bin/.INSTALL + rm -f aur/v2raya/.INSTALL aur/v2raya-bin/.INSTALL cat install/aur/v2raya/PKGBUILD | sed "s|The_Real_Version|${{ steps.prep.outputs.VERSION }}|g" > aur/v2raya/PKGBUILD cat install/aur/v2raya-bin/PKGBUILD | sed "s|The_Real_Version|${{ steps.prep.outputs.VERSION }}|g" > aur/v2raya-bin/PKGBUILD - name: Install Podman @@ -386,11 +351,11 @@ jobs: sudo chown -R $(id -u):$(id -u) aur/v2raya-bin git config --global user.email "github-actions[bot]@users.noreply.github.com" git config --global user.name "github-actions[bot]" - cd $Current_Dir/aur/v2raya && git add .SRCINFO .INSTALL && \ - git commit -a -m "Update to v${{ steps.prep.outputs.VERSION }}" && \ + cd $Current_Dir/aur/v2raya && git add -A && \ + git commit -m "Update to v${{ steps.prep.outputs.VERSION }}" && \ git push --force ssh://aur@aur.archlinux.org/v2raya.git - cd $Current_Dir/aur/v2raya-bin && git add .SRCINFO .INSTALL && \ - git commit -a -m "Update to v${{ steps.prep.outputs.VERSION }}" && \ + cd $Current_Dir/aur/v2raya-bin && git add -A && \ + git commit -m "Update to v${{ steps.prep.outputs.VERSION }}" && \ git push --force ssh://aur@aur.archlinux.org/v2raya-bin.git - name: Clean Up run: | diff --git a/core/dns/qtype.go b/core/dns/qtype.go index 61d7377f..d542c0f8 100644 --- a/core/dns/qtype.go +++ b/core/dns/qtype.go @@ -7,92 +7,28 @@ import ( "github.com/miekg/dns" ) -// QTypeToString converts a QueryType to its string representation. -// For example, TypeA → "A", TypeAAAA → "AAAA". -// If the query type is not in the supported list, it returns the -// numeric string representation (e.g., "TYPE99"). +// QTypeToString returns "A", "AAAA", … or "TYPE99". func QTypeToString(qt QueryType) string { - switch qt { - case TypeA: - return "A" - case TypeAAAA: - return "AAAA" - case TypeCNAME: - return "CNAME" - case TypeTXT: - return "TXT" - case TypeMX: - return "MX" - case TypeSRV: - return "SRV" - case TypeNS: - return "NS" - case TypePTR: - return "PTR" - case TypeSOA: - return "SOA" - default: - // Try miekg/dns string representation first. - s := dns.TypeToString[uint16(qt)] - if s != "" { - return s - } - return fmt.Sprintf("TYPE%d", uint16(qt)) - } + return dns.Type(qt).String() } -// StringToQType converts a string to a QueryType. -// It supports standard type names ("A", "AAAA", etc.) and -// numeric format ("1", "28", "TYPE1", "TYPE28"). -// Returns an error if the string does not represent a valid query type. +// StringToQType accepts a type name, "TYPE" or a number. func StringToQType(s string) (QueryType, error) { s = strings.TrimSpace(s) if s == "" { return 0, fmt.Errorf("dns qtype: empty string") } - - // Try uppercase name lookup first. upper := strings.ToUpper(s) - switch upper { - case "A": - return TypeA, nil - case "AAAA": - return TypeAAAA, nil - case "CNAME": - return TypeCNAME, nil - case "TXT": - return TypeTXT, nil - case "MX": - return TypeMX, nil - case "SRV": - return TypeSRV, nil - case "NS": - return TypeNS, nil - case "PTR": - return TypePTR, nil - case "SOA": - return TypeSOA, nil - } - - // Try miekg/dns reverse lookup via StringToType. if qt, ok := dns.StringToType[upper]; ok { return QueryType(qt), nil } - - // Try "TYPE" format. - if strings.HasPrefix(upper, "TYPE") { - var num uint16 - if _, err := fmt.Sscanf(upper, "TYPE%d", &num); err == nil { - return QueryType(num), nil - } - } - - // Try plain numeric format. var num uint16 + if _, err := fmt.Sscanf(upper, "TYPE%d", &num); err == nil { + return QueryType(num), nil + } if _, err := fmt.Sscanf(upper, "%d", &num); err == nil { return QueryType(num), nil } - return 0, fmt.Errorf("dns qtype: unknown query type: %q", s) } diff --git a/gui/src/AppShell.vue b/gui/src/AppShell.vue index 44e6da77..ff4cc254 100644 --- a/gui/src/AppShell.vue +++ b/gui/src/AppShell.vue @@ -357,10 +357,8 @@ watchEffect(() => { theme.themes.value.dark.colors = schemeColors(store.themeSeed, true); }); watchEffect(() => { - theme.global.name.value = store.isDark ? "dark" : "light"; - // the old components' dark styles key on this class - document.documentElement.classList.toggle("theme-dark", store.isDark); - document.body.classList.toggle("theme-dark", store.isDark); + theme.global.name.value = + store.themePreference === "auto" ? "system" : store.themePreference; }); watch( @@ -374,9 +372,6 @@ watch( { immediate: true }, ); -const darkQuery = window.matchMedia("(prefers-color-scheme: dark)"); -const onSystemTheme = (e: MediaQueryListEvent) => - (store.systemDark = e.matches); // "#docs" or "#docs/
" opens the documentation: the help links in // the dialogs and the About page point there, in this tab or a new one. function openHash() { @@ -388,15 +383,11 @@ function openHash() { history.replaceState(null, "", location.pathname + location.search); } onMounted(() => { - darkQuery.addEventListener("change", onSystemTheme); window.addEventListener("hashchange", openHash); openHash(); void startSession(); }); -onBeforeUnmount(() => { - darkQuery.removeEventListener("change", onSystemTheme); - window.removeEventListener("hashchange", openHash); -}); +onBeforeUnmount(() => window.removeEventListener("hashchange", openHash));