aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2010-04-09 14:42:46 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2010-04-09 14:42:46 +0000
commit19cd2443fcffbeeae74336d19e72ed6caa6f7106 (patch)
treebb663bef1abdeada4ee4835985a991fd2711d0ed
parentf2e80d4faf6883af8d56fa65aeed3d5ab29f407a (diff)
downloadgnunet-19cd2443fcffbeeae74336d19e72ed6caa6f7106.tar.gz
gnunet-19cd2443fcffbeeae74336d19e72ed6caa6f7106.zip
-rw-r--r--src/hostlist/gnunet-daemon-hostlist.c2
-rw-r--r--src/hostlist/hostlist-server.c195
-rw-r--r--src/hostlist/hostlist-server.h2
-rw-r--r--src/hostlist/make0
4 files changed, 128 insertions, 71 deletions
diff --git a/src/hostlist/gnunet-daemon-hostlist.c b/src/hostlist/gnunet-daemon-hostlist.c
index 8eaad00ff..9a30ecca6 100644
--- a/src/hostlist/gnunet-daemon-hostlist.c
+++ b/src/hostlist/gnunet-daemon-hostlist.c
@@ -293,7 +293,7 @@ run (void *cls,
293 } 293 }
294 if (provide_hostlist) 294 if (provide_hostlist)
295 { 295 {
296 GNUNET_HOSTLIST_server_start (cfg, sched, stats, &server_ch, &server_dh); 296 GNUNET_HOSTLIST_server_start (cfg, sched, stats, core, &server_ch, &server_dh);
297 } 297 }
298 if (learning) 298 if (learning)
299 { 299 {
diff --git a/src/hostlist/hostlist-server.c b/src/hostlist/hostlist-server.c
index 4ffcc27f4..9a86b302a 100644
--- a/src/hostlist/hostlist-server.c
+++ b/src/hostlist/hostlist-server.c
@@ -65,6 +65,11 @@ static struct GNUNET_SCHEDULER_Handle *sched;
65static struct GNUNET_STATISTICS_Handle *stats; 65static struct GNUNET_STATISTICS_Handle *stats;
66 66
67/** 67/**
68 * Handle to the core service (NULL until we've connected to it).
69 */
70struct GNUNET_CORE_Handle *core;
71
72/**
68 * Our primary task for IPv4. 73 * Our primary task for IPv4.
69 */ 74 */
70static GNUNET_SCHEDULER_TaskIdentifier hostlist_task_v4; 75static GNUNET_SCHEDULER_TaskIdentifier hostlist_task_v4;
@@ -107,72 +112,6 @@ update_response (void *cls,
107 const struct GNUNET_SCHEDULER_TaskContext *tc); 112 const struct GNUNET_SCHEDULER_TaskContext *tc);
108 113
109/** 114/**
110 * Function that assembles our hostlist adv message.
111 */
112static int
113create_hostlist_adv_message (struct GNUNET_HOSTLIST_ADV_Message *adv_msg)
114{
115 int length = 0;
116 int size = 0;
117 unsigned long long port;
118
119 char *uri;
120 char hostname[HOST_NAME_MAX];
121 char *protocol = "http://";
122 char *port_s = GNUNET_malloc(6 * sizeof(char));
123
124 if (0 != gethostname (hostname, sizeof (hostname) - 1))
125 {
126 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
127 "Could not get system's hostname, unable to create advertisement message");
128 return GNUNET_NO;
129 }
130 if (-1 == GNUNET_CONFIGURATION_get_value_number (cfg,
131 "HOSTLIST",
132 "HTTPPORT",
133 &port))
134 return GNUNET_SYSERR;
135
136 sprintf(port_s, "%llu", port);
137 length = strlen(hostname)+strlen(protocol)+strlen(port_s)+2;
138 size = (length+1) * sizeof (char);
139 uri = GNUNET_malloc(size);
140 uri = strcpy(uri, protocol);
141 uri = strcat(uri, hostname);
142 uri = strcat(uri, ":");
143 uri = strcat(uri, port_s);
144 uri = strcat(uri, "/");
145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Address to obtain hostlist: %s\n", uri);
146
147
148 adv_msg = GNUNET_malloc ( sizeof(struct GNUNET_HOSTLIST_ADV_Message) + size);
149 if ( NULL == adv_msg)
150 {
151 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
152 "Could not allocate memory for the message");
153 return GNUNET_NO;
154 }
155 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
156 "size ADV_Message: %u\n",sizeof(struct GNUNET_HOSTLIST_ADV_Message));
157 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
158 "size uri: %u\n", (length + 1) * sizeof (char));
159
160
161 if ( ( size + sizeof( struct GNUNET_HOSTLIST_ADV_Message )) > GNUNET_SERVER_MAX_MESSAGE_SIZE)
162 {
163 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
164 "Advertisement message is bigger than GNUNET allows");
165 return GNUNET_NO;
166 }
167
168 adv_msg->header.type = htons (GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT);
169 adv_msg->header.size = htons (sizeof (struct GNUNET_HOSTLIST_ADV_Message) + size);
170 memcpy(&adv_msg[1],uri,size);
171
172 return GNUNET_OK;
173}
174
175/**
176 * Function that assembles our response. 115 * Function that assembles our response.
177 */ 116 */
178static void 117static void
@@ -415,6 +354,116 @@ access_handler_callback (void *cls,
415 return MHD_queue_response (connection, MHD_HTTP_OK, response); 354 return MHD_queue_response (connection, MHD_HTTP_OK, response);
416} 355}
417 356
357static size_t
358adv_transmit_ready ( void *cls, size_t size, void *buf)
359{
360 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
361 _("Ready to transmit %u bytes of adv\n"), size);
362 return size;
363}
364
365static int
366adv_transmit_message ( const struct GNUNET_PeerIdentity * peer, int size )
367{
368 /* transmit message to peer */
369 if ( NULL == core)
370 {
371 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
372 _("Not connected to core, unable to send advertisement message\n"));
373 return GNUNET_NO;
374 }
375
376 struct GNUNET_TIME_Relative timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, GNUNET_ADV_TIMEOUT);
377 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
378 _("Asked to transmit %u bytes of adv\n"), size);
379 GNUNET_CORE_notify_transmit_ready (core,
380 0,
381 timeout,
382 peer,
383 size,
384 &adv_transmit_ready, NULL);
385 return GNUNET_YES;
386}
387
388/**
389 * Function that assembles our hostlist adv message.
390 */
391static int
392adv_create_message ( const struct GNUNET_PeerIdentity * peer,
393 struct GNUNET_HOSTLIST_ADV_Message * adv_msg )
394
395{
396 int length = 0;
397 int size = 0;
398 unsigned long long port;
399
400 char *uri;
401 char hostname[HOST_NAME_MAX];
402 char *protocol = "http://";
403 char *port_s = GNUNET_malloc(6 * sizeof(char));
404
405 if (0 != gethostname (hostname, sizeof (hostname) - 1))
406 {
407 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
408 "Could not get system's hostname, unable to create advertisement message");
409 return GNUNET_NO;
410 }
411 if (-1 == GNUNET_CONFIGURATION_get_value_number (cfg,
412 "HOSTLIST",
413 "HTTPPORT",
414 &port))
415 return GNUNET_SYSERR;
416
417 sprintf(port_s, "%llu", port);
418 length = strlen(hostname)+strlen(protocol)+strlen(port_s)+2;
419 size = (length+1) * sizeof (char);
420 uri = GNUNET_malloc(size);
421 uri = strcpy(uri, protocol);
422 uri = strcat(uri, hostname);
423 uri = strcat(uri, ":");
424 uri = strcat(uri, port_s);
425 uri = strcat(uri, "/");
426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Address to obtain hostlist: %s\n", uri);
427
428
429 adv_msg = GNUNET_malloc ( sizeof(struct GNUNET_HOSTLIST_ADV_Message) + size);
430 if (adv_msg==NULL)
431 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
432 "Creating message:address null\n",sizeof(struct GNUNET_HOSTLIST_ADV_Message));
433
434 if ( NULL == adv_msg)
435 {
436 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
437 "Could not allocate memory for the message");
438 return GNUNET_NO;
439 }
440 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
441 "size ADV_Message: %u\n",sizeof(struct GNUNET_HOSTLIST_ADV_Message));
442 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
443 "size uri: %u\n", (length + 1) * sizeof (char));
444
445
446 if ( ( size + sizeof( struct GNUNET_HOSTLIST_ADV_Message )) > GNUNET_SERVER_MAX_MESSAGE_SIZE)
447 {
448 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
449 "Advertisement message is bigger than GNUNET allows");
450 return GNUNET_NO;
451 }
452
453 adv_msg->header.type = htons (GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT);
454 adv_msg->header.size = htons (sizeof (struct GNUNET_HOSTLIST_ADV_Message) + size);
455 memcpy(&adv_msg[1],uri,size);
456
457 /* Request core to transmit message to peer
458 adv_transmit_message(peer, size); */
459
460 GNUNET_free ( port_s );
461 GNUNET_free ( uri );
462 GNUNET_free ( adv_msg );
463
464 return GNUNET_OK;
465}
466
418/** 467/**
419 * Method called whenever a given peer connects. 468 * Method called whenever a given peer connects.
420 * 469 *
@@ -430,12 +479,17 @@ connect_handler (void *cls,
430 struct GNUNET_TIME_Relative latency, 479 struct GNUNET_TIME_Relative latency,
431 uint32_t distance) 480 uint32_t distance)
432{ 481{
482
433 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 483 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
434 "A new peer connected to the server, preparing to send hostlist advertisement\n"); 484 "A new peer connected to the server, preparing to send hostlist advertisement\n");
435 /* create a new advertisement message */ 485 /* create a new advertisement message */
436 struct GNUNET_HOSTLIST_ADV_Message *adv_msg; 486 struct GNUNET_HOSTLIST_ADV_Message *adv_msg = NULL;
437 create_hostlist_adv_message(adv_msg); 487 if ( (GNUNET_OK != adv_create_message(peer, adv_msg)))
438 488 {
489 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
490 _(" GNUNET_OK Could not create a hostlist advertisement message, impossible to advertise hostlist\n"));
491 return;
492 }
439} 493}
440 494
441 495
@@ -551,6 +605,7 @@ int
551GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, 605GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
552 struct GNUNET_SCHEDULER_Handle *s, 606 struct GNUNET_SCHEDULER_Handle *s,
553 struct GNUNET_STATISTICS_Handle *st, 607 struct GNUNET_STATISTICS_Handle *st,
608 struct GNUNET_CORE_Handle *co,
554 GNUNET_CORE_ConnectEventHandler *server_ch, 609 GNUNET_CORE_ConnectEventHandler *server_ch,
555 GNUNET_CORE_DisconnectEventHandler *server_dh) 610 GNUNET_CORE_DisconnectEventHandler *server_dh)
556{ 611{
@@ -606,7 +661,7 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
606 (unsigned short) port); 661 (unsigned short) port);
607 return GNUNET_SYSERR; 662 return GNUNET_SYSERR;
608 } 663 }
609 664 core=co;
610 *server_ch = &connect_handler; 665 *server_ch = &connect_handler;
611 *server_dh = &disconnect_handler; 666 *server_dh = &disconnect_handler;
612 667
diff --git a/src/hostlist/hostlist-server.h b/src/hostlist/hostlist-server.h
index 7251ce11c..bdd7084e4 100644
--- a/src/hostlist/hostlist-server.h
+++ b/src/hostlist/hostlist-server.h
@@ -31,6 +31,7 @@
31#include "gnunet_statistics_service.h" 31#include "gnunet_statistics_service.h"
32#include "gnunet_util_lib.h" 32#include "gnunet_util_lib.h"
33 33
34#define GNUNET_ADV_TIMEOUT 2500
34 35
35/** 36/**
36 * Start server offering our hostlist. 37 * Start server offering our hostlist.
@@ -41,6 +42,7 @@ int
41GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, 42GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
42 struct GNUNET_SCHEDULER_Handle *s, 43 struct GNUNET_SCHEDULER_Handle *s,
43 struct GNUNET_STATISTICS_Handle *st, 44 struct GNUNET_STATISTICS_Handle *st,
45 struct GNUNET_CORE_Handle *core,
44 GNUNET_CORE_ConnectEventHandler *server_ch, 46 GNUNET_CORE_ConnectEventHandler *server_ch,
45 GNUNET_CORE_DisconnectEventHandler *server_dh); 47 GNUNET_CORE_DisconnectEventHandler *server_dh);
46 48
diff --git a/src/hostlist/make b/src/hostlist/make
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/hostlist/make