Skip to content

Commit

Permalink
Merged master to devel
Browse files Browse the repository at this point in the history
  • Loading branch information
oxtoacart committed Dec 19, 2014
2 parents ba2aad6 + d57ae91 commit f12da10
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 10 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
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

0 comments on commit f12da10

Please sign in to comment.