Skip to content

Commit

Permalink
Merge branch 'valencia' into issue-2721
Browse files Browse the repository at this point in the history
  • Loading branch information
uaalto committed Jul 22, 2015
2 parents b0130e9 + 95a42aa commit bcf9cdc
Show file tree
Hide file tree
Showing 323 changed files with 65,995 additions and 88 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -37,3 +37,4 @@ src/github.com/getlantern/systray/Debug
src/github.com/getlantern/systray/Release
src/github.com/getlantern/systray/systray/Debug
src/github.com/getlantern/systray/systray/Release
src/github.com/getlantern/lantern-android/libflashlight/bindings/Flashlight.java
6 changes: 6 additions & 0 deletions Dockerfile
Expand Up @@ -47,12 +47,18 @@ RUN cd $GOROOT/src && CGO_ENABLED=1 ./all.bash
RUN yum install -y glibc-devel glibc-static && yum clean all
RUN yum install -y glibc-devel.i686 glib2-static.i686 glibc-2.20-8.fc21.i686 libgcc.i686 && yum clean all

# Requisites for ARM
# ARM EABI toolchain must be grabbed from an contributor repository, such as:
# https://copr.fedoraproject.org/coprs/lantw44/arm-linux-gnueabi-toolchain/
RUN yum install -y yum-utils && yum-config-manager --add-repo=https://copr.fedoraproject.org/coprs/lantw44/arm-linux-gnueabi-toolchain/repo/fedora-21/lantw44-arm-linux-gnueabi-toolchain-fedora-21.repo && yum install -y arm-linux-gnueabi-gcc arm-linux-gnueabi-binutils arm-linux-gnueabi-glibc && yum clean all

# Requisites for windows.
RUN yum install -y mingw32-gcc.x86_64 && yum clean all

# Boostrapping Go for different platforms.
RUN cd $GOROOT/src && CGO_ENABLED=1 GOOS=linux GOARCH=amd64 ./make.bash --no-clean
RUN cd $GOROOT/src && CGO_ENABLED=1 GOOS=linux GOARCH=386 ./make.bash --no-clean
RUN cd $GOROOT/src && CXX_FOR_TARGET=arm-linux-gnueabi-g++ CC_FOR_TARGET=arm-linux-gnueabi-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7 ./make.bash --no-clean
RUN cd $GOROOT/src && CXX_FOR_TARGET=i686-w64-mingw32-g++ CC_FOR_TARGET=i686-w64-mingw32-gcc CGO_ENABLED=1 GOOS=windows GOARCH=386 ./make.bash --no-clean

RUN cd $GOROOT/src && GOARCH=386 ./make.bash --no-clean
Expand Down
56 changes: 40 additions & 16 deletions Makefile
Expand Up @@ -17,19 +17,19 @@ GIT_REVISION_SHORTCODE := $(shell git rev-parse --short HEAD)
GIT_REVISION := $(shell git describe --abbrev=0 --tags --exact-match 2> /dev/null || git rev-parse --short HEAD)
GIT_REVISION_DATE := $(shell git show -s --format=%ci $(GIT_REVISION_SHORTCODE))

REVISION_DATE := $(shell date -u -j -f "%F %T %z" "$(GIT_REVISION_DATE)" +"%Y%m%d.%H%M%S" || date -u -d "$(GIT_REVISION_DATE)" +"%Y%m%d.%H%M%S")
REVISION_DATE := $(shell date -u -j -f "%F %T %z" "$(GIT_REVISION_DATE)" +"%Y%m%d.%H%M%S" 2>/dev/null || date -u -d "$(GIT_REVISION_DATE)" +"%Y%m%d.%H%M%S")
BUILD_DATE := $(shell date -u +%Y%m%d.%H%M%S)

LOGGLY_TOKEN := 469973d5-6eaf-445a-be71-cf27141316a1
LDFLAGS := -w -X main.version $(GIT_REVISION) -X main.revisionDate $(REVISION_DATE) -X main.buildDate $(BUILD_DATE) -X github.com/getlantern/flashlight/logging.logglyToken \"$(LOGGLY_TOKEN)\"
LANTERN_DESCRIPTION := Censorship circumvention tool
LANTERN_EXTENDED_DESCRIPTION := Lantern allows you to access sites blocked by internet censorship.\nWhen you run it, Lantern reroutes traffic to selected domains through servers located where such domains aren't censored.
LANTERN_DESCRIPTION := "Censorship circumvention tool"
LANTERN_EXTENDED_DESCRIPTION := "Lantern allows you to access sites blocked by internet censorship.\nWhen you run it, Lantern reroutes traffic to selected domains through servers located where such domains aren't censored."

LANTERN_ANDROID_DIR := src/github.com/getlantern/lantern-android

PACKAGE_VENDOR := Brave New Software Project, Inc
PACKAGE_MAINTAINER := Lantern Team <team@getlantern.org>
PACKAGE_URL := https://www.getlantern.org
PACKAGE_VENDOR := "Brave New Software Project, Inc"
PACKAGE_MAINTAINER := "Lantern Team <team@getlantern.org>"
PACKAGE_URL := "https://www.getlantern.org"

LANTERN_BINARIES_PATH ?= ../lantern-binaries

Expand Down Expand Up @@ -129,15 +129,20 @@ docker-genassets: require-npm
go install github.com/akavel/rsrc && \
rsrc -ico installer-resources/windows/lantern.ico -o src/github.com/getlantern/flashlight/lantern_windows_386.syso;

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

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

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

docker-windows-386:
@source setenv.bash && \
Expand Down Expand Up @@ -170,6 +175,8 @@ docker-package-linux-386: docker-linux-386 docker-package-debian-386

docker-package-linux-amd64: docker-linux-amd64 docker-package-debian-amd64

docker-package-linux-arm: docker-linux-arm docker-package-debian-arm

docker-package-debian-386: require-version docker-linux-386
@cp lantern_linux_386 lantern_linux_i386;
@$(call fpm-debian-build,"i386")
Expand All @@ -180,6 +187,10 @@ docker-package-debian-amd64: require-version docker-linux-amd64
@$(call fpm-debian-build,"amd64")
@echo "-> lantern_$(VERSION)_amd64.deb"

docker-package-debian-arm: require-version docker-linux-arm
@$(call fpm-debian-build,"arm")
@echo "-> lantern_$(VERSION)_arm.deb"

docker-package-windows: require-version docker-windows-386
@if [[ -z "$$BNS_CERT" ]]; then echo "BNS_CERT environment value is required."; exit 1; fi && \
if [[ -z "$$BNS_CERT_PASS" ]]; then echo "BNS_CERT_PASS environment value is required."; exit 1; fi && \
Expand Down Expand Up @@ -207,7 +218,7 @@ docker-golang-android: require-mercurial
docker build -t golang/mobile .; \
fi

linux: genassets linux-386 linux-amd64
linux: genassets linux-386 linux-amd64 linux-arm

windows: genassets windows-386

Expand Down Expand Up @@ -250,19 +261,26 @@ genassets: docker
git update-index --assume-unchanged src/github.com/getlantern/flashlight/ui/resources.go && \
echo "OK"

linux-386: require-assets docker
@echo "Building linux/386..." && \
$(call docker-up) && \
docker run -v $$PWD:/lantern -t $(DOCKER_IMAGE_TAG) /bin/bash -c 'cd /lantern && VERSION="'$$VERSION'" HEADLESS="'$$HEADLESS'" make docker-linux-386' && \
cat lantern_linux_386 | bzip2 > update_linux_386.bz2 && \
ls -l lantern_linux_386 update_linux_386.bz2

linux-amd64: require-assets docker
@echo "Building linux/amd64..." && \
$(call docker-up) && \
docker run -v $$PWD:/lantern -t $(DOCKER_IMAGE_TAG) /bin/bash -c 'cd /lantern && VERSION="'$$VERSION'" HEADLESS="'$$HEADLESS'" make docker-linux-amd64' && \
cat lantern_linux_amd64 | bzip2 > update_linux_amd64.bz2 && \
ls -l lantern_linux_amd64 update_linux_amd64.bz2

linux-386: require-assets docker
@echo "Building linux/386..." && \
linux-arm: require-assets docker
@echo "Building linux/arm..." && \
$(call docker-up) && \
docker run -v $$PWD:/lantern -t $(DOCKER_IMAGE_TAG) /bin/bash -c 'cd /lantern && VERSION="'$$VERSION'" HEADLESS="'$$HEADLESS'" make docker-linux-386' && \
cat lantern_linux_386 | bzip2 > update_linux_386.bz2 && \
ls -l lantern_linux_386 update_linux_386.bz2
docker run -v $$PWD:/lantern -t $(DOCKER_IMAGE_TAG) /bin/bash -c 'cd /lantern && VERSION="'$$VERSION'" HEADLESS="1" make docker-linux-arm' && \
cat lantern_linux_arm | bzip2 > update_linux_arm.bz2 && \
ls -l lantern_linux_arm update_linux_arm.bz2

windows-386: require-assets docker
@echo "Building windows/386..." && \
Expand Down Expand Up @@ -293,7 +311,12 @@ package-linux-amd64: require-version genassets linux-amd64
$(call docker-up) && \
docker run -v $$PWD:/lantern -t $(DOCKER_IMAGE_TAG) /bin/bash -c 'cd /lantern && VERSION="'$$VERSION'" make docker-package-linux-amd64'

package-linux: require-version package-linux-386 package-linux-amd64
package-linux-arm: require-version genassets linux-arm
@echo "Generating distribution package for linux/arm..." && \
$(call docker-up) && \
docker run -v $$PWD:/lantern -t $(DOCKER_IMAGE_TAG) /bin/bash -c 'cd /lantern && VERSION="'$$VERSION'" make docker-package-linux-arm'

package-linux: require-version package-linux-386 package-linux-amd64 package-linux-arm

package-windows: require-version windows
@echo "Generating distribution package for windows/386..." && \
Expand Down Expand Up @@ -388,7 +411,8 @@ release: require-tag require-s3cmd require-gh-token require-wget require-ruby re
for URL in $$($(S3CMD) ls s3://$(S3_BUCKET)/ | grep $$BASE_NAME | awk '{print $$4}'); do \
NAME=$$(basename $$URL) && \
PROD=$$(echo $$NAME | sed s/"$$BASE_NAME"/$$PROD_BASE_NAME/) && \
$(S3CMD) cp s3://$(S3_BUCKET)/$$NAME s3://$(S3_BUCKET)/$$PROD; \
$(S3CMD) cp s3://$(S3_BUCKET)/$$NAME s3://$(S3_BUCKET)/$$PROD && \
$(S3CMD) setacl s3://$(S3_BUCKET)/$$PROD --acl-public; \
done && \
for URL in $$($(S3CMD) ls s3://$(S3_BUCKET)/ | grep update_ | awk '{print $$4}'); do \
NAME=$$(basename $$URL) && \
Expand Down
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -56,6 +56,15 @@ file lantern_linux_amd64
# lantern_linux_amd64: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
```

Or ARM:

```sh
make linux-arm
file lantern_linux_arm
# lantern_linux_arm: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
```


### Building for Windows

Lantern supports the 386 architecture on Windows. In order to build Lantern on
Expand Down
45 changes: 39 additions & 6 deletions src/github.com/getlantern/flashlight/flashlight.go
Expand Up @@ -5,10 +5,14 @@ import (
"flag"
"fmt"
"math/rand"
"net"
"os"
"os/signal"
"runtime"
"strconv"
"strings"
"sync"
"syscall"
"time"

"github.com/getlantern/fronted"
Expand All @@ -21,6 +25,7 @@ import (
"github.com/getlantern/flashlight/client"
"github.com/getlantern/flashlight/config"
"github.com/getlantern/flashlight/geolookup"
"github.com/getlantern/flashlight/localdiscovery"
"github.com/getlantern/flashlight/logging"
"github.com/getlantern/flashlight/proxiedsites"
"github.com/getlantern/flashlight/server"
Expand Down Expand Up @@ -105,7 +110,10 @@ func doMain() error {
return err
}

defer quitSystray()
// Schedule cleanup actions
handleSignals()
addExitFunc(func() { logging.Close() })
addExitFunc(quitSystray)

i18nInit()
if showui {
Expand Down Expand Up @@ -204,11 +212,16 @@ func runClientProxy(cfg *config.Config) {
}

// Start user interface.
if cfg.UIAddr != "" {
if err = ui.Start(cfg.UIAddr); err != nil {
exit(fmt.Errorf("Unable to start UI: %v", err))
return
}
if cfg.UIAddr == "" {
exit(fmt.Errorf("Please provide a valid local or remote UI address"))
}
tcpAddr, err := net.ResolveTCPAddr("tcp4", cfg.UIAddr)
if err != nil {
exit(fmt.Errorf("Unable to resolve UI address: %v", err))
}
if err = ui.Start(tcpAddr, !showui); err != nil {
exit(fmt.Errorf("Unable to start UI: %v", err))
return
}

applyClientConfig(client, cfg)
Expand All @@ -220,6 +233,12 @@ func runClientProxy(cfg *config.Config) {
}
}()

// Continually search for local Lantern instances and update the UI
go func() {
addExitFunc(localdiscovery.Stop)
localdiscovery.Start(!showui, strconv.Itoa(tcpAddr.Port))
}()

// watchDirectAddrs will spawn a goroutine that will add any site that is
// directly accesible to the PAC file.
watchDirectAddrs()
Expand Down Expand Up @@ -363,6 +382,20 @@ func exit(err error) {
}
}

// Handle system signals for clean exit
func handleSignals() {
c := make(chan os.Signal, 1)
signal.Notify(c,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
go func() {
<-c
exit(nil)
}()
}

// WaitForExit waits for a request to exit the application.
func waitForExit() error {
return <-exitCh
Expand Down
@@ -1,4 +1,5 @@
# get from http://www.google.com/supported_domains and remove first dot
googleapis.com
google.com
google.ad
google.ae
Expand Down
@@ -0,0 +1,78 @@
// Package localdiscovery provides a service for discovering Lantern instances
// in the local network
package localdiscovery

import (
"sync"

"github.com/getlantern/flashlight/ui"
"github.com/getlantern/golog"
"github.com/getlantern/multicast"
)

const (
messageType = `LocalDiscovery`
)

var (
log = golog.LoggerFor("flashlight.localdiscovery")
service *ui.Service
mc *multicast.Multicast
lastPeers []multicast.PeerInfo
peersMutex sync.Mutex
)

// Start begins the local Lantern discovery process
func Start(advertise bool, portToAdvertise string) {
if service != nil {
// Dev error: this service shouldn't be started unless stopped
panic("The " + messageType + " service is already registered")
return
}

var err error
service, err = ui.Register(messageType, nil, func(write func(interface{}) error) error {
// When connecting the UI we push the current peer list. For this reason, we need
// to hold this list beyond the add/remove events.
return write(buildPeersList())
})
if err != nil {
log.Errorf("Unable to register Local Discovery service: %q", err)
return
}

addOrRemoveCb := func(peer string, peersInfo []multicast.PeerInfo) {
peersMutex.Lock()
lastPeers = peersInfo
peersMutex.Unlock()

service.Out <- buildPeersList()
}
mc = multicast.JoinMulticast(addOrRemoveCb, addOrRemoveCb)

if advertise {
mc.SetPayload(portToAdvertise)
mc.StartMulticast()
}

mc.ListenPeers()
}

// Stop quits the local Lantern discovery process
func Stop() {
ui.Unregister(messageType)
service = nil
mc.LeaveMulticast()
}

func buildPeersList() []string {
peersList := make([]string, len(lastPeers))

peersMutex.Lock()
for i, peer := range lastPeers {
peersList[i] = "http://" + peer.IP.String() + ":" + peer.Payload
}
peersMutex.Unlock()

return peersList
}
13 changes: 8 additions & 5 deletions src/github.com/getlantern/flashlight/ui/ui.go
Expand Up @@ -26,7 +26,7 @@ var (
server *http.Server
uiaddr string

externalUrl = "https://www.facebook.com/manototv" // this string is going to be changed by Makefile
externalUrl = "NO_URL" // this string is going to be changed by Makefile
openedExternal = false
r = http.NewServeMux()
)
Expand Down Expand Up @@ -62,10 +62,13 @@ func Handle(p string, handler http.Handler) string {
return uiaddr + p
}

func Start(addr string) error {
var err error
l, err = net.Listen("tcp", addr)
if err != nil {
func Start(tcpAddr *net.TCPAddr, allowRemote bool) (err error) {
addr := tcpAddr
if allowRemote {
// If we want to allow remote connections, we have to bind all interfaces
addr = &net.TCPAddr{Port: tcpAddr.Port}
}
if l, err = net.ListenTCP("tcp4", addr); err != nil {
return fmt.Errorf("Unable to listen at %v: %v", addr, l)
}

Expand Down
4 changes: 4 additions & 0 deletions src/github.com/getlantern/lantern-ui/app/_css/app.css
Expand Up @@ -7854,6 +7854,10 @@ body.giveMode #npending {
cursor: pointer;
}

#share div img {
width: 30px;
}

#appInfo {
font: normal .875rem/1.4rem 'prxnv_r', sans-serif;
z-index: 1051;
Expand Down

0 comments on commit bcf9cdc

Please sign in to comment.