Search/node-update.go

29 lines
705 B
Go
Raw Normal View History

2024-06-30 21:20:52 +00:00
package main
import (
"fmt"
"log"
"time"
)
// Function to sync updates across all nodes
func nodeUpdateSync() {
fmt.Println("Syncing updates across all nodes...")
2024-08-08 11:35:50 +00:00
for _, peerAddr := range peers {
fmt.Printf("Notifying node %s about update...\n", peerAddr)
msg := Message{
2024-08-08 11:48:18 +00:00
ID: hostID,
2024-08-08 11:35:50 +00:00
Type: "update",
Content: "Start update process",
}
err := sendMessage(peerAddr, msg)
2024-06-30 21:20:52 +00:00
if err != nil {
2024-08-08 11:35:50 +00:00
log.Printf("Failed to notify node %s: %v\n", peerAddr, err)
2024-06-30 21:20:52 +00:00
continue
}
2024-08-08 11:35:50 +00:00
fmt.Printf("Node %s notified. Waiting for it to update...\n", peerAddr)
2024-06-30 21:20:52 +00:00
time.Sleep(30 * time.Second) // Adjust sleep time as needed to allow for updates
}
fmt.Println("All nodes have been updated.")
}