From fb6c630cece186df2d96cb74c643aa25ca062906 Mon Sep 17 00:00:00 2001 From: Dingjun Date: Sat, 16 Sep 2017 10:40:48 +0800 Subject: [PATCH] use dialer on package obfssh --- client.go | 2 +- conn.go | 2 ++ server.go | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index 6b506d9..d94b396 100644 --- a/client.go +++ b/client.go @@ -232,7 +232,7 @@ func (cc *Client) handleLocalForward(conn net.Conn, remote string) { } func (cc *Client) handleRemoteForward(conn net.Conn, local string) { - lconn, err := net.Dial("tcp", local) + lconn, err := dialer.Dial("tcp", local) if err != nil { Log(ERROR, "connect to %s failed: %s", local, err.Error()) conn.Close() diff --git a/conn.go b/conn.go index 36d35f3..4cb709d 100644 --- a/conn.go +++ b/conn.go @@ -5,6 +5,8 @@ import ( "time" ) +var dialer = &net.Dialer{Timeout: 10 * time.Second} + // TimedOutConn is a net.Conn with read/write timeout set type TimedOutConn struct { net.Conn diff --git a/server.go b/server.go index 9e2e15b..41492bc 100644 --- a/server.go +++ b/server.go @@ -182,7 +182,7 @@ func handleDirectTcpip(newch ssh.NewChannel) { Log(DEBUG, "create connection to %s:%d", r.Raddr, r.Rport) - rconn, err := net.Dial("tcp", net.JoinHostPort(r.Raddr, fmt.Sprintf("%d", r.Rport))) + rconn, err := dialer.Dial("tcp", net.JoinHostPort(r.Raddr, fmt.Sprintf("%d", r.Rport))) if err != nil { Log(ERROR, "%s", err.Error()) newch.Reject(ssh.ConnectionFailed, "invalid argument")