diff --git a/cmd/gocq/main.go b/cmd/gocq/main.go index 2e6c85a67..852eb01e5 100644 --- a/cmd/gocq/main.go +++ b/cmd/gocq/main.go @@ -364,7 +364,7 @@ func LoginInteract() { }) saveToken() cli.AllowSlider = true - download.SetGlobalTimeout(time.Duration(base.HTTPTimeout) * time.Second) // 在登录完成后设置, 防止在堵塞协议更新 + download.SetTimeout(time.Duration(base.HTTPTimeout) * time.Second) // 在登录完成后设置, 防止在堵塞协议更新 log.Infof("登录成功 欢迎使用: %v", cli.Nickname) log.Info("开始加载好友列表...") global.Check(cli.ReloadFriendList(), true) diff --git a/internal/download/download.go b/internal/download/download.go index 7622e4c4e..a82af5ad5 100644 --- a/internal/download/download.go +++ b/internal/download/download.go @@ -4,6 +4,7 @@ package download import ( "bufio" "compress/gzip" + "crypto/tls" "fmt" "io" "net/http" @@ -22,15 +23,28 @@ import ( var client = &http.Client{ Transport: &http.Transport{ - Proxy: func(request *http.Request) (u *url.URL, e error) { + Proxy: func(request *http.Request) (*url.URL, error) { if base.Proxy == "" { return http.ProxyFromEnvironment(request) } return url.Parse(base.Proxy) }, - ForceAttemptHTTP2: false, - MaxConnsPerHost: 0, - MaxIdleConns: 0, + // Disable http2 + TLSNextProto: map[string]func(authority string, c *tls.Conn) http.RoundTripper{}, + MaxIdleConnsPerHost: 999, + }, + Timeout: time.Second * 5, +} + +var clienth2 = &http.Client{ + Transport: &http.Transport{ + Proxy: func(request *http.Request) (*url.URL, error) { + if base.Proxy == "" { + return http.ProxyFromEnvironment(request) + } + return url.Parse(base.Proxy) + }, + ForceAttemptHTTP2: true, MaxIdleConnsPerHost: 999, }, Timeout: time.Second * 5, @@ -42,11 +56,13 @@ var ErrOverSize = errors.New("oversize") // UserAgent HTTP请求时使用的UA const UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.66" -func SetGlobalTimeout(t time.Duration) { +// SetTimeout set internal/download client timeout +func SetTimeout(t time.Duration) { if t == 0 { t = time.Second * 10 } client.Timeout = t + clienth2.Timeout = t } // Request is a file download request @@ -58,6 +74,13 @@ type Request struct { Body io.Reader } +func (r Request) client() *http.Client { + if strings.Contains(r.URL, "go-cqhttp.org") { + return clienth2 + } + return client +} + func (r Request) do() (*http.Response, error) { if r.Method == "" { r.Method = http.MethodGet @@ -72,7 +95,7 @@ func (r Request) do() (*http.Response, error) { req.Header.Set(k, v) } - return client.Do(req) + return r.client().Do(req) } func (r Request) body() (io.ReadCloser, error) { diff --git a/internal/encryption/t544/encryption.go b/internal/encryption/t544/encryption.go index 1c2f3e4ee..a2c6bade3 100644 --- a/internal/encryption/t544/encryption.go +++ b/internal/encryption/t544/encryption.go @@ -44,6 +44,7 @@ func sub_e(*[256][6]byte, []byte) //go:noescape func sub_f(*[16]byte, *[15]uint32, *[16][16]byte) (w [44]uint32) +//go:noescape func sub_aa(int, *[16][2][16][16]byte, *[16]byte, []byte) byte // transformInner see com/tencent/mobileqq/dt/model/FEBound diff --git a/pkg/onebot/value.go b/pkg/onebot/value.go index 6192ef881..eefa73d94 100644 --- a/pkg/onebot/value.go +++ b/pkg/onebot/value.go @@ -31,6 +31,7 @@ type ( // Kind is the kind of Value. type Kind int +// Kind const ( KindAny Kind = iota KindBool