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
ee1fb89b
Commit
ee1fb89b
authored
Feb 05, 2016
by
rui.zheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bug #27
parent
a482f258
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
25 deletions
+31
-25
conn.go
conn.go
+1
-1
main.go
main.go
+1
-1
socks.go
socks.go
+25
-22
udp.go
udp.go
+4
-1
No files found.
conn.go
View file @
ee1fb89b
...
...
@@ -232,7 +232,7 @@ func Connect(addr string) (conn net.Conn, err error) {
func
forwardChain
(
chain
...
Args
)
(
conn
net
.
Conn
,
end
Args
,
err
error
)
{
end
=
chain
[
0
]
if
conn
,
err
=
net
.
DialTimeout
(
"tcp"
,
end
.
Addr
,
time
.
Second
*
3
0
);
err
!=
nil
{
if
conn
,
err
=
net
.
DialTimeout
(
"tcp"
,
end
.
Addr
,
time
.
Second
*
9
0
);
err
!=
nil
{
return
}
c
,
err
:=
forward
(
conn
,
end
)
...
...
main.go
View file @
ee1fb89b
...
...
@@ -18,7 +18,7 @@ const (
)
const
(
Version
=
"2.0-rc
2
"
Version
=
"2.0-rc
3
"
)
var
(
...
...
socks.go
View file @
ee1fb89b
...
...
@@ -235,7 +235,7 @@ func handleSocks5Request(req *gosocks5.Request, conn net.Conn) {
return
}
cc
=
Client
(
conn
,
nil
)
glog
.
V
(
LINFO
)
.
Infof
(
"[udp]
tunnel to
%s, length %d"
,
dgram
.
Header
.
Addr
,
len
(
dgram
.
Data
))
glog
.
V
(
LINFO
)
.
Infof
(
"[udp]
->
%s, length %d"
,
dgram
.
Header
.
Addr
,
len
(
dgram
.
Data
))
}
else
{
b
:=
udpPool
.
Get
()
.
([]
byte
)
defer
udpPool
.
Put
(
b
)
...
...
@@ -259,32 +259,31 @@ func handleSocks5Request(req *gosocks5.Request, conn net.Conn) {
glog
.
V
(
LWARNING
)
.
Infoln
(
"socks5 udp:"
,
err
)
return
}
defer
sc
.
Close
()
if
err
=
sc
.
WriteUDPTimeout
(
dgram
,
time
.
Second
*
6
0
);
err
!=
nil
{
if
err
=
sc
.
WriteUDPTimeout
(
dgram
,
time
.
Second
*
9
0
);
err
!=
nil
{
glog
.
V
(
LWARNING
)
.
Infoln
(
"socks5 udp:"
,
err
)
return
}
dgram
,
err
=
sc
.
ReadUDPTimeout
(
time
.
Second
*
6
0
)
dgram
,
err
=
sc
.
ReadUDPTimeout
(
time
.
Second
*
9
0
)
if
err
!=
nil
{
glog
.
V
(
LWARNING
)
.
Infoln
(
"socks5 udp:"
,
err
)
return
}
glog
.
V
(
LINFO
)
.
Infof
(
"[udp]
from
%s, length %d"
,
dgram
.
Header
.
Addr
,
len
(
dgram
.
Data
))
glog
.
V
(
LINFO
)
.
Infof
(
"[udp]
<-
%s, length %d"
,
dgram
.
Header
.
Addr
,
len
(
dgram
.
Data
))
if
err
=
cc
.
WriteUDPTimeout
(
dgram
,
time
.
Second
*
6
0
);
err
!=
nil
{
if
err
=
cc
.
WriteUDPTimeout
(
dgram
,
time
.
Second
*
9
0
);
err
!=
nil
{
glog
.
V
(
LWARNING
)
.
Infoln
(
"socks5 udp:"
,
err
)
return
}
if
req
.
Cmd
==
gosocks5
.
CmdUdp
{
go
func
()
{
ioutil
.
ReadAll
(
conn
)
cc
.
Close
()
sc
.
Close
()
go
TransportUDP
(
cc
,
sc
)
ioutil
.
ReadAll
(
conn
)
// wait for client exit
glog
.
V
(
LINFO
)
.
Infoln
(
"[udp] transfer done"
)
}()
}
}
else
{
TransportUDP
(
cc
,
sc
)
}
default
:
glog
.
V
(
LWARNING
)
.
Infoln
(
"Unrecognized request: "
,
req
)
}
...
...
@@ -317,6 +316,7 @@ func serveBind(conn net.Conn) error {
glog
.
V
(
LDEBUG
)
.
Infoln
(
rep
)
glog
.
V
(
LINFO
)
.
Infoln
(
"[socks5] BIND on"
,
addr
,
"OK"
)
l
.
SetDeadline
(
time
.
Now
()
.
Add
(
time
.
Minute
*
30
))
// wait 30 minutes at most
tconn
,
err
:=
l
.
AcceptTCP
()
l
.
Close
()
// only accept one peer
if
err
!=
nil
{
...
...
@@ -348,7 +348,7 @@ func serveBind(conn net.Conn) error {
func
forwardBind
(
req
*
gosocks5
.
Request
,
conn
net
.
Conn
)
error
{
fconn
,
_
,
err
:=
forwardChain
(
forwardArgs
...
)
if
err
!=
nil
{
glog
.
V
(
LWARNING
)
.
Infoln
(
"[socks5] BIND
(forward)
"
,
req
.
Addr
,
err
)
glog
.
V
(
LWARNING
)
.
Infoln
(
"[socks5] BIND
forward
"
,
req
.
Addr
,
err
)
if
fconn
!=
nil
{
fconn
.
Close
()
}
...
...
@@ -372,18 +372,18 @@ func forwardBind(req *gosocks5.Request, conn net.Conn) error {
// first reply
rep
,
err
:=
peekReply
(
conn
,
fconn
)
if
err
!=
nil
{
glog
.
V
(
LWARNING
)
.
Infoln
(
"[socks5] BIND
(forward)
"
,
err
)
glog
.
V
(
LWARNING
)
.
Infoln
(
"[socks5] BIND
forward
"
,
err
)
return
err
}
glog
.
V
(
LINFO
)
.
Infoln
(
"[socks5] BIND
(forward)
on"
,
rep
.
Addr
,
"OK"
)
glog
.
V
(
LINFO
)
.
Infoln
(
"[socks5] BIND
forward
on"
,
rep
.
Addr
,
"OK"
)
// second reply
rep
,
err
=
peekReply
(
conn
,
fconn
)
if
err
!=
nil
{
glog
.
V
(
LWARNING
)
.
Infoln
(
"[socks5] BIND
(forward)
accept"
,
err
)
glog
.
V
(
LWARNING
)
.
Infoln
(
"[socks5] BIND
forward
accept"
,
err
)
return
err
}
glog
.
V
(
LINFO
)
.
Infoln
(
"[socks5] BIND
(forward)
accept"
,
rep
.
Addr
)
glog
.
V
(
LINFO
)
.
Infoln
(
"[socks5] BIND
forward
accept"
,
rep
.
Addr
)
return
Transport
(
conn
,
fconn
)
}
...
...
@@ -460,13 +460,16 @@ func PipeUDP(src, dst *UDPConn, ch chan<- error) {
for
{
var
dgram
*
gosocks5
.
UDPDatagram
dgram
,
err
=
src
.
ReadUDP
Timeout
(
time
.
Second
*
60
)
dgram
,
err
=
src
.
ReadUDP
(
)
if
err
!=
nil
{
break
}
glog
.
V
(
LDEBUG
)
.
Infof
(
"[udp] addr %s, length %d"
,
dgram
.
Header
.
Addr
,
len
(
dgram
.
Data
))
if
err
=
dst
.
WriteUDPTimeout
(
dgram
,
time
.
Second
*
60
);
err
!=
nil
{
if
src
.
isClient
{
glog
.
V
(
LDEBUG
)
.
Infof
(
"[udp] -> %s, length %d"
,
dgram
.
Header
.
Addr
,
len
(
dgram
.
Data
))
}
else
{
glog
.
V
(
LDEBUG
)
.
Infof
(
"[udp] <- %s, length %d"
,
dgram
.
Header
.
Addr
,
len
(
dgram
.
Data
))
}
if
err
=
dst
.
WriteUDP
(
dgram
);
err
!=
nil
{
break
}
}
...
...
udp.go
View file @
ee1fb89b
...
...
@@ -72,7 +72,10 @@ func (c *UDPConn) readUDPClient() (*gosocks5.UDPDatagram, error) {
func
(
c
*
UDPConn
)
readUDPServer
()
(
*
gosocks5
.
UDPDatagram
,
error
)
{
if
c
.
udp
!=
nil
{
b
:=
make
([]
byte
,
65535
)
// b := make([]byte, 65535)
b
:=
udpPool
.
Get
()
.
([]
byte
)
defer
udpPool
.
Put
(
b
)
n
,
addr
,
err
:=
c
.
udp
.
ReadFrom
(
b
)
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