mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-13 15:50:59 +00:00
FS-9775: Fixed some bugs, unit test now successfully sends, processes, responds, and receives and validates a ping, more on this soon
This commit is contained in:
parent
e4176f5873
commit
f95ca83b06
@ -90,7 +90,7 @@ KS_DECLARE(ks_status_t) ks_dht2_init(ks_dht2_t *dht, const ks_dht2_nodeid_raw_t
|
||||
|
||||
dht->recv_buffer_length = 0;
|
||||
|
||||
dht->transactionid_next = rand() % 0xFFFF;
|
||||
dht->transactionid_next = 1; //rand();
|
||||
ks_hash_create(&dht->transactions_hash, KS_HASH_MODE_INT, KS_HASH_FLAG_RWLOCK, dht->pool);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
@ -471,8 +471,8 @@ KS_DECLARE(ks_status_t) ks_dht2_process_response(ks_dht2_t *dht, ks_sockaddr_t *
|
||||
{
|
||||
struct bencode *r;
|
||||
ks_dht2_transaction_t *transaction;
|
||||
uint32_t *tid;
|
||||
uint32_t transactionid;
|
||||
uint16_t *tid;
|
||||
ks_status_t ret = KS_STATUS_FAIL;
|
||||
|
||||
ks_assert(dht);
|
||||
@ -489,8 +489,8 @@ KS_DECLARE(ks_status_t) ks_dht2_process_response(ks_dht2_t *dht, ks_sockaddr_t *
|
||||
|
||||
message->args = r;
|
||||
|
||||
tid = (uint16_t *)message->transactionid;
|
||||
transactionid = ntohs(*tid);
|
||||
tid = (uint32_t *)message->transactionid;
|
||||
transactionid = ntohl(*tid);
|
||||
|
||||
transaction = ks_hash_search(dht->transactions_hash, (void *)&transactionid, KS_READLOCKED);
|
||||
ks_hash_read_unlock(dht->transactions_hash);
|
||||
@ -541,7 +541,6 @@ KS_DECLARE(ks_status_t) ks_dht2_process_query_ping(ks_dht2_t *dht, ks_sockaddr_t
|
||||
return KS_STATUS_FAIL;
|
||||
}
|
||||
|
||||
//ks_log(KS_LOG_DEBUG, "Message query ping id is '%s'\n", id->id);
|
||||
ks_log(KS_LOG_DEBUG, "Message query ping is valid\n");
|
||||
|
||||
ret = ks_dht2_send_response_ping(dht, raddr, message->transactionid, message->transactionid_length);
|
||||
@ -560,6 +559,8 @@ KS_DECLARE(ks_status_t) ks_dht2_process_response_ping(ks_dht2_t *dht, ks_sockadd
|
||||
ks_assert(raddr);
|
||||
ks_assert(message);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Message response ping is reached\n");
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -600,15 +601,14 @@ KS_DECLARE(ks_status_t) ks_dht2_send_query_ping(ks_dht2_t *dht, ks_sockaddr_t *r
|
||||
goto done;
|
||||
}
|
||||
|
||||
// @todo transaction expiration and raddr
|
||||
|
||||
// @todo transactions_hash mutex?
|
||||
ks_hash_insert(dht->transactions_hash, (void *)&transactionid, transaction);
|
||||
|
||||
// @todo transaction expiration and raddr for validation
|
||||
|
||||
ks_hash_insert(dht->transactions_hash, (void *)&transaction->transactionid, transaction);
|
||||
|
||||
// @note a joins response.data and will be freed with it
|
||||
ben_dict_set(a, ben_blob("id", 2), ben_blob(dht->nodeid.id, KS_DHT_NODEID_LENGTH));
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Sending message query ping\n");
|
||||
ks_log(KS_LOG_DEBUG, "Sending message query ping with transaction id %d\n", transactionid);
|
||||
ret = ks_dht2_send(dht, raddr, &query);
|
||||
|
||||
done:
|
||||
|
@ -54,7 +54,7 @@ struct ks_dht2_endpoint_s {
|
||||
|
||||
struct ks_dht2_transaction_s {
|
||||
ks_pool_t *pool;
|
||||
uint16_t transactionid;
|
||||
uint32_t transactionid;
|
||||
ks_dht2_message_callback_t callback;
|
||||
// @todo expiration data
|
||||
};
|
||||
@ -83,7 +83,7 @@ struct ks_dht2_s {
|
||||
uint8_t recv_buffer[KS_DHT_RECV_BUFFER_SIZE];
|
||||
ks_size_t recv_buffer_length;
|
||||
|
||||
uint16_t transactionid_next;
|
||||
uint32_t transactionid_next;
|
||||
ks_hash_t *transactions_hash;
|
||||
};
|
||||
|
||||
@ -130,7 +130,7 @@ KS_DECLARE(ks_status_t) ks_dht2_message_deinit(ks_dht2_message_t *message);
|
||||
KS_DECLARE(ks_status_t) ks_dht2_message_parse(ks_dht2_message_t *message, const uint8_t *buffer, ks_size_t buffer_length);
|
||||
|
||||
KS_DECLARE(ks_status_t) ks_dht2_message_query(ks_dht2_message_t *message,
|
||||
uint16_t transactionid,
|
||||
uint32_t transactionid,
|
||||
const char *query,
|
||||
struct bencode **args);
|
||||
KS_DECLARE(ks_status_t) ks_dht2_message_response(ks_dht2_message_t *message,
|
||||
@ -150,7 +150,7 @@ KS_DECLARE(ks_status_t) ks_dht2_transaction_prealloc(ks_dht2_transaction_t *tras
|
||||
KS_DECLARE(ks_status_t) ks_dht2_transaction_free(ks_dht2_transaction_t *transaction);
|
||||
|
||||
KS_DECLARE(ks_status_t) ks_dht2_transaction_init(ks_dht2_transaction_t *transaction,
|
||||
uint16_t transactionid,
|
||||
uint32_t transactionid,
|
||||
ks_dht2_message_callback_t callback);
|
||||
KS_DECLARE(ks_status_t) ks_dht2_transaction_deinit(ks_dht2_transaction_t *transaction);
|
||||
|
||||
|
@ -153,19 +153,19 @@ KS_DECLARE(ks_status_t) ks_dht2_message_parse(ks_dht2_message_t *message, const
|
||||
*
|
||||
*/
|
||||
KS_DECLARE(ks_status_t) ks_dht2_message_query(ks_dht2_message_t *message,
|
||||
uint16_t transactionid,
|
||||
uint32_t transactionid,
|
||||
const char *query,
|
||||
struct bencode **args)
|
||||
{
|
||||
struct bencode *a;
|
||||
uint16_t tid;
|
||||
|
||||
uint32_t tid;
|
||||
|
||||
ks_assert(message);
|
||||
ks_assert(query);
|
||||
|
||||
tid = htons(transactionid);
|
||||
tid = htonl(transactionid);
|
||||
|
||||
ben_dict_set(message->data, ben_blob("t", 1), ben_blob((uint8_t *)&tid, 2));
|
||||
ben_dict_set(message->data, ben_blob("t", 1), ben_blob((uint8_t *)&tid, sizeof(uint32_t)));
|
||||
ben_dict_set(message->data, ben_blob("y", 1), ben_blob("q", 1));
|
||||
ben_dict_set(message->data, ben_blob("q", 1), ben_blob(query, strlen(query)));
|
||||
|
||||
|
@ -48,7 +48,7 @@ KS_DECLARE(ks_status_t) ks_dht2_transaction_free(ks_dht2_transaction_t *transact
|
||||
*
|
||||
*/
|
||||
KS_DECLARE(ks_status_t) ks_dht2_transaction_init(ks_dht2_transaction_t *transaction,
|
||||
uint16_t transactionid,
|
||||
uint32_t transactionid,
|
||||
ks_dht2_message_callback_t callback)
|
||||
{
|
||||
ks_assert(transaction);
|
||||
|
@ -98,16 +98,22 @@ int main() {
|
||||
ok(err == KS_STATUS_SUCCESS);
|
||||
|
||||
|
||||
buflen = strlen(TEST_DHT1_PROCESS_QUERY_PING_BUFFER);
|
||||
memcpy(dht1->recv_buffer, TEST_DHT1_PROCESS_QUERY_PING_BUFFER, buflen);
|
||||
dht1->recv_buffer_length = buflen;
|
||||
//buflen = strlen(TEST_DHT1_PROCESS_QUERY_PING_BUFFER);
|
||||
//memcpy(dht1->recv_buffer, TEST_DHT1_PROCESS_QUERY_PING_BUFFER, buflen);
|
||||
//dht1->recv_buffer_length = buflen;
|
||||
|
||||
err = ks_dht2_process(dht1, &raddr);
|
||||
//err = ks_dht2_process(dht1, &raddr);
|
||||
//ok(err == KS_STATUS_SUCCESS);
|
||||
|
||||
err = ks_dht2_send_query_ping(dht1, &raddr);
|
||||
ok(err == KS_STATUS_SUCCESS);
|
||||
|
||||
err = ks_dht2_pulse(&dht2, 1000);
|
||||
ok(err == KS_STATUS_SUCCESS);
|
||||
|
||||
err = ks_dht2_pulse(dht1, 1000);
|
||||
ok(err == KS_STATUS_SUCCESS);
|
||||
|
||||
diag("Cleanup\n");
|
||||
/* Cleanup and shutdown */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user