Don't explore paths if we don't have enough path length left to use them.

This commit is contained in:
JoelKatz
2013-04-12 16:03:57 -07:00
parent 183a6dbd2c
commit 2e39dfc15a

View File

@@ -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);