Skip to content

Commit

Permalink
Merged initfix
Browse files Browse the repository at this point in the history
  • Loading branch information
oxtoacart committed Feb 4, 2016
2 parents 9dded8e + 0cc53bb commit 2c27874
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 39 deletions.
21 changes: 11 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,17 @@ LANTERN_YAML_PATH := installer-resources/lantern.yaml

define build-tags
BUILD_TAGS="" && \
EXTRA_LDFLAGS="" && \
if [[ ! -z "$$VERSION" ]]; then \
BUILD_TAGS="prod" && \
sed s/'PackageVersion.*'/'PackageVersion = "'$$VERSION'"'/ src/github.com/getlantern/flashlight/flashlight.go | sed s/'!prod'/'prod'/ > src/github.com/getlantern/flashlight/flashlight-prod.go; \
EXTRA_LDFLAGS="-X=github.com/getlantern/flashlight.compileTimePackageVersion=$$VERSION"; \
else \
echo "** VERSION was not set, using git revision instead ($(GIT_REVISION)). This is OK while in development."; \
echo "** VERSION was not set, using default version. This is OK while in development."; \
fi && \
if [[ ! -z "$$HEADLESS" ]]; then \
BUILD_TAGS="$$BUILD_TAGS headless"; \
fi && \
BUILD_TAGS=$$(echo $$BUILD_TAGS | xargs) && echo "Build tags: $$BUILD_TAGS"
BUILD_TAGS=$$(echo $$BUILD_TAGS | xargs) && echo "Build tags: $$BUILD_TAGS" && \
EXTRA_LDFLAGS=$$(echo $$EXTRA_LDFLAGS | xargs) && echo "Extra ldflags: $$EXTRA_LDFLAGS"
endef

define docker-up
Expand Down Expand Up @@ -167,22 +168,22 @@ docker-genassets: require-npm
docker-linux-386:
@source setenv.bash && \
$(call build-tags) && \
CGO_ENABLED=1 GOOS=linux GOARCH=386 go build -a -o lantern_linux_386 -tags="$$BUILD_TAGS" -ldflags="$(LDFLAGS) -linkmode internal -extldflags \"-static\"" github.com/getlantern/flashlight/main
CGO_ENABLED=1 GOOS=linux GOARCH=386 go build -a -o lantern_linux_386 -tags="$$BUILD_TAGS" -ldflags="$(LDFLAGS) $$EXTRA_LDFLAGS -linkmode internal -extldflags \"-static\"" github.com/getlantern/flashlight/main

docker-linux-amd64:
@source setenv.bash && \
$(call build-tags) && \
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -a -o lantern_linux_amd64 -tags="$$BUILD_TAGS" -ldflags="$(LDFLAGS) -linkmode internal -extldflags \"-static\"" github.com/getlantern/flashlight/main
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -a -o lantern_linux_amd64 -tags="$$BUILD_TAGS" -ldflags="$(LDFLAGS) $$EXTRA_LDFLAGS -linkmode internal -extldflags \"-static\"" github.com/getlantern/flashlight/main

docker-linux-arm:
@source setenv.bash && \
$(call build-tags) && \
CGO_ENABLED=1 CC=arm-linux-gnueabi-gcc CXX=arm-linux-gnueabi-g++ CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7 go build -a -o lantern_linux_arm -tags="$$BUILD_TAGS" -ldflags="$(LDFLAGS) -linkmode internal -extldflags \"-static\"" github.com/getlantern/flashlight/main
CGO_ENABLED=1 CC=arm-linux-gnueabi-gcc CXX=arm-linux-gnueabi-g++ CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7 go build -a -o lantern_linux_arm -tags="$$BUILD_TAGS" -ldflags="$(LDFLAGS) $$EXTRA_LDFLAGS -linkmode internal -extldflags \"-static\"" github.com/getlantern/flashlight/main

docker-windows-386:
@source setenv.bash && \
$(call build-tags) && \
CGO_ENABLED=1 GOOS=windows GOARCH=386 go build -a -o lantern_windows_386.exe -tags="$$BUILD_TAGS" -ldflags="$(LDFLAGS) -H=windowsgui" github.com/getlantern/flashlight/main;
CGO_ENABLED=1 GOOS=windows GOARCH=386 go build -a -o lantern_windows_386.exe -tags="$$BUILD_TAGS" -ldflags="$(LDFLAGS) $$EXTRA_LDFLAGS -H=windowsgui" github.com/getlantern/flashlight/main;

require-assets:
@if [ ! -f ./src/github.com/getlantern/flashlight/ui/resources.go ]; then make genassets; fi
Expand Down Expand Up @@ -327,7 +328,7 @@ darwin-amd64: require-assets
export CGO_LDFLAGS="--sysroot $$OSX_DEV_SDK"; \
fi && \
MACOSX_DEPLOYMENT_TARGET=$(OSX_MIN_VERSION) \
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -a -o lantern_darwin_amd64 -tags="$$BUILD_TAGS" -ldflags="$(LDFLAGS) -s" github.com/getlantern/flashlight/main; \
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -a -o lantern_darwin_amd64 -tags="$$BUILD_TAGS" -ldflags="$(LDFLAGS) $$EXTRA_LDFLAGS -s" github.com/getlantern/flashlight/main; \
else \
echo "-> Skipped: Can not compile Lantern for OSX on a non-OSX host."; \
fi
Expand Down Expand Up @@ -505,7 +506,7 @@ genconfig:

android-lib:
@source setenv.bash && \
gomobile bind -target=android -tags='headless' -o=$(LANTERN_MOBILE_LIBRARY) -ldflags='$(LDFLAGS)' $(LANTERN_MOBILE_PKG) && \
gomobile bind -target=android -tags='headless' -o=$(LANTERN_MOBILE_LIBRARY) -ldflags='$(LDFLAGS) $$EXTRA_LDFLAGS' $(LANTERN_MOBILE_PKG) && \
mkdir -p $(MOBILE_TESTBED_LIBS) && cp -f $(LANTERN_MOBILE_LIBRARY) $(MOBILE_TESTBED_LIBS) && \
mkdir -p $(MOBILE_SDK_LIBS) && cp -f $(LANTERN_MOBILE_LIBRARY) $(MOBILE_SDK_LIBS)

Expand Down
9 changes: 0 additions & 9 deletions src/github.com/getlantern/balancer/balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,6 @@ func (b *Balancer) AllAuthTokens() []string {
return result
}

// TrustedDialerAndConn creaetes a balancer.Dialer and a network connection for an HTTP connection
// (as opposed to HTTPS).
func (b *Balancer) TrustedDialerAndConn() (*Dialer, net.Conn, error) {
// At this point we don't actually have the destination URL. For our purposes, however,
// the destination URL is not actually necessary and is not even used in the dial function
// because dial is really just dialing the proxy server.
return b.dialerAndConn("tcp", "doesnotexist.com:80", 0)
}

func (b *Balancer) dialerAndConn(network, addr string, targetQOS int) (*Dialer, net.Conn, error) {
var dialers []*dialer

Expand Down
11 changes: 5 additions & 6 deletions src/github.com/getlantern/flashlight/client/balancer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package client

import (
"fmt"
"time"

"github.com/getlantern/balancer"
Expand All @@ -20,20 +21,16 @@ func (client *Client) getBalancer() *balancer.Balancer {

// initBalancer takes hosts from cfg.ChainedServers and it uses them to create a
// balancer.
func (client *Client) initBalancer(cfg *ClientConfig) {
func (client *Client) initBalancer(cfg *ClientConfig) (*balancer.Balancer, error) {
if len(cfg.ChainedServers) == 0 {
log.Debug("No chained servers configured, not initializing balancer")
return
return nil, fmt.Errorf("No chained servers configured, not initializing balancer")
}
// The dialers slice must be large enough to handle all chained
// servers.
dialers := make([]*balancer.Dialer, 0, len(cfg.ChainedServers))

// Add chained (CONNECT proxy) servers.
log.Debugf("Adding %d chained servers", len(cfg.ChainedServers))
if len(cfg.ChainedServers) == 0 {
log.Error("NO CHAINED SERVERS!")
}
for _, s := range cfg.ChainedServers {
dialer, err := s.Dialer(cfg.DeviceID)
if err == nil {
Expand Down Expand Up @@ -61,4 +58,6 @@ func (client *Client) initBalancer(cfg *ClientConfig) {
log.Debug("Closed old balancer")
}()
}

return bal, nil
}
10 changes: 6 additions & 4 deletions src/github.com/getlantern/flashlight/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,12 @@ func (client *Client) Configure(cfg *ClientConfig, proxyAll func() bool) {
client.ProxyAll = proxyAll
client.DeviceID = cfg.DeviceID

client.initBalancer(cfg)
go func() {
client.rp.Set(client.newReverseProxy())
}()
bal, err := client.initBalancer(cfg)
if err != nil {
log.Error(err)
} else if bal != nil {
client.rp.Set(client.newReverseProxy(bal))
}

client.priorCfg = cfg
}
Expand Down
5 changes: 2 additions & 3 deletions src/github.com/getlantern/flashlight/client/reverseproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ import (
"net/http/httputil"
"time"

"github.com/getlantern/balancer"
"github.com/getlantern/detour"
"github.com/getlantern/flashlight/proxy"
"github.com/getlantern/flashlight/status"
)

// newReverseProxy creates a reverse proxy that uses the client's balancer to
// dial out.
func (client *Client) newReverseProxy() *httputil.ReverseProxy {
bal := client.getBalancer()

func (client *Client) newReverseProxy(bal *balancer.Balancer) *httputil.ReverseProxy {
transport := &http.Transport{
TLSHandshakeTimeout: 40 * time.Second,
}
Expand Down
23 changes: 18 additions & 5 deletions src/github.com/getlantern/flashlight/flashlight.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,39 @@ import (
"github.com/getlantern/flashlight/logging"
)

// While in development mode we probably would not want auto-updates to be
// applied. Using a big number here prevents such auto-updates without
// disabling the feature completely. The "make package-*" tool will take care
// of bumping this version number so you don't have to do it by hand.
const (
// While in development mode we probably would not want auto-updates to be
// applied. Using a big number here prevents such auto-updates without
// disabling the feature completely. The "make package-*" tool will take care
// of bumping this version number so you don't have to do it by hand.
DefaultPackageVersion = "9999.99.99"
PackageVersion = DefaultPackageVersion
)

var (
log = golog.LoggerFor("flashlight")

// compileTimePackageVersion is set at compile-time for production builds
compileTimePackageVersion string

PackageVersion = bestPackageVersion()

Version string
RevisionDate string // The revision date and time that is associated with the version string.
BuildDate string // The actual date and time the binary was built.

cfgMutex sync.Mutex
)

func bestPackageVersion() string {
if compileTimePackageVersion != "" {
return compileTimePackageVersion
} else {
return DefaultPackageVersion
}
}

func init() {
log.Debugf("****************************** Package Version: %v", PackageVersion)
if PackageVersion != DefaultPackageVersion {
// packageVersion has precedence over GIT revision. This will happen when
// packing a version intended for release.
Expand Down
2 changes: 0 additions & 2 deletions src/github.com/getlantern/flashlight/main/autoupdate.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build !prod

package main

// This is the public key of the BNS cert. Incoming updates will be signed to
Expand Down

0 comments on commit 2c27874

Please sign in to comment.