1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-04 19:17:38 +08:00

highway: fix upload exciting

This commit is contained in:
wdvxdr 2022-06-15 20:28:56 +08:00
parent 87ff2f9591
commit 3f5174dda1
No known key found for this signature in database
GPG Key ID: 703F8C071DE7A1B6
3 changed files with 16 additions and 28 deletions

View File

@ -227,9 +227,11 @@ func (fs *GroupFileSystem) UploadFile(p, name, folderId string) error {
Unknown3: proto.Int32(0), Unknown3: proto.Int32(0),
}) })
client := fs.client client := fs.client
input := highway.ExcitingInput{ input := highway.Transaction{
CommandID: 71, CommandID: 71,
Body: file, Body: file,
Size: size,
Sum: md5Hash,
Ticket: fs.client.highwaySession.SigSession, Ticket: fs.client.highwaySession.SigSession,
Ext: ext, Ext: ext,
} }

View File

@ -14,7 +14,6 @@ import (
"github.com/Mrs4s/MiraiGo/binary" "github.com/Mrs4s/MiraiGo/binary"
"github.com/Mrs4s/MiraiGo/client/pb" "github.com/Mrs4s/MiraiGo/client/pb"
"github.com/Mrs4s/MiraiGo/internal/proto" "github.com/Mrs4s/MiraiGo/internal/proto"
"github.com/Mrs4s/MiraiGo/utils"
) )
// see com/tencent/mobileqq/highway/utils/BaseConstants.java#L120-L121 // see com/tencent/mobileqq/highway/utils/BaseConstants.java#L120-L121
@ -97,31 +96,17 @@ func (s *Session) Upload(addr Addr, trans Transaction) error {
return nil return nil
} }
type ExcitingInput struct { func (s *Session) UploadExciting(trans Transaction) ([]byte, error) {
CommandID int32
Body io.ReadSeeker
Ticket []byte
Ext []byte
}
func (s *Session) UploadExciting(input ExcitingInput) ([]byte, error) {
fileMd5, fileLength := utils.ComputeMd5AndLength(input.Body)
_, _ = input.Body.Seek(0, io.SeekStart)
addr := s.SsoAddr[0] addr := s.SsoAddr[0]
url := fmt.Sprintf("http://%v/cgi-bin/httpconn?htcmd=0x6FF0087&Uin=%v", addr, s.Uin) url := fmt.Sprintf("http://%v/cgi-bin/httpconn?htcmd=0x6FF0087&Uin=%v", addr, s.Uin)
var ( var rspExt []byte
rspExt []byte var offset int64
offset int64 = 0 const chunkSize = 524288
chunkSize = 524288
)
chunk := make([]byte, chunkSize) chunk := make([]byte, chunkSize)
w := binary.SelectWriter()
w.Reset()
w.Grow(600 * 1024) // 复用,600k 不要放回池中
for { for {
chunk = chunk[:chunkSize] chunk = chunk[:chunkSize]
rl, err := io.ReadFull(input.Body, chunk) rl, err := io.ReadFull(trans.Body, chunk)
if err == io.EOF { if rl == 0 {
break break
} }
if err == io.ErrUnexpectedEOF { if err == io.ErrUnexpectedEOF {
@ -129,16 +114,16 @@ func (s *Session) UploadExciting(input ExcitingInput) ([]byte, error) {
} }
ch := md5.Sum(chunk) ch := md5.Sum(chunk)
head, _ := proto.Marshal(&pb.ReqDataHighwayHead{ head, _ := proto.Marshal(&pb.ReqDataHighwayHead{
MsgBasehead: s.dataHighwayHead(_REQ_CMD_DATA, 0, input.CommandID, 0), MsgBasehead: s.dataHighwayHead(_REQ_CMD_DATA, 0, trans.CommandID, 0),
MsgSeghead: &pb.SegHead{ MsgSeghead: &pb.SegHead{
Filesize: fileLength, Filesize: trans.Size,
Dataoffset: offset, Dataoffset: offset,
Datalength: int32(rl), Datalength: int32(rl),
Serviceticket: input.Ticket, Serviceticket: trans.Ticket,
Md5: ch[:], Md5: ch[:],
FileMd5: fileMd5, FileMd5: trans.Sum,
}, },
ReqExtendinfo: input.Ext, ReqExtendinfo: trans.Ext,
}) })
offset += int64(rl) offset += int64(rl)
frame := newFrame(head, chunk) frame := newFrame(head, chunk)
@ -147,6 +132,7 @@ func (s *Session) UploadExciting(input ExcitingInput) ([]byte, error) {
req.Header.Set("Connection", "Keep-Alive") req.Header.Set("Connection", "Keep-Alive")
req.Header.Set("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)") req.Header.Set("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)")
req.Header.Set("Pragma", "no-cache") req.Header.Set("Pragma", "no-cache")
req.ContentLength = int64(len(head) + len(chunk) + 10)
rsp, err := http.DefaultClient.Do(req) rsp, err := http.DefaultClient.Do(req)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "request error") return nil, errors.Wrap(err, "request error")

View File

@ -7,7 +7,7 @@ import (
) )
// TODO: move to a new package // TODO: move to a new package
const debug = false const debug = true
type Message = any type Message = any