taldir

Directory service to resolve wallet mailboxes by messenger addresses
Log | Files | Refs | Submodules | README | LICENSE

commit 5f0b943e9a12cbbac0f435f224ffb80c69c967b0
parent a5e6294866bba2cb978a7caa22e36fd364273e3b
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date:   Sat,  7 Jun 2025 22:45:58 +0200

start implementing disseminator functionality for GNS/DNS

Diffstat:
Mpkg/rest/taldir.go | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+), 0 deletions(-)

diff --git a/pkg/rest/taldir.go b/pkg/rest/taldir.go @@ -88,6 +88,9 @@ type Taldir struct { // Map of supported validators as defined in the configuration Validators map[string]Validator + // Map of supported disseminators as defined in the configuration + Disseminators map[string]Disseminator + // imprint page ImprintTpl *template.Template @@ -177,6 +180,16 @@ type Validator struct { LandingPageTpl *template.Template } +type Disseminator struct { + + // Disseminator name + Name string + + // The command to call for dissemination + Command string + +} + // VersionResponse is the JSON response of the /config endpoint type VersionResponse struct { // libtool-style representation of the Merchant protocol version, see @@ -378,6 +391,37 @@ func (t *Taldir) getSingleEntry(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNotFound) } +// Disseminate entry +func (t *Taldir) disseminateEntry(e Entry) error { + for _, d := range t.Disseminators { + path, err := exec.LookPath(d.Command) + if err != nil { + t.Logf(LogError, err.Error()+"\n") + return fmt.Errorf("path of command not found: %w", err) + } + t.Logf(LogDebug, "Found `%s' in path as `%s'\n", d.Command, path) + out, err := exec.Command(path, e.HsAddress, e.TargetUri).Output() + t.Logf(LogDebug, "Executing `%s %s %s `\n", path, e.HsAddress, e.TargetUri) + if err != nil { + return fmt.Errorf("failed to execute disseminator command: `%s', %w", out, err) + } + } + return nil +} + +// Disseminate all entries +func (t *Taldir) disseminateEntries() error { + var entries []Entry + t.Db.Where("1 = 1").Find(&entries) + for _, e := range entries { + err := t.disseminateEntry(e) + if err != nil { + return fmt.Errorf("failed to disseminate `%s': %w", e.HsAddress, err) + } + } + return nil +} + // Hashes an identity key (e.g. sha256(<email address>)) with a salt for // Lookup and storage. func saltHAddress(hAddress string, salt string) string { @@ -452,6 +496,7 @@ func (t *Taldir) validationRequest(w http.ResponseWriter, r *http.Request) { } } else { t.Db.Save(&entry) + t.disseminateEntry(entry) } } else { if validation.TargetUri == "" { @@ -1020,6 +1065,17 @@ func (t *Taldir) Initialize(cfg TaldirConfig) { ValidAliasRegex: sec.Key("valid_alias_regex").MustString(""), } } + t.Disseminators = make(map[string]Disseminator) + for _, sec := range cfg.Ini.Sections() { + if !strings.HasPrefix(sec.Name(), "taldir-disseminator-") { + continue + } + dname := strings.TrimPrefix(sec.Name(), "taldir-disseminator-") + t.Disseminators[dname] = Disseminator{ + Name: dname, + Command: sec.Key("command").MustString(""), + } + } t.ChallengeBytes = cfg.Ini.Section("taldir").Key("challenge_bytes").MustInt(16) t.ValidationInitiationMax = cfg.Ini.Section("taldir").Key("validation_initiation_max").MustInt64(3) t.SolutionAttemptsMax = cfg.Ini.Section("taldir").Key("solution_attempt_max").MustInt(3)