commit f758b7f7a501bca2b2a57a6b6da356f167ea8fc4
parent eb21817b69582e5774a07e2ae306f76b85aefba7
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date: Tue, 12 Jul 2022 13:04:09 +0200
relative paid for response
Diffstat:
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/pkg/rest/taldir.go b/pkg/rest/taldir.go
@@ -172,9 +172,6 @@ type Entry struct {
// Public key of the user to register in base32
PublicKey string `json:"public_key"`
- // Time of (re)registration.
- RegisteredAt int64 `json:"-"`
-
// How long the registration lasts in microseconds
Duration time.Duration `json:"-"`
}
@@ -361,7 +358,6 @@ func (t *Taldir) validationRequest(w http.ResponseWriter, r *http.Request){
entry.Inbox = validation.Inbox
tmpDuration := (entry.Duration.Microseconds() + validation.Duration) * 1000
entry.Duration = time.Duration(tmpDuration)
- entry.RegisteredAt = time.Now().UnixMicro()
entry.PublicKey = validation.PublicKey
err = t.Db.First(&entry, "hs_address = ?", entry.HsAddress).Error
if err == nil {
@@ -453,8 +449,7 @@ func (t *Taldir) registerRequest(w http.ResponseWriter, r *http.Request){
entryModified := (req.Inbox != entry.Inbox) ||
(req.PublicKey != entry.PublicKey)
log.Println("Entry for this address already exists..")
- regAt := time.UnixMicro(entry.RegisteredAt)
- entryValidity := regAt.Add(entry.Duration)
+ entryValidity := entry.CreatedAt.Add(entry.Duration)
requestedValidity := entryValidity.Add(reqDuration)
log.Printf("Entry valid until: %s , requested until: %s\n", entryValidity, requestedValidity)
// NOTE: The extension must be at least one month
@@ -462,7 +457,7 @@ func (t *Taldir) registerRequest(w http.ResponseWriter, r *http.Request){
// Nothing changed. Return validity
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "application/json")
- w.Write([]byte("{\"valid_until\": " + entryValidity.String() + "}"))
+ w.Write([]byte(fmt.Sprintf("{\"valid_for\": %d}", time.Until(entryValidity).Microseconds())))
return
} else {
// Entry modified or duration extension requested