From 84a5d38b0b6914e130ac4085ecedfb4ce3365f29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Thu, 12 May 2022 21:07:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E5=90=AF=E5=8A=A8=E6=97=B6=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E8=8A=82=E7=82=B9=E6=97=B6=E9=97=B4=E6=88=B3=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E5=92=8CAPI=E8=8A=82=E7=82=B9=E4=B8=80=E8=87=B4?= =?UTF-8?q?=EF=BC=8C=E5=A6=82=E6=9E=9C=E4=B8=8D=E4=B8=80=E8=87=B4=E5=88=99?= =?UTF-8?q?=E4=B8=8A=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/node.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/internal/nodes/node.go b/internal/nodes/node.go index f3dd5ce..6e04029 100644 --- a/internal/nodes/node.go +++ b/internal/nodes/node.go @@ -426,7 +426,7 @@ func (this *Node) syncConfig(taskVersion int64) error { return nil } - configJSON := configResp.NodeJSON + var configJSON = configResp.NodeJSON if configResp.IsCompressed { var reader = brotli.NewReader(bytes.NewReader(configJSON)) var configBuf = &bytes.Buffer{} @@ -445,7 +445,7 @@ func (this *Node) syncConfig(taskVersion int64) error { nodeConfigUpdatedAt = time.Now().Unix() - nodeConfig := &nodeconfigs.NodeConfig{} + var nodeConfig = &nodeconfigs.NodeConfig{} err = json.Unmarshal(configJSON, nodeConfig) if err != nil { return errors.New("decode config failed: " + err.Error()) @@ -453,6 +453,15 @@ func (this *Node) syncConfig(taskVersion int64) error { teaconst.NodeId = nodeConfig.Id teaconst.NodeIdString = types.String(teaconst.NodeId) + // 检查时间是否一致 + // 这个需要在 teaconst.NodeId 设置之后,因为上报到API节点的时候需要节点ID + if configResp.Timestamp > 0 { + var timestampDelta = configResp.Timestamp - time.Now().Unix() + if timestampDelta > 60 || timestampDelta < -60 { + remotelogs.Error("NODE", "node timestamp ('"+types.String(time.Now().Unix())+"') is not same as api node ('"+types.String(configResp.Timestamp)+"'), please sync the time") + } + } + // 写入到文件中 err = nodeConfig.Save() if err != nil {