mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-02-11 19:34:11 +00:00
Chore: Make some Maps into real Sets (#4362)
This commit is contained in:
parent
e893fa1828
commit
ae327eb7e6
@ -23,7 +23,7 @@ type DynamicInboundHandler struct {
|
|||||||
receiverConfig *proxyman.ReceiverConfig
|
receiverConfig *proxyman.ReceiverConfig
|
||||||
streamSettings *internet.MemoryStreamConfig
|
streamSettings *internet.MemoryStreamConfig
|
||||||
portMutex sync.Mutex
|
portMutex sync.Mutex
|
||||||
portsInUse map[net.Port]bool
|
portsInUse map[net.Port]struct{}
|
||||||
workerMutex sync.RWMutex
|
workerMutex sync.RWMutex
|
||||||
worker []worker
|
worker []worker
|
||||||
lastRefresh time.Time
|
lastRefresh time.Time
|
||||||
@ -39,7 +39,7 @@ func NewDynamicInboundHandler(ctx context.Context, tag string, receiverConfig *p
|
|||||||
tag: tag,
|
tag: tag,
|
||||||
proxyConfig: proxyConfig,
|
proxyConfig: proxyConfig,
|
||||||
receiverConfig: receiverConfig,
|
receiverConfig: receiverConfig,
|
||||||
portsInUse: make(map[net.Port]bool),
|
portsInUse: make(map[net.Port]struct{}),
|
||||||
mux: mux.NewServer(ctx),
|
mux: mux.NewServer(ctx),
|
||||||
v: v,
|
v: v,
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
@ -84,7 +84,7 @@ func (h *DynamicInboundHandler) allocatePort() net.Port {
|
|||||||
port := net.Port(allPorts[r])
|
port := net.Port(allPorts[r])
|
||||||
_, used := h.portsInUse[port]
|
_, used := h.portsInUse[port]
|
||||||
if !used {
|
if !used {
|
||||||
h.portsInUse[port] = true
|
h.portsInUse[port] = struct{}{}
|
||||||
return port
|
return port
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -180,12 +180,12 @@ func UClient(c net.Conn, config *Config, ctx context.Context, dest net.Destinati
|
|||||||
prefix := []byte("https://" + uConn.ServerName)
|
prefix := []byte("https://" + uConn.ServerName)
|
||||||
maps.Lock()
|
maps.Lock()
|
||||||
if maps.maps == nil {
|
if maps.maps == nil {
|
||||||
maps.maps = make(map[string]map[string]bool)
|
maps.maps = make(map[string]map[string]struct{})
|
||||||
}
|
}
|
||||||
paths := maps.maps[uConn.ServerName]
|
paths := maps.maps[uConn.ServerName]
|
||||||
if paths == nil {
|
if paths == nil {
|
||||||
paths = make(map[string]bool)
|
paths = make(map[string]struct{})
|
||||||
paths[config.SpiderX] = true
|
paths[config.SpiderX] = struct{}{}
|
||||||
maps.maps[uConn.ServerName] = paths
|
maps.maps[uConn.ServerName] = paths
|
||||||
}
|
}
|
||||||
firstURL := string(prefix) + getPathLocked(paths)
|
firstURL := string(prefix) + getPathLocked(paths)
|
||||||
@ -232,7 +232,7 @@ func UClient(c net.Conn, config *Config, ctx context.Context, dest net.Destinati
|
|||||||
for _, m := range href.FindAllSubmatch(body, -1) {
|
for _, m := range href.FindAllSubmatch(body, -1) {
|
||||||
m[1] = bytes.TrimPrefix(m[1], prefix)
|
m[1] = bytes.TrimPrefix(m[1], prefix)
|
||||||
if !bytes.Contains(m[1], dot) {
|
if !bytes.Contains(m[1], dot) {
|
||||||
paths[string(m[1])] = true
|
paths[string(m[1])] = struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
req.URL.Path = getPathLocked(paths)
|
req.URL.Path = getPathLocked(paths)
|
||||||
@ -267,10 +267,10 @@ var (
|
|||||||
|
|
||||||
var maps struct {
|
var maps struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
maps map[string]map[string]bool
|
maps map[string]map[string]struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPathLocked(paths map[string]bool) string {
|
func getPathLocked(paths map[string]struct{}) string {
|
||||||
stopAt := int(randBetween(0, int64(len(paths)-1)))
|
stopAt := int(randBetween(0, int64(len(paths)-1)))
|
||||||
i := 0
|
i := 0
|
||||||
for s := range paths {
|
for s := range paths {
|
||||||
|
Loading…
Reference in New Issue
Block a user