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
da30584d
Commit
da30584d
authored
Nov 10, 2017
by
rui.zheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add host for client handshake
parent
637e6423
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
27 additions
and
15 deletions
+27
-15
chain.go
chain.go
+7
-7
client.go
client.go
+8
-0
cmd/gost/main.go
cmd/gost/main.go
+2
-1
node.go
node.go
+3
-1
obfs.go
obfs.go
+3
-2
ws.go
ws.go
+4
-4
No files found.
chain.go
View file @
da30584d
...
...
@@ -100,7 +100,7 @@ func (c *Chain) IsEmpty() bool {
// If the chain is empty, it will use the net.Dial directly.
func
(
c
*
Chain
)
Dial
(
addr
string
)
(
net
.
Conn
,
error
)
{
if
c
.
IsEmpty
()
{
return
net
.
Dial
(
"tcp"
,
addr
)
return
net
.
Dial
Timeout
(
"tcp"
,
addr
,
DialTimeout
)
}
route
,
err
:=
c
.
selectRoute
()
...
...
@@ -108,7 +108,7 @@ func (c *Chain) Dial(addr string) (net.Conn, error) {
return
nil
,
err
}
conn
,
err
:=
c
.
getConn
(
route
)
conn
,
err
:=
route
.
getConn
(
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -128,16 +128,16 @@ func (c *Chain) Conn() (conn net.Conn, err error) {
if
err
!=
nil
{
return
nil
,
err
}
conn
,
err
=
c
.
getConn
(
route
)
conn
,
err
=
route
.
getConn
(
)
return
}
func
(
c
*
Chain
)
getConn
(
route
*
Chain
)
(
conn
net
.
Conn
,
err
error
)
{
if
route
.
IsEmpty
()
{
func
(
c
*
Chain
)
getConn
()
(
conn
net
.
Conn
,
err
error
)
{
if
c
.
IsEmpty
()
{
err
=
ErrEmptyChain
return
}
nodes
:=
route
.
Nodes
()
nodes
:=
c
.
Nodes
()
node
:=
nodes
[
0
]
cn
,
err
:=
node
.
Client
.
Dial
(
node
.
Addr
,
node
.
DialOptions
...
)
...
...
@@ -206,7 +206,7 @@ func (c *Chain) selectRoute() (route *Chain, err error) {
}
func
selectIP
(
node
*
Node
)
(
string
,
error
)
{
s
:=
node
.
IP
Selector
s
:=
node
.
Selector
if
s
==
nil
{
s
=
&
RandomIPSelector
{}
}
...
...
client.go
View file @
da30584d
...
...
@@ -116,6 +116,7 @@ func ChainDialOption(chain *Chain) DialOption {
// HandshakeOptions describes the options for handshake.
type
HandshakeOptions
struct
{
Addr
string
Host
string
User
*
url
.
Userinfo
Timeout
time
.
Duration
Interval
time
.
Duration
...
...
@@ -136,6 +137,13 @@ func AddrHandshakeOption(addr string) HandshakeOption {
}
}
// HostHandshakeOption specifies the hostname
func
HostHandshakeOption
(
host
string
)
HandshakeOption
{
return
func
(
opts
*
HandshakeOptions
)
{
opts
.
Host
=
host
}
}
// UserHandshakeOption specifies the user used by Transporter.Handshake
func
UserHandshakeOption
(
user
*
url
.
Userinfo
)
HandshakeOption
{
return
func
(
opts
*
HandshakeOptions
)
{
...
...
cmd/gost/main.go
View file @
da30584d
...
...
@@ -140,7 +140,7 @@ func parseChainNode(ns string) (node gost.Node, err error) {
node
.
IPs
[
i
]
=
ip
+
":"
+
sport
}
}
node
.
IP
Selector
=
&
gost
.
RoundRobinIPSelector
{}
node
.
Selector
=
&
gost
.
RoundRobinIPSelector
{}
users
,
err
:=
parseUsers
(
node
.
Values
.
Get
(
"secrets"
))
if
err
!=
nil
{
...
...
@@ -265,6 +265,7 @@ func parseChainNode(ns string) (node gost.Node, err error) {
retry
,
_
:=
strconv
.
Atoi
(
node
.
Values
.
Get
(
"retry"
))
node
.
HandshakeOptions
=
append
(
node
.
HandshakeOptions
,
gost
.
AddrHandshakeOption
(
node
.
Addr
),
gost
.
HostHandshakeOption
(
node
.
Host
),
gost
.
UserHandshakeOption
(
node
.
User
),
gost
.
TLSConfigHandshakeOption
(
tlsCfg
),
gost
.
IntervalHandshakeOption
(
time
.
Duration
(
interval
)
*
time
.
Second
),
...
...
node.go
View file @
da30584d
...
...
@@ -11,6 +11,7 @@ type Node struct {
ID
int
Addr
string
IPs
[]
string
Host
string
Protocol
string
Transport
string
Remote
string
// remote address, used by tcp/udp port forwarding
...
...
@@ -19,7 +20,7 @@ type Node struct {
DialOptions
[]
DialOption
HandshakeOptions
[]
HandshakeOption
Client
*
Client
IPSelector
IPSelector
Selector
IPSelector
}
// ParseNode parses the node info.
...
...
@@ -40,6 +41,7 @@ func ParseNode(s string) (node Node, err error) {
node
=
Node
{
Addr
:
u
.
Host
,
Host
:
u
.
Host
,
Remote
:
strings
.
Trim
(
u
.
EscapedPath
(),
"/"
),
Values
:
u
.
Query
(),
User
:
u
.
User
,
...
...
obfs.go
View file @
da30584d
...
...
@@ -35,7 +35,7 @@ func (tr *obfsHTTPTransporter) Handshake(conn net.Conn, options ...HandshakeOpti
for
_
,
option
:=
range
options
{
option
(
opts
)
}
return
&
obfsHTTPConn
{
Conn
:
conn
},
nil
return
&
obfsHTTPConn
{
Conn
:
conn
,
host
:
opts
.
Host
},
nil
}
type
obfsHTTPListener
struct
{
...
...
@@ -66,6 +66,7 @@ func (l *obfsHTTPListener) Accept() (net.Conn, error) {
type
obfsHTTPConn
struct
{
net
.
Conn
host
string
request
*
http
.
Request
response
*
http
.
Response
rbuf
[]
byte
...
...
@@ -151,7 +152,7 @@ func (c *obfsHTTPConn) clientHandshake() (err error) {
Method
:
http
.
MethodGet
,
ProtoMajor
:
1
,
ProtoMinor
:
1
,
URL
:
&
url
.
URL
{
Scheme
:
"http"
,
Host
:
"www.baidu.com"
},
URL
:
&
url
.
URL
{
Scheme
:
"http"
,
Host
:
c
.
host
},
Header
:
make
(
http
.
Header
),
}
r
.
Header
.
Set
(
"Connection"
,
"keep-alive"
)
...
...
ws.go
View file @
da30584d
...
...
@@ -129,7 +129,7 @@ func (tr *wsTransporter) Handshake(conn net.Conn, options ...HandshakeOption) (n
if
opts
.
WSOptions
!=
nil
{
wsOptions
=
opts
.
WSOptions
}
url
:=
url
.
URL
{
Scheme
:
"ws"
,
Host
:
opts
.
Addr
,
Path
:
"/ws"
}
url
:=
url
.
URL
{
Scheme
:
"ws"
,
Host
:
opts
.
Host
,
Path
:
"/ws"
}
return
websocketClientConn
(
url
.
String
(),
conn
,
nil
,
wsOptions
)
}
...
...
@@ -210,7 +210,7 @@ func (tr *mwsTransporter) initSession(addr string, conn net.Conn, opts *Handshak
if
opts
.
WSOptions
!=
nil
{
wsOptions
=
opts
.
WSOptions
}
url
:=
url
.
URL
{
Scheme
:
"ws"
,
Host
:
opts
.
Addr
,
Path
:
"/ws"
}
url
:=
url
.
URL
{
Scheme
:
"ws"
,
Host
:
opts
.
Host
,
Path
:
"/ws"
}
conn
,
err
:=
websocketClientConn
(
url
.
String
(),
conn
,
nil
,
wsOptions
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -252,7 +252,7 @@ func (tr *wssTransporter) Handshake(conn net.Conn, options ...HandshakeOption) (
if
opts
.
TLSConfig
==
nil
{
opts
.
TLSConfig
=
&
tls
.
Config
{
InsecureSkipVerify
:
true
}
}
url
:=
url
.
URL
{
Scheme
:
"wss"
,
Host
:
opts
.
Addr
,
Path
:
"/ws"
}
url
:=
url
.
URL
{
Scheme
:
"wss"
,
Host
:
opts
.
Host
,
Path
:
"/ws"
}
return
websocketClientConn
(
url
.
String
(),
conn
,
opts
.
TLSConfig
,
wsOptions
)
}
...
...
@@ -337,7 +337,7 @@ func (tr *mwssTransporter) initSession(addr string, conn net.Conn, opts *Handsha
if
tlsConfig
==
nil
{
tlsConfig
=
&
tls
.
Config
{
InsecureSkipVerify
:
true
}
}
url
:=
url
.
URL
{
Scheme
:
"wss"
,
Host
:
opts
.
Addr
,
Path
:
"/ws"
}
url
:=
url
.
URL
{
Scheme
:
"wss"
,
Host
:
opts
.
Host
,
Path
:
"/ws"
}
conn
,
err
:=
websocketClientConn
(
url
.
String
(),
conn
,
tlsConfig
,
wsOptions
)
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