@@ -17,12 +17,24 @@ import (
1717
1818const (
1919 baseExtendedURL = "https://raw.githubusercontent.com/threefoldtech/zos-config/main/"
20- hubURL = "https://hub.threefold.me"
21- v4HubURL = "https://v4.hub.threefold.me"
22- flistURL = "redis://hub.threefold.me:9900"
23- v4FlistURL = "redis://v4.hub.threefold.me:9940"
20+
21+ defaultHubURL = "https://hub.threefold.me"
22+ defaultV4HubURL = "https://v4.hub.threefold.me"
23+
24+ defaultFlistURL = "redis://hub.threefold.me:9900"
25+ defaultV4FlistURL = "redis://v4.hub.threefold.me:9940"
26+
27+ defaultHubStorage = "zdb://hub.threefold.me:9900"
28+ defaultV4HubStorage = "zdb://v4.hub.threefold.me:9940"
2429)
2530
31+ var defaultGeoipURLs = []string {
32+ "https://geoip.threefold.me/" ,
33+ "https://geoip.grid.tf/" ,
34+ "https://02.geoip.grid.tf/" ,
35+ "https://03.geoip.grid.tf/" ,
36+ }
37+
2638// PubMac specify how the mac address of the public nic
2739// (in case of public-config) is calculated
2840type PubMac string
@@ -42,8 +54,12 @@ const (
4254type Environment struct {
4355 RunningMode RunMode
4456
45- FlistURL string
46- BinRepo string
57+ FlistURL string
58+ HubStorage string
59+ BinRepo string
60+
61+ HubURL string
62+ V4HubURL string
4763
4864 FarmID pkg.FarmID
4965 Orphan bool
@@ -56,9 +72,9 @@ type Environment struct {
5672 relaysURLs []string
5773 ActivationURL []string
5874 GraphQL []string
75+ GeoipURLs []string
5976 KycURL string
6077 RegistrarURL string
61- HubURL string
6278
6379 // private vlan to join
6480 // if set, zos will use this as its priv vlan
@@ -126,15 +142,18 @@ var (
126142 "https://activation.dev.grid.tf/activation/activate" ,
127143 "https://activation.02.dev.grid.tf/activation/activate" ,
128144 },
129- FlistURL : flistURL ,
130- HubURL : hubURL ,
131- BinRepo : "tf-zos-v3-bins.dev" ,
145+ HubURL : defaultHubURL ,
146+ V4HubURL : defaultV4HubURL ,
147+ FlistURL : defaultFlistURL ,
148+ HubStorage : defaultHubStorage ,
149+ BinRepo : "tf-zos-v3-bins.dev" ,
132150 GraphQL : []string {
133151 "https://graphql.dev.grid.tf/graphql" ,
134152 "https://graphql.02.dev.grid.tf/graphql" ,
135153 },
136154 KycURL : "https://kyc.dev.grid.tf" ,
137155 RegistrarURL : "http://registrar.dev4.grid.tf" ,
156+ GeoipURLs : defaultGeoipURLs ,
138157 }
139158
140159 envTest = Environment {
@@ -150,15 +169,18 @@ var (
150169 "https://activation.test.grid.tf/activation/activate" ,
151170 "https://activation.02.test.grid.tf/activation/activate" ,
152171 },
153- FlistURL : flistURL ,
154- HubURL : hubURL ,
155- BinRepo : "tf-zos-v3-bins.test" ,
172+ HubURL : defaultHubURL ,
173+ V4HubURL : defaultV4HubURL ,
174+ FlistURL : defaultFlistURL ,
175+ HubStorage : defaultHubStorage ,
176+ BinRepo : "tf-zos-v3-bins.test" ,
156177 GraphQL : []string {
157178 "https://graphql.test.grid.tf/graphql" ,
158179 "https://graphql.02.test.grid.tf/graphql" ,
159180 },
160181 KycURL : "https://kyc.test.grid.tf" ,
161182 RegistrarURL : "http://registrar.test4.grid.tf" ,
183+ GeoipURLs : defaultGeoipURLs ,
162184 }
163185
164186 envQA = Environment {
@@ -174,15 +196,18 @@ var (
174196 "https://activation.qa.grid.tf/activation/activate" ,
175197 "https://activation.02.qa.grid.tf/activation/activate" ,
176198 },
177- FlistURL : flistURL ,
178- HubURL : hubURL ,
179- BinRepo : "tf-zos-v3-bins.qanet" ,
199+ HubURL : defaultHubURL ,
200+ V4HubURL : defaultV4HubURL ,
201+ FlistURL : defaultFlistURL ,
202+ HubStorage : defaultHubStorage ,
203+ BinRepo : "tf-zos-v3-bins.qanet" ,
180204 GraphQL : []string {
181205 "https://graphql.qa.grid.tf/graphql" ,
182206 "https://graphql.02.qa.grid.tf/graphql" ,
183207 },
184208 KycURL : "https://kyc.qa.grid.tf" ,
185209 RegistrarURL : "https://registrar.qa4.grid.tf" ,
210+ GeoipURLs : defaultGeoipURLs ,
186211 }
187212
188213 envProd = Environment {
@@ -201,17 +226,22 @@ var (
201226 "https://activation.grid.threefold.me/activation/activate" ,
202227 "https://activation.grid.tf/activation/activate" ,
203228 "https://activation.02.grid.tf/activation/activate" ,
229+ "https://activation.grid.threefold.me/activation/activate" ,
204230 },
205- HubURL : hubURL ,
206- FlistURL : flistURL ,
207- BinRepo : "tf-zos-v3-bins" ,
231+ HubURL : defaultHubURL ,
232+ V4HubURL : defaultV4HubURL ,
233+ FlistURL : defaultFlistURL ,
234+ HubStorage : defaultHubStorage ,
235+ BinRepo : "tf-zos-v3-bins" ,
208236 GraphQL : []string {
209237 "https://graphql.grid.threefold.me/graphql" ,
210238 "https://graphql.grid.tf/graphql" ,
211239 "https://graphql.02.grid.tf/graphql" ,
240+ "https://graphql.grid.threefold.me/graphql" ,
212241 },
213242 KycURL : "https://kyc.threefold.me" ,
214243 RegistrarURL : "https://registrar.prod4.threefold.me" ,
244+ GeoipURLs : defaultGeoipURLs ,
215245 }
216246)
217247
@@ -295,29 +325,24 @@ func getEnvironmentFromParams(params kernel.Params) (Environment, error) {
295325 if err != nil {
296326 // maybe the node can't reach the internet right now
297327 // this will enforce node to skip config
328+ // or we can keep retrying untill it can fetch config
298329 config = Config {}
299330 }
300331
301- if substrate , ok := params .Get ("substrate" ); ok {
302- if len (substrate ) > 0 {
303- env .SubstrateURL = substrate
304- }
332+ if substrate , ok := params .Get ("substrate" ); ok && len (substrate ) > 0 {
333+ env .SubstrateURL = substrate
305334 } else if substrate := config .SubstrateURL ; len (substrate ) > 0 {
306335 env .SubstrateURL = substrate
307336 }
308337
309- if relay , ok := params .Get ("relay" ); ok {
310- if len (relay ) > 0 {
311- env .relaysURLs = relay
312- }
338+ if relay , ok := params .Get ("relay" ); ok && len (relay ) > 0 {
339+ env .relaysURLs = relay
313340 } else if relay := config .RelaysURLs ; len (relay ) > 0 {
314341 env .relaysURLs = relay
315342 }
316343
317- if activation , ok := params .Get ("activation" ); ok {
318- if len (activation ) > 0 {
319- env .ActivationURL = activation
320- }
344+ if activation , ok := params .Get ("activation" ); ok && len (activation ) > 0 {
345+ env .ActivationURL = activation
321346 } else if activation := config .ActivationURL ; len (activation ) > 0 {
322347 env .ActivationURL = activation
323348 }
@@ -326,14 +351,6 @@ func getEnvironmentFromParams(params kernel.Params) (Environment, error) {
326351 env .GraphQL = graphql
327352 }
328353
329- // if flist := config.FlistURL; len(flist) > 0 {
330- // env.FlistURL = flist[0]
331- // }
332-
333- // if hub := config.HubURL; len(hub) > 0 {
334- // env.HubURL = hub[0]
335- // }
336-
337354 if bin := config .BinRepo ; len (bin ) > 0 {
338355 env .BinRepo = bin
339356 }
@@ -346,6 +363,43 @@ func getEnvironmentFromParams(params kernel.Params) (Environment, error) {
346363 env .RegistrarURL = registrar
347364 }
348365
366+ if geoip := config .GeoipURLs ; len (geoip ) > 0 {
367+ env .GeoipURLs = geoip
368+ }
369+
370+ // flist url and hub storage urls shouldn't listen to changes in config as long as we can't change it at run time.
371+ // it would cause breakage in vmd that needs a reboot to be recovered.
372+ if flist := config .FlistURL ; len (flist ) > 0 {
373+ env .FlistURL = flist
374+ }
375+
376+ if storage := config .HubStorage ; len (storage ) > 0 {
377+ env .HubStorage = storage
378+ }
379+
380+ // maybe we should verify that we're using a working hub url
381+ if hub := config .HubURL ; len (hub ) > 0 {
382+ env .HubURL = hub [0 ]
383+ }
384+
385+ // some modules needs v3 hub url even if the node is of v4
386+ if hub := config .V4HubURL ; len (hub ) > 0 {
387+ env .V4HubURL = hub [0 ]
388+ }
389+
390+ // if the node running v4 chage urls to use v4 hub
391+ if params .IsV4 () {
392+ env .FlistURL = defaultV4FlistURL
393+ if flist := config .V4FlistURL ; len (flist ) > 0 {
394+ env .FlistURL = flist
395+ }
396+
397+ env .HubStorage = defaultV4HubStorage
398+ if storage := config .V4HubStorage ; len (storage ) > 0 {
399+ env .HubStorage = storage
400+ }
401+ }
402+
349403 if farmSecret , ok := params .Get ("secret" ); ok {
350404 if len (farmSecret ) > 0 {
351405 env .FarmSecret = farmSecret [len (farmSecret )- 1 ]
@@ -423,11 +477,5 @@ func getEnvironmentFromParams(params kernel.Params) (Environment, error) {
423477 env .BinRepo = e
424478 }
425479
426- // if the node running v4 chage flisturl to use v4.hub.threefold.me
427- if params .IsV4 () {
428- env .FlistURL = v4FlistURL
429- env .HubURL = v4HubURL
430- }
431-
432480 return env , nil
433481}
0 commit comments