mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-03-13 12:40:17 +00:00
FS-9775: Adjusted ks_dht_nodeid_t back to a structure as you cannot cast raw data to a fixed array
This commit is contained in:
parent
70fcffc48c
commit
c22b252ca0
@ -34,6 +34,8 @@ KS_DECLARE(ks_status_t) ks_dht_alloc(ks_dht_t **dht, ks_pool_t *pool)
|
|||||||
d->recv_buffer_length = 0;
|
d->recv_buffer_length = 0;
|
||||||
d->transactionid_next = 0;
|
d->transactionid_next = 0;
|
||||||
d->transactions_hash = NULL;
|
d->transactions_hash = NULL;
|
||||||
|
d->rt_ipv4 = NULL;
|
||||||
|
d->rt_ipv6 = NULL;
|
||||||
|
|
||||||
return KS_STATUS_SUCCESS;
|
return KS_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
@ -65,6 +67,8 @@ KS_DECLARE(ks_status_t) ks_dht_prealloc(ks_dht_t *dht, ks_pool_t *pool)
|
|||||||
dht->recv_buffer_length = 0;
|
dht->recv_buffer_length = 0;
|
||||||
dht->transactionid_next = 0;
|
dht->transactionid_next = 0;
|
||||||
dht->transactions_hash = NULL;
|
dht->transactions_hash = NULL;
|
||||||
|
dht->rt_ipv4 = NULL;
|
||||||
|
dht->rt_ipv6 = NULL;
|
||||||
|
|
||||||
return KS_STATUS_SUCCESS;
|
return KS_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
@ -125,6 +129,9 @@ KS_DECLARE(ks_status_t) ks_dht_init(ks_dht_t *dht)
|
|||||||
dht->transactionid_next = 1; //rand();
|
dht->transactionid_next = 1; //rand();
|
||||||
ks_hash_create(&dht->transactions_hash, KS_HASH_MODE_INT, KS_HASH_FLAG_RWLOCK, dht->pool);
|
ks_hash_create(&dht->transactions_hash, KS_HASH_MODE_INT, KS_HASH_FLAG_RWLOCK, dht->pool);
|
||||||
|
|
||||||
|
dht->rt_ipv4 = NULL;
|
||||||
|
dht->rt_ipv6 = NULL;
|
||||||
|
|
||||||
return KS_STATUS_SUCCESS;
|
return KS_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,6 +142,14 @@ KS_DECLARE(ks_status_t) ks_dht_deinit(ks_dht_t *dht)
|
|||||||
{
|
{
|
||||||
ks_assert(dht);
|
ks_assert(dht);
|
||||||
|
|
||||||
|
if (dht->rt_ipv4) {
|
||||||
|
ks_dhtrt_deinitroute(dht->rt_ipv4);
|
||||||
|
dht->rt_ipv4 = NULL;
|
||||||
|
}
|
||||||
|
if (dht->rt_ipv6) {
|
||||||
|
ks_dhtrt_deinitroute(dht->rt_ipv6);
|
||||||
|
dht->rt_ipv6 = NULL;
|
||||||
|
}
|
||||||
dht->transactionid_next = 0;
|
dht->transactionid_next = 0;
|
||||||
if (dht->transactions_hash) {
|
if (dht->transactions_hash) {
|
||||||
ks_hash_destroy(&dht->transactions_hash);
|
ks_hash_destroy(&dht->transactions_hash);
|
||||||
@ -311,6 +326,17 @@ KS_DECLARE(ks_status_t) ks_dht_bind(ks_dht_t *dht, const ks_dht_nodeid_t *nodeid
|
|||||||
dht->endpoints_poll[epindex].fd = ep->sock;
|
dht->endpoints_poll[epindex].fd = ep->sock;
|
||||||
dht->endpoints_poll[epindex].events = POLLIN | POLLERR;
|
dht->endpoints_poll[epindex].events = POLLIN | POLLERR;
|
||||||
|
|
||||||
|
// @todo initialize or add local nodeid to appropriate route table
|
||||||
|
if (ep->addr.family == AF_INET) {
|
||||||
|
if (!dht->rt_ipv4) {
|
||||||
|
//ks_dhtrt_initroute(&dht->rt_ipv4, dht->pool, (ks_dhtrt_nodeid_t));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!dht->rt_ipv6) {
|
||||||
|
//ks_dhtrt_initroute(&dht->rt_ipv6, dht->pool);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (endpoint) {
|
if (endpoint) {
|
||||||
*endpoint = ep;
|
*endpoint = ep;
|
||||||
}
|
}
|
||||||
@ -727,7 +753,7 @@ KS_DECLARE(ks_status_t) ks_dht_send_ping(ks_dht_t *dht, ks_dht_endpoint_t *ep, k
|
|||||||
return KS_STATUS_FAIL;
|
return KS_STATUS_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ben_dict_set(a, ben_blob("id", 2), ben_blob(ep->nodeid, KS_DHT_NODEID_SIZE));
|
ben_dict_set(a, ben_blob("id", 2), ben_blob(ep->nodeid.id, KS_DHT_NODEID_SIZE));
|
||||||
|
|
||||||
ks_log(KS_LOG_DEBUG, "Sending message query ping\n");
|
ks_log(KS_LOG_DEBUG, "Sending message query ping\n");
|
||||||
ks_q_push(dht->send_q, (void *)message);
|
ks_q_push(dht->send_q, (void *)message);
|
||||||
@ -751,8 +777,8 @@ KS_DECLARE(ks_status_t) ks_dht_send_findnode(ks_dht_t *dht, ks_dht_endpoint_t *e
|
|||||||
return KS_STATUS_FAIL;
|
return KS_STATUS_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ben_dict_set(a, ben_blob("id", 2), ben_blob(ep->nodeid, KS_DHT_NODEID_SIZE));
|
ben_dict_set(a, ben_blob("id", 2), ben_blob(ep->nodeid.id, KS_DHT_NODEID_SIZE));
|
||||||
ben_dict_set(a, ben_blob("target", 6), ben_blob(targetid, KS_DHT_NODEID_SIZE));
|
ben_dict_set(a, ben_blob("target", 6), ben_blob(targetid->id, KS_DHT_NODEID_SIZE));
|
||||||
|
|
||||||
ks_log(KS_LOG_DEBUG, "Sending message query find_node\n");
|
ks_log(KS_LOG_DEBUG, "Sending message query find_node\n");
|
||||||
ks_q_push(dht->send_q, (void *)message);
|
ks_q_push(dht->send_q, (void *)message);
|
||||||
@ -1032,7 +1058,7 @@ KS_DECLARE(ks_status_t) ks_dht_process_query_ping(ks_dht_t *dht, ks_dht_message_
|
|||||||
// goto done;
|
// goto done;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
ben_dict_set(r, ben_blob("id", 2), ben_blob(message->endpoint->nodeid, KS_DHT_NODEID_SIZE));
|
ben_dict_set(r, ben_blob("id", 2), ben_blob(message->endpoint->nodeid.id, KS_DHT_NODEID_SIZE));
|
||||||
|
|
||||||
ks_log(KS_LOG_DEBUG, "Sending message response ping\n");
|
ks_log(KS_LOG_DEBUG, "Sending message response ping\n");
|
||||||
ks_q_push(dht->send_q, (void *)response);
|
ks_q_push(dht->send_q, (void *)response);
|
||||||
@ -1144,7 +1170,7 @@ KS_DECLARE(ks_status_t) ks_dht_process_query_findnode(ks_dht_t *dht, ks_dht_mess
|
|||||||
// goto done;
|
// goto done;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
ben_dict_set(r, ben_blob("id", 2), ben_blob(message->endpoint->nodeid, KS_DHT_NODEID_SIZE));
|
ben_dict_set(r, ben_blob("id", 2), ben_blob(message->endpoint->nodeid.id, KS_DHT_NODEID_SIZE));
|
||||||
// @todo populate nodes/nodes6
|
// @todo populate nodes/nodes6
|
||||||
ben_dict_set(r, ben_blob("nodes", 5), ben_blob(buffer, buffer_length));
|
ben_dict_set(r, ben_blob("nodes", 5), ben_blob(buffer, buffer_length));
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "ks.h"
|
#include "ks.h"
|
||||||
#include "ks_bencode.h"
|
#include "ks_bencode.h"
|
||||||
|
#include "ks_dht_bucket.h"
|
||||||
|
|
||||||
KS_BEGIN_EXTERN_C
|
KS_BEGIN_EXTERN_C
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ KS_BEGIN_EXTERN_C
|
|||||||
#define KS_DHT_TRANSACTION_EXPIRATION_DELAY 30
|
#define KS_DHT_TRANSACTION_EXPIRATION_DELAY 30
|
||||||
|
|
||||||
typedef struct ks_dht_s ks_dht_t;
|
typedef struct ks_dht_s ks_dht_t;
|
||||||
typedef uint8_t ks_dht_nodeid_t[KS_DHT_NODEID_SIZE];
|
typedef struct ks_dht_nodeid_s ks_dht_nodeid_t;
|
||||||
typedef struct ks_dht_message_s ks_dht_message_t;
|
typedef struct ks_dht_message_s ks_dht_message_t;
|
||||||
typedef struct ks_dht_endpoint_s ks_dht_endpoint_t;
|
typedef struct ks_dht_endpoint_s ks_dht_endpoint_t;
|
||||||
typedef struct ks_dht_transaction_s ks_dht_transaction_t;
|
typedef struct ks_dht_transaction_s ks_dht_transaction_t;
|
||||||
@ -29,6 +29,12 @@ typedef struct ks_dht_transaction_s ks_dht_transaction_t;
|
|||||||
|
|
||||||
typedef ks_status_t (*ks_dht_message_callback_t)(ks_dht_t *dht, ks_dht_message_t *message);
|
typedef ks_status_t (*ks_dht_message_callback_t)(ks_dht_t *dht, ks_dht_message_t *message);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Note: This must remain a structure for casting from raw data
|
||||||
|
*/
|
||||||
|
struct ks_dht_nodeid_s {
|
||||||
|
uint8_t id[KS_DHT_NODEID_SIZE];
|
||||||
|
};
|
||||||
|
|
||||||
struct ks_dht_message_s {
|
struct ks_dht_message_s {
|
||||||
ks_pool_t *pool;
|
ks_pool_t *pool;
|
||||||
@ -82,8 +88,11 @@ struct ks_dht_s {
|
|||||||
uint8_t recv_buffer[KS_DHT_RECV_BUFFER_SIZE];
|
uint8_t recv_buffer[KS_DHT_RECV_BUFFER_SIZE];
|
||||||
ks_size_t recv_buffer_length;
|
ks_size_t recv_buffer_length;
|
||||||
|
|
||||||
uint32_t transactionid_next;
|
volatile uint32_t transactionid_next;
|
||||||
ks_hash_t *transactions_hash;
|
ks_hash_t *transactions_hash;
|
||||||
|
|
||||||
|
ks_dhtrt_routetable *rt_ipv4;
|
||||||
|
ks_dhtrt_routetable *rt_ipv6;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -139,7 +148,7 @@ KS_DECLARE(ks_status_t) ks_dht_message_error(ks_dht_message_t *message,
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
KS_DECLARE(ks_status_t) ks_dht_transaction_alloc(ks_dht_transaction_t **transaction, ks_pool_t *pool);
|
KS_DECLARE(ks_status_t) ks_dht_transaction_alloc(ks_dht_transaction_t **transaction, ks_pool_t *pool);
|
||||||
KS_DECLARE(ks_status_t) ks_dht_transaction_prealloc(ks_dht_transaction_t *trasnaction, ks_pool_t *pool);
|
KS_DECLARE(ks_status_t) ks_dht_transaction_prealloc(ks_dht_transaction_t *transaction, ks_pool_t *pool);
|
||||||
KS_DECLARE(ks_status_t) ks_dht_transaction_free(ks_dht_transaction_t *transaction);
|
KS_DECLARE(ks_status_t) ks_dht_transaction_free(ks_dht_transaction_t *transaction);
|
||||||
|
|
||||||
KS_DECLARE(ks_status_t) ks_dht_transaction_init(ks_dht_transaction_t *transaction,
|
KS_DECLARE(ks_status_t) ks_dht_transaction_init(ks_dht_transaction_t *transaction,
|
||||||
|
@ -58,9 +58,9 @@ KS_DECLARE(ks_status_t) ks_dht_endpoint_init(ks_dht_endpoint_t *endpoint, const
|
|||||||
ks_assert(addr->family == AF_INET || addr->family == AF_INET6);
|
ks_assert(addr->family == AF_INET || addr->family == AF_INET6);
|
||||||
|
|
||||||
if (!nodeid) {
|
if (!nodeid) {
|
||||||
randombytes_buf(endpoint->nodeid, KS_DHT_NODEID_SIZE);
|
randombytes_buf(endpoint->nodeid.id, KS_DHT_NODEID_SIZE);
|
||||||
} else {
|
} else {
|
||||||
memcpy(endpoint->nodeid, nodeid, KS_DHT_NODEID_SIZE);
|
memcpy(endpoint->nodeid.id, nodeid->id, KS_DHT_NODEID_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoint->addr = *addr;
|
endpoint->addr = *addr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user