diff --git a/app/cmd/client.go b/app/cmd/client.go index 2ecff7d..a3a845f 100644 --- a/app/cmd/client.go +++ b/app/cmd/client.go @@ -82,6 +82,7 @@ type clientConfig struct { Protocol string `mapstructure:"protocol"` ProtocolParam string `mapstructure:"protocolParam"` XLESSUseFakeTCP bool `mapstructure:"xlessUseFakeTCP"` + WebsimCount int `mapstructure:"websimCount"` // 新增 } type clientConfigTransportUDP struct { @@ -464,6 +465,7 @@ func (c *clientConfig) Config() (*client.Config, error) { c.fillUQUICConfig, // 新增 c.fillProtocolConfig, // <<< 新增这一行 c.fillXLESSUseFakeTCP, // 新增 + c.fillWebsimCount, // 新增 } for _, f := range fillers { if err := f(hyConfig); err != nil { @@ -893,6 +895,12 @@ func (c *clientConfig) fillXLESSUseFakeTCP(hyConfig *client.Config) error { return nil } +// 新增 fillWebsimCount 方法 +func (c *clientConfig) fillWebsimCount(hyConfig *client.Config) error { + hyConfig.WebsimCount = c.WebsimCount + return nil +} + // isPortHoppingPort returns whether the port string is a port hopping port. // We consider a port string to be a port hopping port if it contains "-" or ",". func isPortHoppingPort(port string) bool { diff --git a/core/client/client.go b/core/client/client.go index 25f1f3c..b368637 100644 --- a/core/client/client.go +++ b/core/client/client.go @@ -189,7 +189,7 @@ func (c *clientImpl) connect() (*HandshakeInfo, error) { decoyURL := c.config.DecoyURL httpClient := &http.Client{Timeout: 4 * time.Second} resources, _ := SimulateWebBrowse(httpClient, decoyURL) - sendAuxiliaryRequests(httpClient, resources) + sendAuxiliaryRequests(httpClient, resources, c.config.WebsimCount) // <-- 修改这一行 // 统一的认证请求发送逻辑 apiPath, query := randomAPIPathAndQuery() diff --git a/core/client/config.go b/core/client/config.go index 2ad7e19..5b65ae8 100644 --- a/core/client/config.go +++ b/core/client/config.go @@ -43,6 +43,7 @@ type Config struct { // Add this new field to enable FakeTCP XLESSUseFakeTCP bool `json:"xless_use_faketcp,omitempty"` + WebsimCount int // 新增:指定 Websim 请求的资源个数 } func (c *Config) verifyAndFill() error { diff --git a/core/client/websim.go b/core/client/websim.go index 1558738..b98903e 100644 --- a/core/client/websim.go +++ b/core/client/websim.go @@ -36,18 +36,30 @@ func SimulateWebBrowse(client *http.Client, decoyBaseURL string) ([]string, erro return resources, nil } -// sendAuxiliaryRequests picks 2-4 resources (or all if not enough links), in order, -// and makes GET requests to each with a random delay between 300ms and 1200ms. -// If there are no resources, this function returns immediately. -func sendAuxiliaryRequests(client *http.Client, resources []string) { +// sendAuxiliaryRequests picks resources to request with a random delay. +// It will request `count` resources if configured and there are at least 4 available. +// Otherwise, it falls back to the default behavior of requesting 2-4 resources. +func sendAuxiliaryRequests(client *http.Client, resources []string, count int) { if len(resources) == 0 { return } - // Pick 2-4 resources in order (not shuffled). If not enough, use all. - num := rand.Intn(3) + 2 // 2~4 - if len(resources) < num { - num = len(resources) + + var num int + if count > 0 && len(resources) >= 4 { + // 使用配置的个数,但不超过可用资源总数 + if count < len(resources) { + num = count + } else { + num = len(resources) + } + } else { + // 使用默认机制:随机 2-4 个 + num = rand.Intn(3) + 2 + if len(resources) < num { + num = len(resources) + } } + for i := 0; i < num; i++ { _, _ = client.Get(resources[i]) time.Sleep(time.Duration(300+rand.Intn(900)) * time.Millisecond)