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
e42d27c3
Commit
e42d27c3
authored
Nov 06, 2017
by
rui.zheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix #165 #179
parent
dedd0853
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
9 deletions
+10
-9
ss.go
ss.go
+10
-9
No files found.
ss.go
View file @
e42d27c3
...
@@ -124,11 +124,15 @@ func (h *shadowHandler) Handle(conn net.Conn) {
...
@@ -124,11 +124,15 @@ func (h *shadowHandler) Handle(conn net.Conn) {
log
.
Logf
(
"[ss] %s - %s"
,
conn
.
RemoteAddr
(),
conn
.
LocalAddr
())
log
.
Logf
(
"[ss] %s - %s"
,
conn
.
RemoteAddr
(),
conn
.
LocalAddr
())
conn
.
SetReadDeadline
(
time
.
Now
()
.
Add
(
ReadTimeout
))
addr
,
err
:=
h
.
getRequest
(
conn
)
addr
,
err
:=
h
.
getRequest
(
conn
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Logf
(
"[ss] %s - %s : %s"
,
conn
.
RemoteAddr
(),
conn
.
LocalAddr
(),
err
)
log
.
Logf
(
"[ss] %s - %s : %s"
,
conn
.
RemoteAddr
(),
conn
.
LocalAddr
(),
err
)
return
return
}
}
// clear timer
conn
.
SetReadDeadline
(
time
.
Time
{})
log
.
Logf
(
"[ss] %s -> %s"
,
conn
.
RemoteAddr
(),
addr
)
log
.
Logf
(
"[ss] %s -> %s"
,
conn
.
RemoteAddr
(),
addr
)
if
!
Can
(
"tcp"
,
addr
,
h
.
options
.
Whitelist
,
h
.
options
.
Blacklist
)
{
if
!
Can
(
"tcp"
,
addr
,
h
.
options
.
Whitelist
,
h
.
options
.
Blacklist
)
{
...
@@ -165,19 +169,16 @@ const (
...
@@ -165,19 +169,16 @@ const (
)
)
// This function is copied from shadowsocks library with some modification.
// This function is copied from shadowsocks library with some modification.
func
(
h
*
shadowHandler
)
getRequest
(
conn
net
.
Conn
)
(
host
string
,
err
error
)
{
func
(
h
*
shadowHandler
)
getRequest
(
r
io
.
Reader
)
(
host
string
,
err
error
)
{
// buf size should at least have the same size with the largest possible
// buf size should at least have the same size with the largest possible
// request size (when addrType is 3, domain name has at most 256 bytes)
// request size (when addrType is 3, domain name has at most 256 bytes)
// 1(addrType) + 1(lenByte) + 256(max length address) + 2(port)
// 1(addrType) + 1(lenByte) + 256(max length address) + 2(port)
buf
:=
make
([]
byte
,
smallBufferSize
)
buf
:=
make
([]
byte
,
smallBufferSize
)
// read till we get possible domain length field
// read till we get possible domain length field
conn
.
SetReadDeadline
(
time
.
Now
()
.
Add
(
ReadTimeout
))
if
_
,
err
=
io
.
ReadFull
(
r
,
buf
[
:
idType
+
1
]);
err
!=
nil
{
if
_
,
err
=
io
.
ReadFull
(
conn
,
buf
[
:
idType
+
1
]);
err
!=
nil
{
return
return
}
}
// clear timer
conn
.
SetReadDeadline
(
time
.
Time
{})
var
reqStart
,
reqEnd
int
var
reqStart
,
reqEnd
int
addrType
:=
buf
[
idType
]
addrType
:=
buf
[
idType
]
...
@@ -187,16 +188,16 @@ func (h *shadowHandler) getRequest(conn net.Conn) (host string, err error) {
...
@@ -187,16 +188,16 @@ func (h *shadowHandler) getRequest(conn net.Conn) (host string, err error) {
case
typeIPv6
:
case
typeIPv6
:
reqStart
,
reqEnd
=
idIP0
,
idIP0
+
lenIPv6
reqStart
,
reqEnd
=
idIP0
,
idIP0
+
lenIPv6
case
typeDm
:
case
typeDm
:
if
_
,
err
=
io
.
ReadFull
(
conn
,
buf
[
idType
+
1
:
idDmLen
+
1
]);
err
!=
nil
{
if
_
,
err
=
io
.
ReadFull
(
r
,
buf
[
idType
+
1
:
idDmLen
+
1
]);
err
!=
nil
{
return
return
}
}
reqStart
,
reqEnd
=
idDm0
,
i
nt
(
idDm0
+
buf
[
idDmLen
]
+
lenDmBase
)
reqStart
,
reqEnd
=
idDm0
,
i
dDm0
+
int
(
buf
[
idDmLen
])
+
lenDmBase
default
:
default
:
err
=
fmt
.
Errorf
(
"addr type %d not supported"
,
addrType
&
ss
.
AddrMask
)
err
=
fmt
.
Errorf
(
"addr type %d not supported"
,
addrType
&
ss
.
AddrMask
)
return
return
}
}
if
_
,
err
=
io
.
ReadFull
(
conn
,
buf
[
reqStart
:
reqEnd
]);
err
!=
nil
{
if
_
,
err
=
io
.
ReadFull
(
r
,
buf
[
reqStart
:
reqEnd
]);
err
!=
nil
{
return
return
}
}
...
@@ -209,7 +210,7 @@ func (h *shadowHandler) getRequest(conn net.Conn) (host string, err error) {
...
@@ -209,7 +210,7 @@ func (h *shadowHandler) getRequest(conn net.Conn) (host string, err error) {
case
typeIPv6
:
case
typeIPv6
:
host
=
net
.
IP
(
buf
[
idIP0
:
idIP0
+
net
.
IPv6len
])
.
String
()
host
=
net
.
IP
(
buf
[
idIP0
:
idIP0
+
net
.
IPv6len
])
.
String
()
case
typeDm
:
case
typeDm
:
host
=
string
(
buf
[
idDm0
:
idDm0
+
buf
[
idDmLen
]
])
host
=
string
(
buf
[
idDm0
:
idDm0
+
int
(
buf
[
idDmLen
])
])
}
}
// parse port
// parse port
port
:=
binary
.
BigEndian
.
Uint16
(
buf
[
reqEnd
-
2
:
reqEnd
])
port
:=
binary
.
BigEndian
.
Uint16
(
buf
[
reqEnd
-
2
:
reqEnd
])
...
...
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