commit 772fd99563f7401d9b4af787db5ea16feb57a917
parent cf9841d0292d50dc3550718142a5fd514ebc7322
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date: Tue, 11 Nov 2025 15:45:37 +0100
doc update and format
Diffstat:
2 files changed, 21 insertions(+), 22 deletions(-)
diff --git a/cmd/mailbox-server/main_test.go b/cmd/mailbox-server/main_test.go
@@ -175,7 +175,7 @@ func TestMailboxRegistration(t *testing.T) {
aliceSigningKey := util.Base32CrockfordEncode(testAliceSigningKey)
msg.MailboxMetadata.EncryptionKey = util.Base32CrockfordEncode(encKey)
msg.MailboxMetadata.EncryptionKeyType = "X25519"
- msg.MailboxMetadata.Expiration = mailbox.Timestamp{T_s: uint64(time.Now().Add(time.Hour * 24 * 365).UnixMilli() / 1000)}
+ msg.MailboxMetadata.Expiration = mailbox.Timestamp{T_s: uint64(time.Now().Add(time.Hour*24*365).UnixMilli() / 1000)}
msg.MailboxMetadata.SigningKey = aliceSigningKey
msg.MailboxMetadata.SigningKeyType = "EdDSA"
expNbo := make([]byte, 8)
@@ -222,14 +222,13 @@ func TestMailboxRegistration(t *testing.T) {
a.Db.Where("1 = 1").Delete(&mailbox.PendingMailboxRegistration{})
}
-
func TestMailboxRegistrationPaid(t *testing.T) {
var msg mailbox.MailboxRegistrationRequest
// Make paid
registrationUpdateFee := talerutil.NewAmount("KUDOS", 1, 0)
monthlyFee := talerutil.NewAmount("KUDOS", 2, 0)
- a.RegistrationUpdateFee = ®istrationUpdateFee
+ a.RegistrationUpdateFee = ®istrationUpdateFee
a.MonthlyFee = &monthlyFee
// Dummy pubkey
diff --git a/pkg/rest/mailbox.go b/pkg/rest/mailbox.go
@@ -121,7 +121,6 @@ type Mailbox struct {
// Currency Spec
CurrencySpec talerutil.CurrencySpecification
-
}
type RelativeTime struct {
@@ -135,7 +134,6 @@ type Timestamp struct {
// 1 Month as Go duration
const monthDuration = time.Hour * 24 * 30
-
// VersionResponse is the JSON response of the /config endpoint
type VersionResponse struct {
// libtool-style representation of the Mailbox protocol version, see
@@ -158,10 +156,14 @@ type VersionResponse struct {
MessageResponseLimit uint64 `json:"message_response_limit"`
// How much is the cost of a single
- // registration month of a mailbox
- // May be 0 for a free registration.
- MonthlyFee string `json:"registration_fee"`
+ // registration (update) of a mailbox
+ // May be 0 for a free update/registration.
+ RegistrationUpdateFee string `json:"registration_update_fee"`
+ // How much is the cost of a single
+ // registration period (30 days) of a mailbox
+ // May be 0 for a free registration.
+ MonthlyFee string `json:"monthly_fee"`
}
type MailboxMetadata struct {
@@ -203,16 +205,14 @@ type PendingMailboxRegistration struct {
gorm.Model `json:"-"`
// Hash of the inbox for this entry
- HashedSigningKey string // Requested registration duration
+ HashedSigningKey string // Requested registration duration
Duration time.Duration
// The order ID associated with this registration
OrderID string `json:"-"`
-
}
-
type MailboxRegistrationRequest struct {
// Keys to add/update for a mailbox.
@@ -257,12 +257,13 @@ func (m *Mailbox) configResponse(w http.ResponseWriter, r *http.Request) {
log.Fatal(err)
}
cfg := VersionResponse{
- Version: m.Cfg.LibtoolVersion,
- Name: "taler-mailbox",
- MessageBodyBytes: m.MessageBodyBytes,
- MessageResponseLimit: m.MessageResponseLimit,
- MonthlyFee: m.MonthlyFee.String(),
- DeliveryPeriod: RelativeTime{D_us: uint64(dp.Microseconds())},
+ Version: m.Cfg.LibtoolVersion,
+ Name: "taler-mailbox",
+ MessageBodyBytes: m.MessageBodyBytes,
+ MessageResponseLimit: m.MessageResponseLimit,
+ MonthlyFee: m.MonthlyFee.String(),
+ RegistrationUpdateFee: m.RegistrationUpdateFee.String(),
+ DeliveryPeriod: RelativeTime{D_us: uint64(dp.Microseconds())},
}
w.Header().Set("Content-Type", "application/json")
response, _ := json.Marshal(cfg)
@@ -404,7 +405,6 @@ func calculateCost(sliceCostAmount string, fixedCostAmount string, howLong time.
return sum, nil
}
-
func (m *Mailbox) registerMailboxResponse(w http.ResponseWriter, r *http.Request) {
var msg MailboxRegistrationRequest
var pendingRegistration PendingMailboxRegistration
@@ -443,7 +443,7 @@ func (m *Mailbox) registerMailboxResponse(w http.ResponseWriter, r *http.Request
// This probably meansthe registration is modified or extended or both
entryModified := (registrationEntry.EncryptionKey != msg.MailboxMetadata.EncryptionKey)
// At least one MonthlyFee
- if reqDuration.Microseconds() == 0 && !entryModified {
+ if reqDuration.Microseconds() == 0 && !entryModified {
// Nothing changed. Return validity
w.WriteHeader(http.StatusNotModified)
return
@@ -518,7 +518,7 @@ func (m *Mailbox) registerMailboxResponse(w http.ResponseWriter, r *http.Request
}
func (m *Mailbox) checkPendingRegistrationUpdates(hMailbox string) {
- var pendingEntry PendingMailboxRegistration
+ var pendingEntry PendingMailboxRegistration
var registrationEntry MailboxMetadata
err := m.Db.First(&pendingEntry, "hashed_signing_key = ?", hMailbox).Error
if err != nil {
@@ -526,7 +526,7 @@ func (m *Mailbox) checkPendingRegistrationUpdates(hMailbox string) {
}
m.Logf(LogDebug, "Found pending registration for %s, OrderID: %s", hMailbox, pendingEntry.OrderID)
rc, orderStatus, _, paytoErr := m.Merchant.IsOrderPaid(pendingEntry.OrderID)
- if nil != paytoErr {
+ if nil != paytoErr {
if rc == http.StatusNotFound {
m.Logf(LogInfo, "Registration order for `%s' not found, removing\n", hMailbox)
}
@@ -540,7 +540,7 @@ func (m *Mailbox) checkPendingRegistrationUpdates(hMailbox string) {
if merchant.OrderPaid == orderStatus {
m.Logf(LogDebug, "Order for %v appears to be paid", pendingEntry)
err = m.Db.First(®istrationEntry, "hashed_signing_key = ?", hMailbox).Error
- if err == nil {
+ if err == nil {
m.Logf(LogDebug, "Adding %d seconds to entry expiration", uint64(pendingEntry.Duration.Seconds()))
registrationEntry.Expiration.T_s += uint64(pendingEntry.Duration.Seconds())
m.Db.Save(®istrationEntry)