diff options
author | zugz <mbays+tox@sdf.org> | 2017-01-19 18:51:14 +0100 |
---|---|---|
committer | zugz <mbays+tox@sdf.org> | 2017-01-21 22:08:52 +0100 |
commit | b630121f2f659027e1c9f00cd97087ef34e95677 (patch) | |
tree | 7972d498fa05b0955c684c83b79bf12000cb7cf2 /testing/DHT_test.c | |
parent | f185834e9afe83a2bb06e015a3e41b4ac97b48c3 (diff) |
reduce thread-unsafe use of static variables
- rework ip_ntoa() to avoid use of static variables
- rework sort_client_list() to avoid use of static variables
- move static 'lastdump' into Messenger struct
- rework ID2String() to avoid use of static variables; rename to id_to_string()
- fetch_broadcast_info(): attempt to mitigate risks from concurrent execution
- current_time_monotonic(): attempt to mitigate risks from concurrent execution
- comment on non-thread-safety of unix_time_update
Diffstat (limited to 'testing/DHT_test.c')
-rw-r--r-- | testing/DHT_test.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/testing/DHT_test.c b/testing/DHT_test.c index 1fbe6def..c42dc053 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c | |||
@@ -87,16 +87,17 @@ static void print_hardening(Hardening *h) | |||
87 | static void print_assoc(IPPTsPng *assoc, uint8_t ours) | 87 | static void print_assoc(IPPTsPng *assoc, uint8_t ours) |
88 | { | 88 | { |
89 | IP_Port *ipp = &assoc->ip_port; | 89 | IP_Port *ipp = &assoc->ip_port; |
90 | printf("\nIP: %s Port: %u", ip_ntoa(&ipp->ip), ntohs(ipp->port)); | 90 | char ip_str[IP_NTOA_LEN]; |
91 | printf("\nIP: %s Port: %u", ip_ntoa(&ipp->ip, ip_str, sizeof(ip_str)), ntohs(ipp->port)); | ||
91 | printf("\nTimestamp: %llu", (long long unsigned int) assoc->timestamp); | 92 | printf("\nTimestamp: %llu", (long long unsigned int) assoc->timestamp); |
92 | printf("\nLast pinged: %llu\n", (long long unsigned int) assoc->last_pinged); | 93 | printf("\nLast pinged: %llu\n", (long long unsigned int) assoc->last_pinged); |
93 | 94 | ||
94 | ipp = &assoc->ret_ip_port; | 95 | ipp = &assoc->ret_ip_port; |
95 | 96 | ||
96 | if (ours) { | 97 | if (ours) { |
97 | printf("OUR IP: %s Port: %u\n", ip_ntoa(&ipp->ip), ntohs(ipp->port)); | 98 | printf("OUR IP: %s Port: %u\n", ip_ntoa(&ipp->ip, ip_str, sizeof(ip_str)), ntohs(ipp->port)); |
98 | } else { | 99 | } else { |
99 | printf("RET IP: %s Port: %u\n", ip_ntoa(&ipp->ip), ntohs(ipp->port)); | 100 | printf("RET IP: %s Port: %u\n", ip_ntoa(&ipp->ip, ip_str, sizeof(ip_str)), ntohs(ipp->port)); |
100 | } | 101 | } |
101 | 102 | ||
102 | printf("Timestamp: %llu\n", (long long unsigned int) assoc->ret_timestamp); | 103 | printf("Timestamp: %llu\n", (long long unsigned int) assoc->ret_timestamp); |
@@ -136,7 +137,8 @@ static void print_friendlist(DHT *dht) | |||
136 | print_client_id(dht->friends_list[k].public_key); | 137 | print_client_id(dht->friends_list[k].public_key); |
137 | 138 | ||
138 | int friendok = DHT_getfriendip(dht, dht->friends_list[k].public_key, &p_ip); | 139 | int friendok = DHT_getfriendip(dht, dht->friends_list[k].public_key, &p_ip); |
139 | printf("\nIP: %s:%u (%d)", ip_ntoa(&p_ip.ip), ntohs(p_ip.port), friendok); | 140 | char ip_str[IP_NTOA_LEN]; |
141 | printf("\nIP: %s:%u (%d)", ip_ntoa(&p_ip.ip, ip_str, sizeof(ip_str)), ntohs(p_ip.port), friendok); | ||
140 | 142 | ||
141 | printf("\nCLIENTS IN LIST:\n\n"); | 143 | printf("\nCLIENTS IN LIST:\n\n"); |
142 | 144 | ||