Skip to content

Commit

Permalink
Merge branch 'valencia-embeddable' into valencia-mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
oxtoacart committed Feb 2, 2016
2 parents cedb8fc + a9ceab8 commit 4002ae1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
16 changes: 11 additions & 5 deletions src/github.com/getlantern/flashlight/client/balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,21 @@ func (client *Client) initBalancer(cfg *ClientConfig) {
}

bal := balancer.New(dialers...)
oldBal, ok := client.bal.Get(0 * time.Millisecond)
var oldBal *balancer.Balancer
var ok bool
ob, ok := client.bal.Get(0 * time.Millisecond)
if ok {
oldBal = ob.(*balancer.Balancer)
}

log.Trace("Publishing balancer")
client.bal.Set(bal)

if oldBal != nil {
// Close old balancer on a goroutine to avoid blocking here
go func() {
oldBal.(*balancer.Balancer).Close()
oldBal.Close()
log.Debug("Closed old balancer")
}()
}

log.Trace("Publishing balancer")
client.bal.Set(bal)
}
9 changes: 6 additions & 3 deletions src/github.com/getlantern/flashlight/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ type Client struct {
l net.Listener
}

func NewClient() *Client {
return &Client{
bal: eventual.NewValue(),
}
}

// Addr returns the address at which the client is listening, blocking until the
// given timeout for an address to become available.
func Addr(timeout time.Duration) (interface{}, bool) {
Expand Down Expand Up @@ -100,9 +106,6 @@ func (client *Client) Configure(cfg *ClientConfig, proxyAll func() bool) {
defer client.cfgMutex.Unlock()

log.Debug("Configure() called")
if client.bal == nil {
client.bal = eventual.NewValue()
}

if client.priorCfg != nil {
if reflect.DeepEqual(client.priorCfg, cfg) {
Expand Down
4 changes: 3 additions & 1 deletion src/github.com/getlantern/flashlight/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ var (
m *yamlconf.Manager
lastCloudConfigETag = map[string]string{}
r = regexp.MustCompile("\\d+\\.\\d+")

// Request the config via either chained servers or direct fronted servers.
cf = util.NewChainedAndFronted(client.Addr)
)

type Config struct {
Expand Down Expand Up @@ -467,7 +470,6 @@ func (cfg *Config) fetchCloudConfig(url string) ([]byte, error) {
// successive requests
req.Close = true

cf := util.NewChainedAndFronted(client.Addr)
resp, err := cf.Do(req)
if err != nil {
return nil, fmt.Errorf("Unable to fetch cloud config at %s: %s", url, err)
Expand Down
5 changes: 1 addition & 4 deletions src/github.com/getlantern/flashlight/flashlight.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ func Run(httpProxyAddr string,
return fmt.Errorf("Unable to initialize configuration: %v", err)
}

client := &client.Client{
ReadTimeout: 0, // don't timeout
WriteTimeout: 0,
}
client := client.NewClient()

if beforeStart(cfg) {
log.Debug("Preparing to start client proxy")
Expand Down

0 comments on commit 4002ae1

Please sign in to comment.