Skip to content

Commit

Permalink
add padding and random order to DMs copy-to-self
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelfreitas committed Sep 27, 2014
1 parent 4a0a215 commit 6a15c24
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/twister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1821,28 +1821,41 @@ Value newdirectmsg(const Array& params, bool fHelp)

std::list<entry *> dmsToSend;

entry dmOldFormat;
if( !createDirectMessage(dmOldFormat, strTo, strMsg) )
throw JSONRPCError(RPC_INTERNAL_ERROR,
"error encrypting to pubkey of destination user");

entry payloadNewFormat;
payloadNewFormat["msg"] = strMsg;
payloadNewFormat["to"] = strTo;
std::vector<char> payloadbuf;
bencode(std::back_inserter(payloadbuf), payloadNewFormat);
std::string strMsgData = std::string(payloadbuf.data(),payloadbuf.size());

if( copySelf ) {
// add padding to strMsg so both DMs will have exactly the same size.
// should be removed in future when all clients move to new format.
while( strMsg.length() < strMsgData.length() ) {
strMsg.push_back(' ');
}
}

entry dmOldFormat;
if( !createDirectMessage(dmOldFormat, strTo, strMsg) )
throw JSONRPCError(RPC_INTERNAL_ERROR,
"error encrypting to pubkey of destination user");

entry dmNewFormat;
if( copySelf ) {
// use new format to send a copy to ourselves. in future, message
// to others might use the new format as well.
if( !createDirectMessage(dmNewFormat, strFrom, strMsgData) )
throw JSONRPCError(RPC_INTERNAL_ERROR,
"error encrypting to pubkey of destination user");
// TODO: random order
dmsToSend.push_back(&dmOldFormat);
dmsToSend.push_back(&dmNewFormat);

if( rand() < (RAND_MAX/2) ) {
dmsToSend.push_back(&dmOldFormat);
dmsToSend.push_back(&dmNewFormat);
} else {
dmsToSend.push_back(&dmNewFormat);
dmsToSend.push_back(&dmOldFormat);
}
} else {
dmsToSend.push_back(&dmOldFormat);
}
Expand Down

0 comments on commit 6a15c24

Please sign in to comment.