diff --git a/src/init.cpp b/src/init.cpp
index 612f37bf2eff..b587bf0cf79a 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -303,7 +303,8 @@ std::string HelpMessage()
" -datadir=
" + _("Specify data directory") + "\n" +
" -dbcache= " + _("Set database cache size in megabytes (default: 25)") + "\n" +
" -timeout= " + _("Specify connection timeout in milliseconds (default: 5000)") + "\n" +
- " -proxy= " + _("Connect through socks proxy") + "\n" +
+ " -proxy= " + _("Exclusively connect through socks proxy") + "\n" +
+ " -proxytoo= " + _("Also connect through socks proxy") + "\n" +
" -socks= " + _("Select the version of socks proxy to use (4-5, default: 5)") + "\n" +
" -tor= " + _("Use proxy to reach tor hidden services (default: same as -proxy)") + "\n"
" -dns " + _("Allow DNS lookups for -addnode, -seednode and -connect") + "\n" +
@@ -582,6 +583,7 @@ bool AppInit2(boost::thread_group& threadGroup)
fPrintToConsole = GetBoolArg("-printtoconsole");
fPrintToDebugger = GetBoolArg("-printtodebugger");
fLogTimestamps = GetBoolArg("-logtimestamps", true);
+ fMasternodes = GetBoolArg("-masternodes");
bool fDisableWallet = GetBoolArg("-disablewallet", false);
if (mapArgs.count("-timeout"))
@@ -780,6 +782,23 @@ bool AppInit2(boost::thread_group& threadGroup)
SetReachable(NET_TOR);
}
+ if (mapArgs.count("-proxytoo")) {
+ fProxyToo = true;
+ CService addrProxy = CService(mapArgs["-proxytoo"], 9050);
+ if (!addrProxy.IsValid())
+ return InitError(strprintf(_("Invalid -proxytoo address: '%s'"), mapArgs["-proxytoo"].c_str()));
+
+ if (!IsLimited(NET_IPV4))
+ SetProxy(NET_IPV4, addrProxy, nSocksVersion);
+ if (nSocksVersion > 4) {
+#ifdef USE_IPV6
+ if (!IsLimited(NET_IPV6))
+ SetProxy(NET_IPV6, addrProxy, nSocksVersion);
+#endif
+ SetNameProxy(addrProxy, nSocksVersion);
+ }
+ }
+
// see Step 2: parameter interactions for more information about these
fNoListen = !GetBoolArg("-listen", true);
fDiscover = GetBoolArg("-discover", true);
diff --git a/src/main.cpp b/src/main.cpp
index dd5876ba77d9..97e7eb9c917a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -46,6 +46,7 @@ uint256 hashBestChain = 0;
CBlockIndex* pindexBest = NULL;
set setBlockIndexValid; // may contain all CBlockIndex*'s that have validness >=BLOCK_VALID_TRANSACTIONS, and must contain those who aren't failed
int64 nTimeBestReceived = 0;
+int nAskedForBlocks = 0;
int nScriptCheckThreads = 0;
bool fImporting = false;
bool fReindex = false;
@@ -2616,6 +2617,7 @@ bool CBlock::CheckBlock(CValidationState &state, bool fCheckPOW, bool fCheckMerk
} else {
if(nTime > START_MASTERNODE_PAYMENTS) MasternodePayments = true;
}
+ if (fMasternodes) MasternodePayments = true;
if(MasternodePayments)
{
@@ -2644,7 +2646,7 @@ bool CBlock::CheckBlock(CValidationState &state, bool fCheckPOW, bool fCheckMerk
printf("CheckBlock() : loading prev orphan block %s\n", hashPrevBlock.ToString().c_str());
blockLast = *mapOrphanBlocks[hashPrevBlock];
} else {
- state.DoS(100, error("CheckBlock() : Couldn't load previous block"));
+ printf("CheckBlock() : Couldn't load previous block %s\n", hashPrevBlock.ToString().c_str());
}
if (pindexPrev != NULL && fCheckVotes && !fIsInitialDownload){
@@ -2955,7 +2957,8 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl
mapOrphanBlocksByPrev.insert(make_pair(pblock2->hashPrevBlock, pblock2));
// Ask this guy to fill in what we're missing
- pfrom->PushGetBlocks(pindexBest, GetOrphanRoot(pblock2));
+ if (pfrom->PushGetBlocks(pindexBest, GetOrphanRoot(pblock2)))
+ printf("send fill-in getblocks for %s peer=%d\n", hash.ToString().c_str(), pfrom->id);
}
return true;
}
@@ -2988,7 +2991,6 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl
//might need to reset pool
darkSendPool.NewBlock();
- printf("ProcessBlock: ACCEPTED\n");
return true;
}
@@ -3983,7 +3985,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
pfrom->fSuccessfullyConnected = true;
- printf("receive version message: %s: version %d, blocks=%d, us=%s, them=%s, peer=%s\n", pfrom->cleanSubVer.c_str(), pfrom->nVersion, pfrom->nStartingHeight, addrMe.ToString().c_str(), addrFrom.ToString().c_str(), pfrom->addr.ToString().c_str());
+ printf("receive version message: %s: version %d, blocks=%d, us=%s, them=%s, peer=%d\n", pfrom->cleanSubVer.c_str(), pfrom->nVersion, pfrom->nStartingHeight, addrMe.ToString().c_str(), addrFrom.ToString().c_str(), pfrom->id);
cPeerBlockCounts.input(pfrom->nStartingHeight);
}
@@ -4002,6 +4004,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
pfrom->SetRecvVersion(min(pfrom->nVersion, PROTOCOL_VERSION));
}
+ else if (strCommand == "misbehave") {
+ int howmuch;
+ vRecv >> howmuch;
+ printf("peer=%d says we are misbehaving %d\n", howmuch);
+ }
+
else if (strCommand == "dseg") { //DarkSend Election Get
if (pfrom->nVersion != darkSendPool.MIN_PEER_PROTO_VERSION) {
return false;
@@ -4102,6 +4110,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
return false;
}
+ addrman.Add(CAddress(addr), pfrom->addr, 2*60*60);
CMasterNode mn(addr, vin, pubkey, vchSig, sigTime, pubkey2);
mn.UpdateLastSeen(lastUpdated);
@@ -4236,8 +4245,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
addrman.Add(vAddrOk, pfrom->addr, 2 * 60 * 60);
if (vAddr.size() < 1000)
pfrom->fGetAddr = false;
- if (pfrom->fOneShot)
+ if (pfrom->fOneShot) {
+ printf("OneShot. Disconnecting\n");
pfrom->fDisconnect = true;
+ }
}
@@ -4274,12 +4285,14 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
if (!fImporting && !fReindex)
pfrom->AskFor(inv);
} else if (inv.type == MSG_BLOCK && mapOrphanBlocks.count(inv.hash)) {
- pfrom->PushGetBlocks(pindexBest, GetOrphanRoot(mapOrphanBlocks[inv.hash]));
+ if (pfrom->PushGetBlocks(pindexBest, GetOrphanRoot(mapOrphanBlocks[inv.hash])))
+ printf("send getblocks for %s peer=%d\n", inv.hash.ToString().c_str(), pfrom->id);
} else if (nInv == nLastBlock) {
// In case we are on a very long side-chain, it is possible that we already have
// the last block in an inv bundle sent in response to getblocks. Try to detect
// this situation and push another getblocks to continue.
- pfrom->PushGetBlocks(mapBlockIndex[inv.hash], uint256(0));
+ if (pfrom->PushGetBlocks(mapBlockIndex[inv.hash], uint256(0)))
+ printf("send last getblocks for %s peer=%d\n", inv.hash.ToString().c_str(), pfrom->id);
if (fDebug)
printf("force request: %s\n", inv.ToString().c_str());
}
@@ -4301,10 +4314,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
}
if (fDebugNet || (vInv.size() != 1))
- printf("received getdata (%"PRIszu" invsz)\n", vInv.size());
+ printf("received getdata (%"PRIszu" invsz) peer=%d\n", vInv.size(), pfrom->id);
if ((fDebugNet && vInv.size() > 0) || (vInv.size() == 1))
- printf("received getdata for: %s\n", vInv[0].ToString().c_str());
+ printf("received getdata for: %s peer=%d\n", vInv[0].ToString().c_str(), pfrom->id);
pfrom->vRecvGetData.insert(pfrom->vRecvGetData.end(), vInv.begin(), vInv.end());
ProcessGetData(pfrom);
@@ -4324,7 +4337,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
if (pindex)
pindex = pindex->pnext;
int nLimit = 500;
- printf("getblocks %d to %s limit %d\n", (pindex ? pindex->nHeight : -1), hashStop.ToString().c_str(), nLimit);
+ printf("getblocks %d to %s limit %d peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop==uint256(0) ? "0" : hashStop.ToString().c_str(), nLimit, pfrom->id);
for (; pindex; pindex = pindex->pnext)
{
if (pindex->GetBlockHash() == hashStop)
@@ -4468,7 +4481,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
CBlock block;
vRecv >> block;
- printf("received block %s\n", block.GetHash().ToString().c_str());
+ printf("received block %s peer=%d\n", block.GetHash().ToString().c_str(), pfrom->id);
// block.print();
CInv inv(MSG_BLOCK, block.GetHash());
@@ -4784,9 +4797,14 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
}
// Start block sync
- if (pto->fStartSync && !fImporting && !fReindex) {
- pto->fStartSync = false;
- pto->PushGetBlocks(pindexBest, uint256(0));
+ if (!pto->fAskedForBlocks && !fImporting && !fReindex && !pto->fClient && !pto->fOneShot &&
+ !pto->fDisconnect && pto->fSuccessfullyConnected &&
+ (pto->nStartingHeight > (nBestHeight - 144)) &&
+ (pto->nVersion < NOBLKS_VERSION_START || pto->nVersion >= NOBLKS_VERSION_END)) {
+ nAskedForBlocks++;
+ pto->fAskedForBlocks = true;
+ if (pto->PushGetBlocks(pindexBest, uint256(0)))
+ printf("send initial getblocks peer=%d\n", pto->id);
}
// Resend wallet transactions that haven't gotten in a block yet
@@ -4917,7 +4935,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
if (!AlreadyHave(inv))
{
if (fDebugNet)
- printf("sending getdata: %s\n", inv.ToString().c_str());
+ printf("sending getdata: %s peer=%d\n", inv.ToString().c_str(), pto->id);
vGetData.push_back(inv);
if (vGetData.size() >= 1000)
{
diff --git a/src/main.h b/src/main.h
index 34470c5e8a7a..9717efc82fd5 100644
--- a/src/main.h
+++ b/src/main.h
@@ -120,6 +120,7 @@ extern bool fImporting;
extern bool fReindex;
extern bool fBenchmark;
extern int nScriptCheckThreads;
+extern int nAskedForBlocks; // Nodes sent a getblocks 0
extern bool fTxIndex;
extern unsigned int nCoinCacheSize;
extern CDarkSendPool darkSendPool;
diff --git a/src/net.cpp b/src/net.cpp
index 12267b754b02..ed90bd236bd8 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -69,6 +69,9 @@ CCriticalSection cs_setservAddNodeAddresses;
vector vAddedNodes;
CCriticalSection cs_vAddedNodes;
+NodeId nLastNodeId = 0;
+CCriticalSection cs_nLastNodeId;
+
static CSemaphore *semOutbound = NULL;
void AddOneShot(string strDest)
@@ -82,15 +85,16 @@ unsigned short GetListenPort()
return (unsigned short)(GetArg("-port", GetDefaultPort()));
}
-void CNode::PushGetBlocks(CBlockIndex* pindexBegin, uint256 hashEnd)
+bool CNode::PushGetBlocks(CBlockIndex* pindexBegin, uint256 hashEnd)
{
// Filter out duplicate requests
if (pindexBegin == pindexLastGetBlocksBegin && hashEnd == hashLastGetBlocksEnd)
- return;
+ return false;
pindexLastGetBlocksBegin = pindexBegin;
hashLastGetBlocksEnd = hashEnd;
PushMessage("getblocks", CBlockLocator(pindexBegin), hashEnd);
+ return true;
}
// find 'best' local address for a particular peer
@@ -471,9 +475,9 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest)
/// debug print
- printf("trying connection %s lastseen=%.1fhrs\n",
+ printf("trying connection %s lastseen=%.1fdays\n",
pszDest ? pszDest : addrConnect.ToString().c_str(),
- pszDest ? 0 : (double)(GetAdjustedTime() - addrConnect.nTime)/3600.0);
+ pszDest ? 0 : (double)(GetAdjustedTime() - addrConnect.nTime)/86400.0);
// Connect
SOCKET hSocket;
@@ -544,7 +548,7 @@ void CNode::PushVersion()
CAddress addrYou = (addr.IsRoutable() && !IsProxy(addr) ? addr : CAddress(CService("0.0.0.0",0)));
CAddress addrMe = GetLocalAddress(&addr);
RAND_bytes((unsigned char*)&nLocalHostNonce, sizeof(nLocalHostNonce));
- printf("send version message: version %d, blocks=%d, us=%s, them=%s, peer=%s\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString().c_str(), addrYou.ToString().c_str(), addr.ToString().c_str());
+ printf("send version message: version %d, blocks=%d, us=%s, them=%s, peer=%d\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString().c_str(), addrYou.ToString().c_str(), id);
PushMessage("version", PROTOCOL_VERSION, nLocalServices, nTime, addrYou, addrMe,
nLocalHostNonce, FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, std::vector()), nBestHeight);
}
@@ -586,6 +590,7 @@ bool CNode::Misbehaving(int howmuch)
}
nMisbehavior += howmuch;
+ PushMessage("misbehave", howmuch);
if (nMisbehavior >= GetArg("-banscore", 100))
{
int64 banTime = GetTime()+GetArg("-bantime", 60*60*24); // Default 24-hour ban
diff --git a/src/net.h b/src/net.h
index 218f019b5030..1f5feb8fbaef 100644
--- a/src/net.h
+++ b/src/net.h
@@ -46,6 +46,8 @@ void StartNode(boost::thread_group& threadGroup);
bool StopNode();
void SocketSendData(CNode *pnode);
+typedef int NodeId;
+
enum
{
LOCAL_NONE, // unknown
@@ -87,7 +89,8 @@ extern limitedmap mapAlreadyAskedFor;
extern std::vector vAddedNodes;
extern CCriticalSection cs_vAddedNodes;
-
+extern NodeId nLastNodeId;
+extern CCriticalSection cs_nLastNodeId;
class CNodeStats
@@ -191,6 +194,7 @@ class CNode
bool fNetworkNode;
bool fSuccessfullyConnected;
bool fDisconnect;
+ bool fAskedForBlocks; // true when getblocks 0 sent
// We use fRelayTxes for two purposes -
// a) it allows us to not relay tx invs before receiving the peer's version message
// b) the peer may tell us in their version message that we should not relay tx invs
@@ -200,6 +204,7 @@ class CNode
CCriticalSection cs_filter;
CBloomFilter* pfilter;
int nRefCount;
+ NodeId id;
protected:
// Denial-of-service detection/prevention
@@ -249,6 +254,7 @@ class CNode
fNetworkNode = false;
fSuccessfullyConnected = false;
fDisconnect = false;
+ fAskedForBlocks = false;
nRefCount = 0;
nSendSize = 0;
nSendOffset = 0;
@@ -263,6 +269,11 @@ class CNode
setInventoryKnown.max_size(SendBufferSize() / 1000);
pfilter = new CBloomFilter();
+ {
+ LOCK(cs_nLastNodeId);
+ id = nLastNodeId++;
+ }
+
// Be shy and don't send version until we hear
if (hSocket != INVALID_SOCKET && !fInbound)
PushVersion();
@@ -608,7 +619,7 @@ class CNode
}
}
- void PushGetBlocks(CBlockIndex* pindexBegin, uint256 hashEnd);
+ bool PushGetBlocks(CBlockIndex* pindexBegin, uint256 hashEnd);
bool IsSubscribed(unsigned int nChannel);
void Subscribe(unsigned int nChannel, unsigned int nHops=0);
void CancelSubscribe(unsigned int nChannel);
diff --git a/src/netbase.cpp b/src/netbase.cpp
index d9695167502d..e69d8cd21a68 100644
--- a/src/netbase.cpp
+++ b/src/netbase.cpp
@@ -21,6 +21,7 @@ using namespace std;
static proxyType proxyInfo[NET_MAX];
static proxyType nameproxyInfo;
static CCriticalSection cs_proxyInfos;
+int fProxyToo = false;
int nConnectTimeout = 5000;
bool fNameLookup = false;
@@ -475,7 +476,7 @@ bool ConnectSocket(const CService &addrDest, SOCKET& hSocketRet, int nTimeout)
proxyType proxy;
// no proxy needed
- if (!GetProxy(addrDest.GetNetwork(), proxy))
+ if (!GetProxy(addrDest.GetNetwork(), proxy) || (fProxyToo && rand() %2 == 0))
return ConnectSocketDirectly(addrDest, hSocketRet, nTimeout);
SOCKET hSocket = INVALID_SOCKET;
diff --git a/src/netbase.h b/src/netbase.h
index e4ec4ef5971f..1bc7ef1b42e9 100644
--- a/src/netbase.h
+++ b/src/netbase.h
@@ -148,4 +148,6 @@ bool LookupNumeric(const char *pszName, CService& addr, int portDefault = 0);
bool ConnectSocket(const CService &addr, SOCKET& hSocketRet, int nTimeout = nConnectTimeout);
bool ConnectSocketByName(CService &addr, SOCKET& hSocketRet, const char *pszDest, int portDefault = 0, int nTimeout = nConnectTimeout);
+// Settings
+extern int fProxyToo;
#endif
diff --git a/src/util.cpp b/src/util.cpp
index d9fb3b9c0b29..ac070c40de7e 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -82,6 +82,7 @@ bool fTestNet = false;
bool fBloomFilters = true;
bool fNoListen = false;
bool fLogTimestamps = false;
+bool fMasternodes = false;
CMedianFilter vTimeOffsets(200,0);
volatile bool fReopenDebugLog = false;
bool fCachedPath[2] = {false, false};
diff --git a/src/util.h b/src/util.h
index 42f5a7cf7958..449360bf71a4 100644
--- a/src/util.h
+++ b/src/util.h
@@ -147,6 +147,7 @@ extern bool fTestNet;
extern bool fBloomFilters;
extern bool fNoListen;
extern bool fLogTimestamps;
+extern bool fMasternodes;
extern volatile bool fReopenDebugLog;
void RandAddSeed();