X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fglobal.cpp;h=9bc8f0483bcc2d042e89648498cb41bd86bed30d;hb=6836fbb5db8464f56e682989996b2210b14231d0;hp=aed8c3e91f52703aa8a79f6b2bff402c478a42d2;hpb=52581afffd81f5a71c129d87e3ac822d9522f12d;p=fms.git diff --git a/src/global.cpp b/src/global.cpp index aed8c3e..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(\ @@ -508,6 +520,10 @@ void SetupDB() db->Execute("INSERT INTO tblIdentity(PublicKey,DateAdded,AddedMethod) VALUES('SSK@bloE1LJ~qzSYUkU2nt7sB9kq060D4HTQC66pk5Q8NpA,DOOASUnp0kj6tOdhZJ-h5Tk7Ka50FSrUgsH7tCG1usU,AQACAAE/','"+date.Format("%Y-%m-%d %H:%M:%S")+"','Initial Identity');"); // insert Flink's public key db->Execute("INSERT INTO tblIdentity(PublicKey,DateAdded,AddedMethod) VALUES('SSK@q2TtkNBOuuniyJ56~8NSopCs3ttwe5KlB31ugZtWmXA,6~PzIupS8YK7L6oFNpXGKJmHT2kBMDfwTg73nHdNur8,AQACAAE/','"+date.Format("%Y-%m-%d %H:%M:%S")+"','Initial Identity');"); + // insert Kane's public key + db->Execute("INSERT INTO tblIdentity(PublicKey,DateAdded,AddedMethod) VALUES('SSK@Ofm~yZivDJ5Z2fSzZbMiLEUUQaIc0KHRdZMBTaPLO6I,WLm4s4hNbOOurJ6ijfOq4odz7-dN7uTUvYxJRwWnlMI,AQACAAE/','"+date.Format("%Y-%m-%d %H:%M:%S")+"','Initial Identity');"); + // inserts boardstat's public key + db->Execute("INSERT INTO tblIdentity(PublicKey,DateAdded,AddedMethod) VALUES('SSK@aYWBb6zo2AM13XCNhsmmRKMANEx6PG~C15CWjdZziKA,X1pAG4EIqR1gAiyGFVZ1iiw-uTlh460~rFACJ7ZHQXk,AQACAAE/','"+date.Format("%Y-%m-%d %H:%M:%S")+"','Initial Identity');"); // TODO remove sometime after 0.1.17 FixCapitalBoardNames(); @@ -651,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 @@ -806,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"); @@ -860,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() @@ -899,6 +994,9 @@ void SetupNetwork() void Shutdown() { + + LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"FMS starting shutdown"); + ThreadController::Instance()->ShutdownThreads(); ShutdownNetwork();