aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/config.h
blob: df1ccb75263722c12589e6180694948937e3fe35 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include <zencore/zencore.h>
#include <zenhttp/httpserver.h>
#include <filesystem>
#include <string>
#include <vector>

struct ZenUpstreamJupiterConfig
{
	std::string Name;
	std::string Url;
	std::string OAuthUrl;
	std::string OAuthClientId;
	std::string OAuthClientSecret;
	std::string OpenIdProvider;
	std::string AccessToken;
	std::string Namespace;
	std::string DdcNamespace;
};

struct ZenUpstreamHordeConfig
{
	std::string Name;
	std::string Url;
	std::string OAuthUrl;
	std::string OAuthClientId;
	std::string OAuthClientSecret;
	std::string OpenIdProvider;
	std::string AccessToken;

	std::string StorageUrl;
	std::string StorageOAuthUrl;
	std::string StorageOAuthClientId;
	std::string StorageOAuthClientSecret;
	std::string StorageOpenIdProvider;
	std::string StorageAccessToken;

	std::string Cluster;
	std::string Namespace;
};

struct ZenUpstreamZenConfig
{
	std::string				 Name;
	std::vector<std::string> Urls;
	std::vector<std::string> Dns;
};

enum class UpstreamCachePolicy : uint8_t
{
	Disabled  = 0,
	Read	  = 1 << 0,
	Write	  = 1 << 1,
	ReadWrite = Read | Write
};

struct ZenUpstreamCacheConfig
{
	ZenUpstreamJupiterConfig JupiterConfig;
	ZenUpstreamHordeConfig	 HordeConfig;
	ZenUpstreamZenConfig	 ZenConfig;
	int32_t					 UpstreamThreadCount		= 4;
	int32_t					 ConnectTimeoutMilliseconds = 5000;
	int32_t					 TimeoutMilliseconds		= 0;
	UpstreamCachePolicy		 CachePolicy				= UpstreamCachePolicy::ReadWrite;
};

struct ZenCacheEvictionPolicy
{
	int32_t MaxDurationSeconds = 24 * 60 * 60;
};

struct ZenProjectStoreEvictionPolicy
{
	int32_t MaxDurationSeconds = 7 * 24 * 60 * 60;
};

struct ZenGcConfig
{
	//	ZenCasEvictionPolicy   Cas;
	ZenCacheEvictionPolicy		  Cache;
	ZenProjectStoreEvictionPolicy ProjectStore;
	int32_t						  MonitorIntervalSeconds			= 30;
	int32_t						  IntervalSeconds					= 0;
	bool						  CollectSmallObjects				= true;
	bool						  Enabled							= true;
	uint64_t					  DiskReserveSize					= 1ul << 28;
	uint64_t					  DiskSizeSoftLimit					= 0;
	int32_t						  LightweightIntervalSeconds		= 0;
	uint64_t					  MinimumFreeDiskSpaceToAllowWrites = 1ul << 28;
};

struct ZenOpenIdProviderConfig
{
	std::string Name;
	std::string Url;
	std::string ClientId;
};

struct ZenAuthConfig
{
	std::vector<ZenOpenIdProviderConfig> OpenIdProviders;
};

struct ZenObjectStoreConfig
{
	struct BucketConfig
	{
		std::string			  Name;
		std::filesystem::path Directory;
	};

	std::vector<BucketConfig> Buckets;
};

struct ZenStructuredCacheConfig
{
	bool	 Enabled				 = true;
	bool	 WriteLogEnabled		 = false;
	bool	 AccessLogEnabled		 = false;
	uint64_t MemTargetFootprintBytes = 512 * 1024 * 1024;
	uint64_t MemTrimIntervalSeconds	 = 60;
	uint64_t MemMaxAgeSeconds		 = gsl::narrow<uint64_t>(std::chrono::seconds(std::chrono::days(1)).count());
};

struct ZenServerOptions
{
	ZenUpstreamCacheConfig	 UpstreamCacheConfig;
	ZenGcConfig				 GcConfig;
	ZenAuthConfig			 AuthConfig;
	ZenObjectStoreConfig	 ObjectStoreConfig;
	zen::HttpServerConfig	 HttpServerConfig;
	ZenStructuredCacheConfig StructuredCacheConfig;
	std::filesystem::path	 DataDir;						 // Root directory for state (used for testing)
	std::filesystem::path	 ContentDir;					 // Root directory for serving frontend content (experimental)
	std::filesystem::path	 AbsLogFile;					 // Absolute path to main log file
	std::filesystem::path	 ConfigFile;					 // Path to Lua config file
	std::string				 ChildId;						 // Id assigned by parent process (used for lifetime management)
	std::string				 LogId;							 // Id for tagging log output
	std::string				 EncryptionKey;					 // 256 bit AES encryption key
	std::string				 EncryptionIV;					 // 128 bit AES initialization vector
	int						 BasePort			   = 1337;	 // Service listen port (used for both UDP and TCP)
	int						 OwnerPid			   = 0;		 // Parent process id (zero for standalone)
	bool					 InstallService		   = false;	 // Flag used to initiate service install (temporary)
	bool					 UninstallService	   = false;	 // Flag used to initiate service uninstall (temporary)
	bool					 IsDebug			   = false;
	bool					 IsTest				   = false;
	bool					 IsDedicated		   = false;	 // Indicates a dedicated/shared instance, with larger resource requirements
	bool					 ExecServiceEnabled	   = true;
	bool					 ComputeServiceEnabled = true;
	bool					 ShouldCrash		   = false;	 // Option for testing crash handling
	bool					 IsFirstRun			   = false;
	bool					 NoSentry			   = false;
	bool					 SentryAllowPII		   = false;	 // Allow personally identifiable information in sentry crash reports
	bool					 ObjectStoreEnabled	   = false;
#if ZEN_WITH_TRACE
	std::string TraceHost;	// Host name or IP address to send trace data to
	std::string TraceFile;	// Path of a file to write a trace
#endif
};

void ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions);