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
ipAddr
:=
c
.
resolve
(
addr
,
options
.
Resolver
,
options
.
Hosts
)
timeout
:=
options
.
Timeout
if
timeout
<=
0
{
timeout
=
DialTimeout
}
if
route
.
IsEmpty
()
{
return
net
.
DialTimeout
(
"tcp"
,
ipAddr
,
options
.
T
imeout
)
return
net
.
DialTimeout
(
"tcp"
,
ipAddr
,
t
imeout
)
}
conn
,
err
:=
route
.
getConn
()
...
...
client.go
View file @
8d16b2d0
...
...
@@ -236,7 +236,8 @@ func QUICConfigHandshakeOption(config *QUICConfig) HandshakeOption {
// ConnectOptions describes the options for Connector.Connect.
type
ConnectOptions
struct
{
Addr
string
Addr
string
Timeout
time
.
Duration
}
// ConnectOption allows a common way to set ConnectOptions.
...
...
@@ -248,3 +249,10 @@ func AddrConnectOption(addr string) ConnectOption {
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 (
"net"
"net/http"
"sync"
"time"
)
func
init
()
{
// SetLogger(&LogLogger{})
// Debug = true
DialTimeout
=
500
*
time
.
Millisecond
HandshakeTimeout
=
500
*
time
.
Millisecond
ConnectTimeout
=
500
*
time
.
Millisecond
cert
,
err
:=
GenCertificate
()
if
err
!=
nil
{
...
...
forward.go
View file @
8d16b2d0
...
...
@@ -714,6 +714,8 @@ func (l *tcpRemoteForwardListener) listenLoop() {
continue
}
tempDelay
=
0
select
{
case
l
.
connChan
<-
conn
:
default
:
...
...
@@ -774,7 +776,7 @@ func (l *tcpRemoteForwardListener) muxAccept() (conn net.Conn, err error) {
return
cc
,
nil
}
func
(
l
*
tcpRemoteForwardListener
)
getSession
()
(
*
muxSession
,
error
)
{
func
(
l
*
tcpRemoteForwardListener
)
getSession
()
(
s
*
muxSession
,
err
error
)
{
l
.
sessionMux
.
Lock
()
defer
l
.
sessionMux
.
Unlock
()
...
...
@@ -787,6 +789,15 @@ func (l *tcpRemoteForwardListener) getSession() (*muxSession, error) {
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
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -797,13 +808,11 @@ func (l *tcpRemoteForwardListener) getSession() (*muxSession, error) {
return
nil
,
err
}
conn
.
SetReadDeadline
(
time
.
Now
()
.
Add
(
ReadTimeout
))
rep
,
err
:=
gosocks5
.
ReadReply
(
conn
)
if
err
!=
nil
{
log
.
Log
(
"[rtcp] SOCKS5 BIND reply: "
,
err
)
return
nil
,
err
}
conn
.
SetReadDeadline
(
time
.
Time
{})
if
rep
.
Rep
!=
gosocks5
.
Succeeded
{
log
.
Logf
(
"[rtcp] bind on %s failure"
,
l
.
addr
)
return
nil
,
fmt
.
Errorf
(
"Bind on %s failure"
,
l
.
addr
.
String
())
...
...
gost.go
View file @
8d16b2d0
...
...
@@ -53,10 +53,12 @@ var (
DialTimeout
=
5
*
time
.
Second
// HandshakeTimeout is the timeout of handshake.
HandshakeTimeout
=
5
*
time
.
Second
// ConnectTimeout is the timeout for connect.
ConnectTimeout
=
5
*
time
.
Second
// ReadTimeout is the timeout for reading.
ReadTimeout
=
5
*
time
.
Second
ReadTimeout
=
10
*
time
.
Second
// WriteTimeout is the timeout for writing.
WriteTimeout
=
5
*
time
.
Second
WriteTimeout
=
10
*
time
.
Second
// PingTimeout is the timeout for pinging.
PingTimeout
=
30
*
time
.
Second
// PingRetries is the reties of ping.
...
...
http.go
View file @
8d16b2d0
...
...
@@ -28,6 +28,19 @@ func HTTPConnector(user *url.Userinfo) Connector {
}
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
{
Method
:
http
.
MethodConnect
,
URL
:
&
url
.
URL
{
Host
:
addr
},
...
...
http_test.go
View file @
8d16b2d0
...
...
@@ -12,7 +12,6 @@ import (
"net/http/httptest"
"net/url"
"testing"
"time"
)
// proxyConn obtains a connection to the proxy server.
...
...
@@ -77,8 +76,8 @@ func proxyRoundtrip(client *Client, server *Server, targetURL string, data []byt
return
}
conn
.
SetDeadline
(
time
.
Now
()
.
Add
(
500
*
time
.
Millisecond
))
defer
conn
.
SetDeadline
(
time
.
Time
{})
//
conn.SetDeadline(time.Now().Add(500 * time.Millisecond))
//
defer conn.SetDeadline(time.Time{})
conn
,
err
=
client
.
Connect
(
conn
,
u
.
Host
)
if
err
!=
nil
{
...
...
socks.go
View file @
8d16b2d0
...
...
@@ -205,6 +205,19 @@ func SOCKS5Connector(user *url.Userinfo) Connector {
}
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
{
TLSConfig
:
&
tls
.
Config
{
InsecureSkipVerify
:
true
},
User
:
c
.
User
,
...
...
@@ -266,6 +279,19 @@ func SOCKS5BindConnector(user *url.Userinfo) Connector {
}
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
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -292,12 +318,10 @@ func (c *socks5BindConnector) Connect(conn net.Conn, addr string, options ...Con
log
.
Log
(
"[socks5] bind
\n
"
,
req
)
}
conn
.
SetReadDeadline
(
time
.
Now
()
.
Add
(
ReadTimeout
))
reply
,
err
:=
gosocks5
.
ReadReply
(
conn
)
if
err
!=
nil
{
return
nil
,
err
}
conn
.
SetReadDeadline
(
time
.
Time
{})
if
Debug
{
log
.
Log
(
"[socks5] bind
\n
"
,
reply
)
...
...
@@ -327,6 +351,19 @@ func SOCKS5UDPConnector(user *url.Userinfo) Connector {
}
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
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -388,6 +425,19 @@ func SOCKS4Connector() Connector {
}
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
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -435,6 +485,19 @@ func SOCKS4AConnector() Connector {
}
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
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -1645,7 +1708,7 @@ type socks5UDPConn struct {
func
(
c
*
socks5UDPConn
)
Read
(
b
[]
byte
)
(
int
,
error
)
{
data
:=
mPool
.
Get
()
.
([]
byte
)
defer
mPool
.
Put
(
data
)
n
,
err
:=
c
.
UDPConn
.
Read
(
data
)
if
err
!=
nil
{
return
0
,
err
...
...
ss.go
View file @
8d16b2d0
...
...
@@ -68,6 +68,19 @@ func ShadowConnector(cipher *url.Userinfo) Connector {
}
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
)
if
err
!=
nil
{
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