Sfoglia il codice sorgente

Remove config type in connection settings()

V2Ray 10 anni fa
parent
commit
6e8425b23a
5 ha cambiato i file con 14 aggiunte e 11 eliminazioni
  1. 2 2
      app/point/point.go
  2. 1 1
      config/config.go
  3. 6 2
      config/json/json.go
  4. 4 5
      config/json/json_test.go
  5. 1 1
      testing/mocks/config.go

+ 2 - 2
app/point/point.go

@@ -27,7 +27,7 @@ func NewPoint(pConfig config.PointConfig) (*Point, error) {
 		log.Error("Unknown inbound connection handler factory %s", pConfig.InboundConfig().Protocol())
 		return nil, config.BadConfiguration
 	}
-	ichConfig := pConfig.InboundConfig().Settings(config.TypeInbound)
+	ichConfig := pConfig.InboundConfig().Settings()
 	ich, err := ichFactory.Create(vpoint, ichConfig)
 	if err != nil {
 		log.Error("Failed to create inbound connection handler: %v", err)
@@ -40,7 +40,7 @@ func NewPoint(pConfig config.PointConfig) (*Point, error) {
 		log.Error("Unknown outbound connection handler factory %s", pConfig.OutboundConfig().Protocol())
 		return nil, config.BadConfiguration
 	}
-	ochConfig := pConfig.OutboundConfig().Settings(config.TypeOutbound)
+	ochConfig := pConfig.OutboundConfig().Settings()
 	och, err := ochFactory.Create(ochConfig)
 	if err != nil {
 		log.Error("Failed to create outbound connection handler: %v", err)

+ 1 - 1
config/config.go

@@ -16,7 +16,7 @@ type ConnectionTag string
 
 type ConnectionConfig interface {
 	Protocol() string
-	Settings(configType Type) interface{}
+	Settings() interface{}
 }
 
 type LogConfig interface {

+ 6 - 2
config/json/json.go

@@ -12,14 +12,15 @@ import (
 type ConnectionConfig struct {
 	ProtocolString  string          `json:"protocol"`
 	SettingsMessage json.RawMessage `json:"settings"`
+	Type            config.Type     `json:"-"`
 }
 
 func (config *ConnectionConfig) Protocol() string {
 	return config.ProtocolString
 }
 
-func (config *ConnectionConfig) Settings(configType config.Type) interface{} {
-	creator, found := configCache[getConfigKey(config.Protocol(), configType)]
+func (config *ConnectionConfig) Settings() interface{} {
+	creator, found := configCache[getConfigKey(config.Protocol(), config.Type)]
 	if !found {
 		panic("Unknown protocol " + config.Protocol())
 	}
@@ -88,5 +89,8 @@ func LoadConfig(file string) (*Config, error) {
 		return nil, err
 	}
 
+	jsonConfig.InboundConfigValue.Type = config.TypeInbound
+	jsonConfig.OutboundConfigValue.Type = config.TypeOutbound
+
 	return jsonConfig, err
 }

+ 4 - 5
config/json/json_test.go

@@ -4,7 +4,6 @@ import (
 	"path/filepath"
 	"testing"
 
-	"github.com/v2ray/v2ray-core/config"
 	"github.com/v2ray/v2ray-core/config/json"
 	_ "github.com/v2ray/v2ray-core/proxy/freedom/config/json"
 	_ "github.com/v2ray/v2ray-core/proxy/socks/config/json"
@@ -27,10 +26,10 @@ func TestClientSampleConfig(t *testing.T) {
 	assert.Pointer(pointConfig.OutboundConfig()).IsNotNil()
 
 	assert.String(pointConfig.InboundConfig().Protocol()).Equals("socks")
-	assert.Pointer(pointConfig.InboundConfig().Settings(config.TypeInbound)).IsNotNil()
+	assert.Pointer(pointConfig.InboundConfig().Settings()).IsNotNil()
 
 	assert.String(pointConfig.OutboundConfig().Protocol()).Equals("vmess")
-	assert.Pointer(pointConfig.OutboundConfig().Settings(config.TypeOutbound)).IsNotNil()
+	assert.Pointer(pointConfig.OutboundConfig().Settings()).IsNotNil()
 }
 
 func TestServerSampleConfig(t *testing.T) {
@@ -47,8 +46,8 @@ func TestServerSampleConfig(t *testing.T) {
 	assert.Pointer(pointConfig.OutboundConfig()).IsNotNil()
 
 	assert.String(pointConfig.InboundConfig().Protocol()).Equals("vmess")
-	assert.Pointer(pointConfig.InboundConfig().Settings(config.TypeInbound)).IsNotNil()
+	assert.Pointer(pointConfig.InboundConfig().Settings()).IsNotNil()
 
 	assert.String(pointConfig.OutboundConfig().Protocol()).Equals("freedom")
-	assert.Pointer(pointConfig.OutboundConfig().Settings(config.TypeOutbound)).IsNotNil()
+	assert.Pointer(pointConfig.OutboundConfig().Settings()).IsNotNil()
 }

+ 1 - 1
testing/mocks/config.go

@@ -13,7 +13,7 @@ func (config *ConnectionConfig) Protocol() string {
 	return config.ProtocolValue
 }
 
-func (config *ConnectionConfig) Settings(config.Type) interface{} {
+func (config *ConnectionConfig) Settings() interface{} {
 	return config.SettingsValue
 }