1 #include "../include/identitytestglobal.h"
\r
2 #include "../include/datetime.h"
\r
3 #include "../include/logfile.h"
\r
4 #include "../include/option.h"
\r
5 #include "../include/stringfunctions.h"
\r
6 #include "../include/db/sqlite3db.h"
\r
7 #include "../include/freenet/freenetmasterthread.h"
\r
10 #include <winsock2.h>
\r
20 SQLite3DB::DB *db=SQLite3DB::DB::instance();
\r
22 db->Open("fms.db3");
\r
23 db->SetBusyTimeout(10000); // set timeout to 10 seconds
\r
24 db->Execute("VACUUM;");
\r
26 db->Execute("CREATE TABLE IF NOT EXISTS tblOption(\
\r
27 Option TEXT UNIQUE,\
\r
28 OptionValue TEXT NOT NULL,\
\r
29 OptionDescription TEXT\
\r
32 db->Execute("CREATE TABLE IF NOT EXISTS tblLocalIdentity(\
\r
33 LocalIdentityID INTEGER PRIMARY KEY,\
\r
37 SingleUse BOOL CHECK(SingleUse IN('true','false')) DEFAULT 'false',\
\r
38 InsertingIdentity BOOL CHECK(InsertingIdentity IN('true','false')) DEFAULT 'false',\
\r
39 LastInsertedIdentity DATETIME,\
\r
40 InsertingPuzzle BOOL CHECK(InsertingPuzzle IN('true','false')) DEFAULT 'false',\
\r
41 LastInsertedPuzzle DATETIME,\
\r
42 InsertingTrustList BOOL CHECK(InsertingTrustList IN('true','false')) DEFAULT 'false',\
\r
43 LastInsertedTrustList DATETIME\
\r
46 db->Execute("CREATE TABLE IF NOT EXISTS tblLocalIdentityInserts(\
\r
47 LocalIdentityID INTEGER,\
\r
49 InsertIndex INTEGER\
\r
52 db->Execute("CREATE TABLE IF NOT EXISTS tblIntroductionPuzzleInserts(\
\r
54 LocalIdentityID INTEGER,\
\r
56 InsertIndex INTEGER,\
\r
60 PuzzleSolution TEXT,\
\r
61 FoundSolution BOOL CHECK(FoundSolution IN('true','false')) DEFAULT 'false'\
\r
64 db->Execute("CREATE TABLE IF NOT EXISTS tblIdentity(\
\r
65 IdentityID INTEGER PRIMARY KEY,\
\r
68 SingleUse BOOL CHECK(SingleUse IN('true','false')) DEFAULT 'false',\
\r
69 DateAdded DATETIME,\
\r
71 LocalMessageTrust INTEGER CHECK(LocalMessageTrust BETWEEN 0 AND 100) DEFAULT 50,\
\r
72 PeerMessageTrust INTEGER CHECK(PeerMessageTrust BETWEEN 0 AND 100) DEFAULT 50,\
\r
73 LocalTrustListTrust INTEGER CHECK(LocalTrustListTrust BETWEEN 0 AND 100) DEFAULT 50,\
\r
74 PeerTrustListTrust INTEGER CHECK(PeerTrustListTrust BETWEEN 0 AND 100) DEFAULT 50\
\r
77 db->Execute("CREATE TABLE IF NOT EXISTS tblIdentityRequests(\
\r
78 IdentityID INTEGER PRIMARY KEY,\
\r
80 RequestIndex INTEGER,\
\r
81 Found BOOL CHECK(Found IN('true','false')) DEFAULT 'false'\
\r
84 db->Execute("CREATE TABLE IF NOT EXISTS tblIntroductionPuzzleRequests(\
\r
85 IdentityID INTEGER,\
\r
87 RequestIndex INTEGER,\
\r
88 Found BOOL CHECK(Found IN('true','false')) DEFAULT 'false',\
\r
95 db->Execute("CREATE TABLE IF NOT EXISTS tblIdentityIntroductionInserts(\
\r
96 LocalIdentityID INTEGER,\
\r
100 Inserted BOOL CHECK(Inserted IN('true','false')) DEFAULT 'false'\
\r
105 void SetupDefaultOptions()
\r
107 // OptionValue should always be inserted as a string, even if the option really isn't a string - just to keep the field data type consistent
\r
109 std::ostringstream tempstr; // must set tempstr to "" between db inserts
\r
110 SQLite3DB::DB *db=SQLite3DB::DB::instance();
\r
111 SQLite3DB::Statement st=db->Prepare("INSERT INTO tblOption(Option,OptionValue,OptionDescription) VALUES(?,?,?);");
\r
115 tempstr << LogFile::LOGLEVEL_DEBUG;
\r
116 st.Bind(0,"LogLevel");
\r
117 st.Bind(1,tempstr.str());
\r
118 st.Bind(2,"The maximum logging level that will be written to file. 0=Fatal Errors, 1=Errors, 2=Warnings, 3=Informational Messages, 4=Debug Messages. Higher levels will include all messages from the previous levels.");
\r
122 // StartFreenetUpdater
\r
123 st.Bind(0,"StartFreenetUpdater");
\r
125 st.Bind(2,"Start Freenet Updater.");
\r
130 st.Bind(0,"FCPHost");
\r
131 st.Bind(1,"localhost");
\r
132 st.Bind(2,"Host name or address of Freenet node.");
\r
137 st.Bind(0,"FCPPort");
\r
139 st.Bind(2,"The port that Freenet is listening for FCP connections on.");
\r
143 st.Bind(0,"MessageBase");
\r
145 st.Bind(2,"A unique string shared by all clients who want to communicate with each other. This should not be changed unless you want to create your own separate communications network.");
\r
149 st.Bind(0,"MaxIdentityRequests");
\r
151 st.Bind(2,"Maximum number of concurrent requests for new Identity xml files");
\r
155 st.Bind(0,"MaxIdentityIntroductionRequests");
\r
157 st.Bind(2,"Maximum number of concurrent identities requesting IdentityIntroduction xml files. Each identity may have multiple requests pending.");
\r
161 st.Bind(0,"MaxIntroductionPuzzleRequests");
\r
163 st.Bind(2,"Maximum number of concurrent requests for new IntroductionPuzzle xml files");
\r
169 void SetupLogFile()
\r
172 std::string configval;
\r
175 date.SetToGMTime();
\r
177 LogFile::instance()->SetFileName("fms-"+date.Format("%Y-%m-%d")+".log");
\r
178 LogFile::instance()->OpenFile();
\r
179 LogFile::instance()->SetWriteNewLine(true);
\r
180 LogFile::instance()->SetWriteDate(true);
\r
181 LogFile::instance()->SetWriteLogLevel(true);
\r
183 if(Option::instance()->Get("LogLevel",configval)==false)
\r
186 Option::instance()->Set("LogLevel",configval);
\r
188 if(StringFunctions::Convert(configval,loglevel)==false)
\r
190 loglevel=LogFile::LOGLEVEL_DEBUG;
\r
191 Option::instance()->Set("LogLevel",loglevel);
\r
193 LogFile::instance()->SetLogLevel((LogFile::LogLevel)loglevel);
\r
196 void SetupNetwork()
\r
200 WSAStartup(MAKEWORD(2,2),&wsadata);
\r
204 void ShutdownNetwork()
\r
211 void ShutdownThreads(std::vector<ZThread::Thread *> &threads)
\r
213 std::vector<ZThread::Thread *>::iterator i;
\r
214 for(i=threads.begin(); i!=threads.end(); i++)
\r
216 if((*i)->wait(1)==false)
\r
228 for(i=threads.begin(); i!=threads.end(); i++)
\r
238 void StartThreads(std::vector<ZThread::Thread *> &threads)
\r
240 std::string startfreenet;
\r
241 std::string startnntp;
\r
243 if(Option::instance()->Get("StartFreenetUpdater",startfreenet)==false)
\r
245 startfreenet="true";
\r
246 Option::instance()->Set("StartFreenetUpdater","true");
\r
249 if(startfreenet=="true")
\r
251 ZThread::Thread *t=new ZThread::Thread(new FreenetMasterThread());
\r
252 threads.push_back(t);
\r