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
158125d4
Commit
158125d4
authored
Mar 27, 2015
by
ginuerzh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add shadowsocks compitable
parent
d0aca831
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
114 additions
and
684 deletions
+114
-684
client.go
client.go
+112
-1
gost.go
gost.go
+0
-681
main.go
main.go
+1
-1
server.go
server.go
+1
-1
No files found.
client.go
View file @
158125d4
...
@@ -3,6 +3,8 @@ package main
...
@@ -3,6 +3,8 @@ package main
import
(
import
(
"bufio"
"bufio"
"bytes"
"bytes"
"encoding/binary"
"fmt"
"github.com/ginuerzh/gosocks5"
"github.com/ginuerzh/gosocks5"
"github.com/shadowsocks/shadowsocks-go/shadowsocks"
"github.com/shadowsocks/shadowsocks-go/shadowsocks"
"io"
"io"
...
@@ -81,8 +83,14 @@ func cliHandle(conn net.Conn) {
...
@@ -81,8 +83,14 @@ func cliHandle(conn net.Conn) {
sconn
=
shadowsocks
.
NewConn
(
sconn
,
cipher
)
sconn
=
shadowsocks
.
NewConn
(
sconn
,
cipher
)
}
}
b
:=
make
([]
byte
,
8192
)
if
Shadows
{
cipher
,
_
:=
shadowsocks
.
NewCipher
(
Cipher
,
Password
)
conn
=
shadowsocks
.
NewConn
(
conn
,
cipher
)
handleShadow
(
conn
,
sconn
)
return
}
b
:=
make
([]
byte
,
8192
)
n
,
err
:=
io
.
ReadAtLeast
(
conn
,
b
,
2
)
n
,
err
:=
io
.
ReadAtLeast
(
conn
,
b
,
2
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Println
(
err
)
log
.
Println
(
err
)
...
@@ -258,3 +266,106 @@ func handleHttp(req *http.Request, conn net.Conn, sconn net.Conn) {
...
@@ -258,3 +266,106 @@ func handleHttp(req *http.Request, conn net.Conn, sconn net.Conn) {
log
.
Println
(
err
)
log
.
Println
(
err
)
}
}
}
}
func
handleShadow
(
conn
,
sconn
net
.
Conn
)
{
addr
,
extra
,
err
:=
getShadowRequest
(
conn
)
if
err
!=
nil
{
log
.
Println
(
err
)
return
}
req
:=
gosocks5
.
NewRequest
(
gosocks5
.
CmdConnect
,
addr
)
if
err
:=
req
.
Write
(
sconn
);
err
!=
nil
{
log
.
Println
(
err
)
return
}
rep
,
err
:=
gosocks5
.
ReadReply
(
sconn
)
if
err
!=
nil
||
rep
.
Rep
!=
gosocks5
.
Succeeded
{
log
.
Println
(
err
)
return
}
if
extra
!=
nil
{
if
_
,
err
:=
sconn
.
Write
(
extra
);
err
!=
nil
{
log
.
Println
(
err
)
return
}
}
if
err
:=
Transport
(
conn
,
sconn
);
err
!=
nil
{
log
.
Println
(
err
)
}
}
func
getShadowRequest
(
conn
net
.
Conn
)
(
addr
*
gosocks5
.
Addr
,
extra
[]
byte
,
err
error
)
{
const
(
idType
=
0
// address type index
idIP0
=
1
// ip addres start index
idDmLen
=
1
// domain address length index
idDm0
=
2
// domain address start index
typeIPv4
=
1
// type is ipv4 address
typeDm
=
3
// type is domain address
typeIPv6
=
4
// type is ipv6 address
lenIPv4
=
1
+
net
.
IPv4len
+
2
// 1addrType + ipv4 + 2port
lenIPv6
=
1
+
net
.
IPv6len
+
2
// 1addrType + ipv6 + 2port
lenDmBase
=
1
+
1
+
2
// 1addrType + 1addrLen + 2port, plus addrLen
)
// 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)
// 1(addrType) + 1(lenByte) + 256(max length address) + 2(port)
buf
:=
make
([]
byte
,
260
)
var
n
int
// read till we get possible domain length field
//shadowsocks.SetReadTimeout(conn)
if
n
,
err
=
io
.
ReadAtLeast
(
conn
,
buf
,
idDmLen
+
1
);
err
!=
nil
{
log
.
Println
(
err
)
return
}
addr
=
&
gosocks5
.
Addr
{
Type
:
buf
[
idType
],
}
reqLen
:=
-
1
switch
buf
[
idType
]
{
case
typeIPv4
:
reqLen
=
lenIPv4
case
typeIPv6
:
reqLen
=
lenIPv6
case
typeDm
:
reqLen
=
int
(
buf
[
idDmLen
])
+
lenDmBase
default
:
err
=
fmt
.
Errorf
(
"addr type %d not supported"
,
buf
[
idType
])
return
}
if
n
<
reqLen
{
// rare case
//ss.SetReadTimeout(conn)
if
_
,
err
=
io
.
ReadFull
(
conn
,
buf
[
n
:
reqLen
]);
err
!=
nil
{
log
.
Println
(
err
)
return
}
}
else
if
n
>
reqLen
{
// it's possible to read more than just the request head
extra
=
buf
[
reqLen
:
n
]
}
// Return string for typeIP is not most efficient, but browsers (Chrome,
// Safari, Firefox) all seems using typeDm exclusively. So this is not a
// big problem.
switch
buf
[
idType
]
{
case
typeIPv4
:
addr
.
Host
=
net
.
IP
(
buf
[
idIP0
:
idIP0
+
net
.
IPv4len
])
.
String
()
case
typeIPv6
:
addr
.
Host
=
net
.
IP
(
buf
[
idIP0
:
idIP0
+
net
.
IPv6len
])
.
String
()
case
typeDm
:
addr
.
Host
=
string
(
buf
[
idDm0
:
idDm0
+
buf
[
idDmLen
]])
}
// parse port
addr
.
Port
=
binary
.
BigEndian
.
Uint16
(
buf
[
reqLen
-
2
:
reqLen
])
return
}
gost.go
deleted
100644 → 0
View file @
d0aca831
This diff is collapsed.
Click to expand it.
main.go
View file @
158125d4
...
@@ -18,7 +18,7 @@ func init() {
...
@@ -18,7 +18,7 @@ func init() {
flag
.
StringVar
(
&
Saddr
,
"S"
,
""
,
"the server that connecting to"
)
flag
.
StringVar
(
&
Saddr
,
"S"
,
""
,
"the server that connecting to"
)
flag
.
StringVar
(
&
Laddr
,
"L"
,
":8080"
,
"listen address"
)
flag
.
StringVar
(
&
Laddr
,
"L"
,
":8080"
,
"listen address"
)
flag
.
StringVar
(
&
Cipher
,
"cipher"
,
"rc4-md5"
,
"cipher method"
)
flag
.
StringVar
(
&
Cipher
,
"cipher"
,
"rc4-md5"
,
"cipher method"
)
flag
.
StringVar
(
&
Password
,
"password"
,
"
20150327
"
,
"cipher password"
)
flag
.
StringVar
(
&
Password
,
"password"
,
"
ginuerzh@gmail.com
"
,
"cipher password"
)
flag
.
BoolVar
(
&
Shadows
,
"ss"
,
false
,
"shadowsocks compatible"
)
flag
.
BoolVar
(
&
Shadows
,
"ss"
,
false
,
"shadowsocks compatible"
)
flag
.
BoolVar
(
&
Debug
,
"d"
,
false
,
"debug option"
)
flag
.
BoolVar
(
&
Debug
,
"d"
,
false
,
"debug option"
)
flag
.
Parse
()
flag
.
Parse
()
...
...
server.go
View file @
158125d4
...
@@ -18,7 +18,7 @@ func selectMethod(methods ...uint8) uint8 {
...
@@ -18,7 +18,7 @@ func selectMethod(methods ...uint8) uint8 {
return
method
return
method
}
}
}
}
return
gosocks5
.
MethodNoA
cceptable
return
gosocks5
.
MethodNoA
uth
}
}
func
srvHandle
(
conn
net
.
Conn
,
method
uint8
)
{
func
srvHandle
(
conn
net
.
Conn
,
method
uint8
)
{
...
...
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