aboutsummaryrefslogtreecommitdiff
path: root/src/util/gnunet-service-resolver.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-10-08 19:00:19 +0000
committerChristian Grothoff <christian@grothoff.org>2009-10-08 19:00:19 +0000
commitfe947a9704bed14c2fc74b2f2069596fe884cbad (patch)
tree644efdaa37d692b09f8e279bfe5e8b2ebe81448b /src/util/gnunet-service-resolver.c
parenta8b0ab037820f6a9f405be3855ce8d3ebbd4399b (diff)
downloadgnunet-fe947a9704bed14c2fc74b2f2069596fe884cbad.tar.gz
gnunet-fe947a9704bed14c2fc74b2f2069596fe884cbad.zip
better comments
Diffstat (limited to 'src/util/gnunet-service-resolver.c')
-rw-r--r--src/util/gnunet-service-resolver.c60
1 files changed, 51 insertions, 9 deletions
diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c
index 304f11b7b..1dce5cedc 100644
--- a/src/util/gnunet-service-resolver.c
+++ b/src/util/gnunet-service-resolver.c
@@ -19,7 +19,7 @@
19*/ 19*/
20 20
21/** 21/**
22 * @file resolver/gnunet-service-resolver.c 22 * @file util/gnunet-service-resolver.c
23 * @brief code to do DNS resolution 23 * @brief code to do DNS resolution
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
@@ -35,24 +35,55 @@
35#include "gnunet_time_lib.h" 35#include "gnunet_time_lib.h"
36#include "resolver.h" 36#include "resolver.h"
37 37
38 38/**
39 * A cached DNS lookup result.
40 */
39struct IPCache 41struct IPCache
40{ 42{
43 /**
44 * This is a linked list.
45 */
41 struct IPCache *next; 46 struct IPCache *next;
47
48 /**
49 * Hostname in human-readable form.
50 */
42 char *addr; 51 char *addr;
52
53 /**
54 * Hostname in binary format.
55 */
43 struct sockaddr *sa; 56 struct sockaddr *sa;
57
58 /**
59 * Last time this entry was updated.
60 */
44 struct GNUNET_TIME_Absolute last_refresh; 61 struct GNUNET_TIME_Absolute last_refresh;
62
63 /**
64 * Last time this entry was requested.
65 */
45 struct GNUNET_TIME_Absolute last_request; 66 struct GNUNET_TIME_Absolute last_request;
46 unsigned int salen; 67
68 /**
69 * Number of bytes in sa.
70 */
71 socklen_t salen;
47}; 72};
48 73
49 74
75/**
76 * Start of the linked list of cached DNS lookup results.
77 */
50static struct IPCache *head; 78static struct IPCache *head;
51 79
52 80
53
54
55#if HAVE_GETNAMEINFO 81#if HAVE_GETNAMEINFO
82/**
83 * Resolve the given request using getnameinfo
84 *
85 * @param cache the request to resolve (and where to store the result)
86 */
56static void 87static void
57getnameinfo_resolve (struct IPCache *cache) 88getnameinfo_resolve (struct IPCache *cache)
58{ 89{
@@ -69,6 +100,11 @@ getnameinfo_resolve (struct IPCache *cache)
69 100
70 101
71#if HAVE_GETHOSTBYADDR 102#if HAVE_GETHOSTBYADDR
103/**
104 * Resolve the given request using gethostbyaddr
105 *
106 * @param cache the request to resolve (and where to store the result)
107 */
72static void 108static void
73gethostbyaddr_resolve (struct IPCache *cache) 109gethostbyaddr_resolve (struct IPCache *cache)
74{ 110{
@@ -92,7 +128,11 @@ gethostbyaddr_resolve (struct IPCache *cache)
92} 128}
93#endif 129#endif
94 130
95 131/**
132 * Resolve the given request using the available methods.
133 *
134 * @param cache the request to resolve (and where to store the result)
135 */
96static void 136static void
97cache_resolve (struct IPCache *cache) 137cache_resolve (struct IPCache *cache)
98{ 138{
@@ -114,11 +154,13 @@ cache_resolve (struct IPCache *cache)
114 * may not immediately result in the FQN (but instead in a 154 * may not immediately result in the FQN (but instead in a
115 * human-readable IP address). 155 * human-readable IP address).
116 * 156 *
157 * @param client handle to the client making the request (for sending the reply)
117 * @param sa should be of type "struct sockaddr*" 158 * @param sa should be of type "struct sockaddr*"
159 * @param salen number of bytes in sa
118 */ 160 */
119static void 161static void
120get_ip_as_string (struct GNUNET_SERVER_Client *client, 162get_ip_as_string (struct GNUNET_SERVER_Client *client,
121 const struct sockaddr *sav, socklen_t salen) 163 const struct sockaddr *sa, socklen_t salen)
122{ 164{
123 struct IPCache *cache; 165 struct IPCache *cache;
124 struct IPCache *prev; 166 struct IPCache *prev;
@@ -134,7 +176,7 @@ get_ip_as_string (struct GNUNET_SERVER_Client *client,
134 cache = head; 176 cache = head;
135 prev = NULL; 177 prev = NULL;
136 while ((cache != NULL) && 178 while ((cache != NULL) &&
137 ((cache->salen != salen) || (0 != memcmp (cache->sa, sav, salen)))) 179 ((cache->salen != salen) || (0 != memcmp (cache->sa, sa, salen))))
138 { 180 {
139 if (GNUNET_TIME_absolute_get_duration (cache->last_request).value < 181 if (GNUNET_TIME_absolute_get_duration (cache->last_request).value <
140 60 * 60 * 1000) 182 60 * 60 * 1000)
@@ -178,7 +220,7 @@ get_ip_as_string (struct GNUNET_SERVER_Client *client,
178 cache->next = head; 220 cache->next = head;
179 cache->salen = salen; 221 cache->salen = salen;
180 cache->sa = GNUNET_malloc (salen); 222 cache->sa = GNUNET_malloc (salen);
181 memcpy (cache->sa, sav, salen); 223 memcpy (cache->sa, sa, salen);
182 cache->last_request = GNUNET_TIME_absolute_get (); 224 cache->last_request = GNUNET_TIME_absolute_get ();
183 cache->last_refresh = GNUNET_TIME_absolute_get (); 225 cache->last_refresh = GNUNET_TIME_absolute_get ();
184 cache->addr = NULL; 226 cache->addr = NULL;