mirror of
https://gitee.com/konyshe/goodlink.git
synced 2026-04-22 14:53:05 +08:00
Add version compatibility check function to config package and update usage in local and remote handlers. This change enhances version management by allowing compatibility checks based on major and minor version segments, improving error handling for version mismatches.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package config
|
||||
|
||||
import "strings"
|
||||
|
||||
var (
|
||||
m_version string
|
||||
)
|
||||
@@ -11,3 +13,15 @@ func SetVersion(v string) {
|
||||
func GetVersion() string {
|
||||
return m_version
|
||||
}
|
||||
|
||||
// VersionsCompatible reports whether two X.Y.Z style version strings are
|
||||
// wire-compatible: the first two dot-separated segments must match. If either
|
||||
// string has fewer than two segments, falls back to exact string equality.
|
||||
func VersionsCompatible(a, b string) bool {
|
||||
pa := strings.Split(a, ".")
|
||||
pb := strings.Split(b, ".")
|
||||
if len(pa) >= 2 && len(pb) >= 2 {
|
||||
return pa[0] == pb[0] && pa[1] == pb[1]
|
||||
}
|
||||
return a == b
|
||||
}
|
||||
|
||||
+2
-2
@@ -70,8 +70,8 @@ func handleState0_RegisterSession(sessionID string, redisJson *RedisJsonType, co
|
||||
func handleState1_ProcessRemoteAddr(sessionID string, redisJson *RedisJsonType, conn *net.UDPConn, addr *tun.AddrType, conn_type int, tun_active **tun.TunActive, tun_passive **tun.TunPassive) error {
|
||||
log.Printf("State 1: 收到Remote端地址: %v", redisJson.RemoteAddr)
|
||||
|
||||
// 版本兼容性检查
|
||||
if redisJson.RemoteVersion != config.GetVersion() {
|
||||
// 版本兼容性检查(主版本.次版本一致即可)
|
||||
if !config.VersionsCompatible(config.GetVersion(), redisJson.RemoteVersion) {
|
||||
log.Printf("两端版本不兼容: Local: %s => Remote: %s", config.GetVersion(), redisJson.RemoteVersion)
|
||||
UpdateStartButtonStatue(TagStatusVersionMismatch)
|
||||
RedisSessionDel(sessionID)
|
||||
|
||||
+2
-2
@@ -27,8 +27,8 @@ func handleState1_SendRemoteAddr(sessionID string, redisJson *RedisJsonType, tun
|
||||
redisJson.SocketTimeOut = time.Duration(config.Arg_p2p_timeout) * time.Second
|
||||
redisJson.RedisTimeOut = redisJson.SocketTimeOut * 3
|
||||
|
||||
// 版本兼容性检查
|
||||
if redisJson.LocalVersion != config.GetVersion() {
|
||||
// 版本兼容性检查(主版本.次版本一致即可)
|
||||
if !config.VersionsCompatible(config.GetVersion(), redisJson.LocalVersion) {
|
||||
log.Printf("会话 %s 两端版本不兼容: Local: %s => Remote: %s", sessionID, redisJson.LocalVersion, config.GetVersion())
|
||||
redisJson.State = -1 // 设置版本不一致状态,告知Local端
|
||||
RedisSessionSet(sessionID, redisJson.SocketTimeOut*3, redisJson)
|
||||
|
||||
Reference in New Issue
Block a user