X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fglobal.cpp;h=9bc8f0483bcc2d042e89648498cb41bd86bed30d;hb=6836fbb5db8464f56e682989996b2210b14231d0;hp=38d51bc35c9c2f7253c63541c6af79c7706ea593;hpb=44f964d9b2b2d55a5b5672e9297717bd25fa8ee2;p=fms.git diff --git a/src/global.cpp b/src/global.cpp index 38d51bc..9bc8f04 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -17,7 +17,7 @@ #include #endif -bool wantshutdown=false; +volatile bool wantshutdown=false; std::string CreateShortIdentityName(const std::string &name, const std::string &publickey) { @@ -39,11 +39,18 @@ void SetupDB() { DateTime date; + std::string tempval=""; SQLite3DB::DB *db=SQLite3DB::DB::Instance(); db->Open("fms.db3"); db->SetBusyTimeout(10000); // set timeout to 10 seconds - //db->Execute("VACUUM;"); // not needed every startup + + tempval=""; + Option::Instance()->Get("VacuumOnStartup",tempval); + if(tempval=="true") + { + db->Execute("VACUUM;"); + } db->Execute("CREATE TABLE IF NOT EXISTS tblDBVersion(\ Major INTEGER,\ @@ -113,13 +120,19 @@ void SetupDB() major=1; minor=10; } + if(major==1 && minor==10) + { + ConvertDB0110To0111(); + major=1; + minor=11; + } } else { - db->Execute("INSERT INTO tblDBVersion(Major,Minor) VALUES(1,10);"); + db->Execute("INSERT INTO tblDBVersion(Major,Minor) VALUES(1,11);"); } - db->Execute("UPDATE tblDBVersion SET Major=1, Minor=10;"); + db->Execute("UPDATE tblDBVersion SET Major=1, Minor=11;"); db->Execute("CREATE TABLE IF NOT EXISTS tblOption(\ Option TEXT UNIQUE,\ @@ -143,12 +156,12 @@ void SetupDB() LastInsertedPuzzle DATETIME,\ InsertingTrustList BOOL CHECK(InsertingTrustList IN('true','false')) DEFAULT 'false',\ LastInsertedTrustList DATETIME,\ - InsertingBoardList BOOL CHECK(InsertingBoardList IN('true','false')) DEFAULT 'false',\ LastInsertedBoardList DATETIME,\ - InsertingMessageList BOOL CHECK(InsertingMessageList IN('true','false')) DEFAULT 'false',\ LastInsertedMessageList DATETIME,\ LastInsertedFreesite DATETIME,\ - DateCreated DATETIME\ + DateCreated DATETIME,\ + MinMessageDelay INTEGER DEFAULT 0,\ + MaxMessageDelay INTEGER DEFAULT 0\ );"); db->Execute("CREATE TABLE IF NOT EXISTS tblLocalIdentityInserts(\ @@ -197,8 +210,6 @@ void SetupDB() LocalTrustListTrust INTEGER CHECK(LocalTrustListTrust BETWEEN 0 AND 100) DEFAULT NULL,\ PeerTrustListTrust INTEGER CHECK(PeerTrustListTrust BETWEEN 0 AND 100) DEFAULT NULL,\ AddedMethod TEXT,\ - MessageTrustComment TEXT,\ - TrustListTrustComment TEXT,\ Hidden BOOL CHECK(Hidden IN('true','false')) DEFAULT 'false'\ );"); @@ -279,7 +290,7 @@ void SetupDB() );"); db->Execute("INSERT INTO tblBoard(BoardName,BoardDescription,DateAdded,AddedMethod) VALUES('fms','Freenet Message System','2007-12-01 12:00:00','Initial Board');"); - db->Execute("INSERT INTO tblBoard(BoardName,BoardDescription,DateAdded,AddedMethod) VALUES('freenet','Discussion about Freenet','2007-12-01 12:00:00','Initialt Board');"); + db->Execute("INSERT INTO tblBoard(BoardName,BoardDescription,DateAdded,AddedMethod) VALUES('freenet','Discussion about Freenet','2007-12-01 12:00:00','Initial Board');"); db->Execute("INSERT INTO tblBoard(BoardName,BoardDescription,DateAdded,AddedMethod) VALUES('public','Public discussion','2007-12-01 12:00:00','Initial Board');"); db->Execute("INSERT INTO tblBoard(BoardName,BoardDescription,DateAdded,AddedMethod) VALUES('test','Test board','2007-12-01 12:00:00','Initial Board');"); @@ -337,7 +348,8 @@ void SetupDB() InsertIndex INTEGER,\ MessageUUID TEXT UNIQUE,\ MessageXML TEXT,\ - Inserted BOOL CHECK(Inserted IN('true','false')) DEFAULT 'false'\ + Inserted BOOL CHECK(Inserted IN('true','false')) DEFAULT 'false',\ + SendDate DATETIME\ );"); db->Execute("CREATE TABLE IF NOT EXISTS tblFileInserts(\ @@ -655,6 +667,73 @@ void ConvertDB0109To0110() db->Execute("UPDATE tblDBVersion SET Major=1, Minor=10;"); } +void ConvertDB0110To0111() +{ + /* + Drop MessageTrustComment, TrustListTrustComment FROM tblIdentity + + Drop InsertingMessageList, InsertingBoardList FROM tblLocalIdentity + Add MinMessageDelay, MaxMessageDelay to tblLocalIdentity Default 0 + + Add SendDate to tblMessageInserts + */ + SQLite3DB::DB *db=SQLite3DB::DB::Instance(); + + db->Execute("ALTER TABLE tblMessageInserts ADD COLUMN SendDate DATETIME;"); + + db->Execute("CREATE TEMPORARY TABLE tblLocalIdentityTemp AS SELECT * FROM tblLocalIdentity;"); + db->Execute("DROP TABLE IF EXISTS tblLocalIdentity;"); + db->Execute("CREATE TABLE IF NOT EXISTS tblLocalIdentity(\ + LocalIdentityID INTEGER PRIMARY KEY,\ + Name TEXT,\ + PublicKey TEXT UNIQUE,\ + PrivateKey TEXT UNIQUE,\ + SingleUse BOOL CHECK(SingleUse IN('true','false')) DEFAULT 'false',\ + PublishTrustList BOOL CHECK(PublishTrustList IN('true','false')) DEFAULT 'false',\ + PublishBoardList BOOL CHECK(PublishBoardList IN('true','false')) DEFAULT 'false',\ + PublishFreesite BOOL CHECK(PublishFreesite IN('true','false')) DEFAULT 'false',\ + FreesiteEdition INTEGER,\ + InsertingIdentity BOOL CHECK(InsertingIdentity IN('true','false')) DEFAULT 'false',\ + LastInsertedIdentity DATETIME,\ + InsertingPuzzle BOOL CHECK(InsertingPuzzle IN('true','false')) DEFAULT 'false',\ + LastInsertedPuzzle DATETIME,\ + InsertingTrustList BOOL CHECK(InsertingTrustList IN('true','false')) DEFAULT 'false',\ + LastInsertedTrustList DATETIME,\ + LastInsertedBoardList DATETIME,\ + LastInsertedMessageList DATETIME,\ + LastInsertedFreesite DATETIME,\ + DateCreated DATETIME,\ + MinMessageDelay INTEGER DEFAULT 0,\ + MaxMessageDelay INTEGER DEFAULT 0\ + );"); + db->Execute("INSERT INTO tblLocalIdentity SELECT LocalIdentityID,Name,PublicKey,PrivateKey,SingleUse,PublishTrustList,PublishBoardList,PublishFreesite,FreesiteEdition,InsertingIdentity,LastInsertedIdentity,InsertingPuzzle,LastInsertedPuzzle,InsertingTrustList,LastInsertedTrustList,LastInsertedBoardList,LastInsertedMessageList,LastInsertedFreesite,DateCreated,0,0 FROM tblLocalIdentityTemp;"); + db->Execute("DROP TABLE IF EXISTS tblLocalIdentityTemp;"); + + db->Execute("CREATE TEMPORARY TABLE tblIdentityTemp AS SELECT * FROM tblIdentity;"); + db->Execute("DROP TABLE IF EXISTS tblIdentity;"); + db->Execute("CREATE TABLE IF NOT EXISTS tblIdentity(\ + IdentityID INTEGER PRIMARY KEY,\ + PublicKey TEXT UNIQUE,\ + Name TEXT,\ + SingleUse BOOL CHECK(SingleUse IN('true','false')) DEFAULT 'false',\ + PublishTrustList BOOL CHECK(PublishTrustList IN('true','false')) DEFAULT 'false',\ + PublishBoardList BOOL CHECK(PublishBoardList IN('true','false')) DEFAULT 'false',\ + FreesiteEdition INTEGER,\ + DateAdded DATETIME,\ + LastSeen DATETIME,\ + LocalMessageTrust INTEGER CHECK(LocalMessageTrust BETWEEN 0 AND 100) DEFAULT NULL,\ + PeerMessageTrust INTEGER CHECK(PeerMessageTrust BETWEEN 0 AND 100) DEFAULT NULL,\ + LocalTrustListTrust INTEGER CHECK(LocalTrustListTrust BETWEEN 0 AND 100) DEFAULT NULL,\ + PeerTrustListTrust INTEGER CHECK(PeerTrustListTrust BETWEEN 0 AND 100) DEFAULT NULL,\ + AddedMethod TEXT,\ + Hidden BOOL CHECK(Hidden IN('true','false')) DEFAULT 'false'\ + );"); + db->Execute("INSERT INTO tblIdentity SELECT IdentityID,PublicKey,Name,SingleUse,PublishTrustList,PublishBoardList,FreesiteEdition,DateAdded,LastSeen,LocalMessageTrust,PeerMessageTrust,LocalTrustListTrust,PeerTrustListTrust,AddedMethod,Hidden FROM tblIdentityTemp;"); + db->Execute("DROP TABLE IF EXISTS tblIdentityTemp;"); + + db->Execute("UPDATE tblDBVersion SET Major=1, Minor=11;"); +} + void SetupDefaultOptions() { // 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 @@ -810,6 +889,12 @@ void SetupDefaultOptions() st.Step(); st.Reset(); + st.Bind(0,"LocalTrustOverridesPeerTrust"); + st.Bind(1,"false"); + st.Bind(2,"Set to true if you want your local trust levels to override the peer levels when determining which identities you will poll."); + st.Step(); + st.Reset(); + st.Bind(0,"MessageDownloadMaxDaysBackward"); st.Bind(1,"5"); st.Bind(2,"The maximum number of days backward that messages will be downloaded from each identity"); @@ -864,6 +949,12 @@ void SetupDefaultOptions() st.Step(); st.Reset(); + st.Bind(0,"VacuumOnStartup"); + st.Bind(1,"false"); + st.Bind(2,"VACUUM the database every time FMS starts. This will defragment the free space in the database and create a smaller database file. Vacuuming the database can be CPU and disk intensive."); + st.Step(); + st.Reset(); + } void SetupLogFile() @@ -903,6 +994,9 @@ void SetupNetwork() void Shutdown() { + + LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"FMS starting shutdown"); + ThreadController::Instance()->ShutdownThreads(); ShutdownNetwork();