提交 1aee2786 authored 作者: colm's avatar colm 提交者: Mike Jerris

FS-9775: Format sources

上级 eac02b76
...@@ -431,12 +431,6 @@ ks_status_t ks_dhtrt_insert_node(ks_dhtrt_routetable_t *table, ks_dht_node_t *no ...@@ -431,12 +431,6 @@ ks_status_t ks_dhtrt_insert_node(ks_dhtrt_routetable_t *table, ks_dht_node_t *no
} }
} }
/*
todo: attempting a ping at at this point would require us
to suspend this process ... tricky...assume right now we will go ahead and
eject. Possibly add to a list to recheck
*/
if ( !(header->flags & BHF_LEFT) ) { /* only the left handside node can be split */ if ( !(header->flags & BHF_LEFT) ) { /* only the left handside node can be split */
#ifdef KS_DHT_DEBUGPRINTF_ #ifdef KS_DHT_DEBUGPRINTF_
char bufx[100]; char bufx[100];
...@@ -493,7 +487,8 @@ ks_status_t ks_dhtrt_insert_node(ks_dhtrt_routetable_t *table, ks_dht_node_t *no ...@@ -493,7 +487,8 @@ ks_status_t ks_dhtrt_insert_node(ks_dhtrt_routetable_t *table, ks_dht_node_t *no
ks_rwl_write_lock(bucket->lock); /* lock new bucket */ ks_rwl_write_lock(bucket->lock); /* lock new bucket */
ks_rwl_write_unlock(header->right->bucket->lock); /* unlock old bucket */ ks_rwl_write_unlock(header->right->bucket->lock); /* unlock old bucket */
header = newleft; header = newleft;
} else { }
else {
bucket = newright->bucket; bucket = newright->bucket;
/* note: we still hold a lock on the bucket */ /* note: we still hold a lock on the bucket */
header = newright; header = newright;
...@@ -1162,7 +1157,9 @@ ks_dhtrt_bucket_header_t *ks_dhtrt_create_bucketheader(ks_pool_t *pool, ks_dhtrt ...@@ -1162,7 +1157,9 @@ ks_dhtrt_bucket_header_t *ks_dhtrt_create_bucketheader(ks_pool_t *pool, ks_dhtrt
#ifdef KS_DHT_DEBUGPRINTF_ #ifdef KS_DHT_DEBUGPRINTF_
char buffer[100]; char buffer[100];
ks_log(KS_LOG_DEBUG, "creating bucket header for mask: %s\n", ks_dhtrt_printableid(mask, buffer)); ks_log(KS_LOG_DEBUG, "creating bucket header for mask: %s\n", ks_dhtrt_printableid(mask, buffer));
if (parent) ks_log(KS_LOG_DEBUG, " ... from parent mask: %s\n", ks_dhtrt_printableid(parent->mask, buffer)); if (parent) {
ks_log(KS_LOG_DEBUG, " ... from parent mask: %s\n", ks_dhtrt_printableid(parent->mask, buffer));
}
#endif #endif
return header; return header;
} }
...@@ -1221,7 +1218,6 @@ ks_dhtrt_bucket_header_t *ks_dhtrt_find_relatedbucketheader(ks_dhtrt_bucket_head ...@@ -1221,7 +1218,6 @@ ks_dhtrt_bucket_header_t *ks_dhtrt_find_relatedbucketheader(ks_dhtrt_bucket_head
header = header->right; header = header->right;
} }
} }
return NULL; return NULL;
} }
...@@ -1537,7 +1533,6 @@ uint8_t ks_dhtrt_load_query(ks_dhtrt_querynodes_t *query, ks_dhtrt_sortedxors_t ...@@ -1537,7 +1533,6 @@ uint8_t ks_dhtrt_load_query(ks_dhtrt_querynodes_t *query, ks_dhtrt_sortedxors_t
char buf1[100]; char buf1[100];
ks_log(KS_LOG_DEBUG, "load_query: UNLOCKING bucket %s\n", ks_log(KS_LOG_DEBUG, "load_query: UNLOCKING bucket %s\n",
ks_dhtrt_printableid(current->bheader->mask, buf1)); ks_dhtrt_printableid(current->bheader->mask, buf1));
fflush(stdout);
#endif #endif
ks_rwl_read_unlock(current->bheader->bucket->lock); /* release the read lock from findclosest_bucketnodes */ ks_rwl_read_unlock(current->bheader->bucket->lock); /* release the read lock from findclosest_bucketnodes */
......
...@@ -5,16 +5,16 @@ ...@@ -5,16 +5,16 @@
//#include "ks.h" //#include "ks.h"
#include "../src/dht/ks_dht.h" #include "../src/dht/ks_dht.h"
ks_dht_t* dht; ks_dht_t *dht;
ks_dhtrt_routetable_t* rt; ks_dhtrt_routetable_t *rt;
ks_pool_t* pool; ks_pool_t *pool;
ks_thread_pool_t* tpool; ks_thread_pool_t *tpool;
static ks_thread_t *threads[10]; static ks_thread_t *threads[10];
int doquery(ks_dhtrt_routetable_t* rt, uint8_t* id, enum ks_dht_nodetype_t type, enum ks_afflags_t family) int doquery(ks_dhtrt_routetable_t *rt, uint8_t *id, enum ks_dht_nodetype_t type, enum ks_afflags_t family)
{ {
ks_dhtrt_querynodes_t query; ks_dhtrt_querynodes_t query;
memset(&query, 0, sizeof(query)); memset(&query, 0, sizeof(query));
...@@ -28,9 +28,9 @@ int doquery(ks_dhtrt_routetable_t* rt, uint8_t* id, enum ks_dht_nodetype_t type, ...@@ -28,9 +28,9 @@ int doquery(ks_dhtrt_routetable_t* rt, uint8_t* id, enum ks_dht_nodetype_t type,
void test01() void test01()
{ {
printf("*** testbuckets - test01 start\n"); fflush(stdout); printf("**** testbuckets - test01 start\n"); fflush(stdout);
ks_dhtrt_routetable_t* rt; ks_dhtrt_routetable_t *rt;
ks_dhtrt_initroute(&rt, dht, pool, tpool); ks_dhtrt_initroute(&rt, dht, pool, tpool);
ks_dhtrt_deinitroute(&rt); ks_dhtrt_deinitroute(&rt);
...@@ -41,13 +41,13 @@ void test01() ...@@ -41,13 +41,13 @@ void test01()
char ip[] = "192.168.100.100"; char ip[] = "192.168.100.100";
unsigned short port = 7000; unsigned short port = 7000;
ks_dht_node_t* peer; ks_dht_node_t *peer;
ks_dht_node_t* peer1; ks_dht_node_t *peer1;
ks_status_t status; ks_status_t status;
status = ks_dhtrt_create_node(rt, homeid, KS_DHT_LOCAL, ip, port, &peer); status = ks_dhtrt_create_node(rt, homeid, KS_DHT_LOCAL, ip, port, &peer);
if (status == KS_STATUS_FAIL) { if (status == KS_STATUS_FAIL) {
printf("*** ks_dhtrt_create_node test01 failed\n"); printf("* **ks_dhtrt_create_node test01 failed\n");
exit(101); exit(101);
} }
...@@ -59,28 +59,28 @@ void test01() ...@@ -59,28 +59,28 @@ void test01()
status = ks_dhtrt_create_node(rt, homeid, KS_DHT_LOCAL, ip, port, &peer1); status = ks_dhtrt_create_node(rt, homeid, KS_DHT_LOCAL, ip, port, &peer1);
if (status == KS_STATUS_FAIL) { if (status == KS_STATUS_FAIL) {
printf("*** ks_dhtrt_create_node test01 did allow duplicate createnodes!!\n"); printf("**** ks_dhtrt_create_node test01 did allow duplicate createnodes!!\n");
exit(103); exit(103);
} }
if (peer != peer1) { if (peer != peer1) {
printf("*** ks_dhtrt_create_node duplicate createnode did not return the same node!\n"); printf("**** ks_dhtrt_create_node duplicate createnode did not return the same node!\n");
exit(104); exit(104);
} }
status = ks_dhtrt_delete_node(rt, peer); status = ks_dhtrt_delete_node(rt, peer);
if (status == KS_STATUS_FAIL) { if (status == KS_STATUS_FAIL) {
printf("*** ks_dhtrt_delete_node test01 failed\n"); printf("**** ks_dhtrt_delete_node test01 failed\n");
exit(104); exit(104);
} }
printf("*** testbuckets - test01 complete\n\n\n"); fflush(stdout); printf("**** testbuckets - test01 complete\n\n\n"); fflush(stdout);
} }
void test02() void test02()
{ {
printf("*** testbuckets - test02 start\n"); fflush(stdout); printf("**** testbuckets - test02 start\n"); fflush(stdout);
ks_dht_node_t* peer; ks_dht_node_t *peer;
ks_dht_nodeid_t nodeid; ks_dht_nodeid_t nodeid;
memset(nodeid.id, 0xef, KS_DHT_NODEID_SIZE); memset(nodeid.id, 0xef, KS_DHT_NODEID_SIZE);
...@@ -127,27 +127,27 @@ void test02() ...@@ -127,27 +127,27 @@ void test02()
status = ks_dhtrt_create_node(rt, nodeid, KS_DHT_LOCAL, ipv4, port, &peer); status = ks_dhtrt_create_node(rt, nodeid, KS_DHT_LOCAL, ipv4, port, &peer);
int qcount = doquery(rt, nodeid.id, KS_DHT_LOCAL, both); int qcount = doquery(rt, nodeid.id, KS_DHT_LOCAL, both);
printf("\n*** local query count expected 3, actual %d\n", qcount); fflush(stdout); printf("\n* **local query count expected 3, actual %d\n", qcount); fflush(stdout);
qcount = doquery(rt, nodeid.id, KS_DHT_REMOTE, both); qcount = doquery(rt, nodeid.id, KS_DHT_REMOTE, both);
printf("\n*** remote query count expected 6, actual %d\n", qcount); fflush(stdout); printf("\n* **remote query count expected 6, actual %d\n", qcount); fflush(stdout);
qcount = doquery(rt, nodeid.id, KS_DHT_BOTH, both); qcount = doquery(rt, nodeid.id, KS_DHT_BOTH, both);
printf("\n*** both query count expected 9, actual %d\n", qcount); fflush(stdout); printf("\n* **both query count expected 9, actual %d\n", qcount); fflush(stdout);
qcount = doquery(rt, nodeid.id, KS_DHT_LOCAL, ifv4); qcount = doquery(rt, nodeid.id, KS_DHT_LOCAL, ifv4);
printf("\n*** local AF_INET query count expected 1, actual %d\n", qcount); fflush(stdout); printf("\n* **local AF_INET query count expected 1, actual %d\n", qcount); fflush(stdout);
qcount = doquery(rt, nodeid.id, KS_DHT_LOCAL, ifv6); qcount = doquery(rt, nodeid.id, KS_DHT_LOCAL, ifv6);
printf("\n*** local AF_INET6 query count expected 2, actual %d\n", qcount); fflush(stdout); printf("\n* **local AF_INET6 query count expected 2, actual %d\n", qcount); fflush(stdout);
qcount = doquery(rt, nodeid.id, KS_DHT_BOTH, ifv6); qcount = doquery(rt, nodeid.id, KS_DHT_BOTH, ifv6);
printf("\n*** AF_INET6 count expected 5, actual %d\n", qcount); fflush(stdout); printf("\n* **AF_INET6 count expected 5, actual %d\n", qcount); fflush(stdout);
qcount = doquery(rt, nodeid.id, KS_DHT_REMOTE, ifv4); qcount = doquery(rt, nodeid.id, KS_DHT_REMOTE, ifv4);
printf("\n*** remote AF_INET query count expected 3, actual %d\n", qcount); fflush(stdout); printf("\n* **remote AF_INET query count expected 3, actual %d\n", qcount); fflush(stdout);
qcount = doquery(rt, nodeid.id, KS_DHT_REMOTE, ifv6); qcount = doquery(rt, nodeid.id, KS_DHT_REMOTE, ifv6);
printf("\n*** remote AF_INET6 query count expected 3, actual %d\n", qcount); fflush(stdout); printf("\n* **remote AF_INET6 query count expected 3, actual %d\n", qcount); fflush(stdout);
qcount = doquery(rt, nodeid.id, KS_DHT_BOTH, ifv4); qcount = doquery(rt, nodeid.id, KS_DHT_BOTH, ifv4);
printf("\n*** AF_INET count expected 4, actual %d\n", qcount); fflush(stdout); printf("\n* **AF_INET count expected 4, actual %d\n", qcount); fflush(stdout);
nodeid.id[19] = 5; nodeid.id[19] = 5;
ks_dhtrt_touch_node(rt, nodeid); ks_dhtrt_touch_node(rt, nodeid);
...@@ -155,9 +155,9 @@ void test02() ...@@ -155,9 +155,9 @@ void test02()
ks_dhtrt_touch_node(rt, nodeid); ks_dhtrt_touch_node(rt, nodeid);
qcount = doquery(rt, nodeid.id, KS_DHT_BOTH, ifv4); qcount = doquery(rt, nodeid.id, KS_DHT_BOTH, ifv4);
printf("\n*** AF_INET (after touch) count expected 6, actual %d\n", qcount); fflush(stdout); printf("\n**** AF_INET (after touch) count expected 6, actual %d\n", qcount); fflush(stdout);
printf("*** testbuckets - test02 finished\n"); fflush(stdout); printf("**** testbuckets - test02 finished\n"); fflush(stdout);
return; return;
} }
...@@ -166,9 +166,9 @@ void test02() ...@@ -166,9 +166,9 @@ void test02()
void test03() void test03()
{ {
printf("*** testbuckets - test03 start\n"); fflush(stdout); printf("**** testbuckets - test03 start\n"); fflush(stdout);
ks_dht_node_t* peer; ks_dht_node_t *peer;
ks_dht_nodeid_t nodeid; ks_dht_nodeid_t nodeid;
memset(nodeid.id, 0xef, KS_DHT_NODEID_SIZE); memset(nodeid.id, 0xef, KS_DHT_NODEID_SIZE);
...@@ -230,38 +230,38 @@ void test03() ...@@ -230,38 +230,38 @@ void test03()
int qcount = doquery(rt, nodeid.id, KS_DHT_LOCAL, both); int qcount = doquery(rt, nodeid.id, KS_DHT_LOCAL, both);
printf("\n** local query count expected 2, actual %d, max %d\n", qcount, ipv4_local); fflush(stdout); printf("\n**** local query count expected 2, actual %d, max %d\n", qcount, ipv4_local); fflush(stdout);
qcount = doquery(rt, nodeid.id, KS_DHT_REMOTE, both); qcount = doquery(rt, nodeid.id, KS_DHT_REMOTE, both);
printf("\n*** remote query count expected 20, actual %d\n", qcount); fflush(stdout); printf("\n**** remote query count expected 20, actual %d\n", qcount); fflush(stdout);
qcount = doquery(rt, nodeid.id, KS_DHT_BOTH, both); qcount = doquery(rt, nodeid.id, KS_DHT_BOTH, both);
printf("\n*** both query count expected 20, actual %d\n", qcount); fflush(stdout); printf("\n**** both query count expected 20, actual %d\n", qcount); fflush(stdout);
qcount = doquery(rt, nodeid.id, KS_DHT_LOCAL, ifv4); qcount = doquery(rt, nodeid.id, KS_DHT_LOCAL, ifv4);
printf("\n*** local AF_INET query count expected 2, actual %d\n", qcount); fflush(stdout); printf("\n**** local AF_INET query count expected 2, actual %d\n", qcount); fflush(stdout);
qcount = doquery(rt, nodeid.id, KS_DHT_LOCAL, ifv6); qcount = doquery(rt, nodeid.id, KS_DHT_LOCAL, ifv6);
printf("\n*** local AF_INET6 query count expected 0, actual %d\n", qcount); fflush(stdout); printf("\n**** local AF_INET6 query count expected 0, actual %d\n", qcount); fflush(stdout);
qcount = doquery(rt, nodeid.id, KS_DHT_BOTH, ifv6); qcount = doquery(rt, nodeid.id, KS_DHT_BOTH, ifv6);
printf("\n*** AF_INET6 count expected 20, actual %d\n", qcount); fflush(stdout); printf("\n**** AF_INET6 count expected 20, actual %d\n", qcount); fflush(stdout);
qcount = doquery(rt, nodeid.id, KS_DHT_REMOTE, ifv4); qcount = doquery(rt, nodeid.id, KS_DHT_REMOTE, ifv4);
printf("\n*** remote AF_INET query count expected 20, actual %d max %d\n", qcount, ipv4_remote); fflush(stdout); printf("\n**** remote AF_INET query count expected 20, actual %d max %d\n", qcount, ipv4_remote); fflush(stdout);
qcount = doquery(rt, nodeid.id, KS_DHT_REMOTE, ifv6); qcount = doquery(rt, nodeid.id, KS_DHT_REMOTE, ifv6);
printf("\n*** remote AF_INET6 query count expected 20, actual %d\n", qcount); fflush(stdout); printf("\n**** remote AF_INET6 query count expected 20, actual %d\n", qcount); fflush(stdout);
qcount = doquery(rt, nodeid.id, KS_DHT_BOTH, ifv4); qcount = doquery(rt, nodeid.id, KS_DHT_BOTH, ifv4);
printf("\n*** AF_INET count expected 20, actual %d\n", qcount); fflush(stdout); printf("\n**** AF_INET count expected 20, actual %d\n", qcount); fflush(stdout);
printf("*** testbuckets - test03 finished\n\n\n"); fflush(stdout); printf("**** testbuckets - test03 finished\n\n\n"); fflush(stdout);
return; return;
} }
void test04() void test04()
{ {
printf("*** testbuckets - test04 start\n"); fflush(stdout); printf("**** testbuckets - test04 start\n"); fflush(stdout);
ks_dht_node_t* peer; ks_dht_node_t *peer;
ks_dht_nodeid_t nodeid; ks_dht_nodeid_t nodeid;
memset(nodeid.id, 0xef, KS_DHT_NODEID_SIZE); memset(nodeid.id, 0xef, KS_DHT_NODEID_SIZE);
...@@ -275,10 +275,10 @@ void test04() ...@@ -275,10 +275,10 @@ void test04()
for (int i=0,i2=0,i3=0; i<10000; ++i, ++i2, ++i3) { for (int i=0,i2=0,i3=0; i<10000; ++i, ++i2, ++i3) {
if (i%20 == 0) { if (i%20 == 0) {
nodeid.id[0] = nodeid.id[0] / 2; nodeid.id[0] = nodeid.id[0] / 2;
if(i2%20 == 0) { if (i2%20 == 0) {
nodeid.id[1] = nodeid.id[1] / 2; nodeid.id[1] = nodeid.id[1] / 2;
i2 = 0; i2 = 0;
if(i3%20 == 0) { if (i3%20 == 0) {
nodeid.id[2] = nodeid.id[2] / 2; nodeid.id[2] = nodeid.id[2] / 2;
} }
} }
...@@ -302,9 +302,9 @@ void test04() ...@@ -302,9 +302,9 @@ void test04()
int tx = t1 - t0; int tx = t1 - t0;
t1 /= 1000; t1 /= 1000;
printf("*** query on 10k nodes in %d ms\n", tx); printf("**** query on 10k nodes in %d ms\n", tx);
printf("*** testbuckets - test04 finished\n\n\n"); fflush(stdout); printf("**** testbuckets - test04 finished\n\n\n"); fflush(stdout);
return; return;
} }
...@@ -312,9 +312,9 @@ void test04() ...@@ -312,9 +312,9 @@ void test04()
/* test read/write node locking */ /* test read/write node locking */
void test05() void test05()
{ {
printf("*** testbuckets - test05 start\n"); fflush(stdout); printf("**** testbuckets - test05 start\n"); fflush(stdout);
ks_dht_node_t* peer, *peer1, *peer2; ks_dht_node_t *peer, *peer1, *peer2;
ks_dht_nodeid_t nodeid; ks_dht_nodeid_t nodeid;
ks_status_t s; ks_status_t s;
...@@ -338,22 +338,20 @@ void test05() ...@@ -338,22 +338,20 @@ void test05()
s = ks_dhtrt_release_node(peer1); s = ks_dhtrt_release_node(peer1);
if (s == KS_STATUS_FAIL) printf("release 1 failed\n"); fflush(stdout); if (s == KS_STATUS_FAIL) printf("release 1 failed\n"); fflush(stdout);
s = ks_dhtrt_release_node(peer2); s = ks_dhtrt_release_node(peer2);
if (s == KS_STATUS_FAIL) printf("release 1 failed\n"); if (s == KS_STATUS_FAIL) printf("release 1 failed\n");
printf("*** testbuckets - test05 finished\n\n\n"); fflush(stdout); printf("* **testbuckets - test05 finished\n\n\n"); fflush(stdout);
return; return;
} }
/* test06 */ /* test06 */
/* ------- */ /* ------ */
ks_dht_nodeid_t g_nodeid1; ks_dht_nodeid_t g_nodeid1;
ks_dht_nodeid_t g_nodeid2; ks_dht_nodeid_t g_nodeid2;
ks_dht_node_t* g_peer; ks_dht_node_t *g_peer;
static void *testnodelocking_ex1(ks_thread_t *thread, void *data) static void *testnodelocking_ex1(ks_thread_t *thread, void *data)
{ {
...@@ -367,7 +365,7 @@ static void *testnodelocking_ex1(ks_thread_t *thread, void *data) ...@@ -367,7 +365,7 @@ static void *testnodelocking_ex1(ks_thread_t *thread, void *data)
static void *testnodelocking_ex2(ks_thread_t *thread, void *data) static void *testnodelocking_ex2(ks_thread_t *thread, void *data)
{ {
// lock=4 on entry // lock=4 on entry
ks_dht_node_t* peer2 = ks_dhtrt_find_node(rt, g_nodeid1); //lock=5 ks_dht_node_t *peer2 = ks_dhtrt_find_node(rt, g_nodeid1); //lock=5
ks_dhtrt_release_node(peer2); //lock=4 ks_dhtrt_release_node(peer2); //lock=4
ks_dhtrt_sharelock_node(peer2); //lock=5 ks_dhtrt_sharelock_node(peer2); //lock=5
ks_dhtrt_release_node(peer2); //lock=4 ks_dhtrt_release_node(peer2); //lock=4
...@@ -383,9 +381,9 @@ static void *testnodelocking_ex2(ks_thread_t *thread, void *data) ...@@ -383,9 +381,9 @@ static void *testnodelocking_ex2(ks_thread_t *thread, void *data)
void test06() void test06()
{ {
printf("*** testbuckets - test06 start\n"); fflush(stdout); printf("**** testbuckets - test06 start\n"); fflush(stdout);
ks_dht_node_t* peer; ks_dht_node_t *peer;
memset(g_nodeid1.id, 0xef, KS_DHT_NODEID_SIZE); memset(g_nodeid1.id, 0xef, KS_DHT_NODEID_SIZE);
memset(g_nodeid2.id, 0x1f, KS_DHT_NODEID_SIZE); memset(g_nodeid2.id, 0x1f, KS_DHT_NODEID_SIZE);
...@@ -396,7 +394,7 @@ void test06() ...@@ -396,7 +394,7 @@ void test06()
ks_dhtrt_create_node(rt, g_nodeid1, KS_DHT_REMOTE, ipv4, port, &peer); // lock=1 ks_dhtrt_create_node(rt, g_nodeid1, KS_DHT_REMOTE, ipv4, port, &peer); // lock=1
ks_dhtrt_touch_node(rt, g_nodeid1); ks_dhtrt_touch_node(rt, g_nodeid1);
ks_dht_node_t* peer2 = ks_dhtrt_find_node(rt, g_nodeid1); //lock=2 ks_dht_node_t *peer2 = ks_dhtrt_find_node(rt, g_nodeid1); //lock=2
peer2 = ks_dhtrt_find_node(rt, g_nodeid1); //lock=3 peer2 = ks_dhtrt_find_node(rt, g_nodeid1); //lock=3
peer2 = ks_dhtrt_find_node(rt, g_nodeid1); //lock=4 peer2 = ks_dhtrt_find_node(rt, g_nodeid1); //lock=4
...@@ -405,10 +403,10 @@ void test06() ...@@ -405,10 +403,10 @@ void test06()
g_peer = peer2; g_peer = peer2;
ks_thread_t* t0; ks_thread_t *t0;
ks_thread_create(&t0, testnodelocking_ex1, NULL, pool); ks_thread_create(&t0, testnodelocking_ex1, NULL, pool);
ks_thread_t* t1; ks_thread_t *t1;
ks_thread_create(&t1, testnodelocking_ex2, NULL, pool); ks_thread_create(&t1, testnodelocking_ex2, NULL, pool);
ks_thread_join(t1); ks_thread_join(t1);
...@@ -416,11 +414,11 @@ void test06() ...@@ -416,11 +414,11 @@ void test06()
ks_dhtrt_delete_node(rt, peer2); ks_dhtrt_delete_node(rt, peer2);
printf("\n\n*** testbuckets - test06 -- check if the node gets deleted\n\n\n\n"); fflush(stdout); printf("\n\n* **testbuckets - test06 -- check if the node gets deleted\n\n\n\n"); fflush(stdout);
ks_dhtrt_process_table(rt); ks_dhtrt_process_table(rt);
printf("*** testbuckets - test06 start\n"); fflush(stdout); printf("**** testbuckets - test06 start\n"); fflush(stdout);
return; return;
} }
...@@ -462,19 +460,20 @@ static void *test60ex2(ks_thread_t *thread, void *data) ...@@ -462,19 +460,20 @@ static void *test60ex2(ks_thread_t *thread, void *data)
ks_dhtrt_findclosest_nodes(rt, &query); ks_dhtrt_findclosest_nodes(rt, &query);
ks_sleep(10000); ks_sleep(10000);
for(int i=0; i<query.count; ++i) { for (int i=0; i<query.count; ++i) {
ks_dhtrt_release_node(query.nodes[i]); ks_dhtrt_release_node(query.nodes[i]);
ks_sleep(10000); ks_sleep(10000);
} }
ks_sleep(2000000); ks_sleep(2000000);
} }
return NULL; return NULL;
} }
static void *test60ex(ks_thread_t *thread, void *data) static void *test60ex(ks_thread_t *thread, void *data)
{ {
ks_dht_node_t* peer; ks_dht_node_t *peer;
ks_dht_nodeid_t nodeid; ks_dht_nodeid_t nodeid;
char ipv6[] = "1234:1234:1234:1234"; char ipv6[] = "1234:1234:1234:1234";
char ipv4[] = "123.123.123.123"; char ipv4[] = "123.123.123.123";
...@@ -490,7 +489,7 @@ static void *test60ex(ks_thread_t *thread, void *data) ...@@ -490,7 +489,7 @@ static void *test60ex(ks_thread_t *thread, void *data)
printf("starting thread with i of %d\n", gindex); fflush(stdout); printf("starting thread with i of %d\n", gindex); fflush(stdout);
for(int loop=0; loop<test60loops; ++loop) { for (int loop=0; loop<test60loops; ++loop) {
for (int i=0; i<test60nodes; ++i) { for (int i=0; i<test60nodes; ++i) {
++nodeid.id[19]; ++nodeid.id[19];
...@@ -520,19 +519,19 @@ void test60() ...@@ -520,19 +519,19 @@ void test60()
int i; int i;
ks_mutex_create(&glock, KS_MUTEX_FLAG_DEFAULT, pool); ks_mutex_create(&glock, KS_MUTEX_FLAG_DEFAULT, pool);
ks_thread_t* t0; ks_thread_t *t0;
ks_thread_create(&t0, test60ex1, NULL, pool); ks_thread_create(&t0, test60ex1, NULL, pool);
ks_thread_t* t1; ks_thread_t *t1;
ks_thread_create(&t1, test60ex2, NULL, pool); ks_thread_create(&t1, test60ex2, NULL, pool);
for(i = 0; i < 10; i++) { for (i = 0; i < 10; i++) {
ks_thread_create(&threads[i], test60ex, &i, pool); ks_thread_create(&threads[i], test60ex, &i, pool);
} }
printf("all threads started\n"); fflush(stdout); printf("all threads started\n"); fflush(stdout);
for(i = 0; i < 10; i++) { for (i = 0; i < 10; i++) {
ks_thread_join(threads[i]); ks_thread_join(threads[i]);
} }
gstop = 1; gstop = 1;
...@@ -552,9 +551,9 @@ void test60() ...@@ -552,9 +551,9 @@ void test60()
void test30() void test30()
{ {
printf("*** testbuckets - test03 start\n"); fflush(stdout); printf("**** testbuckets - test03 start\n"); fflush(stdout);
ks_dht_node_t* peer; ks_dht_node_t *peer;
ks_dht_nodeid_t nodeid; ks_dht_nodeid_t nodeid;
memset(nodeid.id, 0xef, KS_DHT_NODEID_SIZE); memset(nodeid.id, 0xef, KS_DHT_NODEID_SIZE);
...@@ -615,13 +614,13 @@ void test30() ...@@ -615,13 +614,13 @@ void test30()
int qcount = doquery(rt, nodeid.id, KS_DHT_LOCAL, both); int qcount = doquery(rt, nodeid.id, KS_DHT_LOCAL, both);
printf("\n** local query count expected 2, actual %d, max %d\n", qcount, ipv4_local); fflush(stdout); printf("\n **** local query count expected 2, actual %d, max %d\n", qcount, ipv4_local); fflush(stdout);
qcount = doquery(rt, nodeid.id, KS_DHT_LOCAL, both); qcount = doquery(rt, nodeid.id, KS_DHT_LOCAL, both);
printf("\n** local query count expected 2, actual %d, max %d\n", qcount, ipv4_local); fflush(stdout); printf("\n **** local query count expected 2, actual %d, max %d\n", qcount, ipv4_local); fflush(stdout);
qcount = doquery(rt, nodeid.id, KS_DHT_BOTH, both); qcount = doquery(rt, nodeid.id, KS_DHT_BOTH, both);
printf("\n** local query count expected 20, actual %d, max %d\n", qcount, ipv4_local); fflush(stdout); printf("\n **** local query count expected 20, actual %d, max %d\n", qcount, ipv4_local); fflush(stdout);
return; return;
} }
...@@ -637,7 +636,7 @@ void test50() ...@@ -637,7 +636,7 @@ void test50()
{ {
printf("*** testbuckets - test50 start\n"); fflush(stdout); printf("*** testbuckets - test50 start\n"); fflush(stdout);
ks_dht_node_t* peer; ks_dht_node_t *peer;
ks_dht_nodeid_t nodeid, nodeid2; ks_dht_nodeid_t nodeid, nodeid2;
memset(nodeid.id, 0xef, KS_DHT_NODEID_SIZE); memset(nodeid.id, 0xef, KS_DHT_NODEID_SIZE);
memset(nodeid2.id, 0xef, KS_DHT_NODEID_SIZE); memset(nodeid2.id, 0xef, KS_DHT_NODEID_SIZE);
...@@ -652,7 +651,7 @@ void test50() ...@@ -652,7 +651,7 @@ void test50()
for (int i=0,i2=0; i<200; ++i, ++i2) { for (int i=0,i2=0; i<200; ++i, ++i2) {
if (i%20 == 0) { if (i%20 == 0) {
nodeid.id[0] = nodeid.id[0] / 2; nodeid.id[0] = nodeid.id[0] / 2;
if(i2%20 == 0) { if (i2%20 == 0) {
i2 = 0; i2 = 0;
nodeid.id[1] = nodeid.id[1] / 2; nodeid.id[1] = nodeid.id[1] / 2;
} }
...@@ -671,7 +670,7 @@ void test50() ...@@ -671,7 +670,7 @@ void test50()
for (int i=0,i2=0; i<200; ++i, ++i2) { for (int i=0,i2=0; i<200; ++i, ++i2) {
if (i%20 == 0) { if (i%20 == 0) {
nodeid.id[0] = nodeid.id[0] / 2; nodeid.id[0] = nodeid.id[0] / 2;
if(i2%20 == 0) { if (i2%20 == 0) {
i2 = 0; i2 = 0;
nodeid.id[1] = nodeid.id[1] / 2; nodeid.id[1] = nodeid.id[1] / 2;
} }
...@@ -696,7 +695,7 @@ void test50() ...@@ -696,7 +695,7 @@ void test50()
for (int i=0,i2=0; i<200; ++i, ++i2) { for (int i=0,i2=0; i<200; ++i, ++i2) {
if (i%20 == 0) { if (i%20 == 0) {
nodeid.id[0] = nodeid.id[0] / 2; nodeid.id[0] = nodeid.id[0] / 2;
if(i2%20 == 0) { if (i2%20 == 0) {
i2 = 0; i2 = 0;
nodeid.id[1] = nodeid.id[1] / 2; nodeid.id[1] = nodeid.id[1] / 2;
} }
...@@ -711,7 +710,7 @@ void test50() ...@@ -711,7 +710,7 @@ void test50()
ks_dhtrt_touch_node(rt, nodeid); ks_dhtrt_touch_node(rt, nodeid);
} }
printf("*** testbuckets - test50 start\n"); fflush(stdout); printf("**** testbuckets - test50 start\n"); fflush(stdout);
return; return;
} }
...@@ -719,9 +718,9 @@ void test50() ...@@ -719,9 +718,9 @@ void test50()
/* test process_table */ /* test process_table */
void test51() void test51()
{ {
printf("*** testbuckets - test51 start\n"); fflush(stdout); printf("**** testbuckets - test51 start\n"); fflush(stdout);
ks_dht_node_t* peer; ks_dht_node_t *peer;
ks_dht_nodeid_t nodeid, nodeid2; ks_dht_nodeid_t nodeid, nodeid2;
memset(nodeid.id, 0xef, KS_DHT_NODEID_SIZE); memset(nodeid.id, 0xef, KS_DHT_NODEID_SIZE);
memset(nodeid2.id, 0xef, KS_DHT_NODEID_SIZE); memset(nodeid2.id, 0xef, KS_DHT_NODEID_SIZE);
...@@ -736,7 +735,7 @@ void test51() ...@@ -736,7 +735,7 @@ void test51()
for (int i=0,i2=0; i<2; ++i, ++i2) { for (int i=0,i2=0; i<2; ++i, ++i2) {
if (i%20 == 0) { if (i%20 == 0) {
nodeid.id[0] = nodeid.id[0] / 2; nodeid.id[0] = nodeid.id[0] / 2;
if(i2%20 == 0) { if (i2%20 == 0) {
i2 = 0; i2 = 0;
nodeid.id[1] = nodeid.id[1] / 2; nodeid.id[1] = nodeid.id[1] / 2;
} }
...@@ -751,33 +750,31 @@ void test51() ...@@ -751,33 +750,31 @@ void test51()
ks_dhtrt_touch_node(rt, nodeid); ks_dhtrt_touch_node(rt, nodeid);
} }
for(int ix=0; ix<50; ++ix) { for (int ix=0; ix<50; ++ix) {
ks_dhtrt_process_table(rt); ks_dhtrt_process_table(rt);
ks_sleep(1000 * 1000 * 120); ks_sleep(1000 *1000 *120);
printf("*** pulse ks_dhtrt_process_table\n"); printf("* **pulse ks_dhtrt_process_table\n");
if ( ix%2 == 0) ks_dhtrt_dump(rt, 7); if ( ix%2 == 0) ks_dhtrt_dump(rt, 7);
} }
printf("**** testbuckets - test51 complete\n"); fflush(stdout);
printf("*** testbuckets - test51 complete\n"); fflush(stdout);
return; return;
} }
int main(int argc, char* argv[]) { int main(int argc, char *argv[]) {
printf("testdhtbuckets - start\n"); printf("testdhtbuckets - start\n");
int tests[100]; int tests[100];
if (argc == 0) { if (argc == 0) {
tests[0] = 1; tests[0] = 1;
tests[1] = 1; tests[1] = 2;
tests[2] = 1; tests[2] = 3;
tests[3] = 1; tests[3] = 4;
tests[4] = 1; tests[4] = 5;
} }
else { else {
for(int tix=1; tix<100 && tix<argc; ++tix) { for(int tix=1; tix<100 && tix<argc; ++tix) {
...@@ -815,7 +812,7 @@ int main(int argc, char* argv[]) { ...@@ -815,7 +812,7 @@ int main(int argc, char* argv[]) {
ks_dhtrt_deinitroute(&rt); ks_dhtrt_deinitroute(&rt);
for(int tix=0; tix<argc; ++tix) { for (int tix=0; tix<argc; ++tix) {
if (tests[tix] == 1) { if (tests[tix] == 1) {
ks_dhtrt_initroute(&rt, dht, pool, tpool); ks_dhtrt_initroute(&rt, dht, pool, tpool);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论