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 (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/md5"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"math"
|
"math"
|
||||||
@ -170,10 +171,13 @@ func (c *QQClient) uploadGroupLongMessage(groupCode int64, m *message.ForwardMes
|
|||||||
}
|
}
|
||||||
for i, ip := range rsp.Uint32UpIp {
|
for i, ip := range rsp.Uint32UpIp {
|
||||||
addr := highway.Addr{IP: uint32(ip), Port: int(rsp.Uint32UpPort[i])}
|
addr := highway.Addr{IP: uint32(ip), Port: int(rsp.Uint32UpPort[i])}
|
||||||
input := highway.Input{
|
hash := md5.Sum(body)
|
||||||
|
input := highway.Transaction{
|
||||||
CommandID: 27,
|
CommandID: 27,
|
||||||
Key: rsp.MsgSig,
|
Ticket: rsp.MsgSig,
|
||||||
Body: bytes.NewReader(body),
|
Body: bytes.NewReader(body),
|
||||||
|
Size: int64(len(body)),
|
||||||
|
Sum: hash[:],
|
||||||
}
|
}
|
||||||
err := c.highwaySession.Upload(addr, input)
|
err := c.highwaySession.Upload(addr, input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -92,7 +92,7 @@ func (c *QQClient) uploadGroupOrGuildImage(target message.Source, img io.ReadSee
|
|||||||
|
|
||||||
var r any
|
var r any
|
||||||
var err error
|
var err error
|
||||||
var input highway.BdhInput
|
var input highway.Transaction
|
||||||
switch target.SourceType {
|
switch target.SourceType {
|
||||||
case message.SourceGroup:
|
case message.SourceGroup:
|
||||||
r, err = c.sendAndWait(c.buildGroupImageStorePacket(target.PrimaryID, fh, int32(length)))
|
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,
|
CommandID: cmd,
|
||||||
Body: img,
|
Body: img,
|
||||||
Size: length,
|
Size: length,
|
||||||
@ -322,7 +322,7 @@ func (c *QQClient) uploadOcrImage(img io.Reader, size int32, sum []byte) (string
|
|||||||
Uuid: binary.GenUUID(r),
|
Uuid: binary.GenUUID(r),
|
||||||
})
|
})
|
||||||
|
|
||||||
rsp, err := c.highwaySession.UploadBDH(highway.BdhInput{
|
rsp, err := c.highwaySession.UploadBDH(highway.Transaction{
|
||||||
CommandID: 76,
|
CommandID: 76,
|
||||||
Body: img,
|
Body: img,
|
||||||
Size: int64(size),
|
Size: int64(size),
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
"github.com/Mrs4s/MiraiGo/internal/proto"
|
"github.com/Mrs4s/MiraiGo/internal/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BdhInput struct {
|
type Transaction struct {
|
||||||
CommandID int32
|
CommandID int32
|
||||||
Body io.Reader
|
Body io.Reader
|
||||||
Sum []byte // md5 sum of body
|
Sum []byte // md5 sum of body
|
||||||
@ -26,7 +26,7 @@ type BdhInput struct {
|
|||||||
Encrypt bool
|
Encrypt bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bdh *BdhInput) encrypt(key []byte) error {
|
func (bdh *Transaction) encrypt(key []byte) error {
|
||||||
if bdh.Encrypt {
|
if bdh.Encrypt {
|
||||||
if len(key) == 0 {
|
if len(key) == 0 {
|
||||||
return errors.New("session key not found. maybe miss some packet?")
|
return errors.New("session key not found. maybe miss some packet?")
|
||||||
@ -36,7 +36,7 @@ func (bdh *BdhInput) encrypt(key []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Session) UploadBDH(input BdhInput) ([]byte, error) {
|
func (s *Session) UploadBDH(input Transaction) ([]byte, error) {
|
||||||
if len(s.SsoAddr) == 0 {
|
if len(s.SsoAddr) == 0 {
|
||||||
return nil, errors.New("srv addrs not found. maybe miss some packet?")
|
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
|
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,
|
// for small file and small thread count,
|
||||||
// use UploadBDH instead of UploadBDHMultiThread
|
// use UploadBDH instead of UploadBDHMultiThread
|
||||||
if input.Size < 1024*1024*3 || threadCount < 2 {
|
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)
|
s.SsoAddr = append(s.SsoAddr, addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Input struct {
|
func (s *Session) Upload(addr Addr, input Transaction) error {
|
||||||
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)
|
|
||||||
conn, err := net.DialTimeout("tcp", addr.String(), time.Second*3)
|
conn, err := net.DialTimeout("tcp", addr.String(), time.Second*3)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "connect error")
|
return errors.Wrap(err, "connect error")
|
||||||
@ -79,12 +71,12 @@ func (s *Session) Upload(addr Addr, input Input) error {
|
|||||||
head, _ := proto.Marshal(&pb.ReqDataHighwayHead{
|
head, _ := proto.Marshal(&pb.ReqDataHighwayHead{
|
||||||
MsgBasehead: s.dataHighwayHead(_REQ_CMD_DATA, 4096, input.CommandID, 2052),
|
MsgBasehead: s.dataHighwayHead(_REQ_CMD_DATA, 4096, input.CommandID, 2052),
|
||||||
MsgSeghead: &pb.SegHead{
|
MsgSeghead: &pb.SegHead{
|
||||||
Filesize: length,
|
Filesize: input.Size,
|
||||||
Dataoffset: int64(offset),
|
Dataoffset: int64(offset),
|
||||||
Datalength: int32(rl),
|
Datalength: int32(rl),
|
||||||
Serviceticket: input.Key,
|
Serviceticket: input.Ticket,
|
||||||
Md5: ch[:],
|
Md5: ch[:],
|
||||||
FileMd5: fh,
|
FileMd5: input.Sum,
|
||||||
},
|
},
|
||||||
ReqExtendinfo: []byte{},
|
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()))
|
content := forwardDisplay(rsp.MsgResid, filename, m.Preview(), fmt.Sprintf("查看 %d 条转发消息", m.Length()))
|
||||||
for i, ip := range rsp.Uint32UpIp {
|
for i, ip := range rsp.Uint32UpIp {
|
||||||
addr := highway.Addr{IP: uint32(ip), Port: int(rsp.Uint32UpPort[i])}
|
addr := highway.Addr{IP: uint32(ip), Port: int(rsp.Uint32UpPort[i])}
|
||||||
input := highway.Input{
|
hash := md5.Sum(body)
|
||||||
|
input := highway.Transaction{
|
||||||
CommandID: 27,
|
CommandID: 27,
|
||||||
Key: rsp.MsgSig,
|
Ticket: rsp.MsgSig,
|
||||||
Body: bytes.NewReader(body),
|
Body: bytes.NewReader(body),
|
||||||
|
Sum: hash[:],
|
||||||
|
Size: int64(len(body)),
|
||||||
}
|
}
|
||||||
err := c.highwaySession.Upload(addr, input)
|
err := c.highwaySession.Upload(addr, input)
|
||||||
if err != nil {
|
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))
|
ext = c.buildGroupPttStoreBDHExt(target.PrimaryID, fh, int32(length), 0, int32(length))
|
||||||
}
|
}
|
||||||
// multi-thread upload is no need
|
// multi-thread upload is no need
|
||||||
rsp, err := c.highwaySession.UploadBDH(highway.BdhInput{
|
rsp, err := c.highwaySession.UploadBDH(highway.Transaction{
|
||||||
CommandID: cmd,
|
CommandID: cmd,
|
||||||
Body: voice,
|
Body: voice,
|
||||||
Sum: fh,
|
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)
|
ext, _ := proto.Marshal(c.buildPttShortVideoProto(target, videoSum, thumbSum, videoLen, thumbLen).PttShortVideoUploadReq)
|
||||||
combined := utils.MultiReadSeeker(thumb, video)
|
combined := utils.MultiReadSeeker(thumb, video)
|
||||||
input := highway.BdhInput{
|
input := highway.Transaction{
|
||||||
CommandID: cmd,
|
CommandID: cmd,
|
||||||
Body: combined,
|
Body: combined,
|
||||||
Size: videoLen + thumbLen,
|
Size: videoLen + thumbLen,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user