Compare commits

..

No commits in common. "94580d73be24d43e82ee28db40109023500073c5" and "4a69e646547e05c0b612307c37ccdc935be417a6" have entirely different histories.

4 changed files with 3 additions and 41 deletions

View File

@ -94,7 +94,6 @@ func Join(ctx context.Context, cl Client, addr netip.AddrPort, np Peer) (*Node,
self: self,
succ: s,
fingers: make([]Peer, 0, 8*len(ID{})),
data: make(map[ID]string),
}
return r, nil
}

View File

@ -205,7 +205,6 @@ func Create(addr netip.AddrPort) (*Node, error) {
self: self,
succ: []Peer{self}[:1:1], // extra cautious about capacity
fingers: make([]Peer, 0, len(ID{})*8),
data: make(map[ID]string),
}
return n, nil
}

36
main.go
View File

@ -2,6 +2,7 @@ package main
import (
"context"
"errors"
"fmt"
"log/slog"
"net"
@ -222,39 +223,8 @@ func cliLookup(ctx context.Context, cmd *cli.Command) error {
return nil
}
func cliPut(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"))
v := cmd.String("v")
cl := &httpnode.Client{HTTP: http.Client{Timeout: 5 * time.Second}}
p, err := cl.FindSuccessor(ctx, chord.Address(n), k)
if err != nil {
return err
}
return cl.Set(ctx, p, k, v)
}
func cliGet(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
}
v, err := cl.Get(ctx, p, k)
if err != nil {
return err
}
fmt.Println(v)
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

@ -26,12 +26,6 @@ sleep 5
./chord-node lookup -k key2 -n 127.0.0.1:3000
./chord-node lookup -k key3 -n 127.0.0.1:3000
# Test data storage.
./chord-node put -k key1 -v value1 -n 127.0.0.1:3000
./chord-node get -k key1 -n 127.0.0.1:3000
./chord-node put -k key1 -v value2 -n 127.0.0.1:3001
./chord-node get -k key1 -n 127.0.0.1:3002
# Test leaving.
./chord-node leave -n 127.0.0.1:3000