Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix failed count; improved logging #245

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions impl/pkg/server/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ func (r *DHTRouter) GetRecord(c *gin.Context) {
// make sure the key is valid
key, err := util.Z32Decode(*id)
if err != nil {
LoggingRespondErrWithMsg(c, err, "invalid record id", http.StatusInternalServerError)
LoggingRespondErrWithMsg(c, err, fmt.Sprintf("invalid record id: %s", *id), http.StatusInternalServerError)
return
}
if len(key) != ed25519.PublicKeySize {
LoggingRespondErrMsg(c, "invalid z32 encoded ed25519 public key", http.StatusBadRequest)
LoggingRespondErrMsg(c, fmt.Sprintf("invalid z32 encoded ed25519 public key: %s", *id), http.StatusBadRequest)
return
}

Expand All @@ -67,11 +67,11 @@ func (r *DHTRouter) GetRecord(c *gin.Context) {
LoggingRespondErrMsg(c, fmt.Sprintf("too many requests for bad key %s", *id), http.StatusTooManyRequests)
return
}
LoggingRespondErrWithMsg(c, err, "failed to get dht record", http.StatusInternalServerError)
LoggingRespondErrWithMsg(c, err, fmt.Sprintf("failed to get dht record: %s", *id), http.StatusInternalServerError)
return
}
if resp == nil {
LoggingRespondErrMsg(c, "dht record not found", http.StatusNotFound)
LoggingRespondErrMsg(c, fmt.Sprintf("dht record not found: %s", *id), http.StatusNotFound)
return
}

Expand Down Expand Up @@ -106,24 +106,24 @@ func (r *DHTRouter) PutRecord(c *gin.Context) {
}
key, err := util.Z32Decode(*id)
if err != nil {
LoggingRespondErrWithMsg(c, err, "invalid record id", http.StatusInternalServerError)
LoggingRespondErrWithMsg(c, err, fmt.Sprintf("invalid record id: %s", *id), http.StatusInternalServerError)
return
}
if len(key) != ed25519.PublicKeySize {
LoggingRespondErrMsg(c, "invalid z32 encoded ed25519 public key", http.StatusBadRequest)
LoggingRespondErrMsg(c, fmt.Sprintf("invalid z32 encoded ed25519 public key: %s", *id), http.StatusBadRequest)
return
}

body, err := io.ReadAll(c.Request.Body)
if err != nil {
LoggingRespondErrWithMsg(c, err, "failed to read body", http.StatusInternalServerError)
LoggingRespondErrWithMsg(c, err, fmt.Sprintf("failed to read body for id: %s", *id), http.StatusInternalServerError)
return
}
defer c.Request.Body.Close()

// 64 byte signature and 8 byte sequence number
if len(body) <= 72 {
LoggingRespondErrMsg(c, "invalid request body", http.StatusBadRequest)
LoggingRespondErrMsg(c, fmt.Sprintf("invalid request body for id: %s", *id), http.StatusBadRequest)
return
}

Expand All @@ -138,7 +138,7 @@ func (r *DHTRouter) PutRecord(c *gin.Context) {
}

if err = r.service.PublishDHT(ctx, *id, *request); err != nil {
LoggingRespondErrWithMsg(c, err, "failed to publish dht record", http.StatusInternalServerError)
LoggingRespondErrWithMsg(c, err, fmt.Sprintf("failed to publish dht record: %s", *id), http.StatusInternalServerError)
return
}

Expand Down
4 changes: 1 addition & 3 deletions impl/pkg/storage/db/bolt/bolt.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,7 @@ func (b *Bolt) WriteFailedRecord(ctx context.Context, id string) error {
var count int32 = 1
v := bucket.Get([]byte(id))
if v != nil {
if err = json.Unmarshal(v, &count); err != nil {
return err
}
count = int32(binary.LittleEndian.Uint32(v))
count++
}

Expand Down
Loading