From 2e39dfc15a4c4eb0d97f49f9ce82eb0ea5720f4c Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 12 Apr 2013 16:03:57 -0700 Subject: [PATCH] Don't explore paths if we don't have enough path length left to use them. --- src/cpp/ripple/Pathfinder.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/cpp/ripple/Pathfinder.cpp b/src/cpp/ripple/Pathfinder.cpp index d58d951da..f3134e904 100644 --- a/src/cpp/ripple/Pathfinder.cpp +++ b/src/cpp/ripple/Pathfinder.cpp @@ -369,7 +369,9 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax continue; } - else if (!speEnd.mCurrencyID) + bool isLast = (spPath.mPath.size() == (iMaxSteps - 1)); + + if (!speEnd.mCurrencyID) { // XXX Might restrict the number of times bridging through XRP. @@ -381,7 +383,10 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax // New end is an order book with the currency and issuer. if (!spPath.hasSeen(ACCOUNT_XRP, book->getCurrencyOut(), book->getIssuerOut()) && - !matchesOrigin(book->getCurrencyOut(), book->getIssuerOut())) + !matchesOrigin(book->getCurrencyOut(), book->getIssuerOut()) && + (!isLast || + (book->getCurrencyOut() == mDstAmount.getCurrency() && + book->getIssuerOut() == mDstAccountID))) { // Not a order book already in path. STPath spNew(spPath); @@ -453,6 +458,10 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax % RippleAddress::createHumanAccountID(uPeerID) % STAmount::createHumanCurrency(speEnd.mCurrencyID)); } + else if (isLast && (!dstCurrency || (uPeerID != mDstAccountID))) + { + nothing(); + } else if (!rspEntry->getBalance().isPositive() // No IOUs to send. && (!rspEntry->getLimitPeer() // Peer does not extend credit. || -rspEntry->getBalance() >= rspEntry->getLimitPeer() // No credit left. @@ -522,7 +531,10 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax BOOST_FOREACH(OrderBook::ref book, books) { if (!spPath.hasSeen(ACCOUNT_XRP, book->getCurrencyOut(), book->getIssuerOut()) && - !matchesOrigin(book->getCurrencyOut(), book->getIssuerOut())) + !matchesOrigin(book->getCurrencyOut(), book->getIssuerOut()) && + (!isLast || + (book->getCurrencyOut() == mDstAmount.getCurrency() && + book->getIssuerOut() == mDstAccountID))) { // A book we haven't seen before. Add it. STPath spNew(spPath);