Pārlūkot izejas kodu

refine proto settings

Darien Raymond 8 gadi atpakaļ
vecāks
revīzija
58ae7e4967

+ 3 - 3
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() {

+ 2 - 2
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) {

+ 2 - 1
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 {

+ 3 - 3
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() {

+ 2 - 5
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) {

+ 1 - 1
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)

+ 1 - 1
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.
 

+ 1 - 4
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
 }