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
148d114c
Commit
148d114c
authored
Jan 14, 2017
by
rui.zheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ss client now support OTA
parent
e476a9f7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
28 deletions
+38
-28
conn.go
conn.go
+21
-24
server.go
server.go
+17
-4
No files found.
conn.go
View file @
148d114c
...
...
@@ -2,18 +2,18 @@ package gost
import
(
"bufio"
"bytes"
"crypto/tls"
"encoding/base64"
"errors"
"github.com/ginuerzh/gosocks5"
"github.com/golang/glog"
"github.com/shadowsocks/shadowsocks-go/shadowsocks"
ss
"github.com/shadowsocks/shadowsocks-go/shadowsocks"
"net"
"net/http"
"net/http/httputil"
"net/url"
"strconv"
"strings"
"sync"
"time"
)
...
...
@@ -115,15 +115,7 @@ func (c *ProxyConn) handshake() error {
}
c
.
conn
=
conn
case
"ss"
:
// shadowsocks
if
len
(
c
.
Node
.
Users
)
>
0
{
method
:=
c
.
Node
.
Users
[
0
]
.
Username
()
password
,
_
:=
c
.
Node
.
Users
[
0
]
.
Password
()
cipher
,
err
:=
shadowsocks
.
NewCipher
(
method
,
password
)
if
err
!=
nil
{
return
err
}
c
.
conn
=
&
shadowConn
{
conn
:
shadowsocks
.
NewConn
(
c
.
conn
,
cipher
)}
}
// nothing to do
case
"http"
,
"http2"
:
fallthrough
default
:
...
...
@@ -138,26 +130,31 @@ func (c *ProxyConn) handshake() error {
func
(
c
*
ProxyConn
)
Connect
(
addr
string
)
error
{
switch
c
.
Node
.
Protocol
{
case
"ss"
:
// shadowsocks
host
,
port
,
err
:=
net
.
SplitHostPort
(
addr
)
rawaddr
,
err
:=
ss
.
RawAddr
(
addr
)
if
err
!=
nil
{
return
err
}
p
,
_
:=
strconv
.
Atoi
(
port
)
req
:=
gosocks5
.
NewRequest
(
gosocks5
.
CmdConnect
,
&
gosocks5
.
Addr
{
Type
:
gosocks5
.
AddrDomain
,
Host
:
host
,
Port
:
uint16
(
p
),
})
buf
:=
bytes
.
Buffer
{}
if
err
:=
req
.
Write
(
&
buf
);
err
!=
nil
{
return
err
var
method
,
password
string
if
len
(
c
.
Node
.
Users
)
>
0
{
method
=
c
.
Node
.
Users
[
0
]
.
Username
()
password
,
_
=
c
.
Node
.
Users
[
0
]
.
Password
()
}
if
c
.
Node
.
getBool
(
"ota"
)
&&
!
strings
.
HasSuffix
(
method
,
"-auth"
)
{
method
+=
"-auth"
}
b
:=
buf
.
Bytes
()
if
_
,
err
:=
c
.
Write
(
b
[
3
:
]);
err
!=
nil
{
cipher
,
err
:=
ss
.
NewCipher
(
method
,
password
)
if
err
!=
nil
{
return
err
}
glog
.
V
(
LDEBUG
)
.
Infoln
(
"[ss]"
,
req
)
ssc
,
err
:=
ss
.
DialWithRawAddrConn
(
rawaddr
,
c
.
conn
,
cipher
)
if
err
!=
nil
{
return
err
}
c
.
conn
=
&
shadowConn
{
conn
:
ssc
}
return
nil
case
"socks"
,
"socks5"
:
host
,
port
,
err
:=
net
.
SplitHostPort
(
addr
)
if
err
!=
nil
{
...
...
server.go
View file @
148d114c
...
...
@@ -10,6 +10,7 @@ import (
"net"
"net/http"
"strconv"
"strings"
)
type
ProxyServer
struct
{
...
...
@@ -18,6 +19,7 @@ type ProxyServer struct {
TLSConfig
*
tls
.
Config
selector
*
serverSelector
cipher
*
ss
.
Cipher
ota
bool
}
func
NewProxyServer
(
node
ProxyNode
,
chain
*
ProxyChain
,
config
*
tls
.
Config
)
*
ProxyServer
{
...
...
@@ -29,10 +31,20 @@ func NewProxyServer(node ProxyNode, chain *ProxyChain, config *tls.Config) *Prox
}
var
cipher
*
ss
.
Cipher
if
node
.
Protocol
==
"ss"
&&
node
.
Users
!=
nil
{
var
ota
bool
if
node
.
Protocol
==
"ss"
{
var
err
error
method
:=
node
.
Users
[
0
]
.
Username
()
password
,
_
:=
node
.
Users
[
0
]
.
Password
()
var
method
,
password
string
if
len
(
node
.
Users
)
>
0
{
method
=
node
.
Users
[
0
]
.
Username
()
password
,
_
=
node
.
Users
[
0
]
.
Password
()
}
ota
=
node
.
getBool
(
"ota"
)
if
strings
.
HasSuffix
(
method
,
"-auth"
)
{
ota
=
true
method
=
strings
.
TrimSuffix
(
method
,
"-auth"
)
}
cipher
,
err
=
ss
.
NewCipher
(
method
,
password
)
if
err
!=
nil
{
glog
.
Fatal
(
err
)
...
...
@@ -54,6 +66,7 @@ func NewProxyServer(node ProxyNode, chain *ProxyChain, config *tls.Config) *Prox
tlsConfig
:
config
,
},
cipher
:
cipher
,
ota
:
ota
,
}
}
...
...
@@ -134,7 +147,7 @@ func (s *ProxyServer) handleConn(conn net.Conn) {
switch
s
.
Node
.
Protocol
{
case
"ss"
:
// shadowsocks
server
:=
NewShadowServer
(
ss
.
NewConn
(
conn
,
s
.
cipher
.
Copy
()),
s
)
server
.
OTA
=
s
.
Node
.
getBool
(
"ota"
)
server
.
OTA
=
s
.
ota
server
.
Serve
()
return
case
"http"
:
...
...
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