From febf21b0c79a8bc49da6eec580091197def01067 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 29 Nov 2017 15:15:58 -0800 Subject: [PATCH 1/5] fix republish interval documentation We republish every 4 hours, not 12. License: MIT Signed-off-by: Steven Allen --- docs/config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/config.md b/docs/config.md index d60c03eca..6c129e44f 100644 --- a/docs/config.md +++ b/docs/config.md @@ -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 From d8de88c4b606eca1683a366e099c41e6688f4b19 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 29 Nov 2017 15:22:00 -0800 Subject: [PATCH 2/5] publish ipns records on start (after a delay of 1 minute) License: MIT Signed-off-by: Steven Allen --- namesys/republisher/repub.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/namesys/republisher/repub.go b/namesys/republisher/repub.go index 3ab382473..b7c864cbd 100644 --- a/namesys/republisher/repub.go +++ b/namesys/republisher/repub.go @@ -27,6 +27,7 @@ var errNoEntry = errors.New("no previous entry") var log = logging.Logger("ipns-repub") var DefaultRebroadcastInterval = time.Hour * 4 +var InitialRebroadcastDelay = time.Minute * 1 const DefaultRecordLifetime = time.Hour * 24 @@ -57,10 +58,12 @@ 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() + delayCh := time.After(InitialRebroadcastDelay) for { select { - case <-tick.C: + case <-delayCh: + delayCh = tick.C err := rp.republishEntries(proc) if err != nil { log.Error("Republisher failed to republish: ", err) From 40b3a72498b458fe9feaeb075b0ff6ffdf28a903 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 29 Nov 2017 15:27:49 -0800 Subject: [PATCH 3/5] retry publishing IPNS records every 5 minutes on failure This way, if we *happen* to be offline while attempting a publish, we don't wait the full interval. License: MIT Signed-off-by: Steven Allen --- namesys/republisher/repub.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/namesys/republisher/repub.go b/namesys/republisher/repub.go index b7c864cbd..28a873f10 100644 --- a/namesys/republisher/repub.go +++ b/namesys/republisher/repub.go @@ -28,6 +28,7 @@ var log = logging.Logger("ipns-repub") var DefaultRebroadcastInterval = time.Hour * 4 var InitialRebroadcastDelay = time.Minute * 1 +var FailureRetryInterval = time.Minute * 5 const DefaultRecordLifetime = time.Hour * 24 @@ -56,17 +57,17 @@ 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() - delayCh := time.After(InitialRebroadcastDelay) + timer := time.NewTimer(InitialRebroadcastDelay) + defer timer.Stop() for { select { - case <-delayCh: - delayCh = tick.C + case <-timer.C: + timer.Reset(rp.Interval) err := rp.republishEntries(proc) if err != nil { log.Error("Republisher failed to republish: ", err) + timer.Reset(FailureRetryInterval) } case <-proc.Closing(): return From fd2d63c5badd4842a290f863f1485a6be8897282 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 29 Nov 2017 15:46:34 -0800 Subject: [PATCH 4/5] document ipns republisher variables (makes code climate happy) License: MIT Signed-off-by: Steven Allen --- namesys/republisher/repub.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/namesys/republisher/repub.go b/namesys/republisher/repub.go index 28a873f10..e1b0473d8 100644 --- a/namesys/republisher/repub.go +++ b/namesys/republisher/repub.go @@ -26,10 +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 { From 228c5552ab7b14875692a52aa97a01becec4771b Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 29 Nov 2017 15:54:06 -0800 Subject: [PATCH 5/5] always obey the IPNS rebroadcast interval if it's smaller License: MIT Signed-off-by: Steven Allen --- namesys/republisher/repub.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/namesys/republisher/repub.go b/namesys/republisher/repub.go index e1b0473d8..4b1496fe6 100644 --- a/namesys/republisher/repub.go +++ b/namesys/republisher/repub.go @@ -65,6 +65,9 @@ func NewRepublisher(r routing.ValueStore, ds ds.Datastore, self ic.PrivKey, ks k func (rp *Republisher) Run(proc goprocess.Process) { timer := time.NewTimer(InitialRebroadcastDelay) defer timer.Stop() + if rp.Interval < InitialRebroadcastDelay { + timer.Reset(rp.Interval) + } for { select { @@ -73,7 +76,9 @@ func (rp *Republisher) Run(proc goprocess.Process) { err := rp.republishEntries(proc) if err != nil { log.Error("Republisher failed to republish: ", err) - timer.Reset(FailureRetryInterval) + if FailureRetryInterval < rp.Interval { + timer.Reset(FailureRetryInterval) + } } case <-proc.Closing(): return