diff --git a/libs/libks/src/dht/ks_dht.c b/libs/libks/src/dht/ks_dht.c index e93c424ba0..1c9c7effe4 100644 --- a/libs/libks/src/dht/ks_dht.c +++ b/libs/libks/src/dht/ks_dht.c @@ -61,6 +61,10 @@ KS_DECLARE(ks_status_t) ks_dht2_init(ks_dht2_t *dht, const uint8_t *nodeid) ks_assert(dht); ks_assert(dht->pool); + if (ks_dht2_nodeid_salloc(&dht->nodeid, dht->pool) != KS_STATUS_SUCCESS) { + return KS_STATUS_FAIL; + } + if (ks_dht2_nodeid_init(&dht->nodeid, nodeid) != KS_STATUS_SUCCESS) { return KS_STATUS_FAIL; } diff --git a/libs/libks/src/dht/ks_dht_endpoint-int.h b/libs/libks/src/dht/ks_dht_endpoint-int.h index c8361aca0b..8483a8a038 100644 --- a/libs/libks/src/dht/ks_dht_endpoint-int.h +++ b/libs/libks/src/dht/ks_dht_endpoint-int.h @@ -6,6 +6,7 @@ KS_BEGIN_EXTERN_C KS_DECLARE(ks_status_t) ks_dht2_endpoint_alloc(ks_dht2_endpoint_t **endpoint, ks_pool_t *pool); +KS_DECLARE(ks_status_t) ks_dht2_endpoint_salloc(ks_dht2_endpoint_t *endpoint, ks_pool_t *pool); KS_DECLARE(ks_status_t) ks_dht2_endpoint_free(ks_dht2_endpoint_t *endpoint); KS_DECLARE(ks_status_t) ks_dht2_endpoint_init(ks_dht2_endpoint_t *endpoint, const ks_sockaddr_t *addr, ks_socket_t sock); diff --git a/libs/libks/src/dht/ks_dht_endpoint.c b/libs/libks/src/dht/ks_dht_endpoint.c index 2818a7c98f..3b5d21b474 100644 --- a/libs/libks/src/dht/ks_dht_endpoint.c +++ b/libs/libks/src/dht/ks_dht_endpoint.c @@ -17,6 +17,19 @@ KS_DECLARE(ks_status_t) ks_dht2_endpoint_alloc(ks_dht2_endpoint_t **endpoint, ks return KS_STATUS_SUCCESS; } +/** + * + */ +KS_DECLARE(ks_status_t) ks_dht2_endpoint_salloc(ks_dht2_endpoint_t *endpoint, ks_pool_t *pool) +{ + ks_assert(endpoint); + ks_assert(pool); + + endpoint->pool = pool; + + return KS_STATUS_SUCCESS; +} + /** * */ @@ -28,7 +41,7 @@ KS_DECLARE(ks_status_t) ks_dht2_endpoint_free(ks_dht2_endpoint_t *endpoint) return KS_STATUS_SUCCESS; } - + /** * @@ -36,6 +49,7 @@ KS_DECLARE(ks_status_t) ks_dht2_endpoint_free(ks_dht2_endpoint_t *endpoint) KS_DECLARE(ks_status_t) ks_dht2_endpoint_init(ks_dht2_endpoint_t *endpoint, const ks_sockaddr_t *addr, ks_socket_t sock) { ks_assert(endpoint); + ks_assert(endpoint->pool); ks_assert(addr); ks_assert(addr->family == AF_INET || addr->family == AF_INET6); diff --git a/libs/libks/src/dht/ks_dht_nodeid.c b/libs/libks/src/dht/ks_dht_nodeid.c index 735213dce2..a3a6296ec2 100644 --- a/libs/libks/src/dht/ks_dht_nodeid.c +++ b/libs/libks/src/dht/ks_dht_nodeid.c @@ -17,6 +17,19 @@ KS_DECLARE(ks_status_t) ks_dht2_nodeid_alloc(ks_dht2_nodeid_t **nodeid, ks_pool_ return KS_STATUS_SUCCESS; } +/** + * + */ +KS_DECLARE(ks_status_t) ks_dht2_nodeid_salloc(ks_dht2_nodeid_t *nodeid, ks_pool_t *pool) +{ + ks_assert(nodeid); + ks_assert(pool); + + nodeid->pool = pool; + + return KS_STATUS_SUCCESS; +} + /** * */ @@ -36,6 +49,7 @@ KS_DECLARE(ks_status_t) ks_dht2_nodeid_free(ks_dht2_nodeid_t *nodeid) KS_DECLARE(ks_status_t) ks_dht2_nodeid_init(ks_dht2_nodeid_t *nodeid, const uint8_t *id) { ks_assert(nodeid); + ks_assert(nodeid->pool); if (!id) { randombytes_buf(nodeid->id, KS_DHT_NODEID_LENGTH); diff --git a/libs/libks/src/dht/ks_dht_nodeid.h b/libs/libks/src/dht/ks_dht_nodeid.h index 5eef173b7c..d8b2594a2f 100644 --- a/libs/libks/src/dht/ks_dht_nodeid.h +++ b/libs/libks/src/dht/ks_dht_nodeid.h @@ -14,6 +14,7 @@ struct ks_dht2_nodeid_s { }; KS_DECLARE(ks_status_t) ks_dht2_nodeid_alloc(ks_dht2_nodeid_t **nodeid, ks_pool_t *pool); +KS_DECLARE(ks_status_t) ks_dht2_nodeid_salloc(ks_dht2_nodeid_t *nodeid, ks_pool_t *pool); KS_DECLARE(ks_status_t) ks_dht2_nodeid_free(ks_dht2_nodeid_t *nodeid); KS_DECLARE(ks_status_t) ks_dht2_nodeid_init(ks_dht2_nodeid_t *nodeid, const uint8_t *id);