diff --git a/libretroshare/src/pqi/p3dhtmgr.cc b/libretroshare/src/pqi/p3dhtmgr.cc index 78b34db95..710b498b2 100644 --- a/libretroshare/src/pqi/p3dhtmgr.cc +++ b/libretroshare/src/pqi/p3dhtmgr.cc @@ -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::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)) { - laddr = it->second.laddr; - raddr = it->second.raddr; - type = it->second.type; - state = it->second.type; + return false; } - dhtMtx.unlock(); /* UNLOCK MUTEX */ + laddr = it->second.laddr; + raddr = it->second.raddr; + type = it->second.type; + state = it->second.type; - 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; diff --git a/libretroshare/src/pqi/p3dhtmgr.h b/libretroshare/src/pqi/p3dhtmgr.h index a9ee2ef1e..ca8d28544 100644 --- a/libretroshare/src/pqi/p3dhtmgr.h +++ b/libretroshare/src/pqi/p3dhtmgr.h @@ -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 diff --git a/libretroshare/src/rsiface/rsfiles.h b/libretroshare/src/rsiface/rsfiles.h index 0a7d0b640..936f2e4de 100644 --- a/libretroshare/src/rsiface/rsfiles.h +++ b/libretroshare/src/rsiface/rsfiles.h @@ -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; diff --git a/libretroshare/src/rsiface/rstypes.h b/libretroshare/src/rsiface/rstypes.h index 5e3d3aa95..c350e4441 100644 --- a/libretroshare/src/rsiface/rstypes.h +++ b/libretroshare/src/rsiface/rstypes.h @@ -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 diff --git a/libretroshare/src/rsserver/p3files.cc b/libretroshare/src/rsserver/p3files.cc index 9a3b901c3..ee14584a7 100644 --- a/libretroshare/src/rsserver/p3files.cc +++ b/libretroshare/src/rsserver/p3files.cc @@ -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;