aboutsummaryrefslogtreecommitdiff
path: root/src/hostlist
diff options
context:
space:
mode:
Diffstat (limited to 'src/hostlist')
-rw-r--r--src/hostlist/Makefile.am4
-rw-r--r--src/hostlist/gnunet-daemon-hostlist.c10
-rw-r--r--src/hostlist/hostlist-client.c26
-rw-r--r--src/hostlist/hostlist-server.c8
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist.c161
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist_peer1.conf6
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist_peer2.conf6
7 files changed, 180 insertions, 41 deletions
diff --git a/src/hostlist/Makefile.am b/src/hostlist/Makefile.am
index ac1409961..6aca797d3 100644
--- a/src/hostlist/Makefile.am
+++ b/src/hostlist/Makefile.am
@@ -27,12 +27,10 @@ gnunet_daemon_hostlist_LDADD = \
27gnunet_daemon_hostlist_CPPFLAGS = \ 27gnunet_daemon_hostlist_CPPFLAGS = \
28 @LIBCURL_CPPFLAGS@ 28 @LIBCURL_CPPFLAGS@
29 29
30
31
32check_PROGRAMS = \ 30check_PROGRAMS = \
33 test_gnunet_daemon_hostlist 31 test_gnunet_daemon_hostlist
34 32
35# TESTS = $(check_PROGRAMS) $(check_SCRIPTS) 33# TESTS = $(check_PROGRAMS)
36 34
37test_gnunet_daemon_hostlist_SOURCES = \ 35test_gnunet_daemon_hostlist_SOURCES = \
38 test_gnunet_daemon_hostlist.c 36 test_gnunet_daemon_hostlist.c
diff --git a/src/hostlist/gnunet-daemon-hostlist.c b/src/hostlist/gnunet-daemon-hostlist.c
index 2c4aca6d0..e8c9bc8c7 100644
--- a/src/hostlist/gnunet-daemon-hostlist.c
+++ b/src/hostlist/gnunet-daemon-hostlist.c
@@ -118,13 +118,21 @@ core_init (void *cls,
118static void 118static void
119cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 119cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
120{ 120{
121 if (bootstrapping)
122 {
123 GNUNET_HOSTLIST_client_stop ();
124 }
125 if (provide_hostlist)
126 {
127 GNUNET_HOSTLIST_server_stop ();
128 }
129 GNUNET_CORE_disconnect (core);
121 if (stats != NULL) 130 if (stats != NULL)
122 { 131 {
123 GNUNET_STATISTICS_destroy (stats, 132 GNUNET_STATISTICS_destroy (stats,
124 GNUNET_NO); 133 GNUNET_NO);
125 stats = NULL; 134 stats = NULL;
126 } 135 }
127 GNUNET_CORE_disconnect (core);
128} 136}
129 137
130 138
diff --git a/src/hostlist/hostlist-client.c b/src/hostlist/hostlist-client.c
index 9a3a31dfe..865ed2674 100644
--- a/src/hostlist/hostlist-client.c
+++ b/src/hostlist/hostlist-client.c
@@ -132,7 +132,9 @@ download_hostlist_processor (void *ptr,
132 132
133 total = size * nmemb; 133 total = size * nmemb;
134 if ( (total == 0) || (bogus_url) ) 134 if ( (total == 0) || (bogus_url) )
135 return total; /* ok, no data or bogus data */ 135 {
136 return total; /* ok, no data or bogus data */
137 }
136 left = total; 138 left = total;
137 while (left > 0) 139 while (left > 0)
138 { 140 {
@@ -161,6 +163,9 @@ download_hostlist_processor (void *ptr,
161 break; 163 break;
162 if (GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message*)msg) == msize) 164 if (GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message*)msg) == msize)
163 { 165 {
166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
167 "Received valid `%s' message from hostlist server.\n",
168 "HELLO");
164 GNUNET_TRANSPORT_offer_hello (transport, msg); 169 GNUNET_TRANSPORT_offer_hello (transport, msg);
165 } 170 }
166 else 171 else
@@ -318,6 +323,11 @@ multi_ready (void *cls,
318 struct CURLMsg *msg; 323 struct CURLMsg *msg;
319 CURLMcode mret; 324 CURLMcode mret;
320 325
326 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
327 {
328 clean_up ();
329 return;
330 }
321 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) 331 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
322 { 332 {
323 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 333 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -365,6 +375,9 @@ multi_ready (void *cls,
365 clean_up (); 375 clean_up ();
366 return; 376 return;
367 } 377 }
378 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
379 _("Download of hostlist `%s' completed.\n"),
380 current_url);
368 clean_up (); 381 clean_up ();
369} 382}
370 383
@@ -521,6 +534,7 @@ static void
521check_task (void *cls, 534check_task (void *cls,
522 const struct GNUNET_SCHEDULER_TaskContext *tc) 535 const struct GNUNET_SCHEDULER_TaskContext *tc)
523{ 536{
537
524 if (connection_count < MIN_CONNECTIONS) 538 if (connection_count < MIN_CONNECTIONS)
525 download_hostlist (); 539 download_hostlist ();
526 else 540 else
@@ -597,6 +611,8 @@ disconnect_handler (void *cls,
597static void 611static void
598primary_task (void *cls, int success) 612primary_task (void *cls, int success)
599{ 613{
614 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
615 "Statistics request done, scheduling hostlist download\n");
600 schedule_hostlist_task (); 616 schedule_hostlist_task ();
601} 617}
602 618
@@ -608,6 +624,9 @@ process_stat (void *cls,
608 uint64_t value, 624 uint64_t value,
609 int is_persistent) 625 int is_persistent)
610{ 626{
627 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
628 _("Initial time between hostlist downloads is %llums\n"),
629 (unsigned long long) value);
611 hostlist_delay.value = value; 630 hostlist_delay.value = value;
612 return GNUNET_OK; 631 return GNUNET_OK;
613} 632}
@@ -656,8 +675,9 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c,
656void 675void
657GNUNET_HOSTLIST_client_stop () 676GNUNET_HOSTLIST_client_stop ()
658{ 677{
659 GNUNET_SCHEDULER_cancel (sched, 678 if (current_task != GNUNET_SCHEDULER_NO_TASK)
660 current_task); 679 GNUNET_SCHEDULER_cancel (sched,
680 current_task);
661 GNUNET_free_non_null (proxy); 681 GNUNET_free_non_null (proxy);
662 proxy = NULL; 682 proxy = NULL;
663 if (sched != NULL) 683 if (sched != NULL)
diff --git a/src/hostlist/hostlist-server.c b/src/hostlist/hostlist-server.c
index 38e144a9d..b15fdc408 100644
--- a/src/hostlist/hostlist-server.c
+++ b/src/hostlist/hostlist-server.c
@@ -144,6 +144,9 @@ update_response (void *cls,
144 GNUNET_TIME_UNIT_MINUTES, 144 GNUNET_TIME_UNIT_MINUTES,
145 &host_processor, 145 &host_processor,
146 results); 146 results);
147 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
148 _("Created new hostlist response with %u bytes\n"),
149 results->size);
147} 150}
148 151
149 152
@@ -174,6 +177,8 @@ access_handler_callback (void *cls,
174 177
175 if (0 != strcmp (method, MHD_HTTP_METHOD_GET)) 178 if (0 != strcmp (method, MHD_HTTP_METHOD_GET))
176 return MHD_NO; 179 return MHD_NO;
180 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
181 _("Received request for our hostlist\n"));
177 if (NULL == *con_cls) 182 if (NULL == *con_cls)
178 { 183 {
179 (*con_cls) = &dummy; 184 (*con_cls) = &dummy;
@@ -282,6 +287,9 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
282 "HTTPPORT", 287 "HTTPPORT",
283 &port)) 288 &port))
284 return GNUNET_SYSERR; 289 return GNUNET_SYSERR;
290 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
291 _("Hostlist service starts on port %llu\n"),
292 port);
285 daemon_handle = MHD_start_daemon (MHD_USE_IPv6, 293 daemon_handle = MHD_start_daemon (MHD_USE_IPv6,
286 (unsigned short) port, 294 (unsigned short) port,
287 &accept_policy_callback, 295 &accept_policy_callback,
diff --git a/src/hostlist/test_gnunet_daemon_hostlist.c b/src/hostlist/test_gnunet_daemon_hostlist.c
index ca7a2369a..66fbf35aa 100644
--- a/src/hostlist/test_gnunet_daemon_hostlist.c
+++ b/src/hostlist/test_gnunet_daemon_hostlist.c
@@ -40,12 +40,15 @@
40static int ok; 40static int ok;
41 41
42static struct GNUNET_SCHEDULER_Handle *sched; 42static struct GNUNET_SCHEDULER_Handle *sched;
43
44static GNUNET_SCHEDULER_TaskIdentifier timeout_task;
43 45
44struct PeerContext 46struct PeerContext
45{ 47{
46 struct GNUNET_CONFIGURATION_Handle *cfg; 48 struct GNUNET_CONFIGURATION_Handle *cfg;
47 struct GNUNET_TRANSPORT_Handle *th; 49 struct GNUNET_TRANSPORT_Handle *th;
48 struct GNUNET_MessageHeader *hello; 50 struct GNUNET_MessageHeader *hello;
51 struct GNUNET_ARM_Handle *arm;
49#if START_ARM 52#if START_ARM
50 pid_t arm_pid; 53 pid_t arm_pid;
51#endif 54#endif
@@ -57,6 +60,52 @@ static struct PeerContext p2;
57 60
58 61
59 62
63/**
64 * Timeout, give up.
65 */
66static void
67timeout_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
68{
69 timeout_task = GNUNET_SCHEDULER_NO_TASK;
70 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
71 "Timeout trying to connect peers, test failed.\n");
72 GNUNET_TRANSPORT_disconnect (p1.th);
73 p1.th = NULL;
74 GNUNET_TRANSPORT_disconnect (p2.th);
75 p2.th = NULL;
76 GNUNET_SCHEDULER_shutdown (sched);
77}
78
79
80/**
81 * Function called to notify transport users that another
82 * peer connected to us.
83 *
84 * @param cls closure
85 * @param peer the peer that connected
86 * @param latency current latency of the connection
87 */
88static void
89notify_connect (void *cls,
90 const struct GNUNET_PeerIdentity * peer,
91 struct GNUNET_TIME_Relative latency)
92{
93 if (peer == NULL)
94 return;
95 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
96 "Peers connected, shutting down.\n");
97 GNUNET_assert (ok == 4);
98 ok = 0;
99
100 GNUNET_SCHEDULER_cancel (sched,
101 timeout_task);
102 GNUNET_TRANSPORT_disconnect (p1.th);
103 p1.th = NULL;
104 GNUNET_TRANSPORT_disconnect (p2.th);
105 p2.th = NULL;
106}
107
108
60static void 109static void
61process_hello (void *cls, 110process_hello (void *cls,
62 struct GNUNET_TIME_Relative latency, 111 struct GNUNET_TIME_Relative latency,
@@ -65,22 +114,13 @@ process_hello (void *cls,
65{ 114{
66 struct PeerContext *p = cls; 115 struct PeerContext *p = cls;
67 116
68 GNUNET_assert (peer != NULL); 117 if (message == NULL)
118 return;
69 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 119 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
70 "Received (my) `%s' from transport service of `%4s'\n", 120 "Received HELLO, starting hostlist service.\n");
71 "HELLO", GNUNET_i2s (peer)); 121 GNUNET_assert ( (ok >= 2) && (ok <= 3) );
72 GNUNET_assert (message != NULL); 122 ok++;
73 p->hello = GNUNET_malloc (ntohs (message->size)); 123 GNUNET_ARM_start_services (p->cfg, sched, "hostlist", NULL);
74 memcpy (p->hello, message, ntohs (message->size));
75 if ((p == &p1) && (p2.th != NULL))
76 GNUNET_TRANSPORT_offer_hello (p2.th, message);
77 if ((p == &p2) && (p1.th != NULL))
78 GNUNET_TRANSPORT_offer_hello (p1.th, message);
79
80 if ((p == &p1) && (p2.hello != NULL))
81 GNUNET_TRANSPORT_offer_hello (p1.th, p2.hello);
82 if ((p == &p2) && (p1.hello != NULL))
83 GNUNET_TRANSPORT_offer_hello (p2.th, p1.hello);
84} 124}
85 125
86 126
@@ -98,13 +138,75 @@ setup_peer (struct PeerContext *p, const char *cfgname)
98#endif 138#endif
99 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 139 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
100 GNUNET_ARM_start_services (p->cfg, sched, "core", NULL); 140 GNUNET_ARM_start_services (p->cfg, sched, "core", NULL);
101 p->th = GNUNET_TRANSPORT_connect (sched, p->cfg, p, NULL, NULL, NULL); 141 p->th = GNUNET_TRANSPORT_connect (sched, p->cfg, p, NULL,
142 &notify_connect, NULL);
102 GNUNET_assert (p->th != NULL); 143 GNUNET_assert (p->th != NULL);
103 GNUNET_TRANSPORT_get_hello (p->th, TIMEOUT, &process_hello, p); 144 GNUNET_TRANSPORT_get_hello (p->th, TIMEOUT, &process_hello, p);
104} 145}
105 146
106 147
107static void 148static void
149waitpid_task (void *cls,
150 const struct GNUNET_SCHEDULER_TaskContext *tc)
151{
152 struct PeerContext *p = cls;
153
154#if START_ARM
155 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
156 "Killing ARM process.\n");
157 if (0 != PLIBC_KILL (p->arm_pid, SIGTERM))
158 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
159 if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK)
160 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
162 "ARM process %u stopped\n", p->arm_pid);
163#endif
164 GNUNET_CONFIGURATION_destroy (p->cfg);
165}
166
167
168static void
169stop_cb (void *cls,
170 int success)
171{
172 struct PeerContext *p = cls;
173
174 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
175 success
176 ? "ARM stopped core service\n"
177 : "ARM failed to stop core service\n");
178 GNUNET_ARM_disconnect (p->arm);
179 p->arm = NULL;
180 /* make sure this runs after all other tasks are done */
181 GNUNET_SCHEDULER_add_delayed (sched,
182 GNUNET_TIME_UNIT_SECONDS,
183 &waitpid_task, p);
184}
185
186
187static void
188stop_arm (struct PeerContext *p)
189{
190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
191 "Asking ARM to stop core service\n");
192 p->arm = GNUNET_ARM_connect (p->cfg, sched, NULL);
193 GNUNET_ARM_stop_service (p->arm, "core", GNUNET_TIME_UNIT_SECONDS,
194 &stop_cb, p);
195}
196
197
198/**
199 * Try again to connect to transport service.
200 */
201static void
202shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
203{
204 stop_arm (&p1);
205 stop_arm (&p2);
206}
207
208
209static void
108run (void *cls, 210run (void *cls,
109 struct GNUNET_SCHEDULER_Handle *s, 211 struct GNUNET_SCHEDULER_Handle *s,
110 char *const *args, 212 char *const *args,
@@ -114,27 +216,20 @@ run (void *cls,
114 GNUNET_assert (ok == 1); 216 GNUNET_assert (ok == 1);
115 ok++; 217 ok++;
116 sched = s; 218 sched = s;
219 timeout_task = GNUNET_SCHEDULER_add_delayed (sched,
220 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
221 15),
222 &timeout_error,
223 NULL);
224 GNUNET_SCHEDULER_add_delayed (sched,
225 GNUNET_TIME_UNIT_FOREVER_REL,
226 &shutdown_task,
227 NULL);
117 setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf"); 228 setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf");
118 setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf"); 229 setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf");
119} 230}
120 231
121 232
122static void
123stop_arm (struct PeerContext *p)
124{
125 GNUNET_ARM_stop_services (p->cfg, sched, "core", NULL);
126#if START_ARM
127 if (0 != PLIBC_KILL (p->arm_pid, SIGTERM))
128 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
129 if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK)
130 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
132 "ARM process %u stopped\n", p->arm_pid);
133#endif
134 GNUNET_CONFIGURATION_destroy (p->cfg);
135}
136
137
138static int 233static int
139check () 234check ()
140{ 235{
@@ -152,8 +247,6 @@ check ()
152 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 247 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
153 argv, "test-gnunet-daemon-hostlist", 248 argv, "test-gnunet-daemon-hostlist",
154 "nohelp", options, &run, &ok); 249 "nohelp", options, &run, &ok);
155 stop_arm (&p1);
156 stop_arm (&p2);
157 return ok; 250 return ok;
158} 251}
159 252
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_peer1.conf b/src/hostlist/test_gnunet_daemon_hostlist_peer1.conf
index 1228a98e8..6d15d4394 100644
--- a/src/hostlist/test_gnunet_daemon_hostlist_peer1.conf
+++ b/src/hostlist/test_gnunet_daemon_hostlist_peer1.conf
@@ -12,6 +12,7 @@ PLUGINS = tcp
12 12
13[arm] 13[arm]
14PORT = 12966 14PORT = 12966
15DEFAULTSERVICES = resolver transport core statistics
15 16
16[statistics] 17[statistics]
17PORT = 12967 18PORT = 12967
@@ -27,3 +28,8 @@ PORT = 12970
27 28
28[testing] 29[testing]
29WEAKRANDOM = YES 30WEAKRANDOM = YES
31
32[hostlist]
33HTTPPORT = 12980
34SERVERS = http://localhost:12981/
35OPTIONS = -b -p -L DEBUG \ No newline at end of file
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_peer2.conf b/src/hostlist/test_gnunet_daemon_hostlist_peer2.conf
index f8c9d4ef1..3cf1ff202 100644
--- a/src/hostlist/test_gnunet_daemon_hostlist_peer2.conf
+++ b/src/hostlist/test_gnunet_daemon_hostlist_peer2.conf
@@ -12,6 +12,7 @@ PLUGINS = tcp
12 12
13[arm] 13[arm]
14PORT = 22966 14PORT = 22966
15DEFAULTSERVICES = resolver transport core statistics
15 16
16[statistics] 17[statistics]
17PORT = 22967 18PORT = 22967
@@ -27,3 +28,8 @@ PORT = 22970
27 28
28[testing] 29[testing]
29WEAKRANDOM = YES 30WEAKRANDOM = YES
31
32[hostlist]
33HTTPPORT = 12981
34SERVERS = http://localhost:12980/
35OPTIONS = -b -p -L DEBUG