commit 3123014b404de5c30a8531f0a7a6d9f825440bc8
parent 3997503ee1339a957a8275cb7e8c724ad618d25d
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date: Wed, 6 Dec 2023 19:04:55 +0100
Some cleanup, handle expirations
Diffstat:
1 file changed, 36 insertions(+), 7 deletions(-)
diff --git a/pkg/rest/gnsregistrar.go b/pkg/rest/gnsregistrar.go
@@ -28,10 +28,11 @@ import (
"io"
"net/http"
"os"
+ "strings"
"time"
- "github.com/skip2/go-qrcode"
"github.com/gorilla/mux"
+ "github.com/skip2/go-qrcode"
"gopkg.in/ini.v1"
"taler.net/taler-go.git/pkg/merchant"
talerutil "taler.net/taler-go.git/pkg/util"
@@ -118,6 +119,9 @@ type Registrar struct {
// Gnunet REST API basename
GnunetUrl string
+ // Registrar base URL
+ BaseUrl string
+
// Cost for a registration
RegistrationCost *talerutil.Amount
@@ -163,7 +167,7 @@ func (t *Registrar) registerName(w http.ResponseWriter, r *http.Request) {
delegationRecord.IsSupplemental = false
delegationRecord.IsMaintenance = false
delegationRecord.IsShadow = false
- delegationRecord.RecordType = "PKEY" // FIXME get from value
+ delegationRecord.RecordType = guessDelegationRecordType(r.URL.Query().Get("zkey"))
delegationRecord.RelativeExpiration = uint64(t.RelativeDelegationExpiration.Microseconds())
delegationRecord.Value = r.URL.Query().Get("zkey")
metadataRecord.IsPrivate = true
@@ -257,7 +261,7 @@ func (t *Registrar) setupRegistrationMetadataBeforePayment(label string, zkey st
delegationRecord.IsSupplemental = false
delegationRecord.IsMaintenance = false
delegationRecord.IsShadow = false
- delegationRecord.RecordType = "PKEY" // FIXME get from value
+ delegationRecord.RecordType = guessDelegationRecordType(zkey)
delegationRecord.RelativeExpiration = uint64(t.RelativeDelegationExpiration.Microseconds())
delegationRecord.Value = zkey
metadataRecord.IsPrivate = true
@@ -347,7 +351,7 @@ func (t *Registrar) buyPage(w http.ResponseWriter, r *http.Request) {
fullData := map[string]interface{}{
"qrCode": template.URL("data:image/png;base64," + encodedPng),
"payto": template.URL(payto),
- "fulfillmentUrl": template.URL("/name/" + vars["label"]),
+ "fulfillmentUrl": template.URL(t.BaseUrl + "/name/" + vars["label"]),
"label": vars["label"],
"error": errorMsg,
"cost": t.RegistrationCost,
@@ -381,9 +385,12 @@ func (t *Registrar) getCurrentRegistrationMetadata(label string, nsRecord *Names
if "" == payto {
// Order was paid!
regMetadata.Paid = true
+ var newZkeyRecord RecordData
+ var newMetaRecord RecordData
for _, record := range nsRecord.Records {
- if record.RecordType == "PKEY" {
+ if isDelegationRecordType(record.RecordType) {
record.IsPrivate = false
+ newZkeyRecord = record
}
if record.RecordType == "TXT" {
metadataRecordValue, err := json.Marshal(regMetadata)
@@ -391,19 +398,40 @@ func (t *Registrar) getCurrentRegistrationMetadata(label string, nsRecord *Names
return nil, err
}
record.Value = string(metadataRecordValue)
+ newMetaRecord = record
}
}
+ nsRecord.Records = []RecordData{newMetaRecord, newZkeyRecord}
t.createOrUpdateRegistration(nsRecord)
} else {
if time.Now().After(regMetadata.NeedsPaymentUntil) {
+ fmt.Printf("Payment request for %s has expired, removing\n", label)
t.expireRegistration(label)
return nil, nil
}
}
+ } else {
+ if time.Now().After(time.UnixMicro(int64(regMetadata.Expiration))) {
+ fmt.Printf("Registration for %s has expired, removing\n", label)
+ t.expireRegistration(label)
+ return nil, nil
+ }
}
return ®Metadata, nil
}
+func guessDelegationRecordType(val string) (string) {
+ if strings.HasPrefix(val, "000G00") {
+ return "PKEY"
+ } else {
+ return "EDKEY"
+ }
+}
+
+func isDelegationRecordType(typ string) (bool) {
+ return typ == "PKEY" || typ == "EDKEY"
+}
+
func (t *Registrar) namePage(w http.ResponseWriter, r *http.Request) {
var namestoreResponse NamestoreRecord
vars := mux.Vars(r)
@@ -440,7 +468,7 @@ func (t *Registrar) namePage(w http.ResponseWriter, r *http.Request) {
return
}
for _, record := range namestoreResponse.Records {
- if record.RecordType == "PKEY" {
+ if isDelegationRecordType(record.RecordType) {
value = record.Value
}
}
@@ -518,8 +546,9 @@ func (t *Registrar) Initialize(cfgfile string) {
t.PaymentExpiration, _ = time.ParseDuration(paymentExp)
fmt.Println(t.RelativeDelegationExpiration)
fmt.Println(t.RelativeRegistrationExpiration)
- costStr := t.Cfg.Section("gns-registrar").Key("registration_cost").MustString("KUDOS:13")
+ costStr := t.Cfg.Section("gns-registrar").Key("registration_cost").MustString("KUDOS:0.3")
t.RegistrationCost, err = talerutil.ParseAmount(costStr)
+ t.BaseUrl = t.Cfg.Section("gns-registrar").Key("base_url").MustString("http://localhost:11000")
t.SuffixHint = t.Cfg.Section("gns-registrar").Key("suffix_hint").MustString("example.alt")
t.RootZoneName = t.Cfg.Section("gns-registrar").Key("root_zone_name").MustString("test")
t.GnunetUrl = t.Cfg.Section("gns-registrar").Key("gnunet_baseurl_private").MustString("http://localhost:7776")