2015-10-29 18:41:37 -04:00
|
|
|
package json
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"github.com/v2ray/v2ray-core/common/log"
|
2015-10-30 17:42:24 -04:00
|
|
|
proxyconfig "github.com/v2ray/v2ray-core/proxy/common/config"
|
|
|
|
proxyjson "github.com/v2ray/v2ray-core/proxy/common/config/json"
|
2015-10-29 18:41:37 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type ConnectionConfig struct {
|
2015-10-30 17:42:24 -04:00
|
|
|
ProtocolString string `json:"protocol"`
|
|
|
|
SettingsMessage json.RawMessage `json:"settings"`
|
|
|
|
Type proxyconfig.Type `json:"-"`
|
2015-10-29 18:41:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ConnectionConfig) Protocol() string {
|
|
|
|
return c.ProtocolString
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ConnectionConfig) Settings() interface{} {
|
2015-10-30 17:42:24 -04:00
|
|
|
configObj := proxyjson.CreateConfig(c.Protocol(), c.Type)
|
|
|
|
if configObj == nil {
|
2015-10-29 18:41:37 -04:00
|
|
|
panic("Unknown protocol " + c.Protocol())
|
|
|
|
}
|
|
|
|
err := json.Unmarshal(c.SettingsMessage, configObj)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("Unable to parse connection config: %v", err)
|
|
|
|
panic("Failed to parse connection config.")
|
|
|
|
}
|
|
|
|
return configObj
|
|
|
|
}
|