Skip to content

Commit

Permalink
Revert "SpeedUP Rand"
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrs4s authored Jan 25, 2021
1 parent 340977e commit ecd5a7b
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 91 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ jobs:
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.13
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.13

- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Get dependencies
run: |
go get -v -t -d ./...
- name: Get dependencies
run: |
go get -v -t -d ./...
- name: Build
run: go build -v ./...
- name: Build
run: go build -v ./...

# - name: Test
# run: go test -v .
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ qq-android协议的golang实现 移植于mirai
- [x] 登录号加群
- [x] 登录号退群(包含T出)
- [x] 新成员进群/退群
- [x] 群/好友消息撤回
- [x] 群/好友消息撤回
- [x] 群禁言
- [x] 群成员权限变更
- [x] 收到邀请进群通知
- [x] 收到其他用户进群请求
- [x] 新好友
- [x] 新好友请求
- [x] 客户端离线
- [x] 群提示 (戳一戳/运气王等)
- [x] 群提示 (戳一戳/运气王等)

#### 主动操作
> 为防止滥用,将不支持主动邀请新成员进群
Expand Down
4 changes: 1 addition & 3 deletions binary/tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package binary

import (
"encoding/binary"
//"math/rand"
"math/rand"
"reflect"
"unsafe"

rand "github.com/LXY1226/fastrand"
)

func xorQ(a, b []byte, c []byte) { // MAGIC
Expand Down
52 changes: 0 additions & 52 deletions binary/tea_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,58 +99,6 @@ func BenchmarkTEAde16(b *testing.B) {
}
}

func BenchmarkTEAen200(b *testing.B) {
data := make([]byte, 200)
_, err := rand.Read(data)
if err != nil {
panic(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
testTEA.Encrypt(data)
}
}

func BenchmarkTEAde200(b *testing.B) {
data := make([]byte, 200)
_, err := rand.Read(data)
if err != nil {
panic(err)
}
data = testTEA.Encrypt(data)
b.ResetTimer()
for i := 0; i < b.N; i++ {
testTEA.Decrypt(data)
}
}

func BenchmarkTEAen200M(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
data := make([]byte, 200)
_, err := rand.Read(data)
if err != nil {
panic(err)
}
for pb.Next() {
testTEA.Encrypt(data)
}
})
}

func BenchmarkTEAde200M(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
data := make([]byte, 200)
_, err := rand.Read(data)
if err != nil {
panic(err)
}
data = testTEA.Encrypt(data)
for pb.Next() {
testTEA.Decrypt(data)
}
})
}

func BenchmarkTEAen256(b *testing.B) {
data := make([]byte, 256)
_, err := rand.Read(data)
Expand Down
7 changes: 3 additions & 4 deletions client/builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package client
import (
"encoding/hex"
"fmt"
"github.com/Mrs4s/MiraiGo/client/pb/profilecard"
"github.com/Mrs4s/MiraiGo/client/pb/qweb"
"math/rand"
"time"

rand "github.com/LXY1226/fastrand"

"github.com/golang/protobuf/proto"

"github.com/Mrs4s/MiraiGo/binary"
Expand All @@ -15,8 +16,6 @@ import (
"github.com/Mrs4s/MiraiGo/client/pb/cmd0x352"
"github.com/Mrs4s/MiraiGo/client/pb/msg"
"github.com/Mrs4s/MiraiGo/client/pb/oidb"
"github.com/Mrs4s/MiraiGo/client/pb/profilecard"
"github.com/Mrs4s/MiraiGo/client/pb/qweb"
"github.com/Mrs4s/MiraiGo/client/pb/structmsg"
"github.com/Mrs4s/MiraiGo/message"
"github.com/Mrs4s/MiraiGo/protocol/crypto"
Expand Down
10 changes: 5 additions & 5 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"bytes"
"crypto/md5"
"fmt"
rand "github.com/LXY1226/fastrand"
"github.com/Mrs4s/MiraiGo/binary/jce"
jsoniter "github.com/json-iterator/go"
"io"
"math"
"math/rand"
"net"
"runtime/debug"
"sort"
Expand Down Expand Up @@ -149,9 +149,9 @@ var decoders = map[string]func(*QQClient, uint16, []byte) (interface{}, error){
"PttCenterSvr.pb_pttCenter_CMD_REQ_APPLY_UPLOAD-500": decodePrivatePttStoreResponse,
}

//func init() {
// rand.Seed(time.Now().UTC().UnixNano())
//}
func init() {
rand.Seed(time.Now().UTC().UnixNano())
}

// NewClient create new qq client
func NewClient(uin int64, password string) *QQClient {
Expand All @@ -167,7 +167,7 @@ func NewClientMd5(uin int64, passwordMd5 [16]byte) *QQClient {
OutGoingPacketSessionId: []byte{0x02, 0xB0, 0x5B, 0x8B},
sigInfo: &loginSigInfo{},
requestPacketRequestId: 1921334513,
groupSeq: rand.Int31n(20000),
groupSeq: int32(rand.Intn(20000)),
friendSeq: 22911,
highwayApplyUpSeq: 77918,
ksid: []byte(fmt.Sprintf("|%s|A8.2.7.27f6ea96", SystemDeviceInfo.IMEI)),
Expand Down
9 changes: 5 additions & 4 deletions client/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import (
"encoding/hex"
"encoding/xml"
"fmt"
"github.com/Mrs4s/MiraiGo/client/pb/oidb"
"math/rand"
"net"
"sort"
"strconv"
"strings"
"time"

rand "github.com/LXY1226/fastrand"
"github.com/Mrs4s/MiraiGo/binary"
"github.com/Mrs4s/MiraiGo/binary/jce"
devinfo "github.com/Mrs4s/MiraiGo/client/pb"
Expand Down Expand Up @@ -367,11 +368,11 @@ func GenIMEI() string {
sum := 0 // the control sum of digits
var final strings.Builder

//randSrc := rand.NewSource(time.Now().UnixNano())
//randGen := rand.New(randSrc)
randSrc := rand.NewSource(time.Now().UnixNano())
randGen := rand.New(randSrc)

for i := 0; i < 14; i++ { // generating all the base digits
toAdd := rand.Intn(10)
toAdd := randGen.Intn(10)
if (i+1)%2 == 0 { // special proc for every 2nd one
toAdd *= 2
if toAdd >= 10 {
Expand Down
6 changes: 3 additions & 3 deletions client/group_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package client
import (
"encoding/base64"
"fmt"
rand "github.com/LXY1226/fastrand"
"github.com/Mrs4s/MiraiGo/client/pb/longmsg"
"github.com/Mrs4s/MiraiGo/client/pb/msg"
"github.com/Mrs4s/MiraiGo/client/pb/multimsg"
Expand All @@ -14,6 +13,7 @@ import (
"github.com/pkg/errors"
"google.golang.org/protobuf/proto"
"math"
"math/rand"
"time"
)

Expand Down Expand Up @@ -93,7 +93,7 @@ func (c *QQClient) GetAtAllRemain(groupCode int64) (*AtAllRemainInfo, error) {

func (c *QQClient) sendGroupMessage(groupCode int64, forward bool, m *message.SendingMessage) *message.GroupMessage {
eid := utils.RandomString(6)
mr := rand.Int31()
mr := int32(rand.Uint32())
ch := make(chan int32)
c.onGroupMessageReceipt(eid, func(c *QQClient, e *groupMessageReceiptEvent) {
if e.Rand == mr && !utils.IsChanClosed(ch) {
Expand All @@ -113,7 +113,7 @@ func (c *QQClient) sendGroupMessage(groupCode int64, forward bool, m *message.Se
}
return ok || ok2 || ok3
}) {
div := rand.Int31()
div := int32(rand.Uint32())
fragmented := m.ToFragmented()
for i, elems := range fragmented {
_, pkt := c.buildGroupSendingPacket(groupCode, mr, int32(len(fragmented)), int32(i), div, forward, elems)
Expand Down
2 changes: 1 addition & 1 deletion client/pb/oidb/oidb0xb77.proto
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ message DB77ExtInfo {

message DB77RichMsgBody {
string title = 10;
string summary = 11;
string summary = 11;
string brief = 12;
string url = 13;
string pictureUrl = 14;
Expand Down
2 changes: 1 addition & 1 deletion client/richmsg.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package client

import (
"math/rand"
"time"

rand "github.com/LXY1226/fastrand"
"github.com/Mrs4s/MiraiGo/client/pb/oidb"
"github.com/Mrs4s/MiraiGo/message"
"github.com/Mrs4s/MiraiGo/protocol/packets"
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/Mrs4s/MiraiGo
go 1.15

require (
github.com/LXY1226/fastrand v0.0.0-20210121160840-7a3db3e79031
github.com/golang/protobuf v1.4.3
github.com/json-iterator/go v1.1.10
github.com/pkg/errors v0.9.1
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/LXY1226/fastrand v0.0.0-20210121160840-7a3db3e79031 h1:DnoCySrXUFvtngW2kSkuBeZoPfvOgctJXjTulCn7eV0=
github.com/LXY1226/fastrand v0.0.0-20210121160840-7a3db3e79031/go.mod h1:mEFi4jHUsE2sqQGSJ7eQfXnO8esMzEYcftiCGG+L/OE=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
2 changes: 1 addition & 1 deletion protocol/tlv/t1.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package tlv

import (
rand "github.com/LXY1226/fastrand"
"github.com/Mrs4s/MiraiGo/binary"
"math/rand"
"time"
)

Expand Down
2 changes: 1 addition & 1 deletion protocol/tlv/t106.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package tlv
import (
"crypto/md5"
binary2 "encoding/binary"
rand "github.com/LXY1226/fastrand"
"github.com/Mrs4s/MiraiGo/binary"
"math/rand"
"strconv"
"time"
)
Expand Down

0 comments on commit ecd5a7b

Please sign in to comment.