From 964f55fd550fc711c0320ce6a24ad713040695d0 Mon Sep 17 00:00:00 2001 From: SomeDude Date: Sat, 26 Jan 2008 17:35:00 +0100 Subject: [PATCH] version 0.1.2 --- CMakeLists.txt | 4 + admin/identitytrust.php | 19 ++--- admin/introduce.php | 18 ++++- admin/introductionstatus.php | 4 +- admin/linkbar.php | 1 + admin/localidentities.php | 102 ++++++++++++++++++++++++++ include/global.h | 2 +- include/nntp/nntplistener.h | 1 + src/freenet/identityinserter.cpp | 9 ++- src/freenet/identityintroductionrequester.cpp | 4 +- src/freenet/introductionpuzzleinserter.cpp | 8 +- src/freenet/messagelistinserter.cpp | 4 +- src/freenet/messagelistrequester.cpp | 2 +- src/freenet/trustlistinserter.cpp | 11 ++- src/global.cpp | 45 +++++++++++- src/nntp/nntpconnection.cpp | 8 +- src/nntp/nntplistener.cpp | 17 ++++- 17 files changed, 227 insertions(+), 32 deletions(-) create mode 100644 admin/localidentities.php diff --git a/CMakeLists.txt b/CMakeLists.txt index ddf3dad..be285e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,6 +58,10 @@ src/xyssl/sha1.c ADD_DEFINITIONS(-DTIXML_USE_STL) +IF(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) + ADD_DEFINITIONS(-fpermissive) +ENDIF(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) + ADD_EXECUTABLE(fms ${FMS_SRC}) INCLUDE_DIRECTORIES(libs/sqlite3 libs/tinyxml) diff --git a/admin/identitytrust.php b/admin/identitytrust.php index 8e5aa1e..6c4663b 100644 --- a/admin/identitytrust.php +++ b/admin/identitytrust.php @@ -25,10 +25,11 @@ function content() } } - $st=$db->prepare("SELECT IdentityID,Name,LocalMessageTrust,PeerMessageTrust,LocalTrustListTrust,PeerTrustListTrust FROM tblIdentity ORDER BY Name;"); + $st=$db->prepare("SELECT IdentityID,Name,LocalMessageTrust,PeerMessageTrust,LocalTrustListTrust,PeerTrustListTrust,PublicKey FROM tblIdentity ORDER BY Name;"); $st->execute(); ?>

Identity Trust

+ Message Trust is how much you trust the identity to post good messages. Trust List Trust is how much weight you want the trust list of that identity to have when calculating the total. The local trust levels are set by you, and the peer trust levels are calculated by a weighted average using other identities trust lists.
@@ -44,18 +45,18 @@ function content() { ?> - - + diff --git a/admin/introduce.php b/admin/introduce.php index aafb20c..b13a05e 100644 --- a/admin/introduce.php +++ b/admin/introduce.php @@ -9,13 +9,13 @@ function localiddropdown($name) $db=new PDO('sqlite:'.$dblocation); - $st=$db->prepare("SELECT LocalIdentityID, Name FROM tblLocalIdentity ORDER BY Name;"); + $st=$db->prepare("SELECT LocalIdentityID, Name, PublicKey FROM tblLocalIdentity ORDER BY Name;"); $st->execute(); print ""; } @@ -58,7 +58,8 @@ function content() // only show latest captcha for each known identity $lastid=''; - while($record=$st->fetch()) + $shown=0; + while(($record=$st->fetch()) && $shown<30) { if($lastid!=$record[2]) { @@ -68,10 +69,21 @@ function content() print ""; print ""; print "
"; + $shown++; } } + + if($shown>0) + { ?> + prepare("SELECT tblLocalIdentity.Name, COUNT(Inserted) FROM tblLocalIdentity LEFT JOIN tblIdentityIntroductionInserts ON tblLocalIdentity.LocalIdentityID=tblIdentityIntroductionInserts.LocalIdentityID WHERE (Inserted='true' OR Inserted IS NULL) GROUP BY tblLocalIdentity.LocalIdentityID;"); + $st=$db->prepare("SELECT tblLocalIdentity.Name, COUNT(Inserted), tblLocalIdentity.PublicKey FROM tblLocalIdentity LEFT JOIN tblIdentityIntroductionInserts ON tblLocalIdentity.LocalIdentityID=tblIdentityIntroductionInserts.LocalIdentityID WHERE (Inserted='true' OR Inserted IS NULL) GROUP BY tblLocalIdentity.LocalIdentityID;"); $st->execute(); ?> @@ -23,7 +23,7 @@ function content() { ?> -
- - + + + - - + + - - + +
+ diff --git a/admin/linkbar.php b/admin/linkbar.php index 3308497..4e80f20 100644 --- a/admin/linkbar.php +++ b/admin/linkbar.php @@ -9,6 +9,7 @@ function linkbar()
  • Home
  • Options
  • Create Identity
  • +
  • Local Identities
  • Introduce Identity
  • Introduction Status
  • Manually Add Peer
  • diff --git a/admin/localidentities.php b/admin/localidentities.php new file mode 100644 index 0000000..b98f420 --- /dev/null +++ b/admin/localidentities.php @@ -0,0 +1,102 @@ + + + prepare("UPDATE tblLocalIdentity SET SingleUse=?, PublishTrustList=? WHERE LocalIdentityID=?;"); + for($i=0; $ibindParam(1,$_REQUEST['singleuse'][$_REQUEST['update'][$i]]); + $st->bindParam(2,$_REQUEST['publishtrustlist'][$_REQUEST['update'][$i]]); + $st->bindParam(3,$_REQUEST['localidentityid'][$_REQUEST['update'][$i]]); + $st->execute(); + } + } + } + if($_REQUEST['formaction']=='delete' && isset($_REQUEST['update'])) + { + $st=$db->prepare("DELETE FROM tblLocalIdentity WHERE LocalIdentityID=?;"); + + for($i=0; $ibindParam(1,$_REQUEST['localidentityid'][$_REQUEST['update'][$i]]); + $st->execute(); + } + } + } + } + + $st=$db->prepare("SELECT LocalIdentityID,Name,PublicKey,PublishTrustList,SingleUse,PublishBoardList FROM tblLocalIdentity ORDER BY Name;"); + $st->execute(); + ?> +

    Local Identities

    +
    + + + + + + + + + fetch()) + { + ?> + + + + + + + +
    NameSingle UsePublish Trust List
    + + + + + + + + +
    + + +
    + \ No newline at end of file diff --git a/include/global.h b/include/global.h index 2b0fe20..1eccbcc 100644 --- a/include/global.h +++ b/include/global.h @@ -4,7 +4,7 @@ #include #include -#define FMS_VERSION "0.1.1" +#define FMS_VERSION "0.1.2" // opens database and creates tables and initial inserts if necessary void SetupDB(); diff --git a/include/nntp/nntplistener.h b/include/nntp/nntplistener.h index e74ca9c..53b5d86 100644 --- a/include/nntp/nntplistener.h +++ b/include/nntp/nntplistener.h @@ -3,6 +3,7 @@ #include #include +#include #include #include #include diff --git a/src/freenet/identityinserter.cpp b/src/freenet/identityinserter.cpp index 571546a..aa1f4ab 100644 --- a/src/freenet/identityinserter.cpp +++ b/src/freenet/identityinserter.cpp @@ -80,7 +80,14 @@ const bool IdentityInserter::HandleMessage(FCPMessage &message) if(message.GetName()=="PutSuccessful") { - m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false', LastInsertedIdentity='"+now.Format("%Y-%m-%d %H:%M:%S")+"' WHERE LocalIdentityID="+idparts[1]+";"); + // a little hack here - if we just inserted index yesterday and it is now the next day - we would have inserted todays date not yesterdays as LastInsertedIdentity. + // If this is the case, we will skip updating LastInsertedIdentity so that we can insert this identity again for today + DateTime lastdate; + lastdate.Set(idparts[4]); + if(lastdate.GetDay()!=now.GetDay()) + { + m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false', LastInsertedIdentity='"+now.Format("%Y-%m-%d %H:%M:%S")+"' WHERE LocalIdentityID="+idparts[1]+";"); + } m_db->Execute("INSERT INTO tblLocalIdentityInserts(LocalIdentityID,Day,InsertIndex) VALUES("+idparts[1]+",'"+idparts[4]+"',"+idparts[2]+");"); m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"IdentityInserter::HandleMessage inserted Identity xml"); return true; diff --git a/src/freenet/identityintroductionrequester.cpp b/src/freenet/identityintroductionrequester.cpp index 9fee644..dc3a120 100644 --- a/src/freenet/identityintroductionrequester.cpp +++ b/src/freenet/identityintroductionrequester.cpp @@ -88,10 +88,12 @@ const bool IdentityIntroductionRequester::HandleAllData(FCPMessage &message) st.Step(); } st.Finalize(); + + m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"IdentityIntroductionRequester::HandleAddData parsed a valid identity."); } else { - m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IdentityIntroductionRequester::HandleAllData parsed public SSK key was not valid."); + m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IdentityIntroductionRequester::HandleAllData parsed, public SSK key was not valid."); } m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"IdentityIntroductionRequester::HandleAllData parsed IdentityIntroduction XML file : "+message["Identifier"]); diff --git a/src/freenet/introductionpuzzleinserter.cpp b/src/freenet/introductionpuzzleinserter.cpp index a4b6617..9dca8e0 100644 --- a/src/freenet/introductionpuzzleinserter.cpp +++ b/src/freenet/introductionpuzzleinserter.cpp @@ -27,11 +27,17 @@ void IntroductionPuzzleInserter::CheckForNeededInsert() while(!rs.AtEnd()) { + std::string localidentityidstr; DateTime now; now.SetToGMTime(); + if(rs.GetField(0)) + { + localidentityidstr=rs.GetField(0); + } + // if this identity has any non-solved puzzles for today, we don't need to insert a new puzzle - SQLite3DB::Recordset rs2=m_db->Query("SELECT UUID FROM tblIntroductionPuzzleInserts WHERE Day='"+now.Format("%Y-%m-%d")+"' AND FoundSolution='false';"); + SQLite3DB::Recordset rs2=m_db->Query("SELECT UUID FROM tblIntroductionPuzzleInserts WHERE Day='"+now.Format("%Y-%m-%d")+"' AND FoundSolution='false' AND LocalIdentityID="+localidentityidstr+";"); // identity doesn't have any non-solved puzzles for today - start a new insert if(rs2.Empty()==true) diff --git a/src/freenet/messagelistinserter.cpp b/src/freenet/messagelistinserter.cpp index 09a6137..1e3a92a 100644 --- a/src/freenet/messagelistinserter.cpp +++ b/src/freenet/messagelistinserter.cpp @@ -29,10 +29,10 @@ void MessageListInserter::CheckForNeededInsert() previous.Add(0,0,0,-m_daysbackward); - // query for identities that have messages in the past X days and we haven't inserted lists for in the past hour + // query for identities that have messages in the past X days and we haven't inserted lists for in the past 30 minutes SQLite3DB::Statement st=m_db->Prepare("SELECT tblLocalIdentity.LocalIdentityID FROM tblLocalIdentity INNER JOIN tblMessageInserts ON tblLocalIdentity.LocalIdentityID=tblMessageInserts.LocalIdentityID WHERE tblMessageInserts.Day>=? AND (tblLocalIdentity.LastInsertedMessageList<=? OR tblLocalIdentity.LastInsertedMessageList IS NULL OR tblLocalIdentity.LastInsertedMessageList='');"); st.Bind(0,previous.Format("%Y-%m-%d")); - st.Bind(1,(now-(1.0/24.0)).Format("%Y-%m-%d %H:%M:%S")); + st.Bind(1,(now-(1.0/48.0)).Format("%Y-%m-%d %H:%M:%S")); st.Step(); if(st.RowReturned()) diff --git a/src/freenet/messagelistrequester.cpp b/src/freenet/messagelistrequester.cpp index 763ba9f..2a13af7 100644 --- a/src/freenet/messagelistrequester.cpp +++ b/src/freenet/messagelistrequester.cpp @@ -81,7 +81,7 @@ const bool MessageListRequester::HandleAllData(FCPMessage &message) st.Step(); st.Finalize(); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"MessageListRequester::HandleAllData parsed TrustList XML file : "+message["Identifier"]); + m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"MessageListRequester::HandleAllData parsed MessageList XML file : "+message["Identifier"]); } else { diff --git a/src/freenet/trustlistinserter.cpp b/src/freenet/trustlistinserter.cpp index bd8f87c..6cd8843 100644 --- a/src/freenet/trustlistinserter.cpp +++ b/src/freenet/trustlistinserter.cpp @@ -126,15 +126,18 @@ void TrustListInserter::StartInsert(const long localidentityid, const std::strin std::string publickey; int messagetrust; int trustlisttrust; - DateTime now; + DateTime now,date; int index; std::string indexstr; std::string localidentityidstr; now.SetToGMTime(); - - // build the xml file - SQLite3DB::Statement st=m_db->Prepare("SELECT PublicKey, LocalMessageTrust, LocalTrustListTrust FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey<>'';"); + date.SetToGMTime(); + + // build the xml file - we only want to add identities that we recently saw, otherwise we could be inserting a ton of identities + date.Add(0,0,0,-20); // identities seen in last 20 days + SQLite3DB::Statement st=m_db->Prepare("SELECT PublicKey, LocalMessageTrust, LocalTrustListTrust FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey<>'' AND LastSeen>=?;"); + st.Bind(0,date.Format("%Y-%m-%d")); st.Step(); while(st.RowReturned()) { diff --git a/src/global.cpp b/src/global.cpp index cf531de..48c3842 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -18,6 +18,7 @@ void SetupDB() { + DateTime date; SQLite3DB::DB *db=SQLite3DB::DB::instance(); db->Open("fms.db3"); @@ -212,21 +213,21 @@ void SetupDB() GROUP BY TargetIdentityID;"); // update PeerTrustLevel when deleting a record from tblPeerTrust - db->Execute("CREATE TRIGGER trgDeleteOntblPeerTrust AFTER DELETE ON tblPeerTrust \ + db->Execute("CREATE TRIGGER IF NOT EXISTS trgDeleteOntblPeerTrust AFTER DELETE ON tblPeerTrust \ FOR EACH ROW \ BEGIN \ UPDATE tblIdentity SET PeerMessageTrust=(SELECT PeerMessageTrust FROM vwCalculatedPeerTrust WHERE TargetIdentityID=old.TargetIdentityID), PeerTrustListTrust=(SELECT PeerTrustListTrust FROM vwCalculatedPeerTrust WHERE TargetIdentityID=old.TargetIdentityID) WHERE IdentityID=old.TargetIdentityID;\ END;"); // update PeerTrustLevel when inserting a record into tblPeerTrust - db->Execute("CREATE TRIGGER trgInsertOntblPeerTrust AFTER INSERT ON tblPeerTrust \ + db->Execute("CREATE TRIGGER IF NOT EXISTS trgInsertOntblPeerTrust AFTER INSERT ON tblPeerTrust \ FOR EACH ROW \ BEGIN \ UPDATE tblIdentity SET PeerMessageTrust=(SELECT PeerMessageTrust FROM vwCalculatedPeerTrust WHERE TargetIdentityID=new.TargetIdentityID), PeerTrustListTrust=(SELECT PeerTrustListTrust FROM vwCalculatedPeerTrust WHERE TargetIdentityID=new.TargetIdentityID) WHERE IdentityID=new.TargetIdentityID;\ END;"); // update PeerTrustLevel when updating a record in tblPeerTrust - db->Execute("CREATE TRIGGER trgUpdateOntblPeerTrust AFTER UPDATE ON tblPeerTrust \ + db->Execute("CREATE TRIGGER IF NOT EXISTS trgUpdateOntblPeerTrust AFTER UPDATE ON tblPeerTrust \ FOR EACH ROW \ BEGIN \ UPDATE tblIdentity SET PeerMessageTrust=(SELECT PeerMessageTrust FROM vwCalculatedPeerTrust WHERE TargetIdentityID=old.TargetIdentityID), PeerTrustListTrust=(SELECT PeerTrustListTrust FROM vwCalculatedPeerTrust WHERE TargetIdentityID=old.TargetIdentityID) WHERE IdentityID=old.TargetIdentityID;\ @@ -234,15 +235,50 @@ void SetupDB() END;"); // recalculate all Peer TrustLevels when updating Local TrustLevels on tblIdentity - doesn't really need to be all, but rather all identities the updated identity has a trust level for. It's easier to update everyone for now. - db->Execute("CREATE TRIGGER trgUpdateLocalTrustLevels AFTER UPDATE OF LocalMessageTrust,LocalTrustListTrust ON tblIdentity \ + db->Execute("CREATE TRIGGER IF NOT EXISTS trgUpdateLocalTrustLevels AFTER UPDATE OF LocalMessageTrust,LocalTrustListTrust ON tblIdentity \ FOR EACH ROW \ 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 \ + BEGIN \ + DELETE FROM tblMessageBoard WHERE tblMessageBoard.MessageID=old.MessageID;\ + DELETE FROM tblMessageReplyTo WHERE tblMessageReplyTo.MessageID=old.MessageID;\ + END;"); + + db->Execute("CREATE TRIGGER IF NOT EXISTS trgDeleteIdentity AFTER DELETE ON tblIdentity \ + FOR EACH ROW \ + BEGIN \ + DELETE FROM tblIdentityRequests WHERE IdentityID=old.IdentityID;\ + DELETE FROM tblIntroductionPuzzleRequests WHERE IdentityID=old.IdentityID;\ + DELETE FROM tblMessageListRequests WHERE IdentityID=old.IdentityID;\ + DELETE FROM tblMessageRequests WHERE IdentityID=old.IdentityID;\ + DELETE FROM tblPeerTrust WHERE IdentityID=old.IdentityID;\ + DELETE FROM tblTrustListRequests WHERE IdentityID=old.IdentityID;\ + END;"); + + db->Execute("CREATE TRIGGER IF NOT EXISTS trgDeleteLocalIdentity AFTER DELETE ON tblLocalIdentity \ + FOR EACH ROW \ + BEGIN \ + DELETE FROM tblIdentityIntroductionInserts WHERE LocalIdentityID=old.LocalIdentityID;\ + DELETE FROM tblIntroductionPuzzleInserts WHERE LocalIdentityID=old.LocalIdentityID;\ + DELETE FROM tblLocalIdentityInserts WHERE LocalIdentityID=old.LocalIdentityID;\ + DELETE FROM tblMessageInserts WHERE LocalIdentityID=old.LocalIdentityID;\ + DELETE FROM tblMessageListInserts WHERE LocalIdentityID=old.LocalIdentityID;\ + DELETE FROM tblTrustListInserts WHERE LocalIdentityID=old.LocalIdentityID;\ + END;"); + // delete introduction puzzles that were half-way inserted db->Execute("DELETE FROM tblIntroductionPuzzleInserts WHERE Day IS NULL AND InsertIndex IS NULL;"); + // delete stale introduction puzzles (2 or more days old) + date.SetToGMTime(); + date.Add(0,0,0,-2); + db->Execute("DELETE FROM tblIntroductionPuzzleInserts WHERE Day<='"+date.Format("%Y-%m-%d")+"';"); + db->Execute("DELETE FROM tblIntroductionPuzzleRequests WHERE Day<='"+date.Format("%Y-%m-%d")+"';"); + } void SetupDefaultOptions() @@ -439,6 +475,7 @@ void ShutdownThreads(std::vector &threads) for(i=threads.begin(); i!=threads.end(); i++) { + LogFile::instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"ShutdownThreads waiting for thread to exit."); (*i)->wait(); delete (*i); } diff --git a/src/nntp/nntpconnection.cpp b/src/nntp/nntpconnection.cpp index ac75d4d..d677c8f 100644 --- a/src/nntp/nntpconnection.cpp +++ b/src/nntp/nntpconnection.cpp @@ -1163,9 +1163,11 @@ void NNTPConnection::SocketReceive() } else if(rval==-1) { + std::string errnostr; + StringFunctions::Convert(GetSocketErrorNumber(),errnostr); // error on receive - close the connection Disconnect(); - m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPConnection::SocketReceive recv returned -1 : "+GetSocketErrorMessage()); + m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPConnection::SocketReceive recv returned -1 : "+errnostr+" - "+GetSocketErrorMessage()); } } @@ -1180,7 +1182,9 @@ void NNTPConnection::SocketSend() } else if(rval==-1) { - m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPConnection::SocketSend returned -1 : "+GetSocketErrorMessage()); + std::string errnostr; + StringFunctions::Convert(GetSocketErrorNumber(),errnostr); + m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPConnection::SocketSend returned -1 : "+errnostr+" - "+GetSocketErrorMessage()); } } } diff --git a/src/nntp/nntplistener.cpp b/src/nntp/nntplistener.cpp index 29f8eb4..01b008d 100644 --- a/src/nntp/nntplistener.cpp +++ b/src/nntp/nntplistener.cpp @@ -82,15 +82,30 @@ void NNTPListener::run() // see if any threads are still running - just calling interrupt without check would cause assert in debug mode if(m_connections.wait(1)==false) { + LogFile::instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPListener::run interrupting connection threads and waiting 60 seconds for exit."); try { m_connections.interrupt(); } catch(...) { + LogFile::instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPListener::run caught unhandled exception."); } - m_connections.wait(); + if(m_connections.wait(60)==false) + { + LogFile::instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPListener::run connection threads did not exit after 60 seconds."); + } + } + + for(listeni=m_listensockets.begin(); listeni!=m_listensockets.end(); listeni++) + { + #ifdef _WIN32 + closesocket((*listeni)); + #else + close((*listeni)); + #endif } + m_listensockets.clear(); } -- 2.7.4