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
7c7a51ec
Commit
7c7a51ec
authored
Jan 12, 2019
by
ginuerzh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ws supports user defined url path
parent
88efafca
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
9 deletions
+66
-9
cmd/gost/route.go
cmd/gost/route.go
+2
-1
ws.go
ws.go
+64
-8
No files found.
cmd/gost/route.go
View file @
7c7a51ec
...
@@ -109,6 +109,7 @@ func parseChainNode(ns string) (nodes []gost.Node, err error) {
...
@@ -109,6 +109,7 @@ func parseChainNode(ns string) (nodes []gost.Node, err error) {
wsOpts
.
ReadBufferSize
=
node
.
GetInt
(
"rbuf"
)
wsOpts
.
ReadBufferSize
=
node
.
GetInt
(
"rbuf"
)
wsOpts
.
WriteBufferSize
=
node
.
GetInt
(
"wbuf"
)
wsOpts
.
WriteBufferSize
=
node
.
GetInt
(
"wbuf"
)
wsOpts
.
UserAgent
=
node
.
Get
(
"agent"
)
wsOpts
.
UserAgent
=
node
.
Get
(
"agent"
)
wsOpts
.
Path
=
node
.
Get
(
"path"
)
var
host
string
var
host
string
...
@@ -276,6 +277,7 @@ func (r *route) GenRouters() ([]router, error) {
...
@@ -276,6 +277,7 @@ func (r *route) GenRouters() ([]router, error) {
wsOpts
.
EnableCompression
=
node
.
GetBool
(
"compression"
)
wsOpts
.
EnableCompression
=
node
.
GetBool
(
"compression"
)
wsOpts
.
ReadBufferSize
=
node
.
GetInt
(
"rbuf"
)
wsOpts
.
ReadBufferSize
=
node
.
GetInt
(
"rbuf"
)
wsOpts
.
WriteBufferSize
=
node
.
GetInt
(
"wbuf"
)
wsOpts
.
WriteBufferSize
=
node
.
GetInt
(
"wbuf"
)
wsOpts
.
Path
=
node
.
Get
(
"path"
)
var
ln
gost
.
Listener
var
ln
gost
.
Listener
switch
node
.
Transport
{
switch
node
.
Transport
{
...
@@ -284,7 +286,6 @@ func (r *route) GenRouters() ([]router, error) {
...
@@ -284,7 +286,6 @@ func (r *route) GenRouters() ([]router, error) {
case
"mtls"
:
case
"mtls"
:
ln
,
err
=
gost
.
MTLSListener
(
node
.
Addr
,
tlsCfg
)
ln
,
err
=
gost
.
MTLSListener
(
node
.
Addr
,
tlsCfg
)
case
"ws"
:
case
"ws"
:
wsOpts
.
WriteBufferSize
=
node
.
GetInt
(
"wbuf"
)
ln
,
err
=
gost
.
WSListener
(
node
.
Addr
,
wsOpts
)
ln
,
err
=
gost
.
WSListener
(
node
.
Addr
,
wsOpts
)
case
"mws"
:
case
"mws"
:
ln
,
err
=
gost
.
MWSListener
(
node
.
Addr
,
wsOpts
)
ln
,
err
=
gost
.
MWSListener
(
node
.
Addr
,
wsOpts
)
...
...
ws.go
View file @
7c7a51ec
...
@@ -19,6 +19,10 @@ import (
...
@@ -19,6 +19,10 @@ import (
smux
"gopkg.in/xtaci/smux.v1"
smux
"gopkg.in/xtaci/smux.v1"
)
)
const
(
defaultWSPath
=
"/ws"
)
// WSOptions describes the options for websocket.
// WSOptions describes the options for websocket.
type
WSOptions
struct
{
type
WSOptions
struct
{
ReadBufferSize
int
ReadBufferSize
int
...
@@ -26,6 +30,7 @@ type WSOptions struct {
...
@@ -26,6 +30,7 @@ type WSOptions struct {
HandshakeTimeout
time
.
Duration
HandshakeTimeout
time
.
Duration
EnableCompression
bool
EnableCompression
bool
UserAgent
string
UserAgent
string
Path
string
}
}
type
wsTransporter
struct
{
type
wsTransporter
struct
{
...
@@ -49,7 +54,15 @@ func (tr *wsTransporter) Handshake(conn net.Conn, options ...HandshakeOption) (n
...
@@ -49,7 +54,15 @@ func (tr *wsTransporter) Handshake(conn net.Conn, options ...HandshakeOption) (n
if
opts
.
WSOptions
!=
nil
{
if
opts
.
WSOptions
!=
nil
{
wsOptions
=
opts
.
WSOptions
wsOptions
=
opts
.
WSOptions
}
}
url
:=
url
.
URL
{
Scheme
:
"ws"
,
Host
:
opts
.
Host
,
Path
:
"/ws"
}
if
wsOptions
==
nil
{
wsOptions
=
&
WSOptions
{}
}
path
:=
wsOptions
.
Path
if
path
==
""
{
path
=
defaultWSPath
}
url
:=
url
.
URL
{
Scheme
:
"ws"
,
Host
:
opts
.
Host
,
Path
:
path
}
return
websocketClientConn
(
url
.
String
(),
conn
,
nil
,
wsOptions
)
return
websocketClientConn
(
url
.
String
(),
conn
,
nil
,
wsOptions
)
}
}
...
@@ -148,7 +161,15 @@ func (tr *mwsTransporter) initSession(addr string, conn net.Conn, opts *Handshak
...
@@ -148,7 +161,15 @@ func (tr *mwsTransporter) initSession(addr string, conn net.Conn, opts *Handshak
if
opts
.
WSOptions
!=
nil
{
if
opts
.
WSOptions
!=
nil
{
wsOptions
=
opts
.
WSOptions
wsOptions
=
opts
.
WSOptions
}
}
url
:=
url
.
URL
{
Scheme
:
"ws"
,
Host
:
opts
.
Host
,
Path
:
"/ws"
}
if
wsOptions
==
nil
{
wsOptions
=
&
WSOptions
{}
}
path
:=
wsOptions
.
Path
if
path
==
""
{
path
=
defaultWSPath
}
url
:=
url
.
URL
{
Scheme
:
"ws"
,
Host
:
opts
.
Host
,
Path
:
path
}
conn
,
err
:=
websocketClientConn
(
url
.
String
(),
conn
,
nil
,
wsOptions
)
conn
,
err
:=
websocketClientConn
(
url
.
String
(),
conn
,
nil
,
wsOptions
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -187,10 +208,18 @@ func (tr *wssTransporter) Handshake(conn net.Conn, options ...HandshakeOption) (
...
@@ -187,10 +208,18 @@ func (tr *wssTransporter) Handshake(conn net.Conn, options ...HandshakeOption) (
if
opts
.
WSOptions
!=
nil
{
if
opts
.
WSOptions
!=
nil
{
wsOptions
=
opts
.
WSOptions
wsOptions
=
opts
.
WSOptions
}
}
if
wsOptions
==
nil
{
wsOptions
=
&
WSOptions
{}
}
if
opts
.
TLSConfig
==
nil
{
if
opts
.
TLSConfig
==
nil
{
opts
.
TLSConfig
=
&
tls
.
Config
{
InsecureSkipVerify
:
true
}
opts
.
TLSConfig
=
&
tls
.
Config
{
InsecureSkipVerify
:
true
}
}
}
url
:=
url
.
URL
{
Scheme
:
"wss"
,
Host
:
opts
.
Host
,
Path
:
"/ws"
}
path
:=
wsOptions
.
Path
if
path
==
""
{
path
=
defaultWSPath
}
url
:=
url
.
URL
{
Scheme
:
"wss"
,
Host
:
opts
.
Host
,
Path
:
path
}
return
websocketClientConn
(
url
.
String
(),
conn
,
opts
.
TLSConfig
,
wsOptions
)
return
websocketClientConn
(
url
.
String
(),
conn
,
opts
.
TLSConfig
,
wsOptions
)
}
}
...
@@ -288,11 +317,19 @@ func (tr *mwssTransporter) initSession(addr string, conn net.Conn, opts *Handsha
...
@@ -288,11 +317,19 @@ func (tr *mwssTransporter) initSession(addr string, conn net.Conn, opts *Handsha
if
opts
.
WSOptions
!=
nil
{
if
opts
.
WSOptions
!=
nil
{
wsOptions
=
opts
.
WSOptions
wsOptions
=
opts
.
WSOptions
}
}
if
wsOptions
==
nil
{
wsOptions
=
&
WSOptions
{}
}
tlsConfig
:=
opts
.
TLSConfig
tlsConfig
:=
opts
.
TLSConfig
if
tlsConfig
==
nil
{
if
tlsConfig
==
nil
{
tlsConfig
=
&
tls
.
Config
{
InsecureSkipVerify
:
true
}
tlsConfig
=
&
tls
.
Config
{
InsecureSkipVerify
:
true
}
}
}
url
:=
url
.
URL
{
Scheme
:
"wss"
,
Host
:
opts
.
Host
,
Path
:
"/ws"
}
path
:=
wsOptions
.
Path
if
path
==
""
{
path
=
defaultWSPath
}
url
:=
url
.
URL
{
Scheme
:
"wss"
,
Host
:
opts
.
Host
,
Path
:
path
}
conn
,
err
:=
websocketClientConn
(
url
.
String
(),
conn
,
tlsConfig
,
wsOptions
)
conn
,
err
:=
websocketClientConn
(
url
.
String
(),
conn
,
tlsConfig
,
wsOptions
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -338,8 +375,12 @@ func WSListener(addr string, options *WSOptions) (Listener, error) {
...
@@ -338,8 +375,12 @@ func WSListener(addr string, options *WSOptions) (Listener, error) {
errChan
:
make
(
chan
error
,
1
),
errChan
:
make
(
chan
error
,
1
),
}
}
path
:=
options
.
Path
if
path
==
""
{
path
=
defaultWSPath
}
mux
:=
http
.
NewServeMux
()
mux
:=
http
.
NewServeMux
()
mux
.
Handle
(
"/ws"
,
http
.
HandlerFunc
(
l
.
upgrade
))
mux
.
Handle
(
path
,
http
.
HandlerFunc
(
l
.
upgrade
))
l
.
srv
=
&
http
.
Server
{
l
.
srv
=
&
http
.
Server
{
Addr
:
addr
,
Addr
:
addr
,
Handler
:
mux
,
Handler
:
mux
,
...
@@ -431,8 +472,13 @@ func MWSListener(addr string, options *WSOptions) (Listener, error) {
...
@@ -431,8 +472,13 @@ func MWSListener(addr string, options *WSOptions) (Listener, error) {
errChan
:
make
(
chan
error
,
1
),
errChan
:
make
(
chan
error
,
1
),
}
}
path
:=
options
.
Path
if
path
==
""
{
path
=
defaultWSPath
}
mux
:=
http
.
NewServeMux
()
mux
:=
http
.
NewServeMux
()
mux
.
Handle
(
"/ws"
,
http
.
HandlerFunc
(
l
.
upgrade
))
mux
.
Handle
(
path
,
http
.
HandlerFunc
(
l
.
upgrade
))
l
.
srv
=
&
http
.
Server
{
l
.
srv
=
&
http
.
Server
{
Addr
:
addr
,
Addr
:
addr
,
Handler
:
mux
,
Handler
:
mux
,
...
@@ -551,8 +597,13 @@ func WSSListener(addr string, tlsConfig *tls.Config, options *WSOptions) (Listen
...
@@ -551,8 +597,13 @@ func WSSListener(addr string, tlsConfig *tls.Config, options *WSOptions) (Listen
tlsConfig
=
DefaultTLSConfig
tlsConfig
=
DefaultTLSConfig
}
}
path
:=
options
.
Path
if
path
==
""
{
path
=
defaultWSPath
}
mux
:=
http
.
NewServeMux
()
mux
:=
http
.
NewServeMux
()
mux
.
Handle
(
"/ws"
,
http
.
HandlerFunc
(
l
.
upgrade
))
mux
.
Handle
(
path
,
http
.
HandlerFunc
(
l
.
upgrade
))
l
.
srv
=
&
http
.
Server
{
l
.
srv
=
&
http
.
Server
{
Addr
:
addr
,
Addr
:
addr
,
TLSConfig
:
tlsConfig
,
TLSConfig
:
tlsConfig
,
...
@@ -612,8 +663,13 @@ func MWSSListener(addr string, tlsConfig *tls.Config, options *WSOptions) (Liste
...
@@ -612,8 +663,13 @@ func MWSSListener(addr string, tlsConfig *tls.Config, options *WSOptions) (Liste
tlsConfig
=
DefaultTLSConfig
tlsConfig
=
DefaultTLSConfig
}
}
path
:=
options
.
Path
if
path
==
""
{
path
=
defaultWSPath
}
mux
:=
http
.
NewServeMux
()
mux
:=
http
.
NewServeMux
()
mux
.
Handle
(
"/ws"
,
http
.
HandlerFunc
(
l
.
upgrade
))
mux
.
Handle
(
path
,
http
.
HandlerFunc
(
l
.
upgrade
))
l
.
srv
=
&
http
.
Server
{
l
.
srv
=
&
http
.
Server
{
Addr
:
addr
,
Addr
:
addr
,
TLSConfig
:
tlsConfig
,
TLSConfig
:
tlsConfig
,
...
...
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