diff --git a/libs/libks/src/dht/ks_dht.h b/libs/libks/src/dht/ks_dht.h index a27e63dd6e..538d19ea2f 100644 --- a/libs/libks/src/dht/ks_dht.h +++ b/libs/libks/src/dht/ks_dht.h @@ -67,8 +67,9 @@ struct ks_dht_node_s { ks_dht_nodeid_t nodeid; ks_sockaddr_t addr; enum ks_afflags_t family; /* AF_INET or AF_INET6 */ - enum ks_dht_nodetype_t type; /* local or remote */ + enum ks_dht_nodetype_t type; /* local or remote */ ks_dhtrt_routetable_t* table; + ks_rwl_t *reflock; }; struct ks_dhtrt_routetable_s { @@ -433,6 +434,7 @@ KS_DECLARE(ks_status_t) ks_dhtrt_expire_node(ks_dhtrt_routetable_t* table KS_DECLARE(uint8_t) ks_dhtrt_findclosest_nodes(ks_dhtrt_routetable_t* table, ks_dhtrt_querynodes_t* query); KS_DECLARE(ks_dht_node_t*) ks_dhtrt_find_node(ks_dhtrt_routetable_t* table, ks_dht_nodeid_t id); +KS_DECLARE(ks_status_t) ks_dhtrt_release_node(ks_dht_node_t* node); KS_DECLARE(void) ks_dhtrt_process_table(ks_dhtrt_routetable_t* table); diff --git a/libs/libks/src/dht/ks_dht_bucket.c b/libs/libks/src/dht/ks_dht_bucket.c index 8278439226..3a68bceadc 100644 --- a/libs/libks/src/dht/ks_dht_bucket.c +++ b/libs/libks/src/dht/ks_dht_bucket.c @@ -235,11 +235,12 @@ KS_DECLARE(ks_status_t) ks_dhtrt_create_node( ks_dhtrt_routetable_t *table, memcpy(tnode->nodeid.id, nodeid.id, KS_DHT_NODEID_SIZE); tnode->type = type; - if ((ks_addr_set(&tnode->addr, ip, port, tnode->family) != KS_STATUS_SUCCESS) || - (ks_dhtrt_insert_node(table, tnode) != KS_STATUS_SUCCESS)) { - ks_pool_free(table->pool, tnode); - return KS_STATUS_FAIL; - } + if (( ks_addr_set(&tnode->addr, ip, port, tnode->family) != KS_STATUS_SUCCESS) || + ( ks_dhtrt_insert_node(table, tnode) != KS_STATUS_SUCCESS) || + ( ks_rwl_create(&tnode->reflock, table->pool) != KS_STATUS_SUCCESS)) { + ks_pool_free(table->pool, tnode); + return KS_STATUS_FAIL; + } (*node) = tnode; @@ -258,6 +259,7 @@ KS_DECLARE(ks_status_t) ks_dhtrt_delete_node(ks_dhtrt_routetable_t *table, ks_dh } } + ks_rwl_destroy(&node->reflock); ks_pool_free(table->pool, node); return KS_STATUS_SUCCESS; } @@ -561,6 +563,14 @@ KS_DECLARE(uint8_t) ks_dhtrt_findclosest_nodes(ks_dhtrt_routetable_t *table, ks_ return query->count; } +KS_DECLARE(ks_status_t) ks_dhtrt_release_node(ks_dht_node_t* node) +{ + return KS_STATUS_SUCCESS; + /* return ks_rwl_read_unlock(node->reflock);*/ +} + + + KS_DECLARE(void) ks_dhtrt_process_table(ks_dhtrt_routetable_t *table) { /* walk the table and update the status of all known knodes */