diff --git a/chord/httpnode/client.go b/chord/httpnode/client.go index 4fdcbb5..39d9188 100644 --- a/chord/httpnode/client.go +++ b/chord/httpnode/client.go @@ -48,7 +48,30 @@ func (cl *Client) FindSuccessor(ctx context.Context, s chord.Peer, id chord.ID) // Notify tells s we believe n to be its predecessor. func (cl *Client) Notify(ctx context.Context, n *chord.Node, s chord.Peer) error { - panic("not implemented") // TODO: Implement + _, addr := s.Values() + if !addr.IsValid() { + return errors.New("Notify with invalid peer") + } + _, self := n.Self().Values() + url := url.URL{ + Scheme: "http", + Host: addr.String(), + Path: path.Join("/", cl.APIBase, "pred"), + RawQuery: url.Values{"s": {self.String()}}.Encode(), + } + req, err := http.NewRequestWithContext(ctx, "POST", url.String(), nil) + if err != nil { + return err + } + resp, err := cl.HTTP.Do(req) + if err != nil { + return err + } + // We expect the server to only be capable of responding with No Content. + if resp.StatusCode != http.StatusNoContent { + return fmt.Errorf("strange response: %s", resp.Status) + } + return nil } // Neighbors requests a peer's beliefs about its own neighbors. diff --git a/chord/topology.go b/chord/topology.go index bde8557..128a3e0 100644 --- a/chord/topology.go +++ b/chord/topology.go @@ -22,6 +22,10 @@ type Node struct { fingers []Peer } +func (n *Node) Self() Peer { + return n.self +} + func (n *Node) Successor() Peer { return n.succ[0] }