Merge pull request #4440 from ipfs/fix/ipns-repub

Fix various IPNS issues
This commit is contained in:
Whyrusleeping 2017-12-01 17:30:06 +01:00 committed by GitHub
commit bc7124226c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

View File

@ -208,7 +208,7 @@ The base64 encoded protobuf describing (and containing) the nodes private key.
- `RepublishPeriod`
A time duration specifying how frequently to republish ipns records to ensure
they stay fresh on the network. If unset, we default to 12 hours.
they stay fresh on the network. If unset, we default to 4 hours.
- `RecordLifetime`
A time duration specifying the value to set on ipns records for their validity

View File

@ -26,8 +26,16 @@ var errNoEntry = errors.New("no previous entry")
var log = logging.Logger("ipns-repub")
// DefaultRebroadcastInterval is the default interval at which we rebroadcast IPNS records
var DefaultRebroadcastInterval = time.Hour * 4
// InitialRebroadcastDelay is the delay before first broadcasting IPNS records on start
var InitialRebroadcastDelay = time.Minute * 1
// FailureRetryInterval is the interval at which we retry IPNS records broadcasts (when they fail)
var FailureRetryInterval = time.Minute * 5
// DefaultRecordLifetime is the default lifetime for IPNS records
const DefaultRecordLifetime = time.Hour * 24
type Republisher struct {
@ -55,15 +63,22 @@ func NewRepublisher(r routing.ValueStore, ds ds.Datastore, self ic.PrivKey, ks k
}
func (rp *Republisher) Run(proc goprocess.Process) {
tick := time.NewTicker(rp.Interval)
defer tick.Stop()
timer := time.NewTimer(InitialRebroadcastDelay)
defer timer.Stop()
if rp.Interval < InitialRebroadcastDelay {
timer.Reset(rp.Interval)
}
for {
select {
case <-tick.C:
case <-timer.C:
timer.Reset(rp.Interval)
err := rp.republishEntries(proc)
if err != nil {
log.Error("Republisher failed to republish: ", err)
if FailureRetryInterval < rp.Interval {
timer.Reset(FailureRetryInterval)
}
}
case <-proc.Closing():
return