@@ -9,47 +9,11 @@ import (
9
9
10
10
"github.com/getlantern/flashlight/client"
11
11
"github.com/getlantern/flashlight/proxied"
12
- "github.com/getlantern/golog"
13
12
"github.com/getlantern/rot13"
14
13
"github.com/getlantern/tarfs"
15
14
"github.com/getlantern/yaml"
16
15
)
17
16
18
- var (
19
- log = golog .LoggerFor ("flashlight.config" )
20
-
21
- // GlobalURLs are the chained and fronted URLs for fetching the global config.
22
- GlobalURLs = & ChainedFrontedURLs {
23
- Chained : "https://globalconfig.flashlightproxy.com/global.yaml.gz" ,
24
- Fronted : "https://d24ykmup0867cj.cloudfront.net/global.yaml.gz" ,
25
- }
26
-
27
- // GlobalStagingURLs are the chained and fronted URLs for fetching the global
28
- // config in a staging environment.
29
- GlobalStagingURLs = & ChainedFrontedURLs {
30
- Chained : "https://globalconfig.flashlightproxy.com/global.yaml.gz" ,
31
- Fronted : "https://d24ykmup0867cj.cloudfront.net/global.yaml.gz" ,
32
- }
33
-
34
- // The following are over HTTP because proxies do not forward X-Forwarded-For
35
- // with HTTPS and because we only support falling back to direct domain
36
- // fronting through the local proxy for HTTP.
37
-
38
- // ProxiesURLs are the chained and fronted URLs for fetching the per user
39
- // proxy config.
40
- ProxiesURLs = & ChainedFrontedURLs {
41
- Chained : "http://config.getiantem.org/proxies.yaml.gz" ,
42
- Fronted : "http://d2wi0vwulmtn99.cloudfront.net/proxies.yaml.gz" ,
43
- }
44
-
45
- // ProxiesStagingURLs are the chained and fronted URLs for fetching the per user
46
- // proxy config in a staging environment.
47
- ProxiesStagingURLs = & ChainedFrontedURLs {
48
- Chained : "http://config-staging.getiantem.org/proxies.yaml.gz" ,
49
- Fronted : "http://d33pfmbpauhmvd.cloudfront.net/proxies.yaml.gz" ,
50
- }
51
- )
52
-
53
17
// Config is an interface for getting proxy data saved locally, embedded
54
18
// in the binary, or fetched over the network.
55
19
type Config interface {
@@ -62,7 +26,7 @@ type Config interface {
62
26
63
27
// Poll polls for new configs from a remote server and saves them to disk for
64
28
// future runs.
65
- poll (UserConfig , chan interface {}, * ChainedFrontedURLs , time.Duration )
29
+ poll (UserConfig , chan interface {}, * chainedFrontedURLs , time.Duration )
66
30
}
67
31
68
32
type config struct {
@@ -72,79 +36,79 @@ type config struct {
72
36
factory func () interface {}
73
37
}
74
38
75
- // ChainedFrontedURLs contains a chained and a fronted URL for fetching a config.
76
- type ChainedFrontedURLs struct {
77
- Chained string
78
- Fronted string
39
+ // chainedFrontedURLs contains a chained and a fronted URL for fetching a config.
40
+ type chainedFrontedURLs struct {
41
+ chained string
42
+ fronted string
79
43
}
80
44
81
- // Options specifies the options to use for piping config data back to the
45
+ // options specifies the options to use for piping config data back to the
82
46
// dispatch processor function.
83
- type Options struct {
47
+ type options struct {
84
48
85
- // SaveDir is the directory where we should save new configs and also look
49
+ // saveDir is the directory where we should save new configs and also look
86
50
// for existing saved configs.
87
- SaveDir string
51
+ saveDir string
88
52
89
- // Obfuscate specifies whether or not to obfuscate the config on disk.
90
- Obfuscate bool
53
+ // obfuscate specifies whether or not to obfuscate the config on disk.
54
+ obfuscate bool
91
55
92
- // Name specifies the name of the config file both on disk and in the
56
+ // name specifies the name of the config file both on disk and in the
93
57
// embedded config that uses tarfs (the same in the interest of using
94
58
// configuration by convention).
95
- Name string
59
+ name string
96
60
97
- // URLs are the chaines and fronted URLs to use for fetching this config.
98
- URLs * ChainedFrontedURLs
61
+ // urls are the chaines and fronted URLs to use for fetching this config.
62
+ urls * chainedFrontedURLs
99
63
100
- // UserConfig contains data for communicating the user details to upstream
64
+ // userConfig contains data for communicating the user details to upstream
101
65
// servers in HTTP headers, such as the pro token.
102
- UserConfig UserConfig
66
+ userConfig UserConfig
103
67
104
- // YAMLTemplater is a factory method for generating structs that will be used
68
+ // yamlTemplater is a factory method for generating structs that will be used
105
69
// when unmarshalling yaml data.
106
- YAMLTemplater func () interface {}
70
+ yamlTemplater func () interface {}
107
71
108
- // Dispatch is essentially a callback function for processing retrieved
72
+ // dispatch is essentially a callback function for processing retrieved
109
73
// yaml configs.
110
- Dispatch func (cfg interface {})
74
+ dispatch func (cfg interface {})
111
75
112
- // EmbeddedData is the data for embedded configs, using tarfs.
113
- EmbeddedData []byte
76
+ // embeddedData is the data for embedded configs, using tarfs.
77
+ embeddedData []byte
114
78
115
- // Sleep the time to sleep between config fetches.
116
- Sleep time.Duration
79
+ // sleep the time to sleep between config fetches.
80
+ sleep time.Duration
117
81
}
118
82
119
- // PipeConfig creates a new config pipeline for reading a specified type of
83
+ // pipeConfig creates a new config pipeline for reading a specified type of
120
84
// config onto a channel for processing by a dispatch function. This will read
121
85
// configs in the following order:
122
86
//
123
87
// 1. Configs saved on disk, if any
124
88
// 2. Configs embedded in the binary according to the specified name, if any.
125
89
// 3. Configs fetched remotely, and those will be piped back over and over
126
90
// again as the remote configs change (but only if they change).
127
- func PipeConfig (opts * Options ) {
91
+ func pipeConfig (opts * options ) {
128
92
129
93
configChan := make (chan interface {})
130
94
131
95
go func () {
132
96
for {
133
97
cfg := <- configChan
134
- opts .Dispatch (cfg )
98
+ opts .dispatch (cfg )
135
99
}
136
100
}()
137
- configPath , err := client .InConfigDir (opts .SaveDir , opts .Name )
101
+ configPath , err := client .InConfigDir (opts .saveDir , opts .name )
138
102
if err != nil {
139
103
log .Errorf ("Could not get config path? %v" , err )
140
104
}
141
105
142
- log .Tracef ("Obfuscating %v" , opts .Obfuscate )
143
- conf := newConfig (configPath , opts .Obfuscate , opts .YAMLTemplater )
106
+ log .Tracef ("Obfuscating %v" , opts .obfuscate )
107
+ conf := newConfig (configPath , opts .obfuscate , opts .yamlTemplater )
144
108
145
109
if saved , proxyErr := conf .saved (); proxyErr != nil {
146
110
log .Debugf ("Could not load stored config %v" , proxyErr )
147
- if embedded , errr := conf .embedded (opts .EmbeddedData , opts .Name ); errr != nil {
111
+ if embedded , errr := conf .embedded (opts .embeddedData , opts .name ); errr != nil {
148
112
log .Errorf ("Could not load embedded config %v" , errr )
149
113
} else {
150
114
log .Debugf ("Sending embedded config for %v" , name )
@@ -157,23 +121,23 @@ func PipeConfig(opts *Options) {
157
121
158
122
// Now continually poll for new configs and pipe them back to the dispatch
159
123
// function.
160
- go conf .poll (opts .UserConfig , configChan , opts .URLs , opts .Sleep )
124
+ go conf .poll (opts .userConfig , configChan , opts .urls , opts .sleep )
161
125
}
162
126
163
127
// newConfig create a new ProxyConfig instance that saves and looks for
164
128
// saved data at the specified path.
165
129
func newConfig (filePath string , obfuscate bool ,
166
130
factory func () interface {}) Config {
167
- pc := & config {
131
+ cfg := & config {
168
132
filePath : filePath ,
169
133
obfuscate : obfuscate ,
170
134
saveChan : make (chan interface {}),
171
135
factory : factory ,
172
136
}
173
137
174
138
// Start separate go routine that saves newly fetched proxies to disk.
175
- go pc .save ()
176
- return pc
139
+ go cfg .save ()
140
+ return cfg
177
141
}
178
142
179
143
func (conf * config ) saved () (interface {}, error ) {
@@ -217,7 +181,7 @@ func (conf *config) embedded(data []byte, fileName string) (interface{}, error)
217
181
}
218
182
219
183
func (conf * config ) poll (uc UserConfig ,
220
- configChan chan interface {}, urls * ChainedFrontedURLs , sleep time.Duration ) {
184
+ configChan chan interface {}, urls * chainedFrontedURLs , sleep time.Duration ) {
221
185
fetcher := newFetcher (uc , proxied .ParallelPreferChained (), urls )
222
186
223
187
for {
@@ -233,8 +197,9 @@ func (conf *config) poll(uc UserConfig,
233
197
234
198
// Push these to channels to avoid race conditions that might occur if
235
199
// we did these on go routines, for example.
236
- configChan <- cfg
237
200
conf .saveChan <- cfg
201
+ log .Debugf ("Sent to save chan" )
202
+ configChan <- cfg
238
203
}
239
204
time .Sleep (sleep )
240
205
}
@@ -280,25 +245,3 @@ func (conf *config) saveOne(in interface{}) error {
280
245
log .Debugf ("Wrote file at %v" , conf .filePath )
281
246
return nil
282
247
}
283
-
284
- // GetProxyURLs returns the proxy URLs to use depending on whether or not we're in
285
- // staging.
286
- func GetProxyURLs (staging bool ) * ChainedFrontedURLs {
287
- if staging {
288
- log .Debug ("Configuring for staging" )
289
- return ProxiesStagingURLs
290
- }
291
- log .Debugf ("Not configuring for staging." )
292
- return ProxiesURLs
293
- }
294
-
295
- // GetGlobalURLs returns the global URLs to use depending on whether or not we're in
296
- // staging.
297
- func GetGlobalURLs (staging bool ) * ChainedFrontedURLs {
298
- if staging {
299
- log .Debug ("Configuring for staging" )
300
- return GlobalStagingURLs
301
- }
302
- log .Debugf ("Not configuring for staging." )
303
- return GlobalURLs
304
- }
0 commit comments