From 53b3f814cf7958dfaa95d54e84e49a9f13db08b6 Mon Sep 17 00:00:00 2001 From: LXY1226 <767763591@qq.com> Date: Mon, 3 Aug 2020 06:46:55 +0800 Subject: [PATCH] [Temporary] Changed Dial to TCPDial to prevent useless conversion --- client/client.go | 13 ++++++------- client/highway.go | 9 +++++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/client/client.go b/client/client.go index d1199899..d96f44af 100644 --- a/client/client.go +++ b/client/client.go @@ -17,7 +17,6 @@ import ( "math" "math/rand" "net" - "strconv" "sync" "sync/atomic" "time" @@ -339,8 +338,7 @@ func (c *QQClient) sendGroupLongOrForwardMessage(groupCode int64, isLong bool, m }, }) for i, ip := range rsp.Uint32UpIp { - updServer := binary.UInt32ToIPV4Address(uint32(ip)) - err := c.highwayUploadImage(updServer+":"+strconv.FormatInt(int64(rsp.Uint32UpPort[i]), 10), rsp.MsgSig, body, 27) + err := c.highwayUploadImage(uint32(ip), int(rsp.Uint32UpPort[i]), rsp.MsgSig, body, 27) if err == nil { if !isLong { var pv string @@ -382,17 +380,18 @@ func (c *QQClient) UploadGroupImage(groupCode int64, img []byte) (*message.Group return nil, errors.New(rsp.Message) } if rsp.IsExists { - return message.NewGroupImage(binary.CalculateImageResourceId(h[:]), h[:]), nil + goto ok } for i, ip := range rsp.UploadIp { - updServer := binary.UInt32ToIPV4Address(uint32(ip)) - err := c.highwayUploadImage(updServer+":"+strconv.FormatInt(int64(rsp.UploadPort[i]), 10), rsp.UploadKey, img, 2) + err := c.highwayUploadImage(uint32(ip), int(rsp.UploadPort[i]), rsp.UploadKey, img, 2) if err != nil { continue } - return message.NewGroupImage(binary.CalculateImageResourceId(h[:]), h[:]), nil + goto ok } return nil, errors.New("upload failed") +ok: + return message.NewGroupImage(binary.CalculateImageResourceId(h[:]), h[:]), nil } func (c *QQClient) UploadPrivateImage(target int64, img []byte) (*message.FriendImageElement, error) { diff --git a/client/highway.go b/client/highway.go index 1f79a335..71117466 100644 --- a/client/highway.go +++ b/client/highway.go @@ -10,8 +10,13 @@ import ( "time" ) -func (c *QQClient) highwayUploadImage(ser string, updKey, img []byte, cmdId int32) error { - conn, err := net.DialTimeout("tcp", ser, time.Second*5) +func (c *QQClient) highwayUploadImage(ip uint32, port int, updKey, img []byte, cmdId int32) error { + addr := net.TCPAddr{ + IP: make([]byte, 4), + Port: port, + } + conn, err := net.DialTCP("tcp", nil, &addr) + println("connected") if err != nil { return err }