ref: 多core表结构和代码调整修改
This commit is contained in:
@@ -29,7 +29,7 @@ func (c *ConnTelnet) NewClient() (*ConnTelnet, error) {
|
||||
proto = "tcp6"
|
||||
c.Addr = fmt.Sprintf("[%s]", c.Addr)
|
||||
}
|
||||
addr := fmt.Sprintf("%s:%d", c.Addr, c.Port)
|
||||
addr := net.JoinHostPort(c.Addr, fmt.Sprint(c.Port))
|
||||
|
||||
// 默认等待5s
|
||||
if c.DialTimeOut == 0 {
|
||||
|
||||
@@ -4,8 +4,10 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"hash/fnv"
|
||||
"net"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"be.ems/src/framework/cmd"
|
||||
@@ -24,29 +26,32 @@ var LaunchInfo map[string]any
|
||||
|
||||
// codeGenerate 生成机器的唯一标识符
|
||||
func codeGenerate() string {
|
||||
var machineID string
|
||||
var machineID []string
|
||||
|
||||
// 获取主机名
|
||||
hostname, err := os.Hostname()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
// 获取所有网络接口信息
|
||||
interfaces, _ := net.Interfaces()
|
||||
for _, iface := range interfaces {
|
||||
// 检查接口是否有 MAC 地址
|
||||
if iface.HardwareAddr != nil {
|
||||
machineID = append(machineID, iface.HardwareAddr.String())
|
||||
break
|
||||
}
|
||||
}
|
||||
machineID += hostname
|
||||
|
||||
// 获取 CPU 信息
|
||||
numCPU := runtime.NumCPU()
|
||||
machineID += fmt.Sprintf("%d", numCPU)
|
||||
machineID = append(machineID, fmt.Sprintf("%d", numCPU))
|
||||
|
||||
// 获取操作系统信息
|
||||
osInfo := runtime.GOOS
|
||||
machineID += osInfo
|
||||
machineID = append(machineID, osInfo)
|
||||
|
||||
// 使用哈希函数生成机器码
|
||||
h := fnv.New32a()
|
||||
h.Write([]byte(machineID))
|
||||
h.Write([]byte(strings.Join(machineID, "&")))
|
||||
machineCode := h.Sum32()
|
||||
|
||||
return fmt.Sprintf("%x", machineCode)
|
||||
return strings.ToUpper(fmt.Sprintf("%x", machineCode))
|
||||
}
|
||||
|
||||
// 网管本地路径
|
||||
@@ -69,8 +74,8 @@ func codeFileRead() (map[string]any, error) {
|
||||
}
|
||||
content := string(bytes)
|
||||
// 解密
|
||||
hostKey := config.Get("aes.hostKey").(string)
|
||||
contentDe, err := crypto.AESDecryptBase64(content, hostKey)
|
||||
appKey := config.Get("aes.appKey").(string)
|
||||
contentDe, err := crypto.AESDecryptBase64(content, appKey)
|
||||
if err != nil {
|
||||
logger.Errorf("CodeFileRead decrypt: %v", err.Error())
|
||||
return mapData, fmt.Errorf("decrypt fail")
|
||||
@@ -88,8 +93,8 @@ func codeFileRead() (map[string]any, error) {
|
||||
func codeFileWrite(data map[string]any) error {
|
||||
jsonByte, _ := json.Marshal(data)
|
||||
// 加密
|
||||
hostKey := config.Get("aes.hostKey").(string)
|
||||
contentEn, err := crypto.AESEncryptBase64(string(jsonByte), hostKey)
|
||||
appKey := config.Get("aes.appKey").(string)
|
||||
contentEn, err := crypto.AESEncryptBase64(string(jsonByte), appKey)
|
||||
if err != nil {
|
||||
logger.Errorf("insert encrypt: %v", err.Error())
|
||||
return fmt.Errorf("encrypt fail")
|
||||
|
||||
Reference in New Issue
Block a user