feat: trust peer
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package discovery
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Peer 代表一个可达的网络端点 (Network Endpoint)。
|
||||
// 注意:一个物理设备 (Device) 可能通过多个网络接口广播,因此会对应多个 Peer 结构体。
|
||||
@@ -20,6 +23,12 @@ type Peer struct {
|
||||
Port int `json:"port"`
|
||||
|
||||
OS OS `json:"os"`
|
||||
|
||||
PublicKey string `json:"pk"`
|
||||
|
||||
// TrustMismatch 指示该节点的公钥与本地信任列表中的公钥不匹配
|
||||
// 如果为 true,说明可能存在 ID 欺骗或密钥轮换
|
||||
TrustMismatch bool `json:"trust_mismatch"`
|
||||
}
|
||||
|
||||
// RouteState 记录单条路径的状态
|
||||
@@ -38,8 +47,17 @@ const (
|
||||
|
||||
// PresencePacket 是 UDP 广播的载荷
|
||||
type PresencePacket struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Port int `json:"port"`
|
||||
OS OS `json:"os"`
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Port int `json:"port"`
|
||||
OS OS `json:"os"`
|
||||
PublicKey string `json:"pk"`
|
||||
Signature string `json:"sig"`
|
||||
}
|
||||
|
||||
// SignPayload 生成用于签名的确定性数据
|
||||
func (p *PresencePacket) SignPayload() []byte {
|
||||
// 使用固定格式拼接字段,避免 JSON 序列化的不确定性
|
||||
// 格式: id|name|port|os|pk
|
||||
return fmt.Appendf(nil, "%s|%s|%d|%s|%s", p.ID, p.Name, p.Port, p.OS, p.PublicKey)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user