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 d69bccc797
commit 1ca88a8a14

View File

@@ -369,7 +369,9 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax
continue; 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. // XXX Might restrict the number of times bridging through XRP.
@@ -379,7 +381,10 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax
// New end is an order book with the currency and issuer. // New end is an order book with the currency and issuer.
if (!spPath.hasSeen(ACCOUNT_XRP, book->getCurrencyOut(), book->getIssuerOut()) && 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. // Not a order book already in path.
STPath spNew(spPath); STPath spNew(spPath);
@@ -451,6 +456,10 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax
% RippleAddress::createHumanAccountID(uPeerID) % RippleAddress::createHumanAccountID(uPeerID)
% STAmount::createHumanCurrency(speEnd.mCurrencyID)); % STAmount::createHumanCurrency(speEnd.mCurrencyID));
} }
else if (isLast && (!dstCurrency || (uPeerID != mDstAccountID)))
{
nothing();
}
else if (!rspEntry->getBalance().isPositive() // No IOUs to send. else if (!rspEntry->getBalance().isPositive() // No IOUs to send.
&& (!rspEntry->getLimitPeer() // Peer does not extend credit. && (!rspEntry->getLimitPeer() // Peer does not extend credit.
|| -rspEntry->getBalance() >= rspEntry->getLimitPeer() // No credit left. || -rspEntry->getBalance() >= rspEntry->getLimitPeer() // No credit left.
@@ -521,7 +530,10 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax
BOOST_FOREACH(OrderBook::ref book, books) BOOST_FOREACH(OrderBook::ref book, books)
{ {
if (!spPath.hasSeen(ACCOUNT_XRP, book->getCurrencyOut(), book->getIssuerOut()) && 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. // A book we haven't seen before. Add it.
STPath spNew(spPath); STPath spNew(spPath);