Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
b60f0d58
Commit
b60f0d58
authored
Oct 09, 2014
by
Peter Borzov
Committed by
Juan Batiz-Benet
Oct 09, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Limit update checks to once per configurable time period to avoid HTTP request time delay
parent
3e40ada0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
13 deletions
+43
-13
cmd/ipfs/ipfs.go
cmd/ipfs/ipfs.go
+4
-1
config/config.go
config/config.go
+0
-12
config/version.go
config/version.go
+39
-0
No files found.
cmd/ipfs/ipfs.go
View file @
b60f0d58
...
...
@@ -120,13 +120,16 @@ func localNode(confdir string, online bool) (*core.IpfsNode, error) {
return
nil
,
err
}
if
cfg
.
Version
.
Check
!=
config
.
CheckIgnore
{
if
cfg
.
Version
.
EligibleForUpdateCheck
()
{
obsolete
:=
updates
.
CheckForUpdates
()
if
obsolete
!=
nil
{
if
cfg
.
Version
.
Check
==
config
.
CheckError
{
return
nil
,
obsolete
}
log
.
Warning
(
fmt
.
Sprintf
(
"%v"
,
obsolete
))
// when "warn" version.check mode we just show warning message
}
else
{
// update most recent check timestamp in config
cfg
.
RecordCurrentUpdateCheck
(
filename
)
}
}
...
...
config/config.go
View file @
b60f0d58
...
...
@@ -45,18 +45,6 @@ func (bp *BootstrapPeer) String() string {
return
bp
.
Address
+
"/"
+
bp
.
PeerID
}
// Version regulates checking if the most recent version is run
type
Version
struct
{
Check
string
// "ignore" for do not check, "warn" and "error" for reacting when obsolete
Current
string
// ipfs version for which config was generated
}
const
(
CheckError
=
"error"
// value for Version.Check to raise error and exit if version is obsolete
CheckWarn
=
"warn"
// value for Version.Check to show warning message if version is obsolete
CheckIgnore
=
"ignore"
// value for Version.Check to not perform update check
)
// Config is used to load IPFS config files.
type
Config
struct
{
Identity
Identity
// local node's peer identity
...
...
config/version.go
0 → 100644
View file @
b60f0d58
package
config
import
"time"
// Version regulates checking if the most recent version is run
type
Version
struct
{
Check
string
// "ignore" for do not check, "warn" and "error" for reacting when obsolete
Current
string
// ipfs version for which config was generated
UpdateCheckedTime
time
.
Time
// timestamp for the last time API endpoint was checked for updates
UpdateCheckPeriod
time
.
Duration
// time duration over which the update check will not be performed
}
// supported Version.Check values
const
(
CheckError
=
"error"
// value for Version.Check to raise error and exit if version is obsolete
CheckWarn
=
"warn"
// value for Version.Check to show warning message if version is obsolete
CheckIgnore
=
"ignore"
// value for Version.Check to not perform update check
)
var
defaultUpdateCheckPeriod
=
time
.
Hour
*
48
// EligibleForUpdateCheck returns if update check API endpoint is needed for this specific runtime
func
(
v
*
Version
)
EligibleForUpdateCheck
()
bool
{
if
v
.
Check
==
CheckIgnore
||
v
.
UpdateCheckedTime
.
Add
(
v
.
UpdateCheckPeriod
)
.
After
(
time
.
Now
())
{
return
false
}
return
true
}
// RecordCurrentUpdateCheck is called to record that update check was performed and showed that the running version is the most recent one
func
(
cfg
*
Config
)
RecordCurrentUpdateCheck
(
filename
string
)
{
cfg
.
Version
.
UpdateCheckedTime
=
time
.
Now
()
if
cfg
.
Version
.
UpdateCheckPeriod
==
time
.
Duration
(
0
)
{
// UpdateCheckPeriod was not initialized for some reason (e.g. config file used is broken)
cfg
.
Version
.
UpdateCheckPeriod
=
defaultUpdateCheckPeriod
}
WriteConfigFile
(
filename
,
cfg
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment