diff --git a/client/group_msg.go b/client/group_msg.go index 9c1a5578..1183ad39 100644 --- a/client/group_msg.go +++ b/client/group_msg.go @@ -2,6 +2,7 @@ package client import ( "bytes" + "crypto/md5" "encoding/base64" "encoding/json" "math" @@ -170,10 +171,13 @@ func (c *QQClient) uploadGroupLongMessage(groupCode int64, m *message.ForwardMes } for i, ip := range rsp.Uint32UpIp { addr := highway.Addr{IP: uint32(ip), Port: int(rsp.Uint32UpPort[i])} - input := highway.Input{ + hash := md5.Sum(body) + input := highway.Transaction{ CommandID: 27, - Key: rsp.MsgSig, + Ticket: rsp.MsgSig, Body: bytes.NewReader(body), + Size: int64(len(body)), + Sum: hash[:], } err := c.highwaySession.Upload(addr, input) if err != nil { diff --git a/client/image.go b/client/image.go index 84b8e810..0764f203 100644 --- a/client/image.go +++ b/client/image.go @@ -92,7 +92,7 @@ func (c *QQClient) uploadGroupOrGuildImage(target message.Source, img io.ReadSee var r any var err error - var input highway.BdhInput + var input highway.Transaction switch target.SourceType { case message.SourceGroup: r, err = c.sendAndWait(c.buildGroupImageStorePacket(target.PrimaryID, fh, int32(length))) @@ -115,7 +115,7 @@ func (c *QQClient) uploadGroupOrGuildImage(target message.Source, img io.ReadSee } } - input = highway.BdhInput{ + input = highway.Transaction{ CommandID: cmd, Body: img, Size: length, @@ -322,7 +322,7 @@ func (c *QQClient) uploadOcrImage(img io.Reader, size int32, sum []byte) (string Uuid: binary.GenUUID(r), }) - rsp, err := c.highwaySession.UploadBDH(highway.BdhInput{ + rsp, err := c.highwaySession.UploadBDH(highway.Transaction{ CommandID: 76, Body: img, Size: int64(size), diff --git a/client/internal/highway/bdh.go b/client/internal/highway/bdh.go index 97d571f3..54622a7f 100644 --- a/client/internal/highway/bdh.go +++ b/client/internal/highway/bdh.go @@ -16,7 +16,7 @@ import ( "github.com/Mrs4s/MiraiGo/internal/proto" ) -type BdhInput struct { +type Transaction struct { CommandID int32 Body io.Reader Sum []byte // md5 sum of body @@ -26,7 +26,7 @@ type BdhInput struct { Encrypt bool } -func (bdh *BdhInput) encrypt(key []byte) error { +func (bdh *Transaction) encrypt(key []byte) error { if bdh.Encrypt { if len(key) == 0 { return errors.New("session key not found. maybe miss some packet?") @@ -36,7 +36,7 @@ func (bdh *BdhInput) encrypt(key []byte) error { return nil } -func (s *Session) UploadBDH(input BdhInput) ([]byte, error) { +func (s *Session) UploadBDH(input Transaction) ([]byte, error) { if len(s.SsoAddr) == 0 { return nil, errors.New("srv addrs not found. maybe miss some packet?") } @@ -108,7 +108,7 @@ func (s *Session) UploadBDH(input BdhInput) ([]byte, error) { return rspExt, nil } -func (s *Session) UploadBDHMultiThread(input BdhInput, threadCount int) ([]byte, error) { +func (s *Session) UploadBDHMultiThread(input Transaction, threadCount int) ([]byte, error) { // for small file and small thread count, // use UploadBDH instead of UploadBDHMultiThread if input.Size < 1024*1024*3 || threadCount < 2 { diff --git a/client/internal/highway/highway.go b/client/internal/highway/highway.go index f641c94d..9447d407 100644 --- a/client/internal/highway/highway.go +++ b/client/internal/highway/highway.go @@ -47,15 +47,7 @@ func (s *Session) AppendAddr(ip, port uint32) { s.SsoAddr = append(s.SsoAddr, addr) } -type Input struct { - CommandID int32 - Key []byte - Body io.ReadSeeker -} - -func (s *Session) Upload(addr Addr, input Input) error { - fh, length := utils.ComputeMd5AndLength(input.Body) - _, _ = input.Body.Seek(0, io.SeekStart) +func (s *Session) Upload(addr Addr, input Transaction) error { conn, err := net.DialTimeout("tcp", addr.String(), time.Second*3) if err != nil { return errors.Wrap(err, "connect error") @@ -79,12 +71,12 @@ func (s *Session) Upload(addr Addr, input Input) error { head, _ := proto.Marshal(&pb.ReqDataHighwayHead{ MsgBasehead: s.dataHighwayHead(_REQ_CMD_DATA, 4096, input.CommandID, 2052), MsgSeghead: &pb.SegHead{ - Filesize: length, + Filesize: input.Size, Dataoffset: int64(offset), Datalength: int32(rl), - Serviceticket: input.Key, + Serviceticket: input.Ticket, Md5: ch[:], - FileMd5: fh, + FileMd5: input.Sum, }, ReqExtendinfo: []byte{}, }) diff --git a/client/multimsg.go b/client/multimsg.go index 1050a17b..8ca22486 100644 --- a/client/multimsg.go +++ b/client/multimsg.go @@ -294,10 +294,13 @@ func (builder *ForwardMessageBuilder) Main(m *message.ForwardMessage) *message.F content := forwardDisplay(rsp.MsgResid, filename, m.Preview(), fmt.Sprintf("查看 %d 条转发消息", m.Length())) for i, ip := range rsp.Uint32UpIp { addr := highway.Addr{IP: uint32(ip), Port: int(rsp.Uint32UpPort[i])} - input := highway.Input{ + hash := md5.Sum(body) + input := highway.Transaction{ CommandID: 27, - Key: rsp.MsgSig, + Ticket: rsp.MsgSig, Body: bytes.NewReader(body), + Sum: hash[:], + Size: int64(len(body)), } err := c.highwaySession.Upload(addr, input) if err != nil { diff --git a/client/ptt.go b/client/ptt.go index 024d3097..6ea82280 100644 --- a/client/ptt.go +++ b/client/ptt.go @@ -73,7 +73,7 @@ func (c *QQClient) UploadVoice(target message.Source, voice io.ReadSeeker) (*mes ext = c.buildGroupPttStoreBDHExt(target.PrimaryID, fh, int32(length), 0, int32(length)) } // multi-thread upload is no need - rsp, err := c.highwaySession.UploadBDH(highway.BdhInput{ + rsp, err := c.highwaySession.UploadBDH(highway.Transaction{ CommandID: cmd, Body: voice, Sum: fh, @@ -157,7 +157,7 @@ func (c *QQClient) UploadShortVideo(target message.Source, video, thumb io.ReadS } ext, _ := proto.Marshal(c.buildPttShortVideoProto(target, videoSum, thumbSum, videoLen, thumbLen).PttShortVideoUploadReq) combined := utils.MultiReadSeeker(thumb, video) - input := highway.BdhInput{ + input := highway.Transaction{ CommandID: cmd, Body: combined, Size: videoLen + thumbLen,