@cryptotaxi247 / kubo / commits / 74fad48e4

clean up dead code and config fields

License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>

Jeromy committed Apr 8, 2016 at 13:11 UTC 74fad48e4b79dc59e5eb8d891a6eac97ecf5e722
3 files changed +2 -140
repo/config/config.go
-1
@@ -21,7 +21,6 @@ type Config struct {
21 Datastore Datastore // local node's storage
22 Addresses Addresses // local node's addresses
23 Mounts Mounts // local node's mount points
24 - Version Version // local node's version management
24 Discovery Discovery // local node's discovery mechanisms
25 Ipns Ipns // Ipns settings
26 Bootstrap []string // local nodes's bootstrap peer addresses
repo/config/init.go
+2 -12
@@ -21,11 +21,6 @@ func Init(out io.Writer, nBitsForKeypair int) (*Config, error) {
21 return nil, err
22 }
23
24 - snr, err := initSNRConfig()
25 - if err != nil {
26 - return nil, err
27 - }
28 -
24 conf := &Config{
25
26 // setup the node's default addresses.
@@ -40,9 +35,8 @@ func Init(out io.Writer, nBitsForKeypair int) (*Config, error) {
35 Gateway: "/ip4/127.0.0.1/tcp/8080",
36 },
37
43 - Bootstrap: BootstrapPeerStrings(bootstrapPeers),
44 - SupernodeRouting: *snr,
45 - Identity: identity,
38 + Bootstrap: BootstrapPeerStrings(bootstrapPeers),
39 + Identity: identity,
40 Discovery: Discovery{MDNS{
41 Enabled: true,
42 Interval: 10,
@@ -58,10 +52,6 @@ func Init(out io.Writer, nBitsForKeypair int) (*Config, error) {
52 ResolveCacheSize: 128,
53 },
54
61 - // tracking ipfs version used to generate the init folder and adding
62 - // update checker default setting.
63 - Version: VersionDefaultValue(),
64 -
55 Gateway: Gateway{
56 RootRedirect: "",
57 Writable: false,
repo/config/version.go
-127
@@ -1,12 +1,5 @@
1 package config
2
3 -import (
4 - "errors"
5 - "strconv"
6 - "strings"
7 - "time"
8 -)
9 -
3 // CurrentCommit is the current git commit, this is set as a ldflag in the Makefile
4 var CurrentCommit string
5
@@ -14,123 +7,3 @@ var CurrentCommit string
7 const CurrentVersionNumber = "0.4.0"
8
9 const ApiVersion = "/go-ipfs/" + CurrentVersionNumber + "/"
17 -
18 -// Version regulates checking if the most recent version is run
19 -type Version struct {
20 - // Current is the ipfs version for which config was generated
21 - Current string
22 -
23 - // Check signals how to react on updates:
24 - // - "ignore" for not checking
25 - // - "warn" for issuing a warning and proceeding
26 - // - "error" for exiting with an error
27 - Check string
28 -
29 - // CheckDate is a timestamp for the last time API endpoint was checked for updates
30 - CheckDate time.Time
31 -
32 - // CheckPeriod is the time duration over which the update check will not be performed
33 - // (Note: cannot use time.Duration because marshalling with json breaks it)
34 - CheckPeriod string
35 -
36 - // AutoUpdate is optional
37 - AutoUpdate AutoUpdateSetting
38 -}
39 -
40 -// supported Version.Check values
41 -const (
42 - // CheckError value for Version.Check to raise error and exit if version is obsolete
43 - CheckError = "error"
44 -
45 - // CheckWarn value for Version.Check to show warning message if version is obsolete
46 - CheckWarn = "warn"
47 -
48 - // CheckIgnore value for Version.Check to not perform update check
49 - CheckIgnore = "ignore"
50 -)
51 -
52 -// AutoUpdateSetting implements json.Unmarshaler to check values in config
53 -type AutoUpdateSetting int
54 -
55 -// AutoUpdateSetting values
56 -const (
57 - AutoUpdateNever AutoUpdateSetting = iota // do not auto-update
58 - AutoUpdatePatch // only on new patch versions
59 - AutoUpdateMinor // on new minor or patch versions (Default)
60 - AutoUpdateMajor // on all, even Major, version changes
61 -)
62 -
63 -// ErrUnknownAutoUpdateSetting is returned when an unknown value is read from the config
64 -var ErrUnknownAutoUpdateSetting = errors.New("unknown value for AutoUpdate")
65 -
66 -// defaultCheckPeriod governs h
67 -var defaultCheckPeriod = time.Hour * 48
68 -
69 -// UnmarshalJSON checks the input against known strings
70 -func (s *AutoUpdateSetting) UnmarshalJSON(in []byte) error {
71 -
72 - switch strings.ToLower(string(in)) {
73 - case `"never"`:
74 - *s = AutoUpdateNever
75 - case `"major"`:
76 - *s = AutoUpdateMajor
77 - case `"minor"`:
78 - *s = AutoUpdateMinor
79 - case `"patch"`:
80 - *s = AutoUpdatePatch
81 - default:
82 - *s = AutoUpdateMinor
83 - return ErrUnknownAutoUpdateSetting
84 - }
85 - return nil
86 -}
87 -
88 -// MarshalJSON converts the value back to JSON string
89 -func (s AutoUpdateSetting) MarshalJSON() ([]byte, error) {
90 - return []byte(`"` + s.String() + `"`), nil
91 -}
92 -
93 -// String converts valye to human readable string
94 -func (s AutoUpdateSetting) String() string {
95 - switch s {
96 - case AutoUpdateNever:
97 - return "never"
98 - case AutoUpdateMajor:
99 - return "major"
100 - case AutoUpdateMinor:
101 - return "minor"
102 - case AutoUpdatePatch:
103 - return "patch"
104 - default:
105 - return ErrUnknownAutoUpdateSetting.Error()
106 - }
107 -}
108 -
109 -func (v *Version) checkPeriodDuration() time.Duration {
110 - d, err := strconv.Atoi(v.CheckPeriod)
111 - if err != nil {
112 - log.Warning("config.Version.CheckPeriod parse error. Using default.")
113 - return defaultCheckPeriod
114 - }
115 - return time.Duration(d)
116 -}
117 -
118 -// ShouldCheckForUpdate returns if update check API endpoint is needed for this specific runtime
119 -func (v *Version) ShouldCheckForUpdate() bool {
120 -
121 - period := v.checkPeriodDuration()
122 - if v.Check == CheckIgnore || v.CheckDate.Add(period).After(time.Now()) {
123 - return false
124 - }
125 - return true
126 -}
127 -
128 -// VersionDefaultValue returns the default version config value (for init).
129 -func VersionDefaultValue() Version {
130 - return Version{
131 - Current: CurrentVersionNumber,
132 - Check: "error",
133 - CheckPeriod: strconv.Itoa(int(defaultCheckPeriod)),
134 - AutoUpdate: AutoUpdateMinor,
135 - }
136 -}