mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-09 17:22:21 +08:00
make publish more configurable and add test for repub
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
26
core/core.go
26
core/core.go
@ -56,6 +56,7 @@ import (
|
||||
pin "github.com/ipfs/go-ipfs/pin"
|
||||
repo "github.com/ipfs/go-ipfs/repo"
|
||||
config "github.com/ipfs/go-ipfs/repo/config"
|
||||
u "github.com/ipfs/go-ipfs/util"
|
||||
)
|
||||
|
||||
const IpnsValidatorTag = "ipns"
|
||||
@ -229,26 +230,45 @@ func (n *IpfsNode) startOnlineServicesWithHost(ctx context.Context, host p2phost
|
||||
n.Namesys = namesys.NewNameSystem(n.Routing)
|
||||
|
||||
// setup ipns republishing
|
||||
n.IpnsRepub = ipnsrp.NewRepublisher(n.Routing, n.Repo.Datastore(), n.Peerstore)
|
||||
n.IpnsRepub.AddName(n.Identity)
|
||||
err = n.setupIpnsRepublisher()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *IpfsNode) setupIpnsRepublisher() error {
|
||||
cfg, err := n.Repo.Config()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
n.IpnsRepub = ipnsrp.NewRepublisher(n.Routing, n.Repo.Datastore(), n.Peerstore)
|
||||
n.IpnsRepub.AddName(n.Identity)
|
||||
|
||||
if cfg.Ipns.RepublishPeriod != "" {
|
||||
d, err := time.ParseDuration(cfg.Ipns.RepublishPeriod)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failure to parse config setting IPNS.RepublishPeriod: %s", err)
|
||||
}
|
||||
|
||||
if d < time.Minute || d > (time.Hour*24) {
|
||||
if !u.Debug && (d < time.Minute || d > (time.Hour*24)) {
|
||||
return fmt.Errorf("config setting IPNS.RepublishPeriod is not between 1min and 1day: %s", d)
|
||||
}
|
||||
|
||||
n.IpnsRepub.Interval = d
|
||||
}
|
||||
|
||||
if cfg.Ipns.RecordLifetime != "" {
|
||||
d, err := time.ParseDuration(cfg.Ipns.RepublishPeriod)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failure to parse config setting IPNS.RecordLifetime: %s", err)
|
||||
}
|
||||
|
||||
n.IpnsRepub.RecordLifetime = d
|
||||
}
|
||||
|
||||
n.Process().Go(n.IpnsRepub.Run)
|
||||
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user