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
791bd63d
Commit
791bd63d
authored
Jul 11, 2017
by
rui.zheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix websocket config
parent
2a2deb02
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
21 deletions
+59
-21
conn.go
conn.go
+31
-10
ws.go
ws.go
+28
-11
No files found.
conn.go
View file @
791bd63d
...
@@ -6,10 +6,6 @@ import (
...
@@ -6,10 +6,6 @@ import (
"encoding/base64"
"encoding/base64"
"errors"
"errors"
"fmt"
"fmt"
"github.com/ginuerzh/gosocks4"
"github.com/ginuerzh/gosocks5"
"github.com/golang/glog"
ss
"github.com/shadowsocks/shadowsocks-go/shadowsocks"
"net"
"net"
"net/http"
"net/http"
"net/http/httputil"
"net/http/httputil"
...
@@ -18,6 +14,11 @@ import (
...
@@ -18,6 +14,11 @@ import (
"strings"
"strings"
"sync"
"sync"
"time"
"time"
"github.com/ginuerzh/gosocks4"
"github.com/ginuerzh/gosocks5"
"github.com/golang/glog"
ss
"github.com/shadowsocks/shadowsocks-go/shadowsocks"
)
)
type
ProxyConn
struct
{
type
ProxyConn
struct
{
...
@@ -57,20 +58,40 @@ func (c *ProxyConn) handshake() error {
...
@@ -57,20 +58,40 @@ func (c *ProxyConn) handshake() error {
switch
c
.
Node
.
Transport
{
switch
c
.
Node
.
Transport
{
case
"ws"
:
// websocket connection
case
"ws"
:
// websocket connection
rbuf
,
_
:=
strconv
.
Atoi
(
c
.
Node
.
Get
(
"rbuf"
))
wbuf
,
_
:=
strconv
.
Atoi
(
c
.
Node
.
Get
(
"wbuf"
))
comp
:=
c
.
Node
.
getBool
(
"compression"
)
opt
:=
WSOptions
{
ReadBufferSize
:
rbuf
,
WriteBufferSize
:
wbuf
,
HandshakeTimeout
:
DialTimeout
,
EnableCompression
:
comp
,
}
u
:=
url
.
URL
{
Scheme
:
"ws"
,
Host
:
c
.
Node
.
Addr
,
Path
:
"/ws"
}
u
:=
url
.
URL
{
Scheme
:
"ws"
,
Host
:
c
.
Node
.
Addr
,
Path
:
"/ws"
}
conn
,
err
:=
WebsocketClientConn
(
u
.
String
(),
c
.
conn
,
nil
)
conn
,
err
:=
WebsocketClientConn
(
u
.
String
(),
c
.
conn
,
&
opt
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
c
.
conn
=
conn
c
.
conn
=
conn
case
"wss"
:
// websocket security
case
"wss"
:
// websocket security
tlsUsed
=
true
tlsUsed
=
true
u
:=
url
.
URL
{
Scheme
:
"wss"
,
Host
:
c
.
Node
.
Addr
,
Path
:
"/ws"
}
config
:=
&
tls
.
Config
{
rbuf
,
_
:=
strconv
.
Atoi
(
c
.
Node
.
Get
(
"rbuf"
))
wbuf
,
_
:=
strconv
.
Atoi
(
c
.
Node
.
Get
(
"wbuf"
))
comp
:=
c
.
Node
.
getBool
(
"compression"
)
opt
:=
WSOptions
{
ReadBufferSize
:
rbuf
,
WriteBufferSize
:
wbuf
,
HandshakeTimeout
:
DialTimeout
,
EnableCompression
:
comp
,
TLSConfig
:
&
tls
.
Config
{
InsecureSkipVerify
:
c
.
Node
.
insecureSkipVerify
(),
InsecureSkipVerify
:
c
.
Node
.
insecureSkipVerify
(),
ServerName
:
c
.
Node
.
serverName
,
ServerName
:
c
.
Node
.
serverName
,
},
}
}
conn
,
err
:=
WebsocketClientConn
(
u
.
String
(),
c
.
conn
,
config
)
u
:=
url
.
URL
{
Scheme
:
"wss"
,
Host
:
c
.
Node
.
Addr
,
Path
:
"/ws"
}
conn
,
err
:=
WebsocketClientConn
(
u
.
String
(),
c
.
conn
,
&
opt
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
ws.go
View file @
791bd63d
...
@@ -2,12 +2,14 @@ package gost
...
@@ -2,12 +2,14 @@ package gost
import
(
import
(
"crypto/tls"
"crypto/tls"
"github.com/golang/glog"
"gopkg.in/gorilla/websocket.v1"
"net"
"net"
"net/http"
"net/http"
"net/http/httputil"
"net/http/httputil"
"strconv"
"time"
"time"
"github.com/golang/glog"
"gopkg.in/gorilla/websocket.v1"
)
)
type
WebsocketServer
struct
{
type
WebsocketServer
struct
{
...
@@ -18,14 +20,18 @@ type WebsocketServer struct {
...
@@ -18,14 +20,18 @@ type WebsocketServer struct {
}
}
func
NewWebsocketServer
(
base
*
ProxyServer
)
*
WebsocketServer
{
func
NewWebsocketServer
(
base
*
ProxyServer
)
*
WebsocketServer
{
rbuf
,
_
:=
strconv
.
Atoi
(
base
.
Node
.
Get
(
"rbuf"
))
wbuf
,
_
:=
strconv
.
Atoi
(
base
.
Node
.
Get
(
"wbuf"
))
comp
:=
base
.
Node
.
getBool
(
"compression"
)
return
&
WebsocketServer
{
return
&
WebsocketServer
{
Addr
:
base
.
Node
.
Addr
,
Addr
:
base
.
Node
.
Addr
,
Base
:
base
,
Base
:
base
,
upgrader
:
websocket
.
Upgrader
{
upgrader
:
websocket
.
Upgrader
{
ReadBufferSize
:
1024
,
ReadBufferSize
:
rbuf
,
WriteBufferSize
:
1024
,
WriteBufferSize
:
wbuf
,
CheckOrigin
:
func
(
r
*
http
.
Request
)
bool
{
return
true
},
CheckOrigin
:
func
(
r
*
http
.
Request
)
bool
{
return
true
},
EnableCompression
:
true
,
EnableCompression
:
comp
,
},
},
}
}
}
}
...
@@ -68,18 +74,29 @@ func (s *WebsocketServer) ListenAndServeTLS(config *tls.Config) error {
...
@@ -68,18 +74,29 @@ func (s *WebsocketServer) ListenAndServeTLS(config *tls.Config) error {
return
server
.
ListenAndServeTLS
(
""
,
""
)
return
server
.
ListenAndServeTLS
(
""
,
""
)
}
}
type
WSOptions
struct
{
ReadBufferSize
int
WriteBufferSize
int
HandshakeTimeout
time
.
Duration
EnableCompression
bool
TLSConfig
*
tls
.
Config
}
type
WebsocketConn
struct
{
type
WebsocketConn
struct
{
conn
*
websocket
.
Conn
conn
*
websocket
.
Conn
rb
[]
byte
rb
[]
byte
}
}
func
WebsocketClientConn
(
url
string
,
conn
net
.
Conn
,
config
*
tls
.
Config
)
(
*
WebsocketConn
,
error
)
{
func
WebsocketClientConn
(
url
string
,
conn
net
.
Conn
,
options
*
WSOptions
)
(
*
WebsocketConn
,
error
)
{
if
options
==
nil
{
options
=
&
WSOptions
{}
}
dialer
:=
websocket
.
Dialer
{
dialer
:=
websocket
.
Dialer
{
ReadBufferSize
:
1024
,
ReadBufferSize
:
options
.
ReadBufferSize
,
WriteBufferSize
:
1024
,
WriteBufferSize
:
options
.
WriteBufferSize
,
TLSClientConfig
:
c
onfig
,
TLSClientConfig
:
options
.
TLSC
onfig
,
HandshakeTimeout
:
Dial
Timeout
,
HandshakeTimeout
:
options
.
Handshake
Timeout
,
EnableCompression
:
true
,
EnableCompression
:
options
.
EnableCompression
,
NetDial
:
func
(
net
,
addr
string
)
(
net
.
Conn
,
error
)
{
NetDial
:
func
(
net
,
addr
string
)
(
net
.
Conn
,
error
)
{
return
conn
,
nil
return
conn
,
nil
},
},
...
...
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