mirror of
https://github.com/v2rayA/v2rayA.git
synced 2026-10-20 16:05:18 +08:00
833af7dc74
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.
64 lines
1.0 KiB
Go
64 lines
1.0 KiB
Go
package reqCache
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/v2rayA/v2rayA/common"
|
|
"sync"
|
|
)
|
|
|
|
type requestLock struct {
|
|
sync.Mutex
|
|
users int
|
|
}
|
|
|
|
type reqGlen struct {
|
|
reqIdMu map[string]*requestLock
|
|
reqMu sync.Mutex
|
|
}
|
|
|
|
func newReqGlen() *reqGlen {
|
|
return &reqGlen{
|
|
reqIdMu: make(map[string]*requestLock),
|
|
reqMu: sync.Mutex{},
|
|
}
|
|
}
|
|
|
|
var (
|
|
glen = newReqGlen()
|
|
)
|
|
|
|
func ReqCache(ctx *gin.Context) {
|
|
reqId := ctx.GetHeader(common.RequestIdHeader)
|
|
if reqId == "" {
|
|
return
|
|
}
|
|
glen.reqMu.Lock()
|
|
if resp, ok := common.RespCache.Get(reqId); ok {
|
|
glen.reqMu.Unlock()
|
|
ctx.AbortWithStatusJSON(resp.Status, resp.Body)
|
|
return
|
|
}
|
|
mu, ok := glen.reqIdMu[reqId]
|
|
if !ok {
|
|
mu = new(requestLock)
|
|
glen.reqIdMu[reqId] = mu
|
|
}
|
|
mu.users++
|
|
glen.reqMu.Unlock()
|
|
mu.Lock()
|
|
defer func() {
|
|
mu.Unlock()
|
|
glen.reqMu.Lock()
|
|
mu.users--
|
|
if mu.users == 0 {
|
|
delete(glen.reqIdMu, reqId)
|
|
}
|
|
glen.reqMu.Unlock()
|
|
}()
|
|
if resp, ok := common.RespCache.Get(reqId); ok {
|
|
ctx.AbortWithStatusJSON(resp.Status, resp.Body)
|
|
return
|
|
}
|
|
ctx.Next()
|
|
}
|