* BUGFIX: Multiple DHT searches / reconnect attempts (p3dhtmgr) done!

* Tweaks to the File Interface.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@636 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2008-07-06 15:05:59 +00:00
parent 1f01c08de4
commit 9629c6923c
5 changed files with 81 additions and 18 deletions

View File

@ -212,6 +212,16 @@ bool p3DhtMgr::findPeer(std::string id)
it = peers.find(id);
if (it != peers.end())
{
/* reset some of it */
it->second.state = DHT_PEER_INIT;
// No point destroying a valid address!.
//it->second.type = DHT_ADDR_INVALID;
// Reset notify
it->second.notifyPending = 0;
it->second.notifyTS = 0;
return true;
}
@ -250,8 +260,8 @@ bool p3DhtMgr::dropPeer(std::string id)
return false;
}
/* remove */
peers.erase(it);
/* leave it in there - just switch to off */
it->second.state = DHT_PEER_OFF;
return true;
}
@ -270,6 +280,12 @@ bool p3DhtMgr::notifyPeer(std::string id)
{
return false;
}
/* ignore OFF peers */
if (it->second.state == DHT_PEER_OFF)
{
return false;
}
time_t now = time(NULL);
@ -305,23 +321,23 @@ bool p3DhtMgr::getPeerStatus(std::string id,
struct sockaddr_in &raddr,
uint32_t &type, uint32_t &state)
{
dhtMtx.lock(); /* LOCK MUTEX */
RsStackMutex stack(dhtMtx); /* LOCK MUTEX */
std::map<std::string, dhtPeerEntry>::iterator it;
it = peers.find(id);
bool found = it != peers.end();
if (found)
/* ignore OFF peers */
if ((it == peers.end()) || (it->second.state == DHT_PEER_OFF))
{
return false;
}
laddr = it->second.laddr;
raddr = it->second.raddr;
type = it->second.type;
state = it->second.type;
}
dhtMtx.unlock(); /* UNLOCK MUTEX */
return found;
return true;
}
/********************************* STUN HANDLING **********************************
@ -697,6 +713,12 @@ int p3DhtMgr::checkPeerDHTKeys()
for(it = peers.begin(); it != peers.end(); it++)
{
/* ignore OFF peers */
if (it->second.state == DHT_PEER_OFF)
{
continue;
}
time_t delta = now - it->second.lastTS;
if (it->second.state < DHT_PEER_FOUND)
{
@ -777,6 +799,12 @@ int p3DhtMgr::checkNotifyDHT()
/* find the first with a notify flag */
for(it = peers.begin(); it != peers.end(); it++)
{
/* ignore OFF peers */
if (it->second.state == DHT_PEER_OFF)
{
continue;
}
if (it->second.notifyPending)
{
if (it->second.state == DHT_PEER_FOUND)
@ -1523,7 +1551,8 @@ bool p3DhtMgr::dhtResultNotify(std::string idhash)
/* update data */
std::string peerid;
if (it != peers.end())
/* ignore OFF peers */
if ((it != peers.end()) && (it->second.state != DHT_PEER_OFF))
{
#ifdef DHT_DEBUG
std::cerr << "p3DhtMgr::dhtResult() NOTIFY for id: " << it->first << std::endl;
@ -1573,7 +1602,8 @@ bool p3DhtMgr::dhtResultSearch(std::string idhash,
for(it = peers.begin(); (it != peers.end()) && ((it->second).hash1 != idhash); it++);
/* update data */
if (it != peers.end())
/* ignore OFF peers */
if ((it != peers.end()) && (it->second.state != DHT_PEER_OFF))
{
#ifdef DHT_DEBUG
std::cerr << "p3DhtMgr::dhtResult() SEARCH for id: " << it->first << std::endl;

View File

@ -43,13 +43,14 @@
/* for DHT peer STATE */
#define DHT_PEER_INIT 0
#define DHT_PEER_SEARCH 1
#define DHT_PEER_FOUND 2
#define DHT_PEER_OFF 0
#define DHT_PEER_INIT 1
#define DHT_PEER_SEARCH 2
#define DHT_PEER_FOUND 3
/* for DHT peer STATE (ownEntry) */
#define DHT_PEER_ADDR_KNOWN 3
#define DHT_PEER_PUBLISHED 4
#define DHT_PEER_ADDR_KNOWN 4
#define DHT_PEER_PUBLISHED 5
/* Interface with Real DHT Implementation */
#define DHT_MODE_SEARCH 1

View File

@ -49,6 +49,23 @@ const uint32_t RS_FILE_CTRL_STREAM_AUDIO = 0x0005;
const uint32_t RS_FILE_CTRL_STREAM_VIDEO = 0x0006;
/************************************
* Used To indicate where to search.
*/
const uint32_t RS_FILE_HINTS_MASK = 0x00ff;
const uint32_t RS_FILE_HINTS_CACHE = 0x0001;
const uint32_t RS_FILE_HINTS_EXTRA = 0x0002;
const uint32_t RS_FILE_HINTS_LOCAL = 0x0004;
const uint32_t RS_FILE_HINTS_REMOTE = 0x0008;
const uint32_t RS_FILE_HINTS_DOWNLOAD = 0x0010;
const uint32_t RS_FILE_HINTS_UPLOAD = 0x0020;
const uint32_t RS_FILE_HINTS_SPEC_ONLY = 0x1000;
const uint32_t RS_FILE_EXTRA_DELETE = 0x0010;

View File

@ -83,6 +83,20 @@ static const int kRsFiStatusDone = 2;
double tfRate; /* kbytes */
bool download;
int downloadStatus; /* 0 = Err, 1 = Ok, 2 = Done */
/* ENTRIES USED BY SFI ***
*
* path,
* fname,
* hash,
* size,
* avail,
*
* source?
*
*/
};
class FileTransferInfo: public FileInfo

View File

@ -68,6 +68,7 @@ int p3Files::UpdateAllTransfers()
ti.size = (*it) -> file.filesize;
ti.transfered = (*it) -> transferred;
ti.avail = ti.transfered;
/* other ones!!! */
ti.tfRate = (*it) -> crate / 1000;
ti.download = (*it) -> in;