File tree Expand file tree Collapse file tree 5 files changed +45
-15
lines changed
Expand file tree Collapse file tree 5 files changed +45
-15
lines changed Original file line number Diff line number Diff line change @@ -94,6 +94,11 @@ namespace util
9494
9595 i2p::config::GetOption (" daemon" , isDaemon);
9696
97+ std::string certsdir; i2p::config::GetOption (" certsdir" , certsdir);
98+ i2p::fs::SetCertsDir (certsdir);
99+
100+ certsdir = i2p::fs::GetCertsDir ();
101+
97102 std::string logs = " " ; i2p::config::GetOption (" log" , logs);
98103 std::string logfile = " " ; i2p::config::GetOption (" logfile" , logfile);
99104 std::string loglevel = " " ; i2p::config::GetOption (" loglevel" , loglevel);
@@ -132,6 +137,7 @@ namespace util
132137 LogPrint (eLogNone, " i2pd v" , VERSION, " starting" );
133138 LogPrint (eLogDebug, " FS: main config file: " , config);
134139 LogPrint (eLogDebug, " FS: data directory: " , datadir);
140+ LogPrint (eLogDebug, " FS: certificates directory: " , certsdir);
135141
136142 bool precomputation; i2p::config::GetOption (" precomputation.elgamal" , precomputation);
137143 bool aesni; i2p::config::GetOption (" cpuext.aesni" , aesni);
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ namespace i2p {
2424namespace fs {
2525 std::string appName = " i2pd" ;
2626 std::string dataDir = " " ;
27+ std::string certsDir = " " ;
2728#ifdef _WIN32
2829 std::string dirSep = " \\ " ;
2930#else
@@ -42,6 +43,10 @@ namespace fs {
4243 return dataDir;
4344 }
4445
46+ const std::string & GetCertsDir () {
47+ return certsDir;
48+ }
49+
4550 const std::string GetUTF8DataDir () {
4651#ifdef _WIN32
4752 boost::filesystem::wpath path (dataDir);
@@ -126,6 +131,21 @@ namespace fs {
126131#endif
127132 }
128133
134+ void SetCertsDir (const std::string & cmdline_certsdir) {
135+ if (cmdline_certsdir != " " )
136+ {
137+ if (cmdline_certsdir[cmdline_certsdir.length ()-1 ] == ' /' )
138+ certsDir = cmdline_certsdir.substr (0 , cmdline_certsdir.size ()-1 ); // strip trailing slash
139+ else
140+ certsDir = cmdline_certsdir;
141+ }
142+ else
143+ {
144+ certsDir = i2p::fs::DataDirPath (" certificates" );
145+ }
146+ return ;
147+ }
148+
129149 bool Init () {
130150 if (!boost::filesystem::exists (dataDir))
131151 boost::filesystem::create_directory (dataDir);
Original file line number Diff line number Diff line change @@ -75,6 +75,9 @@ namespace fs {
7575 /* * @brief Returns datadir path */
7676 const std::string & GetDataDir ();
7777
78+ /* * @brief Returns certsdir path */
79+ const std::string & GetCertsDir ();
80+
7881 /* * @brief Returns datadir path in UTF-8 encoding */
7982 const std::string GetUTF8DataDir ();
8083
@@ -90,7 +93,20 @@ namespace fs {
9093 * Mac: /Library/Application Support/i2pd/ or ~/Library/Application Support/i2pd/
9194 * Unix: /var/lib/i2pd/ (system=1) >> ~/.i2pd/ or /tmp/i2pd/
9295 */
93- void DetectDataDir (const std::string & cmdline_datadir, bool isService = false );
96+ void DetectDataDir (const std::string & cmdline_datadir, bool isService = false );
97+
98+ /* *
99+ * @brief Set certsdir either from cmdline option or using autodetection
100+ * @param cmdline_param Value of cmdline parameter --certsdir=<something>
101+ *
102+ * Examples of autodetected paths:
103+ *
104+ * Windows < Vista: C:\Documents and Settings\Username\Application Data\i2pd\certificates
105+ * Windows >= Vista: C:\Users\Username\AppData\Roaming\i2pd\certificates
106+ * Mac: /Library/Application Support/i2pd/ or ~/Library/Application Support/i2pd/certificates
107+ * Unix: /var/lib/i2pd/certificates (system=1) >> ~/.i2pd/ or /tmp/i2pd/certificates
108+ */
109+ void SetCertsDir (const std::string & cmdline_certsdir);
94110
95111 /* *
96112 * @brief Create subdirectories inside datadir
Original file line number Diff line number Diff line change @@ -99,13 +99,7 @@ namespace data
9999
100100 void Families::LoadCertificates ()
101101 {
102- std::string certDir;
103- std::string certsdir; i2p::config::GetOption (" certsdir" , certsdir);
104- if (!i2p::config::IsDefault (" certsdir" ))
105- certDir = certsdir + i2p::fs::dirSep + " family" ;
106-
107- if (certDir.empty () || !i2p::fs::Exists (certDir))
108- certDir = i2p::fs::DataDirPath (" certificates" , " family" );
102+ std::string certDir = i2p::fs::GetCertsDir () + i2p::fs::dirSep + " family" ;
109103
110104 std::vector<std::string> files;
111105 int numCertificates = 0 ;
Original file line number Diff line number Diff line change @@ -497,13 +497,7 @@ namespace data
497497
498498 void Reseeder::LoadCertificates ()
499499 {
500- std::string certDir;
501- std::string certsdir; i2p::config::GetOption (" certsdir" , certsdir);
502- if (!i2p::config::IsDefault (" certsdir" ))
503- certDir = certsdir + i2p::fs::dirSep + " reseed" ;
504-
505- if (certDir.empty () || !i2p::fs::Exists (certDir))
506- certDir = i2p::fs::DataDirPath (" certificates" , " reseed" );
500+ std::string certDir = i2p::fs::GetCertsDir () + i2p::fs::dirSep + " reseed" ;
507501
508502 std::vector<std::string> files;
509503 int numCertificates = 0 ;
You can’t perform that action at this time.
0 commit comments