implement client notify
This commit is contained in:
parent
54d9536692
commit
93771480ff
@ -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.
|
// Notify tells s we believe n to be its predecessor.
|
||||||
func (cl *Client) Notify(ctx context.Context, n *chord.Node, s chord.Peer) error {
|
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.
|
// Neighbors requests a peer's beliefs about its own neighbors.
|
||||||
|
@ -22,6 +22,10 @@ type Node struct {
|
|||||||
fingers []Peer
|
fingers []Peer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n *Node) Self() Peer {
|
||||||
|
return n.self
|
||||||
|
}
|
||||||
|
|
||||||
func (n *Node) Successor() Peer {
|
func (n *Node) Successor() Peer {
|
||||||
return n.succ[0]
|
return n.succ[0]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user