Skip to content
This repository was archived by the owner on Aug 11, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion core/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions core/client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
28 changes: 20 additions & 8 deletions core/client/websim.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading