MCPcopy Create free account
hub / github.com/0xUnixIO/pulse / onNodeConnected

Function onNodeConnected

internal/server/server_grpc.go:82–100  ·  view source on GitHub ↗

onNodeConnected 返回节点建连回调:用 gRPC 对端 IP 更新 node.BaseURL。 仅更新 loopback 或空 BaseURL,保留管理员手动配置的域名。

(store nodes.Store)

Source from the content-addressed store, hash-verified

80// onNodeConnected 返回节点建连回调:用 gRPC 对端 IP 更新 node.BaseURL。
81// 仅更新 loopback 或空 BaseURL,保留管理员手动配置的域名。
82func onNodeConnected(store nodes.Store) func(nodeID, peerIP string) {
83 return func(nodeID, peerIP string) {
84 if peerIP == "" {
85 return
86 }
87 node, err := store.Get(nodeID)
88 if err != nil {
89 return
90 }
91 existing := node.BaseURL
92 if existing != "" && !isLoopbackURL(existing) {
93 return
94 }
95 node.BaseURL = fmt.Sprintf("http://%s", peerIP)
96 if _, err := store.Upsert(node); err != nil {
97 log.Printf("nodehub: update node %s base_url: %v", nodeID, err)
98 }
99 }
100}
101
102func isLoopbackURL(u string) bool {
103 // 支持 http://host:port、http://host、https://[::1]:port 等格式

Callers 1

startNodeHubFunction · 0.85

Calls 3

isLoopbackURLFunction · 0.85
GetMethod · 0.65
UpsertMethod · 0.65

Tested by

no test coverage detected