Permalink
Browse files

Add Peer Info to Console

Many changes to Nodes, including: nodeIds, syncNodes, and cleanSubVer

Nodes are started with boost signals

Added guiutils: formatDurationStr, formatPingTime, formatServicesStr,
and  class TableViewLastColumnResizingFixer.

Removed Extended PeerInformation message popup.

rpcconsole.ui was missed from 3446a75
  • Loading branch information...
Tranz5 committed Sep 22, 2014
1 parent 3446a75 commit e6c3456ea3c1103f47f87e10bf298f94f86f7144
View
@@ -247,15 +247,7 @@ bool CAlert::ProcessAlert(bool fThread)
// be safe we first strip anything not in safeChars, then add single quotes around
// the whole string before passing it to the shell:
std::string singleQuote("'");
- // safeChars chosen to allow simple messages/URLs/email addresses, but avoid anything
- // even possibly remotely dangerous like & or >
- std::string safeChars("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890 .,;_/:?@");
- std::string safeStatus;
- for (std::string::size_type i = 0; i < strStatusBar.size(); i++)
- {
- if (safeChars.find(strStatusBar[i]) != std::string::npos)
- safeStatus.push_back(strStatusBar[i]);
- }
+ std::string safeStatus = SanitizeString(strStatusBar);
safeStatus = singleQuote+safeStatus+singleQuote;
boost::replace_all(strCmd, "%s", safeStatus);
View
@@ -2,11 +2,13 @@
// Copyright (c) 2009-2012 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+#include "init.h"
+#include "main.h"
#include "txdb.h"
#include "walletdb.h"
#include "bitcoinrpc.h"
#include "net.h"
-#include "init.h"
+
#include "util.h"
#include "ui_interface.h"
#include "timer.h"
@@ -85,6 +87,7 @@ void Shutdown(void* parg)
// CTxDB().Close();
bitdb.Flush(false);
StopNode();
+ UnregisterNodeSignals(GetNodeSignals());
bitdb.Flush(true);
boost::filesystem::remove(GetPidFile());
delete pWalletManager;
@@ -673,6 +676,8 @@ bool AppInit2()
// ********************************************************* Step 6: network initialization
+ RegisterNodeSignals(GetNodeSignals());
+
int nSocksVersion = GetArg("-socks", 5);
if (nSocksVersion != 4 && nSocksVersion != 5)
View
@@ -54,6 +54,8 @@ uint256 nBestInvalidTrust = 0;
uint256 hashBestChain = 0;
CBlockIndex* pindexBest = NULL;
int64 nTimeBestReceived = 0;
+bool fImporting = false; //Tranz need to fix this 66b02c93
+bool fReindex = false; // Tranz need to fix this 7fea4846
CMedianFilter<int> cPeerBlockCounts(5, 0); // Amount of blocks that other nodes claim to have
@@ -232,8 +234,80 @@ void ResendWalletTransactions(bool fForce)
}
+//////////////////////////////////////////////////////////////////////////////
+//
+// Registration of network node signals.
+//
+
+namespace {
+// Maintain validation-specific state about nodes, protected by cs_main, instead
+// by CNode's own locks. This simplifies asynchronous operation, where
+// processing of incoming data is done after the ProcessMessage call returns,
+// and we're no longer holding the node's locks.
+struct CNodeState {
+ // Accumulated misbehaviour score for this peer.
+ int nMisbehavior;
+ // Whether this peer should be disconnected and banned.
+ bool fShouldBan;
+ // String name of this peer (debugging/logging purposes).
+ std::string name;
+
+ CNodeState() {
+ nMisbehavior = 0;
+ fShouldBan = false;
+ }
+};
+
+map<NodeId, CNodeState> mapNodeState;
+
+// Requires cs_main. (Tranz Locks removed for now due to deadlock)
+CNodeState *State(NodeId pnode) {
+ map<NodeId, CNodeState>::iterator it = mapNodeState.find(pnode);
+ if (it == mapNodeState.end())
+ return NULL;
+ return &it->second;
+}
+
+int GetHeight()
+{
+ return nBestHeight;
+}
+void InitializeNode(NodeId nodeid, const CNode *pnode) {
+ CNodeState &state = mapNodeState.insert(std::make_pair(nodeid, CNodeState())).first->second;
+ state.name = pnode->addrName;
+}
+
+void FinalizeNode(NodeId nodeid) {
+ mapNodeState.erase(nodeid);
+}
+}
+
+bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) {
+ CNodeState *state = State(nodeid);
+ if (state == NULL)
+ return false;
+ stats.nMisbehavior = state->nMisbehavior;
+ return true;
+}
+
+void RegisterNodeSignals(CNodeSignals& nodeSignals)
+{
+ nodeSignals.GetHeight.connect(&GetHeight);
+ nodeSignals.ProcessMessages.connect(&ProcessMessages);
+ nodeSignals.SendMessages.connect(&SendMessages);
+ nodeSignals.InitializeNode.connect(&InitializeNode);
+ nodeSignals.FinalizeNode.connect(&FinalizeNode);
+}
+void UnregisterNodeSignals(CNodeSignals& nodeSignals)
+{
+ nodeSignals.GetHeight.disconnect(&GetHeight);
+ nodeSignals.ProcessMessages.disconnect(&ProcessMessages);
+ nodeSignals.SendMessages.disconnect(&SendMessages);
+ nodeSignals.InitializeNode.disconnect(&InitializeNode);
+ nodeSignals.FinalizeNode.disconnect(&FinalizeNode);
+}
@@ -2279,6 +2353,24 @@ bool CBlockIndex::IsSuperMajority(int minVersion, const CBlockIndex* pstart, uns
return (nFound >= nRequired);
}
+void Misbehaving(NodeId pnode, int howmuch)
+{
+ if (howmuch == 0)
+ return;
+
+ CNodeState *state = State(pnode);
+ if (state == NULL)
+ return;
+
+ state->nMisbehavior += howmuch;
+ if (state->nMisbehavior >= GetArg("-banscore", 100))
+ {
+ printf("Misbehaving: %s (%d -> %d) BAN THRESHOLD EXCEEDED\n", state->name.c_str(), state->nMisbehavior-howmuch, state->nMisbehavior);
+ state->fShouldBan = true;
+ } else
+ printf("Misbehaving: %s (%d -> %d)\n", state->name.c_str(), state->nMisbehavior-howmuch, state->nMisbehavior);
+}
+
uint256 CBlockIndex::GetBlockTrust() const
{
CBigNum bnTarget;
@@ -2337,7 +2429,7 @@ bool ProcessBlock(CNode* pfrom, CBlock* pblock)
if (bnNewBlock > bnRequired)
{
if (pfrom)
- pfrom->Misbehaving(100);
+ Misbehaving(pfrom->GetId(), 100);
return error("ProcessBlock() : block with too little %s", pblock->IsProofOfStake()? "proof-of-stake" : "proof-of-work");
}
}
@@ -3006,6 +3098,8 @@ bool static AlreadyHave(CTxDB& txdb, const CInv& inv)
+
+
// The message start string is designed to be unlikely to occur in normal data.
// The characters are rarely used upper ASCII, not valid as UTF-8, and produce
// a large 4-byte int at any alignment.
@@ -3032,7 +3126,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
// Each connection can only send one version message
if (pfrom->nVersion != 0)
{
- pfrom->Misbehaving(1);
+ Misbehaving(pfrom->GetId(), 1);
return false;
}
@@ -3061,8 +3155,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
pfrom->nVersion = 300;
if (!vRecv.empty())
vRecv >> addrFrom >> nNonce;
- if (!vRecv.empty())
+ if (!vRecv.empty()) {
vRecv >> pfrom->strSubVer;
+ pfrom->cleanSubVer = SanitizeString(pfrom->strSubVer);
+ }
if (!vRecv.empty())
vRecv >> pfrom->nStartingHeight;
@@ -3122,18 +3218,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
}
}
- // Ask the first connected node for block updates
- static int nAskedForBlocks = 0;
- if (!pfrom->fClient && !pfrom->fOneShot &&
- (pfrom->nStartingHeight > (nBestHeight - 144)) &&
- (pfrom->nVersion < NOBLKS_VERSION_START ||
- pfrom->nVersion >= NOBLKS_VERSION_END) &&
- (nAskedForBlocks < 1 || vNodes.size() <= 1))
- {
- nAskedForBlocks++;
- pfrom->PushGetBlocks(pindexBest, uint256(0));
- }
-
// Relay alerts
{
LOCK(cs_mapAlerts);
@@ -3150,7 +3234,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
pfrom->fSuccessfullyConnected = true;
- printf("receive version message: version %d, blocks=%d, us=%s, them=%s, peer=%s\n", pfrom->nVersion, pfrom->nStartingHeight, addrMe.ToString().c_str(), addrFrom.ToString().c_str(), pfrom->addr.ToString().c_str());
+ printf("receive version message: version %s, blocks=%d, us=%s, them=%s, peer=%s\n", pfrom->cleanSubVer.c_str(), pfrom->nStartingHeight, addrMe.ToString().c_str(), addrFrom.ToString().c_str(), pfrom->addr.ToString().c_str());
cPeerBlockCounts.input(pfrom->nStartingHeight);
@@ -3163,7 +3247,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
else if (pfrom->nVersion == 0)
{
// Must have a version message before anything else
- pfrom->Misbehaving(1);
+ Misbehaving(pfrom->GetId(), 1);
return false;
}
@@ -3184,7 +3268,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
return true;
if (vAddr.size() > 1000)
{
- pfrom->Misbehaving(20);
+ Misbehaving(pfrom->GetId(), 20);
return error("message addr size() = %"PRIszu"", vAddr.size());
}
@@ -3247,7 +3331,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
vRecv >> vInv;
if (vInv.size() > MAX_INV_SZ)
{
- pfrom->Misbehaving(20);
+ Misbehaving(pfrom->GetId(), 20);
return error("message inv size() = %"PRIszu"", vInv.size());
}
@@ -3297,7 +3381,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
vRecv >> vInv;
if (vInv.size() > MAX_INV_SZ)
{
- pfrom->Misbehaving(20);
+ Misbehaving(pfrom->GetId(), 20);
return error("message getdata size() = %"PRIszu"", vInv.size());
}
@@ -3511,7 +3595,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
if (nEvicted > 0)
printf("mapOrphan overflow, removed %u tx\n", nEvicted);
}
- if (tx.nDoS) pfrom->Misbehaving(tx.nDoS);
+ if (tx.nDoS) Misbehaving(pfrom->GetId(), tx.nDoS);
}
@@ -3529,7 +3613,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
if (ProcessBlock(pfrom, &block))
mapAlreadyAskedFor.erase(inv);
- if (block.nDoS) pfrom->Misbehaving(block.nDoS);
+ if (block.nDoS) Misbehaving(pfrom->GetId(), block.nDoS);
}
@@ -3675,7 +3759,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
if (!(sProblem.empty())) {
printf("pong %s %s: %s, %"PRI64x" expected, %"PRI64x" received, %u bytes\n"
, pfrom->addr.ToString().c_str()
- , pfrom->strSubVer.c_str()
+ , pfrom->cleanSubVer.c_str()
, sProblem.c_str()
, pfrom->nPingNonceSent
, nonce
@@ -3711,7 +3795,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
// This isn't a Misbehaving(100) (immediate ban) because the
// peer might be an older or different implementation with
// a different signature key, etc.
- pfrom->Misbehaving(10);
+ Misbehaving(pfrom->GetId(), 10);
}
}
}
@@ -3884,6 +3968,12 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
}
}
+ // Start block sync
+ if (pto->fStartSync && !fImporting && !fReindex) {
+ pto->fStartSync = false;
+ pto->PushGetBlocks(pindexBest, uint256(0));
+ }
+
// Resend wallet transactions that haven't gotten in a block yet
ResendWalletTransactions();
@@ -3937,6 +4027,20 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
pto->PushMessage("addr", vAddr);
}
+ TRY_LOCK(cs_main, lockMain);
+ if (!lockMain)
+ return true;
+
+ if (State(pto->GetId())->fShouldBan) {
+ if (pto->addr.IsLocal())
+ printf("Warning: not banning local node %s!\n", pto->addr.ToString().c_str());
+ else {
+ pto->fDisconnect = true;
+ CNode::Ban(pto->addr);
+ }
+ State(pto->GetId())->fShouldBan = false;
+ }
+
//
// Message: inventory
View
@@ -105,6 +105,8 @@ extern CCriticalSection cs_setpwalletRegistered;
extern std::set<CWallet*> setpwalletRegistered;
extern unsigned char pchMessageStart[4];
extern std::map<uint256, CBlock*> mapOrphanBlocks;
+extern bool fImporting;
+extern bool fReindex;
// Settings
extern int64 nTransactionFee;
@@ -118,12 +120,17 @@ static const uint64 nMinDiskSpace = 52428800;
class CReserveKey;
class CTxDB;
class CTxIndex;
+struct CNodeStateStats;
void RegisterWallet(CWallet* pwalletIn);
void UnregisterWallet(CWallet* pwalletIn);
void UnregisterAllWallets();
void SyncWithWallets(const CTransaction& tx, const CBlock* pblock = NULL, bool fUpdate = false, bool fConnect = true);
void ReacceptWalletTransactions();
+/** Register with a network node to receive its signals */
+void RegisterNodeSignals(CNodeSignals& nodeSignals);
+/** Unregister a network node */
+void UnregisterNodeSignals(CNodeSignals& nodeSignals);
bool ProcessBlock(CNode* pfrom, CBlock* pblock);
bool CheckDiskSpace(uint64 nAdditionalBytes=0);
FILE* OpenBlockFile(unsigned int nFile, unsigned int nBlockPos, const char* pszMode="rb");
@@ -151,22 +158,20 @@ const CBlockIndex* GetLastBlockIndex(const CBlockIndex* pindex, bool fProofOfSta
void BitcoinMiner(CWallet *pwallet);
void StakeMiner(CWallet *pwallet);
void ResendWalletTransactions(bool fForce = false);
+/** Get statistics from node state */
+bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats);
/** (try to) add transaction to memory pool **/
bool AcceptToMemoryPool(CTxMemPool& pool, CTransaction &tx,
bool* pfMissingInputs);
+bool GetWalletFile(CWallet* pwallet, std::string &strWalletFileOut);
+struct CNodeStateStats {
+int nMisbehavior;
+};
-
-
-
-
-
-
-bool GetWalletFile(CWallet* pwallet, std::string &strWalletFileOut);
-
/** Position on disk for a particular transaction. */
class CDiskTxPos
{
Oops, something went wrong.

0 comments on commit e6c3456

Please sign in to comment.