1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-30 07:46:41 -04:00

refine proto settings

This commit is contained in:
Darien Raymond 2017-01-01 21:19:12 +01:00
parent 2a52ae9e96
commit 58ae7e4967
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
8 changed files with 15 additions and 20 deletions

View File

@ -5,11 +5,11 @@ import (
"v2ray.com/core/transport/internet" "v2ray.com/core/transport/internet"
) )
func (v *ConnectionReuse) IsEnabled() bool { func (v *Config) IsConnectionReuse() bool {
if v == nil { if v == nil || v.ConnectionReuse == nil {
return true return true
} }
return v.Enable return v.ConnectionReuse.Enable
} }
func init() { func init() {

View File

@ -39,7 +39,7 @@ func NewConnection(id internal.ConnectionId, conn net.Conn, manager ConnectionMa
id: id, id: id,
conn: conn, conn: conn,
listener: manager, listener: manager,
reusable: config.ConnectionReuse.IsEnabled(), reusable: config.IsConnectionReuse(),
config: config, config: config,
} }
} }
@ -97,7 +97,7 @@ func (v *Connection) SetReusable(reusable bool) {
} }
func (v *Connection) Reusable() bool { func (v *Connection) Reusable() bool {
return v.config.ConnectionReuse.IsEnabled() && v.reusable return v.config.IsConnectionReuse() && v.reusable
} }
func (v *Connection) SysFd() (int, error) { func (v *Connection) SysFd() (int, error) {

View File

@ -3,6 +3,7 @@ package tcp
import ( import (
"crypto/tls" "crypto/tls"
"net" "net"
"v2ray.com/core/common/errors" "v2ray.com/core/common/errors"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"
@ -28,7 +29,7 @@ func Dial(src v2net.Address, dest v2net.Destination, options internet.DialerOpti
id := internal.NewConnectionId(src, dest) id := internal.NewConnectionId(src, dest)
var conn net.Conn var conn net.Conn
if dest.Network == v2net.Network_TCP && tcpSettings.ConnectionReuse.IsEnabled() { if dest.Network == v2net.Network_TCP && tcpSettings.IsConnectionReuse() {
conn = globalCache.Get(id) conn = globalCache.Get(id)
} }
if conn == nil { if conn == nil {

View File

@ -5,11 +5,11 @@ import (
"v2ray.com/core/transport/internet" "v2ray.com/core/transport/internet"
) )
func (v *ConnectionReuse) IsEnabled() bool { func (c *Config) IsConnectionReuse() bool {
if v == nil { if c == nil || c.ConnectionReuse == nil {
return false return false
} }
return v.Enable return c.ConnectionReuse.Enable
} }
func init() { func init() {

View File

@ -29,7 +29,7 @@ func NewConnection(dest string, conn *wsconn, manager ConnectionManager, config
dest: dest, dest: dest,
conn: conn, conn: conn,
listener: manager, listener: manager,
reusable: config.ConnectionReuse.IsEnabled(), reusable: config.IsConnectionReuse(),
config: config, config: config,
} }
} }
@ -83,14 +83,11 @@ func (v *Connection) SetWriteDeadline(t time.Time) error {
} }
func (v *Connection) SetReusable(reusable bool) { func (v *Connection) SetReusable(reusable bool) {
if !v.config.ConnectionReuse.IsEnabled() {
return
}
v.reusable = reusable v.reusable = reusable
} }
func (v *Connection) Reusable() bool { func (v *Connection) Reusable() bool {
return v.reusable return v.config.IsConnectionReuse() && v.reusable
} }
func (v *Connection) SysFd() (int, error) { func (v *Connection) SysFd() (int, error) {

View File

@ -28,7 +28,7 @@ func Dial(src v2net.Address, dest v2net.Destination, options internet.DialerOpti
id := src.String() + "-" + dest.NetAddr() id := src.String() + "-" + dest.NetAddr()
var conn *wsconn var conn *wsconn
if dest.Network == v2net.Network_TCP && wsSettings.ConnectionReuse.IsEnabled() { if dest.Network == v2net.Network_TCP && wsSettings.IsConnectionReuse() {
connt := globalCache.Get(id) connt := globalCache.Get(id)
if connt != nil { if connt != nil {
conn = connt.(*wsconn) conn = connt.(*wsconn)

View File

@ -1,4 +1,4 @@
/*Package ws implements Websocket transport /*Package websocket implements Websocket transport
Websocket transport implements a HTTP(S) compliable, surveillance proof transport method with plausible deniability. Websocket transport implements a HTTP(S) compliable, surveillance proof transport method with plausible deniability.

View File

@ -159,13 +159,10 @@ func (ws *wsconn) setup() {
} }
func (ws *wsconn) Reusable() bool { func (ws *wsconn) Reusable() bool {
return ws.reusable && !ws.connClosing return ws.config.IsConnectionReuse() && ws.reusable && !ws.connClosing
} }
func (ws *wsconn) SetReusable(reusable bool) { func (ws *wsconn) SetReusable(reusable bool) {
if !ws.config.ConnectionReuse.IsEnabled() {
return
}
ws.reusable = reusable ws.reusable = reusable
} }