diff --git a/chord/httpnode/server.go b/chord/httpnode/server.go index 4c55101..99e9451 100644 --- a/chord/httpnode/server.go +++ b/chord/httpnode/server.go @@ -1,7 +1,9 @@ package httpnode import ( + "context" "errors" + "fmt" "net" "net/http" "net/netip" @@ -49,6 +51,20 @@ func (n *Node) Router() http.Handler { return m } +// Check performs checks that implement the Chord protocol. +// It must be called periodically while the node is alive. +func (n *Node) Check(ctx context.Context) error { + if err := chord.Stabilize(ctx, n.client, n.self); err != nil { + return fmt.Errorf("failed to stabilize: %w", err) + } + // TODO(zeph): enable once implemented + // if err := chord.FixFingers(ctx, n.client, n.self); err != nil { + // return fmt.Errorf("failed to fix fingers: %w", err) + // } + chord.CheckPredecessor(ctx, n.client, n.self) + return nil +} + func (n *Node) successor(w http.ResponseWriter, r *http.Request) { s := r.FormValue("s") id, err := chord.ParseID(s)