From f9b18254ab35cfc57ec0f7359cf34d643319e860 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 8 Apr 2013 01:17:20 -0700 Subject: [PATCH] Fix some paths we missed. --- src/cpp/ripple/Pathfinder.cpp | 21 ++++++++++++--------- src/cpp/ripple/Pathfinder.h | 3 ++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/cpp/ripple/Pathfinder.cpp b/src/cpp/ripple/Pathfinder.cpp index 502ed9fbc..f7972951e 100644 --- a/src/cpp/ripple/Pathfinder.cpp +++ b/src/cpp/ripple/Pathfinder.cpp @@ -121,9 +121,9 @@ typedef std::pair candidate_t; bool candCmp(uint32 seq, const candidate_t& first, const candidate_t& second) { if (first.first < second.first) - return true; - if (first.first > second.first) return false; + if (first.first > second.first) + return true; return (first.first ^ seq) < (second.first ^ seq); } @@ -464,13 +464,13 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax } else if (dstCurrency && (uPeerID == mDstAccountID)) { // never skip the destination node - candidates.push_back(std::make_pair(-1, uPeerID)); + candidates.push_back(std::make_pair(1000000, uPeerID)); } else { // save this candidate - int paths_out = getPathsOut(speEnd.mCurrencyID, uPeerID, dstCurrency, mDstAccountID); - if (paths_out != 0) - candidates.push_back(std::make_pair(paths_out, uPeerID)); + int out = getPathsOut(speEnd.mCurrencyID, uPeerID, bRequireAuth, dstCurrency, mDstAccountID); + if (out != 0) + candidates.push_back(std::make_pair(out, uPeerID)); } } @@ -832,7 +832,7 @@ bool Pathfinder::matchesOrigin(const uint160& currency, const uint160& issuer) } int Pathfinder::getPathsOut(const uint160& currencyID, const uint160& accountID, - bool isDstCurrency, const uint160& dstAccount) + bool authRequired, bool isDstCurrency, const uint160& dstAccount) { std::pair accountCurrency(currencyID, accountID); boost::unordered_map, int>::iterator it = mPOMap.find(accountCurrency); @@ -846,10 +846,13 @@ int Pathfinder::getPathsOut(const uint160& currencyID, const uint160& accountID, RippleState* rspEntry = (RippleState*) item.get(); if (currencyID != rspEntry->getLimit().getCurrency()) nothing(); - else if (!rspEntry->getBalance().isPositive() && !rspEntry->getLimitPeer().isPositive()) // no credit + else if (!rspEntry->getBalance().isPositive() && + (!rspEntry->getLimitPeer() + || -rspEntry->getBalance() >= rspEntry->getLimitPeer() + || (authRequired && !rspEntry->getAuth()))) nothing(); else if (isDstCurrency && (dstAccount == rspEntry->getAccountIDPeer())) - count += 10; // count a path to the destination extra + count += 100; // count a path to the destination extra else ++count; } diff --git a/src/cpp/ripple/Pathfinder.h b/src/cpp/ripple/Pathfinder.h index d82b250e3..3de0b3c0a 100644 --- a/src/cpp/ripple/Pathfinder.h +++ b/src/cpp/ripple/Pathfinder.h @@ -65,7 +65,8 @@ class Pathfinder AccountItems& getRippleLines(const uint160& accountID); - int getPathsOut(const uint160& currency, const uint160& accountID, bool isDestCurrency, const uint160& dest); + int getPathsOut(const uint160& currency, const uint160& accountID, + bool isAuthRequired, bool isDestCurrency, const uint160& dest); public: Pathfinder(Ledger::ref ledger,