mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
Work on path finding.
This commit is contained in:
@@ -76,21 +76,57 @@ PathOption::PathOption(PathOption::pointer other)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Return true, if path is a default path with an element.
|
// Return true, if path is a default path with an element.
|
||||||
|
// A path is a default path if it is implied via src, dst, send, and sendmax.
|
||||||
// XXX Could be determined via STAmount
|
// XXX Could be determined via STAmount
|
||||||
bool Pathfinder::bDefaultPath(const STPath& spPath)
|
bool Pathfinder::bDefaultPath(const STPath& spPath)
|
||||||
{
|
{
|
||||||
|
if (2 == spPath.mPath.size()) {
|
||||||
|
// Empty path is a default. Don't need to add it to return set.
|
||||||
|
cLog(lsDEBUG) << "findPaths: empty path: direct";
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
PathState::pointer pspCurrent = boost::make_shared<PathState>(mDstAmount, mSrcAmount, mLedger);
|
||||||
|
|
||||||
|
if (pspCurrent)
|
||||||
|
{
|
||||||
|
bool bDefault;
|
||||||
|
LedgerEntrySet lesActive(mLedger);
|
||||||
|
|
||||||
|
pspCurrent->setExpanded(lesActive, spPath, mDstAccountID, mSrcAccountID);
|
||||||
|
|
||||||
|
bDefault = pspCurrent->vpnNodes == mPsDefault->vpnNodes;
|
||||||
|
|
||||||
|
// Path is a default (implied). Don't need to add it to return set.
|
||||||
|
cLog(lsDEBUG) << "findPaths: default path: indirect: " << spPath.getJson(0);
|
||||||
|
|
||||||
|
return bDefault;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
// return spPath.size() == 3 && spPath.mPath[1].mType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// XXX Optionally, specifying a source and destination issuer might be nice. Especially, to convert between issuers. However, this
|
// XXX Optionally, specifying a source and destination issuer might be nice. Especially, to convert between issuers. However, this
|
||||||
// functionality is left to the future.
|
// functionality is left to the future.
|
||||||
//
|
//
|
||||||
Pathfinder::Pathfinder(const RippleAddress& srcAccountID, const RippleAddress& dstAccountID, const uint160& srcCurrencyID, const uint160& srcIssuerID, const STAmount& dstAmount)
|
Pathfinder::Pathfinder(const RippleAddress& uSrcAccountID, const RippleAddress& uDstAccountID, const uint160& uSrcCurrencyID, const uint160& uSrcIssuerID, const STAmount& saDstAmount)
|
||||||
: mSrcAccountID(srcAccountID.getAccountID()), mDstAccountID(dstAccountID.getAccountID()), mDstAmount(dstAmount), mSrcCurrencyID(srcCurrencyID), mSrcIssuerID(srcIssuerID), mOrderBook(theApp->getLedgerMaster().getCurrentLedger())
|
: mSrcAccountID(uSrcAccountID.getAccountID()), mDstAccountID(uDstAccountID.getAccountID()), mDstAmount(saDstAmount), mSrcCurrencyID(uSrcCurrencyID), mSrcIssuerID(uSrcIssuerID), mOrderBook(theApp->getLedgerMaster().getCurrentLedger())
|
||||||
{
|
{
|
||||||
mLedger=theApp->getLedgerMaster().getCurrentLedger();
|
mLedger = theApp->getLedgerMaster().getCurrentLedger();
|
||||||
|
mSrcAmount = STAmount(uSrcCurrencyID, uSrcIssuerID, 1, 0, true); // -1/uSrcIssuerID/uSrcIssuerID
|
||||||
|
|
||||||
|
// Construct the default path for later comparison.
|
||||||
|
|
||||||
|
mPsDefault = boost::make_shared<PathState>(mDstAmount, mSrcAmount, mLedger);
|
||||||
|
|
||||||
|
if (mPsDefault)
|
||||||
|
{
|
||||||
|
LedgerEntrySet lesActive(mLedger);
|
||||||
|
|
||||||
|
mPsDefault->setExpanded(lesActive, STPath(), mDstAccountID, mSrcAccountID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If possible, returns a single path.
|
// If possible, returns a single path.
|
||||||
@@ -114,7 +150,14 @@ bool Pathfinder::findPaths(int maxSearchSteps, int maxPay, STPathSet& retPathSet
|
|||||||
% RippleAddress::createHumanAccountID(mSrcIssuerID)
|
% RippleAddress::createHumanAccountID(mSrcIssuerID)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (mLedger) {
|
if (!mPsDefault)
|
||||||
|
{
|
||||||
|
cLog(lsDEBUG) << boost::str(boost::format("findPaths: failed to generate default path."));
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (mLedger)
|
||||||
|
{
|
||||||
std::queue<STPath> pqueue;
|
std::queue<STPath> pqueue;
|
||||||
STPathElement ele(mSrcAccountID,
|
STPathElement ele(mSrcAccountID,
|
||||||
mSrcCurrencyID,
|
mSrcCurrencyID,
|
||||||
@@ -160,16 +203,8 @@ bool Pathfinder::findPaths(int maxSearchSteps, int maxPay, STPathSet& retPathSet
|
|||||||
if (ele.mAccountID == mDstAccountID // Tail is destination account.
|
if (ele.mAccountID == mDstAccountID // Tail is destination account.
|
||||||
&& ele.mCurrencyID == mDstAmount.getCurrency()) { // With correct output currency.
|
&& ele.mCurrencyID == mDstAmount.getCurrency()) { // With correct output currency.
|
||||||
// Found a path to the destination.
|
// Found a path to the destination.
|
||||||
|
if (bDefaultPath(path)) {
|
||||||
if (2 == path.mPath.size()) {
|
cLog(lsDEBUG) << "findPaths: default path: dropping: " << path.getJson(0);
|
||||||
// Empty path is a default. Don't need to add it to return set.
|
|
||||||
cLog(lsDEBUG) << "findPaths: empty path: direct";
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (bDefaultPath(path)) {
|
|
||||||
// Path is a default (implied). Don't need to add it to return set.
|
|
||||||
cLog(lsDEBUG) << "findPaths: default path: indirect: " << path.getJson(0);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -246,6 +281,15 @@ bool Pathfinder::findPaths(int maxSearchSteps, int maxPay, STPathSet& retPathSet
|
|||||||
|
|
||||||
bContinued = true;
|
bContinued = true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cLog(lsDEBUG) <<
|
||||||
|
boost::str(boost::format("findPaths: SEEN: %s/%s --> %s/%s")
|
||||||
|
% RippleAddress::createHumanAccountID(ele.mAccountID)
|
||||||
|
% STAmount::createHumanCurrency(ele.mCurrencyID)
|
||||||
|
% RippleAddress::createHumanAccountID(line->getAccountIDPeer().getAccountID())
|
||||||
|
% STAmount::createHumanCurrency(ele.mCurrencyID));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Every book that wants the source currency.
|
// Every book that wants the source currency.
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
|
#ifndef __PATHFINDER__
|
||||||
|
#define __PATHFINDER__
|
||||||
|
|
||||||
#include "SerializedTypes.h"
|
#include "SerializedTypes.h"
|
||||||
#include "RippleAddress.h"
|
#include "RippleAddress.h"
|
||||||
#include "OrderBookDB.h"
|
#include "OrderBookDB.h"
|
||||||
|
#include "RippleCalc.h"
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@@ -30,14 +34,16 @@ public:
|
|||||||
|
|
||||||
class Pathfinder
|
class Pathfinder
|
||||||
{
|
{
|
||||||
uint160 mSrcAccountID;
|
uint160 mSrcAccountID;
|
||||||
uint160 mDstAccountID;
|
uint160 mDstAccountID;
|
||||||
STAmount mDstAmount;
|
STAmount mDstAmount;
|
||||||
uint160 mSrcCurrencyID;
|
uint160 mSrcCurrencyID;
|
||||||
uint160 mSrcIssuerID;
|
uint160 mSrcIssuerID;
|
||||||
|
STAmount mSrcAmount;
|
||||||
|
|
||||||
OrderBookDB mOrderBook;
|
OrderBookDB mOrderBook;
|
||||||
Ledger::pointer mLedger;
|
Ledger::pointer mLedger;
|
||||||
|
PathState::pointer mPsDefault;
|
||||||
|
|
||||||
// std::list<PathOption::pointer> mBuildingPaths;
|
// std::list<PathOption::pointer> mBuildingPaths;
|
||||||
// std::list<PathOption::pointer> mCompletePaths;
|
// std::list<PathOption::pointer> mCompletePaths;
|
||||||
@@ -56,4 +62,6 @@ public:
|
|||||||
|
|
||||||
bool bDefaultPath(const STPath& spPath);
|
bool bDefaultPath(const STPath& spPath);
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
// vim:ts=4
|
// vim:ts=4
|
||||||
|
|||||||
Reference in New Issue
Block a user