28 lines
705 B
Go
28 lines
705 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"time"
|
|
)
|
|
|
|
// Function to sync updates across all nodes
|
|
func nodeUpdateSync() {
|
|
fmt.Println("Syncing updates across all nodes...")
|
|
for _, peerAddr := range peers {
|
|
fmt.Printf("Notifying node %s about update...\n", peerAddr)
|
|
msg := Message{
|
|
ID: hostID,
|
|
Type: "update",
|
|
Content: "Start update process",
|
|
}
|
|
err := sendMessage(peerAddr, msg)
|
|
if err != nil {
|
|
log.Printf("Failed to notify node %s: %v\n", peerAddr, err)
|
|
continue
|
|
}
|
|
fmt.Printf("Node %s notified. Waiting for it to update...\n", peerAddr)
|
|
time.Sleep(30 * time.Second) // Adjust sleep time as needed to allow for updates
|
|
}
|
|
fmt.Println("All nodes have been updated.")
|
|
}
|