aboutsummaryrefslogtreecommitdiff
path: root/src/util/gnunet-service-resolver.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-06-11 10:00:22 +0000
committerChristian Grothoff <christian@grothoff.org>2014-06-11 10:00:22 +0000
commita542abe16a1fe410eafb6ec273f8d7106709e28e (patch)
treee0332ab732782189446168be95559289d5a4e663 /src/util/gnunet-service-resolver.c
parentebf90b0e0d92be6df926e1a2462176302c0d17bb (diff)
downloadgnunet-a542abe16a1fe410eafb6ec273f8d7106709e28e.tar.gz
gnunet-a542abe16a1fe410eafb6ec273f8d7106709e28e.zip
-indentation, doxygen
Diffstat (limited to 'src/util/gnunet-service-resolver.c')
-rw-r--r--src/util/gnunet-service-resolver.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c
index cade20738..96ed101f7 100644
--- a/src/util/gnunet-service-resolver.c
+++ b/src/util/gnunet-service-resolver.c
@@ -30,7 +30,7 @@
30#include "resolver.h" 30#include "resolver.h"
31 31
32/** 32/**
33 * A cached DNS lookup result. 33 * A cached DNS lookup result (for reverse lookup).
34 */ 34 */
35struct IPCache 35struct IPCache
36{ 36{
@@ -131,9 +131,13 @@ getnameinfo_resolve (struct IPCache *cache)
131 } 131 }
132 132
133 if (0 == 133 if (0 ==
134 getnameinfo (sa, salen, hostname, sizeof (hostname), NULL, 134 getnameinfo (sa, salen,
135 hostname, sizeof (hostname),
136 NULL,
135 0, 0)) 137 0, 0))
138 {
136 cache->addr = GNUNET_strdup (hostname); 139 cache->addr = GNUNET_strdup (hostname);
140 }
137} 141}
138#endif 142#endif
139 143
@@ -153,7 +157,9 @@ gethostbyaddr_resolve (struct IPCache *cache)
153 cache->ip_len, 157 cache->ip_len,
154 cache->af); 158 cache->af);
155 if (NULL != ent) 159 if (NULL != ent)
160 {
156 cache->addr = GNUNET_strdup (ent->h_name); 161 cache->addr = GNUNET_strdup (ent->h_name);
162 }
157} 163}
158#endif 164#endif
159 165
@@ -185,7 +191,7 @@ cache_resolve (struct IPCache *cache)
185 * 191 *
186 * @param client handle to the client making the request (for sending the reply) 192 * @param client handle to the client making the request (for sending the reply)
187 * @param af AF_INET or AF_INET6 193 * @param af AF_INET or AF_INET6
188 * @param ip 'struct in_addr' or 'struct in6_addr' 194 * @param ip `struct in_addr` or `struct in6_addr`
189 */ 195 */
190static void 196static void
191get_ip_as_string (struct GNUNET_SERVER_Client *client, 197get_ip_as_string (struct GNUNET_SERVER_Client *client,
@@ -197,6 +203,7 @@ get_ip_as_string (struct GNUNET_SERVER_Client *client,
197 struct GNUNET_TIME_Absolute now; 203 struct GNUNET_TIME_Absolute now;
198 struct GNUNET_SERVER_TransmitContext *tc; 204 struct GNUNET_SERVER_TransmitContext *tc;
199 size_t ip_len; 205 size_t ip_len;
206 struct in6_addr ix;
200 207
201 switch (af) 208 switch (af)
202 { 209 {
@@ -228,16 +235,17 @@ get_ip_as_string (struct GNUNET_SERVER_Client *client,
228 continue; 235 continue;
229 } 236 }
230 } 237 }
231 if (pos != NULL) 238 if (NULL != pos)
232 { 239 {
233 pos->last_request = now; 240 if (1 == inet_pton (af,
234 if (GNUNET_TIME_absolute_get_duration (pos->last_request).rel_value_us < 241 pos->ip,
235 60 * 60 * 1000 * 1000LL) 242 &ix))
236 { 243 {
237 GNUNET_free_non_null (pos->addr); 244 GNUNET_free_non_null (pos->addr);
238 pos->addr = NULL; 245 pos->addr = NULL;
239 cache_resolve (pos); 246 cache_resolve (pos);
240 } 247 }
248 pos->last_request = now;
241 } 249 }
242 else 250 else
243 { 251 {
@@ -254,7 +262,7 @@ get_ip_as_string (struct GNUNET_SERVER_Client *client,
254 cache_resolve (pos); 262 cache_resolve (pos);
255 } 263 }
256 tc = GNUNET_SERVER_transmit_context_create (client); 264 tc = GNUNET_SERVER_transmit_context_create (client);
257 if (pos->addr != NULL) 265 if (NULL != pos->addr)
258 GNUNET_SERVER_transmit_context_append_data (tc, pos->addr, 266 GNUNET_SERVER_transmit_context_append_data (tc, pos->addr,
259 strlen (pos->addr) + 1, 267 strlen (pos->addr) + 1,
260 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); 268 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
@@ -311,7 +319,7 @@ getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc,
311 return GNUNET_NO; /* other function may still succeed */ 319 return GNUNET_NO; /* other function may still succeed */
312 return GNUNET_SYSERR; 320 return GNUNET_SYSERR;
313 } 321 }
314 if (result == NULL) 322 if (NULL == result)
315 return GNUNET_SYSERR; 323 return GNUNET_SYSERR;
316 for (pos = result; pos != NULL; pos = pos->ai_next) 324 for (pos = result; pos != NULL; pos = pos->ai_next)
317 { 325 {
@@ -436,7 +444,8 @@ gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc,
436 * @param af AF_INET or AF_INET6; use AF_UNSPEC for "any" 444 * @param af AF_INET or AF_INET6; use AF_UNSPEC for "any"
437 */ 445 */
438static void 446static void
439get_ip_from_hostname (struct GNUNET_SERVER_Client *client, const char *hostname, 447get_ip_from_hostname (struct GNUNET_SERVER_Client *client,
448 const char *hostname,
440 int af) 449 int af)
441{ 450{
442 int ret; 451 int ret;
@@ -470,7 +479,8 @@ get_ip_from_hostname (struct GNUNET_SERVER_Client *client, const char *hostname,
470 * @param message the actual message 479 * @param message the actual message
471 */ 480 */
472static void 481static void
473handle_get (void *cls, struct GNUNET_SERVER_Client *client, 482handle_get (void *cls,
483 struct GNUNET_SERVER_Client *client,
474 const struct GNUNET_MessageHeader *message) 484 const struct GNUNET_MessageHeader *message)
475{ 485{
476 uint16_t msize; 486 uint16_t msize;
@@ -596,7 +606,8 @@ main (int argc, char *const *argv)
596/** 606/**
597 * MINIMIZE heap size (way below 128k) since this process doesn't need much. 607 * MINIMIZE heap size (way below 128k) since this process doesn't need much.
598 */ 608 */
599void __attribute__ ((constructor)) GNUNET_ARM_memory_init () 609void __attribute__ ((constructor))
610GNUNET_ARM_memory_init ()
600{ 611{
601 mallopt (M_TRIM_THRESHOLD, 4 * 1024); 612 mallopt (M_TRIM_THRESHOLD, 4 * 1024);
602 mallopt (M_TOP_PAD, 1 * 1024); 613 mallopt (M_TOP_PAD, 1 * 1024);