aboutsummaryrefslogtreecommitdiff
path: root/src/gns/gnunet-service-gns.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2012-02-21 10:12:23 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2012-02-21 10:12:23 +0000
commit06f1df5d97a16e0bffd67eb362a41fbb7b3eb3f2 (patch)
tree424402914189a99359357f8901bb6b7a57da702a /src/gns/gnunet-service-gns.c
parent5c41d90016ad0c48f8069932ecf40ded9af51399 (diff)
downloadgnunet-06f1df5d97a16e0bffd67eb362a41fbb7b3eb3f2.tar.gz
gnunet-06f1df5d97a16e0bffd67eb362a41fbb7b3eb3f2.zip
Better logging
modified ns stub
Diffstat (limited to 'src/gns/gnunet-service-gns.c')
-rw-r--r--src/gns/gnunet-service-gns.c79
1 files changed, 66 insertions, 13 deletions
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index c33ea5575..fd9b23fd5 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -63,6 +63,8 @@ struct GNUNET_GNS_PendingQuery
63 int num_records; 63 int num_records;
64 int num_authority_records; //FIXME are all of our replies auth? 64 int num_authority_records; //FIXME are all of our replies auth?
65 65
66 char *name;
67 uint16_t type;
66 /* the dns request id */ 68 /* the dns request id */
67 int id; // FIXME can handle->request_id also be used here? 69 int id; // FIXME can handle->request_id also be used here?
68 70
@@ -140,19 +142,22 @@ reply_to_dns(struct GNUNET_GNS_PendingQuery *answer)
140 j = 0; 142 j = 0;
141 for (i=answer->records_head; i != NULL; i=i->next) 143 for (i=answer->records_head; i != NULL; i=i->next)
142 { 144 {
145 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
146 "Adding %s to DNS response\n", i->record->name);
143 memcpy(&packet->answers[j], 147 memcpy(&packet->answers[j],
144 i->record, 148 i->record,
145 sizeof (struct GNUNET_DNSPARSER_Record)); 149 sizeof (struct GNUNET_DNSPARSER_Record));
146 GNUNET_free(i->record); 150 GNUNET_free(i->record);
147 j++; 151 j++;
148 } 152 }
149 153 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "after memcpy\n");
150 /* FIXME how to handle auth, additional etc */ 154 /* FIXME how to handle auth, additional etc */
151 packet->num_answers = answer->num_records; 155 packet->num_answers = answer->num_records;
152 packet->num_authority_records = answer->num_authority_records; 156 packet->num_authority_records = answer->num_authority_records;
153 157
154 dnsflags.authoritative_answer = 1; 158 dnsflags.authoritative_answer = 1;
155 dnsflags.return_code = GNUNET_DNSPARSER_RETURN_CODE_YXDOMAIN; //not sure 159 dnsflags.opcode = GNUNET_DNSPARSER_OPCODE_QUERY;
160 dnsflags.return_code = GNUNET_DNSPARSER_RETURN_CODE_NO_ERROR; //not sure
156 dnsflags.query_or_response = 1; 161 dnsflags.query_or_response = 1;
157 packet->flags = dnsflags; 162 packet->flags = dnsflags;
158 163
@@ -161,17 +166,23 @@ reply_to_dns(struct GNUNET_GNS_PendingQuery *answer)
161 1024, /* FIXME magic from dns redirector */ 166 1024, /* FIXME magic from dns redirector */
162 &buf, 167 &buf,
163 &len); 168 &len);
169 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
170 "Built DNS response! (ret=%d)\n", ret);
164 if (ret == GNUNET_OK) 171 if (ret == GNUNET_OK)
165 { 172 {
173 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
174 "Answering DNS request\n");
166 GNUNET_DNS_request_answer(answer->request_handle, 175 GNUNET_DNS_request_answer(answer->request_handle,
167 len, 176 len,
168 buf); 177 buf);
169 GNUNET_free(answer); 178 GNUNET_free(answer);
179 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Answered DNS request\n");
170 //FIXME return code, free datastructures 180 //FIXME return code, free datastructures
171 } 181 }
172 else 182 else
173 { 183 {
174 fprintf(stderr, "Error building DNS response! (ret=%d)", ret); 184 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
185 "Error building DNS response! (ret=%d)", ret);
175 } 186 }
176} 187}
177 188
@@ -187,6 +198,7 @@ process_ns_result(void* cls, const GNUNET_HashCode *zone,
187 struct GNUNET_GNS_QueryRecordList *qrecord; 198 struct GNUNET_GNS_QueryRecordList *qrecord;
188 struct GNUNET_DNSPARSER_Record *record; 199 struct GNUNET_DNSPARSER_Record *record;
189 query = (struct GNUNET_GNS_PendingQuery *) cls; 200 query = (struct GNUNET_GNS_PendingQuery *) cls;
201 char bufA[INET6_ADDRSTRLEN];
190 202
191 203
192 if (NULL == data) 204 if (NULL == data)
@@ -195,8 +207,11 @@ process_ns_result(void* cls, const GNUNET_HashCode *zone,
195 * Last result received (or none) 207 * Last result received (or none)
196 * Do we have what we need to answer? 208 * Do we have what we need to answer?
197 * If not -> DHT Phase 209 * If not -> DHT Phase
198 * FIXME extract to func 210 * FIXME free memory
199 */ 211 */
212 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
213 "Namestore lookup terminated. (answered=%d)", query->answered);
214
200 if (query->answered) 215 if (query->answered)
201 reply_to_dns(query); 216 reply_to_dns(query);
202 else 217 else
@@ -208,6 +223,9 @@ process_ns_result(void* cls, const GNUNET_HashCode *zone,
208 /** 223 /**
209 * New result 224 * New result
210 */ 225 */
226 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
227 "Processing additional result %s from namestore\n", name);
228
211 qrecord = GNUNET_malloc(sizeof(struct GNUNET_GNS_QueryRecordList)); 229 qrecord = GNUNET_malloc(sizeof(struct GNUNET_GNS_QueryRecordList));
212 record = GNUNET_malloc(sizeof(struct GNUNET_DNSPARSER_Record)); 230 record = GNUNET_malloc(sizeof(struct GNUNET_DNSPARSER_Record));
213 qrecord->record = record; 231 qrecord->record = record;
@@ -216,14 +234,28 @@ process_ns_result(void* cls, const GNUNET_HashCode *zone,
216 /* FIXME for gns records this requires the dnsparser to be modified! 234 /* FIXME for gns records this requires the dnsparser to be modified!
217 * or use RAW 235 * or use RAW
218 * */ 236 * */
219 //record->data = data; FIXME! 237 if (record_type == GNUNET_DNSPARSER_TYPE_A)
238 {
239 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "A record: %s\n", data);
240 record->data.raw.data = GNUNET_malloc(sizeof (struct in_addr));
241 GNUNET_assert(1 == inet_pton (AF_INET, data,
242 record->data.raw.data));
243 record->data.raw.data_len = sizeof (struct in_addr);
244 }
220 record->expiration_time = expiration; 245 record->expiration_time = expiration;
221 record->type = record_type; 246 record->type = record_type;
222 record->class = GNUNET_DNSPARSER_CLASS_INTERNET; /* srsly? */ 247 record->class = GNUNET_DNSPARSER_CLASS_INTERNET; /* srsly? */
223 248
224 if (flags == GNUNET_NAMESTORE_RF_AUTHORITY) 249 if (flags == GNUNET_NAMESTORE_RF_AUTHORITY)
225 { 250 {
226 query->num_authority_records++; 251 //query->num_authority_records++;
252 }
253
254 if ((0 == strcmp(query->name , name)) &&
255 (query->type == record_type))
256 {
257 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Found answer to query!\n");
258 query->answered = 1;
227 } 259 }
228 260
229 query->num_records++; 261 query->num_records++;
@@ -242,12 +274,19 @@ handle_dns_response(void *cls,
242 size_t request_length, 274 size_t request_length,
243 const char *request) 275 const char *request)
244{ 276{
245 fprintf (stderr, "This is a response!\n");
246 GNUNET_DNS_request_forward (rh); 277 GNUNET_DNS_request_forward (rh);
247} 278}
248 279
280
281/**
282 * Phase 1 of name resolution: Lookup local namestore
283 *
284 * @param name the name to look up
285 * @param id the id of the dns request (for the reply)
286 * @param type the record type to look for
287 */
249void 288void
250lookup_namestore(char* name, uint16_t id, uint16_t type) 289lookup_namestore(struct GNUNET_DNS_RequestHandle *rh, char* name, uint16_t id, uint16_t type)
251{ 290{
252 struct GNUNET_GNS_PendingQuery *answer; 291 struct GNUNET_GNS_PendingQuery *answer;
253 292
@@ -255,9 +294,12 @@ lookup_namestore(char* name, uint16_t id, uint16_t type)
255 * Do db lookup here. Make dht lookup if necessary 294 * Do db lookup here. Make dht lookup if necessary
256 * FIXME for now only local lookups for our zone! 295 * FIXME for now only local lookups for our zone!
257 */ 296 */
258 fprintf (stderr, "This is .gnunet (%s)!\n", name); 297 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "This is .gnunet (%s)!\n", name);
259 answer = GNUNET_malloc(sizeof (struct GNUNET_GNS_PendingQuery)); 298 answer = GNUNET_malloc(sizeof (struct GNUNET_GNS_PendingQuery));
260 answer->id = id; 299 answer->id = id;
300 answer->name = name;
301 answer->type =type;
302 answer->request_handle = rh;
261 303
262 GNUNET_NAMESTORE_lookup_name(namestore_handle, 304 GNUNET_NAMESTORE_lookup_name(namestore_handle,
263 my_zone, 305 my_zone,
@@ -269,7 +311,6 @@ lookup_namestore(char* name, uint16_t id, uint16_t type)
269 311
270/** 312/**
271 * The DNS request handler 313 * The DNS request handler
272 * Phase 1 of resolution. Lookup local namestore.
273 * 314 *
274 * @param cls closure 315 * @param cls closure
275 * @param rh request handle to user for reply 316 * @param rh request handle to user for reply
@@ -290,12 +331,13 @@ handle_dns_request(void *cls,
290 int i; 331 int i;
291 char *tail; 332 char *tail;
292 333
293 fprintf (stderr, "request hijacked!\n"); 334 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "hijacked a request...processing\n");
294 p = GNUNET_DNSPARSER_parse (request, request_length); 335 p = GNUNET_DNSPARSER_parse (request, request_length);
295 336
296 if (NULL == p) 337 if (NULL == p)
297 { 338 {
298 fprintf (stderr, "Received malformed DNS packet, leaving it untouched\n"); 339 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
340 "Received malformed DNS packet, leaving it untouched\n");
299 GNUNET_DNS_request_forward (rh); 341 GNUNET_DNS_request_forward (rh);
300 return; 342 return;
301 } 343 }
@@ -321,13 +363,15 @@ handle_dns_request(void *cls,
321 /* FIXME we need to answer to ALL queries in ONE response... 363 /* FIXME we need to answer to ALL queries in ONE response...
322 * Like this we only answer one... 364 * Like this we only answer one...
323 */ 365 */
324 lookup_namestore(p->queries[i].name, p->id, p->queries[i].type); 366 lookup_namestore(rh, p->queries[i].name, p->id, p->queries[i].type);
325 } 367 }
326 else 368 else
327 { 369 {
328 /** 370 /**
329 * This request does not concern us. Forward to real DNS. 371 * This request does not concern us. Forward to real DNS.
330 */ 372 */
373 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
374 "Request for %s is forwarded to DNS\n", p->queries[i].name);
331 GNUNET_DNS_request_forward (rh); 375 GNUNET_DNS_request_forward (rh);
332 } 376 }
333 } 377 }
@@ -413,6 +457,13 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
413 GNUNET_DNS_FLAG_PRE_RESOLUTION, 457 GNUNET_DNS_FLAG_PRE_RESOLUTION,
414 &handle_dns_response, /* rh */ 458 &handle_dns_response, /* rh */
415 NULL); /* Closure */ 459 NULL); /* Closure */
460
461 if (NULL == dns_handle)
462 {
463 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
464 "Failed to connect to the dnsservice!\n");
465 }
466
416 /** 467 /**
417 * handle to our local namestore 468 * handle to our local namestore
418 */ 469 */
@@ -421,6 +472,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
421 if (NULL == namestore_handle) 472 if (NULL == namestore_handle)
422 { 473 {
423 //FIXME do error handling; 474 //FIXME do error handling;
475 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
476 "Failed to connect to the namestore!\n");
424 } 477 }
425 478
426 put_some_records(); 479 put_some_records();