replace cloudflare-bpc with utls (#58)

* replace cloudflare-bpc with utls

* fix test

* ci: skip utls test
This commit is contained in:
UUBulb
2024-08-28 23:21:25 +08:00
committed by GitHub
parent 42187f2bf2
commit c8134a8b86
9 changed files with 368 additions and 37 deletions
+9 -12
View File
@@ -17,13 +17,13 @@ import (
"strings"
"time"
bpc "github.com/DaRealFreak/cloudflare-bp-go"
"github.com/blang/semver"
"github.com/ebi-yade/altsvc-go"
"github.com/go-ping/ping"
"github.com/nezhahq/go-github-selfupdate/selfupdate"
"github.com/nezhahq/service"
"github.com/quic-go/quic-go/http3"
utls "github.com/refraction-networking/utls"
"github.com/shirou/gopsutil/v4/host"
"github.com/spf13/cobra"
"google.golang.org/grpc"
@@ -36,6 +36,7 @@ import (
"github.com/nezhahq/agent/pkg/processgroup"
"github.com/nezhahq/agent/pkg/pty"
"github.com/nezhahq/agent/pkg/util"
utlsx "github.com/nezhahq/agent/pkg/utls"
pb "github.com/nezhahq/agent/proto"
)
@@ -95,7 +96,6 @@ var (
const (
delayWhenError = time.Second * 10 // Agent 重连间隔
networkTimeOut = time.Second * 5 // 普通网络超时
macOSChromeUA = ""
)
func init() {
@@ -121,15 +121,12 @@ func init() {
return nil, err
}
headers := util.BrowserHeaders()
http.DefaultClient.Timeout = time.Second * 30
httpClient.Transport = bpc.AddCloudFlareByPass(httpClient.Transport, bpc.Options{
AddMissingHeaders: true,
Headers: map[string]string{
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.5",
"User-Agent": monitor.MacOSChromeUA,
},
})
httpClient.Transport = utlsx.NewUTLSHTTPRoundTripperWithProxy(
utls.HelloChrome_Auto, new(utls.Config),
http.DefaultTransport, nil, headers,
)
ex, err := os.Executable()
if err != nil {
@@ -725,7 +722,7 @@ func handleTerminalTask(task *pb.Task) {
if remoteData, err = remoteIO.Recv(); err != nil {
return
}
if remoteData.Data == nil || len(remoteData.Data) == 0 {
if len(remoteData.Data) == 0 {
return
}
switch remoteData.Data[0] {
@@ -838,7 +835,7 @@ func handleFMTask(task *pb.Task) {
if remoteData, err = remoteIO.Recv(); err != nil {
return
}
if remoteData.Data == nil || len(remoteData.Data) == 0 {
if len(remoteData.Data) == 0 {
return
}
fmc.DoTask(remoteData)