implement lookup

This commit is contained in:
Branden J Brown 2025-03-15 07:56:31 -04:00
parent c0afd85f11
commit 5d5155d8d8
2 changed files with 27 additions and 3 deletions

21
main.go
View File

@ -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)

View File

@ -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