Skip to content

Commit

Permalink
Merged devel to go1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
oxtoacart committed Dec 21, 2014
2 parents 49ee134 + 3470925 commit 6af0225
Show file tree
Hide file tree
Showing 17 changed files with 204 additions and 90 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ flashlight_darwin_amd64
flashlight_linux_386
flashlight_linux_amd64
flashlight_windows_386.exe
flashlight.yaml
79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,82 @@ flashlight-build [![Travis CI Status](https://travis-ci.org/getlantern/flashligh
flashlight-build is a [gost](https://github.com/getlantern/gost) project that
provides repeatable builds and consolidated pull requests for flashlight.

### Building Flashlight

Flashlight requires [Go 1.4.x](http://golang.org/dl/).

It is convenient to build flashlight for multiple platforms using
[gox](https://github.com/mitchellh/gox).

The typical cross-compilation setup doesn't work for anything that uses C code,
which includes the DNS resolution code and some other things. See
[this blog](https://inconshreveable.com/04-30-2014/cross-compiling-golang-programs-with-native-libraries/)
for more discussion.

To deal with that, you need to use a Go installed using
[gonative](https://github.com/getlantern/gonative). Ultimately, you can put this
go wherever you like. Ox keeps his at ~/go_native.

```bash
go get github.com/mitchellh/gox
go get github.com/getlantern/gonative
cd ~
gonative -version="1.4" -platforms="darwin_amd64 linux_386 linux_amd64 windows_386"
mv go go_native
```

Finally update your GOROOT and PATH to point at `~/go_native` instead of your
previous go installation. They should look something like this:

```bash
➜ flashlight git:(1606) ✗ echo $GOROOT
/Users/ox.to.a.cart//go_native
➜ flashlight git:(1606) ✗ which go
/Users/ox.to.a.cart//go_native/bin/go
```

Now that you have go and gox set up, the binaries used for Lantern can be built
with the `./crosscompile.bash` script. This script also sets the version of
flashlight to the most recent commit id in git, or if the most recent commit is
tagged, the tag of that commit id.

An annotated tag can be added like this:

```bash
git tag -a v1.0.0 -m"Tagged 1.0.0"
git push --tags
```

The script `tagandbuild.bash` tags and runs crosscompile.bash.

`./tagandbuild.bash <tag>`

Note - ./crosscompile.bash omits debug symbols to keep the build smaller.

Note also that these binaries should be signed for use in production, at least
on OSX and Windows. On OSX the command to do this should resemble the following
(assuming you have an associated code signing certificate):

```
codesign -s "Developer ID Application: Brave New Software Project, Inc" -f install/osx/pt/flashlight/flashlight
```

The script `copyexecutables.bash` takes care of signing the OS X executable and
copying everything in the Lantern file tree.

`copyexecutables.bash` will also optionally sign the Windows executable if the
environment variables BNS_CERT and BNS_CERT_PASS are set to point to
[bns-cert.p12](https://github.com/getlantern/too-many-secrets/blob/master/bns_cert.p12)
and its [password](https://github.com/getlantern/too-many-secrets/blob/master/build-installers/env-vars.txt#L3).

The code signing [certificate](https://github.com/getlantern/too-many-secrets/blob/master/osx-code-signing-certificate.p12)
and [password](https://github.com/getlantern/too-many-secrets/blob/master/osx-code-signing-certificate.p12.txt)
can be obtained from [too-many-secrets](https://github.com/getlantern/too-many-secrets).

note - Signing windows code requires that the
[osslsigncode](http://sourceforge.net/projects/osslsigncode/) utility be
installed. On OS X with homebrew, you can do this with
`brew install osslsigncode`.



File renamed without changes.
8 changes: 8 additions & 0 deletions crosscompile.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# The VERSION is set to the tag for the current commit (if it exists) otherwise
# just the commit id.
VERSION="`git describe --abbrev=0 --tags --exact-match || git rev-parse --short HEAD`"
BUILD_DATE="`date -u +%Y%m%d%.%H%M%S`"
echo "Building flashlight version $VERSION ($BUILD_DATE)"
gox -ldflags="-w -X main.version $VERSION -X main.buildDate $BUILD_DATE" -osarch="linux/386 linux/amd64 windows/386 darwin/amd64" github.com/getlantern/flashlight
75 changes: 0 additions & 75 deletions src/github.com/getlantern/flashlight/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,81 +75,6 @@ On the client, you should see something like this for every request:
Handling request for: http://www.google.com/humans.txt
```
### Building
Flashlight is built with [Go 1.4.x](http://golang.org/dl/).
It is convenient to build flashlight for multiple platforms using
[gox](https://github.com/getlantern/gox).
The typical cross-compilation setup doesn't work for anything that uses C code,
which includes the DNS resolution code and some other things. See
[this blog](https://inconshreveable.com/04-30-2014/cross-compiling-golang-programs-with-native-libraries/)
for more discussion.
To deal with that, you need to use a Go installed using
[gonative](https://github.com/getlantern/gonative). Ultimately, you can put this
go wherever you like. Ox keeps his at ~/go_native.
```bash
go get github.com/mitchellh/gox
go get github.com/getlantern/gonative
cd ~
gonative -version="1.4" -platforms="darwin_amd64 linux_386 linux_amd64 windows_386"
mv go go_native
```
Finally update your GOROOT and PATH to point at `~/go_native` instead of your
previous go installation. They should look something like this:
```bash
➜ flashlight git:(1606) ✗ echo $GOROOT
/Users/ox.to.a.cart//go_native
➜ flashlight git:(1606) ✗ which go
/Users/ox.to.a.cart//go_native/bin/go
```
Now that you have go and gox set up, the binaries used for Lantern can be built
with the `./crosscompile.bash` script. This script also sets the version of
flashlight to the most recent annotated tag in git. An annotated tag can be
added like this:
```bash
git tag -a v1.0.0 -m"Tagged 1.0.0"
git push --tags
```
The script `tagandbuild.bash` tags and runs crosscompile.bash.
`./tagandbuild.bash <tag>`
Note - ./crosscompile.bash omits debug symbols to keep the build smaller.
Note also that these binaries should also be signed for use in production, at
least on OSX and Windows. On OSX the command to do this should resemble the
following (assuming you have an associated code signing certificate):
```
codesign -s "Developer ID Application: Brave New Software Project, Inc" -f install/osx/pt/flashlight/flashlight
```
The script `copyexecutables.bash` takes care of signing the OS X executable and
copying everything in the Lantern file tree.
`copyexecutables.bash` will also optionally sign the Windows executable if the
environment variables BNS_CERT and BNS_CERT_PASS are set to point to
[bns-cert.p12](https://github.com/getlantern/too-many-secrets/blob/master/bns_cert.p12)
and its [password](https://github.com/getlantern/too-many-secrets/blob/master/build-installers/env-vars.txt#L3).
The code signing [certificate](https://github.com/getlantern/too-many-secrets/blob/master/osx-code-signing-certificate.p12)
and [password](https://github.com/getlantern/too-many-secrets/blob/master/osx-code-signing-certificate.p12.txt)
can be obtained from [too-many-secrets](https://github.com/getlantern/too-many-secrets).
note - Signing windows code requires that the
[osslsigncode](http://sourceforge.net/projects/osslsigncode/) utility be
installed. On OS X with homebrew, you can do this with
`brew install osslsigncode`.
### Masquerade Host Management
Masquerade host configuration is managed using utilities in the [`genconfig/`](genconfig/) subfolder.
Expand Down
5 changes: 0 additions & 5 deletions src/github.com/getlantern/flashlight/crosscompile.bash

This file was deleted.

6 changes: 5 additions & 1 deletion src/github.com/getlantern/flashlight/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,12 @@ func unmapPort(port int) error {
return nil
}

// determineInternalIP determines the internal IP to use for mapping ports. It
// does this by dialing a website on the public Internet and then finding out
// the LocalAddr for the corresponding connection. This gives us an interface
// that we know has Internet access, which makes it suitable for port mapping.
func determineInternalIP() (string, error) {
conn, err := net.Dial("tcp", "s3.amazonaws.com:443")
conn, err := net.DialTimeout("tcp", "s3.amazonaws.com:443", 20*time.Second)
if err != nil {
return "", fmt.Errorf("Unable to determine local IP: %s", err)
}
Expand Down
23 changes: 22 additions & 1 deletion src/github.com/getlantern/go-igdman/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,25 @@ Acknowledgements:
igdman is just a wrapper around:

- [miniupnpc](https://github.com/miniupnp/miniupnp)
- [go-nat-pmp](https://github.com/jackpal/go-nat-pmp/)
- [go-nat-pmp](https://github.com/jackpal/go-nat-pmp/)

## Embedding upnpc

To build the go files that embed the upnpc executables for different platforms,
just place the binaries into the right subfolder of `binaries` and then run
`embedupnpc.bash`. This script takes care of code signing the ~~Windows and~~
OS X executables.

~~This script signs the Windows executable, which requires that
[osslsigncode](http://sourceforge.net/projects/osslsigncode/) utility be
installed. On OS X with homebrew, you can do this with
`brew install osslsigncode`.~~

~~You will also need to set the environment variables BNS_CERT and BNS_CERT_PASS
to point to [bns-cert.p12](https://github.com/getlantern/too-many-secrets/blob/master/bns_cert.p12)
and its [password](https://github.com/getlantern/too-many-secrets/blob/master/build-installers/env-vars.txt#L3)
so that the script can sign the Windows executable.~~

This script also signs the OS X executable, which requires you to use our OS X
signing certificate, available [here](https://github.com/getlantern/too-many-secrets/blob/master/osx-code-signing-certificate.p12).
The password is [here](https://github.com/getlantern/too-many-secrets/blob/master/osx-code-signing-certificate.p12.txt).
Binary file not shown.
25 changes: 25 additions & 0 deletions src/github.com/getlantern/go-igdman/embedupnpc.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

###############################################################################
#
# This script regenerates the source files that embed the upnpc executable.
#
###############################################################################

function die() {
echo $*
exit 1
}

# if [ -z "$BNS_CERT" ] || [ -z "$BNS_CERT_PASS" ]
# then
# die "$0: Please set BNS_CERT and BNS_CERT_PASS to the bns_cert.p12 signing key and the password for that key"
# fi

# osslsigncode sign -pkcs12 "$BNS_CERT" -pass "$BNS_CERT_PASS" -in binaries/windows/natty -out binaries/windows/natty || die "Could not sign windows"
codesign -s "Developer ID Application: Brave New Software Project, Inc" -f binaries/osx/upnpc || die "Could not sign macintosh"

go-bindata -nomemcopy -nocompress -pkg igdman -prefix binaries/osx -o igdman/upnpc_darwin.go binaries/osx
# go-bindata -nomemcopy -nocompress -pkg bin -prefix binaries/linux_386 -o natty/bin/linux_386.go binaries/linux_386
# go-bindata -nomemcopy -nocompress -pkg bin -prefix binaries/linux_amd64 -o natty/bin/linux_amd64.go binaries/linux_amd64
# go-bindata -nomemcopy -nocompress -pkg bin -prefix binaries/windows -o natty/bin/windows.go binaries/windows
7 changes: 5 additions & 2 deletions src/github.com/getlantern/go-igdman/igdman/igdman.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
package igdman

import (
"log"
"time"

"github.com/getlantern/golog"
)

// protocol is TCP or UDP
Expand All @@ -35,6 +36,8 @@ const (
)

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

opTimeout = 10 * time.Second
)

Expand All @@ -55,7 +58,7 @@ type IGD interface {
func NewIGD() (igd IGD, err error) {
igd, err = NewUpnpIGD()
if err != nil {
log.Printf("Unable to initialize UPnP IGD, falling back to NAT-PMP: %s", err)
log.Debugf("Unable to initialize UPnP IGD, falling back to NAT-PMP: %s", err)
igd, err = NewNATPMPIGD()
}
return
Expand Down
2 changes: 1 addition & 1 deletion src/github.com/getlantern/go-igdman/igdman/upnp.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (igd *upnpIGD) AddPortMapping(proto protocol, internalIP string, internalPo
if expiration > 0 {
params = append(params, fmt.Sprintf("%d", expiration/time.Second))
}
out, err := upnpcbe.Command(params...).CombinedOutput()
out, err := execTimeout(opTimeout, upnpcbe.Command(params...))
if err != nil {
return fmt.Errorf("Unable to add port mapping: %s\n%s", err, out)
} else if strings.Contains(string(out), "failed with") {
Expand Down
58 changes: 56 additions & 2 deletions src/github.com/getlantern/go-igdman/igdman/upnpc_darwin.go

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/github.com/getlantern/go-igdman/igdman/util_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package igdman

import (
"fmt"
"log"
"os/exec"
"regexp"
"time"
Expand All @@ -21,11 +20,13 @@ func init() {
}

func defaultGatewayIp() (string, error) {
log.Trace("Calling netstat")
cmd := exec.Command("netstat", "-f", "inet", "-rn")
out, err := execTimeout(10*time.Second, cmd)
if err != nil {
return "", fmt.Errorf("Unable to call netstat: %s\n%s", err, out)
}
log.Tracef("Netstat output\n------------\n%s\n\n", out)

submatches := searchRegex.FindSubmatch(out)
if len(submatches) < 2 {
Expand Down
1 change: 0 additions & 1 deletion src/github.com/getlantern/go-igdman/igdman/util_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package igdman

import (
"fmt"
"log"
"os/exec"
"regexp"
"time"
Expand Down
1 change: 0 additions & 1 deletion src/github.com/getlantern/go-igdman/igdman/util_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package igdman

import (
"fmt"
"log"
"os/exec"
"regexp"
)
Expand Down
File renamed without changes.

0 comments on commit 6af0225

Please sign in to comment.