Skip to content

Commit

Permalink
Merge pull request #4425 from getlantern/issue4193-fffw
Browse files Browse the repository at this point in the history
flashlight client call protect package only on Android
  • Loading branch information
oxtoacart committed May 31, 2016
2 parents e33b07f + bd55306 commit dc8f658
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/github.com/getlantern/flashlight/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/getlantern/detour"
"github.com/getlantern/eventual"
"github.com/getlantern/golog"
"github.com/getlantern/protected"
)

const (
Expand Down Expand Up @@ -234,7 +233,7 @@ func (client *Client) dialCONNECT(addr string, port int) (net.Conn, error) {
return d("tcp", addr)
}
log.Tracef("Port not allowed, bypassing proxy and sending CONNECT request directly to %v", addr)
return protected.Dial("tcp", addr, 1*time.Minute)
return dialDirect("tcp", addr, 1*time.Minute)
}

func (client *Client) shouldSendToProxy(port int) bool {
Expand Down
12 changes: 12 additions & 0 deletions src/github.com/getlantern/flashlight/client/dial_direct.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// +build !android

package client

import (
"net"
"time"
)

func dialDirect(network, addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout(network, addr, timeout)
}
13 changes: 13 additions & 0 deletions src/github.com/getlantern/flashlight/client/dial_direct_android.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package client

import (
"net"
"time"

"github.com/getlantern/protected"
)

// Bypass VPN on Android
func DialDirect(network, addr string, timeout time.Duration) (net.Conn, error) {
return protected.Dial(network, addr, timeout)
}
6 changes: 1 addition & 5 deletions src/github.com/getlantern/protected/protected.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,6 @@ func Resolve(addr string) (*net.TCPAddr, error) {
// specified system device (this is primarily
// used for Android VpnService routing functionality)
func Dial(network, addr string, timeout time.Duration) (net.Conn, error) {
protect, _ := getCurrent()
if protect == nil {
return net.DialTimeout(network, addr, timeout)
}

host, port, err := SplitHostPort(addr)
if err != nil {
return nil, err
Expand Down Expand Up @@ -164,6 +159,7 @@ func Dial(network, addr string, timeout time.Duration) (net.Conn, error) {
defer conn.cleanup()

// Actually protect the underlying socket here
protect, _ := getCurrent()
err = protect(conn.socketFd)
if err != nil {
return nil, fmt.Errorf("Could not bind socket to system device: %v", err)
Expand Down

0 comments on commit dc8f658

Please sign in to comment.