func (this *ShadowsocksServerConfig) Build() (*loader.TypedSettings, error) { config := new(shadowsocks.ServerConfig) config.UdpEnabled = this.UDP if len(this.Password) == 0 { return nil, errors.New("Shadowsocks password is not specified.") } account := &shadowsocks.Account{ Password: this.Password, Ota: shadowsocks.Account_Auto, } cipher := strings.ToLower(this.Cipher) switch cipher { case "aes-256-cfb": account.CipherType = shadowsocks.CipherType_AES_256_CFB case "aes-128-cfb": account.CipherType = shadowsocks.CipherType_AES_128_CFB case "chacha20": account.CipherType = shadowsocks.CipherType_CHACHA20 case "chacha20-ietf": account.CipherType = shadowsocks.CipherType_CHACHA20_IEFT default: return nil, errors.New("Unknown cipher method: " + cipher) } config.User = &protocol.User{ Email: this.Email, Level: uint32(this.Level), Account: loader.NewTypedSettings(account), } return loader.NewTypedSettings(config), nil }
func (v *ShadowsocksServerConfig) Build() (*serial.TypedMessage, error) { config := new(shadowsocks.ServerConfig) config.UdpEnabled = v.UDP if len(v.Password) == 0 { return nil, errors.New("Shadowsocks password is not specified.") } account := &shadowsocks.Account{ Password: v.Password, Ota: shadowsocks.Account_Auto, } if v.OTA != nil { if *v.OTA { account.Ota = shadowsocks.Account_Enabled } else { account.Ota = shadowsocks.Account_Disabled } } cipher := strings.ToLower(v.Cipher) switch cipher { case "aes-256-cfb": account.CipherType = shadowsocks.CipherType_AES_256_CFB case "aes-128-cfb": account.CipherType = shadowsocks.CipherType_AES_128_CFB case "chacha20": account.CipherType = shadowsocks.CipherType_CHACHA20 case "chacha20-ietf": account.CipherType = shadowsocks.CipherType_CHACHA20_IEFT default: return nil, errors.New("Unknown cipher method: " + cipher) } config.User = &protocol.User{ Email: v.Email, Level: uint32(v.Level), Account: serial.ToTypedMessage(account), } return serial.ToTypedMessage(config), nil }