{\r
DateTime now;\r
SQLite3DB::Statement st;\r
+ SQLite3DB::Statement trustst;\r
std::vector<std::string> idparts;\r
long datalength;\r
std::vector<char> data;\r
// parse file into xml and update the database\r
if(xml.ParseXML(std::string(data.begin(),data.end()))==true)\r
{\r
+\r
+ // drop all existing peer trust from this identity - we will rebuild it when we go through each trust in the xml file\r
+ st=m_db->Prepare("DELETE FROM tblPeerTrust WHERE IdentityID=?;");\r
+ st.Bind(0,identityid);\r
+ st.Step();\r
+ st.Finalize();\r
+\r
st=m_db->Prepare("SELECT IdentityID FROM tblIdentity WHERE PublicKey=?;");\r
+ trustst=m_db->Prepare("INSERT INTO tblPeerTrust(IdentityID,TargetIdentityID,MessageTrust,TrustListTrust) VALUES(?,?,?,?);");\r
// loop through all trust entries in xml and add to database if we don't already know them\r
for(long i=0; i<xml.TrustCount(); i++)\r
{\r
+ int id;\r
std::string identity;\r
identity=xml.GetIdentity(i);\r
\r
- //TODO get the trust levels as well\r
-\r
st.Bind(0,identity);\r
st.Step();\r
if(st.RowReturned()==false)\r
{\r
- m_db->Execute("INSERT INTO tblIdentity(PublicKey,DateAdded) VALUES('"+identity+"','"+now.Format("%Y-%m-%d %H:%M:%S")+"');");\r
+ m_db->ExecuteInsert("INSERT INTO tblIdentity(PublicKey,DateAdded) VALUES('"+identity+"','"+now.Format("%Y-%m-%d %H:%M:%S")+"');",(long &)id);\r
+ }\r
+ else\r
+ {\r
+ st.ResultInt(0,id);\r
}\r
st.Reset();\r
+\r
+ //insert trust for this identity\r
+ trustst.Bind(0,identityid);\r
+ trustst.Bind(1,id);\r
+ trustst.Bind(2,xml.GetMessageTrust(i));\r
+ trustst.Bind(3,xml.GetTrustListTrust(i));\r
+ trustst.Step();\r
+ trustst.Reset();\r
+\r
}\r
+ trustst.Finalize();\r
+ st.Finalize();\r
\r
st=m_db->Prepare("INSERT INTO tblTrustListRequests(IdentityID,Day,RequestIndex,Found) VALUES(?,?,?,'true');");\r
st.Bind(0,identityid);\r
st.Step();\r
st.Finalize();\r
\r
- m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,__FUNCTION__" parsed Identity XML file : "+message["Identifier"]);\r
+ m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"TrustListRequester::HandleAllData parsed TrustList XML file : "+message["Identifier"]);\r
}\r
else\r
{\r
st.Step();\r
st.Finalize();\r
\r
- m_log->WriteLog(LogFile::LOGLEVEL_ERROR,__FUNCTION__" error parsing TrustList XML file : "+message["Identifier"]);\r
+ m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"TrustListRequester::HandleAllData error parsing TrustList XML file : "+message["Identifier"]);\r
}\r
\r
// remove this identityid from request list\r
st.Step();\r
st.Finalize();\r
\r
- m_log->WriteLog(LogFile::LOGLEVEL_ERROR,__FUNCTION__" fatal error requesting "+message["Identifier"]);\r
+ m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"TrustListRequester::HandleGetFailed fatal error requesting "+message["Identifier"]);\r
}\r
\r
// remove this identityid from request list\r
void TrustListRequester::Initialize()\r
{\r
std::string tempval="";\r
- Option::instance()->Get("MaxIdentityRequests",tempval);\r
+ Option::Instance()->Get("MaxIdentityRequests",tempval);\r
StringFunctions::Convert(tempval,m_maxrequests);\r
if(m_maxrequests<1)\r
{\r
{\r
m_log->WriteLog(LogFile::LOGLEVEL_WARNING,"Option MaxTrustListRequests is currently set at "+tempval+". This value might be incorrectly configured.");\r
}\r
- Option::instance()->Get("MessageBase",m_messagebase);\r
+ Option::Instance()->Get("MessageBase",m_messagebase);\r
m_tempdate.SetToGMTime();\r
}\r
\r
{\r
DateTime date;\r
int id;\r
+ std::string sql;\r
\r
date.SetToGMTime();\r
\r
// select identities we want to query (we've seen them today and they are publishing trust list) - sort by their trust level (descending) with secondary sort on how long ago we saw them (ascending)\r
- SQLite3DB::Statement st=m_db->Prepare("SELECT IdentityID FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey <> '' AND LastSeen>='"+date.Format("%Y-%m-%d")+"' AND PublishTrustList='true' AND LocalTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalTrustListTrust') ORDER BY LocalMessageTrust+LocalTrustListTrust DESC, LastSeen;");\r
+ sql="SELECT IdentityID FROM tblIdentity ";\r
+ sql+="WHERE PublicKey IS NOT NULL AND PublicKey <> '' AND LastSeen>='"+date.Format("%Y-%m-%d")+"' AND PublishTrustList='true' AND LocalTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalTrustListTrust') AND ( PeerTrustListTrust IS NULL OR PeerTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinPeerTrustListTrust') )";\r
+ sql+="ORDER BY LocalMessageTrust+LocalTrustListTrust DESC, LastSeen;";\r
+\r
+ SQLite3DB::Statement st=m_db->Prepare(sql);\r
st.Step();\r
\r
m_ids.clear();\r
// this will recheck for ids every minute\r
DateTime now;\r
now.SetToGMTime();\r
- if(m_tempdate<(now-(1.0/1440.0)))\r
+ if(m_ids.size()==0 && m_tempdate<(now-(1.0/1440.0)))\r
{\r
PopulateIDList();\r
m_tempdate=now;\r