Skip to content

Commit

Permalink
vendor: update
Browse files Browse the repository at this point in the history
  • Loading branch information
fatedier committed May 8, 2018
1 parent 20fcb58 commit 071cbf4
Show file tree
Hide file tree
Showing 21 changed files with 1,651 additions and 811 deletions.
25 changes: 15 additions & 10 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions tests/func_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (

"github.com/fatedier/frp/client"
"github.com/fatedier/frp/server"
"github.com/fatedier/frp/utils/net"

gnet "github.com/fatedier/golib/net"
)

var (
Expand Down Expand Up @@ -279,7 +280,7 @@ func TestPluginHttpProxy(t *testing.T) {
}

// connect method
conn, err := net.ConnectTcpServerByProxy("http://"+addr, fmt.Sprintf("127.0.0.1:%d", TEST_TCP_FRP_PORT))
conn, err := gnet.DialTcpByProxy("http://"+addr, fmt.Sprintf("127.0.0.1:%d", TEST_TCP_FRP_PORT))
if assert.NoError(err) {
res, err := sendTcpMsgByConn(conn, TEST_TCP_ECHO_STR)
assert.NoError(err)
Expand Down
7 changes: 6 additions & 1 deletion utils/net/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/fatedier/frp/utils/log"

gnet "github.com/fatedier/golib/net"
kcp "github.com/fatedier/kcp-go"
)

Expand Down Expand Up @@ -123,7 +124,11 @@ func ConnectServer(protocol string, addr string) (c Conn, err error) {
func ConnectServerByProxy(proxyUrl string, protocol string, addr string) (c Conn, err error) {
switch protocol {
case "tcp":
return ConnectTcpServerByProxy(proxyUrl, addr)
var conn net.Conn
if conn, err = gnet.DialTcpByProxy(proxyUrl, addr); err != nil {
return
}
return WrapConn(conn), nil
case "kcp":
// http proxy is not supported for kcp
return ConnectServer(protocol, addr)
Expand Down
91 changes: 0 additions & 91 deletions utils/net/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,10 @@
package net

import (
"bufio"
"encoding/base64"
"fmt"
"net"
"net/http"
"net/url"

"github.com/fatedier/frp/utils/log"

"golang.org/x/net/proxy"
)

type TcpListener struct {
Expand Down Expand Up @@ -115,88 +109,3 @@ func ConnectTcpServer(addr string) (c Conn, err error) {
c = NewTcpConn(conn)
return
}

// ConnectTcpServerByProxy try to connect remote server by proxy.
func ConnectTcpServerByProxy(proxyStr string, serverAddr string) (c Conn, err error) {
if proxyStr == "" {
return ConnectTcpServer(serverAddr)
}

var (
proxyUrl *url.URL
username string
passwd string
)
if proxyUrl, err = url.Parse(proxyStr); err != nil {
return
}
if proxyUrl.User != nil {
username = proxyUrl.User.Username()
passwd, _ = proxyUrl.User.Password()
}

switch proxyUrl.Scheme {
case "http":
return ConnectTcpServerByHttpProxy(proxyUrl, username, passwd, serverAddr)
case "socks5":
return ConnectTcpServerBySocks5Proxy(proxyUrl, username, passwd, serverAddr)
default:
err = fmt.Errorf("Proxy URL scheme must be http or socks5, not [%s]", proxyUrl.Scheme)
return
}
}

// ConnectTcpServerByHttpProxy try to connect remote server by http proxy.
func ConnectTcpServerByHttpProxy(proxyUrl *url.URL, user string, passwd string, serverAddr string) (c Conn, err error) {
var proxyAuth string
if proxyUrl.User != nil {
proxyAuth = "Basic " + base64.StdEncoding.EncodeToString([]byte(user+":"+passwd))
}

if c, err = ConnectTcpServer(proxyUrl.Host); err != nil {
return
}

req, err := http.NewRequest("CONNECT", "http://"+serverAddr, nil)
if err != nil {
return
}
if proxyAuth != "" {
req.Header.Set("Proxy-Authorization", proxyAuth)
}
req.Header.Set("User-Agent", "Mozilla/5.0")
req.Write(c)

resp, err := http.ReadResponse(bufio.NewReader(c), req)
if err != nil {
return
}
resp.Body.Close()
if resp.StatusCode != 200 {
err = fmt.Errorf("ConnectTcpServer using proxy error, StatusCode [%d]", resp.StatusCode)
return
}
return
}

func ConnectTcpServerBySocks5Proxy(proxyUrl *url.URL, user string, passwd string, serverAddr string) (c Conn, err error) {
var auth *proxy.Auth
if proxyUrl.User != nil {
auth = &proxy.Auth{
User: user,
Password: passwd,
}
}

dialer, err := proxy.SOCKS5("tcp", proxyUrl.Host, auth, nil)
if err != nil {
return nil, err
}

var conn net.Conn
if conn, err = dialer.Dial("tcp", serverAddr); err != nil {
return
}
c = NewTcpConn(conn)
return
}
106 changes: 106 additions & 0 deletions vendor/github.com/fatedier/golib/net/proxy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions vendor/github.com/julienschmidt/httprouter/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 071cbf4

Please sign in to comment.