implement periodic checks in a function
This commit is contained in:
parent
85e381f4bd
commit
936decf0e6
@ -1,7 +1,9 @@
|
|||||||
package httpnode
|
package httpnode
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
@ -49,6 +51,20 @@ func (n *Node) Router() http.Handler {
|
|||||||
return m
|
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) {
|
func (n *Node) successor(w http.ResponseWriter, r *http.Request) {
|
||||||
s := r.FormValue("s")
|
s := r.FormValue("s")
|
||||||
id, err := chord.ParseID(s)
|
id, err := chord.ParseID(s)
|
||||||
|
Loading…
Reference in New Issue
Block a user