* Added new interface functions for start / stop DHT and to get stats.

* Implemented start/stop interface in udpbitdht and bemanager
 * added Restart of DHT if it fails to get going.
 * added start / stop functionality to bdnode and bdstore
 * added cleanup code to rest of bitdht classes.
 * reworked NetworkSize calc functions.
 * added thread debugging (prints at start / stop / join).
 * TESTS: added utest.h header file for automated unit testing (from libretroshare)
 * TESTS: bdmetric_test started conversion to automated tests
 * TESTS: udpbitdht_nettest. Added dht start / stop and network reset (thread join) functionality.
 * TESTS: fresh bdboot.txt



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3678 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2010-10-17 20:55:32 +00:00
parent 884f0e7a22
commit 74961774cc
18 changed files with 1193 additions and 601 deletions

View File

@ -277,3 +277,11 @@ int bdHashSpace::cleanHashSpace(bdNodeId *min, bdNodeId *max, time_t maxAge)
return 1;
}
int bdHashSpace::clear()
{
mHashTable.clear();
return 1;
}

View File

@ -76,6 +76,7 @@ int modify(bdNodeId *id, std::string key, bdHashEntry *entry, uint32_t modFlags
int printHashSpace(std::ostream&);
int cleanHashSpace(bdNodeId *min, bdNodeId *max, time_t maxAge);
int clear();
private:

View File

@ -176,6 +176,12 @@ virtual void removeCallback(BitDhtCallback *cb) = 0;
virtual int getDhtPeerAddress(const bdNodeId *id, struct sockaddr_in &from) = 0;
virtual int getDhtValue(const bdNodeId *id, std::string key, std::string &value) = 0;
/* stats and Dht state */
virtual int startDht() = 0;
virtual int stopDht() = 0;
virtual int stateDht() = 0; /* STOPPED, STARTING, ACTIVE, FAILED */
virtual uint32_t statsNetworkSize() = 0;
virtual uint32_t statsBDVersionSize() = 0; /* same version as us! */
};
#endif

View File

@ -54,13 +54,17 @@
* #define DEBUG_MGR_PKT 1
***/
bdNodeManager::bdNodeManager(bdNodeId *id, std::string dhtVersion, std::string bootfile, bdDhtFunctions *fns)
:bdNode(id, dhtVersion, bootfile, fns)
{
mMode = BITDHT_MGR_STATE_STARTUP;
mMode = BITDHT_MGR_STATE_OFF;
mFns = fns;
mModeTS = 0 ;
mNetworkSize = 0;
mBdNetworkSize = 0;
/* setup a query for self */
#ifdef DEBUG_MGR
std::cerr << "bdNodeManager::bdNodeManager() ID: ";
@ -69,6 +73,57 @@ bdNodeManager::bdNodeManager(bdNodeId *id, std::string dhtVersion, std::string b
#endif
}
int bdNodeManager::stopDht()
{
time_t now = time(NULL);
/* clean up node */
shutdownNode();
/* flag queries as inactive */
/* check if exists already */
std::map<bdNodeId, bdQueryPeer>::iterator it;
for(it = mActivePeers.begin(); it != mActivePeers.end(); it++)
{
it->second.mStatus = BITDHT_QUERY_READY;
}
/* set state flag */
mMode = BITDHT_MGR_STATE_OFF;
mModeTS = now;
return 1;
}
int bdNodeManager::startDht()
{
time_t now = time(NULL);
/* set startup mode */
restartNode();
mMode = BITDHT_MGR_STATE_STARTUP;
mModeTS = now;
return 1;
}
/* STOPPED, STARTING, ACTIVE, FAILED */
int bdNodeManager::stateDht()
{
return mMode;
}
uint32_t bdNodeManager::statsNetworkSize()
{
return mNetworkSize;
}
/* same version as us! */
uint32_t bdNodeManager::statsBDVersionSize()
{
return mBdNetworkSize;
}
void bdNodeManager::addFindNode(bdNodeId *id, uint32_t qflags)
@ -166,6 +221,15 @@ void bdNodeManager::iteration()
time_t modeAge = now - mModeTS;
switch(mMode)
{
case BITDHT_MGR_STATE_OFF:
{
#ifdef DEBUG_MGR
std::cerr << "bdNodeManager::iteration(): OFF";
std::cerr << std::endl;
#endif
}
break;
case BITDHT_MGR_STATE_STARTUP:
/* 10 seconds startup .... then switch to ACTIVE */
@ -189,17 +253,26 @@ void bdNodeManager::iteration()
#define MAX_FINDSELF_TIME 60
#define MIN_OP_SPACE_SIZE 100
{
uint32_t nodeSpaceSize = mNodeSpace.calcSpaceSize();
#ifdef DEBUG_MGR
std::cerr << "bdNodeManager::iteration() Finding Oneself: NodeSpace Size:" << mNodeSpace.size();
std::cerr << "bdNodeManager::iteration() Finding Oneself: ";
std::cerr << "NodeSpace Size:" << nodeSpaceSize;
std::cerr << std::endl;
#endif
if ((modeAge > MAX_FINDSELF_TIME) ||
(mNodeSpace.size() > MIN_OP_SPACE_SIZE))
{
//mMode = BITDHT_MGR_STATE_ACTIVE;
mMode = BITDHT_MGR_STATE_REFRESH;
mModeTS = now;
if (nodeSpaceSize > MIN_OP_SPACE_SIZE)
{
mMode = BITDHT_MGR_STATE_REFRESH;
mModeTS = now;
}
if (modeAge > MAX_FINDSELF_TIME)
{
mMode = BITDHT_MGR_STATE_FAILED;
mModeTS = now;
}
}
break;
@ -253,15 +326,37 @@ void bdNodeManager::iteration()
case BITDHT_MGR_STATE_QUIET:
{
#ifdef DEBUG_MGR
std::cerr << "bdNodeManager::iteration(): QUIET";
std::cerr << std::endl;
#endif
}
break;
default:
case BITDHT_MGR_STATE_FAILED:
{
#ifdef DEBUG_MGR
std::cerr << "bdNodeManager::iteration(): FAILED ==> STARTUP";
std::cerr << std::endl;
#endif
stopDht();
startDht();
}
break;
}
/* tick parent */
bdNode::iteration();
if (mMode == BITDHT_MGR_STATE_OFF)
{
bdNode::iterationOff();
}
else
{
/* tick parent */
bdNode::iteration();
}
}
@ -271,6 +366,11 @@ int bdNodeManager::status()
printState();
checkStatus();
/* update the network numbers */
mNetworkSize = mNodeSpace.calcNetworkSize();
mBdNetworkSize = mNodeSpace.calcNetworkSizeWithFlag(
BITDHT_PEER_STATUS_DHT_APPL);
return 1;

View File

@ -70,11 +70,13 @@ class bdQueryPeer
};
#define BITDHT_MGR_STATE_OFF 0
#define BITDHT_MGR_STATE_STARTUP 1
#define BITDHT_MGR_STATE_FINDSELF 2
#define BITDHT_MGR_STATE_ACTIVE 3
#define BITDHT_MGR_STATE_REFRESH 4
#define BITDHT_MGR_STATE_QUIET 5
#define BITDHT_MGR_STATE_FAILED 6
#define MAX_STARTUP_TIME 10
#define MAX_REFRESH_TIME 10
@ -112,6 +114,12 @@ virtual void removeCallback(BitDhtCallback *cb);
virtual int getDhtPeerAddress(const bdNodeId *id, struct sockaddr_in &from);
virtual int getDhtValue(const bdNodeId *id, std::string key, std::string &value);
/* stats and Dht state */
virtual int startDht();
virtual int stopDht();
virtual int stateDht(); /* STOPPED, STARTING, ACTIVE, FAILED */
virtual uint32_t statsNetworkSize();
virtual uint32_t statsBDVersionSize(); /* same version as us! */
/******************* Internals *************************/
// Overloaded from bdnode for external node callback.
@ -140,6 +148,9 @@ void startQueries();
bdDhtFunctions *mFns;
uint32_t mNetworkSize;
uint32_t mBdNetworkSize;
/* future node functions */
//addPeerPing(foundId);
//clearPing(it->first);

View File

@ -61,41 +61,7 @@
bdNode::bdNode(bdNodeId *ownId, std::string dhtVersion, std::string bootfile, bdDhtFunctions *fns)
:mOwnId(*ownId), mNodeSpace(ownId, fns), mStore(bootfile, fns), mDhtVersion(dhtVersion), mFns(fns)
{
/* setup */
bdPeer peer;
while(mStore.getPeer(&peer))
{
addPotentialPeer(&(peer.mPeerId));
}
mCounterOutOfDatePing = 0;
mCounterPings = 0;
mCounterPongs = 0;
mCounterQueryNode = 0;
mCounterQueryHash = 0;
mCounterReplyFindNode = 0;
mCounterReplyQueryHash = 0;
mCounterRecvPing = 0;
mCounterRecvPong = 0;
mCounterRecvQueryNode = 0;
mCounterRecvQueryHash = 0;
mCounterRecvReplyFindNode = 0;
mCounterRecvReplyQueryHash = 0;
mLpfOutOfDatePing = 0;
mLpfPings = 0;
mLpfPongs = 0;
mLpfQueryNode = 0;
mLpfQueryHash = 0;
mLpfReplyFindNode = 0;
mLpfReplyQueryHash = 0;
mLpfRecvPing = 0;
mLpfRecvPong = 0;
mLpfRecvQueryNode = 0;
mLpfRecvQueryHash = 0;
mLpfRecvReplyFindNode = 0;
mLpfRecvReplyQueryHash = 0;
resetStats();
}
void bdNode::getOwnId(bdNodeId *id)
@ -103,19 +69,47 @@ void bdNode::getOwnId(bdNodeId *id)
*id = mOwnId;
}
#if 0
void bdNode::run()
/***** Startup / Shutdown ******/
void bdNode::restartNode()
{
resetStats();
mStore.reloadFromStore();
/* setup */
while(1)
bdPeer peer;
while(mStore.getPeer(&peer))
{
iteration();
sleep(1);
addPotentialPeer(&(peer.mPeerId));
}
}
#endif
void bdNode::shutdownNode()
{
/* clear the queries */
mLocalQueries.clear();
mRemoteQueries.clear();
/* clear the space */
mNodeSpace.clear();
mHashSpace.clear();
/* clear other stuff */
mPotentialPeers.clear();
mStore.clear();
/* clean up any outgoing messages */
while(mOutgoingMsgs.size() > 0)
{
bdNodeNetMsg *msg = mOutgoingMsgs.front();
mOutgoingMsgs.pop_front();
/* cleanup message */
delete msg;
}
}
/* Crappy initial store... use bdspace as answer */
void bdNode::updateStore()
@ -156,6 +150,20 @@ void bdNode::printQueries()
}
}
void bdNode::iterationOff()
{
/* clean up any incoming messages */
while(mIncomingMsgs.size() > 0)
{
bdNodeNetMsg *msg = mIncomingMsgs.front();
mIncomingMsgs.pop_front();
/* cleanup message */
delete msg;
}
}
void bdNode::iteration()
{
#ifdef DEBUG_NODE_MULTIPEER
@ -313,14 +321,6 @@ void bdNode::doStats()
mLpfReplyQueryHash *= (LPF_FACTOR);
mLpfReplyQueryHash += (1.0 - LPF_FACTOR) * mCounterReplyQueryHash;
mCounterOutOfDatePing = 0;
mCounterPings = 0;
mCounterPongs = 0;
mCounterQueryNode = 0;
mCounterQueryHash = 0;
mCounterReplyFindNode = 0;
mCounterReplyQueryHash = 0;
mLpfRecvPing *= (LPF_FACTOR);
mLpfRecvPing += (1.0 - LPF_FACTOR) * mCounterRecvPing;
mLpfRecvPong *= (LPF_FACTOR);
@ -334,12 +334,8 @@ void bdNode::doStats()
mLpfRecvReplyQueryHash *= (LPF_FACTOR);
mLpfRecvReplyQueryHash += (1.0 - LPF_FACTOR) * mCounterRecvReplyQueryHash;
mCounterRecvPing = 0;
mCounterRecvPong = 0;
mCounterRecvQueryNode = 0;
mCounterRecvQueryHash = 0;
mCounterRecvReplyFindNode = 0;
mCounterRecvReplyQueryHash = 0;
resetCounters();
}
void bdNode::printStats(std::ostream &out)
@ -370,8 +366,43 @@ void bdNode::printStats(std::ostream &out)
out << std::endl;
}
void bdNode::resetCounters()
{
mCounterOutOfDatePing = 0;
mCounterPings = 0;
mCounterPongs = 0;
mCounterQueryNode = 0;
mCounterQueryHash = 0;
mCounterReplyFindNode = 0;
mCounterReplyQueryHash = 0;
mCounterRecvPing = 0;
mCounterRecvPong = 0;
mCounterRecvQueryNode = 0;
mCounterRecvQueryHash = 0;
mCounterRecvReplyFindNode = 0;
mCounterRecvReplyQueryHash = 0;
}
void bdNode::resetStats()
{
mLpfOutOfDatePing = 0;
mLpfPings = 0;
mLpfPongs = 0;
mLpfQueryNode = 0;
mLpfQueryHash = 0;
mLpfReplyFindNode = 0;
mLpfReplyQueryHash = 0;
mLpfRecvPing = 0;
mLpfRecvPong = 0;
mLpfRecvQueryNode = 0;
mLpfRecvQueryHash = 0;
mLpfRecvReplyFindNode = 0;
mLpfRecvReplyQueryHash = 0;
resetCounters();
}
void bdNode::checkPotentialPeer(bdId *id)
@ -694,7 +725,7 @@ void bdNode::msgout_pong(bdId *id, bdToken *transId)
/* generate message, send to udp */
bdToken vid;
int vlen = BITDHT_TOKEN_MAX_LEN;
uint32_t vlen = BITDHT_TOKEN_MAX_LEN;
if (mDhtVersion.size() < vlen)
{
vlen = mDhtVersion.size();

View File

@ -97,6 +97,10 @@ class bdNode
bdNode(bdNodeId *id, std::string dhtVersion, std::string bootfile,
bdDhtFunctions *fns);
/* startup / shutdown node */
void restartNode();
void shutdownNode();
// virtual so manager can do callback.
// peer flags defined in bdiface.h
virtual void addPeer(const bdId *id, uint32_t peerflags);
@ -109,6 +113,7 @@ class bdNode
void clearQuery(const bdNodeId *id);
void QueryStatus(std::map<bdNodeId, bdQueryStatus> &statusMap);
void iterationOff();
void iteration();
void processRemoteQuery();
void updateStore();
@ -176,6 +181,8 @@ void recvPkt(char *msg, int len, struct sockaddr_in addr);
void printStats(std::ostream &out);
void printQueries();
void resetCounters();
void resetStats();
protected:

View File

@ -313,6 +313,19 @@ bdSpace::bdSpace(bdNodeId *ownId, bdDhtFunctions *fns)
return;
}
/* empty the buckets */
int bdSpace::clear()
{
std::vector<bdBucket>::iterator it;
/* iterate through the buckets, and sort by distance */
for(it = buckets.begin(); it != buckets.end(); it++)
{
it->entries.clear();
}
return 1;
}
int bdSpace::find_nearest_nodes(const bdNodeId *id, int number, std::list<bdId> /*excluding*/, std::multimap<bdMetric, bdId> &nearest)
{
std::multimap<bdMetric, bdId> closest;
@ -735,7 +748,84 @@ int bdSpace::printDHT()
}
int bdSpace::calcSizes()
uint32_t bdSpace::calcNetworkSize()
{
std::vector<bdBucket>::iterator it;
/* little summary */
unsigned long long sum = 0;
unsigned long long no_peers = 0;
uint32_t count = 0;
bool doPrint = false;
bool doAvg = false;
int i = 0;
for(it = buckets.begin(); it != buckets.end(); it++, i++)
{
int size = it->entries.size();
int shift = BITDHT_KEY_BITLEN - i;
bool toBig = false;
if (shift > BITDHT_ULLONG_BITS - mFns->bdBucketBitSize() - 1)
{
toBig = true;
shift = BITDHT_ULLONG_BITS - mFns->bdBucketBitSize() - 1;
}
unsigned long long no_nets = ((unsigned long long) 1 << shift);
/* use doPrint so it acts as a single switch */
if (size && !doAvg && !doPrint)
{
doAvg = true;
}
if (size && !doPrint)
{
doPrint = true;
}
if (size == 0)
{
/* reset counters - if empty slot - to discount outliers in average */
sum = 0;
no_peers = 0;
count = 0;
}
if (!toBig)
{
no_peers = no_nets * size;
}
if (doPrint && doAvg && !toBig)
{
if (size == mFns->bdNodesPerBucket())
{
/* last average */
doAvg = false;
}
if (no_peers != 0)
{
sum += no_peers;
count++;
}
}
}
uint32_t NetSize = 0;
if (count != 0)
{
NetSize = sum / count;
}
//std::cerr << "bdSpace::calcNetworkSize() : " << NetSize;
//std::cerr << std::endl;
return NetSize;
}
uint32_t bdSpace::calcNetworkSizeWithFlag(uint32_t withFlag)
{
std::vector<bdBucket>::iterator it;
@ -750,7 +840,16 @@ int bdSpace::calcSizes()
int i = 0;
for(it = buckets.begin(); it != buckets.end(); it++, i++)
{
int size = it->entries.size();
int size = 0;
std::list<bdPeer>::iterator lit;
for(lit = it->entries.begin(); lit != it->entries.end(); lit++)
{
if (withFlag & lit->mPeerFlags)
{
size++;
}
}
totalcount += size;
int shift = BITDHT_KEY_BITLEN - i;
@ -804,31 +903,29 @@ int bdSpace::calcSizes()
}
mLastSize = totalcount;
if (count == 0)
uint32_t NetSize = 0;
if (count != 0)
{
mLastNetSize = 0;
}
else
{
mLastNetSize = sum / count;
NetSize = sum / count;
}
return 1;
//std::cerr << "bdSpace::calcNetworkSize() : " << NetSize;
//std::cerr << std::endl;
return NetSize;
}
uint32_t bdSpace::size()
uint32_t bdSpace::calcSpaceSize()
{
calcSizes();
return mLastSize;
std::vector<bdBucket>::iterator it;
/* little summary */
uint32_t totalcount = 0;
for(it = buckets.begin(); it != buckets.end(); it++)
{
totalcount += it->entries.size();
}
return totalcount;
}
uint32_t bdSpace::netSize()
{
calcSizes();
return mLastNetSize;
}

View File

@ -146,6 +146,8 @@ class bdSpace
bdSpace(bdNodeId *ownId, bdDhtFunctions *fns);
int clear();
/* accessors */
int find_nearest_nodes(const bdNodeId *id, int number,
std::list<bdId> excluding, std::multimap<bdMetric, bdId> &nearest);
@ -154,9 +156,9 @@ int out_of_date_peer(bdId &id); // side-effect updates, send flag on peer.
int add_peer(const bdId *id, uint32_t mode);
int printDHT();
int calcSizes();
uint32_t size();
uint32_t netSize();
uint32_t calcNetworkSize();
uint32_t calcNetworkSizeWithFlag(uint32_t withFlag);
uint32_t calcSpaceSize();
/* to add later */
int updateOwnId(bdNodeId *newOwnId);
@ -166,9 +168,6 @@ int updateOwnId(bdNodeId *newOwnId);
std::vector<bdBucket> buckets;
bdNodeId mOwnId;
bdDhtFunctions *mFns;
uint32_t mLastSize;
uint32_t mLastNetSize;
};

View File

@ -41,14 +41,27 @@ bdStore::bdStore(std::string file, bdDhtFunctions *fns)
#endif
/* read data from file */
mIndex = 0;
mStoreFile = file;
FILE *fd = fopen(file.c_str(), "r");
reloadFromStore();
}
int bdStore::clear()
{
mIndex = 0;
store.clear();
return 1;
}
int bdStore::reloadFromStore()
{
clear();
FILE *fd = fopen(mStoreFile.c_str(), "r");
if (!fd)
{
fprintf(stderr, "Failed to Open File: %s ... No Peers\n", file.c_str());
return;
fprintf(stderr, "Failed to Open File: %s ... No Peers\n", mStoreFile.c_str());
return 0;
}
@ -84,6 +97,8 @@ bdStore::bdStore(std::string file, bdDhtFunctions *fns)
fprintf(stderr, "Read %ld Peers\n", (long) store.size());
#endif
return 1;
}
int bdStore::getPeer(bdPeer *peer)

View File

@ -36,6 +36,10 @@ class bdStore
public:
bdStore(std::string file, bdDhtFunctions *fns);
int reloadFromStore(); /* for restarts */
int clear();
int getPeer(bdPeer *peer);
void addStore(bdPeer *peer);
void writeStore(std::string file);

View File

@ -1,500 +1,500 @@
142.177.246.95 59112
116.2.32.161 20124
188.126.46.50 44950
95.179.25.105 20206
95.68.47.164 30021
58.123.157.201 26652
201.153.228.202 21677
121.44.92.49 46001
80.98.231.47 26348
77.81.214.54 55140
188.2.177.127 18893
77.106.248.215 61010
92.40.218.25 17436
79.11.74.201 25511
124.217.18.33 52665
110.139.49.2 10021
116.75.93.225 17753
91.154.247.194 47519
85.157.34.95 39877
87.207.198.164 57380
76.88.103.96 6688
69.156.182.48 9745
174.118.75.21 57528
78.131.114.243 35625
85.120.227.7 39679
67.21.102.65 61696
90.20.253.243 17134
77.106.112.192 63044
89.132.70.154 54892
89.228.34.41 11402
99.16.45.162 58728
114.169.35.228 10609
119.247.254.79 5294
62.194.214.11 53956
86.140.220.164 63805
89.209.84.223 45645
71.176.151.158 34312
87.252.246.164 10004
174.6.184.150 55074
122.116.144.204 6881
188.126.95.124 51422
178.40.80.76 14409
71.167.112.211 6881
204.210.194.241 6881
99.0.82.216 51494
109.124.16.234 11636
220.131.73.187 20718
178.88.8.252 56292
83.87.238.214 6881
87.78.183.103 24204
92.249.133.6 6754
81.225.216.54 53358
89.166.108.48 47175
109.194.46.208 80
24.252.70.24 52516
78.154.10.6 35981
99.1.110.3 22440
201.53.55.59 61292
95.58.92.65 48802
89.178.134.24 64389
76.215.117.211 51413
114.27.89.171 43349
80.99.42.137 10566
187.20.103.130 16333
213.85.141.144 46456
85.186.48.10 25274
70.48.43.93 59364
114.154.228.24 14512
202.67.20.232 13380
94.15.164.174 45657
151.56.153.203 10006
92.243.177.118 26338
95.71.69.196 25226
98.117.36.191 56023
209.222.54.23 6881
79.141.52.134 48614
82.4.38.3 60580
77.160.150.63 12348
95.132.188.142 16747
89.123.135.44 12967
24.242.52.51 41199
84.3.164.209 38059
67.61.48.132 51772
75.51.92.53 46369
61.56.132.76 23439
112.104.6.195 21025
78.116.106.245 29797
62.205.245.195 43207
188.24.228.246 48433
188.241.183.77 41892
95.78.151.107 28055
91.144.104.160 40122
203.135.35.68 16058
94.180.34.231 18040
216.186.213.183 34057
182.88.83.202 6881
188.163.76.190 51413
77.71.45.107 63222
71.63.16.85 44949
68.215.227.132 50513
62.228.103.223 11249
118.168.199.192 21018
89.103.74.81 11790
77.110.201.72 55144
87.21.255.123 32743
72.39.132.149 11229
178.49.20.218 42235
87.121.209.168 27230
118.108.135.76 22708
112.144.249.69 17601
85.210.192.179 53929
95.143.216.174 25887
95.43.73.227 25933
208.70.61.203 18073
70.178.206.42 24881
189.24.23.171 60416
62.201.119.41 61849
87.206.75.146 6881
78.176.207.54 6881
78.163.164.237 24362
99.190.51.250 59551
76.252.236.215 19134
98.242.28.163 26145
99.50.200.151 53564
220.98.144.232 22922
79.113.121.141 35771
98.148.246.127 50300
142.68.210.47 63653
218.168.225.229 22678
92.104.49.179 8500
173.32.63.117 61054
87.121.173.150 6148
83.251.66.66 65052
91.154.137.162 11984
80.171.58.170 22797
94.27.109.220 36053
118.160.53.83 12731
216.138.216.227 49001
187.16.62.58 63388
121.80.39.231 18252
213.112.106.243 18786
79.113.182.121 42808
82.119.65.229 41614
121.124.190.173 50282
117.194.194.73 13257
93.102.129.104 36854
92.104.22.153 6881
68.203.251.86 18992
173.51.127.134 33785
98.232.90.6 53436
59.98.161.236 62056
201.87.32.172 36138
88.115.78.139 15273
123.117.107.29 19970
93.96.190.204 6883
78.96.174.224 60387
68.40.87.11 37253
77.101.133.246 14789
115.143.47.172 30429
93.100.92.224 27243
80.80.153.98 11832
91.206.4.9 3333
188.35.8.236 62459
24.22.195.49 6881
76.101.135.11 20009
193.106.25.130 57020
79.107.183.240 45683
71.229.83.233 45682
76.88.94.229 37557
76.21.110.223 51413
99.40.159.122 25946
88.173.24.47 41595
67.149.36.107 40347
201.155.152.51 10196
118.128.22.37 37251
95.143.25.198 47616
92.144.60.92 13751
86.197.129.179 47067
99.66.5.48 21364
99.48.229.94 25361
121.254.45.84 6800
188.248.58.21 50340
95.26.55.82 59164
62.221.151.184 20536
109.201.74.159 10207
203.185.36.12 19872
210.73.1.92 12469
218.171.240.219 10236
173.73.187.215 37840
86.10.229.246 27857
119.247.45.173 10745
79.113.175.185 50877
95.31.11.189 6886
90.49.27.240 50510
188.4.197.57 59491
84.101.189.175 19015
67.189.42.213 53943
113.199.242.93 35720
183.179.97.20 24840
121.45.215.192 58823
121.219.253.112 31161
118.137.194.171 26705
210.6.173.121 14972
87.194.243.159 64670
83.77.171.200 15846
84.52.63.250 14255
173.75.218.211 63205
122.118.67.231 23915
83.9.39.33 22798
94.69.249.98 48057
88.106.69.215 11924
88.89.180.142 10766
77.45.166.176 32802
24.14.73.12 40442
123.203.168.108 16828
110.4.246.105 15045
88.215.184.26 52757
74.68.145.105 11524
112.70.90.34 7793
89.216.145.232 57343
86.207.79.244 19560
67.86.153.146 61010
92.83.127.98 18709
116.15.128.30 9998
203.59.10.85 22847
182.93.10.208 13054
79.17.30.127 32896
123.118.137.119 25421
219.175.138.61 23739
95.96.188.23 12400
24.98.183.64 57540
93.123.41.127 23436
173.87.8.115 22866
189.19.100.69 1224
220.102.166.142 27156
82.25.111.214 21311
193.201.198.253 63408
173.71.152.93 50989
70.119.159.158 62727
86.176.212.56 53046
74.78.254.79 55775
124.37.161.214 10990
123.204.252.197 10037
78.233.97.234 28751
78.106.52.107 15048
89.211.154.147 57399
78.92.20.255 14850
76.22.26.195 10269
60.46.193.129 20326
89.132.136.252 51385
122.217.69.120 21438
24.184.162.88 20212
71.139.186.245 31114
93.94.21.27 15252
87.70.142.8 15960
98.135.71.79 29008
117.47.90.194 10016
76.65.18.45 7700
87.224.254.21 25388
93.84.84.155 51757
213.16.120.166 54701
92.81.249.11 11185
77.54.70.32 35815
60.244.140.57 12687
109.165.40.174 23806
147.46.216.167 50410
180.25.22.176 40005
71.12.16.186 11422
88.141.135.252 58810
92.112.66.105 55311
111.249.218.164 56509
41.223.241.48 38494
80.99.189.105 50001
95.32.38.47 31175
92.28.148.131 22902
114.42.222.199 22443
175.115.187.64 13038
114.44.107.200 17500
81.50.148.235 64081
88.230.2.13 41680
60.49.48.177 21184
86.43.195.228 39164
88.237.29.153 14665
86.126.237.42 49627
68.37.160.28 29734
123.123.0.174 16330
84.215.70.237 25116
200.118.51.152 23106
92.62.116.14 38298
189.115.242.12 16373
86.126.244.83 10358
93.86.94.198 12077
220.134.70.7 57682
81.101.108.205 62082
80.48.112.175 24917
94.27.95.56 25376
41.239.99.14 16942
89.190.216.86 53241
58.152.99.134 16001
124.181.115.135 34574
110.226.38.196 11614
117.254.176.138 24325
67.164.200.224 40281
94.125.247.162 22331
213.130.92.78 32973
70.26.64.139 26358
219.70.171.198 18038
189.78.31.162 39736
86.184.173.124 63265
118.170.7.23 26814
186.45.139.74 12756
116.88.194.226 8883
114.47.171.209 21087
76.177.235.15 13961
178.164.177.154 8929
77.41.69.144 58436
93.152.162.14 42404
72.39.29.128 22844
70.160.28.191 29602
24.87.88.9 49947
41.204.126.178 11275
71.227.139.224 32093
76.28.227.60 10277
212.80.48.31 11175
95.130.12.19 61050
66.197.165.38 6821
72.12.147.238 48200
80.190.139.91 6892
77.108.227.234 46150
69.61.67.154 51413
209.82.182.182 46512
76.83.2.223 51867
76.189.218.104 31714
174.100.244.175 32360
178.162.183.226 6821
78.72.106.34 53188
188.134.14.120 9089
94.31.232.73 47220
24.12.33.224 25976
24.250.154.26 52769
84.86.167.83 49250
109.87.83.228 48931
88.162.153.3 45698
178.82.201.203 12055
67.215.242.138 6881
173.50.147.111 55669
67.240.191.70 53081
68.62.10.72 22867
88.184.85.157 40478
24.35.86.183 48539
67.183.139.6 29721
219.112.140.25 16297
110.175.157.60 12000
70.178.210.213 38087
77.93.16.43 35431
222.164.18.139 6881
83.248.90.115 53778
98.254.244.165 56359
90.180.166.149 6880
88.177.195.185 20299
67.215.242.139 6881
86.13.80.190 51326
86.107.79.233 49905
212.242.219.216 47000
95.76.50.171 19698
81.106.247.102 19244
188.134.67.102 6882
81.236.226.106 6882
94.47.188.106 56342
200.29.72.19 46935
99.139.154.78 8877
84.124.205.238 23020
213.125.29.122 6881
68.149.168.121 64750
99.57.47.134 19965
24.49.177.89 40029
221.46.51.137 22507
85.12.239.118 64317
78.90.116.74 19466
95.79.41.39 40496
213.133.98.4 6881
71.170.86.79 20322
90.154.242.204 59379
195.184.205.254 14834
201.37.1.184 20996
183.179.244.186 17518
98.219.151.25 33246
99.25.55.50 63685
95.90.32.98 21015
66.197.165.51 6821
68.44.82.53 12371
24.186.168.108 36916
74.79.37.90 31551
207.38.168.53 44635
209.202.78.188 14812
76.101.24.82 13823
68.46.57.52 11695
189.122.64.147 24387
123.163.132.87 64425
125.24.191.183 32201
123.231.81.151 45682
76.189.50.158 29456
212.117.167.140 10005
82.75.135.251 49155
77.250.123.105 6884
83.25.71.129 43558
212.117.1.153 17845
95.84.155.141 21057
195.22.140.72 4214
84.40.91.202 42870
85.10.46.180 24142
174.112.6.77 6881
151.12.60.142 42488
70.162.99.44 54092
193.91.144.166 43190
213.60.233.181 34385
71.235.207.19 53148
114.42.20.220 14842
81.98.127.164 48895
213.10.67.211 17030
62.45.245.22 6881
80.82.92.76 29221
89.28.27.55 17886
69.151.72.98 12345
78.187.75.191 41182
122.173.206.18 21221
75.53.192.65 56862
123.204.71.15 12632
213.46.44.100 59580
76.115.102.119 40940
85.227.178.143 25158
79.129.187.145 16458
195.98.76.238 24480
85.227.228.157 51413
83.252.123.146 58345
117.207.214.217 54937
86.110.176.106 30000
74.13.82.92 6881
92.33.129.197 16432
109.252.111.191 33426
188.17.177.14 23023
94.232.104.14 59873
60.54.43.194 14046
122.211.106.11 14409
113.10.81.130 18145
193.23.54.47 23933
151.46.167.111 14107
74.73.144.128 8944
188.168.34.126 50862
85.30.148.74 34178
83.99.166.208 32575
109.226.90.250 59039
216.252.93.187 10248
201.127.74.88 23041
220.232.101.77 10765
220.134.120.229 6881
41.228.251.92 47814
78.62.131.230 50104
24.150.5.250 51413
76.110.187.39 14164
65.184.131.218 6881
111.119.246.115 22046
68.96.113.203 14608
85.99.200.222 27808
184.56.211.105 52867
66.31.185.120 10317
218.145.169.134 3149
219.161.251.38 31529
99.101.221.11 11764
109.192.73.224 52318
98.242.28.163 26145
188.81.211.246 8080
80.254.125.140 34296
64.53.28.136 10809
111.254.1.128 17447
74.44.148.55 34665
84.10.244.103 48553
109.173.50.36 49288
84.3.119.233 45000
216.121.134.38 10348
77.49.255.137 38764
96.252.163.120 35217
72.89.151.90 17320
89.168.85.181 15348
124.84.78.74 10674
190.188.199.13 62986
94.254.73.152 44229
192.188.244.1 10634
84.215.248.234 40991
79.119.111.31 63150
95.155.230.83 54993
83.85.60.232 6881
178.130.32.118 14247
67.149.152.217 41077
91.86.3.133 32176
95.221.19.39 12976
83.83.80.92 6881
87.252.162.190 56515
151.66.131.139 46954
78.58.202.177 59464
71.199.157.116 30520
96.254.62.199 8200
24.14.102.44 44245
70.127.115.202 38183
99.189.18.223 41292
213.213.218.65 60981
190.50.213.190 36891
118.171.47.177 16001
119.83.243.224 16654
113.190.134.153 20216
114.42.139.73 16001
182.88.142.211 37365
119.6.28.67 18045
85.241.136.42 60048
68.40.16.60 11232
212.122.106.140 31783
109.173.59.147 12962
95.27.70.32 35054
77.37.202.193 36299
178.82.201.203 12055
109.161.85.240 44209
94.24.232.164 1500
75.73.169.64 22011
90.142.147.91 51488
76.92.206.199 14832
99.57.74.12 50424
173.60.116.127 55492
99.90.234.80 54989
99.192.38.145 50847
85.240.71.5 32193
98.219.151.25 33246
81.236.226.106 6882
89.88.117.136 50637
91.117.62.76 34004
99.230.133.39 9536
74.69.217.130 36242
86.23.42.71 50946
66.249.57.76 57217
210.89.51.164 52413
76.226.51.91 12663
24.64.83.1 45429
117.198.144.222 21855
64.166.166.167 22837
91.202.9.75 35691
24.158.190.101 30993
124.144.30.72 34172
98.220.212.46 13972
221.86.239.1 11798
68.190.208.15 50557
68.203.251.86 18992
178.92.94.213 56595
89.212.178.131 64999
178.140.66.146 47690
212.2.140.47 35691
93.100.231.80 33103
95.25.141.71 60569
109.87.58.45 36303
46.0.141.155 11396
87.97.230.29 21009
119.56.32.42 32382
92.124.53.28 46108
89.134.67.24 14172
114.38.122.171 40232
114.41.85.198 59723
122.148.239.163 6881
112.205.134.194 55288
78.147.163.160 14027
122.104.168.226 13618
138.217.156.134 63770
117.254.208.18 40438
75.3.113.99 6881
84.29.97.213 15577
91.211.83.75 61617
93.2.244.233 43565
86.139.36.0 12037
87.59.181.239 62153
174.112.6.77 6881
24.60.73.227 45502
69.137.165.233 6881
76.30.10.86 6881
24.79.144.209 34882
84.127.134.131 25717
98.193.20.11 58714
95.165.18.201 17170
189.12.171.99 13596
94.128.46.21 8827
60.34.66.88 25136
95.130.12.19 61050
77.250.121.26 51413
77.70.21.207 64309
213.133.98.4 6881
69.137.229.111 8500
109.184.173.10 10058
65.6.149.143 63622
82.194.190.194 36219
59.99.200.15 50007
98.180.221.118 37950
111.243.51.215 17517
125.27.60.193 55555
85.142.208.26 18256
87.120.157.123 6073
90.155.192.228 59169
91.103.205.231 30573
85.12.239.118 64317
174.64.9.192 25397
78.100.208.205 39074
66.229.163.248 41546
123.204.158.238 6881
94.6.215.232 35125
120.144.133.123 41889
203.218.92.102 13383
111.250.205.16 16001
91.179.186.59 12654
84.234.241.206 62793
84.211.40.116 26202
213.66.1.88 31701
109.93.197.4 15932
84.238.182.126 18755
86.107.219.33 29748
94.251.22.96 6890
94.28.27.245 10249
88.167.63.173 17155
95.160.98.229 19948
76.230.136.237 51413
88.160.107.217 33383
75.1.151.129 42526
80.99.198.116 51819
175.144.252.191 1722
67.140.208.226 44078
118.157.66.146 15267
88.89.93.181 6881
188.195.214.69 9089
90.214.16.2 10050
24.47.133.24 27457
88.186.78.58 53354
178.128.240.54 33591
67.215.242.139 6881
79.110.118.172 17827
85.17.74.169 6881
190.150.26.121 23765
189.5.90.211 16422
71.110.78.125 50924
112.104.174.102 25693
222.145.168.62 64457
125.25.169.12 46286
79.84.4.144 16887
95.52.76.243 27570
151.32.158.158 10464
189.4.13.169 60285
70.189.217.212 39037
119.117.135.178 13778
85.24.236.236 60224
77.110.26.188 19101
90.199.170.34 10491
212.187.127.4 42544
213.167.146.216 62238
24.36.225.41 13970
88.162.153.3 45698
67.167.185.252 36758
119.234.57.170 42523
118.93.145.87 27871
118.19.235.114 22136
124.244.75.29 50766
114.26.158.95 20185
143.238.237.25 14151
2.85.8.6 53180
112.105.159.195 21721
77.249.209.133 41620
109.230.14.32 30747
86.101.42.86 27426
213.149.144.24 23206
85.226.150.37 17020
95.42.53.21 50840
91.146.51.190 52891
79.139.234.104 16939
93.0.225.253 15592
98.254.244.165 56359
114.44.224.46 24232
60.50.37.37 63880
119.56.90.14 6884
222.134.253.50 25460
200.82.124.226 11216
86.124.181.25 41812
151.71.224.236 26022
78.128.123.63 22260
79.44.193.147 46988
81.88.124.26 25171
92.140.191.170 10583
74.192.41.234 12306
24.11.0.152 6881
98.162.214.118 6881
76.112.183.73 16254
217.217.35.121 32001
67.175.133.224 32772
78.36.196.61 59269
76.29.12.37 12308
78.180.216.41 17351
61.231.198.76 14685
118.14.157.125 21624
71.62.37.197 7914
71.29.78.193 55989
118.18.244.181 25949
92.97.196.183 42303
118.104.11.221 21289
190.174.204.226 42233
89.134.203.232 17633
95.26.152.248 60268
46.0.3.147 27613
24.49.32.34 28441
99.23.91.163 15016
90.209.174.130 21332
71.17.47.149 53164
119.246.176.132 6881
111.249.153.64 21540
123.119.85.79 24805
116.15.111.133 44914
109.154.116.92 24460
142.167.215.241 12277
78.8.106.8 50000
78.8.193.215 64759
76.234.70.144 63498
118.165.101.148 25966
78.29.72.239 10169
88.203.69.43 20846
85.230.126.66 59655
114.33.208.192 6881
213.137.40.155 28447
79.40.28.4 22978
85.220.113.75 44116
2.85.54.157 26621
92.82.169.146 10122
24.191.39.52 13692
24.92.85.17 41738
222.164.18.139 6881
59.156.223.119 58460
201.24.51.203 18936
210.207.227.15 54112
220.135.104.71 6885
111.166.209.176 16001
120.83.182.73 44755
203.219.45.127 56366
92.27.98.236 42249
213.107.103.7 26498
87.194.35.172 19102
85.155.45.17 26814
80.190.139.91 6895
80.202.98.113 24874
95.143.217.5 26620
87.121.131.142 18291
68.37.105.85 18621
76.125.40.83 36132
76.83.2.223 51867
82.130.145.80 10145
116.49.130.251 42663
219.95.36.65 22024
93.138.138.25 36193
125.198.109.94 25391
118.166.52.195 7613
125.214.154.196 14295
189.93.138.193 30752
212.116.83.37 48862
89.178.0.217 51413
95.95.243.42 63297
92.63.29.186 35073
213.100.103.111 59606
212.40.113.62 19734
71.206.232.202 46400
70.119.92.84 32082
78.101.105.86 17183
173.58.66.221 26774
94.28.105.90 37707
86.26.47.187 20295
70.52.182.161 20499
95.111.185.235 48104
122.94.252.223 21574
113.20.82.4 11560
1.23.143.146 24679
114.40.118.14 21330
85.181.59.132 34288
118.154.53.162 16234
109.174.68.4 51490
109.201.74.210 20655
75.62.19.231 37592
97.85.74.36 14594
83.233.120.5 51800
64.231.15.87 45129
24.85.138.161 26724
147.32.8.69 6881
88.216.128.98 32122
142.167.5.37 29661
68.4.207.220 63881
98.237.164.36 52796
99.109.20.192 16385
91.105.126.138 33105
111.255.46.225 26839
85.10.3.55 58402
123.243.29.227 37451
94.153.114.233 34599
94.75.136.162 31042
112.204.106.67 48691
217.120.148.194 51615
109.121.134.46 64548
178.150.86.230 63371
188.153.7.124 29949
2.55.82.43 18407
95.58.44.125 11121
116.74.115.65 32886
83.131.71.123 39603
99.148.166.253 49200
99.179.93.192 26004
117.200.32.60 33696
190.193.153.225 26735
68.103.246.183 62692
92.23.100.103 20962
82.48.131.139 6881
96.50.99.76 40637
183.83.0.210 55716
94.156.160.208 1296
99.240.114.49 60001
123.238.20.56 11495
98.164.225.18 51413
83.248.115.125 48880
77.50.124.217 45561
195.13.160.107 40473
91.185.36.137 16415
68.189.164.175 35316
90.163.159.154 48436
124.8.223.66 16880
24.161.134.16 23585
72.12.147.238 48200
77.99.163.56 14408
79.165.239.5 41714
95.34.50.159 33001
92.150.184.16 57367
76.120.195.253 52729
87.238.1.77 20617
115.134.213.88 22989
94.59.123.17 45340
189.6.134.85 16228
201.198.78.18 24646
82.244.111.116 50102
78.159.163.4 16880
203.214.42.15 35239
142.177.246.150 41881
220.253.180.201 51413
86.16.190.229 51413
81.89.106.209 51413
88.207.84.240 34723
79.108.206.28 16866
193.11.162.109 40000
88.222.107.185 23367
85.73.84.231 52545
81.249.93.113 53727
69.119.12.235 16181
94.97.7.171 21608
88.194.178.213 36956
83.10.93.128 17371
121.166.23.3 19226
85.136.235.241 10889
219.69.115.178 21604
220.136.219.134 19860
112.118.91.195 25949
189.74.105.192 1730
72.53.76.39 55501
213.64.51.135 35114
74.105.9.97 62498
79.56.233.96 37086
95.84.0.84 20090
70.75.213.15 20077
24.21.100.94 28550
208.118.23.71 56690
88.109.14.155 34392
189.236.5.200 26306
80.184.65.55 12052
90.151.185.253 49653
140.136.239.153 51413
119.77.220.96 22438
75.11.180.71 21205
114.76.81.8 20869
93.81.137.222 59627
99.249.255.103 21609
82.207.43.123 12452
94.72.123.6 16660
67.168.18.61 46759
216.8.170.95 44302
95.59.128.199 30499
190.159.56.248 60787
24.15.32.32 32241
114.249.142.149 23363
78.86.71.118 23744
89.160.3.33 10132
89.152.240.196 32504
94.244.172.119 28248
95.245.89.123 7881
88.87.1.254 20493
195.182.132.66 64356
94.64.144.11 7110
99.240.139.107 6881
71.91.56.80 19492
82.245.161.72 29889
41.201.68.118 15497
119.239.155.80 55121
200.104.77.39 15443
201.34.97.64 61884
121.221.223.224 12114
123.192.140.58 17701
158.193.168.5 21798
78.86.111.253 23576
88.106.167.216 28781
188.94.39.175 15010
213.111.238.195 56312
78.56.7.200 21846
94.41.112.123 23918
85.117.33.27 19637
209.20.68.239 62368
190.11.108.123 35985
89.34.34.249 24474
89.79.136.193 51413
95.27.123.195 34348
87.126.188.76 25422
195.214.237.249 15300
80.80.116.100 55993
180.2.23.99 24383
76.27.231.95 11423
188.51.83.143 56717
92.47.229.200 10385
210.6.213.167 26301
112.119.40.105 62294
24.108.1.66 63373
184.36.90.143 37107
182.48.202.118 28011
114.26.162.140 24871
67.149.182.183 17372
220.255.183.95 10793
89.243.44.234 23297
118.173.35.219 19018
124.13.140.102 38007
112.118.43.128 27673
188.87.87.100 45595
173.33.201.88 34218
184.91.39.18 20931
208.103.246.149 61903
114.41.224.18 19562
91.121.177.18 53140
178.94.155.182 60556
211.74.67.111 14181
199.74.97.182 29255
94.9.44.224 52476
189.91.127.145 20801
109.87.34.215 51413
82.69.1.251 5001
125.3.4.166 51187
69.203.68.51 11758
96.22.31.154 43510
174.65.137.136 48100
190.228.94.165 26710
187.104.62.61 19789
188.82.144.27 52696
219.237.1.104 52827
82.1.75.63 13312
83.94.240.45 30864
87.89.12.207 37559
59.101.167.84 20459
203.217.50.120 56814
219.79.49.98 23007
221.140.188.163 58808
24.87.209.90 9344
82.40.248.27 16676
99.32.75.52 14690
220.137.140.31 26831
83.9.219.77 48034
79.97.250.119 19888
212.142.76.123 53413
94.180.157.168 35124
216.245.196.72 54821
116.72.169.167 14492
189.47.125.243 36874
94.112.8.99 29633
117.207.235.231 25849
173.183.106.57 58370
95.93.136.147 21175
99.247.172.168 22177
77.95.59.144 34007
111.167.216.189 6881
95.77.154.219 27317
71.7.161.68 12588
115.164.135.201 56196
122.100.221.107 24300
213.60.104.227 22642
113.151.72.159 16352
218.103.176.234 10519
88.247.49.186 11074
83.6.190.105 26554
76.181.160.45 23986
216.252.75.148 51413
88.162.86.247 8444
89.215.27.13 9200

View File

@ -29,8 +29,106 @@
#include <iostream>
#include <stdio.h>
#include "utest.h"
bool test_metric_explicit();
bool test_metric_random();
INITTEST();
int main(int argc, char **argv)
{
std::cerr << "libbitdht: " << argv[0] << std::endl;
test_metric_explicit();
FINALREPORT("libbitdht: Metric Tests");
return TESTRESULT();
}
bool test_metric_explicit()
{
std::cerr << "test_metric_explicit:" << std::endl;
#define NUM_IDS 6
/* create some ids */
bdId id[NUM_IDS];
int i, j;
/* create a set of known ids ... and
* check the metrics are what we expect.
*/
for(i = 0; i < NUM_IDS; i++)
{
bdZeroNodeId(&(id[i].id));
}
/* test the zero node works */
for(i = 0; i < NUM_IDS; i++)
{
for(j = 0; j < BITDHT_KEY_LEN; j++)
{
CHECK(id[i].id.data[j] == 0);
}
}
for(i = 0; i < NUM_IDS; i++)
{
for(j = i; j < NUM_IDS; j++)
{
id[j].id.data[BITDHT_KEY_LEN - i - 1] = 1;
}
}
for(i = 0; i < NUM_IDS; i++)
{
fprintf(stderr, "id[%d]:", i+1);
bdStdPrintId(std::cerr,&(id[i]));
fprintf(stderr, "\n");
}
/* now do the sums */
bdMetric met;
bdMetric met2;
int bdist = 0;
for(i = 0; i < 6; i++)
{
for(j = i+1; j < 6; j++)
{
bdStdDistance(&(id[i].id), &(id[j].id), &met);
fprintf(stderr, "%d^%d:", i, j);
bdStdPrintNodeId(std::cerr,&met);
fprintf(stderr, "\n");
bdist = bdStdBucketDistance(&met);
fprintf(stderr, " bucket: %d\n", bdist);
}
}
#if 0
int c1 = met < met2;
int c2 = met2 < met;
fprintf(stderr, "1^2<1^3? : %d 1^3<1^2?: %d\n", c1, c2);
#endif
REPORT("Test Byte Manipulation");
//FAILED("Couldn't Bind to socket");
return 1;
}
bool test_metric_random()
{
std::cerr << "test_metric_random:" << std::endl;
/* create some ids */
bdId id1;

View File

@ -66,13 +66,21 @@ int main(int argc, char **argv)
std::string uid;
bool setUid = false;
bool doRandomQueries = false;
bool doRestart = false;
bool doThreadJoin = false;
srand(time(NULL));
while((c = getopt(argc, argv,"p:b:u:r")) != -1)
while((c = getopt(argc, argv,"rjp:b:u:q")) != -1)
{
switch (c)
{
case 'r':
doRestart = true;
break;
case 'j':
doThreadJoin = true;
break;
case 'p':
{
int tmp_port = atoi(optarg);
@ -107,7 +115,7 @@ int main(int argc, char **argv)
std::cerr << std::endl;
}
break;
case 'r':
case 'q':
{
doRandomQueries = true;
std::cerr << "Doing Random Queries";
@ -183,9 +191,29 @@ int main(int argc, char **argv)
int count = 0;
int running = 1;
std::cerr << "Starting Dht: ";
std::cerr << std::endl;
bitdht->startDht();
while(1)
{
sleep(60);
std::cerr << "BitDht State: ";
std::cerr << bitdht->stateDht();
std::cerr << std::endl;
std::cerr << "Dht Network Size: ";
std::cerr << bitdht->statsNetworkSize();
std::cerr << std::endl;
std::cerr << "BitDht Network Size: ";
std::cerr << bitdht->statsBDVersionSize();
std::cerr << std::endl;
if (++count == 2)
{
/* switch to one-shot searchs */
@ -196,10 +224,50 @@ int main(int argc, char **argv)
{
bdNodeId rndId;
bdStdRandomNodeId(&rndId);
std::cerr << "BitDht Launching Random Search: ";
bdStdPrintNodeId(std::cerr, &rndId);
std::cerr << std::endl;
bitdht->addFindNode(&rndId, mode);
}
}
if (doThreadJoin)
{
/* change address */
if (count % 2 == 0)
{
std::cerr << "Resetting UdpStack: ";
std::cerr << std::endl;
udpstack->resetAddress(local);
}
}
if (doRestart)
{
if (count % 2 == 1)
{
if (running)
{
std::cerr << "Stopping Dht: ";
std::cerr << std::endl;
bitdht->stopDht();
running = 0;
}
else
{
std::cerr << "Starting Dht: ";
std::cerr << std::endl;
bitdht->startDht();
running = 1;
}
}
}
}
return 1;
}

View File

@ -0,0 +1,23 @@
#ifndef _UNIT_TEST_MACROS_H__
#define _UNIT_TEST_MACROS_H__
#include <stdio.h>
#define TFAILURE( s ) printf( "FAILURE: " __FILE__ ":%-4d %s\n", __LINE__, s )
#define TSUCCESS( s ) printf( "SUCCESS: " __FILE__ ":%-4d %s\n", __LINE__, s )
/* careful with this line (no protection) */
#define INITTEST() int ok = 1; int gok = 1;
/* declare the variables */
extern int ok;
extern int gok;
#define CHECK( b ) do { if ( ! (b) ) { ok = 0; TFAILURE( #b ); } } while(0)
#define FAILED( s ) do { ok = 0; TFAILURE( s ); } while(0)
#define REPORT( s ) do { if ( ! (ok) ) { ok = 0; TFAILURE( s ); } else { TSUCCESS( s );} gok &= ok; ok = 1; } while(0)
#define REPORT2( b, s ) do { if ( ! (b) ) { ok = 0; TFAILURE( s ); } else { TSUCCESS( s );} gok &= ok; ok = 1; } while(0)
#define FINALREPORT( s ) do { gok &= ok; ok = 1; if ( ! (gok) ) { TFAILURE( s ); } else { TSUCCESS( s );} } while(0)
#define TESTRESULT() (!gok)
#endif

View File

@ -131,6 +131,43 @@ int UdpBitDht::getDhtValue(const bdNodeId *id, std::string key, std::string &va
return mBitDhtManager->getDhtValue(id, key, value);
}
/* stats and Dht state */
int UdpBitDht:: startDht()
{
bdStackMutex stack(dhtMtx); /********** MUTEX LOCKED *************/
return mBitDhtManager->startDht();
}
int UdpBitDht:: stopDht()
{
bdStackMutex stack(dhtMtx); /********** MUTEX LOCKED *************/
return mBitDhtManager->stopDht();
}
int UdpBitDht::stateDht()
{
bdStackMutex stack(dhtMtx); /********** MUTEX LOCKED *************/
return mBitDhtManager->stateDht();
}
uint32_t UdpBitDht::statsNetworkSize()
{
bdStackMutex stack(dhtMtx); /********** MUTEX LOCKED *************/
return mBitDhtManager->statsNetworkSize();
}
uint32_t UdpBitDht::statsBDVersionSize()
{
bdStackMutex stack(dhtMtx); /********** MUTEX LOCKED *************/
return mBitDhtManager->statsBDVersionSize();
}
/******************* Internals *************************/
/***** Iteration / Loop Management *****/

View File

@ -71,6 +71,13 @@ virtual void removeCallback(BitDhtCallback *cb);
virtual int getDhtPeerAddress(const bdNodeId *id, struct sockaddr_in &from);
virtual int getDhtValue(const bdNodeId *id, std::string key, std::string &value);
/* stats and Dht state */
virtual int startDht();
virtual int stopDht();
virtual int stateDht();
virtual uint32_t statsNetworkSize();
virtual uint32_t statsBDVersionSize();
/******************* Internals *************************/
/***** Iteration / Loop Management *****/

View File

@ -32,15 +32,26 @@
* #define DEBUG_THREADS 1
*******/
#define DEBUG_THREADS 1
#ifdef DEBUG_THREADS
#include <iostream>
#endif
extern "C" void* bdthread_init(void* p)
{
#ifdef DEBUG_THREADS
std::cerr << "bdthread_init()";
std::cerr << std::endl;
#endif
bdThread *thread = (bdThread *) p;
if (!thread)
{
#ifdef DEBUG_THREADS
std::cerr << "bdthread_init() Error Invalid thread pointer.";
std::cerr << std::endl;
#endif
return 0;
}
thread -> run();
@ -53,19 +64,45 @@ pthread_t createThread(bdThread &thread)
pthread_t tid;
void *data = (void *) (&thread);
#ifdef DEBUG_THREADS
std::cerr << "createThread() creating a bdThread";
std::cerr << std::endl;
#endif
thread.mMutex.lock();
{
pthread_create(&tid, 0, &bdthread_init, data);
thread.mTid = tid;
}
#ifdef DEBUG_THREADS
std::cerr << "createThread() created Thread.mTid: ";
#if defined(_WIN32) || defined(__MINGW32__)
std::cerr << "WIN32: Cannot print mTid ";
#else
std::cerr << thread.mTid;
#endif
std::cerr << std::endl;
#endif
thread.mMutex.unlock();
return tid;
}
bdThread::bdThread()
{
#ifdef DEBUG_THREADS
std::cerr << "bdThread::bdThread()";
std::cerr << std::endl;
#endif
#if defined(_WIN32) || defined(__MINGW32__)
memset (&mTid, 0, sizeof(mTid));
#else
@ -75,16 +112,59 @@ bdThread::bdThread()
void bdThread::join() /* waits for the the mTid thread to stop */
{
#ifdef DEBUG_THREADS
std::cerr << "bdThread::join() Called! Waiting for Thread.mTid: ";
#if defined(_WIN32) || defined(__MINGW32__)
std::cerr << "WIN32: Cannot print mTid ";
#else
std::cerr << mTid;
#endif
std::cerr << std::endl;
#endif
mMutex.lock();
{
#if defined(_WIN32) || defined(__MINGW32__)
/* Its a struct in Windows compile and the member .p ist checked in the pthreads library */
#else
if(mTid > 0)
#endif
pthread_join(mTid, NULL);
#ifdef DEBUG_THREADS
std::cerr << "bdThread::join() Joined Thread.mTid: ";
#if defined(_WIN32) || defined(__MINGW32__)
std::cerr << "WIN32: Cannot print mTid ";
#else
std::cerr << mTid;
#endif
std::cerr << std::endl;
std::cerr << "bdThread::join() Setting mTid = 0";
std::cerr << std::endl;
#endif
#if defined(_WIN32) || defined(__MINGW32__)
memset (&mTid, 0, sizeof(mTid));
#else
mTid = 0;
#endif
}
mMutex.unlock();
}
void bdThread::stop()
{
#ifdef DEBUG_THREADS
std::cerr << "bdThread::stop() Called!";
std::cerr << std::endl;
#endif
pthread_exit(NULL);
}