mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-08 04:55:56 +08:00
feature server quality test.
This commit is contained in:
parent
c0ec373de5
commit
d1ae3f5ba5
@ -12,6 +12,7 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -190,7 +191,6 @@ func NewClientMd5(uin int64, passwordMd5 [16]byte) *QQClient {
|
|||||||
IP: addr,
|
IP: addr,
|
||||||
Port: 8080,
|
Port: 8080,
|
||||||
})
|
})
|
||||||
break // 第一个就好23333
|
|
||||||
}
|
}
|
||||||
cli.servers = append(hostAddrs, cli.servers...)
|
cli.servers = append(hostAddrs, cli.servers...)
|
||||||
}
|
}
|
||||||
@ -204,6 +204,27 @@ func NewClientMd5(uin int64, passwordMd5 [16]byte) *QQClient {
|
|||||||
{IP: net.IP{42, 81, 172, 22}, Port: 80},
|
{IP: net.IP{42, 81, 172, 22}, Port: 80},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pings := make([]int64, len(cli.servers))
|
||||||
|
wg := sync.WaitGroup{}
|
||||||
|
wg.Add(len(cli.servers))
|
||||||
|
for i := range cli.servers {
|
||||||
|
go func(index int, w sync.WaitGroup) {
|
||||||
|
p, err := qualityTest(cli.servers[index])
|
||||||
|
if err != nil {
|
||||||
|
pings[index] = 9999
|
||||||
|
return
|
||||||
|
}
|
||||||
|
pings[index] = p
|
||||||
|
wg.Done()
|
||||||
|
}(i, wg)
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
sort.Slice(cli.servers, func(i, j int) bool {
|
||||||
|
return pings[i] < pings[j]
|
||||||
|
})
|
||||||
|
if len(cli.servers) > 3 {
|
||||||
|
cli.servers = cli.servers[0 : len(cli.servers)/2] // 保留ping值中位数以上的server
|
||||||
|
}
|
||||||
rand.Read(cli.RandomKey)
|
rand.Read(cli.RandomKey)
|
||||||
return cli
|
return cli
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DeviceInfo struct {
|
type DeviceInfo struct {
|
||||||
@ -338,6 +339,18 @@ func getSSOAddress() ([]*net.TCPAddr, error) {
|
|||||||
return adds, nil
|
return adds, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func qualityTest(addr *net.TCPAddr) (int64, error) {
|
||||||
|
// see QualityTestManager
|
||||||
|
start := time.Now()
|
||||||
|
conn, err := net.DialTCP("tcp", nil, addr)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
_ = conn.Close()
|
||||||
|
end := time.Now()
|
||||||
|
return end.Sub(start).Milliseconds(), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *QQClient) parsePrivateMessage(msg *msg.Message) *message.PrivateMessage {
|
func (c *QQClient) parsePrivateMessage(msg *msg.Message) *message.PrivateMessage {
|
||||||
friend := c.FindFriend(msg.Head.FromUin)
|
friend := c.FindFriend(msg.Head.FromUin)
|
||||||
var sender *message.Sender
|
var sender *message.Sender
|
||||||
|
Loading…
x
Reference in New Issue
Block a user