Compare commits
No commits in common. "56c1ad3737bcb67f1d0ecd4a448041f99dd8525c" and "730bb45db4ea8bbe09a7d71de046da9bbefc5260" have entirely different histories.
56c1ad3737
...
730bb45db4
@ -5,7 +5,6 @@ import (
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
@ -36,7 +35,6 @@ func (cl *Client) Find(ctx context.Context, s chord.Peer, id chord.ID) (chord.Pe
|
||||
if err != nil {
|
||||
return chord.Peer{}, "", err
|
||||
}
|
||||
slog.InfoContext(ctx, "find", slog.String("url", url.String()))
|
||||
resp, err := cl.HTTP.Do(req)
|
||||
if err != nil {
|
||||
return chord.Peer{}, "", err
|
||||
@ -45,7 +43,6 @@ func (cl *Client) Find(ctx context.Context, s chord.Peer, id chord.ID) (chord.Pe
|
||||
if err != nil {
|
||||
return chord.Peer{}, "", fmt.Errorf("%w (%s)", err, resp.Status)
|
||||
}
|
||||
slog.InfoContext(ctx, "found", slog.String("peer", p.Peer.String()), slog.String("value", p.Value))
|
||||
return chord.Address(p.Peer), p.Value, nil
|
||||
}
|
||||
|
||||
|
@ -28,9 +28,6 @@ func writeError(w http.ResponseWriter, status int, msg string) {
|
||||
}
|
||||
|
||||
func readResponse[T any](r *http.Response) (x T, err error) {
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return x, errors.New(r.Status)
|
||||
}
|
||||
var b struct {
|
||||
Data T `json:"data"`
|
||||
Error string `json:"error"`
|
||||
@ -41,7 +38,7 @@ func readResponse[T any](r *http.Response) (x T, err error) {
|
||||
if b.Error != "" {
|
||||
return x, errors.New(b.Error)
|
||||
}
|
||||
return b.Data, nil
|
||||
return x, nil
|
||||
}
|
||||
|
||||
type neighbors struct {
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/netip"
|
||||
@ -68,7 +67,6 @@ func (n *Node) Check(ctx context.Context) error {
|
||||
|
||||
func (n *Node) key(w http.ResponseWriter, r *http.Request) {
|
||||
s := r.PathValue("id")
|
||||
slog.InfoContext(r.Context(), "received find", slog.String("id", s), slog.String("from", r.RemoteAddr))
|
||||
id, err := chord.ParseID(s)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusBadRequest, err.Error())
|
||||
@ -80,7 +78,6 @@ func (n *Node) key(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
_, addr := p.Values()
|
||||
slog.InfoContext(r.Context(), "tell found", slog.String("id", s), slog.String("addr", addr.String()), slog.String("value", v))
|
||||
pv := peervalue{addr, v}
|
||||
writeOk(w, pv)
|
||||
}
|
||||
|
3
main.go
3
main.go
@ -147,8 +147,7 @@ func cliJoin(ctx context.Context, cmd *cli.Command) error {
|
||||
cl := &httpnode.Client{HTTP: http.Client{Timeout: 5 * time.Second}}
|
||||
var node *chord.Node
|
||||
if peer := cmd.String("c"); peer != "" {
|
||||
var p netip.AddrPort
|
||||
p, err = netip.ParseAddrPort(peer)
|
||||
p, err := netip.ParseAddrPort(peer)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user