Beispiel #1
0
func (v *VMessInboundConfig) Build() (*serial.TypedMessage, error) {
	config := new(inbound.Config)

	if v.Defaults != nil {
		config.Default = v.Defaults.Build()
	}

	if v.DetourConfig != nil {
		config.Detour = v.DetourConfig.Build()
	} else if v.Features != nil && v.Features.Detour != nil {
		config.Detour = v.Features.Detour.Build()
	}

	config.User = make([]*protocol.User, len(v.Users))
	for idx, rawData := range v.Users {
		user := new(protocol.User)
		if err := json.Unmarshal(rawData, user); err != nil {
			return nil, errors.Base(err).Message("Invalid VMess user.")
		}
		account := new(VMessAccount)
		if err := json.Unmarshal(rawData, account); err != nil {
			return nil, errors.Base(err).Message("Invalid VMess user.")
		}
		user.Account = serial.ToTypedMessage(account.Build())
		config.User[idx] = user
	}

	return serial.ToTypedMessage(config), nil
}
Beispiel #2
0
func (this *VMessInboundConfig) Build() (*loader.TypedSettings, error) {
	config := new(inbound.Config)

	if this.Defaults != nil {
		config.Default = this.Defaults.Build()
	}

	if this.DetourConfig != nil {
		config.Detour = this.DetourConfig.Build()
	} else if this.Features != nil && this.Features.Detour != nil {
		config.Detour = this.Features.Detour.Build()
	}

	config.User = make([]*protocol.User, len(this.Users))
	for idx, rawData := range this.Users {
		user := new(protocol.User)
		if err := json.Unmarshal(rawData, user); err != nil {
			return nil, errors.New("VMess|Inbound: Invalid user: "******"VMess|Inbound: Invalid user: " + err.Error())
		}
		user.Account = loader.NewTypedSettings(account.Build())
		config.User[idx] = user
	}

	return loader.NewTypedSettings(config), nil
}