package node import ( "fmt" "time" util "gitlab.dms3.io/dms3/go-dms3-util" "gitlab.dms3.io/dms3/go-dms3ns" "gitlab.dms3.io/p2p/go-p2p-core/crypto" "gitlab.dms3.io/p2p/go-p2p-core/peerstore" "gitlab.dms3.io/p2p/go-p2p-core/routing" record "gitlab.dms3.io/p2p/go-p2p-record" "gitlab.dms3.io/dms3/go-dms3/namesys" "gitlab.dms3.io/dms3/go-dms3/namesys/republisher" "gitlab.dms3.io/dms3/go-dms3/repo" ) const DefaultDms3NsCacheSize = 128 // RecordValidator provides namesys compatible routing record validator func RecordValidator(ps peerstore.Peerstore) record.Validator { return record.NamespacedValidator{ "pk": record.PublicKeyValidator{}, "dms3ns": dms3ns.Validator{KeyBook: ps}, } } // Namesys creates new name system func Namesys(cacheSize int) func(rt routing.Routing, repo repo.Repo) (namesys.NameSystem, error) { return func(rt routing.Routing, repo repo.Repo) (namesys.NameSystem, error) { return namesys.NewNameSystem(rt, repo.Datastore(), cacheSize), nil } } // Dms3NsRepublisher runs new DMS3NS republisher service func Dms3NsRepublisher(repubPeriod time.Duration, recordLifetime time.Duration) func(lcProcess, namesys.NameSystem, repo.Repo, crypto.PrivKey) error { return func(lc lcProcess, namesys namesys.NameSystem, repo repo.Repo, privKey crypto.PrivKey) error { repub := republisher.NewRepublisher(namesys, repo.Datastore(), privKey, repo.Keystore()) if repubPeriod != 0 { if !util.Debug && (repubPeriod < time.Minute || repubPeriod > (time.Hour*24)) { return fmt.Errorf("config setting DMS3NS.RepublishPeriod is not between 1min and 1day: %s", repubPeriod) } repub.Interval = repubPeriod } if recordLifetime != 0 { repub.RecordLifetime = recordLifetime } lc.Append(repub.Run) return nil } }