Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
G
gost
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
gost
Commits
8d16b2d0
Commit
8d16b2d0
authored
Dec 22, 2018
by
ginuerzh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add timeout for Connectors
parent
99a08048
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
154 additions
and
13 deletions
+154
-13
.dockerignore
.dockerignore
+25
-0
chain.go
chain.go
+6
-1
client.go
client.go
+9
-1
common_test.go
common_test.go
+4
-0
forward.go
forward.go
+12
-3
gost.go
gost.go
+4
-2
http.go
http.go
+13
-0
http_test.go
http_test.go
+2
-3
socks.go
socks.go
+66
-3
ss.go
ss.go
+13
-0
No files found.
.dockerignore
0 → 100644
View file @
8d16b2d0
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
# Folders
_obj
_test
release
debian
docs
*.exe
*.test
*.bak
.git
.gitignore
LICENSE
VERSION
README.md
Changelog.md
Makefile
docker-compose.yml
\ No newline at end of file
chain.go
View file @
8d16b2d0
...
@@ -136,8 +136,13 @@ func (c *Chain) dialWithOptions(addr string, options *ChainOptions) (net.Conn, e
...
@@ -136,8 +136,13 @@ func (c *Chain) dialWithOptions(addr string, options *ChainOptions) (net.Conn, e
ipAddr
:=
c
.
resolve
(
addr
,
options
.
Resolver
,
options
.
Hosts
)
ipAddr
:=
c
.
resolve
(
addr
,
options
.
Resolver
,
options
.
Hosts
)
timeout
:=
options
.
Timeout
if
timeout
<=
0
{
timeout
=
DialTimeout
}
if
route
.
IsEmpty
()
{
if
route
.
IsEmpty
()
{
return
net
.
DialTimeout
(
"tcp"
,
ipAddr
,
options
.
T
imeout
)
return
net
.
DialTimeout
(
"tcp"
,
ipAddr
,
t
imeout
)
}
}
conn
,
err
:=
route
.
getConn
()
conn
,
err
:=
route
.
getConn
()
...
...
client.go
View file @
8d16b2d0
...
@@ -236,7 +236,8 @@ func QUICConfigHandshakeOption(config *QUICConfig) HandshakeOption {
...
@@ -236,7 +236,8 @@ func QUICConfigHandshakeOption(config *QUICConfig) HandshakeOption {
// ConnectOptions describes the options for Connector.Connect.
// ConnectOptions describes the options for Connector.Connect.
type
ConnectOptions
struct
{
type
ConnectOptions
struct
{
Addr
string
Addr
string
Timeout
time
.
Duration
}
}
// ConnectOption allows a common way to set ConnectOptions.
// ConnectOption allows a common way to set ConnectOptions.
...
@@ -248,3 +249,10 @@ func AddrConnectOption(addr string) ConnectOption {
...
@@ -248,3 +249,10 @@ func AddrConnectOption(addr string) ConnectOption {
opts
.
Addr
=
addr
opts
.
Addr
=
addr
}
}
}
}
// TimeoutConnectOption specifies the timeout for connecting to target.
func
TimeoutConnectOption
(
timeout
time
.
Duration
)
ConnectOption
{
return
func
(
opts
*
ConnectOptions
)
{
opts
.
Timeout
=
timeout
}
}
common_test.go
View file @
8d16b2d0
...
@@ -8,11 +8,15 @@ import (
...
@@ -8,11 +8,15 @@ import (
"net"
"net"
"net/http"
"net/http"
"sync"
"sync"
"time"
)
)
func
init
()
{
func
init
()
{
// SetLogger(&LogLogger{})
// SetLogger(&LogLogger{})
// Debug = true
// Debug = true
DialTimeout
=
500
*
time
.
Millisecond
HandshakeTimeout
=
500
*
time
.
Millisecond
ConnectTimeout
=
500
*
time
.
Millisecond
cert
,
err
:=
GenCertificate
()
cert
,
err
:=
GenCertificate
()
if
err
!=
nil
{
if
err
!=
nil
{
...
...
forward.go
View file @
8d16b2d0
...
@@ -714,6 +714,8 @@ func (l *tcpRemoteForwardListener) listenLoop() {
...
@@ -714,6 +714,8 @@ func (l *tcpRemoteForwardListener) listenLoop() {
continue
continue
}
}
tempDelay
=
0
select
{
select
{
case
l
.
connChan
<-
conn
:
case
l
.
connChan
<-
conn
:
default
:
default
:
...
@@ -774,7 +776,7 @@ func (l *tcpRemoteForwardListener) muxAccept() (conn net.Conn, err error) {
...
@@ -774,7 +776,7 @@ func (l *tcpRemoteForwardListener) muxAccept() (conn net.Conn, err error) {
return
cc
,
nil
return
cc
,
nil
}
}
func
(
l
*
tcpRemoteForwardListener
)
getSession
()
(
*
muxSession
,
error
)
{
func
(
l
*
tcpRemoteForwardListener
)
getSession
()
(
s
*
muxSession
,
err
error
)
{
l
.
sessionMux
.
Lock
()
l
.
sessionMux
.
Lock
()
defer
l
.
sessionMux
.
Unlock
()
defer
l
.
sessionMux
.
Unlock
()
...
@@ -787,6 +789,15 @@ func (l *tcpRemoteForwardListener) getSession() (*muxSession, error) {
...
@@ -787,6 +789,15 @@ func (l *tcpRemoteForwardListener) getSession() (*muxSession, error) {
return
nil
,
err
return
nil
,
err
}
}
defer
func
(
c
net
.
Conn
)
{
if
err
!=
nil
{
c
.
Close
()
}
}(
conn
)
conn
.
SetDeadline
(
time
.
Now
()
.
Add
(
HandshakeTimeout
))
defer
conn
.
SetDeadline
(
time
.
Time
{})
conn
,
err
=
socks5Handshake
(
conn
,
l
.
chain
.
LastNode
()
.
User
)
conn
,
err
=
socks5Handshake
(
conn
,
l
.
chain
.
LastNode
()
.
User
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -797,13 +808,11 @@ func (l *tcpRemoteForwardListener) getSession() (*muxSession, error) {
...
@@ -797,13 +808,11 @@ func (l *tcpRemoteForwardListener) getSession() (*muxSession, error) {
return
nil
,
err
return
nil
,
err
}
}
conn
.
SetReadDeadline
(
time
.
Now
()
.
Add
(
ReadTimeout
))
rep
,
err
:=
gosocks5
.
ReadReply
(
conn
)
rep
,
err
:=
gosocks5
.
ReadReply
(
conn
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Log
(
"[rtcp] SOCKS5 BIND reply: "
,
err
)
log
.
Log
(
"[rtcp] SOCKS5 BIND reply: "
,
err
)
return
nil
,
err
return
nil
,
err
}
}
conn
.
SetReadDeadline
(
time
.
Time
{})
if
rep
.
Rep
!=
gosocks5
.
Succeeded
{
if
rep
.
Rep
!=
gosocks5
.
Succeeded
{
log
.
Logf
(
"[rtcp] bind on %s failure"
,
l
.
addr
)
log
.
Logf
(
"[rtcp] bind on %s failure"
,
l
.
addr
)
return
nil
,
fmt
.
Errorf
(
"Bind on %s failure"
,
l
.
addr
.
String
())
return
nil
,
fmt
.
Errorf
(
"Bind on %s failure"
,
l
.
addr
.
String
())
...
...
gost.go
View file @
8d16b2d0
...
@@ -53,10 +53,12 @@ var (
...
@@ -53,10 +53,12 @@ var (
DialTimeout
=
5
*
time
.
Second
DialTimeout
=
5
*
time
.
Second
// HandshakeTimeout is the timeout of handshake.
// HandshakeTimeout is the timeout of handshake.
HandshakeTimeout
=
5
*
time
.
Second
HandshakeTimeout
=
5
*
time
.
Second
// ConnectTimeout is the timeout for connect.
ConnectTimeout
=
5
*
time
.
Second
// ReadTimeout is the timeout for reading.
// ReadTimeout is the timeout for reading.
ReadTimeout
=
5
*
time
.
Second
ReadTimeout
=
10
*
time
.
Second
// WriteTimeout is the timeout for writing.
// WriteTimeout is the timeout for writing.
WriteTimeout
=
5
*
time
.
Second
WriteTimeout
=
10
*
time
.
Second
// PingTimeout is the timeout for pinging.
// PingTimeout is the timeout for pinging.
PingTimeout
=
30
*
time
.
Second
PingTimeout
=
30
*
time
.
Second
// PingRetries is the reties of ping.
// PingRetries is the reties of ping.
...
...
http.go
View file @
8d16b2d0
...
@@ -28,6 +28,19 @@ func HTTPConnector(user *url.Userinfo) Connector {
...
@@ -28,6 +28,19 @@ func HTTPConnector(user *url.Userinfo) Connector {
}
}
func
(
c
*
httpConnector
)
Connect
(
conn
net
.
Conn
,
addr
string
,
options
...
ConnectOption
)
(
net
.
Conn
,
error
)
{
func
(
c
*
httpConnector
)
Connect
(
conn
net
.
Conn
,
addr
string
,
options
...
ConnectOption
)
(
net
.
Conn
,
error
)
{
opts
:=
&
ConnectOptions
{}
for
_
,
option
:=
range
options
{
option
(
opts
)
}
timeout
:=
opts
.
Timeout
if
timeout
<=
0
{
timeout
=
ConnectTimeout
}
conn
.
SetDeadline
(
time
.
Now
()
.
Add
(
timeout
))
defer
conn
.
SetDeadline
(
time
.
Time
{})
req
:=
&
http
.
Request
{
req
:=
&
http
.
Request
{
Method
:
http
.
MethodConnect
,
Method
:
http
.
MethodConnect
,
URL
:
&
url
.
URL
{
Host
:
addr
},
URL
:
&
url
.
URL
{
Host
:
addr
},
...
...
http_test.go
View file @
8d16b2d0
...
@@ -12,7 +12,6 @@ import (
...
@@ -12,7 +12,6 @@ import (
"net/http/httptest"
"net/http/httptest"
"net/url"
"net/url"
"testing"
"testing"
"time"
)
)
// proxyConn obtains a connection to the proxy server.
// proxyConn obtains a connection to the proxy server.
...
@@ -77,8 +76,8 @@ func proxyRoundtrip(client *Client, server *Server, targetURL string, data []byt
...
@@ -77,8 +76,8 @@ func proxyRoundtrip(client *Client, server *Server, targetURL string, data []byt
return
return
}
}
conn
.
SetDeadline
(
time
.
Now
()
.
Add
(
500
*
time
.
Millisecond
))
//
conn.SetDeadline(time.Now().Add(500 * time.Millisecond))
defer
conn
.
SetDeadline
(
time
.
Time
{})
//
defer conn.SetDeadline(time.Time{})
conn
,
err
=
client
.
Connect
(
conn
,
u
.
Host
)
conn
,
err
=
client
.
Connect
(
conn
,
u
.
Host
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
socks.go
View file @
8d16b2d0
...
@@ -205,6 +205,19 @@ func SOCKS5Connector(user *url.Userinfo) Connector {
...
@@ -205,6 +205,19 @@ func SOCKS5Connector(user *url.Userinfo) Connector {
}
}
func
(
c
*
socks5Connector
)
Connect
(
conn
net
.
Conn
,
addr
string
,
options
...
ConnectOption
)
(
net
.
Conn
,
error
)
{
func
(
c
*
socks5Connector
)
Connect
(
conn
net
.
Conn
,
addr
string
,
options
...
ConnectOption
)
(
net
.
Conn
,
error
)
{
opts
:=
&
ConnectOptions
{}
for
_
,
option
:=
range
options
{
option
(
opts
)
}
timeout
:=
opts
.
Timeout
if
timeout
<=
0
{
timeout
=
ConnectTimeout
}
conn
.
SetDeadline
(
time
.
Now
()
.
Add
(
timeout
))
defer
conn
.
SetDeadline
(
time
.
Time
{})
selector
:=
&
clientSelector
{
selector
:=
&
clientSelector
{
TLSConfig
:
&
tls
.
Config
{
InsecureSkipVerify
:
true
},
TLSConfig
:
&
tls
.
Config
{
InsecureSkipVerify
:
true
},
User
:
c
.
User
,
User
:
c
.
User
,
...
@@ -266,6 +279,19 @@ func SOCKS5BindConnector(user *url.Userinfo) Connector {
...
@@ -266,6 +279,19 @@ func SOCKS5BindConnector(user *url.Userinfo) Connector {
}
}
func
(
c
*
socks5BindConnector
)
Connect
(
conn
net
.
Conn
,
addr
string
,
options
...
ConnectOption
)
(
net
.
Conn
,
error
)
{
func
(
c
*
socks5BindConnector
)
Connect
(
conn
net
.
Conn
,
addr
string
,
options
...
ConnectOption
)
(
net
.
Conn
,
error
)
{
opts
:=
&
ConnectOptions
{}
for
_
,
option
:=
range
options
{
option
(
opts
)
}
timeout
:=
opts
.
Timeout
if
timeout
<=
0
{
timeout
=
ConnectTimeout
}
conn
.
SetDeadline
(
time
.
Now
()
.
Add
(
timeout
))
defer
conn
.
SetDeadline
(
time
.
Time
{})
cc
,
err
:=
socks5Handshake
(
conn
,
c
.
User
)
cc
,
err
:=
socks5Handshake
(
conn
,
c
.
User
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -292,12 +318,10 @@ func (c *socks5BindConnector) Connect(conn net.Conn, addr string, options ...Con
...
@@ -292,12 +318,10 @@ func (c *socks5BindConnector) Connect(conn net.Conn, addr string, options ...Con
log
.
Log
(
"[socks5] bind
\n
"
,
req
)
log
.
Log
(
"[socks5] bind
\n
"
,
req
)
}
}
conn
.
SetReadDeadline
(
time
.
Now
()
.
Add
(
ReadTimeout
))
reply
,
err
:=
gosocks5
.
ReadReply
(
conn
)
reply
,
err
:=
gosocks5
.
ReadReply
(
conn
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
conn
.
SetReadDeadline
(
time
.
Time
{})
if
Debug
{
if
Debug
{
log
.
Log
(
"[socks5] bind
\n
"
,
reply
)
log
.
Log
(
"[socks5] bind
\n
"
,
reply
)
...
@@ -327,6 +351,19 @@ func SOCKS5UDPConnector(user *url.Userinfo) Connector {
...
@@ -327,6 +351,19 @@ func SOCKS5UDPConnector(user *url.Userinfo) Connector {
}
}
func
(
c
*
socks5UDPConnector
)
Connect
(
conn
net
.
Conn
,
addr
string
,
options
...
ConnectOption
)
(
net
.
Conn
,
error
)
{
func
(
c
*
socks5UDPConnector
)
Connect
(
conn
net
.
Conn
,
addr
string
,
options
...
ConnectOption
)
(
net
.
Conn
,
error
)
{
opts
:=
&
ConnectOptions
{}
for
_
,
option
:=
range
options
{
option
(
opts
)
}
timeout
:=
opts
.
Timeout
if
timeout
<=
0
{
timeout
=
ConnectTimeout
}
conn
.
SetDeadline
(
time
.
Now
()
.
Add
(
timeout
))
defer
conn
.
SetDeadline
(
time
.
Time
{})
cc
,
err
:=
socks5Handshake
(
conn
,
c
.
User
)
cc
,
err
:=
socks5Handshake
(
conn
,
c
.
User
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -388,6 +425,19 @@ func SOCKS4Connector() Connector {
...
@@ -388,6 +425,19 @@ func SOCKS4Connector() Connector {
}
}
func
(
c
*
socks4Connector
)
Connect
(
conn
net
.
Conn
,
addr
string
,
options
...
ConnectOption
)
(
net
.
Conn
,
error
)
{
func
(
c
*
socks4Connector
)
Connect
(
conn
net
.
Conn
,
addr
string
,
options
...
ConnectOption
)
(
net
.
Conn
,
error
)
{
opts
:=
&
ConnectOptions
{}
for
_
,
option
:=
range
options
{
option
(
opts
)
}
timeout
:=
opts
.
Timeout
if
timeout
<=
0
{
timeout
=
ConnectTimeout
}
conn
.
SetDeadline
(
time
.
Now
()
.
Add
(
timeout
))
defer
conn
.
SetDeadline
(
time
.
Time
{})
taddr
,
err
:=
net
.
ResolveTCPAddr
(
"tcp4"
,
addr
)
taddr
,
err
:=
net
.
ResolveTCPAddr
(
"tcp4"
,
addr
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -435,6 +485,19 @@ func SOCKS4AConnector() Connector {
...
@@ -435,6 +485,19 @@ func SOCKS4AConnector() Connector {
}
}
func
(
c
*
socks4aConnector
)
Connect
(
conn
net
.
Conn
,
addr
string
,
options
...
ConnectOption
)
(
net
.
Conn
,
error
)
{
func
(
c
*
socks4aConnector
)
Connect
(
conn
net
.
Conn
,
addr
string
,
options
...
ConnectOption
)
(
net
.
Conn
,
error
)
{
opts
:=
&
ConnectOptions
{}
for
_
,
option
:=
range
options
{
option
(
opts
)
}
timeout
:=
opts
.
Timeout
if
timeout
<=
0
{
timeout
=
ConnectTimeout
}
conn
.
SetDeadline
(
time
.
Now
()
.
Add
(
timeout
))
defer
conn
.
SetDeadline
(
time
.
Time
{})
host
,
port
,
err
:=
net
.
SplitHostPort
(
addr
)
host
,
port
,
err
:=
net
.
SplitHostPort
(
addr
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -1645,7 +1708,7 @@ type socks5UDPConn struct {
...
@@ -1645,7 +1708,7 @@ type socks5UDPConn struct {
func
(
c
*
socks5UDPConn
)
Read
(
b
[]
byte
)
(
int
,
error
)
{
func
(
c
*
socks5UDPConn
)
Read
(
b
[]
byte
)
(
int
,
error
)
{
data
:=
mPool
.
Get
()
.
([]
byte
)
data
:=
mPool
.
Get
()
.
([]
byte
)
defer
mPool
.
Put
(
data
)
defer
mPool
.
Put
(
data
)
n
,
err
:=
c
.
UDPConn
.
Read
(
data
)
n
,
err
:=
c
.
UDPConn
.
Read
(
data
)
if
err
!=
nil
{
if
err
!=
nil
{
return
0
,
err
return
0
,
err
...
...
ss.go
View file @
8d16b2d0
...
@@ -68,6 +68,19 @@ func ShadowConnector(cipher *url.Userinfo) Connector {
...
@@ -68,6 +68,19 @@ func ShadowConnector(cipher *url.Userinfo) Connector {
}
}
func
(
c
*
shadowConnector
)
Connect
(
conn
net
.
Conn
,
addr
string
,
options
...
ConnectOption
)
(
net
.
Conn
,
error
)
{
func
(
c
*
shadowConnector
)
Connect
(
conn
net
.
Conn
,
addr
string
,
options
...
ConnectOption
)
(
net
.
Conn
,
error
)
{
opts
:=
&
ConnectOptions
{}
for
_
,
option
:=
range
options
{
option
(
opts
)
}
timeout
:=
opts
.
Timeout
if
timeout
<=
0
{
timeout
=
ConnectTimeout
}
conn
.
SetDeadline
(
time
.
Now
()
.
Add
(
timeout
))
defer
conn
.
SetDeadline
(
time
.
Time
{})
rawaddr
,
err
:=
ss
.
RawAddr
(
addr
)
rawaddr
,
err
:=
ss
.
RawAddr
(
addr
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment