Merge branch 'master' of github.com:jedmccaleb/NewCoin

This commit is contained in:
Arthur Britto
2013-03-19 02:34:35 -07:00
3 changed files with 35 additions and 6 deletions

View File

@@ -209,6 +209,12 @@ void ConnectionPool::policyEnforce()
// Enforce policies.
policyLowWater();
if (((++mPhase) % 12) == 0)
{
cLog(lsTRACE) << "Making configured connections";
makeConfigured();
}
// Schedule next enforcement.
mPolicyTimer.expires_at(boost::posix_time::second_clock::universal_time()+boost::posix_time::seconds(POLICY_INTERVAL_SECONDS));
mPolicyTimer.async_wait(boost::bind(&ConnectionPool::policyHandler, this, _1));
@@ -313,11 +319,11 @@ Peer::pointer ConnectionPool::peerConnect(const std::string& strIp, int iPort)
if (ppResult)
{
ppResult->connect(strIp, iPort);
//cLog(lsINFO) << "Pool: Connecting: " << ADDRESS_SHARED(ppResult) << ": " << strIp << " " << iPort;
cLog(lsTRACE) << "Pool: Connecting: " << ADDRESS_SHARED(ppResult) << ": " << strIp << " " << iPort;
}
else
{
//cLog(lsINFO) << "Pool: Already connected: " << strIp << " " << iPort;
cLog(lsTRACE) << "Pool: Already connected: " << strIp << " " << iPort;
}
return ppResult;
@@ -623,6 +629,20 @@ void ConnectionPool::scanHandler(const boost::system::error_code& ecResult)
}
}
void ConnectionPool::makeConfigured()
{
if (theConfig.RUN_STANDALONE)
return;
BOOST_FOREACH(const std::string& strPeer, theConfig.IPS)
{
std::string strIP;
int iPort;
if (parseIpPort(strPeer, strIP, iPort))
peerConnect(strIP, iPort);
}
}
// Scan ips as per db entries.
void ConnectionPool::scanRefresh()
{

View File

@@ -18,6 +18,7 @@ class ConnectionPool
private:
boost::recursive_mutex mPeerLock;
uint64 mLastPeer;
int mPhase;
typedef std::pair<RippleAddress, Peer::pointer> naPeer;
typedef std::pair<ipPort, Peer::pointer> pipPeer;
@@ -59,7 +60,7 @@ private:
public:
ConnectionPool(boost::asio::io_service& io_service) :
mLastPeer(0), mScanTimer(io_service), mPolicyTimer(io_service)
mLastPeer(0), mPhase(0), mScanTimer(io_service), mPolicyTimer(io_service)
{ ; }
// Begin enforcing connection policy.
@@ -114,6 +115,8 @@ public:
void policyLowWater();
void policyEnforce();
// configured connections
void makeConfigured();
};
extern void splitIpPort(const std::string& strIpPort, std::string& strIp, int& iPort);

View File

@@ -41,7 +41,7 @@ void SHAMap::getMissingNodes(std::vector<SHAMapNode>& nodeIDs, std::vector<uint2
stack.pop();
int base = rand() % 256;
bool have_all = false;
bool have_all = true;
for (int ii = 0; ii < 16; ++ii)
{ // traverse in semi-random order
int branch = (base + ii) % 16;
@@ -72,14 +72,17 @@ void SHAMap::getMissingNodes(std::vector<SHAMapNode>& nodeIDs, std::vector<uint2
}
if (!d)
{ // we need this node
have_all = false;
nodeIDs.push_back(childID);
hashes.push_back(childHash);
if (--max <= 0)
return;
have_all = false;
}
else if (d->isInner() && !d->isFullBelow()) // we might need children of this node
{
have_all = false;
stack.push(d);
}
}
}
if (have_all)
@@ -111,7 +114,7 @@ std::vector<uint256> SHAMap::getNeededHashes(int max)
stack.pop();
int base = rand() % 256;
bool have_all = false;
bool have_all = true;
for (int ii = 0; ii < 16; ++ii)
{ // traverse in semi-random order
int branch = (base + ii) % 16;
@@ -124,7 +127,10 @@ std::vector<uint256> SHAMap::getNeededHashes(int max)
SHAMapTreeNode* d = getNodePointer(childID, childHash);
assert(d);
if (d->isInner() && !d->isFullBelow())
{
have_all = false;
stack.push(d);
}
}
catch (SHAMapMissingNode&)
{ // node is not in the map