コード例 #1
0
ファイル: socks.go プロジェクト: v2ray/v2ray-core
func (v *SocksClientConfig) Build() (*serial.TypedMessage, error) {
	config := new(socks.ClientConfig)
	config.Server = make([]*protocol.ServerEndpoint, len(v.Servers))
	for idx, serverConfig := range v.Servers {
		server := &protocol.ServerEndpoint{
			Address: serverConfig.Address.Build(),
			Port:    uint32(serverConfig.Port),
		}
		for _, rawUser := range serverConfig.Users {
			user := new(protocol.User)
			if err := json.Unmarshal(rawUser, user); err != nil {
				return nil, errors.Base(err).Message("Socks|Client: Failed to parse user.")
			}
			account := new(SocksAccount)
			if err := json.Unmarshal(rawUser, account); err != nil {
				return nil, errors.Base(err).Message("Socks|Client: Failed to parse socks account.")
			}
			user.Account = serial.ToTypedMessage(account.Build())
			server.User = append(server.User, user)
		}
		config.Server[idx] = server
	}
	return serial.ToTypedMessage(config), nil
}
コード例 #2
0
ファイル: socks.go プロジェクト: xyz12810/v2ray-core
func (this *SocksClientConfig) Build() (*loader.TypedSettings, error) {
	config := new(socks.ClientConfig)
	config.Server = make([]*protocol.ServerEndpoint, len(this.Servers))
	for idx, serverConfig := range this.Servers {
		server := &protocol.ServerEndpoint{
			Address: serverConfig.Address.Build(),
			Port:    uint32(serverConfig.Port),
		}
		for _, rawUser := range serverConfig.Users {
			user := new(protocol.User)
			if err := json.Unmarshal(rawUser, user); err != nil {
				return nil, errors.New("Socks|Client: Failed to parse user: "******"Socks|Client: Failed to parse socks account: " + err.Error())
			}
			user.Account = loader.NewTypedSettings(account.Build())
			server.User = append(server.User, user)
		}
		config.Server[idx] = server
	}
	return loader.NewTypedSettings(config), nil
}