updates to libbitdht to make it work with retroshare.

* decreased nodes per bucket to 10 - to try reduce traffic.
 * changed operator< to non const.
 * fixed up debuging.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3322 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2010-07-31 18:01:24 +00:00
parent 1069ed0c58
commit c1b624832f
6 changed files with 24 additions and 9 deletions

View file

@ -54,7 +54,7 @@
* #define DEBUG_MGR_PKT 1 * #define DEBUG_MGR_PKT 1
***/ ***/
//#define DEBUG_MGR 1 #define DEBUG_MGR 1
bdNodeManager::bdNodeManager(bdNodeId *id, std::string dhtVersion, std::string bootfile, bdDhtFunctions *fns) bdNodeManager::bdNodeManager(bdNodeId *id, std::string dhtVersion, std::string bootfile, bdDhtFunctions *fns)
:bdNode(id, dhtVersion, bootfile, fns) :bdNode(id, dhtVersion, bootfile, fns)
@ -141,7 +141,7 @@ void bdNodeManager::iteration()
if (modeAge > MAX_STARTUP_TIME) if (modeAge > MAX_STARTUP_TIME)
{ {
#ifdef DEBUG_MGR #ifdef DEBUG_MGR
std::cerr << "bdNodeManager::iteration(): STARTUP "; std::cerr << "bdNodeManager::iteration(): STARTUP -> REFRESH";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
bdNodeId id; bdNodeId id;
@ -157,6 +157,10 @@ void bdNodeManager::iteration()
case BITDHT_MGR_STATE_ACTIVE: case BITDHT_MGR_STATE_ACTIVE:
if (modeAge > MAX_REFRESH_TIME) if (modeAge > MAX_REFRESH_TIME)
{ {
#ifdef DEBUG_MGR
std::cerr << "bdNodeManager::iteration(): ACTIVE -> REFRESH";
std::cerr << std::endl;
#endif
mMode = BITDHT_MGR_STATE_REFRESH; mMode = BITDHT_MGR_STATE_REFRESH;
mModeTS = now; mModeTS = now;
} }
@ -165,6 +169,10 @@ void bdNodeManager::iteration()
case BITDHT_MGR_STATE_REFRESH: case BITDHT_MGR_STATE_REFRESH:
{ {
#ifdef DEBUG_MGR
std::cerr << "bdNodeManager::iteration(): REFRESH -> ACTIVE";
std::cerr << std::endl;
#endif
/* select random ids, and perform searchs to refresh space */ /* select random ids, and perform searchs to refresh space */
mMode = BITDHT_MGR_STATE_ACTIVE; mMode = BITDHT_MGR_STATE_ACTIVE;
mModeTS = now; mModeTS = now;

View file

@ -215,8 +215,8 @@ void bdNode::iteration()
genNewTransId(&transId); genNewTransId(&transId);
registerOutgoingMsg(&id, &transId, BITDHT_MSG_TYPE_FIND_NODE); registerOutgoingMsg(&id, &transId, BITDHT_MSG_TYPE_FIND_NODE);
msgout_find_node(&id, &transId, &targetNodeId);
#ifdef DEBUG_NODE_MSGS #ifdef DEBUG_NODE_MSGS
msgout_find_node(&id, &transId, &targetNodeId);
std::cerr << "bdNode::iteration() Find Node Req for : "; std::cerr << "bdNode::iteration() Find Node Req for : ";
mFns->bdPrintId(std::cerr, &id); mFns->bdPrintId(std::cerr, &id);
std::cerr << " searching for : "; std::cerr << " searching for : ";
@ -371,7 +371,7 @@ void bdNode::addPeer(const bdId *id, uint32_t peerflags)
#ifdef DEBUG_NODE_ACTIONS #ifdef DEBUG_NODE_ACTIONS
fprintf(stderr, "bdNode::addPeer("); fprintf(stderr, "bdNode::addPeer(");
bdPrintId(std::cerr, id); mFns->bdPrintId(std::cerr, id);
fprintf(stderr, ")\n"); fprintf(stderr, ")\n");
#endif #endif
@ -484,8 +484,8 @@ void bdNode::processRemoteQuery()
std::cerr << "bdNode::processRemoteQuery() Reply to Find Node: "; std::cerr << "bdNode::processRemoteQuery() Reply to Find Node: ";
mFns->bdPrintId(std::cerr, &(query.mId)); mFns->bdPrintId(std::cerr, &(query.mId));
std::cerr << " searching for : "; std::cerr << " searching for : ";
bdPrintNodeId(std::cerr, &(query.mQuery)); mFns->bdPrintNodeId(std::cerr, &(query.mQuery));
mFns->std::cerr << ", found " << nearest.size() << " nodes "; std::cerr << ", found " << nearest.size() << " nodes ";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif

View file

@ -29,7 +29,7 @@
#include "bitdht/bdiface.h" #include "bitdht/bdiface.h"
#define BITDHT_STANDARD_BUCKET_SIZE 20 #define BITDHT_STANDARD_BUCKET_SIZE 10 // 20 - too many per query.
#define BITDHT_STANDARD_BUCKET_SIZE_BITS 5 #define BITDHT_STANDARD_BUCKET_SIZE_BITS 5
#define BITDHT_STANDARD_N_BUCKETS BITDHT_KEY_BITLEN #define BITDHT_STANDARD_N_BUCKETS BITDHT_KEY_BITLEN

View file

@ -42,6 +42,7 @@
/* /*
* #define DEBUG_UDP_BITDHT 1 * #define DEBUG_UDP_BITDHT 1
*/ */
//#define DEBUG_UDP_BITDHT 1 //#define DEBUG_UDP_BITDHT 1
/*************************************/ /*************************************/

View file

@ -37,6 +37,8 @@
* #define DEBUG_UDP_LAYER 1 * #define DEBUG_UDP_LAYER 1
***/ ***/
//#define DEBUG_UDP_LAYER 1
static const int UDP_DEF_TTL = 64; static const int UDP_DEF_TTL = 64;
/* NB: This #define makes the listener open 0.0.0.0:X port instead /* NB: This #define makes the listener open 0.0.0.0:X port instead
@ -77,7 +79,8 @@ class udpPacket
int len; int len;
}; };
std::ostream &operator<<(std::ostream &out, const struct sockaddr_in &addr) //std::ostream &operator<<(std::ostream &out, const struct sockaddr_in &addr)
std::ostream &operator<<(std::ostream &out, struct sockaddr_in &addr)
{ {
out << "[" << inet_ntoa(addr.sin_addr) << ":"; out << "[" << inet_ntoa(addr.sin_addr) << ":";
out << htons(addr.sin_port) << "]"; out << htons(addr.sin_port) << "]";

View file

@ -33,7 +33,10 @@
#include <list> #include <list>
#include <deque> #include <deque>
std::ostream &operator<<(std::ostream &out, const struct sockaddr_in &addr); /* careful - duplicate definitions */
//std::ostream &operator<<(std::ostream &out, const struct sockaddr_in &addr);
std::ostream &operator<<(std::ostream &out, struct sockaddr_in &addr);
bool operator==(const struct sockaddr_in &addr, const struct sockaddr_in &addr2); bool operator==(const struct sockaddr_in &addr, const struct sockaddr_in &addr2);
bool operator<(const struct sockaddr_in &addr, const struct sockaddr_in &addr2); bool operator<(const struct sockaddr_in &addr, const struct sockaddr_in &addr2);