Skip to content

Commit

Permalink
Merge branch 'valencia' into uniform-fallbacks-json
Browse files Browse the repository at this point in the history
  • Loading branch information
aranhoide committed Aug 12, 2015
2 parents afa10f9 + 8ff4d90 commit a9d9fea
Show file tree
Hide file tree
Showing 1,416 changed files with 272,932 additions and 418 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ docker-mobile:
DOCKER_CONTEXT=.$(DOCKER_MOBILE_IMAGE_TAG)-context && \
mkdir -p $$DOCKER_CONTEXT && \
cp $(LANTERN_MOBILE_DIR)/Dockerfile $$DOCKER_CONTEXT && \
docker build -t $(DOCKER_MOBILE_IMAGE_TAG) $$DOCKER_CONTEXT && \
$(GO) get -d golang.org/x/mobile/example/...
docker build -t $(DOCKER_MOBILE_IMAGE_TAG) $$DOCKER_CONTEXT

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

Expand Down
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# lantern [![Travis CI Status](https://travis-ci.org/getlantern/lantern.svg?branch=valencia)](https://travis-ci.org/getlantern/lantern) [![Coverage Status](https://coveralls.io/repos/getlantern/lantern/badge.png?branch=valencia)](https://coveralls.io/r/getlantern/lantern)

lantern is a [gost](https://github.com/getlantern/gost) project that
provides repeatable builds and consolidated pull requests for lantern. **It's very important to read the gost documentation thoroughly in
order to build this project.**
provides repeatable builds and consolidated pull requests for lantern.

## Building Lantern

Expand All @@ -18,6 +17,32 @@ for Windows and Linux, in order to compile Lantern for OSX you'll need an OSX
host, this is a limitation caused by Lantern depending on C code and OSX build
tools for certain features.


### Contributing changes

Go code in Lantern must pass several tests:

* [errcheck](https://github.com/kisielk/errcheck)
* [golint](https://github.com/golang/lint)
* Go vet
* Go test -race

You can find a generic [git-hook](https://github.com/getlantern/lantern/blob/valencia/git-hook)
file, which can be used as a pre-push (or pre-commit) hook to automatically
ensure these tests are passed before committing any code. Only Go packages in
`src/github.com/getlantern` will be tested, and only those that have changes in
them.

Install by copying it into the local `.git/hooks/` directory, with the `pre-push`
file name if you want to run it before pushing. Alternatively, you can name it
`pre-commit` to run it before each commit..

**Important notice**

If you *must* commit without running the hooks, you can run git with the
`--no-verify` flag.


### Building the docker image

In order to build the docker image open a terminal, `cd` into the
Expand Down
63 changes: 63 additions & 0 deletions git-hook
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/sh

# Git pre-push hook for the Lantern project
# Maintainer: Ulysses Aalto <[email protected]>
#
# Installation: Copy into .git/hooks/pre-push


# Exit immediately if a command exits with a non-zero status.
set -e

# Find only modified files/directories
MODIFIED_DIRS=$(git status --porcelain | \
awk 'match($1, "M") && match($2, "src/github.com/getlantern/*"){print $2}' | \
sed 's+src/github.com/getlantern/++g' | \
sed 's+/.*++' | \
uniq)
echo "Running hook -- Analyzing modified packages..."
for i in $MODIFIED_DIRS; do
echo " * $i";
done
echo

cd src/github.com/getlantern

which errcheck >/dev/null || (echo "Unable to find errcheck, please install it: \`go get github.com/kisielk/errcheck\`" && exit 1)
which golint >/dev/null || (echo "Unable to find golint, please install it: \`go get -u github.com/golang/lint/golint\`" && exit 1)

echo "*** Running \033[0;34mErrcheck\033[0m ***" && \
for dir in $MODIFIED_DIRS; do
errcheck github.com/getlantern/$dir || (\
echo "\033[0;31merrcheck returned error analyzing the package '$dir'\033[0m" && \
echo "Please, fix and run again\n" && \
exit 1)
done
echo "\033[1;34mErrcheck\033[0m ran successfully\n"

echo "*** Running \033[0;34mGo vet\033[0m ***" && \
for dir in $MODIFIED_DIRS; do
go vet github.com/getlantern/$dir || (\
echo "\033[0;31mgo vet returned error analyzing the package '$dir'\033[0m"
echo "Please, fix and run again\n" && \
exit 1)
done
echo "\033[1;34mGo vet\033[0m ran successfully\n"

echo "*** Running \033[0;34mGolint\033[0m ***" && \
for dir in $MODIFIED_DIRS; do
golint github.com/getlantern/$dir || (\
echo "\033[0;31mgo vet returned error analyzing the package '$dir'\033[0m"
echo "Please, fix and run again\n" && \
exit 1)
done
echo "\033[1;34mGolint\033[0m ran successfully\n"

echo "*** Running \033[0;34mGo test -race\033[0m ***" && \
for dir in $MODIFIED_DIRS; do
go test -race github.com/getlantern/$dir || (\
echo "\033[0;31mgo vet returned error analyzing the package '$dir'\033[0m"
echo "Please, fix and run again\n" && \
exit 1)
done
echo "\033[1;34mGo test -race\033[0m ran successfully\n"
4 changes: 2 additions & 2 deletions installer-resources/windows/lantern.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Section
CreateShortCut "$DESKTOP\Lantern.lnk" "$INSTDIR\lantern.exe" "" "$INSTDIR\lantern.ico" 0

# This is a bad registry entry created by old Lantern versions.
DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Run\value"
DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "value"

# Add a registry key to set -clear-proxy-settings. See https://github.com/getlantern/lantern/issues/2776
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Run" \
Expand Down Expand Up @@ -135,7 +135,7 @@ Section "uninstall"
DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Lantern"

# Don't run Lantern on startup.
DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Run\Lantern"
DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "Lantern"

${nsProcess::Unload}
SectionEnd
Expand Down
20 changes: 17 additions & 3 deletions src/github.com/getlantern/analytics/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package analytics
import (
"bytes"
"net/http"
"net/http/httputil"
"net/url"
"runtime"
"strconv"
Expand Down Expand Up @@ -77,7 +78,11 @@ func Configure(trackingId string, version string, proxyAddr string) {
return
}
// Store new session info whenever client proxy is ready
sessionEvent(trackingId, version)
if status, err := sessionEvent(trackingId, version); err != nil {
log.Errorf("Unable to store new session info: %v", err)
} else {
log.Tracef("Storing new session info: %v", status)
}
}()
}

Expand Down Expand Up @@ -147,14 +152,23 @@ func SendRequest(payload *Payload) (status bool, err error) {
r.Header.Add("Content-Type", "application/x-www-form-urlencoded")
r.Header.Add("Content-Length", strconv.Itoa(len(args)))

if req, err := httputil.DumpRequestOut(r, true); err != nil {
log.Debugf("Could not dump request: %v", err)
} else {
log.Debugf("Full analytics request: %v", string(req))
}

resp, err := httpClient.Do(r)
if err != nil {
log.Errorf("Could not send HTTP request to GA: %s", err)
return false, err
}
log.Debugf("Successfully sent request to GA: %s", resp.Status)
defer resp.Body.Close()

defer func() {
if err := resp.Body.Close(); err != nil {
log.Debugf("Unable to close response body: %v", err)
}
}()
return true, nil
}

Expand Down
15 changes: 11 additions & 4 deletions src/github.com/getlantern/appdir/appdir_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ package appdir
import (
"fmt"
"path/filepath"
"runtime"
"strings"
)

func general(app string) string {
// It is more common on Linux to expect application related directories
// in all lowercase. The lantern wrapper also expects a lowercased
// directory.
return InHomeDir(fmt.Sprintf(".%s", strings.ToLower(app)))
if runtime.GOOS == "android" {
// TODO: Go for Android currently doesn't support Home Directory.
// Remove as soon as this is available in the future
return fmt.Sprintf(".%s", strings.ToLower(app))
} else {
// It is more common on Linux to expect application related directories
// in all lowercase. The lantern wrapper also expects a lowercased
// directory.
return InHomeDir(fmt.Sprintf(".%s", strings.ToLower(app)))
}
}

func logs(app string) string {
Expand Down
14 changes: 11 additions & 3 deletions src/github.com/getlantern/autoupdate-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,21 @@ func backgroundUpdate() {

func (u *updateHandler) closeWithStatus(w http.ResponseWriter, status int) {
w.WriteHeader(status)
w.Write([]byte(http.StatusText(status)))
if _, err := w.Write([]byte(http.StatusText(status))); err != nil {
log.Debugf("Unable to write status: %v", err)
}
}

func (u *updateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var err error
var res *server.Result

if r.Method == "POST" {
defer r.Body.Close()
defer func() {
if err := r.Body.Close(); err != nil {
log.Debugf("Unable to close request body: %v", err)
}
}()

var params server.Params
decoder := json.NewDecoder(r.Body)
Expand Down Expand Up @@ -93,7 +99,9 @@ func (u *updateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {

w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "application/json")
w.Write(content)
if _, err := w.Write(content); err != nil {
log.Debugf("Unable to write response: %v", err)
}
return
}
u.closeWithStatus(w, http.StatusNotFound)
Expand Down
12 changes: 10 additions & 2 deletions src/github.com/getlantern/balancer/balancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ func TestAll(t *testing.T) {
if err != nil {
log.Fatalf("Unable to listen: %s", err)
}
defer l.Close()
defer func() {
if err := l.Close(); err != nil {
log.Fatalf("Unable to close listener: %v", err)
}
}()
go func() {
for {
c, err := l.Accept()
Expand Down Expand Up @@ -264,7 +268,11 @@ func newFailingDialer(num int32, dialedBy *int32, attempts *int32) *Dialer {
}

func doTestConn(t *testing.T, conn net.Conn) {
defer conn.Close()
defer func() {
if err := conn.Close(); err != nil {
log.Debugf("Unable to close connection: %v", err)
}
}()

var wg sync.WaitGroup
wg.Add(2)
Expand Down
4 changes: 3 additions & 1 deletion src/github.com/getlantern/balancer/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ func (d *dialer) defaultCheck() bool {
log.Debugf("Error testing dialer %s to humans.txt: %s", d.Label, err)
return false, nil
}
resp.Body.Close()
if err := resp.Body.Close(); err != nil {
log.Debugf("Unable to close response body: %v", err)
}
log.Tracef("Tested dialer %s to humans.txt, status code %d", d.Label, resp.StatusCode)
return resp.StatusCode == 200, nil
})
Expand Down
12 changes: 10 additions & 2 deletions src/github.com/getlantern/buuid/buuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"fmt"

"code.google.com/p/go-uuid/uuid"

"github.com/getlantern/golog"
)

const (
Expand All @@ -16,6 +18,8 @@ const (
var (
endianness = binary.LittleEndian
zero = ID{}

log = golog.LoggerFor("buuid")
)

// ID is a type 4 UUID.
Expand Down Expand Up @@ -58,7 +62,9 @@ func (id ID) Write(b []byte) error {
// ToBytes returns a 16-byte representation of this ID
func (id ID) ToBytes() []byte {
b := make([]byte, EncodedLength)
id.Write(b)
if err := id.Write(b); err != nil {
log.Errorf("Unable to write as 16-bytes representation: %v", err)
}
return b
}

Expand All @@ -70,6 +76,8 @@ func FromString(s string) (ID, error) {
// String() returns the string-encoded version like in uuid.UUID.
func (id ID) String() string {
b := uuid.UUID(make([]byte, EncodedLength))
id.Write([]byte(b))
if err := id.Write([]byte(b)); err != nil {
log.Errorf("Unable to write as string: %v", err)
}
return b.String()
}
Loading

0 comments on commit a9d9fea

Please sign in to comment.