X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fglobal.cpp;h=a3c811121ea2168cfa0f29159537870950fe75f1;hb=b9c3763a932cebaa015a27fe111017f6f34dfbaa;hp=8552db28565f05c91f67b8a66a7d8a84c44b7e12;hpb=c7fcb4c4bc5012a584add81a9509fc1f84c3c688;p=fms.git diff --git a/src/global.cpp b/src/global.cpp index 8552db2..a3c8111 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -6,6 +6,7 @@ #include "../include/db/sqlite3db.h" #include "../include/freenet/freenetmasterthread.h" #include "../include/nntp/nntplistener.h" +#include "../include/http/httpthread.h" #ifdef _WIN32 #include @@ -24,6 +25,28 @@ void SetupDB() db->Open("fms.db3"); db->SetBusyTimeout(10000); // set timeout to 10 seconds db->Execute("VACUUM;"); + + // TODO remove this - temp fix for problem in 0.1.8 + db->Execute("DELETE FROM tblMessageBoard WHERE MessageID NOT IN (SELECT MessageID FROM tblMessage);"); + + db->Execute("CREATE TABLE IF NOT EXISTS tblDBVersion(\ + Major INTEGER,\ + Minor INTEGER\ + );"); + + SQLite3DB::Statement st=db->Prepare("SELECT Major,Minor FROM tblDBVersion;"); + st.Step(); + if(st.RowReturned()) + { + int major; + int minor; + st.ResultInt(0,major); + st.ResultInt(1,minor); + } + else + { + db->Execute("INSERT INTO tblDBVersion(Major,Minor) VALUES(1,0);"); + } db->Execute("CREATE TABLE IF NOT EXISTS tblOption(\ Option TEXT UNIQUE,\ @@ -196,6 +219,12 @@ void SetupDB() Inserted BOOL CHECK(Inserted IN('true','false')) DEFAULT 'false'\ );"); + db->Execute("CREATE TABLE IF NOT EXISTS tblAdministrationBoard(\ + BoardID INTEGER UNIQUE,\ + ModifyLocalMessageTrust INTEGER,\ + ModifyLocalTrustListTrust INTEGER\ + );"); + // MessageInserter will insert a record into this temp table which the MessageListInserter will query for and insert a MessageList when needed db->Execute("CREATE TEMPORARY TABLE IF NOT EXISTS tmpMessageListInsert(\ LocalIdentityID INTEGER,\ @@ -203,16 +232,14 @@ void SetupDB() );"); // low / high / message count for each board - db->Execute("DROP VIEW IF EXISTS vwBoardStats; \ - CREATE VIEW IF NOT EXISTS vwBoardStats AS \ + db->Execute("CREATE VIEW IF NOT EXISTS vwBoardStats AS \ SELECT tblBoard.BoardID AS 'BoardID', IFNULL(MIN(MessageID),0) AS 'LowMessageID', IFNULL(MAX(MessageID),0) AS 'HighMessageID', COUNT(MessageID) AS 'MessageCount' \ FROM tblBoard LEFT JOIN tblMessageBoard ON tblBoard.BoardID=tblMessageBoard.BoardID \ WHERE MessageID>=0 OR MessageID IS NULL \ GROUP BY tblBoard.BoardID;"); // calculates peer trust - db->Execute("DROP VIEW IF EXISTS vwCalculatedPeerTrust; \ - CREATE VIEW IF NOT EXISTS vwCalculatedPeerTrust AS \ + db->Execute("CREATE VIEW IF NOT EXISTS vwCalculatedPeerTrust AS \ SELECT TargetIdentityID, \ ROUND(SUM(MessageTrust*(LocalMessageTrust/100.0))/SUM(LocalMessageTrust/100.0),0) AS 'PeerMessageTrust', \ ROUND(SUM(TrustListTrust*(LocalTrustListTrust/100.0))/SUM(LocalTrustListTrust/100.0),0) AS 'PeerTrustListTrust' \ @@ -221,6 +248,16 @@ void SetupDB() AND ( PeerTrustListTrust IS NULL OR PeerTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinPeerTrustListTrust') ) \ GROUP BY TargetIdentityID;"); + /* + These peer trust calculations are too CPU intensive to be triggers - they were called every time a new trust list was processed + All trust levels will now be recalculated every hour in the PeriodicDBMaintenance class + */ + // drop existing triggers + db->Execute("DROP TRIGGER IF EXISTS trgDeleteOntblPeerTrust;"); + db->Execute("DROP TRIGGER IF EXISTS trgInsertOntblPeerTrust;"); + db->Execute("DROP TRIGGER IF EXISTS trgUpdateOntblPeerTrust;"); + db->Execute("DROP TRIGGER IF EXISTS trgUpdateLocalTrustLevels;"); +/* // update PeerTrustLevel when deleting a record from tblPeerTrust db->Execute("CREATE TRIGGER IF NOT EXISTS trgDeleteOntblPeerTrust AFTER DELETE ON tblPeerTrust \ FOR EACH ROW \ @@ -249,6 +286,7 @@ void SetupDB() BEGIN \ UPDATE tblIdentity SET PeerMessageTrust=(SELECT PeerMessageTrust FROM vwCalculatedPeerTrust WHERE TargetIdentityID=IdentityID), PeerTrustListTrust=(SELECT PeerTrustListTrust FROM vwCalculatedPeerTrust WHERE TargetIdentityID=IdentityID);\ END;"); +*/ db->Execute("CREATE TRIGGER IF NOT EXISTS trgDeleteMessage AFTER DELETE ON tblMessage \ FOR EACH ROW \ @@ -290,7 +328,7 @@ void SetupDB() // insert SomeDude's public key date.SetToGMTime(); -// db->Execute("INSERT INTO tblIdentity(PublicKey,DateAdded) VALUES('SSK@NuBL7aaJ6Cn4fB7GXFb9Zfi8w1FhPyW3oKgU9TweZMw,iXez4j3qCpd596TxXiJgZyTq9o-CElEuJxm~jNNZAuA,AQACAAE/','"+date.Format("%Y-%m-%d %H:%M:%S")+"');"); + db->Execute("INSERT INTO tblIdentity(PublicKey,DateAdded) VALUES('SSK@NuBL7aaJ6Cn4fB7GXFb9Zfi8w1FhPyW3oKgU9TweZMw,iXez4j3qCpd596TxXiJgZyTq9o-CElEuJxm~jNNZAuA,AQACAAE/','"+date.Format("%Y-%m-%d %H:%M:%S")+"');"); } @@ -334,7 +372,19 @@ void SetupDefaultOptions() // StartNNTP st.Bind(0,"StartNNTP"); st.Bind(1,"true"); - st.Bind(2,"Start NNTP service."); + st.Bind(2,"Start NNTP server."); + st.Step(); + st.Reset(); + + st.Bind(0,"StartHTTP"); + st.Bind(1,"true"); + st.Bind(2,"Start HTTP server."); + st.Step(); + st.Reset(); + + st.Bind(0,"HTTPListenPort"); + st.Bind(1,"8080"); + st.Bind(2,"Port HTTP server will listen on."); st.Step(); st.Reset(); @@ -347,7 +397,7 @@ void SetupDefaultOptions() // FCPHost st.Bind(0,"FCPHost"); - st.Bind(1,"localhost"); + st.Bind(1,"127.0.0.1"); st.Bind(2,"Host name or address of Freenet node."); st.Step(); st.Reset(); @@ -408,31 +458,31 @@ void SetupDefaultOptions() st.Reset(); st.Bind(0,"MinPeerMessageTrust"); - st.Bind(1,"25"); + st.Bind(1,"30"); st.Bind(2,"Specifies a peer message trust level that a peer must have before its messages will be downloaded."); st.Step(); st.Reset(); st.Bind(0,"MinLocalTrustListTrust"); - st.Bind(1,"50"); + st.Bind(1,"51"); st.Bind(2,"Specifies a local trust list trust level that a peer must have before its trust list will be included in the weighted average. Any peers below this number will be excluded from the results."); st.Step(); st.Reset(); st.Bind(0,"MinPeerTrustListTrust"); - st.Bind(1,"25"); + st.Bind(1,"30"); st.Bind(2,"Specifies a peer trust list trust level that a peer must have before its trust list will be included in the weighted average. Any peers below this number will be excluded from the results."); st.Step(); st.Reset(); st.Bind(0,"MessageDownloadMaxDaysBackward"); - st.Bind(1,"3"); + st.Bind(1,"5"); st.Bind(2,"The maximum number of days backward that messages will be downloaded from each identity"); st.Step(); st.Reset(); st.Bind(0,"MessageListDaysBackward"); - st.Bind(1,"3"); + st.Bind(1,"5"); st.Bind(2,"The number of days backward that messages you have inserted will appear in your MessageLists"); st.Step(); st.Reset(); @@ -516,6 +566,7 @@ void StartThreads(std::vector &threads) { std::string startfreenet; std::string startnntp; + std::string starthttp; if(Option::Instance()->Get("StartFreenetUpdater",startfreenet)==false) { @@ -529,6 +580,12 @@ void StartThreads(std::vector &threads) Option::Instance()->Set("StartNNTP","true"); } + if(Option::Instance()->Get("StartHTTP",starthttp)==false) + { + starthttp="true"; + Option::Instance()->Set("StartHTTP","true"); + } + if(startfreenet=="true") { PThread::Thread *t=new PThread::Thread(new FreenetMasterThread()); @@ -541,4 +598,10 @@ void StartThreads(std::vector &threads) threads.push_back(t); } + if(starthttp=="true") + { + PThread::Thread *t=new PThread::Thread(new HTTPThread()); + threads.push_back(t); + } + }