Make sure mixing messages are relayed/accepted properly (#1547)

* make sure addr of mixing mn matches peer's addr exactly (including port)

* Store addr of every mixing client and relay mixing mesasges to them only
This commit is contained in:
UdjinM6 2017-07-25 13:57:26 +03:00 committed by GitHub
parent a0851494db
commit 9694658cd3
4 changed files with 69 additions and 15 deletions

View File

@ -60,7 +60,7 @@ void CPrivateSendClient::ProcessMessage(CNode* pfrom, std::string& strCommand, C
// if the queue is ready, submit if we can // if the queue is ready, submit if we can
if(dsq.fReady) { if(dsq.fReady) {
if(!infoMixingMasternode.fInfoValid) return; if(!infoMixingMasternode.fInfoValid) return;
if((CNetAddr)infoMixingMasternode.addr != (CNetAddr)infoMn.addr) { if(infoMixingMasternode.addr != infoMn.addr) {
LogPrintf("DSQUEUE -- message doesn't match current Masternode: infoMixingMasternode=%s, addr=%s\n", infoMixingMasternode.addr.ToString(), infoMn.addr.ToString()); LogPrintf("DSQUEUE -- message doesn't match current Masternode: infoMixingMasternode=%s, addr=%s\n", infoMixingMasternode.addr.ToString(), infoMn.addr.ToString());
return; return;
} }
@ -105,7 +105,7 @@ void CPrivateSendClient::ProcessMessage(CNode* pfrom, std::string& strCommand, C
} }
if(!infoMixingMasternode.fInfoValid) return; if(!infoMixingMasternode.fInfoValid) return;
if((CNetAddr)infoMixingMasternode.addr != (CNetAddr)pfrom->addr) { if(infoMixingMasternode.addr != pfrom->addr) {
//LogPrintf("DSSTATUSUPDATE -- message doesn't match current Masternode: infoMixingMasternode %s addr %s\n", infoMixingMasternode.addr.ToString(), pfrom->addr.ToString()); //LogPrintf("DSSTATUSUPDATE -- message doesn't match current Masternode: infoMixingMasternode %s addr %s\n", infoMixingMasternode.addr.ToString(), pfrom->addr.ToString());
return; return;
} }
@ -149,7 +149,7 @@ void CPrivateSendClient::ProcessMessage(CNode* pfrom, std::string& strCommand, C
} }
if(!infoMixingMasternode.fInfoValid) return; if(!infoMixingMasternode.fInfoValid) return;
if((CNetAddr)infoMixingMasternode.addr != (CNetAddr)pfrom->addr) { if(infoMixingMasternode.addr != pfrom->addr) {
//LogPrintf("DSFINALTX -- message doesn't match current Masternode: infoMixingMasternode %s addr %s\n", infoMixingMasternode.addr.ToString(), pfrom->addr.ToString()); //LogPrintf("DSFINALTX -- message doesn't match current Masternode: infoMixingMasternode %s addr %s\n", infoMixingMasternode.addr.ToString(), pfrom->addr.ToString());
return; return;
} }
@ -176,7 +176,7 @@ void CPrivateSendClient::ProcessMessage(CNode* pfrom, std::string& strCommand, C
} }
if(!infoMixingMasternode.fInfoValid) return; if(!infoMixingMasternode.fInfoValid) return;
if((CNetAddr)infoMixingMasternode.addr != (CNetAddr)pfrom->addr) { if(infoMixingMasternode.addr != pfrom->addr) {
LogPrint("privatesend", "DSCOMPLETE -- message doesn't match current Masternode: infoMixingMasternode=%s addr=%s\n", infoMixingMasternode.addr.ToString(), pfrom->addr.ToString()); LogPrint("privatesend", "DSCOMPLETE -- message doesn't match current Masternode: infoMixingMasternode=%s addr=%s\n", infoMixingMasternode.addr.ToString(), pfrom->addr.ToString());
return; return;
} }

View File

@ -229,6 +229,7 @@ void CPrivateSendServer::ProcessMessage(CNode* pfrom, std::string& strCommand, C
PoolMessage nMessageID = MSG_NOERR; PoolMessage nMessageID = MSG_NOERR;
entry.addr = pfrom->addr;
if(AddEntry(entry, nMessageID)) { if(AddEntry(entry, nMessageID)) {
PushStatus(pfrom, STATUS_ACCEPTED, nMessageID); PushStatus(pfrom, STATUS_ACCEPTED, nMessageID);
CheckPool(); CheckPool();
@ -795,10 +796,21 @@ bool CPrivateSendServer::AddUserToExistingSession(int nDenom, CTransaction txCol
void CPrivateSendServer::RelayFinalTransaction(const CTransaction& txFinal) void CPrivateSendServer::RelayFinalTransaction(const CTransaction& txFinal)
{ {
g_connman->ForEachNode([&txFinal, this](CNode* pnode) { LogPrint("privatesend", "CPrivateSendServer::%s -- nSessionID: %d nSessionDenom: %d (%s)\n",
if(pnode->nVersion >= MIN_PRIVATESEND_PEER_PROTO_VERSION) __func__, nSessionID, nSessionDenom, CPrivateSend::GetDenominationsToString(nSessionDenom));
// final mixing tx with empty signatures should be relayed to mixing participants only
for (const auto entry : vecEntries) {
bool fOk = g_connman->ForNode(entry.addr, [&txFinal, this](CNode* pnode) {
pnode->PushMessage(NetMsgType::DSFINALTX, nSessionID, txFinal); pnode->PushMessage(NetMsgType::DSFINALTX, nSessionID, txFinal);
return true;
}); });
if(!fOk) {
// no such node? maybe this client disconnected or our own connection went down
RelayStatus(STATUS_REJECTED);
break;
}
}
} }
void CPrivateSendServer::PushStatus(CNode* pnode, PoolStatusUpdate nStatusUpdate, PoolMessage nMessageID) void CPrivateSendServer::PushStatus(CNode* pnode, PoolStatusUpdate nStatusUpdate, PoolMessage nMessageID)
@ -809,18 +821,57 @@ void CPrivateSendServer::PushStatus(CNode* pnode, PoolStatusUpdate nStatusUpdate
void CPrivateSendServer::RelayStatus(PoolStatusUpdate nStatusUpdate, PoolMessage nMessageID) void CPrivateSendServer::RelayStatus(PoolStatusUpdate nStatusUpdate, PoolMessage nMessageID)
{ {
g_connman->ForEachNode([nStatusUpdate, nMessageID, this](CNode* pnode) { unsigned int nDisconnected{};
if(pnode->nVersion >= MIN_PRIVATESEND_PEER_PROTO_VERSION) // status updates should be relayed to mixing participants only
for (const auto entry : vecEntries) {
// make sure everyone is still connected
bool fOk = g_connman->ForNode(entry.addr, [&nStatusUpdate, &nMessageID, this](CNode* pnode) {
PushStatus(pnode, nStatusUpdate, nMessageID); PushStatus(pnode, nStatusUpdate, nMessageID);
return true;
}); });
if(!fOk) {
// no such node? maybe this client disconnected or our own connection went down
++nDisconnected;
}
}
if (nDisconnected == 0) return; // all is clear
// smth went wrong
LogPrintf("CPrivateSendServer::%s -- can't continue, %llu client(s) disconnected, nSessionID: %d nSessionDenom: %d (%s)\n",
__func__, nDisconnected, nSessionID, nSessionDenom, CPrivateSend::GetDenominationsToString(nSessionDenom));
// notify everyone else that this session should be terminated
for (const auto entry : vecEntries) {
g_connman->ForNode(entry.addr, [this](CNode* pnode) {
PushStatus(pnode, STATUS_REJECTED, MSG_NOERR);
return true;
});
}
if(nDisconnected == vecEntries.size()) {
// all clients disconnected, there is probably some issues with our own connection
// do not charge any fees, just reset the pool
SetNull();
}
} }
void CPrivateSendServer::RelayCompletedTransaction(PoolMessage nMessageID) void CPrivateSendServer::RelayCompletedTransaction(PoolMessage nMessageID)
{ {
g_connman->ForEachNode([nMessageID, this](CNode* pnode) { LogPrint("privatesend", "CPrivateSendServer::%s -- nSessionID: %d nSessionDenom: %d (%s)\n",
if(pnode->nVersion >= MIN_PRIVATESEND_PEER_PROTO_VERSION) __func__, nSessionID, nSessionDenom, CPrivateSend::GetDenominationsToString(nSessionDenom));
// final mixing tx with empty signatures should be relayed to mixing participants only
for (const auto entry : vecEntries) {
bool fOk = g_connman->ForNode(entry.addr, [&nMessageID, this](CNode* pnode) {
pnode->PushMessage(NetMsgType::DSCOMPLETE, nSessionID, (int)nMessageID); pnode->PushMessage(NetMsgType::DSCOMPLETE, nSessionID, (int)nMessageID);
return true;
}); });
if(!fOk) {
// no such node? maybe client disconnected or our own connection went down
RelayStatus(STATUS_REJECTED);
break;
}
}
} }
void CPrivateSendServer::SetState(PoolState nStateNew) void CPrivateSendServer::SetState(PoolState nStateNew)

View File

@ -20,7 +20,7 @@
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
CDarkSendEntry::CDarkSendEntry(const std::vector<CTxIn>& vecTxIn, const std::vector<CTxOut>& vecTxOut, const CTransaction& txCollateral) : CDarkSendEntry::CDarkSendEntry(const std::vector<CTxIn>& vecTxIn, const std::vector<CTxOut>& vecTxOut, const CTransaction& txCollateral) :
txCollateral(txCollateral) txCollateral(txCollateral), addr(CService())
{ {
BOOST_FOREACH(CTxIn txin, vecTxIn) BOOST_FOREACH(CTxIn txin, vecTxIn)
vecTxDSIn.push_back(txin); vecTxDSIn.push_back(txin);

View File

@ -117,11 +117,14 @@ public:
std::vector<CTxDSIn> vecTxDSIn; std::vector<CTxDSIn> vecTxDSIn;
std::vector<CTxDSOut> vecTxDSOut; std::vector<CTxDSOut> vecTxDSOut;
CTransaction txCollateral; CTransaction txCollateral;
// memory only
CService addr;
CDarkSendEntry() : CDarkSendEntry() :
vecTxDSIn(std::vector<CTxDSIn>()), vecTxDSIn(std::vector<CTxDSIn>()),
vecTxDSOut(std::vector<CTxDSOut>()), vecTxDSOut(std::vector<CTxDSOut>()),
txCollateral(CTransaction()) txCollateral(CTransaction()),
addr(CService())
{} {}
CDarkSendEntry(const std::vector<CTxIn>& vecTxIn, const std::vector<CTxOut>& vecTxOut, const CTransaction& txCollateral); CDarkSendEntry(const std::vector<CTxIn>& vecTxIn, const std::vector<CTxOut>& vecTxOut, const CTransaction& txCollateral);