Complete public key cache logic and tie to application object.

This commit is contained in:
JoelKatz
2011-12-04 19:32:16 -08:00
parent c52512e5e7
commit c891df0ef8
3 changed files with 14 additions and 9 deletions

View File

@@ -5,6 +5,7 @@
#include "ConnectionPool.h"
#include "KnownNodeList.h"
#include "TimingService.h"
#include "PubKeyCache.h"
#include "ScopedLock.h"
#include "Wallet.h"
#include "database/database.h"
@@ -21,6 +22,7 @@ class Application
UniqueNodeList mUNL;
KnownNodeList mKnownNodes;
Wallet mWallet;
PubKeyCache mPKCache;
Database* mDatabase;
@@ -36,13 +38,14 @@ class Application
public:
Application();
ConnectionPool& getConnectionPool(){ return(mConnectionPool); }
UniqueNodeList& getUNL(){ return(mUNL); }
Wallet& getWallet(){ return(mWallet); }
Database* getDB(){ return(mDatabase); }
ConnectionPool& getConnectionPool() { return(mConnectionPool); }
UniqueNodeList& getUNL() { return(mUNL); }
Wallet& getWallet() { return(mWallet); }
PubKeyCache& getPubKeyCache() { return mPKCache; }
Database* getDB() { return(mDatabase); }
ScopedLock getDBLock() { return ScopedLock(dbLock); }
void setDB(Database* db){ mDatabase=db; }
void setDB(Database* db) { mDatabase=db; }
//Serializer* getSerializer(){ return(mSerializer); }
//void setSerializer(Serializer* ser){ mSerializer=ser; }

View File

@@ -43,12 +43,13 @@ CKey::pointer PubKeyCache::locate(const uint160& id)
return ckp;
}
void PubKeyCache::store(const uint160& id, CKey::pointer key)
{
CKey::pointer PubKeyCache::store(const uint160& id, CKey::pointer key)
{ // stored if needed, returns cached copy (possibly the original)
if(1)
{
boost::mutex::scoped_lock sl(mLock);
if(mCache[id]) return;
CKey::pointer cached(mCache[id]);
if(cached) return cached;
mCache[id]=key;
}
std::string sql="INSERT INTO PubKeys (ID, PubKey) VALUES ('";
@@ -62,6 +63,7 @@ void PubKeyCache::store(const uint160& id, CKey::pointer key)
sql.append(";");
ScopedLock sl(theApp->getDBLock());
theApp->getDB()->executeSQL(sql.c_str());
return key;
}
void PubKeyCache::clear()

View File

@@ -18,7 +18,7 @@ public:
PubKeyCache() { ; }
CKey::pointer locate(const uint160& id);
void store(const uint160& id, CKey::pointer key);
CKey::pointer store(const uint160& id, CKey::pointer key);
void clear(void);
};