implement lookup
This commit is contained in:
parent
c0afd85f11
commit
5d5155d8d8
21
main.go
21
main.go
@ -207,9 +207,24 @@ func cliLeave(ctx context.Context, cmd *cli.Command) error {
|
||||
return cl.SayBye(ctx, chord.Address(n))
|
||||
}
|
||||
|
||||
func cliLookup(ctx context.Context, cmd *cli.Command) error { return errors.New("not implemented") }
|
||||
func cliPut(ctx context.Context, cmd *cli.Command) error { return errors.New("not implemented") }
|
||||
func cliGet(ctx context.Context, cmd *cli.Command) error { return errors.New("not implemented") }
|
||||
func cliLookup(ctx context.Context, cmd *cli.Command) error {
|
||||
n, err := netip.ParseAddrPort(cmd.String("n"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
k := chord.Key(cmd.String("k"))
|
||||
cl := &httpnode.Client{HTTP: http.Client{Timeout: 5 * time.Second}}
|
||||
p, err := cl.FindSuccessor(ctx, chord.Address(n), k)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, addr := p.Values()
|
||||
fmt.Println(addr)
|
||||
return nil
|
||||
}
|
||||
|
||||
func cliPut(ctx context.Context, cmd *cli.Command) error { return errors.New("not implemented") }
|
||||
func cliGet(ctx context.Context, cmd *cli.Command) error { return errors.New("not implemented") }
|
||||
|
||||
func main() {
|
||||
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
|
||||
|
@ -17,6 +17,15 @@ THIRD=$!
|
||||
sleep 5
|
||||
# Each node logs its predecessor and successors. At this point, we see the ring.
|
||||
|
||||
# Test lookup.
|
||||
# First check that the lookup is independent of the node we ask.
|
||||
./chord-node lookup -k key1 -n 127.0.0.1:3000
|
||||
./chord-node lookup -k key1 -n 127.0.0.1:3001
|
||||
./chord-node lookup -k key1 -n 127.0.0.1:3002
|
||||
# Now check that we get some different nodes for different keys.
|
||||
./chord-node lookup -k key2 -n 127.0.0.1:3000
|
||||
./chord-node lookup -k key3 -n 127.0.0.1:3000
|
||||
|
||||
# Test leaving.
|
||||
./chord-node leave -n 127.0.0.1:3000
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user