提交 767326b0 authored 作者: Shane Bryldt's avatar Shane Bryldt 提交者: Mike Jerris

FS-9775: Search for both v4 and v6 should now be implemented, untested currently

上级 c2868dbf
......@@ -267,6 +267,7 @@ KS_DECLARE(ks_status_t) ks_dht_search_create(ks_dht_search_t **search, ks_pool_t
KS_DECLARE(void) ks_dht_search_destroy(ks_dht_search_t **search);
KS_DECLARE(ks_status_t) ks_dht_search_callback_add(ks_dht_search_t *search, ks_dht_search_callback_t callback);
KS_DECLARE(void) ks_dht_search_expire(ks_dht_search_t *search, ks_hash_t *pending, int32_t *active);
KS_DECLARE(ks_status_t) ks_dht_search_pending_create(ks_dht_search_pending_t **pending, ks_pool_t *pool, const ks_dht_nodeid_t *nodeid);
KS_DECLARE(void) ks_dht_search_pending_destroy(ks_dht_search_pending_t **pending);
......
......@@ -149,17 +149,6 @@ struct ks_dht_transaction_s {
ks_bool_t finished;
};
// Check if search already exists for the target id, if so add another callback, must be a popular target id
// Otherwise create new search, set target id, add callback, and insert the search into the dht search_hash with target id key
// Get closest local nodes to target id, check against results, send_findnode for closer nodes and add to pending hash with queried node id
// Upon receiving find_node response, check target id against dht search_hash, check responding node id against pending hash, set finished for purging
// Update results if responding node id is closer than any current result, or the results are not full
// Check response nodes against results, send_findnode for closer nodes and add to pending hash with an expiration
// Pulse expirations purges expired and finished from pending hash, once hash is empty callbacks are called providing results array
// Note:
// During the lifetime of a search, the ks_dht_node_t's must be kept alive
// Do a query touch on nodes prior to being added to pending, this should reset timeout and keep the nodes alive long enough even if they are dubious
// Nodes which land in results are known good with recent response to find_nodes and should be around for a while before route table worries about cleanup
struct ks_dht_search_s {
ks_pool_t *pool;
ks_mutex_t *mutex;
......@@ -208,9 +197,6 @@ struct ks_dht_s {
ks_hash_t *registry_query;
ks_hash_t *registry_error;
ks_bool_t bind_ipv4;
ks_bool_t bind_ipv6;
ks_dht_endpoint_t **endpoints;
int32_t endpoints_size;
ks_hash_t *endpoints_hash;
......@@ -230,7 +216,8 @@ struct ks_dht_s {
ks_dhtrt_routetable_t *rt_ipv4;
ks_dhtrt_routetable_t *rt_ipv6;
ks_hash_t *search_hash;
ks_hash_t *searches4_hash;
ks_hash_t *searches6_hash;
volatile uint32_t token_secret_current;
volatile uint32_t token_secret_previous;
......@@ -300,7 +287,7 @@ KS_DECLARE(ks_status_t) ks_dht_register_error(ks_dht_t *dht, const char *value,
* @param dht pointer to the dht instance
* @param nodeid pointer to a nodeid for this endpoint, may be NULL to generate one randomly
* @param addr pointer to the local address information
* @param dereferenced out pointer to the allocated endpoint, may be NULL to ignore endpoint output
* @param endpoint dereferenced out pointer to the allocated endpoint, may be NULL to ignore endpoint output
* @return The ks_status_t result: KS_STATUS_SUCCESS, KS_STATUS_FAIL, ...
* @see ks_socket_option
* @see ks_addr_bind
......@@ -320,6 +307,25 @@ KS_DECLARE(ks_status_t) ks_dht_bind(ks_dht_t *dht, const ks_dht_nodeid_t *nodeid
*/
KS_DECLARE(void) ks_dht_pulse(ks_dht_t *dht, int32_t timeout);
/**
* Create a network search of the closest nodes to a target.
* @param dht pointer to the dht instance
* @param family either AF_INET or AF_INET6 for the appropriate network to search
* @param target pointer to the nodeid for the target to be searched
* @param callback an optional callback to add to the search when it is finished
* @param search dereferenced out pointer to the allocated search, may be NULL to ignore search output
* @return The ks_status_t result: KS_STATUS_SUCCESS, KS_STATUS_FAIL
* @see ks_dht_search_create
* @see ks_dht_search_callback_add
* @see ks_hash_insert
* @see ks_dht_search_pending_create
* @see ks_dht_send_findnode
*/
KS_DECLARE(ks_status_t) ks_dht_search(ks_dht_t *dht,
int32_t family,
ks_dht_nodeid_t *target,
ks_dht_search_callback_t callback,
ks_dht_search_t **search);
/**
*
......
......@@ -31,8 +31,7 @@ KS_DECLARE(ks_status_t) ks_dht_datagram_create(ks_dht_datagram_t **datagram,
// done:
if (ret != KS_STATUS_SUCCESS) {
if (dg) ks_dht_datagram_destroy(&dg);
*datagram = NULL;
ks_dht_datagram_destroy(datagram);
}
return ret;
}
......@@ -46,9 +45,7 @@ KS_DECLARE(void) ks_dht_datagram_destroy(ks_dht_datagram_t **datagram)
dg = *datagram;
ks_pool_free(dg->pool, &dg);
*datagram = NULL;
ks_pool_free(dg->pool, datagram);
}
/* For Emacs:
......
......@@ -30,8 +30,7 @@ KS_DECLARE(ks_status_t) ks_dht_endpoint_create(ks_dht_endpoint_t **endpoint,
// done:
if (ret != KS_STATUS_SUCCESS) {
if (ep) ks_dht_endpoint_destroy(&ep);
*endpoint = NULL;
if (ep) ks_dht_endpoint_destroy(endpoint);
}
return ret;
}
......@@ -49,9 +48,8 @@ KS_DECLARE(void) ks_dht_endpoint_destroy(ks_dht_endpoint_t **endpoint)
ep = *endpoint;
if (ep->sock != KS_SOCK_INVALID) ks_socket_close(&ep->sock);
ks_pool_free(ep->pool, &ep);
*endpoint = NULL;
ks_pool_free(ep->pool, endpoint);
}
/* For Emacs:
......
......@@ -26,8 +26,7 @@ KS_DECLARE(ks_status_t) ks_dht_message_create(ks_dht_message_t **message,
// done:
if (ret != KS_STATUS_SUCCESS) {
if (m) ks_dht_message_destroy(&m);
*message = NULL;
ks_dht_message_destroy(message);
}
return ret;
}
......@@ -45,9 +44,8 @@ KS_DECLARE(void) ks_dht_message_destroy(ks_dht_message_t **message)
ben_free(m->data);
m->data = NULL;
}
ks_pool_free(m->pool, &(*message));
*message = NULL;
ks_pool_free(m->pool, message);
}
......
......@@ -27,8 +27,7 @@ KS_DECLARE(ks_status_t) ks_dht_search_create(ks_dht_search_t **search, ks_pool_t
// done:
if (ret != KS_STATUS_SUCCESS) {
if (s) ks_dht_search_destroy(&s);
*search = NULL;
if (s) ks_dht_search_destroy(search);
}
return ret;
}
......@@ -58,9 +57,7 @@ KS_DECLARE(void) ks_dht_search_destroy(ks_dht_search_t **search)
}
if (s->mutex) ks_mutex_destroy(&s->mutex);
ks_pool_free(s->pool, &s);
*search = NULL;
ks_pool_free(s->pool, search);
}
KS_DECLARE(ks_status_t) ks_dht_search_callback_add(ks_dht_search_t *search, ks_dht_search_callback_t callback)
......@@ -100,10 +97,9 @@ KS_DECLARE(ks_status_t) ks_dht_search_pending_create(ks_dht_search_pending_t **p
// done:
if (ret != KS_STATUS_SUCCESS) {
if (p) ks_dht_search_pending_destroy(&p);
*pending = NULL;
if (p) ks_dht_search_pending_destroy(pending);
}
return KS_STATUS_SUCCESS;
return ret;
}
KS_DECLARE(void) ks_dht_search_pending_destroy(ks_dht_search_pending_t **pending)
......@@ -115,9 +111,7 @@ KS_DECLARE(void) ks_dht_search_pending_destroy(ks_dht_search_pending_t **pending
p = *pending;
ks_pool_free(p->pool, &p);
*pending = NULL;
ks_pool_free(p->pool, pending);
}
/* For Emacs:
......
......@@ -32,8 +32,7 @@ KS_DECLARE(ks_status_t) ks_dht_storageitem_create_immutable(ks_dht_storageitem_t
// done:
if (ret != KS_STATUS_SUCCESS) {
if (si) ks_dht_storageitem_destroy(&si);
*item = NULL;
if (si) ks_dht_storageitem_destroy(item);
}
return ret;
}
......@@ -83,8 +82,7 @@ KS_DECLARE(ks_status_t) ks_dht_storageitem_create_mutable(ks_dht_storageitem_t *
// done:
if (ret != KS_STATUS_SUCCESS) {
if (si) ks_dht_storageitem_destroy(&si);
*item = NULL;
if (si) ks_dht_storageitem_destroy(item);
}
return ret;
}
......@@ -105,9 +103,8 @@ KS_DECLARE(void) ks_dht_storageitem_destroy(ks_dht_storageitem_t **item)
ben_free(si->v);
si->v = NULL;
}
ks_pool_free(si->pool, &si);
*item = NULL;
ks_pool_free(si->pool, item);
}
/* For Emacs:
......
......@@ -25,8 +25,7 @@ KS_DECLARE(ks_status_t) ks_dht_transaction_create(ks_dht_transaction_t **transac
// done:
if (ret != KS_STATUS_SUCCESS) {
if (t) ks_dht_transaction_destroy(&t);
*transaction = NULL;
if (t) ks_dht_transaction_destroy(transaction);
}
return ret;
}
......@@ -40,9 +39,7 @@ KS_DECLARE(void) ks_dht_transaction_destroy(ks_dht_transaction_t **transaction)
t = *transaction;
ks_pool_free(t->pool, &t);
*transaction = NULL;
ks_pool_free(t->pool, transaction);
}
/* For Emacs:
......
......@@ -149,9 +149,9 @@ int main() {
diag("Pulsing for route table pings\n"); // Wait for route table pinging to catch up
for (int i = 0; i < 10; ++i) {
diag("DHT 1\n");
//diag("DHT 1\n");
ks_dht_pulse(dht1, 100);
diag("DHT 2\n");
//diag("DHT 2\n");
ks_dht_pulse(dht2, 100);
}
ok(ks_dhtrt_find_node(dht1->rt_ipv4, ep2->nodeid) != NULL); // The node should be good by now, and thus be returned as good
......@@ -174,9 +174,9 @@ int main() {
diag("Pulsing for route table pings\n"); // Wait for route table pinging to catch up
for (int i = 0; i < 10; ++i) {
diag("DHT 1\n");
//diag("DHT 1\n");
ks_dht_pulse(dht1, 100);
diag("DHT 2\n");
//diag("DHT 2\n");
ks_dht_pulse(dht2, 100);
}
ok(ks_dhtrt_find_node(dht3->rt_ipv4, ep2->nodeid) != NULL); // The node should be good by now, and thus be returned as good
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论