From 8739f7fccb7cafc54ca0f5fa074c9a740f7048ba Mon Sep 17 00:00:00 2001 From: iphydf Date: Thu, 5 Jul 2018 10:31:29 +0000 Subject: Make tox.c unambiguously parseable. Rules: 1. Constants are uppercase names: THE_CONSTANT. 2. SUE[1] types start with an uppercase letter and have at least one lowercase letter in it: The_Type, THE_Type. 3. Function types end in "_cb": tox_friend_connection_cb. 4. Variable and function names are all lowercase: the_function. This makes it easier for humans reading the code to determine what an identifier means. I'm not convinced by the enum type name change, but I don't know a better rule. Currently, a lot of enum types are spelled like constants, which is confusing. [1] struct/union/enum --- testing/DHT_test.c | 12 ++++++------ testing/Messenger_test.c | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'testing') diff --git a/testing/DHT_test.c b/testing/DHT_test.c index 59856395..336e7e18 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c @@ -128,7 +128,7 @@ static void print_friendlist(DHT *dht) print_client_id(dht_get_friend_public_key(dht, k)); - int friendok = DHT_getfriendip(dht, dht_get_friend_public_key(dht, k), &p_ip); + int friendok = dht_getfriendip(dht, dht_get_friend_public_key(dht, k), &p_ip); char ip_str[IP_NTOA_LEN]; printf("\nIP: %s:%u (%d)", ip_ntoa(&p_ip.ip, ip_str, sizeof(ip_str)), net_ntohs(p_ip.port), friendok); @@ -190,7 +190,7 @@ int main(int argc, char *argv[]) IP ip; ip_init(&ip, ipv6enabled); - DHT *dht = new_DHT(nullptr, new_networking(nullptr, ip, PORT), true); + DHT *dht = new_dht(nullptr, new_networking(nullptr, ip, PORT), true); printf("OUR ID: "); uint32_t i; @@ -216,14 +216,14 @@ int main(int argc, char *argv[]) } uint8_t *bin_id = hex_string_to_bin(temp_id); - DHT_addfriend(dht, bin_id, 0, 0, 0, 0); + dht_addfriend(dht, bin_id, 0, 0, 0, 0); free(bin_id); perror("Initialization"); uint16_t port = net_htons(atoi(argv[argvoffset + 2])); unsigned char *binary_string = hex_string_to_bin(argv[argvoffset + 3]); - int res = DHT_bootstrap_from_address(dht, argv[argvoffset + 1], ipv6enabled, port, binary_string); + int res = dht_bootstrap_from_address(dht, argv[argvoffset + 1], ipv6enabled, port, binary_string); free(binary_string); if (!res) { @@ -238,12 +238,12 @@ int main(int argc, char *argv[]) #endif while (1) { - do_DHT(dht); + do_dht(dht); #if 0 /* TODO(slvr): */ while (receivepacket(&ip_port, data, &length) != -1) { - if (DHT_handlepacket(data, length, ip_port) && friendreq_handlepacket(data, length, ip_port)) { + if (dht_handlepacket(data, length, ip_port) && friendreq_handlepacket(data, length, ip_port)) { //unhandled packet printpacket(data, length, ip_port); } else { diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c index ebc1975a..7885779b 100644 --- a/testing/Messenger_test.c +++ b/testing/Messenger_test.c @@ -121,7 +121,7 @@ int main(int argc, char *argv[]) if (argc == argvoffset + 4) { uint16_t port = net_htons(atoi(argv[argvoffset + 2])); uint8_t *bootstrap_key = hex_string_to_bin(argv[argvoffset + 3]); - int res = DHT_bootstrap_from_address(m->dht, argv[argvoffset + 1], + int res = dht_bootstrap_from_address(m->dht, argv[argvoffset + 1], ipv6enabled, port, bootstrap_key); free(bootstrap_key); -- cgit v1.2.3