Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
opentxs::ConfigLoader Struct Reference

#include <ConfigLoader.hpp>

Static Public Member Functions

static bool load (OTString &walletFilename)
 

Detailed Description

Definition at line 141 of file ConfigLoader.hpp.

Member Function Documentation

bool opentxs::ConfigLoader::load ( OTString walletFilename)
static

Definition at line 150 of file ConfigLoader.cpp.

151 {
152  const char* szFunc = "ConfigLoader::load()";
153 
154  // Setup Config File
155  OTString strConfigFolder, strConfigFilename;
156 
158  OT_FAIL;
159  }
160 
161  // Create Config Object (OTSettings)
162  OTString strConfigFilePath = "";
163  if (!OTDataFolder::GetConfigFilePath(strConfigFilePath)) {
164  OT_FAIL;
165  }
166  OTSettings* p_Config = new OTSettings(strConfigFilePath);
167 
168  // First Load, Create new fresh config file if failed loading.
169  if (!p_Config->Load()) {
171  0, "%s: Note: Unable to Load Config. Creating a new file: %s\n",
172  szFunc, strConfigFilename.Get());
173  if (!p_Config->Reset()) return false;
174  if (!p_Config->Save()) return false;
175  }
176 
177  if (!p_Config->Reset()) return false;
178 
179  // Second Load, Throw Assert if Failed loading.
180  if (!p_Config->Load()) {
181  OTLog::vError(0, "%s: Error: Unable to load config file: %s It should "
182  "exist, as we just saved it!\n",
183  szFunc, strConfigFilename.Get());
184  OT_FAIL;
185  }
186 
187  // LOG LEVEL
188  {
189  bool bIsNewKey;
190  int64_t lValue;
191  p_Config->CheckSet_long("logging", "log_level", 0, lValue, bIsNewKey);
192  OTLog::SetLogLevel(static_cast<int32_t>(lValue));
193  }
194 
195  // WALLET
196 
197  // WALLET FILENAME
198  //
199  // Clean and Set
200  {
201  bool bIsNewKey;
202  OTString strValue;
203  p_Config->CheckSet_str("wallet", "wallet_filename",
204  SERVER_WALLET_FILENAME, strValue, bIsNewKey);
205  walletFilename.Set(strValue);
206  OTLog::vOutput(0, "Using Wallet: %s\n", strValue.Get());
207  }
208 
209  // CRON
210  {
211  const char* szComment = ";; CRON (regular events like market trades "
212  "and smart contract clauses)\n";
213 
214  bool b_SectionExist;
215  p_Config->CheckSetSection("cron", szComment, b_SectionExist);
216  }
217 
218  {
219  const char* szComment = "; refill_trans_number is the count of "
220  "transaction numbers cron will grab for "
221  "itself,\n"
222  "; whenever its supply is getting low. If it "
223  "ever drops below 20% of this count\n"
224  "; while in the middle of processing, it will "
225  "put a WARNING into your server log.\n";
226 
227  bool bIsNewKey;
228  int64_t lValue;
229  p_Config->CheckSet_long("cron", "refill_trans_number", 500, lValue,
230  bIsNewKey, szComment);
231  OTCron::SetCronRefillAmount(static_cast<int32_t>(lValue));
232  }
233 
234  {
235  const char* szComment = "; ms_between_cron_beats is the number of "
236  "milliseconds before Cron processes\n"
237  "; (all the trades, all the smart contracts, "
238  "etc every 10 seconds.)\n";
239 
240  bool bIsNewKey;
241  int64_t lValue;
242  p_Config->CheckSet_long("cron", "ms_between_cron_beats", 10000, lValue,
243  bIsNewKey, szComment);
244  OTCron::SetCronMsBetweenProcess(static_cast<int32_t>(lValue));
245  }
246 
247  {
248  const char* szComment = "; max_items_per_nym is the number of cron "
249  "items (such as market offers or payment\n"
250  "; plans) that any given Nym is allowed to "
251  "have live and active at the same time.\n";
252 
253  bool bIsNewKey;
254  int64_t lValue;
255  p_Config->CheckSet_long("cron", "max_items_per_nym", 10, lValue,
256  bIsNewKey, szComment);
257  OTCron::SetCronMaxItemsPerNym(static_cast<int32_t>(lValue));
258  }
259 
260  // HEARTBEAT
261 
262  {
263  const char* szComment = ";; HEARTBEAT\n";
264 
265  bool bSectionExist;
266  p_Config->CheckSetSection("heartbeat", szComment, bSectionExist);
267  }
268 
269  {
270  const char* szComment = "; no_requests is the number of client "
271  "requests the server processes per "
272  "heartbeat.\n";
273 
274  bool bIsNewKey;
275  int64_t lValue;
276  p_Config->CheckSet_long("heartbeat", "no_requests", 10, lValue,
277  bIsNewKey, szComment);
278  ServerSettings::SetHeartbeatNoRequests(static_cast<int32_t>(lValue));
279  }
280 
281  {
282  const char* szComment = "; ms_between_beats is the number of "
283  "milliseconds between each heartbeat.\n";
284 
285  bool bIsNewKey;
286  int64_t lValue;
287  p_Config->CheckSet_long("heartbeat", "ms_between_beats", 100, lValue,
288  bIsNewKey, szComment);
290  static_cast<int32_t>(lValue));
291  }
292 
293  // PERMISSIONS
294 
295  {
296  const char* szComment = ";; PERMISSIONS\n"
297  ";; You can deactivate server functions here "
298  "by setting them to false.\n"
299  ";; (Even if you do, override_nym_id will "
300  "STILL be able to do those functions.)\n";
301 
302  bool bSectionExists;
303  p_Config->CheckSetSection("permissions", szComment, bSectionExists);
304  }
305 
306  {
307  OTString strValue;
308  const char* szValue;
309 
310  std::string stdstrValue = ServerSettings::GetOverrideNymID();
311  szValue = stdstrValue.c_str();
312 
313  bool bIsNewKey;
314 
315  if (nullptr == szValue)
316  p_Config->CheckSet_str("permissions", "override_nym_id", nullptr,
317  strValue, bIsNewKey);
318  else
319  p_Config->CheckSet_str("permissions", "override_nym_id", szValue,
320  strValue, bIsNewKey);
321 
322  ServerSettings::SetOverrideNymID(strValue.Get());
323  }
324 
325  // MARKETS
326 
327  {
328  const char* szComment = "; minimum_scale is the smallest allowed "
329  "power-of-ten for the scale, for any market.\n"
330  "; (1oz, 10oz, 100oz, 1000oz.)\n";
331 
332  bool bIsNewKey;
333  int64_t lValue;
334  p_Config->CheckSet_long("markets", "minimum_scale",
336  bIsNewKey, szComment);
338  }
339 
340  // SECURITY (beginnings of..)
341 
342  // Master Key Timeout
343  {
344  const char* szComment =
345  "; master_key_timeout is how int64_t the master key will be in "
346  "memory until a thread wipes it out.\n"
347  "; 0 : means you have to type your password EVERY time OT uses a "
348  "private key. (Even multiple times in a single function.)\n"
349  "; 300 : means you only have to type it once per 5 minutes.\n"
350  "; -1 : means you only type it once PER RUN (popular for "
351  "servers.)\n";
352 
353  bool bIsNewKey;
354  int64_t lValue;
355  p_Config->CheckSet_long("security", "master_key_timeout",
357  bIsNewKey, szComment);
358  OTCachedKey::It()->SetTimeoutSeconds(static_cast<int32_t>(lValue));
359  }
360 
361  // Use System Keyring
362  {
363  bool bIsNewKey;
364  bool bValue;
365  p_Config->CheckSet_bool("security", "use_system_keyring",
366  SERVER_USE_SYSTEM_KEYRING, bValue, bIsNewKey);
367  OTCachedKey::It()->UseSystemKeyring(bValue);
368 
369 #if defined(OT_KEYRING_FLATFILE)
370  // Is there a password folder? (There shouldn't be, but we allow it...)
371  //
372  if (bValue) {
373  bool bIsNewKey2;
374  OTString strValue;
375  p_Config->CheckSet_str("security", "password_folder",
376  SERVER_PASSWORD_FOLDER, strValue,
377  bIsNewKey2);
378  if (strValue.Exists()) {
379  OTKeyring::FlatFile_SetPasswordFolder(strValue.Get());
380  OTLog::vOutput(0, " Using server password folder: %s\n",
381  strValue.Get());
382  }
383  }
384 #endif
385  }
386 
387  // (#defined right above this function.)
388  //
389 
390  p_Config->SetOption_bool("permissions", "admin_usage_credits",
392  p_Config->SetOption_bool("permissions", "admin_server_locked",
394  p_Config->SetOption_bool("permissions", "cmd_usage_credits",
396  p_Config->SetOption_bool("permissions", "cmd_issue_asset",
398  p_Config->SetOption_bool("permissions", "cmd_get_contract",
400  p_Config->SetOption_bool("permissions", "cmd_check_server_id",
402  p_Config->SetOption_bool("permissions", "cmd_create_user_acct",
404  p_Config->SetOption_bool("permissions", "cmd_del_user_acct",
406  p_Config->SetOption_bool("permissions", "cmd_check_user",
408  p_Config->SetOption_bool("permissions", "cmd_get_request",
410  p_Config->SetOption_bool("permissions", "cmd_get_trans_num",
412  p_Config->SetOption_bool("permissions", "cmd_send_message",
414  p_Config->SetOption_bool("permissions", "cmd_get_nymbox",
416  p_Config->SetOption_bool("permissions", "cmd_process_nymbox",
418  p_Config->SetOption_bool("permissions", "cmd_create_asset_acct",
420  p_Config->SetOption_bool("permissions", "cmd_del_asset_acct",
422  p_Config->SetOption_bool("permissions", "cmd_get_acct",
424  p_Config->SetOption_bool("permissions", "cmd_get_inbox",
426  p_Config->SetOption_bool("permissions", "cmd_get_outbox",
428  p_Config->SetOption_bool("permissions", "cmd_process_inbox",
430  p_Config->SetOption_bool("permissions", "cmd_issue_basket",
432  p_Config->SetOption_bool("permissions", "transact_exchange_basket",
434  p_Config->SetOption_bool("permissions", "cmd_notarize_transaction",
436  p_Config->SetOption_bool("permissions", "transact_process_inbox",
438  p_Config->SetOption_bool("permissions", "transact_transfer",
440  p_Config->SetOption_bool("permissions", "transact_withdrawal",
442  p_Config->SetOption_bool("permissions", "transact_deposit",
444  p_Config->SetOption_bool("permissions", "transact_withdraw_voucher",
446  p_Config->SetOption_bool("permissions", "transact_pay_dividend",
448  p_Config->SetOption_bool("permissions", "transact_deposit_cheque",
450  p_Config->SetOption_bool("permissions", "cmd_get_mint",
452  p_Config->SetOption_bool("permissions", "transact_withdraw_cash",
454  p_Config->SetOption_bool("permissions", "transact_deposit_cash",
456  p_Config->SetOption_bool("permissions", "cmd_get_market_list",
458  p_Config->SetOption_bool("permissions", "cmd_get_market_offers",
460  p_Config->SetOption_bool("permissions", "cmd_get_market_recent_trades",
462  p_Config->SetOption_bool("permissions", "cmd_get_nym_market_offers",
464  p_Config->SetOption_bool("permissions", "transact_market_offer",
466  p_Config->SetOption_bool("permissions", "transact_payment_plan",
468  p_Config->SetOption_bool("permissions", "transact_cancel_cron_item",
470  p_Config->SetOption_bool("permissions", "transact_smart_contract",
472  p_Config->SetOption_bool("permissions", "cmd_trigger_clause",
474 
475  // Done Loading... Lets save any changes...
476  if (!p_Config->Save()) {
477  OTLog::vError("%s: Error! Unable to save updated Config!!!\n", szFunc);
478  OT_FAIL;
479  }
480 
481  // Finsihed Saving... now lets cleanup!
482  if (!p_Config->Reset()) return false;
483 
484  if (nullptr != p_Config) delete p_Config;
485  p_Config = nullptr;
486 
487  return true;
488 }
static EXPORT void vError(const char *szError,...)
Definition: OTLog.cpp:800
static void SetCronRefillAmount(int32_t nAmount)
Definition: OTCron.hpp:209
static void SetHeartbeatNoRequests(int32_t value)
static bool __transact_withdraw_cash
static EXPORT bool GetConfigFilePath(OTString &strConfigFilePath)
static bool __cmd_create_asset_acct
static const std::string & GetOverrideNymID()
static EXPORT bool SetLogLevel(const int32_t &nLogLevel)
Definition: OTLog.cpp:443
static void SetCronMaxItemsPerNym(int32_t nMax)
Definition: OTCron.hpp:217
static bool __transact_market_offer
static bool __transact_cancel_cron_item
static EXPORT bool IsInitialized()
static EXPORT std::shared_ptr< OTCachedKey > It(OTIdentifier *pIdentifier=nullptr)
static void SetHeartbeatMsBetweenBeats(int32_t value)
static int64_t GetMinMarketScale()
static bool __transact_smart_contract
static void SetCronMsBetweenProcess(int32_t lMS)
Definition: OTCron.hpp:200
static bool __transact_process_inbox
static bool __cmd_get_nym_market_offers
#define OT_FAIL
Definition: Assert.hpp:139
#define SERVER_USE_SYSTEM_KEYRING
static bool __transact_exchange_basket
static bool __transact_withdraw_voucher
static void SetMinMarketScale(int64_t value)
static bool __transact_deposit_cash
#define SERVER_WALLET_FILENAME
static bool __cmd_create_user_acct
static bool __transact_deposit_cheque
static bool __transact_payment_plan
#define SERVER_MASTER_KEY_TIMEOUT_DEFAULT
static void SetOverrideNymID(const std::string &id)
#define SERVER_PASSWORD_FOLDER
Definition: OTServer.cpp:184
static bool __cmd_get_market_offers
static bool __transact_pay_dividend
static bool __cmd_notarize_transaction
static EXPORT void vOutput(int32_t nVerbosity, const char *szOutput,...)
Definition: OTLog.cpp:768
static bool __cmd_get_market_recent_trades

The documentation for this struct was generated from the following files: