package node import ( "encoding/json" "io" "log" "deevirt.fr/compute/pkg/api/proto" "deevirt.fr/compute/pkg/api/raft" "deevirt.fr/compute/pkg/config" deevirt_schema "deevirt.fr/compute/pkg/schema/deevirt" ) type Node struct { Config *config.Config Store *raft.Store proto.UnimplementedNodeServer } func (n *Node) Alive(stream proto.Node_AliveServer) error { println("Alive") for { req, err := stream.Recv() if err == io.EOF || err != nil { log.Println("Client closed the connection") return nil } log.Printf("Received heartbeat: %v", req) cluster := deevirt_schema.NodeStore{} res, _ := n.Store.Get("/etc/libvirt/cluster") json.Unmarshal(res, &cluster) cluster[n.Config.NodeID].LastUpdate = req.Timestamp d, _ := json.Marshal(cluster) n.Store.Set("/etc/libvirt/cluster", d) stream.Send(&proto.NodeAliveQemuResponse{ Nodes: res, }) } }