diff options
Diffstat (limited to 'src/transport/plugin_transport_http_server.c')
-rw-r--r-- | src/transport/plugin_transport_http_server.c | 327 |
1 files changed, 187 insertions, 140 deletions
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c index e5b20cfb4..48c8739d5 100644 --- a/src/transport/plugin_transport_http_server.c +++ b/src/transport/plugin_transport_http_server.c | |||
@@ -39,7 +39,7 @@ struct ServerConnection | |||
39 | int disconnect; | 39 | int disconnect; |
40 | 40 | ||
41 | struct Session *session; | 41 | struct Session *session; |
42 | struct MHD_Connection * mhd_conn; | 42 | struct MHD_Connection *mhd_conn; |
43 | }; | 43 | }; |
44 | 44 | ||
45 | /** | 45 | /** |
@@ -50,7 +50,8 @@ struct ServerConnection | |||
50 | * @return gnunet task identifier | 50 | * @return gnunet task identifier |
51 | */ | 51 | */ |
52 | static GNUNET_SCHEDULER_TaskIdentifier | 52 | static GNUNET_SCHEDULER_TaskIdentifier |
53 | server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle, int now); | 53 | server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle, |
54 | int now); | ||
54 | 55 | ||
55 | static void | 56 | static void |
56 | server_log (void *arg, const char *fmt, va_list ap) | 57 | server_log (void *arg, const char *fmt, va_list ap) |
@@ -74,13 +75,14 @@ server_log (void *arg, const char *fmt, va_list ap) | |||
74 | static int | 75 | static int |
75 | server_accept_cb (void *cls, const struct sockaddr *addr, socklen_t addr_len) | 76 | server_accept_cb (void *cls, const struct sockaddr *addr, socklen_t addr_len) |
76 | { | 77 | { |
77 | struct Plugin * plugin = cls; | 78 | struct Plugin *plugin = cls; |
78 | 79 | ||
79 | if (plugin->cur_connections <= plugin->max_connections) | 80 | if (plugin->cur_connections <= plugin->max_connections) |
80 | return MHD_YES; | 81 | return MHD_YES; |
81 | else | 82 | else |
82 | { | 83 | { |
83 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Server: Cannot accept new connections\n"); | 84 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
85 | "Server: Cannot accept new connections\n"); | ||
84 | return MHD_NO; | 86 | return MHD_NO; |
85 | } | 87 | } |
86 | } | 88 | } |
@@ -131,8 +133,11 @@ server_load_certificate (struct Plugin *plugin) | |||
131 | /* Get crypto init string from config | 133 | /* Get crypto init string from config |
132 | * If not present just use default values */ | 134 | * If not present just use default values */ |
133 | 135 | ||
134 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name, | 136 | GNUNET_assert (GNUNET_OK == |
135 | "CRYPTO_INIT", &plugin->crypto_init)); | 137 | GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, |
138 | plugin->name, | ||
139 | "CRYPTO_INIT", | ||
140 | &plugin->crypto_init)); | ||
136 | 141 | ||
137 | if (GNUNET_OK != | 142 | if (GNUNET_OK != |
138 | GNUNET_CONFIGURATION_get_value_filename (plugin->env->cfg, plugin->name, | 143 | GNUNET_CONFIGURATION_get_value_filename (plugin->env->cfg, plugin->name, |
@@ -145,7 +150,7 @@ server_load_certificate (struct Plugin *plugin) | |||
145 | GNUNET_CONFIGURATION_get_value_filename (plugin->env->cfg, plugin->name, | 150 | GNUNET_CONFIGURATION_get_value_filename (plugin->env->cfg, plugin->name, |
146 | "CERT_FILE", &cert_file)) | 151 | "CERT_FILE", &cert_file)) |
147 | { | 152 | { |
148 | GNUNET_asprintf(&cert_file, "%s", "https_cert.crt"); | 153 | GNUNET_asprintf (&cert_file, "%s", "https_cert.crt"); |
149 | } | 154 | } |
150 | 155 | ||
151 | /* read key & certificates from file */ | 156 | /* read key & certificates from file */ |
@@ -244,7 +249,7 @@ server_reschedule (struct Plugin *plugin, int now) | |||
244 | { | 249 | { |
245 | if (plugin->server_v4_task != GNUNET_SCHEDULER_NO_TASK) | 250 | if (plugin->server_v4_task != GNUNET_SCHEDULER_NO_TASK) |
246 | { | 251 | { |
247 | GNUNET_SCHEDULER_cancel(plugin->server_v4_task); | 252 | GNUNET_SCHEDULER_cancel (plugin->server_v4_task); |
248 | plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK; | 253 | plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK; |
249 | } | 254 | } |
250 | plugin->server_v4_task = server_schedule (plugin, plugin->server_v4, now); | 255 | plugin->server_v4_task = server_schedule (plugin, plugin->server_v4, now); |
@@ -252,12 +257,12 @@ server_reschedule (struct Plugin *plugin, int now) | |||
252 | 257 | ||
253 | if (plugin->server_v6 != NULL) | 258 | if (plugin->server_v6 != NULL) |
254 | { | 259 | { |
255 | if (plugin->server_v6_task != GNUNET_SCHEDULER_NO_TASK) | 260 | if (plugin->server_v6_task != GNUNET_SCHEDULER_NO_TASK) |
256 | { | 261 | { |
257 | GNUNET_SCHEDULER_cancel(plugin->server_v6_task); | 262 | GNUNET_SCHEDULER_cancel (plugin->server_v6_task); |
258 | plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK; | 263 | plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK; |
259 | } | 264 | } |
260 | plugin->server_v6_task = server_schedule (plugin, plugin->server_v6, now); | 265 | plugin->server_v6_task = server_schedule (plugin, plugin->server_v6, now); |
261 | } | 266 | } |
262 | } | 267 | } |
263 | 268 | ||
@@ -269,9 +274,10 @@ server_reschedule (struct Plugin *plugin, int now) | |||
269 | */ | 274 | */ |
270 | static void | 275 | static void |
271 | server_receive_mst_cb (void *cls, void *client, | 276 | server_receive_mst_cb (void *cls, void *client, |
272 | const struct GNUNET_MessageHeader *message) | 277 | const struct GNUNET_MessageHeader *message) |
273 | { | 278 | { |
274 | struct Session *s = cls; | 279 | struct Session *s = cls; |
280 | |||
275 | #if VERBOSE_SERVER | 281 | #if VERBOSE_SERVER |
276 | struct Plugin *plugin = s->plugin; | 282 | struct Plugin *plugin = s->plugin; |
277 | #endif | 283 | #endif |
@@ -279,13 +285,16 @@ server_receive_mst_cb (void *cls, void *client, | |||
279 | 285 | ||
280 | delay = http_plugin_receive (s, &s->target, message, s, s->addr, s->addrlen); | 286 | delay = http_plugin_receive (s, &s->target, message, s, s->addr, s->addrlen); |
281 | 287 | ||
282 | s->next_receive = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), delay); | 288 | s->next_receive = |
289 | GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), delay); | ||
283 | 290 | ||
284 | if (delay.rel_value > 0) | 291 | if (delay.rel_value > 0) |
285 | { | 292 | { |
286 | #if VERBOSE_CLIENT | 293 | #if VERBOSE_CLIENT |
287 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Server: peer `%s' address `%s' next read delayed for %llu ms\n", | 294 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
288 | GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen), delay); | 295 | "Server: peer `%s' address `%s' next read delayed for %llu ms\n", |
296 | GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen), | ||
297 | delay); | ||
289 | #endif | 298 | #endif |
290 | } | 299 | } |
291 | } | 300 | } |
@@ -305,6 +314,7 @@ server_send_callback (void *cls, uint64_t pos, char *buf, size_t max) | |||
305 | 314 | ||
306 | struct HTTP_Message *msg; | 315 | struct HTTP_Message *msg; |
307 | int bytes_read = 0; | 316 | int bytes_read = 0; |
317 | |||
308 | //static int c = 0; | 318 | //static int c = 0; |
309 | msg = s->msg_head; | 319 | msg = s->msg_head; |
310 | if (msg != NULL) | 320 | if (msg != NULL) |
@@ -328,54 +338,58 @@ server_send_callback (void *cls, uint64_t pos, char *buf, size_t max) | |||
328 | { | 338 | { |
329 | if (NULL != msg->transmit_cont) | 339 | if (NULL != msg->transmit_cont) |
330 | msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK); | 340 | msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK); |
331 | GNUNET_CONTAINER_DLL_remove(s->msg_head, s->msg_tail, msg); | 341 | GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg); |
332 | GNUNET_free (msg); | 342 | GNUNET_free (msg); |
333 | } | 343 | } |
334 | } | 344 | } |
335 | 345 | ||
336 | #if VERBOSE_CLIENT | 346 | #if VERBOSE_CLIENT |
337 | struct Plugin *plugin = s->plugin; | 347 | struct Plugin *plugin = s->plugin; |
348 | |||
338 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 349 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
339 | "Server: %X: sent %u bytes\n", | 350 | "Server: %X: sent %u bytes\n", s, bytes_read); |
340 | s, bytes_read); | ||
341 | #endif | 351 | #endif |
342 | return bytes_read; | 352 | return bytes_read; |
343 | } | 353 | } |
344 | 354 | ||
345 | static struct ServerConnection * | 355 | static struct ServerConnection * |
346 | server_lookup_session (struct Plugin *plugin, | 356 | server_lookup_session (struct Plugin *plugin, |
347 | struct MHD_Connection *mhd_connection, | 357 | struct MHD_Connection *mhd_connection, const char *url, |
348 | const char * url, | 358 | const char *method) |
349 | const char *method) | ||
350 | { | 359 | { |
351 | struct Session *s = NULL; | 360 | struct Session *s = NULL; |
352 | struct Session * t; | 361 | struct Session *t; |
353 | struct ServerConnection *sc = NULL; | 362 | struct ServerConnection *sc = NULL; |
354 | const union MHD_ConnectionInfo *conn_info; | 363 | const union MHD_ConnectionInfo *conn_info; |
355 | 364 | ||
356 | struct IPv4HttpAddress a4; | 365 | struct IPv4HttpAddress a4; |
357 | struct IPv6HttpAddress a6; | 366 | struct IPv6HttpAddress a6; |
358 | struct sockaddr_in * s4; | 367 | struct sockaddr_in *s4; |
359 | struct sockaddr_in6 * s6; | 368 | struct sockaddr_in6 *s6; |
360 | void * a; | 369 | void *a; |
361 | size_t a_len; | 370 | size_t a_len; |
362 | struct GNUNET_PeerIdentity target; | 371 | struct GNUNET_PeerIdentity target; |
363 | int check = GNUNET_NO; | 372 | int check = GNUNET_NO; |
364 | uint32_t tag = 0; | 373 | uint32_t tag = 0; |
365 | int direction; | 374 | int direction; |
366 | 375 | ||
367 | conn_info = MHD_get_connection_info (mhd_connection, MHD_CONNECTION_INFO_CLIENT_ADDRESS); | 376 | conn_info = |
368 | if ((conn_info->client_addr->sa_family != AF_INET) && (conn_info->client_addr->sa_family != AF_INET6)) | 377 | MHD_get_connection_info (mhd_connection, |
378 | MHD_CONNECTION_INFO_CLIENT_ADDRESS); | ||
379 | if ((conn_info->client_addr->sa_family != AF_INET) && | ||
380 | (conn_info->client_addr->sa_family != AF_INET6)) | ||
369 | return MHD_NO; | 381 | return MHD_NO; |
370 | 382 | ||
371 | if ((strlen(&url[1]) >= 105) && (url[104] == ';')) | 383 | if ((strlen (&url[1]) >= 105) && (url[104] == ';')) |
372 | { | 384 | { |
373 | char hash[104]; | 385 | char hash[104]; |
374 | char * tagc = (char *) &url[105]; | 386 | char *tagc = (char *) &url[105]; |
375 | memcpy(&hash, &url[1], 103); | 387 | |
376 | hash [103] = '\0'; | 388 | memcpy (&hash, &url[1], 103); |
377 | if (GNUNET_OK == GNUNET_CRYPTO_hash_from_string ((const char *) &hash, | 389 | hash[103] = '\0'; |
378 | &(target.hashPubKey))) | 390 | if (GNUNET_OK == |
391 | GNUNET_CRYPTO_hash_from_string ((const char *) &hash, | ||
392 | &(target.hashPubKey))) | ||
379 | { | 393 | { |
380 | tag = strtoul (tagc, NULL, 10); | 394 | tag = strtoul (tagc, NULL, 10); |
381 | if (tagc > 0) | 395 | if (tagc > 0) |
@@ -395,7 +409,8 @@ server_lookup_session (struct Plugin *plugin, | |||
395 | 409 | ||
396 | #if VERBOSE_SERVER | 410 | #if VERBOSE_SERVER |
397 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 411 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
398 | "Server: New inbound connection from %s with tag %u\n", GNUNET_i2s(&target), tag); | 412 | "Server: New inbound connection from %s with tag %u\n", |
413 | GNUNET_i2s (&target), tag); | ||
399 | #endif | 414 | #endif |
400 | /* find duplicate session */ | 415 | /* find duplicate session */ |
401 | 416 | ||
@@ -403,17 +418,20 @@ server_lookup_session (struct Plugin *plugin, | |||
403 | 418 | ||
404 | while (t != NULL) | 419 | while (t != NULL) |
405 | { | 420 | { |
406 | if ((t->inbound) && (0 == memcmp (&t->target, &target, sizeof (struct GNUNET_PeerIdentity))) && | 421 | if ((t->inbound) && |
422 | (0 == memcmp (&t->target, &target, sizeof (struct GNUNET_PeerIdentity))) | ||
423 | && | ||
407 | /* FIXME add source address comparison */ | 424 | /* FIXME add source address comparison */ |
408 | (t->tag == tag)) | 425 | (t->tag == tag)) |
409 | break; | 426 | break; |
410 | t = t->next; | 427 | t = t->next; |
411 | } | 428 | } |
412 | if (t != NULL) | 429 | if (t != NULL) |
413 | { | 430 | { |
414 | #if VERBOSE_SERVER | 431 | #if VERBOSE_SERVER |
415 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 432 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
416 | "Server: Duplicate session, dismissing new connection from peer `%s'\n", GNUNET_i2s (&target)); | 433 | "Server: Duplicate session, dismissing new connection from peer `%s'\n", |
434 | GNUNET_i2s (&target)); | ||
417 | #endif | 435 | #endif |
418 | goto error; | 436 | goto error; |
419 | } | 437 | } |
@@ -424,8 +442,8 @@ server_lookup_session (struct Plugin *plugin, | |||
424 | while (t != NULL) | 442 | while (t != NULL) |
425 | { | 443 | { |
426 | /* FIXME add source address comparison */ | 444 | /* FIXME add source address comparison */ |
427 | if ((0 == memcmp (&t->target, &target, sizeof (struct GNUNET_PeerIdentity))) && | 445 | if ((0 == memcmp (&t->target, &target, sizeof (struct GNUNET_PeerIdentity))) |
428 | (t->tag == tag)) | 446 | && (t->tag == tag)) |
429 | { | 447 | { |
430 | break; | 448 | break; |
431 | } | 449 | } |
@@ -437,25 +455,29 @@ server_lookup_session (struct Plugin *plugin, | |||
437 | 455 | ||
438 | #if VERBOSE_SERVER | 456 | #if VERBOSE_SERVER |
439 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 457 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
440 | "Server: Found existing semi-session for `%s'\n", GNUNET_i2s (&target)); | 458 | "Server: Found existing semi-session for `%s'\n", |
459 | GNUNET_i2s (&target)); | ||
441 | #endif | 460 | #endif |
442 | 461 | ||
443 | if ((direction == _SEND) && (t->server_send != NULL)) | 462 | if ((direction == _SEND) && (t->server_send != NULL)) |
444 | { | 463 | { |
445 | #if VERBOSE_SERVER | 464 | #if VERBOSE_SERVER |
446 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 465 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
447 | "Server: Duplicate GET session, dismissing new connection from peer `%s'\n", GNUNET_i2s (&target)); | 466 | "Server: Duplicate GET session, dismissing new connection from peer `%s'\n", |
467 | GNUNET_i2s (&target)); | ||
448 | #endif | 468 | #endif |
449 | goto error; | 469 | goto error; |
450 | } | 470 | } |
451 | else | 471 | else |
452 | { | 472 | { |
453 | s = t; | 473 | s = t; |
454 | GNUNET_CONTAINER_DLL_remove(plugin->server_semi_head, plugin->server_semi_tail, s); | 474 | GNUNET_CONTAINER_DLL_remove (plugin->server_semi_head, |
455 | GNUNET_CONTAINER_DLL_insert(plugin->head, plugin->tail, s); | 475 | plugin->server_semi_tail, s); |
476 | GNUNET_CONTAINER_DLL_insert (plugin->head, plugin->tail, s); | ||
456 | #if VERBOSE_SERVER | 477 | #if VERBOSE_SERVER |
457 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 478 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
458 | "Server: Found matching semi-session, merging session for peer `%s'\n", GNUNET_i2s (&target)); | 479 | "Server: Found matching semi-session, merging session for peer `%s'\n", |
480 | GNUNET_i2s (&target)); | ||
459 | #endif | 481 | #endif |
460 | 482 | ||
461 | goto found; | 483 | goto found; |
@@ -464,18 +486,21 @@ server_lookup_session (struct Plugin *plugin, | |||
464 | { | 486 | { |
465 | #if VERBOSE_SERVER | 487 | #if VERBOSE_SERVER |
466 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 488 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
467 | "Server: Duplicate PUT session, dismissing new connection from peer `%s'\n", GNUNET_i2s (&target)); | 489 | "Server: Duplicate PUT session, dismissing new connection from peer `%s'\n", |
490 | GNUNET_i2s (&target)); | ||
468 | #endif | 491 | #endif |
469 | goto error; | 492 | goto error; |
470 | } | 493 | } |
471 | else | 494 | else |
472 | { | 495 | { |
473 | s = t; | 496 | s = t; |
474 | GNUNET_CONTAINER_DLL_remove(plugin->server_semi_head, plugin->server_semi_tail, s); | 497 | GNUNET_CONTAINER_DLL_remove (plugin->server_semi_head, |
475 | GNUNET_CONTAINER_DLL_insert(plugin->head, plugin->tail, s); | 498 | plugin->server_semi_tail, s); |
499 | GNUNET_CONTAINER_DLL_insert (plugin->head, plugin->tail, s); | ||
476 | #if VERBOSE_SERVER | 500 | #if VERBOSE_SERVER |
477 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 501 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
478 | "Server: Found matching semi-session, merging session for peer `%s'\n", GNUNET_i2s (&target)); | 502 | "Server: Found matching semi-session, merging session for peer `%s'\n", |
503 | GNUNET_i2s (&target)); | ||
479 | #endif | 504 | #endif |
480 | goto found; | 505 | goto found; |
481 | } | 506 | } |
@@ -484,53 +509,48 @@ create: | |||
484 | /* create new session */ | 509 | /* create new session */ |
485 | #if VERBOSE_SERVER | 510 | #if VERBOSE_SERVER |
486 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 511 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
487 | "Server: Creating new session for peer `%s' \n", GNUNET_i2s (&target)); | 512 | "Server: Creating new session for peer `%s' \n", |
513 | GNUNET_i2s (&target)); | ||
488 | #endif | 514 | #endif |
489 | 515 | ||
490 | switch (conn_info->client_addr->sa_family) | 516 | switch (conn_info->client_addr->sa_family) |
491 | { | 517 | { |
492 | case (AF_INET): | 518 | case (AF_INET): |
493 | s4 = ((struct sockaddr_in * ) conn_info->client_addr); | 519 | s4 = ((struct sockaddr_in *) conn_info->client_addr); |
494 | a4.u4_port = s4->sin_port; | 520 | a4.u4_port = s4->sin_port; |
495 | memcpy (&a4.ipv4_addr, &s4->sin_addr, | 521 | memcpy (&a4.ipv4_addr, &s4->sin_addr, sizeof (struct in_addr)); |
496 | sizeof (struct in_addr)); | 522 | a = &a4; |
497 | a = &a4; | 523 | a_len = sizeof (struct IPv4HttpAddress); |
498 | a_len = sizeof (struct IPv4HttpAddress); | 524 | break; |
499 | break; | ||
500 | case (AF_INET6): | 525 | case (AF_INET6): |
501 | s6 = ((struct sockaddr_in6 * ) conn_info->client_addr); | 526 | s6 = ((struct sockaddr_in6 *) conn_info->client_addr); |
502 | a6.u6_port = s6->sin6_port; | 527 | a6.u6_port = s6->sin6_port; |
503 | memcpy (&a6.ipv6_addr, &s6->sin6_addr, | 528 | memcpy (&a6.ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr)); |
504 | sizeof (struct in6_addr)); | 529 | a = &a6; |
505 | a = &a6; | 530 | a_len = sizeof (struct IPv6HttpAddress); |
506 | a_len = sizeof (struct IPv6HttpAddress); | 531 | break; |
507 | break; | ||
508 | default: | 532 | default: |
509 | GNUNET_break (0); | 533 | GNUNET_break (0); |
510 | goto error; | 534 | goto error; |
511 | } | 535 | } |
512 | 536 | ||
513 | s = create_session (plugin, | 537 | s = create_session (plugin, &target, a, a_len, NULL, NULL); |
514 | &target, | ||
515 | a, | ||
516 | a_len, | ||
517 | NULL, | ||
518 | NULL); | ||
519 | 538 | ||
520 | s->inbound = GNUNET_YES; | 539 | s->inbound = GNUNET_YES; |
521 | s->next_receive = GNUNET_TIME_absolute_get_zero(); | 540 | s->next_receive = GNUNET_TIME_absolute_get_zero (); |
522 | s->tag= tag; | 541 | s->tag = tag; |
523 | if (0 == strcmp (MHD_HTTP_METHOD_PUT, method)) | 542 | if (0 == strcmp (MHD_HTTP_METHOD_PUT, method)) |
524 | s->server_recv = s; | 543 | s->server_recv = s; |
525 | if (0 == strcmp (MHD_HTTP_METHOD_GET, method)) | 544 | if (0 == strcmp (MHD_HTTP_METHOD_GET, method)) |
526 | s->server_send = s; | 545 | s->server_send = s; |
527 | GNUNET_CONTAINER_DLL_insert (plugin->server_semi_head, plugin->server_semi_tail, s); | 546 | GNUNET_CONTAINER_DLL_insert (plugin->server_semi_head, |
547 | plugin->server_semi_tail, s); | ||
528 | goto found; | 548 | goto found; |
529 | 549 | ||
530 | error: | 550 | error: |
531 | #if VERBOSE_SERVER | 551 | #if VERBOSE_SERVER |
532 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 552 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
533 | "Server: Invalid connection request\n"); | 553 | "Server: Invalid connection request\n"); |
534 | #endif | 554 | #endif |
535 | return NULL; | 555 | return NULL; |
536 | 556 | ||
@@ -546,6 +566,7 @@ found: | |||
546 | 566 | ||
547 | #if MHD_VERSION >= 0x00090E00 | 567 | #if MHD_VERSION >= 0x00090E00 |
548 | int to = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value / 1000); | 568 | int to = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value / 1000); |
569 | |||
549 | #if VERBOSE_SERVER | 570 | #if VERBOSE_SERVER |
550 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 571 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
551 | "Server: Setting timeout for %X to %u sec.\n", sc, to); | 572 | "Server: Setting timeout for %X to %u sec.\n", sc, to); |
@@ -581,12 +602,14 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, | |||
581 | /* new connection */ | 602 | /* new connection */ |
582 | if (sc == NULL) | 603 | if (sc == NULL) |
583 | { | 604 | { |
584 | sc = server_lookup_session(plugin, mhd_connection, url, method); | 605 | sc = server_lookup_session (plugin, mhd_connection, url, method); |
585 | if (sc != NULL) | 606 | if (sc != NULL) |
586 | (*httpSessionCache) = sc; | 607 | (*httpSessionCache) = sc; |
587 | else | 608 | else |
588 | { | 609 | { |
589 | response = MHD_create_response_from_data (strlen (HTTP_ERROR_RESPONSE),HTTP_ERROR_RESPONSE, MHD_NO, MHD_NO); | 610 | response = |
611 | MHD_create_response_from_data (strlen (HTTP_ERROR_RESPONSE), | ||
612 | HTTP_ERROR_RESPONSE, MHD_NO, MHD_NO); | ||
590 | res = MHD_queue_response (mhd_connection, MHD_HTTP_NOT_FOUND, response); | 613 | res = MHD_queue_response (mhd_connection, MHD_HTTP_NOT_FOUND, response); |
591 | MHD_destroy_response (response); | 614 | MHD_destroy_response (response); |
592 | return res; | 615 | return res; |
@@ -597,10 +620,12 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, | |||
597 | sc = (*httpSessionCache); | 620 | sc = (*httpSessionCache); |
598 | s = sc->session; | 621 | s = sc->session; |
599 | 622 | ||
600 | /* connection is to be disconnected*/ | 623 | /* connection is to be disconnected */ |
601 | if (sc->disconnect == GNUNET_YES) | 624 | if (sc->disconnect == GNUNET_YES) |
602 | { | 625 | { |
603 | response = MHD_create_response_from_data (strlen ("Thank you!"), "Thank you!", MHD_NO, MHD_NO); | 626 | response = |
627 | MHD_create_response_from_data (strlen ("Thank you!"), "Thank you!", | ||
628 | MHD_NO, MHD_NO); | ||
604 | res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response); | 629 | res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response); |
605 | #if VERBOSE_SERVER | 630 | #if VERBOSE_SERVER |
606 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 631 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -613,7 +638,8 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, | |||
613 | GNUNET_assert (s != NULL); | 638 | GNUNET_assert (s != NULL); |
614 | if (sc->direction == _SEND) | 639 | if (sc->direction == _SEND) |
615 | { | 640 | { |
616 | response = MHD_create_response_from_callback (-1, 32 * 1024, &server_send_callback, | 641 | response = |
642 | MHD_create_response_from_callback (-1, 32 * 1024, &server_send_callback, | ||
617 | s, NULL); | 643 | s, NULL); |
618 | res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response); | 644 | res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response); |
619 | MHD_destroy_response (response); | 645 | MHD_destroy_response (response); |
@@ -624,9 +650,10 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, | |||
624 | if (*upload_data_size == 0) | 650 | if (*upload_data_size == 0) |
625 | { | 651 | { |
626 | #if VERBOSE_SERVER | 652 | #if VERBOSE_SERVER |
627 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 653 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
628 | "Server: Peer `%s' PUT on address `%s' connected\n", | 654 | "Server: Peer `%s' PUT on address `%s' connected\n", |
629 | GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen)); | 655 | GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, |
656 | s->addrlen)); | ||
630 | #endif | 657 | #endif |
631 | return MHD_YES; | 658 | return MHD_YES; |
632 | } | 659 | } |
@@ -635,23 +662,28 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, | |||
635 | if ((*upload_data_size > 0)) | 662 | if ((*upload_data_size > 0)) |
636 | { | 663 | { |
637 | #if VERBOSE_SERVER | 664 | #if VERBOSE_SERVER |
638 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 665 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
639 | "Server: peer `%s' PUT on address `%s' received %Zu bytes\n", | 666 | "Server: peer `%s' PUT on address `%s' received %Zu bytes\n", |
640 | GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen), *upload_data_size); | 667 | GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, |
668 | s->addrlen), | ||
669 | *upload_data_size); | ||
641 | #endif | 670 | #endif |
642 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); | 671 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); |
643 | if (( s->next_receive.abs_value <= now.abs_value)) | 672 | |
673 | if ((s->next_receive.abs_value <= now.abs_value)) | ||
644 | { | 674 | { |
645 | #if VERBOSE_SERVER | 675 | #if VERBOSE_SERVER |
646 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 676 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
647 | "Server: %X: PUT with %u bytes forwarded to MST\n", s, | 677 | "Server: %X: PUT with %u bytes forwarded to MST\n", s, |
648 | *upload_data_size); | 678 | *upload_data_size); |
649 | #endif | 679 | #endif |
650 | if (s->msg_tk == NULL) | 680 | if (s->msg_tk == NULL) |
651 | { | 681 | { |
652 | s->msg_tk = GNUNET_SERVER_mst_create (&server_receive_mst_cb, s); | 682 | s->msg_tk = GNUNET_SERVER_mst_create (&server_receive_mst_cb, s); |
653 | } | 683 | } |
654 | res = GNUNET_SERVER_mst_receive (s->msg_tk, s, upload_data, *upload_data_size, GNUNET_NO, GNUNET_NO); | 684 | res = |
685 | GNUNET_SERVER_mst_receive (s->msg_tk, s, upload_data, | ||
686 | *upload_data_size, GNUNET_NO, GNUNET_NO); | ||
655 | 687 | ||
656 | #if MHD_VERSION >= 0x00090E00 | 688 | #if MHD_VERSION >= 0x00090E00 |
657 | int to = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value / 1000); | 689 | int to = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value / 1000); |
@@ -668,18 +700,22 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, | |||
668 | t = s->server_recv; | 700 | t = s->server_recv; |
669 | #if VERBOSE_SERVER | 701 | #if VERBOSE_SERVER |
670 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 702 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
671 | "Server: Setting timeout for %X to %u sec.\n", t, to); | 703 | "Server: Setting timeout for %X to %u sec.\n", t, |
704 | to); | ||
672 | #endif | 705 | #endif |
673 | MHD_set_connection_option (t->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, to); | 706 | MHD_set_connection_option (t->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, |
707 | to); | ||
674 | } | 708 | } |
675 | if (s->server_send != NULL) | 709 | if (s->server_send != NULL) |
676 | { | 710 | { |
677 | t = s->server_send; | 711 | t = s->server_send; |
678 | #if VERBOSE_SERVER | 712 | #if VERBOSE_SERVER |
679 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 713 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
680 | "Server: Setting timeout for %X to %u sec.\n", t, to); | 714 | "Server: Setting timeout for %X to %u sec.\n", t, |
715 | to); | ||
681 | #endif | 716 | #endif |
682 | MHD_set_connection_option (t->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, to); | 717 | MHD_set_connection_option (t->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, |
718 | to); | ||
683 | } | 719 | } |
684 | server_reschedule (plugin, GNUNET_NO); | 720 | server_reschedule (plugin, GNUNET_NO); |
685 | #endif | 721 | #endif |
@@ -688,8 +724,9 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, | |||
688 | else | 724 | else |
689 | { | 725 | { |
690 | #if DEBUG_HTTP | 726 | #if DEBUG_HTTP |
691 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 727 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
692 | "Server: %X no inbound bandwidth available! Next read was delayed by %llu ms\n", s, now.abs_value - s->next_receive.abs_value); | 728 | "Server: %X no inbound bandwidth available! Next read was delayed by %llu ms\n", |
729 | s, now.abs_value - s->next_receive.abs_value); | ||
693 | #endif | 730 | #endif |
694 | } | 731 | } |
695 | return MHD_YES; | 732 | return MHD_YES; |
@@ -706,22 +743,22 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, | |||
706 | { | 743 | { |
707 | struct ServerConnection *sc = *httpSessionCache; | 744 | struct ServerConnection *sc = *httpSessionCache; |
708 | struct ServerConnection *tc = *httpSessionCache; | 745 | struct ServerConnection *tc = *httpSessionCache; |
709 | struct Session * s = NULL; | 746 | struct Session *s = NULL; |
710 | struct Session * t = NULL; | 747 | struct Session *t = NULL; |
711 | struct Plugin * plugin = NULL; | 748 | struct Plugin *plugin = NULL; |
712 | 749 | ||
713 | if (sc == NULL) | 750 | if (sc == NULL) |
714 | return; | 751 | return; |
715 | 752 | ||
716 | s = sc->session; | 753 | s = sc->session; |
717 | plugin = s-> plugin; | 754 | plugin = s->plugin; |
718 | if (sc->direction == _SEND) | 755 | if (sc->direction == _SEND) |
719 | { | 756 | { |
720 | #if VERBOSE_SERVER | 757 | #if VERBOSE_SERVER |
721 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, | 758 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, |
722 | "Server: %X peer `%s' GET on address `%s' disconnected\n", | 759 | "Server: %X peer `%s' GET on address `%s' disconnected\n", |
723 | s->server_send, | 760 | s->server_send, GNUNET_i2s (&s->target), |
724 | GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen)); | 761 | GNUNET_a2s (s->addr, s->addrlen)); |
725 | #endif | 762 | #endif |
726 | s->server_send = NULL; | 763 | s->server_send = NULL; |
727 | 764 | ||
@@ -730,17 +767,18 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, | |||
730 | tc = s->server_recv; | 767 | tc = s->server_recv; |
731 | tc->disconnect = GNUNET_YES; | 768 | tc->disconnect = GNUNET_YES; |
732 | #if MHD_VERSION >= 0x00090E00 | 769 | #if MHD_VERSION >= 0x00090E00 |
733 | MHD_set_connection_option (sc->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, 1); | 770 | MHD_set_connection_option (sc->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, |
771 | 1); | ||
734 | #endif | 772 | #endif |
735 | } | 773 | } |
736 | } | 774 | } |
737 | if (sc->direction == _RECEIVE) | 775 | if (sc->direction == _RECEIVE) |
738 | { | 776 | { |
739 | #if VERBOSE_SERVER | 777 | #if VERBOSE_SERVER |
740 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, | 778 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, |
741 | "Server: %X peer `%s' PUT on address `%s' disconnected\n", | 779 | "Server: %X peer `%s' PUT on address `%s' disconnected\n", |
742 | s->server_recv, | 780 | s->server_recv, GNUNET_i2s (&s->target), |
743 | GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen)); | 781 | GNUNET_a2s (s->addr, s->addrlen)); |
744 | #endif | 782 | #endif |
745 | s->server_recv = NULL; | 783 | s->server_recv = NULL; |
746 | if (s->server_send != NULL) | 784 | if (s->server_send != NULL) |
@@ -748,13 +786,14 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, | |||
748 | tc = s->server_send; | 786 | tc = s->server_send; |
749 | tc->disconnect = GNUNET_YES; | 787 | tc->disconnect = GNUNET_YES; |
750 | #if MHD_VERSION >= 0x00090E00 | 788 | #if MHD_VERSION >= 0x00090E00 |
751 | MHD_set_connection_option (sc->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, 1); | 789 | MHD_set_connection_option (sc->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, |
790 | 1); | ||
752 | #endif | 791 | #endif |
753 | } | 792 | } |
754 | if (s->msg_tk != NULL) | 793 | if (s->msg_tk != NULL) |
755 | { | 794 | { |
756 | GNUNET_SERVER_mst_destroy(s->msg_tk); | 795 | GNUNET_SERVER_mst_destroy (s->msg_tk); |
757 | s->msg_tk = NULL; | 796 | s->msg_tk = NULL; |
758 | } | 797 | } |
759 | } | 798 | } |
760 | GNUNET_free (sc); | 799 | GNUNET_free (sc); |
@@ -764,8 +803,9 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, | |||
764 | { | 803 | { |
765 | if (t == s) | 804 | if (t == s) |
766 | { | 805 | { |
767 | GNUNET_CONTAINER_DLL_remove(plugin->server_semi_head, plugin->server_semi_tail, s); | 806 | GNUNET_CONTAINER_DLL_remove (plugin->server_semi_head, |
768 | GNUNET_CONTAINER_DLL_insert(plugin->head, plugin->tail, s); | 807 | plugin->server_semi_tail, s); |
808 | GNUNET_CONTAINER_DLL_insert (plugin->head, plugin->tail, s); | ||
769 | break; | 809 | break; |
770 | } | 810 | } |
771 | t = t->next; | 811 | t = t->next; |
@@ -777,17 +817,17 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, | |||
777 | if ((s->server_send == NULL) && (s->server_recv == NULL)) | 817 | if ((s->server_send == NULL) && (s->server_recv == NULL)) |
778 | { | 818 | { |
779 | #if VERBOSE_SERVER | 819 | #if VERBOSE_SERVER |
780 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 820 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
781 | "Server: peer `%s' on address `%s' disconnected\n", | 821 | "Server: peer `%s' on address `%s' disconnected\n", |
782 | GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen)); | 822 | GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen)); |
783 | #endif | 823 | #endif |
784 | if (s->msg_tk != NULL) | 824 | if (s->msg_tk != NULL) |
785 | { | 825 | { |
786 | GNUNET_SERVER_mst_destroy(s->msg_tk); | 826 | GNUNET_SERVER_mst_destroy (s->msg_tk); |
787 | s->msg_tk = NULL; | 827 | s->msg_tk = NULL; |
788 | } | 828 | } |
789 | 829 | ||
790 | notify_session_end(s->plugin, &s->target, s); | 830 | notify_session_end (s->plugin, &s->target, s); |
791 | } | 831 | } |
792 | } | 832 | } |
793 | 833 | ||
@@ -818,7 +858,7 @@ server_disconnect (struct Session *s) | |||
818 | } | 858 | } |
819 | 859 | ||
820 | int | 860 | int |
821 | server_send (struct Session *s, struct HTTP_Message * msg) | 861 | server_send (struct Session *s, struct HTTP_Message *msg) |
822 | { | 862 | { |
823 | GNUNET_CONTAINER_DLL_insert (s->msg_head, s->msg_tail, msg); | 863 | GNUNET_CONTAINER_DLL_insert (s->msg_head, s->msg_tail, msg); |
824 | server_reschedule (s->plugin, GNUNET_YES); | 864 | server_reschedule (s->plugin, GNUNET_YES); |
@@ -834,10 +874,10 @@ server_send (struct Session *s, struct HTTP_Message * msg) | |||
834 | * @param tc task context | 874 | * @param tc task context |
835 | */ | 875 | */ |
836 | static void | 876 | static void |
837 | server_v4_run (void *cls, | 877 | server_v4_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
838 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
839 | { | 878 | { |
840 | struct Plugin *plugin = cls; | 879 | struct Plugin *plugin = cls; |
880 | |||
841 | GNUNET_assert (cls != NULL); | 881 | GNUNET_assert (cls != NULL); |
842 | 882 | ||
843 | plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK; | 883 | plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK; |
@@ -847,7 +887,8 @@ server_v4_run (void *cls, | |||
847 | 887 | ||
848 | GNUNET_assert (MHD_YES == MHD_run (plugin->server_v4)); | 888 | GNUNET_assert (MHD_YES == MHD_run (plugin->server_v4)); |
849 | if (plugin->server_v4 != NULL) | 889 | if (plugin->server_v4 != NULL) |
850 | plugin->server_v4_task = server_schedule (plugin, plugin->server_v4, GNUNET_NO); | 890 | plugin->server_v4_task = |
891 | server_schedule (plugin, plugin->server_v4, GNUNET_NO); | ||
851 | } | 892 | } |
852 | 893 | ||
853 | 894 | ||
@@ -858,10 +899,10 @@ server_v4_run (void *cls, | |||
858 | * @param tc task context | 899 | * @param tc task context |
859 | */ | 900 | */ |
860 | static void | 901 | static void |
861 | server_v6_run (void *cls, | 902 | server_v6_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
862 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
863 | { | 903 | { |
864 | struct Plugin *plugin = cls; | 904 | struct Plugin *plugin = cls; |
905 | |||
865 | GNUNET_assert (cls != NULL); | 906 | GNUNET_assert (cls != NULL); |
866 | 907 | ||
867 | plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK; | 908 | plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK; |
@@ -871,7 +912,8 @@ server_v6_run (void *cls, | |||
871 | 912 | ||
872 | GNUNET_assert (MHD_YES == MHD_run (plugin->server_v6)); | 913 | GNUNET_assert (MHD_YES == MHD_run (plugin->server_v6)); |
873 | if (plugin->server_v6 != NULL) | 914 | if (plugin->server_v6 != NULL) |
874 | plugin->server_v6_task = server_schedule (plugin, plugin->server_v6, GNUNET_NO); | 915 | plugin->server_v6_task = |
916 | server_schedule (plugin, plugin->server_v6, GNUNET_NO); | ||
875 | } | 917 | } |
876 | 918 | ||
877 | /** | 919 | /** |
@@ -882,7 +924,8 @@ server_v6_run (void *cls, | |||
882 | * @return gnunet task identifier | 924 | * @return gnunet task identifier |
883 | */ | 925 | */ |
884 | static GNUNET_SCHEDULER_TaskIdentifier | 926 | static GNUNET_SCHEDULER_TaskIdentifier |
885 | server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle, int now) | 927 | server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle, |
928 | int now) | ||
886 | { | 929 | { |
887 | GNUNET_SCHEDULER_TaskIdentifier ret; | 930 | GNUNET_SCHEDULER_TaskIdentifier ret; |
888 | fd_set rs; | 931 | fd_set rs; |
@@ -909,7 +952,7 @@ server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle, int no | |||
909 | GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max)); | 952 | GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max)); |
910 | haveto = MHD_get_timeout (daemon_handle, &timeout); | 953 | haveto = MHD_get_timeout (daemon_handle, &timeout); |
911 | if (haveto == MHD_YES) | 954 | if (haveto == MHD_YES) |
912 | { | 955 | { |
913 | if (timeout != last_timeout) | 956 | if (timeout != last_timeout) |
914 | { | 957 | { |
915 | #if VERBOSE_SERVER | 958 | #if VERBOSE_SERVER |
@@ -920,7 +963,7 @@ server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle, int no | |||
920 | last_timeout = timeout; | 963 | last_timeout = timeout; |
921 | } | 964 | } |
922 | tv.rel_value = (uint64_t) timeout; | 965 | tv.rel_value = (uint64_t) timeout; |
923 | } | 966 | } |
924 | else | 967 | else |
925 | tv = GNUNET_TIME_UNIT_SECONDS; | 968 | tv = GNUNET_TIME_UNIT_SECONDS; |
926 | /* Force immediate run, since we have outbound data to send */ | 969 | /* Force immediate run, since we have outbound data to send */ |
@@ -972,7 +1015,7 @@ server_start (struct Plugin *plugin) | |||
972 | if (res == GNUNET_SYSERR) | 1015 | if (res == GNUNET_SYSERR) |
973 | { | 1016 | { |
974 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, | 1017 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, |
975 | "Could not load or create server certificate! Loading plugin failed!\n"); | 1018 | "Could not load or create server certificate! Loading plugin failed!\n"); |
976 | return res; | 1019 | return res; |
977 | } | 1020 | } |
978 | #endif | 1021 | #endif |
@@ -981,11 +1024,13 @@ server_start (struct Plugin *plugin) | |||
981 | #if MHD_VERSION >= 0x00090E00 | 1024 | #if MHD_VERSION >= 0x00090E00 |
982 | timeout = GNUNET_CONSTANTS_DISCONNECT_SESSION_TIMEOUT.rel_value / 1000; | 1025 | timeout = GNUNET_CONSTANTS_DISCONNECT_SESSION_TIMEOUT.rel_value / 1000; |
983 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 1026 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
984 | "MHD can set timeout per connection! Default time out %u sec.\n", timeout); | 1027 | "MHD can set timeout per connection! Default time out %u sec.\n", |
1028 | timeout); | ||
985 | #else | 1029 | #else |
986 | timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value / 1000; | 1030 | timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value / 1000; |
987 | GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name, | 1031 | GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name, |
988 | "MHD cannot set timeout per connection! Default time out %u sec.\n", timeout); | 1032 | "MHD cannot set timeout per connection! Default time out %u sec.\n", |
1033 | timeout); | ||
989 | #endif | 1034 | #endif |
990 | plugin->server_v4 = NULL; | 1035 | plugin->server_v4 = NULL; |
991 | if (plugin->ipv4 == GNUNET_YES) | 1036 | if (plugin->ipv4 == GNUNET_YES) |
@@ -1015,7 +1060,7 @@ server_start (struct Plugin *plugin) | |||
1015 | plugin->cert, | 1060 | plugin->cert, |
1016 | #endif | 1061 | #endif |
1017 | MHD_OPTION_CONNECTION_TIMEOUT, | 1062 | MHD_OPTION_CONNECTION_TIMEOUT, |
1018 | timeout , | 1063 | timeout, |
1019 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, | 1064 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, |
1020 | (size_t) (2 * | 1065 | (size_t) (2 * |
1021 | GNUNET_SERVER_MAX_MESSAGE_SIZE), | 1066 | GNUNET_SERVER_MAX_MESSAGE_SIZE), |
@@ -1066,15 +1111,15 @@ server_start (struct Plugin *plugin) | |||
1066 | if ((plugin->ipv4 == GNUNET_YES) && (plugin->server_v4 == NULL)) | 1111 | if ((plugin->ipv4 == GNUNET_YES) && (plugin->server_v4 == NULL)) |
1067 | { | 1112 | { |
1068 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, | 1113 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, |
1069 | "Failed to start %s IPv4 server component on port %u\n", plugin->name, | 1114 | "Failed to start %s IPv4 server component on port %u\n", |
1070 | plugin->port); | 1115 | plugin->name, plugin->port); |
1071 | return GNUNET_SYSERR; | 1116 | return GNUNET_SYSERR; |
1072 | } | 1117 | } |
1073 | if ((plugin->ipv6 == GNUNET_YES) && (plugin->server_v6 == NULL)) | 1118 | if ((plugin->ipv6 == GNUNET_YES) && (plugin->server_v6 == NULL)) |
1074 | { | 1119 | { |
1075 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, | 1120 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, |
1076 | "Failed to start %s IPv6 server component on port %u\n", plugin->name, | 1121 | "Failed to start %s IPv6 server component on port %u\n", |
1077 | plugin->port); | 1122 | plugin->name, plugin->port); |
1078 | return GNUNET_SYSERR; | 1123 | return GNUNET_SYSERR; |
1079 | } | 1124 | } |
1080 | 1125 | ||
@@ -1095,8 +1140,10 @@ server_stop (struct Plugin *plugin) | |||
1095 | struct Session *t = NULL; | 1140 | struct Session *t = NULL; |
1096 | 1141 | ||
1097 | struct MHD_Daemon *server_v4_tmp = plugin->server_v4; | 1142 | struct MHD_Daemon *server_v4_tmp = plugin->server_v4; |
1143 | |||
1098 | plugin->server_v4 = NULL; | 1144 | plugin->server_v4 = NULL; |
1099 | struct MHD_Daemon *server_v6_tmp = plugin->server_v6; | 1145 | struct MHD_Daemon *server_v6_tmp = plugin->server_v6; |
1146 | |||
1100 | plugin->server_v6 = NULL; | 1147 | plugin->server_v6 = NULL; |
1101 | 1148 | ||
1102 | if (plugin->server_v4_task != GNUNET_SCHEDULER_NO_TASK) | 1149 | if (plugin->server_v4_task != GNUNET_SCHEDULER_NO_TASK) |