Fixed the Missing Cache File bug.

* Added Old Cache Storage... so these can be retrieved.
 * Connected up the CancelCacheFile() -> FileCancel.

Other Changes.
 * Removed ipaddr = 1 bug (thought someone else had commited this earlier???)
 * added #ifdefs to remove debugging output in p3BitDht.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4330 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2011-06-24 15:10:52 +00:00
parent ee278b45b7
commit a333b12618
5 changed files with 97 additions and 13 deletions

View File

@ -99,14 +99,21 @@ bool CacheSource::refreshCache(const CacheData &data)
bool ret = false;
if (data.cid.type == getCacheType())
{
int subid = 0;
if (isMultiCache())
{
caches[data.cid.subid] = data;
subid = data.cid.subid;
}
else
/* Backup the old Caches */
CacheSet::const_iterator it;
if (caches.end() != (it = caches.find(subid)))
{
caches[0] = data;
mOldCaches[it->second.hash] = it->second;
}
/* store new cache */
caches[subid] = data;
ret = true;
}
@ -127,6 +134,8 @@ bool CacheSource::clearCache(CacheId id)
CacheSet::iterator it;
if (caches.end() != (it = caches.find(id.subid)))
{
/* Backup the old Caches */
mOldCaches[it->second.hash] = it->second;
caches.erase(it);
ret = true;
}
@ -170,6 +179,17 @@ bool CacheSource::findCache(std::string hash, CacheData &data) const
}
}
if (!found)
{
std::map<std::string, CacheData>::const_iterator oit;
oit = mOldCaches.find(hash);
if (oit != mOldCaches.end())
{
data = oit->second;
found = true;
}
}
unlockData(); /* UNLOCK MUTEX */
return found;
@ -384,6 +404,7 @@ void CacheStore::availableCache(const CacheData &data)
}
/* called when the download is completed ... updates internal data */
void CacheStore::downloadedCache(const CacheData &data)
{
@ -404,6 +425,7 @@ void CacheStore::failedCache(const CacheData &data)
#ifdef CS_DEBUG
std::cerr << "CacheStore::failedCache() :" << data << std::endl;
#endif
return;
}

View File

@ -206,7 +206,8 @@ class CacheSource
void lockData() const;
void unlockData() const;
CacheSet caches; /// all cache data local and remote stored here
CacheSet caches; /// all local cache data stored here
std::map<std::string, CacheData> mOldCaches; /// replaced/cleared caches are pushed here (in case requested)
private:

View File

@ -71,6 +71,7 @@ p3BitDht::p3BitDht(std::string id, pqiConnectCb *cb, UdpStack *udpstack, std::st
std::string dhtVersion = "RS51"; // should come from elsewhere!
bdNodeId ownId;
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::p3BitDht()" << std::endl;
std::cerr << "Using Id: " << id;
std::cerr << std::endl;
@ -78,21 +79,26 @@ p3BitDht::p3BitDht(std::string id, pqiConnectCb *cb, UdpStack *udpstack, std::st
std::cerr << std::endl;
std::cerr << "Converting OwnId to bdNodeId....";
std::cerr << std::endl;
#endif
/* setup ownId */
storeTranslation(id);
lookupNodeId(id, &ownId);
#ifdef DEBUG_BITDHT
std::cerr << "Own NodeId: ";
bdStdPrintNodeId(std::cerr, &ownId);
std::cerr << std::endl;
#endif
/* standard dht behaviour */
bdDhtFunctions *stdfns = new bdStdDht();
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht() startup ... creating UdpBitDht";
std::cerr << std::endl;
#endif
/* create dht */
mUdpBitDht = new UdpBitDht(udpstack, &ownId, dhtVersion, bootstrapfile, stdfns);
@ -112,8 +118,10 @@ p3BitDht::~p3BitDht()
void p3BitDht::start()
{
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::start()";
std::cerr << std::endl;
#endif
mUdpBitDht->start(); /* starts up the bitdht thread */
@ -123,8 +131,10 @@ void p3BitDht::start()
/* pqiNetAssist - external interface functions */
void p3BitDht::enable(bool on)
{
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::enable(" << on << ")";
std::cerr << std::endl;
#endif
if (on)
{
@ -169,8 +179,10 @@ bool p3BitDht::getNetworkStats(uint32_t &netsize, uint32_t &localnetsize)
/* add / remove peers */
bool p3BitDht::findPeer(std::string pid)
{
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::findPeer(" << pid << ")";
std::cerr << std::endl;
#endif
/* convert id -> NodeId */
if (!storeTranslation(pid))
@ -192,9 +204,11 @@ bool p3BitDht::findPeer(std::string pid)
return false;
}
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::findPeer() calling AddFindNode() with pid => NodeId: ";
bdStdPrintNodeId(std::cerr, &nid);
std::cerr << std::endl;
#endif
/* add in peer */
mUdpBitDht->addFindNode(&nid, BITDHT_QFLAGS_DO_IDLE);
@ -204,8 +218,10 @@ bool p3BitDht::findPeer(std::string pid)
bool p3BitDht::dropPeer(std::string pid)
{
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::dropPeer(" << pid << ")";
std::cerr << std::endl;
#endif
/* convert id -> NodeId */
bdNodeId nid;
@ -218,9 +234,11 @@ bool p3BitDht::dropPeer(std::string pid)
return false;
}
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::dropPeer() Translated to NodeId: ";
bdStdPrintNodeId(std::cerr, &nid);
std::cerr << std::endl;
#endif
/* remove in peer */
mUdpBitDht->removeFindNode(&nid);
@ -243,8 +261,10 @@ bool p3BitDht::getPeerStatus(std::string id,
struct sockaddr_in &laddr, struct sockaddr_in &raddr,
uint32_t &type, uint32_t &mode)
{
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::getPeerStatus(" << id << ")";
std::cerr << std::endl;
#endif
return false;
@ -254,8 +274,10 @@ bool p3BitDht::getExternalInterface(struct sockaddr_in &raddr,
uint32_t &mode)
{
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::getExternalInterface()";
std::cerr << std::endl;
#endif
return false;
@ -273,7 +295,9 @@ const uint8_t rs_dht_version_data[RS_DHT_VERSION_LEN] = "RS_VERSION_0.5.1";
int p3BitDht::calculateNodeId(const std::string pid, bdNodeId *id)
{
/* generate node id from pid */
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::calculateNodeId() " << pid;
#endif
/* use a hash to make it impossible to reverse */
@ -292,17 +316,21 @@ int p3BitDht::calculateNodeId(const std::string pid, bdNodeId *id)
}
delete sha_ctx;
#ifdef DEBUG_BITDHT
std::cerr << " => ";
bdStdPrintNodeId(std::cerr, id);
std::cerr << std::endl;
#endif
return 1;
}
int p3BitDht::lookupNodeId(const std::string pid, bdNodeId *id)
{
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::lookupNodeId() for : " << pid;
std::cerr << std::endl;
#endif
RsStackMutex stack(dhtMtx);
@ -310,17 +338,21 @@ int p3BitDht::lookupNodeId(const std::string pid, bdNodeId *id)
it = mTransToNodeId.find(pid);
if (it == mTransToNodeId.end())
{
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::lookupNodeId() failed";
std::cerr << std::endl;
#endif
return 0;
}
*id = it->second;
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::lookupNodeId() Found NodeId: ";
bdStdPrintNodeId(std::cerr, id);
std::cerr << std::endl;
#endif
return 1;
}
@ -350,31 +382,39 @@ int p3BitDht::lookupRsId(const bdNodeId *id, std::string &pid)
pid = nit->second;
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::lookupRsId() Found Matching RsId: " << pid;
std::cerr << std::endl;
#endif
return 1;
}
int p3BitDht::storeTranslation(const std::string pid)
{
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::storeTranslation(" << pid << ")";
std::cerr << std::endl;
#endif
bdNodeId nid;
calculateNodeId(pid, &nid);
RsStackMutex stack(dhtMtx);
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::storeTranslation() Converts to NodeId: ";
bdStdPrintNodeId(std::cerr, &(nid));
std::cerr << std::endl;
#endif
mTransToNodeId[pid] = nid;
mTransToRsId[nid] = pid;
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::storeTranslation() Success";
std::cerr << std::endl;
#endif
return 1;
}
@ -383,8 +423,10 @@ int p3BitDht::removeTranslation(const std::string pid)
{
RsStackMutex stack(dhtMtx);
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::removeTranslation(" << pid << ")";
std::cerr << std::endl;
#endif
std::map<std::string, bdNodeId>::iterator it = mTransToNodeId.find(pid);
it = mTransToNodeId.find(pid);
@ -398,9 +440,11 @@ int p3BitDht::removeTranslation(const std::string pid)
bdNodeId nid = it->second;
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::removeTranslation() Found Translation: NodeId: ";
bdStdPrintNodeId(std::cerr, &(nid));
std::cerr << std::endl;
#endif
std::map<bdNodeId, std::string>::iterator nit;
@ -416,8 +460,10 @@ int p3BitDht::removeTranslation(const std::string pid)
mTransToNodeId.erase(it);
mTransToRsId.erase(nit);
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::removeTranslation() SUCCESS";
std::cerr << std::endl;
#endif
return 1;
}
@ -462,11 +508,13 @@ int p3BitDht::NodeCallback(const bdId *id, uint32_t peerflags)
/* check for translation */
if (lookupRsId(&(id->id), pid))
{
#ifdef DEBUG_BITDHT
/* we found it ... do callback to p3connmgr */
std::cerr << "p3BitDht::NodeCallback() FOUND NODE!!!: ";
bdStdPrintNodeId(std::cerr, &(id->id));
std::cerr << "-> " << pid << " flags: " << peerflags;
std::cerr << std::endl;
#endif
/* send status info to p3connmgr */
@ -526,43 +574,53 @@ uint32_t translatebdcbflgs(uint32_t peerflags)
int p3BitDht::PeerCallback(const bdId *id, uint32_t status)
{
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::PeerCallback() bdId: ";
bdStdPrintId(std::cerr, id);
std::cerr << std::endl;
#endif
/* is it one that we are interested in? */
std::string pid;
/* check for translation */
if (lookupRsId(&(id->id), pid))
{
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::PeerCallback() => RsId: ";
std::cerr << pid << " status: " << status;
std::cerr << " NOOP for NOW";
std::cerr << std::endl;
#endif
bool connect = false;
switch(status)
{
case BITDHT_MGR_QUERY_FAILURE:
/* do nothing */
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::PeerCallback() QUERY FAILURE ... do nothin ";
std::cerr << std::endl;
#endif
break;
case BITDHT_MGR_QUERY_PEER_OFFLINE:
/* do nothing */
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::PeerCallback() QUERY PEER OFFLINE ... do nothin ";
std::cerr << std::endl;
#endif
break;
case BITDHT_MGR_QUERY_PEER_UNREACHABLE:
/* do nothing */
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::PeerCallback() QUERY PEER UNREACHABLE ... flag? / do nothin ";
std::cerr << std::endl;
#endif
break;
@ -570,8 +628,10 @@ int p3BitDht::PeerCallback(const bdId *id, uint32_t status)
case BITDHT_MGR_QUERY_PEER_ONLINE:
/* do something */
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::PeerCallback() QUERY PEER ONLINE ... try udp connection";
std::cerr << std::endl;
#endif
connect = true;
break;
@ -579,8 +639,10 @@ int p3BitDht::PeerCallback(const bdId *id, uint32_t status)
if (connect)
{
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::PeerCallback() mConnCb->peerConnectRequest()";
std::cerr << std::endl;
#endif
mConnCb->peerConnectRequest(pid, id->addr, RS_CB_DHT);
return 1;
@ -592,11 +654,13 @@ int p3BitDht::PeerCallback(const bdId *id, uint32_t status)
}
else
{
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::PeerCallback()";
std::cerr << " FAILED TO TRANSLATE ID ";
std::cerr << " status: " << status;
std::cerr << " NOOP for NOW";
std::cerr << std::endl;
#endif
}
return 0;
@ -604,8 +668,10 @@ int p3BitDht::PeerCallback(const bdId *id, uint32_t status)
int p3BitDht::ValueCallback(const bdNodeId *id, std::string key, uint32_t status)
{
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::ValueCallback() NOOP for NOW";
std::cerr << std::endl;
#endif
/* ignore for now */
return 0;

View File

@ -1831,13 +1831,14 @@ bool ftController::RequestCacheFile(RsPeerId id, std::string path, std::string h
bool ftController::CancelCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size)
{
#ifdef CONTROL_DEBUG
std::cerr << "ftController::CancelCacheFile(" << id << ",";
std::cerr << path << "," << hash << "," << size << ")";
std::cerr << std::endl;
#ifdef CONTROL_DEBUG
#endif
return true;
return FileCancel(hash);
}
const std::string active_downloads_size_ss("MAX_ACTIVE_DOWNLOADS");

View File

@ -600,13 +600,7 @@ bool SetTlvIpAddrPortV4(void *data, uint32_t size, uint32_t *offset,
ok &= SetTlvBase(data, tlvend, offset, type, tlvsize);
sockaddr_in addr = *out;
//it looks like if ip or port is null that there is a problem
if (addr.sin_addr.s_addr == 0) {
addr.sin_addr.s_addr = 1;
}
if (addr.sin_port == 0) {
addr.sin_port = 1;
}
/* now add the data .... (its already in network order) - so flip */
uint32_t ipaddr = addr.sin_addr.s_addr;
ok &= setRawUInt32(data, tlvend, offset, ntohl(ipaddr));