From 0df5c54166c3e695d1ef151378fa632281514554 Mon Sep 17 00:00:00 2001 From: Miguel Freitas Date: Tue, 1 Oct 2013 08:57:51 -0300 Subject: [PATCH] promoted posts implemented --- src/main.cpp | 14 +++++++++++++- src/twister.cpp | 35 +++++++++++++++++++++++++++++++++++ src/twister.h | 2 ++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 9f9103cd..a147f4a1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,6 +12,9 @@ #include "ui_interface.h" #include "checkqueue.h" #include "chainparams.h" + +#include "twister.h" + #include #include #include @@ -65,7 +68,7 @@ int64 nHPSTimerStart = 0; // Settings int64 nTransactionFee = 0; -string strSpamMessage = "spam message test [en]"; +string strSpamMessage = "Promoted posts are needed to run the network infrastructure. If you want to help, start generating blocks and advertise. [en]"; string strSpamUser = "nobody"; // [MF] FIXME: authenticy check needed @@ -1657,6 +1660,15 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl } printf("ProcessBlock: ACCEPTED\n"); + if( pblock->vtx[0].IsSpamMessage() ) { + string msg = pblock->vtx[0].message.ExtractPushDataString(0); + string user = pblock->vtx[0].userName.ExtractPushDataString(0); + // [MF] FIXME: validate user properly + if( msg.length() <= 140 ) { + printf("ProcessBlock: msg='%s' user='%s'\n", msg.c_str(), user.c_str()); + receivedSpamMessage(msg, user); + } + } return true; } diff --git a/src/twister.cpp b/src/twister.cpp index 7865e3eb..5f286c8c 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -41,6 +41,9 @@ static map m_dhtgetMap; static map m_specialResources; static map m_userTorrent; static std::set m_following; +static std::string preferredSpamLang = "[en]"; +static std::string receivedSpamMsgStr; +static std::string receivedSpamUserStr; sha1_hash dhtTargetHash(std::string const &username, std::string const &resource, std::string const &type) { @@ -715,6 +718,16 @@ int getBestHeight() return nBestHeight; } +void receivedSpamMessage(std::string const &message, std::string const &user) +{ + if( !receivedSpamMsgStr.length() || + (preferredSpamLang.length() && message.find(preferredSpamLang) != string::npos) ) { + receivedSpamMsgStr = message; + receivedSpamUserStr = user; + } +} + + Value dhtput(const Array& params, bool fHelp) { if (fHelp || params.size() < 5 || params.size() > 6) @@ -1020,6 +1033,28 @@ Value getposts(const Array& params, bool fHelp) ret.push_back( entryToJson(rit->second) ); } + if( receivedSpamMsgStr.length() ) { + // we must agree on an acceptable level here + if( rand() < (RAND_MAX/10) ) { + entry v; + entry &userpost = v["userpost"]; + + userpost["n"] = receivedSpamUserStr; + userpost["k"] = 1; + userpost["time"] = GetAdjustedTime(); + userpost["height"] = getBestHeight(); + + userpost["msg"] = receivedSpamMsgStr; + + unsigned char vchSig[65]; + RAND_bytes(vchSig,sizeof(vchSig)); + v["sig_userpost"] = std::string((const char *)vchSig, sizeof(vchSig)); + ret.insert(ret.begin(),entryToJson(v)); + } + receivedSpamMsgStr = ""; + receivedSpamUserStr = ""; + } + return ret; } diff --git a/src/twister.h b/src/twister.h index e75cf3f1..21c10b7e 100644 --- a/src/twister.h +++ b/src/twister.h @@ -25,6 +25,8 @@ bool verifySignature(std::string const &strMessage, std::string const &strUserna bool acceptSignedPost(char const *data, int data_size, std::string username, int seq, std::string &errmsg, boost::uint32_t *flags); bool validatePostNumberForUser(std::string const &username, int k); +void receivedSpamMessage(std::string const &message, std::string const &user); + int getBestHeight(); #endif // TWISTER_H