Skip to content

Commit

Permalink
feat: 网络状态诊断
Browse files Browse the repository at this point in the history
  • Loading branch information
Redmomn committed Nov 29, 2024
1 parent d89d21d commit 494692a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 32 deletions.
18 changes: 11 additions & 7 deletions cmd/gocq/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import (
"sync"
"time"

"github.com/LagrangeDev/LagrangeGo/client/packets/pb/action"
"github.com/LagrangeDev/LagrangeGo/utils"
"github.com/LagrangeDev/LagrangeGo/utils/crypto"
"github.com/Mrs4s/go-cqhttp/internal/selfdiagnosis"

"github.com/LagrangeDev/LagrangeGo/client/auth"

Expand Down Expand Up @@ -325,11 +328,13 @@ func LoginInteract() {
global.Check(cli.RefreshAllGroupsInfo(), true)
GroupListLen := len(cli.GetCachedAllGroupsInfo())
log.Infof("共加载 %v 个群.", GroupListLen)
// TODO 设置在线状态 暂不支持?
// if uint(base.Account.Status) >= uint(len(allowStatus)) {
// base.Account.Status = 0
//}
//cli.SetOnlineStatus(allowStatus[base.Account.Status])
if uint(base.Account.Status) >= 3000 {
base.Account.Status = 10
}
_ = cli.SetOnlineStatus(utils.Ternary(base.Account.Status >= 1000, action.SetStatus{
Status: 10,
ExtStatus: uint32(base.Account.Status),
}, action.SetStatus{Status: uint32(base.Account.Status)}))
servers.Run(coolq.NewQQBot(cli))
log.Info("资源初始化完成, 开始处理信息.")
log.Info("アトリは、高性能ですから!")
Expand All @@ -342,8 +347,7 @@ func LoginInteract() {
func WaitSignal() {
go func() {
selfupdate.CheckUpdate()
// TODO 服务器连接质量测试
// selfdiagnosis.NetworkDiagnosis(cli)
selfdiagnosis.NetworkDiagnosis(cli)
}()

<-global.SetupMainSignalHandler()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/FloatTech/sqlite v1.6.3
github.com/LagrangeDev/LagrangeGo v0.1.3-0.20241128062531-bea32754985f
github.com/LagrangeDev/LagrangeGo v0.1.3-0.20241129090211-e0fdf8ca5390
github.com/Microsoft/go-winio v0.6.2-0.20230724192519-b29bbd58a65a
github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7
github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ github.com/FloatTech/sqlite v1.6.3 h1:MQkqBNlkPuCoKQQgoNLuTL/2Ci3tBTFAnVYBdD0Wy4
github.com/FloatTech/sqlite v1.6.3/go.mod h1:zFbHzRfB+CJ+VidfjuVbrcin3DAz283F7hF1hIeHzpY=
github.com/FloatTech/ttl v0.0.0-20230307105452-d6f7b2b647d1 h1:g4pTnDJUW4VbJ9NvoRfUvdjDrHz/6QhfN/LoIIpICbo=
github.com/FloatTech/ttl v0.0.0-20230307105452-d6f7b2b647d1/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs=
github.com/LagrangeDev/LagrangeGo v0.1.3-0.20241128062531-bea32754985f h1:arXQxi9PrzbK3d2dw9xvRFkn9jMqqd0dwziwO24dMhg=
github.com/LagrangeDev/LagrangeGo v0.1.3-0.20241128062531-bea32754985f/go.mod h1:m7ydyvA8DKOg5c6iTFDfNtfIK9uhqXVJKRXl4mlGkTA=
github.com/LagrangeDev/LagrangeGo v0.1.3-0.20241129090211-e0fdf8ca5390 h1:NIDdk9Z5ztBhWcLJc8WvXxRSgdSqZlikrFBU5pII78Q=
github.com/LagrangeDev/LagrangeGo v0.1.3-0.20241129090211-e0fdf8ca5390/go.mod h1:m7ydyvA8DKOg5c6iTFDfNtfIK9uhqXVJKRXl4mlGkTA=
github.com/Microsoft/go-winio v0.6.2-0.20230724192519-b29bbd58a65a h1:aU1703IHxupjzipvhu16qYKLMR03e+8WuNR+JMsKfGU=
github.com/Microsoft/go-winio v0.6.2-0.20230724192519-b29bbd58a65a/go.mod h1:OZqLNXdYJHmx7aqq/T6wAdFEdoGm5nmIfC4kU7M8P8o=
github.com/RomiChan/protobuf v0.1.1-0.20230204044148-2ed269a2e54d h1:/Xuj3fIiMY2ls1TwvPKmaqQrtJsPY+c9s+0lOScVHd8=
Expand Down
47 changes: 27 additions & 20 deletions internal/selfdiagnosis/diagnoses.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
// Package selfdiagnosis 自我诊断相关
package selfdiagnosis

/*
import (
"github.com/LagrangeDev/LagrangeGo/client"
log "github.com/sirupsen/logrus"
)

// NetworkDiagnosis 诊断网络状态并输出结果
func NetworkDiagnosis(c *client.QQClient) {
log.Infof("开始诊断网络情况")
qualityInfo := c.ConnectionQualityTest()
log.Debugf("聊天服务器连接延迟: %vms", qualityInfo.ChatServerLatency)
log.Debugf("聊天服务器丢包率: %v%%", qualityInfo.ChatServerPacketLoss*10)
log.Debugf("长消息服务器连接延迟: %vms", qualityInfo.LongMessageServerLatency)
log.Debugf("长消息服务器响应延迟: %vms", qualityInfo.LongMessageServerResponseLatency)
//log.Debugf("长消息服务器连接延迟: %vms", qualityInfo.LongMessageServerLatency)
//log.Debugf("长消息服务器响应延迟: %vms", qualityInfo.LongMessageServerResponseLatency)
log.Debugf("媒体服务器连接延迟: %vms", qualityInfo.SrvServerLatency)
log.Debugf("媒体服务器丢包率: %v%%", qualityInfo.SrvServerPacketLoss*10)

Expand All @@ -31,21 +35,21 @@ func NetworkDiagnosis(c *client.QQClient) {
log.Warnf("警告: 本地连接聊天服务器丢包率为 %v%%, %v", qualityInfo.ChatServerPacketLoss*10, chatServerErrorMessage)
}

if qualityInfo.LongMessageServerLatency > 1000 {
if qualityInfo.LongMessageServerLatency == 9999 {
log.Errorf("错误: 长消息服务器延迟测试失败, %v 如果您使用的腾讯云服务器, 请修改DNS到114.114.114.114", longMessageServerErrorMessage)
} else {
log.Warnf("警告: 长消息延迟为 %vms, 大于 1000ms, %v", qualityInfo.LongMessageServerLatency, longMessageServerErrorMessage)
}
}
if qualityInfo.LongMessageServerResponseLatency > 2000 {
if qualityInfo.LongMessageServerResponseLatency == 9999 {
log.Errorf("错误: 长消息服务器响应延迟测试失败, %v 如果您使用的腾讯云服务器, 请修改DNS到114.114.114.114", longMessageServerErrorMessage)
} else {
log.Warnf("警告: 长消息响应延迟为 %vms, 大于 1000ms, %v", qualityInfo.LongMessageServerResponseLatency, longMessageServerErrorMessage)
}
}
//if qualityInfo.LongMessageServerLatency > 1000 {
// if qualityInfo.LongMessageServerLatency == 9999 {
// log.Errorf("错误: 长消息服务器延迟测试失败, %v 如果您使用的腾讯云服务器, 请修改DNS到114.114.114.114", longMessageServerErrorMessage)
// } else {
// log.Warnf("警告: 长消息延迟为 %vms, 大于 1000ms, %v", qualityInfo.LongMessageServerLatency, longMessageServerErrorMessage)
// }
//}
//
//if qualityInfo.LongMessageServerResponseLatency > 2000 {
// if qualityInfo.LongMessageServerResponseLatency == 9999 {
// log.Errorf("错误: 长消息服务器响应延迟测试失败, %v 如果您使用的腾讯云服务器, 请修改DNS到114.114.114.114", longMessageServerErrorMessage)
// } else {
// log.Warnf("警告: 长消息响应延迟为 %vms, 大于 1000ms, %v", qualityInfo.LongMessageServerResponseLatency, longMessageServerErrorMessage)
// }
//}

if qualityInfo.SrvServerLatency > 1000 {
if qualityInfo.SrvServerPacketLoss == 9999 {
Expand All @@ -59,7 +63,11 @@ func NetworkDiagnosis(c *client.QQClient) {
log.Warnf("警告: 本地连接媒体服务器丢包率为 %v%%, %v", qualityInfo.SrvServerPacketLoss*10, mediaServerErrorMessage)
}

if qualityInfo.ChatServerLatency > 1000 || qualityInfo.ChatServerPacketLoss > 0 || qualityInfo.LongMessageServerLatency > 1000 || qualityInfo.SrvServerLatency > 1000 || qualityInfo.SrvServerPacketLoss > 0 {
if qualityInfo.ChatServerLatency > 1000 ||
qualityInfo.ChatServerPacketLoss > 0 ||
//qualityInfo.LongMessageServerLatency > 1000 ||
qualityInfo.SrvServerLatency > 1000 ||
qualityInfo.SrvServerPacketLoss > 0 {
log.Infof("网络诊断完成. 发现问题, 请检查日志.")
} else {
log.Infof("网络诊断完成. 未发现问题")
Expand All @@ -75,4 +83,3 @@ func DNSDiagnosis() {
func EnvironmentDiagnosis() {
// todo
}
*/
4 changes: 2 additions & 2 deletions modules/config/default_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ account: # 账号相关
#
# 服务器不提供自建
sign-servers:
- url: 'https://sign.ciallo.site/api/sign' # 主签名服务器地址, 必填
- url: 'https://sign.lagrangecore.org/api/sign/25765' # 备用
- url: '-' # 主签名服务器地址, 必填
- url: '-' # 备用

# 连续寻找可用签名服务器最大尝试次数
# 为 0 时会在连续 3 次没有找到可用签名服务器后保持使用主签名服务器,不再尝试进行切换备用
Expand Down

0 comments on commit 494692a

Please sign in to comment.