From 58ae7e4967449ea1a3608c95e8c1e3c59c609b91 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Sun, 1 Jan 2017 21:19:12 +0100 Subject: [PATCH] refine proto settings --- transport/internet/tcp/config.go | 6 +++--- transport/internet/tcp/connection.go | 4 ++-- transport/internet/tcp/dialer.go | 3 ++- transport/internet/websocket/config.go | 6 +++--- transport/internet/websocket/connection.go | 7 ++----- transport/internet/websocket/dialer.go | 2 +- transport/internet/websocket/ws.go | 2 +- transport/internet/websocket/wsconn.go | 5 +---- 8 files changed, 15 insertions(+), 20 deletions(-) diff --git a/transport/internet/tcp/config.go b/transport/internet/tcp/config.go index 0f2eb8b4..2f2b1344 100644 --- a/transport/internet/tcp/config.go +++ b/transport/internet/tcp/config.go @@ -5,11 +5,11 @@ import ( "v2ray.com/core/transport/internet" ) -func (v *ConnectionReuse) IsEnabled() bool { - if v == nil { +func (v *Config) IsConnectionReuse() bool { + if v == nil || v.ConnectionReuse == nil { return true } - return v.Enable + return v.ConnectionReuse.Enable } func init() { diff --git a/transport/internet/tcp/connection.go b/transport/internet/tcp/connection.go index 043052a9..37e98dd9 100644 --- a/transport/internet/tcp/connection.go +++ b/transport/internet/tcp/connection.go @@ -39,7 +39,7 @@ func NewConnection(id internal.ConnectionId, conn net.Conn, manager ConnectionMa id: id, conn: conn, listener: manager, - reusable: config.ConnectionReuse.IsEnabled(), + reusable: config.IsConnectionReuse(), config: config, } } @@ -97,7 +97,7 @@ func (v *Connection) SetReusable(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) { diff --git a/transport/internet/tcp/dialer.go b/transport/internet/tcp/dialer.go index 11473d67..7f4696a5 100644 --- a/transport/internet/tcp/dialer.go +++ b/transport/internet/tcp/dialer.go @@ -3,6 +3,7 @@ package tcp import ( "crypto/tls" "net" + "v2ray.com/core/common/errors" "v2ray.com/core/common/log" 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) 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) } if conn == nil { diff --git a/transport/internet/websocket/config.go b/transport/internet/websocket/config.go index 0a419679..01ee1b6d 100644 --- a/transport/internet/websocket/config.go +++ b/transport/internet/websocket/config.go @@ -5,11 +5,11 @@ import ( "v2ray.com/core/transport/internet" ) -func (v *ConnectionReuse) IsEnabled() bool { - if v == nil { +func (c *Config) IsConnectionReuse() bool { + if c == nil || c.ConnectionReuse == nil { return false } - return v.Enable + return c.ConnectionReuse.Enable } func init() { diff --git a/transport/internet/websocket/connection.go b/transport/internet/websocket/connection.go index 4d4aa247..5be16ae4 100644 --- a/transport/internet/websocket/connection.go +++ b/transport/internet/websocket/connection.go @@ -29,7 +29,7 @@ func NewConnection(dest string, conn *wsconn, manager ConnectionManager, config dest: dest, conn: conn, listener: manager, - reusable: config.ConnectionReuse.IsEnabled(), + reusable: config.IsConnectionReuse(), config: config, } } @@ -83,14 +83,11 @@ func (v *Connection) SetWriteDeadline(t time.Time) error { } func (v *Connection) SetReusable(reusable bool) { - if !v.config.ConnectionReuse.IsEnabled() { - return - } v.reusable = reusable } func (v *Connection) Reusable() bool { - return v.reusable + return v.config.IsConnectionReuse() && v.reusable } func (v *Connection) SysFd() (int, error) { diff --git a/transport/internet/websocket/dialer.go b/transport/internet/websocket/dialer.go index 10155e71..c7a3987b 100644 --- a/transport/internet/websocket/dialer.go +++ b/transport/internet/websocket/dialer.go @@ -28,7 +28,7 @@ func Dial(src v2net.Address, dest v2net.Destination, options internet.DialerOpti id := src.String() + "-" + dest.NetAddr() var conn *wsconn - if dest.Network == v2net.Network_TCP && wsSettings.ConnectionReuse.IsEnabled() { + if dest.Network == v2net.Network_TCP && wsSettings.IsConnectionReuse() { connt := globalCache.Get(id) if connt != nil { conn = connt.(*wsconn) diff --git a/transport/internet/websocket/ws.go b/transport/internet/websocket/ws.go index 56bc5413..58deb6cf 100644 --- a/transport/internet/websocket/ws.go +++ b/transport/internet/websocket/ws.go @@ -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. diff --git a/transport/internet/websocket/wsconn.go b/transport/internet/websocket/wsconn.go index 8f07a53f..57b302c7 100644 --- a/transport/internet/websocket/wsconn.go +++ b/transport/internet/websocket/wsconn.go @@ -159,13 +159,10 @@ func (ws *wsconn) setup() { } func (ws *wsconn) Reusable() bool { - return ws.reusable && !ws.connClosing + return ws.config.IsConnectionReuse() && ws.reusable && !ws.connClosing } func (ws *wsconn) SetReusable(reusable bool) { - if !ws.config.ConnectionReuse.IsEnabled() { - return - } ws.reusable = reusable }