version 0.2.7
authorSomeDude <SomeDude@NuBL7aaJ6Cn4fB7GXFb9Zfi8w1FhPyW3oKgU9TweZMw>
Wed, 2 Apr 2008 14:49:00 +0000 (16:49 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Wed, 2 Apr 2008 14:49:00 +0000 (16:49 +0200)
15 files changed:
include/global.h
include/http/pages/peertrustpage.h
include/message.h
readme.txt
src/freenet/freenetmasterthread.cpp
src/freenet/messagerequester.cpp
src/freenet/siteinserter.cpp
src/freenet/trustlistinserter.cpp
src/global.cpp
src/http/pages/announceidentitypage.cpp
src/http/pages/localidentitiespage.cpp
src/http/pages/peerdetailspage.cpp
src/http/pages/peertrustpage.cpp
src/main.cpp
src/message.cpp

index 8b781f9..834f605 100644 (file)
@@ -4,7 +4,7 @@
 #include <vector>\r
 #include "pthreadwrapper/thread.h"\r
 \r
-#define FMS_VERSION    "0.2.6"\r
+#define FMS_VERSION    "0.2.7"\r
 \r
 // opens database and creates tables and initial inserts if necessary\r
 void SetupDB();\r
@@ -19,6 +19,8 @@ void SetupDefaultOptions();
 // opens logfile and sets it up\r
 void SetupLogFile();\r
 \r
+std::string CreateShortIdentityName(const std::string &name, const std::string &publickey);\r
+\r
 // TODO remove sometime after 0.1.17\r
 void FixCapitalBoardNames();\r
 \r
index 8f91446..851296f 100644 (file)
@@ -14,8 +14,9 @@ private:
        const std::string GeneratePage(const std::string &method, const std::map<std::string,std::string> &queryvars);\r
 \r
        const std::string GetClassString(const std::string &trustlevel);\r
-       const std::string BuildQueryString(const long startrow, const std::string &namesearch, const std::string &sortby, const std::string &sortorder);\r
+       const std::string BuildQueryString(const long startrow, const std::string &namesearch, const std::string &sortby, const std::string &sortorder, const int localidentityid);\r
        const std::string ReverseSort(const std::string &sortname, const std::string &currentsortby, const std::string &currentsortorder);\r
+       const std::string CreateLocalIdentityDropDown(const std::string &name, const int selectedlocalidentityid);\r
 \r
 };\r
 \r
index 3033229..eda6752 100644 (file)
@@ -55,6 +55,7 @@ private:
        const bool CheckForAdministrationBoard(const std::vector<std::string> &boards);\r
        void HandleChangeTrust();\r
        void StripAdministrationBoards();       // removes administration boards from boards vector\r
+       const int FindLocalIdentityID(const std::string &name);\r
 \r
        long m_messageid;\r
        bool m_addnewpostfromidentities;\r
index 593a99f..db879dc 100644 (file)
@@ -83,6 +83,13 @@ trust to arbitrary identities.  Pick whom you trust wisely.  The settings for
 minimum trust before downloading messages and trust lists can be changed on the\r
 web interface.\r
 \r
+You must have a local identity created before you can set trust levels.  Even\r
+if you don't want to post messages, you must still create an identity, but you\r
+do not have to announce it.  This way, no-one will know about that identity and\r
+you will be able to set trust.  If you have multiple identities, each with\r
+different trust levels for peers, the highest trust level set for a peer will\r
+determine if messages/trust lists are downloaded from them.\r
+\r
 A note on NULL trust:  If you neither trust or distrust an identity, they will\r
 have NULL trust (no trust at all).  You will download messages and trust lists\r
 from identities with NULL peer trust as long as the local trust level is at or\r
index 4e7b570..db72906 100644 (file)
@@ -245,7 +245,7 @@ void FreenetMasterThread::Run()
 \r
                        if(m_fcp.Connected()==false)\r
                        {\r
-                               m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"FreenetMasterThread::Run Disconnected from Freenet node.");\r
+                               m_log->WriteLog(LogFile::LOGLEVEL_INFO,"FreenetMasterThread::Run Disconnected from Freenet node.");\r
                        }\r
 \r
                }\r
index 5b6d271..c9b78bb 100644 (file)
@@ -376,6 +376,7 @@ void MessageRequester::PopulateIDList()
        sql+="WHERE (tblIdentity.LocalMessageTrust IS NULL OR tblIdentity.LocalMessageTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalMessageTrust')) ";\r
        sql+="AND FromMessageList='true' AND Found='false' AND Day>='"+date.Format("%Y-%m-%d")+"' ";\r
        sql+="AND (tblIdentity.PeerMessageTrust IS NULL OR tblIdentity.PeerMessageTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinPeerMessageTrust')) ";\r
+       sql+="AND tblIdentity.Name <> '' ";\r
        sql+=";";\r
 \r
        SQLite3DB::Statement st=m_db->Prepare(sql);\r
index f943f56..76bfb95 100644 (file)
@@ -1,4 +1,5 @@
 #include "../../include/freenet/siteinserter.h"\r
+#include "../../include/global.h"\r
 \r
 #ifdef XMEM\r
        #include <xmem.h>\r
@@ -191,8 +192,9 @@ std::string SiteInserter::GenerateTrustList(const std::string &htmltemplate, con
 \r
        date.SetToGMTime();\r
        date.Add(0,0,0,-20);\r
-       SQLite3DB::Statement st=m_db->Prepare("SELECT Name,PublicKey,LocalMessageTrust,LocalTrustListTrust,IdentityID,MessageTrustComment,TrustListTrustComment FROM tblIdentity WHERE PublicKey IS NOT NULL AND LastSeen IS NOT NULL AND LastSeen>=? ORDER BY Name COLLATE NOCASE;");\r
-       st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S"));\r
+       SQLite3DB::Statement st=m_db->Prepare("SELECT Name,PublicKey,tblIdentityTrust.LocalMessageTrust,tblIdentityTrust.LocalTrustListTrust,tblIdentity.IdentityID,tblIdentityTrust.MessageTrustComment,tblIdentityTrust.TrustListTrustComment FROM tblIdentity LEFT JOIN (SELECT IdentityID,LocalMessageTrust,LocalTrustListTrust,MessageTrustComment,TrustListTrustComment FROM tblIdentityTrust WHERE LocalIdentityID=?) AS 'tblIdentityTrust' ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID WHERE PublicKey IS NOT NULL AND LastSeen IS NOT NULL AND LastSeen>=? ORDER BY Name COLLATE NOCASE;");\r
+       st.Bind(0,localidentityid);\r
+       st.Bind(1,date.Format("%Y-%m-%d %H:%M:%S"));\r
        st.Step();\r
 \r
        content+="<table>";\r
@@ -209,7 +211,6 @@ std::string SiteInserter::GenerateTrustList(const std::string &htmltemplate, con
                std::string messagetrust="";\r
                std::string trustlisttrust="";\r
                std::string publickey="";\r
-               std::string keypart="";\r
                std::string uskkey="";\r
 \r
                st.ResultText(0,idname);\r
@@ -220,11 +221,6 @@ std::string SiteInserter::GenerateTrustList(const std::string &htmltemplate, con
                st.ResultText(5,messagetrustcomment);\r
                st.ResultText(6,trustlisttrustcomment);\r
 \r
-               if(publickey.size()>8)\r
-               {\r
-                       keypart=publickey.substr(3,5);\r
-               }\r
-\r
                if(publickey.find("SSK@")==0)\r
                {\r
                        uskkey=publickey;\r
@@ -234,7 +230,7 @@ std::string SiteInserter::GenerateTrustList(const std::string &htmltemplate, con
                }\r
 \r
                content+="<tr>";\r
-               content+="<td><a href=\""+uskkey+"\">"+SanitizeOutput(idname+keypart)+"...</a></td>";\r
+               content+="<td><a href=\""+uskkey+"\">"+SanitizeOutput(CreateShortIdentityName(idname,publickey))+"</a></td>";\r
                content+="<td "+GetClassString(messagetrust)+">"+messagetrust+"</td>";\r
                content+="<td>"+SanitizeOutput(messagetrustcomment)+"</td>";\r
                content+="<td "+GetClassString(trustlisttrust)+">"+trustlisttrust+"</td>";\r
index 79745ee..8962d5e 100644 (file)
@@ -142,10 +142,16 @@ void TrustListInserter::StartInsert(const long localidentityid, const std::strin
        now.SetToGMTime();\r
        date.SetToGMTime();\r
 \r
+       // insert all identities not in trust list already\r
+       m_db->Execute("INSERT INTO tblIdentityTrust(LocalIdentityID,IdentityID) SELECT LocalIdentityID,IdentityID FROM tblLocalIdentity,tblIdentity WHERE LocalIdentityID || '_' || IdentityID NOT IN (SELECT LocalIdentityID || '_' || IdentityID FROM tblIdentityTrust);");\r
+\r
        // build the xml file - we only want to add identities that we recently saw, otherwise we could be inserting a ton of identities\r
        date.Add(0,0,0,-20);    // identities seen in last 20 days\r
-       SQLite3DB::Statement st=m_db->Prepare("SELECT PublicKey, LocalMessageTrust, LocalTrustListTrust, MessageTrustComment, TrustListTrustComment FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey<>'' AND LastSeen>=?;");\r
+       //SQLite3DB::Statement st=m_db->Prepare("SELECT PublicKey, LocalMessageTrust, LocalTrustListTrust, MessageTrustComment, TrustListTrustComment FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey<>'' AND LastSeen>=?;");\r
+       // we want to order by public key so we can't do identity correllation based on the sequence of identities in the list.\r
+       SQLite3DB::Statement st=m_db->Prepare("SELECT PublicKey, tblIdentityTrust.LocalMessageTrust, tblIdentityTrust.LocalTrustListTrust, tblIdentityTrust.MessageTrustComment, tblIdentityTrust.TrustListTrustComment FROM tblIdentity INNER JOIN tblIdentityTrust ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID WHERE PublicKey IS NOT NULL AND PublicKey<>'' AND LastSeen>=? AND tblIdentityTrust.LocalIdentityID=? ORDER BY PublicKey;");\r
        st.Bind(0,date.Format("%Y-%m-%d"));\r
+       st.Bind(1,localidentityid);\r
        st.Step();\r
        while(st.RowReturned())\r
        {\r
index aa87b99..7889810 100644 (file)
 \r
 bool wantshutdown=false;\r
 \r
+std::string CreateShortIdentityName(const std::string &name, const std::string &publickey)\r
+{\r
+       std::string result="";\r
+       std::vector<std::string> keyparts;\r
+\r
+       StringFunctions::SplitMultiple(publickey,"@,",keyparts);\r
+\r
+       result+=name;\r
+       if(keyparts.size()>1 && keyparts[1].size()>8)\r
+       {\r
+               result+="@"+keyparts[1].substr(0,4)+"...";\r
+       }\r
+\r
+       return result;\r
+}\r
+\r
 void SetupDB()\r
 {\r
 \r
@@ -27,7 +43,7 @@ void SetupDB()
 \r
        db->Open("fms.db3");\r
        db->SetBusyTimeout(10000);              // set timeout to 10 seconds\r
-       db->Execute("VACUUM;");\r
+       //db->Execute("VACUUM;");               // not needed every startup\r
 \r
        db->Execute("CREATE TABLE IF NOT EXISTS tblDBVersion(\\r
                                Major                           INTEGER,\\r
@@ -192,6 +208,35 @@ void SetupDB()
                                Inserted                        BOOL CHECK(Inserted IN('true','false')) DEFAULT 'false'\\r
                                );");\r
 \r
+       db->Execute("CREATE TABLE IF NOT EXISTS tblIdentityTrust(\\r
+                               LocalIdentityID                 INTEGER,\\r
+                               IdentityID                              INTEGER,\\r
+                               LocalMessageTrust               INTEGER CHECK(LocalMessageTrust BETWEEN 0 AND 100) DEFAULT NULL,\\r
+                               MessageTrustComment             TEXT,\\r
+                               LocalTrustListTrust             INTEGER CHECK(LocalTrustListTrust BETWEEN 0 AND 100) DEFAULT NULL,\\r
+                               TrustListTrustComment   TEXT\\r
+                               );");\r
+\r
+       db->Execute("CREATE UNIQUE INDEX IF NOT EXISTS idxIdentityTrust_IDs ON tblIdentityTrust(LocalIdentityID,IdentityID);");\r
+\r
+       db->Execute("CREATE TRIGGER IF NOT EXISTS trgInsertOnIdentityTrust AFTER INSERT ON tblIdentityTrust \\r
+                               FOR EACH ROW \\r
+                               BEGIN \\r
+                                       UPDATE tblIdentity SET LocalMessageTrust=(SELECT MAX(LocalMessageTrust) FROM tblIdentityTrust WHERE tblIdentityTrust.IdentityID=new.IdentityID GROUP BY tblIdentityTrust.IdentityID), LocalTrustListTrust=(SELECT MAX(LocalTrustListTrust) FROM tblIdentityTrust WHERE tblIdentityTrust.IdentityID=new.IdentityID GROUP BY tblIdentityTrust.IdentityID) WHERE tblIdentity.IdentityID=new.IdentityID; \\r
+                               END;");\r
+\r
+       db->Execute("CREATE TRIGGER IF NOT EXISTS trgUpdateOnIdentityTrust AFTER UPDATE OF LocalMessageTrust,LocalTrustListTrust ON tblIdentityTrust \\r
+                               FOR EACH ROW \\r
+                               BEGIN \\r
+                                       UPDATE tblIdentity SET LocalMessageTrust=(SELECT MAX(LocalMessageTrust) FROM tblIdentityTrust WHERE tblIdentityTrust.IdentityID=new.IdentityID GROUP BY tblIdentityTrust.IdentityID), LocalTrustListTrust=(SELECT MAX(LocalTrustListTrust) FROM tblIdentityTrust WHERE tblIdentityTrust.IdentityID=new.IdentityID GROUP BY tblIdentityTrust.IdentityID) WHERE tblIdentity.IdentityID=new.IdentityID; \\r
+                               END;");\r
+\r
+       db->Execute("CREATE TRIGGER IF NOT EXISTS trgDeleteOnIdentityTrust AFTER DELETE ON tblIdentityTrust \\r
+                               FOR EACH ROW \\r
+                               BEGIN \\r
+                                       UPDATE tblIdentity SET LocalMessageTrust=(SELECT MAX(LocalMessageTrust) FROM tblIdentityTrust WHERE tblIdentityTrust.IdentityID=old.IdentityID GROUP BY tblIdentityTrust.IdentityID), LocalTrustListTrust=(SELECT MAX(LocalTrustListTrust) FROM tblIdentityTrust WHERE tblIdentityTrust.IdentityID=old.IdentityID GROUP BY tblIdentityTrust.IdentityID) WHERE tblIdentity.IdentityID=old.IdentityID; \\r
+                               END;");\r
+\r
        db->Execute("CREATE TABLE IF NOT EXISTS tblPeerTrust(\\r
                                IdentityID                              INTEGER,\\r
                                TargetIdentityID                INTEGER,\\r
@@ -386,6 +431,7 @@ void SetupDB()
                                        DELETE FROM tblTrustListRequests WHERE IdentityID=old.IdentityID;\\r
                                END;");\r
 \r
+       db->Execute("DROP TRIGGER IF EXISTS trgDeleteLocalIdentity;");\r
        db->Execute("CREATE TRIGGER IF NOT EXISTS trgDeleteLocalIdentity AFTER DELETE ON tblLocalIdentity \\r
                                FOR EACH ROW \\r
                                BEGIN \\r
@@ -395,6 +441,7 @@ void SetupDB()
                                        DELETE FROM tblMessageInserts WHERE LocalIdentityID=old.LocalIdentityID;\\r
                                        DELETE FROM tblMessageListInserts WHERE LocalIdentityID=old.LocalIdentityID;\\r
                                        DELETE FROM tblTrustListInserts WHERE LocalIdentityID=old.LocalIdentityID;\\r
+                                       DELETE FROM tblIdentityTrust WHERE LocalIdentityID=old.LocalIdentityID;\\r
                                END;");\r
 \r
        db->Execute("CREATE TRIGGER IF NOT EXISTS trgDeleteBoard AFTER DELETE ON tblBoard \\r
index 32a13cc..83ce674 100644 (file)
@@ -1,6 +1,7 @@
 #include "../../../include/http/pages/announceidentitypage.h"\r
 #include "../../../include/stringfunctions.h"\r
 #include "../../../include/datetime.h"\r
+#include "../../../include/global.h"\r
 \r
 #ifdef XMEM\r
        #include <xmem.h>\r
@@ -18,18 +19,12 @@ const std::string AnnounceIdentityPage::CreateLocalIdentityDropDown(const std::s
                std::string id;\r
                std::string name;\r
                std::string pubkey;\r
-               std::string keypart="";\r
 \r
                st.ResultText(0,id);\r
                st.ResultText(1,name);\r
                st.ResultText(2,pubkey);\r
 \r
-               if(pubkey.size()>8)\r
-               {\r
-                       keypart=pubkey.substr(3,5);\r
-               }\r
-\r
-               rval+="<option value=\""+id+"\" title=\""+pubkey+"\">"+SanitizeOutput(name+keypart)+"...</option>";\r
+               rval+="<option value=\""+id+"\" title=\""+pubkey+"\">"+SanitizeOutput(CreateShortIdentityName(name,pubkey))+"</option>";\r
                st.Step();\r
        }\r
        rval+="</select>";\r
index c0b6105..8b26238 100644 (file)
@@ -1,6 +1,7 @@
 #include "../../../include/http/pages/localidentitiespage.h"\r
 #include "../../../include/stringfunctions.h"\r
 #include "../../../include/http/identityexportxml.h"\r
+#include "../../../include/global.h"\r
 \r
 #ifdef XMEM\r
        #include <xmem.h>\r
@@ -221,7 +222,6 @@ const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, c
                std::string publickey="";\r
                std::string publishtrustlist="";\r
                std::string singleuse="";\r
-               std::string keypart="";\r
                std::string publishboardlist="";\r
                std::string publishfreesite="";\r
 \r
@@ -233,14 +233,9 @@ const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, c
                st.ResultText(5,publishboardlist);\r
                st.ResultText(7,publishfreesite);\r
 \r
-               if(publickey.size()>8)\r
-               {\r
-                       keypart=publickey.substr(3,5);\r
-               }\r
-\r
                content+="<tr>";\r
 //             content+="<td><input type=\"checkbox\" name=\"chkidentityid["+countstr+"]\" value=\""+id+"\"></td>";\r
-               content+="<td title=\""+publickey+"\"><form name=\"frmupdate\""+countstr+"\" method=\"POST\"><input type=\"hidden\" name=\"formaction\" value=\"update\"><input type=\"hidden\" name=\"chkidentityid["+countstr+"]\" value=\""+id+"\">"+SanitizeOutput(name+keypart)+"...</td>";\r
+               content+="<td title=\""+publickey+"\"><form name=\"frmupdate\""+countstr+"\" method=\"POST\"><input type=\"hidden\" name=\"formaction\" value=\"update\"><input type=\"hidden\" name=\"chkidentityid["+countstr+"]\" value=\""+id+"\">"+SanitizeOutput(CreateShortIdentityName(name,publickey))+"</td>";\r
                content+="<td>"+CreateTrueFalseDropDown("singleuse["+countstr+"]",singleuse)+"</td>";\r
                content+="<td>"+CreateTrueFalseDropDown("publishtrustlist["+countstr+"]",publishtrustlist)+"</td>";\r
                content+="<td>"+CreateTrueFalseDropDown("publishboardlist["+countstr+"]",publishboardlist)+"</td>";\r
index 6d05231..78ea02c 100644 (file)
@@ -1,6 +1,7 @@
 #include "../../../include/http/pages/peerdetailspage.h"\r
 #include "../../../include/stringfunctions.h"\r
 #include "../../../include/option.h"\r
+#include "../../../include/global.h"\r
 \r
 #ifdef XMEM\r
        #include <xmem.h>\r
@@ -15,7 +16,6 @@ const std::string PeerDetailsPage::GeneratePage(const std::string &method, const
        std::string publickey;\r
        std::string messagetrust;\r
        std::string trustlisttrust;\r
-       std::string keypart="";\r
        std::string lastseen="";\r
        std::string dateadded="";\r
        std::string addedmethod="";\r
@@ -144,13 +144,8 @@ const std::string PeerDetailsPage::GeneratePage(const std::string &method, const
                st.ResultText(5,messagetrustcomment);\r
                st.ResultText(6,trustlisttrustcomment);\r
 \r
-               if(publickey.size()>8)\r
-               {\r
-                       keypart=publickey.substr(3,5);\r
-               }\r
-\r
                content+="<tr>";\r
-               content+="<td><a href=\"peerdetails.htm?identityid="+thisid+"\">"+SanitizeOutput(name+keypart)+"...</a></td>";\r
+               content+="<td><a href=\"peerdetails.htm?identityid="+thisid+"\">"+SanitizeOutput(CreateShortIdentityName(name,publickey))+"</a></td>";\r
                content+="<td "+GetClassString(messagetrust)+">"+messagetrust+"</td>";\r
                content+="<td>"+SanitizeOutput(messagetrustcomment)+"</td>";\r
                content+="<td "+GetClassString(trustlisttrust)+">"+trustlisttrust+"</td>";\r
@@ -182,14 +177,9 @@ const std::string PeerDetailsPage::GeneratePage(const std::string &method, const
                st.ResultText(4,thisid);\r
                st.ResultText(5,messagetrustcomment);\r
                st.ResultText(6,trustlisttrustcomment);\r
-               \r
-               if(publickey.size()>8)\r
-               {\r
-                       keypart=publickey.substr(3,5);\r
-               }\r
 \r
                content+="<tr>";\r
-               content+="<td><a href=\"peerdetails.htm?identityid="+thisid+"\">"+SanitizeOutput(name+keypart)+"...</a></td>";\r
+               content+="<td><a href=\"peerdetails.htm?identityid="+thisid+"\">"+SanitizeOutput(CreateShortIdentityName(name,publickey))+"</a></td>";\r
                content+="<td "+GetClassString(messagetrust)+">"+messagetrust+"</td>";\r
                content+="<td>"+SanitizeOutput(messagetrustcomment)+"</td>";\r
                content+="<td "+GetClassString(trustlisttrust)+">"+trustlisttrust+"</td>";\r
index 9429ede..21b0730 100644 (file)
@@ -1,11 +1,12 @@
 #include "../../../include/http/pages/peertrustpage.h"\r
 #include "../../../include/stringfunctions.h"\r
+#include "../../../include/global.h"\r
 \r
 #ifdef XMEM\r
        #include <xmem.h>\r
 #endif\r
 \r
-const std::string PeerTrustPage::BuildQueryString(const long startrow, const std::string &namesearch, const std::string &sortby, const std::string &sortorder)\r
+const std::string PeerTrustPage::BuildQueryString(const long startrow, const std::string &namesearch, const std::string &sortby, const std::string &sortorder, const int localidentityid)\r
 {\r
        std::string returnval="";\r
        std::string tempval="";\r
@@ -43,10 +44,57 @@ const std::string PeerTrustPage::BuildQueryString(const long startrow, const std
                returnval+="sortorder="+sortorder;\r
        }\r
 \r
+       if(localidentityid>=0)\r
+       {\r
+               std::string localidentityidstr="";\r
+               StringFunctions::Convert(localidentityid,localidentityidstr);\r
+               if(returnval!="")\r
+               {\r
+                       returnval+="&";\r
+               }\r
+               returnval+="localidentityid="+localidentityidstr;\r
+       }\r
+\r
        return returnval;\r
 \r
 }\r
 \r
+const std::string PeerTrustPage::CreateLocalIdentityDropDown(const std::string &name, const int selectedlocalidentityid)\r
+{\r
+       std::string result="";\r
+       \r
+       result+="<select name=\""+name+"\">";\r
+       \r
+       SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID,Name,PublicKey FROM tblLocalIdentity WHERE PublicKey IS NOT NULL ORDER BY Name COLLATE NOCASE;");\r
+       st.Step();\r
+\r
+       while(st.RowReturned())\r
+       {\r
+               int localidentityid=-1;\r
+               std::string localidentityidstr="";\r
+               std::string name="";\r
+               std::string publickey="";\r
+\r
+               st.ResultInt(0,localidentityid);\r
+               st.ResultText(1,name);\r
+               st.ResultText(2,publickey);\r
+\r
+               StringFunctions::Convert(localidentityid,localidentityidstr);\r
+\r
+               result+="<option value=\""+localidentityidstr+"\"";\r
+               if(localidentityid==selectedlocalidentityid)\r
+               {\r
+                       result+=" SELECTED";\r
+               }\r
+               result+=">"+SanitizeOutput(CreateShortIdentityName(name,publickey))+"</option>";\r
+               st.Step();\r
+       }\r
+\r
+       result+="</select>";\r
+\r
+       return result;\r
+}\r
+\r
 const std::string PeerTrustPage::GeneratePage(const std::string &method, const std::map<std::string,std::string> &queryvars)\r
 {\r
        int count=0;\r
@@ -61,9 +109,28 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s
        std::string sql;\r
        std::string sortby="";\r
        std::string sortorder="";\r
+       std::string localidentityidstr="";\r
+       int localidentityid=-1;\r
 \r
        StringFunctions::Convert(rowsperpage,rowsperpagestr);\r
 \r
+       // get localidentityid from querystring or load one from the database\r
+       if(queryvars.find("localidentityid")!=queryvars.end())\r
+       {\r
+               localidentityidstr=(*queryvars.find("localidentityid")).second;\r
+               StringFunctions::Convert(localidentityidstr,localidentityid);\r
+       }\r
+       else\r
+       {\r
+               SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID FROM tblLocalIdentity;");\r
+               st.Step();\r
+               if(st.RowReturned())\r
+               {\r
+                       st.ResultInt(0,localidentityid);\r
+                       StringFunctions::Convert(localidentityid,localidentityidstr);\r
+               }\r
+       }\r
+\r
        if(queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="update")\r
        {\r
                std::vector<std::string> identityids;\r
@@ -77,7 +144,7 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s
                std::vector<std::string> tltc;\r
                int localmessagetrust=0;\r
                int localtrustlisttrust=0;\r
-               int identityid;\r
+               int identityid=-1;\r
 \r
                CreateArgArray(queryvars,"identityid",identityids);\r
                CreateArgArray(queryvars,"oldlocalmessagetrust",oldlmt);\r
@@ -88,8 +155,9 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s
                CreateArgArray(queryvars,"messagetrustcomment",mtc);\r
                CreateArgArray(queryvars,"oldtrustlisttrustcomment",oldtltc);\r
                CreateArgArray(queryvars,"trustlisttrustcomment",tltc);\r
-               \r
-               SQLite3DB::Statement update=m_db->Prepare("UPDATE tblIdentity SET LocalMessageTrust=?, LocalTrustListTrust=?, MessageTrustComment=?, TrustListTrustComment=? WHERE IdentityID=?;");\r
+\r
+               SQLite3DB::Statement ins=m_db->Prepare("INSERT INTO tblIdentityTrust(LocalIdentityID,IdentityID) VALUES(?,?);");\r
+               SQLite3DB::Statement update=m_db->Prepare("UPDATE tblIdentityTrust SET LocalMessageTrust=?, LocalTrustListTrust=?, MessageTrustComment=?, TrustListTrustComment=? WHERE LocalIdentityID=? AND IdentityID=?;");\r
 \r
                for(int i=0; i<identityids.size(); i++)\r
                {\r
@@ -99,6 +167,11 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s
                                StringFunctions::Convert(ltlt[i],localtrustlisttrust);\r
                                StringFunctions::Convert(identityids[i],identityid);\r
 \r
+                               ins.Bind(0,localidentityid);\r
+                               ins.Bind(1,identityid);\r
+                               ins.Step();\r
+                               ins.Reset();\r
+\r
                                if(lmt[i]!="")\r
                                {\r
                                        update.Bind(0,localmessagetrust);\r
@@ -117,7 +190,8 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s
                                }\r
                                update.Bind(2,mtc[i]);\r
                                update.Bind(3,tltc[i]);\r
-                               update.Bind(4,identityid);\r
+                               update.Bind(4,localidentityid);\r
+                               update.Bind(5,identityid);\r
                                update.Step();\r
                                update.Reset();\r
                        }\r
@@ -165,59 +239,69 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s
        }\r
 \r
        content+="<h2>Peer Trust</h2>";\r
-       content+="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.  Trust is recalculated once an hour from received trust lists.";\r
-       content+="<div style=\"text-align:center;\">";\r
-       content+="<form name=\"frmsearch\" method=\"POST\" action=\"peertrust.htm\">";\r
+       content+="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.  Trust is recalculated once an hour from received trust lists.  You must have at least 1 identity created and have received the SSK keypair for it from Freenet before setting trust.";\r
+       \r
+       // search drop down\r
+       content+="<div style=\"text-align:center;margin-bottom:5px;\">";\r
+       content+="<form name=\"frmsearch\" method=\"POST\" action=\"peertrust.htm?"+BuildQueryString(0,"","","",localidentityid)+"\">";\r
        content+="<input type=\"text\" name=\"namesearch\" value=\""+SanitizeOutput(namesearch)+"\">";\r
        content+="<input type=\"submit\" value=\"Search\">";\r
        content+="</form>";\r
        content+="</div>";\r
+\r
+       content+="<div style=\"text-align:center;\">";\r
+       content+="<form name=\"frmlocalidentity\" method=\"POST\" action=\"peertrust.htm?"+BuildQueryString(startrow,namesearch,sortby,sortorder,-1)+"\">";\r
+       content+="Load Trust List of ";\r
+       content+=CreateLocalIdentityDropDown("localidentityid",localidentityid);\r
+       content+="<input type=\"submit\" value=\"Load List\">";\r
+       content+="</form>";\r
+       content+="</div>";\r
+\r
        content+="<form name=\"frmtrust\" method=\"POST\">";\r
        content+="<input type=\"hidden\" name=\"formaction\" value=\"update\">";\r
+       content+="<input type=\"hidden\" name=\"localidentityid\" value=\""+localidentityidstr+"\">";\r
        content+="<input type=\"hidden\" name=\"startrow\" value=\""+startrowstr+"\">";\r
        if(namesearch!="")\r
        {\r
                content+="<input type=\"hidden\" name=\"namesearch\" value=\""+SanitizeOutput(namesearch)+"\">";\r
        }\r
        content+="<table class=\"small90\">";\r
-       content+="<tr><th><a href=\"peertrust.htm?"+BuildQueryString(startrow,namesearch,"Name",ReverseSort("Name",sortby,sortorder))+"\">Name</a></th>";\r
-       content+="<th><a href=\"peertrust.htm?"+BuildQueryString(startrow,namesearch,"LocalMessageTrust",ReverseSort("LocalMessageTrust",sortby,sortorder))+"\">Local Message Trust</a></th>";\r
+       content+="<tr><th><a href=\"peertrust.htm?"+BuildQueryString(startrow,namesearch,"Name",ReverseSort("Name",sortby,sortorder),localidentityid)+"\">Name</a></th>";\r
+       content+="<th><a href=\"peertrust.htm?"+BuildQueryString(startrow,namesearch,"tblIdentityTrust.LocalMessageTrust",ReverseSort("tblIdentityTrust.LocalMessageTrust",sortby,sortorder),localidentityid)+"\">Local Message Trust</a></th>";\r
        content+="<th>Message Comment</th>";\r
-       content+="<th><a href=\"peertrust.htm?"+BuildQueryString(startrow,namesearch,"PeerMessageTrust",ReverseSort("PeerMessageTrust",sortby,sortorder))+"\">Peer Message Trust</a></th>";\r
-       content+="<th><a href=\"peertrust.htm?"+BuildQueryString(startrow,namesearch,"LocalTrustListTrust",ReverseSort("LocalTrustListTrust",sortby,sortorder))+"\">Local Trust List Trust</a></th>";\r
+       content+="<th><a href=\"peertrust.htm?"+BuildQueryString(startrow,namesearch,"PeerMessageTrust",ReverseSort("PeerMessageTrust",sortby,sortorder),localidentityid)+"\">Peer Message Trust</a></th>";\r
+       content+="<th><a href=\"peertrust.htm?"+BuildQueryString(startrow,namesearch,"tblIdentityTrust.LocalTrustListTrust",ReverseSort("tblIdentityTrust.LocalTrustListTrust",sortby,sortorder),localidentityid)+"\">Local Trust List Trust</a></th>";\r
        content+="<th>Trust Comment</th>";\r
-       content+="<th><a href=\"peertrust.htm?"+BuildQueryString(startrow,namesearch,"PeerTrustListTrust",ReverseSort("PeerTrustListTrust",sortby,sortorder))+"\">Peer Trust List Trust</a></th>";\r
-       content+="<th><a href=\"peertrust.htm?"+BuildQueryString(startrow,namesearch,"MessageCount",ReverseSort("MessageCount",sortby,sortorder))+"\">Message Count</a></th>";\r
+       content+="<th><a href=\"peertrust.htm?"+BuildQueryString(startrow,namesearch,"PeerTrustListTrust",ReverseSort("PeerTrustListTrust",sortby,sortorder),localidentityid)+"\">Peer Trust List Trust</a></th>";\r
+       content+="<th><a href=\"peertrust.htm?"+BuildQueryString(startrow,namesearch,"MessageCount",ReverseSort("MessageCount",sortby,sortorder),localidentityid)+"\">Message Count</a></th>";\r
        content+="</tr>\r\n";\r
        \r
+//TODO - modify this query\r
        // get count of identities we are showing\r
-       sql="SELECT COUNT(*) FROM tblIdentity";\r
+       sql="SELECT COUNT(*) FROM tblIdentity LEFT JOIN (SELECT IdentityID FROM tblIdentityTrust WHERE LocalIdentityID=?) AS 'tblIdentityTrust' ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID ";\r
+       sql+="WHERE tblIdentity.Hidden='false'";\r
        if(namesearch!="")\r
        {\r
-               sql+=" WHERE Name LIKE '%' || ? || '%' AND tblIdentity.Hidden='false'";\r
-       }\r
-       else\r
-       {\r
-               sql+=" WHERE tblIdentity.Hidden='false'";       \r
+               sql+=" AND (Name LIKE '%' || ? || '%' OR PublicKey LIKE '%' || ? || '%')";\r
        }\r
        sql+=";";\r
        SQLite3DB::Statement st=m_db->Prepare(sql);\r
+       st.Bind(0,localidentityid);\r
        if(namesearch!="")\r
        {\r
-               st.Bind(0,namesearch);\r
+               st.Bind(1,namesearch);\r
+               st.Bind(2,namesearch);\r
        }\r
        st.Step();\r
        st.ResultInt(0,identitycount);\r
        st.Finalize();\r
 \r
-       sql="SELECT tblIdentity.IdentityID,Name,LocalMessageTrust,PeerMessageTrust,LocalTrustListTrust,PeerTrustListTrust,PublicKey,MessageTrustComment,TrustListTrustComment,COUNT(MessageID) AS 'MessageCount' FROM tblIdentity LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID";\r
+       sql="SELECT tblIdentity.IdentityID,Name,tblIdentityTrust.LocalMessageTrust,PeerMessageTrust,tblIdentityTrust.LocalTrustListTrust,PeerTrustListTrust,PublicKey,tblIdentityTrust.MessageTrustComment,tblIdentityTrust.TrustListTrustComment,COUNT(MessageID) AS 'MessageCount' ";\r
+       sql+="FROM tblIdentity LEFT JOIN (SELECT LocalIdentityID,IdentityID,LocalMessageTrust,LocalTrustListTrust,MessageTrustComment,TrustListTrustComment FROM tblIdentityTrust WHERE LocalIdentityID=?) AS tblIdentityTrust ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID ";\r
+       sql+="WHERE tblIdentity.Hidden='false'";\r
        if(namesearch!="")\r
        {\r
-               sql+=" WHERE (Name LIKE  '%' || ? || '%' OR PublicKey LIKE '%' || ? || '%') AND tblIdentity.Hidden='false'";\r
-       }\r
-       else\r
-       {\r
-               sql+=" WHERE tblIdentity.Hidden='false'";       \r
+               sql+=" AND (Name LIKE  '%' || ? || '%' OR PublicKey LIKE '%' || ? || '%')";\r
        }\r
        sql+=" GROUP BY tblIdentity.IdentityID";\r
        sql+=" ORDER BY";\r
@@ -235,10 +319,11 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s
        }\r
        sql+=" LIMIT "+startrowstr+","+rowsperpagestr+";";\r
        st=m_db->Prepare(sql);\r
+       st.Bind(0,localidentityid);\r
        if(namesearch!="")\r
        {\r
-               st.Bind(0,namesearch);\r
                st.Bind(1,namesearch);\r
+               st.Bind(2,namesearch);\r
        }\r
        st.Step();\r
 \r
@@ -251,7 +336,6 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s
                std::string localtrustlisttrust;\r
                std::string peertrustlisttrust;\r
                std::string publickey;\r
-               std::string keypart="";\r
                std::string messagetrustcomment="";\r
                std::string trustlisttrustcomment="";\r
                std::string messagecountstr="";\r
@@ -269,18 +353,13 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s
                st.ResultText(8,trustlisttrustcomment);\r
                st.ResultText(9,messagecountstr);\r
 \r
-               if(publickey.size()>8)\r
-               {\r
-                       keypart=publickey.substr(3,5);\r
-               }\r
-\r
                content+="<tr>";\r
                content+="<td title=\""+publickey+"\">";\r
                content+="<input type=\"hidden\" name=\"identityid["+countstr+"]\" value=\""+identityid+"\">";\r
                content+="<a href=\"peerdetails.htm?identityid="+identityid+"\">";\r
                if(name!="")\r
                {\r
-                       content+=SanitizeOutput(name+keypart)+"...";\r
+                       content+=SanitizeOutput(CreateShortIdentityName(name,publickey));\r
                }\r
                else\r
                {\r
@@ -321,7 +400,7 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s
                if(startrow>0)\r
                {\r
                        StringFunctions::Convert(startrow-rowsperpage,tempstr);\r
-                       content+="<td colspan=\"3\" align=\"left\"><a href=\"peertrust.htm?"+BuildQueryString(startrow-rowsperpage,namesearch,sortby,sortorder)+"\"><-- Previous Page</a></td>";\r
+                       content+="<td colspan=\"3\" align=\"left\"><a href=\"peertrust.htm?"+BuildQueryString(startrow-rowsperpage,namesearch,sortby,sortorder,localidentityid)+"\"><-- Previous Page</a></td>";\r
                        cols+=3;\r
                }\r
                if(startrow+rowsperpage<identitycount)\r
@@ -331,7 +410,7 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s
                                content+="<td></td>";\r
                                cols++;\r
                        }\r
-                       content+="<td colspan=\"3\" align=\"right\"><a href=\"peertrust.htm?"+BuildQueryString(startrow+rowsperpage,namesearch,sortby,sortorder)+"\">Next Page --></a></td>";\r
+                       content+="<td colspan=\"3\" align=\"right\"><a href=\"peertrust.htm?"+BuildQueryString(startrow+rowsperpage,namesearch,sortby,sortorder,localidentityid)+"\">Next Page --></a></td>";\r
                }\r
                content+="</tr>";\r
        }\r
index 8b33355..4bbcb70 100644 (file)
@@ -6,6 +6,9 @@
 #include <csignal>\r
 #include <iostream>\r
 \r
+//debug\r
+#include "../include/freenet/fcpv2.h"\r
+\r
 #ifdef _WIN32\r
        #include "../include/fmsservice.h"\r
 #else\r
index f95f541..eea0633 100644 (file)
@@ -42,6 +42,35 @@ const bool Message::CheckForAdministrationBoard(const std::vector<std::string> &
        return false;\r
 }\r
 \r
+const int Message::FindLocalIdentityID(const std::string &name)\r
+{\r
+       SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID FROM tblLocalIdentity WHERE Name=?;");\r
+       st.Bind(0,name);\r
+       st.Step();\r
+       if(st.RowReturned())\r
+       {\r
+               int result=-1;\r
+               st.ResultInt(0,result);\r
+               return result;\r
+       }\r
+       else\r
+       {\r
+               if(m_addnewpostfromidentities==true)\r
+               {\r
+                       DateTime now;\r
+                       now.SetToGMTime();\r
+                       st=m_db->Prepare("INSERT INTO tblLocalIdentity(Name) VALUES(?);");\r
+                       st.Bind(0,name);\r
+                       st.Step(true);\r
+                       return st.GetLastInsertRowID();\r
+               }\r
+               else\r
+               {\r
+                       return -1;\r
+               }\r
+       }\r
+}\r
+\r
 const std::string Message::GetNNTPArticleID() const\r
 {\r
        // old message - before 0.1.12 - doesn't have @domain so add @freenetproject.org\r
@@ -112,6 +141,7 @@ void Message::HandleAdministrationMessage()
        // only continue if this message was actually a reply to another message\r
        if(m_inreplyto.size()>0)\r
        {\r
+               int localidentityid=-1;\r
                int boardid=0;\r
                std::string boardname="";\r
                std::string identityname="";\r
@@ -123,7 +153,9 @@ void Message::HandleAdministrationMessage()
                SQLite3DB::Statement st=m_db->Prepare("SELECT tblBoard.BoardID,BoardName,ModifyLocalMessageTrust,ModifyLocalTrustListTrust FROM tblBoard INNER JOIN tblAdministrationBoard ON tblBoard.BoardID=tblAdministrationBoard.BoardID;");\r
                st.Step();\r
 \r
-               while(st.RowReturned())\r
+               localidentityid=FindLocalIdentityID(m_fromname);\r
+\r
+               while(st.RowReturned() && localidentityid!=-1)\r
                {\r
                        st.ResultInt(0,boardid);\r
                        st.ResultText(1,boardname);\r
@@ -132,8 +164,9 @@ void Message::HandleAdministrationMessage()
 \r
                        if(std::find(m_boards.begin(),m_boards.end(),boardname)!=m_boards.end())\r
                        {\r
-                               SQLite3DB::Statement origmess=m_db->Prepare("SELECT tblIdentity.IdentityID,tblIdentity.Name,tblIdentity.LocalMessageTrust,tblIdentity.LocalTrustListTrust FROM tblIdentity INNER JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE tblMessage.MessageUUID=?;");\r
-                               origmess.Bind(0,m_inreplyto[0]);\r
+                               SQLite3DB::Statement origmess=m_db->Prepare("SELECT tblIdentity.IdentityID,tblIdentity.Name,tblIdentityTrust.LocalMessageTrust,tblIdentityTrust.LocalTrustListTrust FROM tblIdentity INNER JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID LEFT JOIN (SELECT IdentityID,LocalMessageTrust,LocalTrustListTrust FROM tblIdentityTrust WHERE LocalIdentityID=?) AS 'tblIdentityTrust' ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID WHERE tblMessage.MessageUUID=?;");\r
+                               origmess.Bind(0,localidentityid);\r
+                               origmess.Bind(1,m_inreplyto[0]);\r
                                origmess.Step();\r
 \r
                                if(origmess.RowReturned())\r
@@ -165,11 +198,18 @@ void Message::HandleAdministrationMessage()
                                        origtrustlisttrust<0 ? origtrustlisttrust=0 : false;\r
                                        origtrustlisttrust>100 ? origtrustlisttrust=100 : false;\r
 \r
+                                       // make sure we have a record in tblIdentityTrust\r
+                                       SQLite3DB::Statement ins=m_db->Prepare("INSERT INTO tblIdentityTrust(LocalIdentityID,IdentityID) VALUES(?,?);");\r
+                                       ins.Bind(0,localidentityid);\r
+                                       ins.Bind(1,identityid);\r
+                                       ins.Step();\r
+\r
                                        // update new trust levels\r
-                                       SQLite3DB::Statement update=m_db->Prepare("UPDATE tblIdentity SET LocalMessageTrust=?, LocalTrustListTrust=? WHERE IdentityID=?;");\r
+                                       SQLite3DB::Statement update=m_db->Prepare("UPDATE tblIdentityTrust SET LocalMessageTrust=?, LocalTrustListTrust=? WHERE IdentityID=? AND LocalIdentityID=?;");\r
                                        update.Bind(0,origmessagetrust);\r
                                        update.Bind(1,origtrustlisttrust);\r
                                        update.Bind(2,identityid);\r
+                                       update.Bind(3,localidentityid);\r
                                        update.Step();\r
 \r
                                        // insert message to show what id was changed and what current levels are\r
@@ -182,6 +222,7 @@ void Message::HandleAdministrationMessage()
                                        now.SetToGMTime();\r
                                        StringFunctions::Convert(origmessagetrust,messagetruststr);\r
                                        StringFunctions::Convert(origtrustlisttrust,trustlisttruststr);\r
+                                       messagebody="Trust List of "+m_fromname+"\r\n";\r
                                        messagebody="Trust Changed for "+identityname+"\r\n";\r
                                        messagebody+="Local Message Trust : "+messagetruststr+"\r\n";\r
                                        messagebody+="Local Trust List Trust : "+trustlisttruststr+"\r\n";\r
@@ -215,39 +256,52 @@ void Message::HandleChangeTrust()
 {\r
        if(m_changemessagetrustonreply!=0 && m_inreplyto.size()>0)\r
        {\r
-               SQLite3DB::Statement st=m_db->Prepare("SELECT tblIdentity.IdentityID,tblIdentity.LocalMessageTrust FROM tblIdentity INNER JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE tblMessage.MessageUUID=?;");\r
-               st.Bind(0,m_inreplyto[0]);\r
-               st.Step();\r
-               if(st.RowReturned())\r
+               int localidentityid=FindLocalIdentityID(m_fromname);\r
+               if(localidentityid!=-1)\r
                {\r
-                       int identityid=0;\r
-                       int localmessagetrust=0;\r
+                       // make sure we have a record in tblIdentityTrust\r
+                       SQLite3DB::Statement ins=m_db->Prepare("INSERT INTO tblIdentityTrust(LocalIdentityID,IdentityID) VALUES(?,?);");\r
 \r
-                       st.ResultInt(0,identityid);\r
-                       if(st.ResultNull(1)==false)\r
-                       {\r
-                               st.ResultInt(1,localmessagetrust);\r
-                       }\r
-                       else\r
+                       SQLite3DB::Statement st=m_db->Prepare("SELECT tblIdentity.IdentityID,tblIdentityTrust.LocalMessageTrust FROM tblIdentity INNER JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID LEFT JOIN (SELECT IdentityID,LocalMessageTrust FROM tblIdentityTrust WHERE LocalIdentityID=?) AS 'tblIdentityTrust' ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID WHERE tblMessage.MessageUUID=?;");\r
+                       st.Bind(0,localidentityid);\r
+                       st.Bind(1,m_inreplyto[0]);\r
+                       st.Step();\r
+                       if(st.RowReturned())\r
                        {\r
-                               localmessagetrust=m_minlocalmessagetrust;\r
-                       }\r
+                               int identityid=0;\r
+                               int localmessagetrust=0;\r
 \r
-                       localmessagetrust+=m_changemessagetrustonreply;\r
-                       if(localmessagetrust<0)\r
-                       {\r
-                               localmessagetrust=0;\r
-                       }\r
-                       if(localmessagetrust>100)\r
-                       {\r
-                               localmessagetrust=100;\r
-                       }\r
+                               st.ResultInt(0,identityid);\r
+                               if(st.ResultNull(1)==false)\r
+                               {\r
+                                       st.ResultInt(1,localmessagetrust);\r
+                               }\r
+                               else\r
+                               {\r
+                                       localmessagetrust=m_minlocalmessagetrust;\r
+                               }\r
+\r
+                               localmessagetrust+=m_changemessagetrustonreply;\r
+                               if(localmessagetrust<0)\r
+                               {\r
+                                       localmessagetrust=0;\r
+                               }\r
+                               if(localmessagetrust>100)\r
+                               {\r
+                                       localmessagetrust=100;\r
+                               }\r
 \r
-                       SQLite3DB::Statement st2=m_db->Prepare("UPDATE tblIdentity SET LocalMessageTrust=? WHERE IdentityID=?;");\r
-                       st2.Bind(0,localmessagetrust);\r
-                       st2.Bind(1,identityid);\r
-                       st2.Step();\r
+                               ins.Bind(0,localidentityid);\r
+                               ins.Bind(1,identityid);\r
+                               ins.Step();\r
 \r
+                               SQLite3DB::Statement st2=m_db->Prepare("UPDATE tblIdentityTrust SET LocalMessageTrust=? WHERE IdentityID=? AND LocalIdentityID=?;");\r
+                               st2.Bind(0,localmessagetrust);\r
+                               st2.Bind(1,identityid);\r
+                               st2.Bind(2,localidentityid);\r
+                               st2.Step();\r
+\r
+                       }\r
                }\r
        }\r
 }\r
@@ -635,7 +689,9 @@ const bool Message::StartFreenetInsert()
                xml.AddInReplyTo((*j).first,(*j).second);\r
        }\r
 \r
+\r
        // find identity to insert with\r
+       /*\r
        SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID FROM tblLocalIdentity WHERE Name=?;");\r
        st.Bind(0,m_fromname);\r
        st.Step();\r
@@ -661,8 +717,14 @@ const bool Message::StartFreenetInsert()
        {\r
                st.ResultInt(0,localidentityid);\r
        }\r
+       */\r
+       localidentityid=FindLocalIdentityID(m_fromname);\r
+       if(localidentityid==-1)\r
+       {\r
+               return false;\r
+       }\r
 \r
-       st=m_db->Prepare("INSERT INTO tblMessageInserts(LocalIdentityID,MessageUUID,MessageXML) VALUES(?,?,?);");\r
+       SQLite3DB::Statement st=m_db->Prepare("INSERT INTO tblMessageInserts(LocalIdentityID,MessageUUID,MessageXML) VALUES(?,?,?);");\r
        st.Bind(0,localidentityid);\r
        st.Bind(1,m_messageuuid);\r
        st.Bind(2,xml.GetXML());\r