mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-11-13 04:57:05 +00:00
FS-9775: Bug fixes and exposed interface changes while implementing tests for get/put which are functional and pass initial tests now. Deep searching needs to be revamped now to complete the full announcing process.
This commit is contained in:
1 parent
4970c7e9a6
commit
5dfd6d1b8f
8 files changed
+860
-288
No files matched your search
+125
-49
@@ -3,14 +3,32 @@
|
||||
#include <../dht/ks_dht-int.h>
|
||||
#include <tap.h>
|
||||
|
||||
#define TEST_DHT1_REGISTER_TYPE_BUFFER "d1:ad2:id20:12345678901234567890e1:q4:ping1:t2:421:y1:ze"
|
||||
#define TEST_DHT1_PROCESS_QUERY_PING_BUFFER "d1:ad2:id20:12345678901234567890e1:q4:ping1:t2:421:y1:qe"
|
||||
ks_dht_storageitem_skey_t sk;
|
||||
ks_dht_storageitem_pkey_t pk;
|
||||
|
||||
ks_status_t dht_z_callback(ks_dht_t *dht, ks_dht_message_t *message)
|
||||
ks_status_t dht2_put_callback(ks_dht_t *dht, ks_dht_job_t *job)
|
||||
{
|
||||
diag("dht_z_callback\n");
|
||||
ok(message->transactionid[0] == '4' && message->transactionid[1] == '2');
|
||||
ks_dht_error(dht, message->endpoint, &message->raddr, message->transactionid, message->transactionid_length, 201, "Generic test error");
|
||||
diag("dht2_put_callback\n");
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
ks_status_t dht2_get_token_callback(ks_dht_t *dht, ks_dht_job_t *job)
|
||||
{
|
||||
char buf[KS_DHT_TOKEN_SIZE * 2 + 1];
|
||||
const char *v = "Hello World!";
|
||||
size_t v_len = strlen(v);
|
||||
ks_dht_storageitem_signature_t sig;
|
||||
ks_dht_storageitem_t *mutable = NULL;
|
||||
|
||||
diag("dht2_get_token_callback %s\n", ks_dht_hex(job->response_token.token, buf, KS_DHT_TOKEN_SIZE));
|
||||
|
||||
ks_dht_storageitem_signature_generate(&sig, &sk, NULL, 0, 1, (uint8_t *)v, v_len);
|
||||
// @todo check if exists
|
||||
ks_dht_storageitem_create_mutable(&mutable, dht->pool, &job->query_target, (uint8_t *)v, v_len, &pk, NULL, 0, 1, &sig);
|
||||
mutable->sk = sk;
|
||||
ks_dht_storageitems_insert(dht, mutable);
|
||||
|
||||
ks_dht_put(dht, &job->raddr, dht2_put_callback, &job->response_token, 0, mutable);
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -30,6 +48,27 @@ int main() {
|
||||
ks_sockaddr_t raddr1;
|
||||
//ks_sockaddr_t raddr2;
|
||||
//ks_sockaddr_t raddr3;
|
||||
ks_dht_nodeid_t target;
|
||||
//ks_dht_storageitem_t *immutable = NULL;
|
||||
//ks_dht_storageitem_t *mutable = NULL;
|
||||
//const char *v = "Hello World!";
|
||||
//size_t v_len = strlen(v);
|
||||
//ks_dht_storageitem_skey_t sk; //= { { 0xe0, 0x6d, 0x31, 0x83, 0xd1, 0x41, 0x59, 0x22, 0x84, 0x33, 0xed, 0x59, 0x92, 0x21, 0xb8, 0x0b,
|
||||
//0xd0, 0xa5, 0xce, 0x83, 0x52, 0xe4, 0xbd, 0xf0, 0x26, 0x2f, 0x76, 0x78, 0x6e, 0xf1, 0xc7, 0x4d,
|
||||
//0xb7, 0xe7, 0xa9, 0xfe, 0xa2, 0xc0, 0xeb, 0x26, 0x9d, 0x61, 0xe3, 0xb3, 0x8e, 0x45, 0x0a, 0x22,
|
||||
//0xe7, 0x54, 0x94, 0x1a, 0xc7, 0x84, 0x79, 0xd6, 0xc5, 0x4e, 0x1f, 0xaf, 0x60, 0x37, 0x88, 0x1d } };
|
||||
//ks_dht_storageitem_pkey_t pk; //= { { 0x77, 0xff, 0x84, 0x90, 0x5a, 0x91, 0x93, 0x63, 0x67, 0xc0, 0x13, 0x60, 0x80, 0x31, 0x04, 0xf9,
|
||||
//0x24, 0x32, 0xfc, 0xd9, 0x04, 0xa4, 0x35, 0x11, 0x87, 0x6d, 0xf5, 0xcd, 0xf3, 0xe7, 0xe5, 0x48 } };
|
||||
//uint8_t sk1[KS_DHT_STORAGEITEM_SKEY_SIZE];
|
||||
//uint8_t pk1[KS_DHT_STORAGEITEM_PKEY_SIZE];
|
||||
//ks_dht_storageitem_signature_t sig;
|
||||
//char sk_buf[KS_DHT_STORAGEITEM_SKEY_SIZE * 2 + 1];
|
||||
//char pk_buf[KS_DHT_STORAGEITEM_PKEY_SIZE * 2 + 1];
|
||||
//const char *test1vector = "3:seqi1e1:v12:Hello World!";
|
||||
//const char *test1vector = "4:salt6:foobar3:seqi1e1:v12:Hello World!";
|
||||
//size_t test1vector_len = strlen(test1vector);
|
||||
//uint8_t test1vector_sig[KS_DHT_STORAGEITEM_SIGNATURE_SIZE];
|
||||
//char test1vector_buf[KS_DHT_STORAGEITEM_SIGNATURE_SIZE * 2 + 1];
|
||||
|
||||
err = ks_init();
|
||||
ok(!err);
|
||||
@@ -62,9 +101,6 @@ int main() {
|
||||
err = ks_dht_create(&dht3, NULL, NULL);
|
||||
ok(err == KS_STATUS_SUCCESS);
|
||||
|
||||
|
||||
ks_dht_register_type(dht1, "z", dht_z_callback);
|
||||
|
||||
if (have_v4) {
|
||||
err = ks_addr_set(&addr, v4, KS_DHT_DEFAULT_PORT, AF_INET);
|
||||
ok(err == KS_STATUS_SUCCESS);
|
||||
@@ -111,30 +147,9 @@ int main() {
|
||||
ok(err == KS_STATUS_SUCCESS);
|
||||
}
|
||||
|
||||
//diag("Custom type tests\n");
|
||||
|
||||
//buflen = strlen(TEST_DHT1_REGISTER_TYPE_BUFFER);
|
||||
//memcpy(dht1->recv_buffer, TEST_DHT1_REGISTER_TYPE_BUFFER, buflen);
|
||||
//dht1->recv_buffer_length = buflen;
|
||||
|
||||
//err = ks_dht_process(dht1, ep1, &raddr);
|
||||
//ok(err == KS_STATUS_SUCCESS);
|
||||
|
||||
//ks_dht_pulse(dht1, 100);
|
||||
|
||||
//ks_dht_pulse(&dht2, 100);
|
||||
|
||||
|
||||
//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_dht_process(dht1, &raddr);
|
||||
//ok(err == KS_STATUS_SUCCESS);
|
||||
|
||||
/*
|
||||
diag("Ping test\n");
|
||||
|
||||
//ks_dht_send_ping(dht2, ep2, &raddr1); // Queue bootstrap ping from dht2 to dht1
|
||||
ks_dht_ping(dht2, &raddr1, NULL); // (QUERYING)
|
||||
|
||||
ks_dht_pulse(dht2, 100); // Send queued ping from dht2 to dht1 (RESPONDING)
|
||||
@@ -147,7 +162,7 @@ int main() {
|
||||
|
||||
ok(ks_dhtrt_find_node(dht2->rt_ipv4, ep1->nodeid) != NULL); // The node should be good, and thus be returned as good
|
||||
|
||||
ks_dht_pulse(dht2, 100); // (COMPLETING)
|
||||
ks_dht_pulse(dht2, 100); // Call finish callback and purge the job (COMPLETING)
|
||||
|
||||
diag("Pulsing for route table pings\n"); // Wait for route table pinging to catch up
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
@@ -157,31 +172,92 @@ int main() {
|
||||
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
|
||||
*/
|
||||
|
||||
// Test bootstrap find_node from dht3 to dht1 to find dht2 nodeid
|
||||
|
||||
diag("Find_Node test\n");
|
||||
|
||||
ks_dht_findnode(dht3, &raddr1, NULL, &ep2->nodeid);
|
||||
|
||||
ks_dht_pulse(dht3, 100); // Send queued findnode from dht3 to dht1
|
||||
|
||||
ks_dht_pulse(dht1, 100); // Receive and process findnode query from dht3, queue and send findnode response
|
||||
|
||||
ok(ks_dhtrt_find_node(dht1->rt_ipv4, ep3->nodeid) == NULL); // The node should be dubious, and thus not be returned as good yet
|
||||
|
||||
ks_dht_pulse(dht3, 100); // Receive and process findnode response from dht1
|
||||
|
||||
ok(ks_dhtrt_find_node(dht3->rt_ipv4, ep2->nodeid) == NULL); // The node should be dubious, and thus not be returned as good yet
|
||||
//diag("Get test\n");
|
||||
|
||||
diag("Pulsing for route table pings\n"); // Wait for route table pinging to catch up
|
||||
|
||||
/*
|
||||
ks_dht_storageitem_target_immutable((uint8_t *)v, v_len, &target);
|
||||
ks_dht_storageitem_create_immutable(&immutable, dht1->pool, &target, (uint8_t *)v, v_len);
|
||||
ks_dht_storageitems_insert(dht1, immutable);
|
||||
*/
|
||||
|
||||
/*
|
||||
crypto_sign_keypair(pk.key, sk.key);
|
||||
|
||||
ks_dht_storageitem_signature_generate(&sig, &sk, NULL, 0, 1, (uint8_t *)v, v_len);
|
||||
ks_dht_storageitem_target_mutable(&pk, NULL, 0, &target);
|
||||
ks_dht_storageitem_create_mutable(&mutable, dht1->pool, &target, (uint8_t *)v, v_len, &pk, NULL, 0, 1, &sig);
|
||||
mutable->sk = sk;
|
||||
ks_dht_storageitems_insert(dht1, mutable);
|
||||
|
||||
ks_dht_get(dht2, &raddr1, dht2_get_callback, &target, NULL, 0);
|
||||
|
||||
ks_dht_pulse(dht2, 100); // send get query
|
||||
|
||||
ks_dht_pulse(dht1, 100); // receive get query and send get response
|
||||
|
||||
ks_dht_pulse(dht2, 100); // receive get response
|
||||
|
||||
ok(ks_dht_storageitems_find(dht2, &target) != NULL); // item should be verified and stored
|
||||
|
||||
ks_dht_pulse(dht2, 100); // Call finish callback and purge the job (COMPLETING)
|
||||
*/
|
||||
|
||||
diag("Put test\n");
|
||||
|
||||
crypto_sign_keypair(pk.key, sk.key);
|
||||
|
||||
ks_dht_storageitem_target_mutable(&pk, NULL, 0, &target);
|
||||
|
||||
ks_dht_get(dht2, &raddr1, dht2_get_token_callback, &target, NULL, 0); // create job
|
||||
|
||||
ks_dht_pulse(dht2, 100); // send get query
|
||||
|
||||
ks_dht_pulse(dht1, 100); // receive get query and send get response
|
||||
|
||||
ks_dht_pulse(dht2, 100); // receive get response
|
||||
|
||||
ks_dht_pulse(dht2, 100); // Call finish callback and purge the job (COMPLETING), send put query
|
||||
|
||||
ks_dht_pulse(dht1, 100); // receive put query and send put response
|
||||
|
||||
ks_dht_pulse(dht2, 100); // receive put response
|
||||
|
||||
ks_dht_pulse(dht2, 100); // Call finish callback and purse the job (COMPLETING)
|
||||
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
//diag("DHT 1\n");
|
||||
ks_dht_pulse(dht1, 100);
|
||||
//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
|
||||
|
||||
// Test bootstrap find_node from dht3 to dht1 to find dht2 nodeid
|
||||
|
||||
//diag("Find_Node test\n");
|
||||
|
||||
//ks_dht_findnode(dht3, &raddr1, NULL, &ep2->nodeid);
|
||||
|
||||
//ks_dht_pulse(dht3, 100); // Send queued findnode from dht3 to dht1
|
||||
|
||||
//ks_dht_pulse(dht1, 100); // Receive and process findnode query from dht3, queue and send findnode response
|
||||
|
||||
//ok(ks_dhtrt_find_node(dht1->rt_ipv4, ep3->nodeid) == NULL); // The node should be dubious, and thus not be returned as good yet
|
||||
|
||||
//ks_dht_pulse(dht3, 100); // Receive and process findnode response from dht1
|
||||
|
||||
//ok(ks_dhtrt_find_node(dht3->rt_ipv4, ep2->nodeid) == NULL); // The node should be dubious, and thus not be returned as good yet
|
||||
|
||||
//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");
|
||||
//ks_dht_pulse(dht1, 100);
|
||||
//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
|
||||
|
||||
|
||||
/* Cleanup and shutdown */
|
||||
|
||||
Reference in new issue
Block a user