mirror of
https://github.com/v2rayA/v2rayA.git
synced 2026-11-20 23:02:25 +03:00
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.
This commit is contained in:
20 files changed
+32
-684
No files matched your search
@@ -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: |
|
||||
|
||||
+6
-70
@@ -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<n>" 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<num>" 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)
|
||||
}
|
||||
|
||||
|
||||
+3
-12
@@ -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/<section>" 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));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -55,7 +55,6 @@ export const useAppStore = defineStore("app", {
|
||||
)
|
||||
? localStorage.getItem("theme")
|
||||
: "auto") as ThemePreference,
|
||||
systemDark: window.matchMedia("(prefers-color-scheme: dark)").matches,
|
||||
/** the seed colour the theme's palettes derive from */
|
||||
themeSeed: (() => {
|
||||
const seed = localStorage.getItem("themeSeed") ?? "";
|
||||
@@ -78,10 +77,6 @@ export const useAppStore = defineStore("app", {
|
||||
return "";
|
||||
}
|
||||
},
|
||||
isDark: (s) =>
|
||||
s.themePreference === "auto"
|
||||
? s.systemDark
|
||||
: s.themePreference === "dark",
|
||||
},
|
||||
actions: {
|
||||
setToken(token: string) {
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
post_install() {
|
||||
ECHOLEN=$(echo -e|awk '{print length($0)}')
|
||||
if [ ${ECHOLEN} = '0' ]
|
||||
then
|
||||
ECHO='echo -e'
|
||||
else
|
||||
ECHO='echo'
|
||||
fi;
|
||||
$ECHO "\033[36m******************************\033[0m"
|
||||
$ECHO "\033[36m* Completed! *\033[0m"
|
||||
$ECHO "\033[36m******************************\033[0m"
|
||||
}
|
||||
|
||||
post_upgrade() {
|
||||
ECHOLEN=$(echo -e|awk '{print length($0)}')
|
||||
if [ ${ECHOLEN} = '0' ]
|
||||
then
|
||||
ECHO='echo -e'
|
||||
else
|
||||
ECHO='echo'
|
||||
fi;
|
||||
$ECHO "\033[36m******************************\033[0m"
|
||||
$ECHO "\033[36m* Completed! *\033[0m"
|
||||
$ECHO "\033[36m******************************\033[0m"
|
||||
}
|
||||
@@ -4,7 +4,6 @@ pkgname=v2raya-bin
|
||||
_pkgname=v2raya
|
||||
pkgver=The_Real_Version
|
||||
pkgrel=1
|
||||
install=.INSTALL
|
||||
pkgdesc="A web GUI client of Project V which supports VMess, VLESS, SS, SSR, Trojan, Tuic and Juicity protocols"
|
||||
arch=('i686' 'x86_64' 'armv7h' 'aarch64' 'loong64')
|
||||
url="https://github.com/v2rayA/v2rayA"
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
post_install() {
|
||||
ECHOLEN=$(echo -e|awk '{print length($0)}')
|
||||
if [ ${ECHOLEN} = '0' ]
|
||||
then
|
||||
ECHO='echo -e'
|
||||
else
|
||||
ECHO='echo'
|
||||
fi;
|
||||
$ECHO "\033[36m******************************\033[0m"
|
||||
$ECHO "\033[36m* Completed! *\033[0m"
|
||||
$ECHO "\033[36m******************************\033[0m"
|
||||
}
|
||||
|
||||
post_upgrade() {
|
||||
ECHOLEN=$(echo -e|awk '{print length($0)}')
|
||||
if [ ${ECHOLEN} = '0' ]
|
||||
then
|
||||
ECHO='echo -e'
|
||||
else
|
||||
ECHO='echo'
|
||||
fi;
|
||||
$ECHO "\033[36m******************************\033[0m"
|
||||
$ECHO "\033[36m* Completed! *\033[0m"
|
||||
$ECHO "\033[36m******************************\033[0m"
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
pkgname=v2raya
|
||||
pkgver=The_Real_Version
|
||||
pkgrel=1
|
||||
install=.INSTALL
|
||||
pkgdesc="A web GUI client of Project V which supports VMess, VLESS, SS, SSR, Trojan, Tuic and Juicity protocols"
|
||||
arch=('i686' 'pentium4' 'x86_64' 'arm' 'armv7h' 'armv6h' 'aarch64' 'loong64')
|
||||
url="https://github.com/v2rayA/v2rayA"
|
||||
|
||||
@@ -1,14 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
systemctl daemon-reload
|
||||
|
||||
ECHOLEN=$(echo -e|awk '{print length($0)}')
|
||||
if [ "${ECHOLEN}" = '0' ]
|
||||
then
|
||||
ECHO='echo -e'
|
||||
else
|
||||
ECHO='echo'
|
||||
fi;
|
||||
$ECHO "\033[36m******************************\033[0m"
|
||||
$ECHO "\033[36m* Completed! *\033[0m"
|
||||
$ECHO "\033[36m******************************\033[0m"
|
||||
@@ -3,18 +3,5 @@
|
||||
systemctl daemon-reload
|
||||
|
||||
if [ "$(systemctl is-active v2raya)" = "active" ]; then
|
||||
echo "Restarting v2rayA service..."
|
||||
systemctl restart v2raya
|
||||
echo "v2rayA service restarted"
|
||||
fi
|
||||
|
||||
ECHOLEN=$(echo -e|awk '{print length($0)}')
|
||||
if [ "${ECHOLEN}" = '0' ]
|
||||
then
|
||||
ECHO='echo -e'
|
||||
else
|
||||
ECHO='echo'
|
||||
fi;
|
||||
$ECHO "\033[36m******************************\033[0m"
|
||||
$ECHO "\033[36m* Completed! *\033[0m"
|
||||
$ECHO "\033[36m******************************\033[0m"
|
||||
@@ -3,9 +3,8 @@ package httpClient
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/v2rayA/v2rayA/common"
|
||||
"github.com/v2rayA/v2rayA/kernel/v2ray"
|
||||
"github.com/v2rayA/v2rayA/db/configure"
|
||||
proxyWithHttp2 "github.com/v2rayA/v2rayA/pkg/util/proxyWithHttp"
|
||||
"github.com/v2rayA/v2rayA/kernel/v2ray"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -19,15 +18,7 @@ func GetHttpClientWithProxy(proxyURL string) (client *http.Client, err error) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
dialer, err := proxyWithHttp2.FromURL(u, proxyWithHttp2.Direct)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
httpTransport := &http.Transport{
|
||||
Dial: dialer.Dial,
|
||||
}
|
||||
client = &http.Client{Transport: httpTransport}
|
||||
return
|
||||
return &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(u)}}, nil
|
||||
}
|
||||
|
||||
func GetHttpClientWithv2rayAProxy() (client *http.Client, err error) {
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
package netTools
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/v2rayA/v2rayA/infra/dataStructure/trie"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var intranet4 = []string{
|
||||
@@ -50,8 +46,8 @@ type IPNets struct {
|
||||
}
|
||||
|
||||
var (
|
||||
trieIntranet4 *trie.Trie
|
||||
trieJokernet4 *trie.Trie
|
||||
ipnetsIntranet4 *IPNets
|
||||
ipnetsJokernet4 *IPNets
|
||||
ipnetsIntranet6 *IPNets
|
||||
ipnetsJokernet6 *IPNets
|
||||
)
|
||||
@@ -78,48 +74,18 @@ func (n *IPNets) Match(ip net.IP) bool {
|
||||
}
|
||||
|
||||
func init() {
|
||||
trieIntranet4 = New4(intranet4)
|
||||
trieJokernet4 = New4(jokernet4)
|
||||
ipnetsIntranet4, _ = NewIPNets(intranet4)
|
||||
ipnetsJokernet4, _ = NewIPNets(jokernet4)
|
||||
ipnetsIntranet6, _ = NewIPNets(intranet6)
|
||||
ipnetsJokernet6, _ = NewIPNets(jokernet6)
|
||||
}
|
||||
|
||||
func New4(CIDRs []string) *trie.Trie {
|
||||
dict := make([]string, 0, len(CIDRs))
|
||||
for _, CIDR := range CIDRs {
|
||||
grp := strings.SplitN(CIDR, "/", 2)
|
||||
l, _ := strconv.Atoi(grp[1])
|
||||
arr := strings.Split(grp[0], ".")
|
||||
var builder strings.Builder
|
||||
for _, sec := range arr {
|
||||
itg, _ := strconv.Atoi(sec)
|
||||
tmp := strconv.FormatInt(int64(itg), 2)
|
||||
builder.WriteString(strings.Repeat("0", 8-len(tmp)))
|
||||
builder.WriteString(tmp)
|
||||
if builder.Len() >= l {
|
||||
break
|
||||
}
|
||||
}
|
||||
dict = append(dict, builder.String()[:l])
|
||||
}
|
||||
return trie.New(dict)
|
||||
}
|
||||
|
||||
func ipv4ToBin(ipv4 *[4]byte) string {
|
||||
var buff = new(bytes.Buffer)
|
||||
for _, b := range ipv4 {
|
||||
tmp := strconv.FormatInt(int64(b), 2)
|
||||
buff.WriteString(strings.Repeat("0", 8-len(tmp)) + tmp)
|
||||
}
|
||||
return buff.String()
|
||||
}
|
||||
|
||||
func IsIntranet4(ipv4 *[4]byte) bool {
|
||||
return trieIntranet4.Match(ipv4ToBin(ipv4)) != ""
|
||||
return ipnetsIntranet4.Match(net.IP(ipv4[:]))
|
||||
}
|
||||
|
||||
func IsJokernet4(ipv4 *[4]byte) bool {
|
||||
return trieJokernet4.Match(ipv4ToBin(ipv4)) != ""
|
||||
return ipnetsJokernet4.Match(net.IP(ipv4[:]))
|
||||
}
|
||||
|
||||
func IsIntranet6(ipv6 *[16]byte) bool {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/v2rayA/v2rayA/infra/dataStructure/lru"
|
||||
lru "github.com/hashicorp/golang-lru/v2"
|
||||
)
|
||||
|
||||
type Code string
|
||||
@@ -33,7 +33,7 @@ func codedErrorBody(err error, coded *CodedError) gin.H {
|
||||
return body
|
||||
}
|
||||
|
||||
var RespCache = lru.New(lru.FixedLength, 10)
|
||||
var RespCache, _ = lru.New[string, Resp](10)
|
||||
|
||||
const (
|
||||
SUCCESS = "SUCCESS"
|
||||
@@ -45,21 +45,12 @@ const (
|
||||
// 当code为FAIL时,data为string类型返回给前端的消息
|
||||
func Response(ctx *gin.Context, code Code, data interface{}) (status int, body gin.H) {
|
||||
if reqId := ctx.GetHeader(RequestIdHeader); reqId != "" {
|
||||
if resp := RespCache.Get(reqId); resp != nil {
|
||||
resp, ok := resp.(Resp)
|
||||
if !ok {
|
||||
ctx.JSON(http.StatusInternalServerError, gin.H{
|
||||
"code": FAIL,
|
||||
"message": "internal cache error",
|
||||
"data": nil,
|
||||
})
|
||||
return http.StatusInternalServerError, nil
|
||||
}
|
||||
if resp, ok := RespCache.Get(reqId); ok {
|
||||
ctx.JSON(resp.Status, resp.Body)
|
||||
return resp.Status, resp.Body
|
||||
}
|
||||
defer func() {
|
||||
RespCache.Insert(reqId, Resp{
|
||||
RespCache.Add(reqId, Resp{
|
||||
Status: status,
|
||||
Body: body,
|
||||
})
|
||||
|
||||
+1
-2
@@ -12,7 +12,6 @@ require (
|
||||
github.com/golang-jwt/jwt/v5 v5.2.2
|
||||
github.com/gorilla/websocket v1.5.3
|
||||
github.com/json-iterator/go v1.1.12
|
||||
github.com/matoous/go-nanoid v1.5.0
|
||||
github.com/mattn/go-sqlite3 v1.14.22
|
||||
github.com/miekg/dns v1.1.72
|
||||
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
|
||||
@@ -55,7 +54,7 @@ require (
|
||||
github.com/golang/protobuf v1.5.4 // indirect
|
||||
github.com/google/pprof v0.0.0-20250208200701-d0013a598941 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7
|
||||
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
|
||||
github.com/leodido/go-urn v1.4.0 // indirect
|
||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
|
||||
|
||||
@@ -113,8 +113,6 @@ github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ
|
||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
|
||||
github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40 h1:EnfXoSqDfSNJv0VBNqY/88RNnhSGYkrHaO0mmFGbVsc=
|
||||
github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40/go.mod h1:vy1vK6wD6j7xX6O6hXe621WabdtNkou2h7uRtTfRMyg=
|
||||
github.com/matoous/go-nanoid v1.5.0 h1:VRorl6uCngneC4oUQqOYtO3S0H5QKFtKuKycFG3euek=
|
||||
github.com/matoous/go-nanoid v1.5.0/go.mod h1:zyD2a71IubI24efhpvkJz+ZwfwagzgSO6UNiFsZKN7U=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
|
||||
|
||||
@@ -1,112 +0,0 @@
|
||||
package lru
|
||||
|
||||
import (
|
||||
"container/list"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type LimitStrategy int
|
||||
|
||||
const (
|
||||
FixedLength LimitStrategy = iota
|
||||
FixedTimeout
|
||||
)
|
||||
|
||||
type LRU struct {
|
||||
list *list.List
|
||||
index map[interface{}]*list.Element
|
||||
reverseIndex map[*list.Element]interface{}
|
||||
mutex sync.Mutex
|
||||
strategy LimitStrategy
|
||||
limit int64
|
||||
}
|
||||
|
||||
type EncapsulatedValue struct {
|
||||
Value interface{}
|
||||
LastUseTime time.Time
|
||||
}
|
||||
|
||||
func New(strategy LimitStrategy, limit int64) *LRU {
|
||||
return &LRU{
|
||||
index: make(map[interface{}]*list.Element),
|
||||
reverseIndex: make(map[*list.Element]interface{}),
|
||||
list: list.New(),
|
||||
strategy: strategy,
|
||||
limit: limit,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *LRU) GetOrInsert(key interface{}, valFunc func() (val interface{})) (val interface{}, removed []*EncapsulatedValue) {
|
||||
l.mutex.Lock()
|
||||
defer l.mutex.Unlock()
|
||||
val = l.get(key)
|
||||
if val == nil {
|
||||
val := valFunc()
|
||||
return val, l.insert(key, val)
|
||||
}
|
||||
return val, nil
|
||||
}
|
||||
|
||||
func (l *LRU) Get(key interface{}) (value interface{}) {
|
||||
l.mutex.Lock()
|
||||
defer l.mutex.Unlock()
|
||||
return l.get(key)
|
||||
}
|
||||
|
||||
func (l *LRU) get(key interface{}) (value interface{}) {
|
||||
v, ok := l.index[key]
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
l.list.MoveToFront(v)
|
||||
ev := v.Value.(*EncapsulatedValue)
|
||||
ev.LastUseTime = time.Now()
|
||||
return ev.Value
|
||||
}
|
||||
|
||||
func (l *LRU) Insert(key interface{}, val interface{}) (removed []*EncapsulatedValue) {
|
||||
l.mutex.Lock()
|
||||
defer l.mutex.Unlock()
|
||||
return l.insert(key, val)
|
||||
}
|
||||
|
||||
func (l *LRU) insert(key interface{}, val interface{}) (removed []*EncapsulatedValue) {
|
||||
ev := &EncapsulatedValue{
|
||||
Value: val,
|
||||
LastUseTime: time.Now(),
|
||||
}
|
||||
node := l.list.PushFront(ev)
|
||||
l.index[key] = node
|
||||
l.reverseIndex[node] = key
|
||||
switch l.strategy {
|
||||
case FixedLength:
|
||||
if int64(len(l.index)) > l.limit {
|
||||
back := l.list.Back()
|
||||
removed = []*EncapsulatedValue{back.Value.(*EncapsulatedValue)}
|
||||
key := l.reverseIndex[back]
|
||||
l.list.Remove(back)
|
||||
delete(l.index, key)
|
||||
delete(l.reverseIndex, back)
|
||||
}
|
||||
case FixedTimeout:
|
||||
now := time.Now()
|
||||
// pop timeout exceeded nodes until the last node does not exceed
|
||||
for {
|
||||
back := l.list.Back()
|
||||
if back == nil {
|
||||
break
|
||||
}
|
||||
ev := back.Value.(*EncapsulatedValue)
|
||||
if int64(now.Sub(ev.LastUseTime)) < l.limit {
|
||||
break
|
||||
}
|
||||
removed = append(removed, ev)
|
||||
key := l.reverseIndex[back]
|
||||
l.list.Remove(back)
|
||||
delete(l.index, key)
|
||||
delete(l.reverseIndex, back)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
// Static trie
|
||||
package trie
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type cast map[rune]*next
|
||||
|
||||
type next struct {
|
||||
*node
|
||||
str *string
|
||||
}
|
||||
|
||||
type node struct {
|
||||
c cast
|
||||
end bool
|
||||
}
|
||||
|
||||
type Trie struct {
|
||||
root *node
|
||||
}
|
||||
|
||||
func newNode() *node {
|
||||
return &node{
|
||||
c: cast{},
|
||||
end: false,
|
||||
}
|
||||
}
|
||||
|
||||
func New(dict []string) (trie *Trie) {
|
||||
var t Trie
|
||||
var ok bool
|
||||
var p *node
|
||||
t.root = newNode()
|
||||
for _, d := range dict {
|
||||
p = t.root
|
||||
for i, r := range d {
|
||||
_, ok = p.c[r]
|
||||
if !ok {
|
||||
n := next{
|
||||
node: newNode(),
|
||||
str: nil,
|
||||
}
|
||||
p.c[r] = &n
|
||||
}
|
||||
p = p.c[r].node
|
||||
if i == len(d)-1 {
|
||||
p.end = true
|
||||
}
|
||||
}
|
||||
}
|
||||
//make jump
|
||||
makeJump(t.root)
|
||||
return &t
|
||||
}
|
||||
|
||||
func fastJump(from *next, to *next, str *string) {
|
||||
from.str = str
|
||||
from.node = to.node
|
||||
}
|
||||
|
||||
func _makeJump(cur *next, from *next, builder *strings.Builder) {
|
||||
var fork bool
|
||||
if cur.node.end || len(cur.node.c) > 1 {
|
||||
if builder.Len() > 1 {
|
||||
s := builder.String()
|
||||
fastJump(from, cur, &s)
|
||||
}
|
||||
fork = true
|
||||
}
|
||||
for k := range cur.node.c {
|
||||
child := cur.node.c[k]
|
||||
if fork {
|
||||
from = child
|
||||
builder = new(strings.Builder)
|
||||
}
|
||||
builder.WriteRune(k)
|
||||
_makeJump(child, from, builder)
|
||||
}
|
||||
}
|
||||
|
||||
func makeJump(root *node) {
|
||||
//DFS
|
||||
for k := range root.c {
|
||||
builder := new(strings.Builder)
|
||||
builder.WriteRune(k)
|
||||
_makeJump(root.c[k], root.c[k], builder)
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Trie) Match(str string) (prefix string) {
|
||||
var builder strings.Builder
|
||||
var runes = []rune(str)
|
||||
var length = len(runes)
|
||||
p := t.root
|
||||
for i := 0; i < length; i++ {
|
||||
r := runes[i]
|
||||
tmp, ok := p.c[r]
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if tmp.str == nil {
|
||||
builder.WriteRune(r)
|
||||
} else {
|
||||
if lenTmp := len(*tmp.str); builder.Len()+lenTmp <= length {
|
||||
if string(runes[i:lenTmp+i]) == *tmp.str {
|
||||
builder.WriteString(*tmp.str)
|
||||
i += len(*tmp.str) - 1
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if tmp.node.end {
|
||||
if builder.Len() <= length {
|
||||
prefix = builder.String()
|
||||
if len(prefix) == length {
|
||||
break
|
||||
}
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
p = tmp.node
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package trie
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTrie_Match(t *testing.T) {
|
||||
trie := New([]string{
|
||||
"12",
|
||||
"12345",
|
||||
"1234567",
|
||||
"2222",
|
||||
"1",
|
||||
})
|
||||
test := [][2]string{
|
||||
{"1", "1"},
|
||||
{"123", "12"},
|
||||
{"1233", "12"},
|
||||
{"12345", "12345"},
|
||||
{"123456", "12345"},
|
||||
{"1234567", "1234567"},
|
||||
{"123456789", "1234567"},
|
||||
{"222", ""},
|
||||
{"2222", "2222"},
|
||||
{"22222", "2222"},
|
||||
{"122", "12"},
|
||||
}
|
||||
for _, tt := range test {
|
||||
if p := trie.Match(tt[0]); p == tt[1] {
|
||||
t.Log(tt[0], "match prefix", p)
|
||||
} else {
|
||||
t.Error(tt[0], "expect", tt[1], "wrong prefix", p)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,9 +33,8 @@ func ReqCache(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
glen.reqMu.Lock()
|
||||
if resp := common.RespCache.Get(reqId); resp != nil {
|
||||
if resp, ok := common.RespCache.Get(reqId); ok {
|
||||
glen.reqMu.Unlock()
|
||||
resp := resp.(common.Resp)
|
||||
ctx.AbortWithStatusJSON(resp.Status, resp.Body)
|
||||
return
|
||||
}
|
||||
@@ -56,8 +55,7 @@ func ReqCache(ctx *gin.Context) {
|
||||
}
|
||||
glen.reqMu.Unlock()
|
||||
}()
|
||||
if resp := common.RespCache.Get(reqId); resp != nil {
|
||||
resp := resp.(common.Resp)
|
||||
if resp, ok := common.RespCache.Get(reqId); ok {
|
||||
ctx.AbortWithStatusJSON(resp.Status, resp.Body)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
package proxyWithHttp
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"github.com/v2rayA/v2rayA/pkg/util/log"
|
||||
"golang.org/x/net/proxy"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type direct struct{}
|
||||
|
||||
// Direct is a direct proxy: one that makes network connections directly.
|
||||
var Direct = direct{}
|
||||
|
||||
func (direct) Dial(network, addr string) (net.Conn, error) {
|
||||
return net.Dial(network, addr)
|
||||
}
|
||||
|
||||
// httpsDialer
|
||||
type httpsDialer struct{}
|
||||
|
||||
// HTTPSDialer is a https proxy: one that makes network connections on tls.
|
||||
var HttpsDialer = httpsDialer{}
|
||||
var TlsConfig = &tls.Config{}
|
||||
|
||||
func (d httpsDialer) Dial(network, addr string) (c net.Conn, err error) {
|
||||
c, err = tls.Dial("tcp", addr, TlsConfig)
|
||||
if err != nil {
|
||||
log.Warn("%v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// proxyWithHttp is a HTTP/HTTPS connect proxy.
|
||||
type httpProxy struct {
|
||||
host string
|
||||
haveAuth bool
|
||||
username string
|
||||
password string
|
||||
forward proxy.Dialer
|
||||
}
|
||||
|
||||
func newHTTPSProxy(uri *url.URL, forward proxy.Dialer) (proxy.Dialer, error) {
|
||||
return newHTTPProxy(uri, HttpsDialer)
|
||||
}
|
||||
|
||||
func newHTTPProxy(uri *url.URL, forward proxy.Dialer) (proxy.Dialer, error) {
|
||||
s := new(httpProxy)
|
||||
s.host = uri.Host
|
||||
s.forward = forward
|
||||
if uri.User != nil {
|
||||
s.haveAuth = true
|
||||
s.username = uri.User.Username()
|
||||
s.password, _ = uri.User.Password()
|
||||
}
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func (s *httpProxy) Dial(network, addr string) (net.Conn, error) {
|
||||
// Dial and create the https client connection.
|
||||
c, err := s.forward.Dial("tcp", s.host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// HACK. http.ReadRequest also does this.
|
||||
reqURL, err := url.Parse("http://" + addr)
|
||||
if err != nil {
|
||||
c.Close()
|
||||
return nil, err
|
||||
}
|
||||
reqURL.Scheme = ""
|
||||
|
||||
req, err := http.NewRequest("CONNECT", reqURL.String(), nil)
|
||||
if err != nil {
|
||||
c.Close()
|
||||
return nil, err
|
||||
}
|
||||
req.Close = false
|
||||
if s.haveAuth {
|
||||
req.SetBasicAuth(s.username, s.password)
|
||||
req.Header.Set("Proxy-Authorization", req.Header.Get("Authorization"))
|
||||
req.Header.Del("Authorization")
|
||||
}
|
||||
req.Header.Set("User-Agent", "v2rayA")
|
||||
|
||||
err = req.Write(c)
|
||||
if err != nil {
|
||||
c.Close()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := http.ReadResponse(bufio.NewReader(c), req)
|
||||
if err != nil {
|
||||
if resp != nil {
|
||||
resp.Body.Close()
|
||||
}
|
||||
c.Close()
|
||||
return nil, err
|
||||
}
|
||||
resp.Body.Close()
|
||||
if resp.StatusCode != 200 {
|
||||
c.Close()
|
||||
err = fmt.Errorf("Connect server using proxy error, StatusCode [%d]", resp.StatusCode)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func FromURL(u *url.URL, forward proxy.Dialer) (proxy.Dialer, error) {
|
||||
return proxy.FromURL(u, forward)
|
||||
}
|
||||
|
||||
func FromEnvironment() proxy.Dialer {
|
||||
return proxy.FromEnvironment()
|
||||
}
|
||||
|
||||
func init() {
|
||||
proxy.RegisterDialerType("http", newHTTPProxy)
|
||||
proxy.RegisterDialerType("https", newHTTPSProxy)
|
||||
}
|
||||
Reference in new issue
Block a user