mirror of
https://github.com/wyx2685/V2bX.git
synced 2025-02-08 17:18:13 -05:00
增加本地节点Hash辅助判断信息
This commit is contained in:
parent
0d274bcf61
commit
73f9b19222
@ -1,7 +1,9 @@
|
|||||||
package panel
|
package panel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -130,7 +132,19 @@ func (c *Client) GetNodeInfo() (node *NodeInfo, err error) {
|
|||||||
r, err := c.client.
|
r, err := c.client.
|
||||||
R().
|
R().
|
||||||
SetHeader("If-None-Match", c.nodeEtag).
|
SetHeader("If-None-Match", c.nodeEtag).
|
||||||
|
ForceContentType("application/json").
|
||||||
Get(path)
|
Get(path)
|
||||||
|
|
||||||
|
if r.StatusCode() == 304 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
hash := sha256.Sum256(r.Body())
|
||||||
|
newBodyHash := hex.EncodeToString(hash[:])
|
||||||
|
if c.responseBodyHash == newBodyHash {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
c.responseBodyHash = newBodyHash
|
||||||
|
c.nodeEtag = r.Header().Get("ETag")
|
||||||
if err = c.checkResponse(r, path, err); err != nil {
|
if err = c.checkResponse(r, path, err); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -141,9 +155,6 @@ func (c *Client) GetNodeInfo() (node *NodeInfo, err error) {
|
|||||||
r.RawBody().Close()
|
r.RawBody().Close()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
if r.StatusCode() == 304 {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return nil, fmt.Errorf("received nil response")
|
return nil, fmt.Errorf("received nil response")
|
||||||
}
|
}
|
||||||
@ -274,8 +285,7 @@ func (c *Client) GetNodeInfo() (node *NodeInfo, err error) {
|
|||||||
cm.Routes = nil
|
cm.Routes = nil
|
||||||
cm.BaseConfig = nil
|
cm.BaseConfig = nil
|
||||||
|
|
||||||
c.nodeEtag = r.Header().Get("ETag")
|
return node, nil
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func intervalToTime(i interface{}) time.Duration {
|
func intervalToTime(i interface{}) time.Duration {
|
||||||
|
@ -23,6 +23,7 @@ type Client struct {
|
|||||||
NodeId int
|
NodeId int
|
||||||
nodeEtag string
|
nodeEtag string
|
||||||
userEtag string
|
userEtag string
|
||||||
|
responseBodyHash string
|
||||||
LastReportOnline map[int]int
|
LastReportOnline map[int]int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,10 +307,8 @@ func extractPortFromAddr(addr string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func formatAddress(ip string, port int) string {
|
func formatAddress(ip string, port int) string {
|
||||||
// 检查 IP 地址是否为 IPv6
|
|
||||||
if strings.Contains(ip, ":") {
|
if strings.Contains(ip, ":") {
|
||||||
return fmt.Sprintf("[%s]:%d", ip, port)
|
return fmt.Sprintf("[%s]:%d", ip, port)
|
||||||
}
|
}
|
||||||
// 对于 IPv4 地址,直接返回 IP:Port 格式
|
|
||||||
return fmt.Sprintf("%s:%d", ip, port)
|
return fmt.Sprintf("%s:%d", ip, port)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user