mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 11:07:40 +08:00
highway: rename BdhInput and Input to Transaction
This commit is contained in:
parent
9422ce4751
commit
33590e4b32
@ -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 {
|
||||
|
@ -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),
|
||||
|
@ -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 {
|
||||
|
@ -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{},
|
||||
})
|
||||
|
@ -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 {
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user