From 38f176ca9c1f21fc11b3ccc6aa45bd2f47e2eab7 Mon Sep 17 00:00:00 2001 From: Jesper Jensen Date: Sat, 16 Oct 2021 23:43:07 +0200 Subject: Flush in main --- src/main.c | 3 ++- src/proto.c | 8 +++----- test/proto.c | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/main.c b/src/main.c index 3cffa29..20cd376 100644 --- a/src/main.c +++ b/src/main.c @@ -21,11 +21,12 @@ int main(int argc, char** argv) { struct dht dht; dht.self = (struct nodeid){.inner={0xebe9bbf1, 0x3cdba6b3, 0x993e0c87, 0x900d5e25}}; + routing_init(&dht.self); + struct message* message_cursor = outbuff; proto_begin(&dht, time(NULL), &message_cursor, outbuff+32); flush_messages(dht.sfd, outbuff, message_cursor); - char buff_storage[2049]; int rc = 0; while(rc == 0) { diff --git a/src/proto.c b/src/proto.c index 8f4f737..196b912 100644 --- a/src/proto.c +++ b/src/proto.c @@ -180,7 +180,7 @@ PROCESS_TIMEOUT(getclient_timeout) { size_t reqId = (typeof(dht->requestdata[0])*)((void*)cont - offsetof(typeof(dht->requestdata[0]), cont)) - dht->requestdata; if(cont->ping.attempt >= 2) { - dbg("Timing out request %d after %d attempts", reqId, cont->ping.attempt); + dbg("Timing out request %ld after %d attempts", reqId, cont->ping.attempt); if(cont->ping.is_new) return 0; @@ -190,7 +190,7 @@ PROCESS_TIMEOUT(getclient_timeout) { return 0; } - dbg("Retrying request %d", reqId); + dbg("Retrying request %ld", reqId); if(*msgbuff->messages >= msgbuff->messages_end) return PROTO_ENOREQ; @@ -356,7 +356,6 @@ enum commandType { }; void proto_begin(struct dht* dht, time_t now, struct message** output, const struct message* const output_end) { - routing_flush(); struct msgbuff msgbuff = { output, output_end, @@ -367,7 +366,6 @@ void proto_begin(struct dht* dht, time_t now, struct message** output, const str dht->reqalloc[i] = false; } - routing_init(&dht->self); dbgl_id(&dht->self); dht->sfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); @@ -646,7 +644,7 @@ int proto_run(struct dht* dht, char* buff, size_t recv_len, struct sockaddr_in* } } - dbg("%d/%d requests pending", allocated, MAX_INFLIGHT); + dbg("%ld/%ld requests pending", allocated, MAX_INFLIGHT); } { int filled; diff --git a/test/proto.c b/test/proto.c index 277f68c..4c9bc15 100644 --- a/test/proto.c +++ b/test/proto.c @@ -10,6 +10,8 @@ void test_begin_pings_bootstrap_node() { struct dht dht; dht.self = (struct nodeid){.inner={0x42424242, 0x42424242, 0x42424242, 0x42424242, 0x42424242}}; + routing_flush(); + routing_init(&dht.self); struct message* message_cursor = outbuff; proto_begin(&dht, time(NULL), &message_cursor, outbuff+10); @@ -28,6 +30,9 @@ void test_response_from_initial_probe() { struct dht dht; dht.self = (struct nodeid){.inner={0x42424242, 0x42424242, 0x42424242, 0x42424242, 0x42424242}}; + routing_flush(); + routing_init(&dht.self); + { struct message* message_cursor = outbuff; proto_begin(&dht, time(NULL), &message_cursor, outbuff+2); @@ -58,6 +63,8 @@ void test_reponse_from_wrong_ip() { struct dht dht; dht.self = (struct nodeid){.inner={0x42424242, 0x42424242, 0x42424242, 0x42424242, 0x42424242}}; + routing_flush(); + routing_init(&dht.self); { struct message* message_cursor = outbuff; proto_begin(&dht, time(NULL), &message_cursor, outbuff+2); @@ -90,6 +97,8 @@ void test_ping() { struct dht dht; dht.self = (struct nodeid){.inner={0x42424242, 0x42424242, 0x42424242, 0x42424242, 0x42424242}}; + routing_flush(); + routing_init(&dht.self); { struct message* message_cursor = outbuff; proto_begin(&dht, time(NULL), &message_cursor, outbuff+2); @@ -116,6 +125,8 @@ void test_unknown_method() { struct dht dht; dht.self = (struct nodeid){.inner={0x42424242, 0x42424242, 0x42424242, 0x42424242, 0x42424242}}; + routing_flush(); + routing_init(&dht.self); { struct message* message_cursor = outbuff; proto_begin(&dht, time(NULL), &message_cursor, outbuff+2); @@ -146,6 +157,8 @@ void test_note_times_out() { struct dht dht; dht.self = (struct nodeid){.inner={0x42424242, 0x42424242, 0x42424242, 0x42424242, 0x42424242}}; + routing_flush(); + routing_init(&dht.self); { struct message* message_cursor = outbuff; proto_begin(&dht, 0, &message_cursor, outbuff+2); @@ -176,6 +189,8 @@ void test_response_after_retry() { struct dht dht; dht.self = (struct nodeid){.inner={0x42424242, 0x42424242, 0x42424242, 0x42424242, 0x42424242}}; + routing_flush(); + routing_init(&dht.self); { struct message* message_cursor = outbuff; @@ -201,6 +216,8 @@ void test_remove_from_routing_after_3_retries() { struct dht dht; dht.self = (struct nodeid){.inner={0x42424242, 0x42424242, 0x42424242, 0x42424242, 0x42424242}}; + routing_flush(); + routing_init(&dht.self); struct nodeid other = (struct nodeid){.inner={0x61616161, 0x61616161, 0x61616161, 0x61616161, 0x61616161}}; { @@ -264,6 +281,8 @@ void test_ping_node_when_uncertain() { struct dht dht; dht.self = (struct nodeid){.inner={0x42424242, 0x42424242, 0x42424242, 0x42424242, 0x42424242}}; + routing_flush(); + routing_init(&dht.self); struct nodeid other = (struct nodeid){.inner={0x61616161, 0x61616161, 0x61616161, 0x61616161, 0x61616161}}; { @@ -320,6 +339,8 @@ void test_query_find_node() { struct dht dht; dht.self = (struct nodeid){.inner={0x42424242, 0x42424242, 0x42424242, 0x42424242, 0x42424242}}; + routing_flush(); + routing_init(&dht.self); struct nodeid other = (struct nodeid){.inner={0x61616161, 0x61616161, 0x61616161, 0x61616161, 0x61616161}}; { -- cgit v1.2.3