mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-23 04:54:30 +00:00
promoted posts implemented
This commit is contained in:
parent
ea32a5a117
commit
0df5c54166
14
src/main.cpp
14
src/main.cpp
@ -12,6 +12,9 @@
|
||||
#include "ui_interface.h"
|
||||
#include "checkqueue.h"
|
||||
#include "chainparams.h"
|
||||
|
||||
#include "twister.h"
|
||||
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,9 @@ static map<sha1_hash, alert_manager*> m_dhtgetMap;
|
||||
static map<std::string, bool> m_specialResources;
|
||||
static map<std::string, torrent_handle> m_userTorrent;
|
||||
static std::set<std::string> 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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user