Skip to content

Commit

Permalink
Fixed nil masquerades issue and problem with calculating wait time
Browse files Browse the repository at this point in the history
  • Loading branch information
oxtoacart committed Feb 24, 2015
1 parent d4288fc commit ce0c6ed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/github.com/getlantern/flashlight/geolookup/geolookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import (
const (
messageType = `GeoLookup`

basePublishInterval = 30 * time.Second
publishIntervalVariance = basePublishInterval - 10*time.Second
basePublishSeconds = 30
publishSecondsVariance = basePublishSeconds - 10
retryWaitMillis = 100
)

var (
Expand Down Expand Up @@ -69,14 +70,13 @@ func registerService() error {
}

func write() {
retryWaitTime := 100 * time.Millisecond
consecutiveFailures := 0

for {
// Wait a random amount of time (to avoid looking too suspicious)
// Note - rand was seeded with the startup time in flashlight.go
n := rand.Int63n(int64(publishIntervalVariance))
wait := basePublishInterval - publishIntervalVariance/2 + time.Duration(n)
n := rand.Intn(publishSecondsVariance)
wait := time.Duration(basePublishSeconds-publishSecondsVariance/2+n) * time.Second

oldLocation := lastKnownLocation.Load()
location, err := geolookup.LookupIPWithClient("", client.Load().(*http.Client))
Expand All @@ -92,7 +92,7 @@ func write() {
} else {
log.Errorf("Unable to get current location: %v", err)
// When retrying after a failure, wait a different amount of time
retryWait := time.Duration(math.Pow(2, float64(consecutiveFailures)) * float64(retryWaitTime))
retryWait := time.Duration(math.Pow(2, float64(consecutiveFailures))*float64(retryWaitMillis)) * time.Millisecond
if retryWait < wait {
wait = retryWait
}
Expand Down
5 changes: 4 additions & 1 deletion src/github.com/getlantern/fronted/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ func (d *dialer) HttpClientUsing(masquerade *Masquerade) *http.Client {
}

func (d *dialer) DirectHttpClient() *http.Client {
masquerade := d.masquerades.nextVerified()
var masquerade *Masquerade
if d.masquerades != nil {
masquerade = d.masquerades.nextVerified()
}
return &http.Client{
Transport: &http.Transport{
Dial: func(network, addr string) (net.Conn, error) {
Expand Down

0 comments on commit ce0c6ed

Please sign in to comment.