diff options
-rw-r--r-- | src/transport/plugin_transport_http.h | 2 | ||||
-rw-r--r-- | src/transport/plugin_transport_http_client.c | 25 | ||||
-rw-r--r-- | src/transport/plugin_transport_http_new.c | 94 | ||||
-rw-r--r-- | src/transport/plugin_transport_http_server.c | 92 |
4 files changed, 157 insertions, 56 deletions
diff --git a/src/transport/plugin_transport_http.h b/src/transport/plugin_transport_http.h index 5e452ba84..d11bbd15c 100644 --- a/src/transport/plugin_transport_http.h +++ b/src/transport/plugin_transport_http.h | |||
@@ -45,7 +45,7 @@ | |||
45 | #define DEBUG_HTTP GNUNET_YES | 45 | #define DEBUG_HTTP GNUNET_YES |
46 | #define VERBOSE_SERVER GNUNET_YES | 46 | #define VERBOSE_SERVER GNUNET_YES |
47 | #define VERBOSE_CLIENT GNUNET_YES | 47 | #define VERBOSE_CLIENT GNUNET_YES |
48 | #define VERBOSE_CURL GNUNET_NO | 48 | #define VERBOSE_CURL GNUNET_YES |
49 | 49 | ||
50 | #if BUILD_HTTPS | 50 | #if BUILD_HTTPS |
51 | #define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_https_init | 51 | #define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_https_init |
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index 3b3a4705b..224adb474 100644 --- a/src/transport/plugin_transport_http_client.c +++ b/src/transport/plugin_transport_http_client.c | |||
@@ -181,7 +181,7 @@ client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
181 | { | 181 | { |
182 | #if DEBUG_HTTP | 182 | #if DEBUG_HTTP |
183 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 183 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
184 | "Connection to '%s' %s ended\n", GNUNET_i2s(&s->target), http_plugin_address_to_string(plugin, s->addr, s->addrlen)); | 184 | "Connection to '%s' %s ended\n", GNUNET_i2s(&s->target), GNUNET_a2s (s->addr, s->addrlen)); |
185 | #endif | 185 | #endif |
186 | client_disconnect(s); | 186 | client_disconnect(s); |
187 | //GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,"Notifying about ended session to peer `%s' `%s'\n", GNUNET_i2s (&s->target), http_plugin_address_to_string (plugin, s->addr, s->addrlen)); | 187 | //GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,"Notifying about ended session to peer `%s' `%s'\n", GNUNET_i2s (&s->target), http_plugin_address_to_string (plugin, s->addr, s->addrlen)); |
@@ -206,9 +206,9 @@ client_disconnect (struct Session *s) | |||
206 | struct HTTP_Message * msg; | 206 | struct HTTP_Message * msg; |
207 | struct HTTP_Message * t; | 207 | struct HTTP_Message * t; |
208 | 208 | ||
209 | #if 0 | 209 | #if DEBUG_HTTP |
210 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 210 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
211 | "Deleting outbound PUT session to peer `%s'\n", | 211 | "Client: Deleting outbound PUT session to peer `%s'\n", |
212 | GNUNET_i2s (&s->target)); | 212 | GNUNET_i2s (&s->target)); |
213 | #endif | 213 | #endif |
214 | 214 | ||
@@ -227,7 +227,7 @@ client_disconnect (struct Session *s) | |||
227 | 227 | ||
228 | #if DEBUG_HTTP | 228 | #if DEBUG_HTTP |
229 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 229 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
230 | "Deleting outbound GET session to peer `%s'\n", | 230 | "Client: Deleting outbound GET session to peer `%s'\n", |
231 | GNUNET_i2s (&s->target)); | 231 | GNUNET_i2s (&s->target)); |
232 | #endif | 232 | #endif |
233 | 233 | ||
@@ -304,6 +304,12 @@ client_receive (void *stream, size_t size, size_t nmemb, void *cls) | |||
304 | struct Session *s = cls; | 304 | struct Session *s = cls; |
305 | struct Plugin *plugin = s->plugin; | 305 | struct Plugin *plugin = s->plugin; |
306 | 306 | ||
307 | #if VERBOSE_CLIENT | ||
308 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Client: Received %Zu bytes from peer `%s'\n", | ||
309 | size * nmemb, | ||
310 | GNUNET_i2s (&s->target)); | ||
311 | #endif | ||
312 | |||
307 | if (GNUNET_TIME_absolute_get().abs_value < s->delay.abs_value) | 313 | if (GNUNET_TIME_absolute_get().abs_value < s->delay.abs_value) |
308 | { | 314 | { |
309 | #if DEBUG_CLIENT | 315 | #if DEBUG_CLIENT |
@@ -314,17 +320,13 @@ client_receive (void *stream, size_t size, size_t nmemb, void *cls) | |||
314 | return 0; | 320 | return 0; |
315 | } | 321 | } |
316 | 322 | ||
323 | |||
317 | if (s->msg_tk == NULL) | 324 | if (s->msg_tk == NULL) |
318 | s->msg_tk = GNUNET_SERVER_mst_create (&client_receive_mst_cb, s); | 325 | s->msg_tk = GNUNET_SERVER_mst_create (&client_receive_mst_cb, s); |
319 | 326 | ||
320 | GNUNET_SERVER_mst_receive (s->msg_tk, s, stream, size * nmemb, GNUNET_NO, | 327 | GNUNET_SERVER_mst_receive (s->msg_tk, s, stream, size * nmemb, GNUNET_NO, |
321 | GNUNET_NO); | 328 | GNUNET_NO); |
322 | 329 | ||
323 | #if VERBOSE_CLIENT | ||
324 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Received %u bytes from peer `%s'\n", | ||
325 | size * nmemb, | ||
326 | GNUNET_i2s (&s->target)); | ||
327 | #endif | ||
328 | return (size * nmemb); | 330 | return (size * nmemb); |
329 | } | 331 | } |
330 | 332 | ||
@@ -389,9 +391,9 @@ client_send_cb (void *stream, size_t size, size_t nmemb, void *cls) | |||
389 | 391 | ||
390 | if (msg->pos == msg->size) | 392 | if (msg->pos == msg->size) |
391 | { | 393 | { |
392 | #if DEBUG_CONNECTIONS | 394 | #if VERBOSE_CLIENT |
393 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 395 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
394 | "Connection %X: Message with %u bytes sent, removing message from queue\n", | 396 | "Message with %u bytes sent, removing message from queue\n", |
395 | s, msg->pos); | 397 | s, msg->pos); |
396 | #endif | 398 | #endif |
397 | /* Calling transmit continuation */ | 399 | /* Calling transmit continuation */ |
@@ -422,6 +424,7 @@ client_connect (struct Session *s) | |||
422 | plugin->last_tag++; | 424 | plugin->last_tag++; |
423 | /* create url */ | 425 | /* create url */ |
424 | GNUNET_asprintf (&url, "%s%s;%u", http_plugin_address_to_string (plugin, s->addr, s->addrlen), GNUNET_h2s_full (&plugin->env->my_identity->hashPubKey),plugin->last_tag); | 426 | GNUNET_asprintf (&url, "%s%s;%u", http_plugin_address_to_string (plugin, s->addr, s->addrlen), GNUNET_h2s_full (&plugin->env->my_identity->hashPubKey),plugin->last_tag); |
427 | //GNUNET_asprintf (&url, "http://www.heise.de", http_plugin_address_to_string (plugin, s->addr, s->addrlen), GNUNET_h2s_full (&plugin->env->my_identity->hashPubKey),plugin->last_tag); | ||
425 | #if 0 | 428 | #if 0 |
426 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 429 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
427 | "URL `%s'\n", | 430 | "URL `%s'\n", |
diff --git a/src/transport/plugin_transport_http_new.c b/src/transport/plugin_transport_http_new.c index 48477b809..e998636b2 100644 --- a/src/transport/plugin_transport_http_new.c +++ b/src/transport/plugin_transport_http_new.c | |||
@@ -375,6 +375,7 @@ http_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) | |||
375 | 375 | ||
376 | struct Session * | 376 | struct Session * |
377 | lookup_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, | 377 | lookup_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, |
378 | struct Session * session, | ||
378 | const void *addr, size_t addrlen, int force_address) | 379 | const void *addr, size_t addrlen, int force_address) |
379 | { | 380 | { |
380 | struct Session *s = NULL; | 381 | struct Session *s = NULL; |
@@ -385,39 +386,79 @@ lookup_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, | |||
385 | t = plugin->head; | 386 | t = plugin->head; |
386 | if (t == NULL) | 387 | if (t == NULL) |
387 | return NULL; | 388 | return NULL; |
388 | while (t->next != NULL) | 389 | while (t != NULL) |
389 | { | 390 | { |
390 | e_peer = GNUNET_NO; | 391 | e_peer = GNUNET_NO; |
391 | e_addr = GNUNET_NO; | 392 | e_addr = GNUNET_NO; |
393 | |||
394 | #if DEBUG_HTTP | ||
395 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, | ||
396 | "Comparing session %X <-> %X\n", session, t); | ||
397 | #endif | ||
398 | |||
392 | if (0 == memcmp (target, &t->target, sizeof (struct GNUNET_PeerIdentity))) | 399 | if (0 == memcmp (target, &t->target, sizeof (struct GNUNET_PeerIdentity))) |
393 | { | 400 | { |
394 | e_peer = GNUNET_YES; | 401 | e_peer = GNUNET_YES; |
395 | if (addrlen == t->addrlen) | 402 | if (addrlen == t->addrlen) |
396 | { | 403 | { |
397 | if (0 == memcmp (addr, &t->addr, addrlen)) | 404 | if (0 == memcmp (addr, &t->addr, addrlen)) |
405 | { | ||
398 | e_addr = GNUNET_YES; | 406 | e_addr = GNUNET_YES; |
407 | } | ||
408 | } | ||
409 | if ((t == session)) | ||
410 | { | ||
411 | #if DEBUG_HTTP | ||
412 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, | ||
413 | "Session %X: %s: \n", t, GNUNET_a2s (t->addr, t->addrlen)); | ||
414 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, | ||
415 | "Session %X: %s: \n", session, GNUNET_a2s (session->addr, session->addrlen)); | ||
416 | |||
417 | #endif | ||
418 | if(t->addrlen == session->addrlen) | ||
419 | { | ||
420 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, | ||
421 | "length ok\n"); | ||
422 | if (0 == memcmp (session->addr, t->addr, t->addrlen)) | ||
423 | { | ||
424 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, | ||
425 | "equal\n"); | ||
426 | e_addr = GNUNET_YES; | ||
427 | } | ||
428 | } | ||
399 | } | 429 | } |
400 | } | 430 | } |
401 | 431 | ||
432 | #if DEBUG_HTTP | ||
433 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, | ||
434 | "Session %X: E_PEER YES : %i E_ADDR: %i force %u: \n", t, e_peer, e_addr, force_address); | ||
435 | #endif | ||
436 | |||
402 | if ((e_peer == GNUNET_YES) && (force_address == GNUNET_NO)) | 437 | if ((e_peer == GNUNET_YES) && (force_address == GNUNET_NO)) |
403 | { | 438 | { |
404 | s = t; | 439 | s = t; |
405 | break; | 440 | break; |
406 | } | 441 | } |
407 | else if ((e_peer == GNUNET_YES) && (force_address == GNUNET_YES) && | 442 | if ((e_peer == GNUNET_YES) && (force_address == GNUNET_YES) && (e_addr == GNUNET_YES)) |
408 | (e_addr == GNUNET_YES)) | ||
409 | { | 443 | { |
410 | s = t; | 444 | s = t; |
445 | #if DEBUG_HTTP | ||
446 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, | ||
447 | "Session %X: HERE!\n", t, e_addr, s); | ||
448 | #endif | ||
411 | break; | 449 | break; |
412 | } | 450 | } |
413 | else if ((e_peer == GNUNET_YES) && (force_address == GNUNET_SYSERR)) | 451 | if ((e_peer == GNUNET_YES) && (force_address == GNUNET_SYSERR)) |
414 | { | 452 | { |
415 | s = t; | 453 | s = t; |
416 | break; | 454 | break; |
417 | } | 455 | } |
456 | if (s != NULL) | ||
457 | break; | ||
418 | t = t->next; | 458 | t = t->next; |
419 | } | 459 | } |
420 | 460 | ||
461 | |||
421 | return s; | 462 | return s; |
422 | } | 463 | } |
423 | 464 | ||
@@ -514,15 +555,22 @@ http_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, | |||
514 | 555 | ||
515 | #if DEBUG_HTTP | 556 | #if DEBUG_HTTP |
516 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, | 557 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, |
517 | "Sending %u bytes to peer `%s'\n", msgbuf_size, | 558 | "Sending %u bytes to peer `%s' on address `%s' %X %i\n", msgbuf_size, |
518 | GNUNET_i2s (target)); | 559 | GNUNET_i2s (target), GNUNET_a2s (addr, addrlen), session, force_address); |
519 | #endif | 560 | #endif |
520 | 561 | ||
521 | struct Session *s = NULL; | 562 | struct Session *s = NULL; |
522 | 563 | ||
523 | /* look for existing connection */ | 564 | /* look for existing connection */ |
524 | s = lookup_session (plugin, target, addr, addrlen, force_address); | 565 | s = lookup_session (plugin, target, session, addr, addrlen, 1); |
525 | 566 | #if DEBUG_HTTP | |
567 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, | ||
568 | "%s exisiting session\n", (s!=NULL) ? "Found" : "NOT Found"); | ||
569 | #endif | ||
570 | // FIXME DEBUGGING | ||
571 | if (session != NULL) | ||
572 | s= session; | ||
573 | //FIXME END | ||
526 | /* create new outbound connection */ | 574 | /* create new outbound connection */ |
527 | if (s == NULL) | 575 | if (s == NULL) |
528 | { | 576 | { |
@@ -561,10 +609,26 @@ http_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, | |||
561 | memcpy (msg->buf, msgbuf, msgbuf_size); | 609 | memcpy (msg->buf, msgbuf, msgbuf_size); |
562 | 610 | ||
563 | if (s->inbound == GNUNET_NO) | 611 | if (s->inbound == GNUNET_NO) |
564 | res = client_send (s, msg); | 612 | { |
613 | #if DEBUG_HTTP | ||
614 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, | ||
615 | "Using client session to send to `%s'\n", | ||
616 | GNUNET_i2s (target)); | ||
617 | #endif | ||
618 | client_send (s, msg); | ||
619 | res = msgbuf_size; | ||
620 | } | ||
565 | if (s->inbound == GNUNET_YES) | 621 | if (s->inbound == GNUNET_YES) |
566 | res = server_send (s, msg); | 622 | { |
623 | server_send (s, msg); | ||
624 | res = msgbuf_size; | ||
625 | #if DEBUG_HTTP | ||
626 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, | ||
627 | "Using server session to send to `%s'\n", | ||
628 | GNUNET_i2s (target)); | ||
629 | #endif | ||
567 | 630 | ||
631 | } | ||
568 | return res; | 632 | return res; |
569 | } | 633 | } |
570 | 634 | ||
@@ -614,6 +678,8 @@ nat_connection_reversal (void *cls, const struct sockaddr *addr, | |||
614 | socklen_t addrlen) | 678 | socklen_t addrlen) |
615 | { | 679 | { |
616 | 680 | ||
681 | |||
682 | |||
617 | } | 683 | } |
618 | 684 | ||
619 | static void | 685 | static void |
@@ -771,7 +837,7 @@ nat_port_map_callback (void *cls, int add_remove, const struct sockaddr *addr, | |||
771 | { | 837 | { |
772 | GNUNET_assert (cls != NULL); | 838 | GNUNET_assert (cls != NULL); |
773 | struct Plugin *plugin = cls; | 839 | struct Plugin *plugin = cls; |
774 | 840 | static int limit; | |
775 | #if DEBUG_HTTP | 841 | #if DEBUG_HTTP |
776 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 842 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
777 | "NPMC called %s to address `%s'\n", | 843 | "NPMC called %s to address `%s'\n", |
@@ -782,7 +848,11 @@ nat_port_map_callback (void *cls, int add_remove, const struct sockaddr *addr, | |||
782 | switch (add_remove) | 848 | switch (add_remove) |
783 | { | 849 | { |
784 | case GNUNET_YES: | 850 | case GNUNET_YES: |
785 | nat_add_address (cls, add_remove, addr, addrlen); | 851 | // FIXME DEBUGGING |
852 | if (limit < 1) | ||
853 | nat_add_address (cls, add_remove, addr, addrlen); | ||
854 | limit++; | ||
855 | // FIXME END | ||
786 | break; | 856 | break; |
787 | case GNUNET_NO: | 857 | case GNUNET_NO: |
788 | nat_remove_address (cls, add_remove, addr, addrlen); | 858 | nat_remove_address (cls, add_remove, addr, addrlen); |
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c index 98fbfda1c..0c2ab54cf 100644 --- a/src/transport/plugin_transport_http_server.c +++ b/src/transport/plugin_transport_http_server.c | |||
@@ -37,7 +37,7 @@ server_log (void *arg, const char *fmt, va_list ap) | |||
37 | 37 | ||
38 | vsnprintf (text, sizeof (text), fmt, ap); | 38 | vsnprintf (text, sizeof (text), fmt, ap); |
39 | va_end (ap); | 39 | va_end (ap); |
40 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "server: %s\n", text); | 40 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Server: %s\n", text); |
41 | } | 41 | } |
42 | 42 | ||
43 | struct ServerConnection | 43 | struct ServerConnection |
@@ -70,7 +70,7 @@ server_accept_cb (void *cls, const struct sockaddr *addr, socklen_t addr_len) | |||
70 | return MHD_YES; | 70 | return MHD_YES; |
71 | else | 71 | else |
72 | { | 72 | { |
73 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "server: Cannot accept new connections\n"); | 73 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Server: Cannot accept new connections\n"); |
74 | return MHD_NO; | 74 | return MHD_NO; |
75 | } | 75 | } |
76 | } | 76 | } |
@@ -267,12 +267,12 @@ server_receive_mst_cb (void *cls, void *client, | |||
267 | * @return bytes written to buffer | 267 | * @return bytes written to buffer |
268 | */ | 268 | */ |
269 | static ssize_t | 269 | static ssize_t |
270 | mhd_send_callback (void *cls, uint64_t pos, char *buf, size_t max) | 270 | server_send_callback (void *cls, uint64_t pos, char *buf, size_t max) |
271 | { | 271 | { |
272 | struct Session *s = cls; | 272 | struct Session *s = cls; |
273 | struct HTTP_Message *msg; | 273 | struct HTTP_Message *msg; |
274 | int bytes_read = 0; | 274 | int bytes_read = 0; |
275 | 275 | //static int c = 0; | |
276 | msg = s->msg_head; | 276 | msg = s->msg_head; |
277 | if (msg != NULL) | 277 | if (msg != NULL) |
278 | { | 278 | { |
@@ -299,7 +299,8 @@ mhd_send_callback (void *cls, uint64_t pos, char *buf, size_t max) | |||
299 | GNUNET_free (msg); | 299 | GNUNET_free (msg); |
300 | } | 300 | } |
301 | } | 301 | } |
302 | #if DEBUG_CONNECTIONS | 302 | |
303 | #if VERBOSE_CLIENT | ||
303 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connection %X: MHD has sent %u bytes\n", | 304 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connection %X: MHD has sent %u bytes\n", |
304 | s, bytes_read); | 305 | s, bytes_read); |
305 | #endif | 306 | #endif |
@@ -371,7 +372,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, | |||
371 | plugin->cur_connections++; | 372 | plugin->cur_connections++; |
372 | 373 | ||
373 | #if VERBOSE_SERVER | 374 | #if VERBOSE_SERVER |
374 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "server: New inbound connection from %s with tag %u\n", GNUNET_h2s_full(&(target.hashPubKey)), tag); | 375 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server: New inbound connection from %s with tag %u\n", GNUNET_i2s(&target), tag); |
375 | #endif | 376 | #endif |
376 | /* find duplicate session */ | 377 | /* find duplicate session */ |
377 | 378 | ||
@@ -388,7 +389,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, | |||
388 | if (t != NULL) | 389 | if (t != NULL) |
389 | { | 390 | { |
390 | #if VERBOSE_SERVER | 391 | #if VERBOSE_SERVER |
391 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "server: Duplicate session, dismissing new connection from peer `%s'\n", GNUNET_i2s (&target)); | 392 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server: Duplicate session, dismissing new connection from peer `%s'\n", GNUNET_i2s (&target)); |
392 | #endif | 393 | #endif |
393 | goto error; | 394 | goto error; |
394 | } | 395 | } |
@@ -411,13 +412,13 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, | |||
411 | goto create; | 412 | goto create; |
412 | 413 | ||
413 | #if VERBOSE_SERVER | 414 | #if VERBOSE_SERVER |
414 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "server: Found existing semi-session for `%s'\n", GNUNET_i2s (&target)); | 415 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server: Found existing semi-session for `%s'\n", GNUNET_i2s (&target)); |
415 | #endif | 416 | #endif |
416 | 417 | ||
417 | if ((direction == _SEND) && (t->server_send != NULL)) | 418 | if ((direction == _SEND) && (t->server_send != NULL)) |
418 | { | 419 | { |
419 | #if VERBOSE_SERVER | 420 | #if VERBOSE_SERVER |
420 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "server: Duplicate GET session, dismissing new connection from peer `%s'\n", GNUNET_i2s (&target)); | 421 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server: Duplicate GET session, dismissing new connection from peer `%s'\n", GNUNET_i2s (&target)); |
421 | #endif | 422 | #endif |
422 | goto error; | 423 | goto error; |
423 | } | 424 | } |
@@ -427,7 +428,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, | |||
427 | GNUNET_CONTAINER_DLL_remove(plugin->server_semi_head, plugin->server_semi_tail, s); | 428 | GNUNET_CONTAINER_DLL_remove(plugin->server_semi_head, plugin->server_semi_tail, s); |
428 | GNUNET_CONTAINER_DLL_insert(plugin->head, plugin->tail, s); | 429 | GNUNET_CONTAINER_DLL_insert(plugin->head, plugin->tail, s); |
429 | #if VERBOSE_SERVER | 430 | #if VERBOSE_SERVER |
430 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "server: Found matching semi-session, merging session for peer `%s'\n", GNUNET_i2s (&target)); | 431 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server: Found matching semi-session, merging session for peer `%s'\n", GNUNET_i2s (&target)); |
431 | #endif | 432 | #endif |
432 | 433 | ||
433 | goto found; | 434 | goto found; |
@@ -435,7 +436,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, | |||
435 | if ((direction == _RECEIVE) && (t->server_recv != NULL)) | 436 | if ((direction == _RECEIVE) && (t->server_recv != NULL)) |
436 | { | 437 | { |
437 | #if VERBOSE_SERVER | 438 | #if VERBOSE_SERVER |
438 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "server: Duplicate PUT session, dismissing new connection from peer `%s'\n", GNUNET_i2s (&target)); | 439 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server: Duplicate PUT session, dismissing new connection from peer `%s'\n", GNUNET_i2s (&target)); |
439 | #endif | 440 | #endif |
440 | goto error; | 441 | goto error; |
441 | } | 442 | } |
@@ -445,7 +446,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, | |||
445 | GNUNET_CONTAINER_DLL_remove(plugin->server_semi_head, plugin->server_semi_tail, s); | 446 | GNUNET_CONTAINER_DLL_remove(plugin->server_semi_head, plugin->server_semi_tail, s); |
446 | GNUNET_CONTAINER_DLL_insert(plugin->head, plugin->tail, s); | 447 | GNUNET_CONTAINER_DLL_insert(plugin->head, plugin->tail, s); |
447 | #if VERBOSE_SERVER | 448 | #if VERBOSE_SERVER |
448 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "server: Found matching semi-session, merging session for peer `%s'\n", GNUNET_i2s (&target)); | 449 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server: Found matching semi-session, merging session for peer `%s'\n", GNUNET_i2s (&target)); |
449 | #endif | 450 | #endif |
450 | goto found; | 451 | goto found; |
451 | } | 452 | } |
@@ -453,7 +454,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, | |||
453 | create: | 454 | create: |
454 | /* create new session */ | 455 | /* create new session */ |
455 | #if VERBOSE_SERVER | 456 | #if VERBOSE_SERVER |
456 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "server: Creating new session for peer `%s' \n", GNUNET_i2s (&target)); | 457 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server: Creating new session for peer `%s' \n", GNUNET_i2s (&target)); |
457 | #endif | 458 | #endif |
458 | 459 | ||
459 | s = create_session(plugin, | 460 | s = create_session(plugin, |
@@ -473,7 +474,7 @@ create: | |||
473 | 474 | ||
474 | goto found; | 475 | goto found; |
475 | error: | 476 | error: |
476 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "server: Invalid connection request\n"); | 477 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Server: Invalid connection request\n"); |
477 | response = MHD_create_response_from_data (strlen (HTTP_ERROR_RESPONSE),HTTP_ERROR_RESPONSE, MHD_NO, MHD_NO); | 478 | response = MHD_create_response_from_data (strlen (HTTP_ERROR_RESPONSE),HTTP_ERROR_RESPONSE, MHD_NO, MHD_NO); |
478 | res = MHD_queue_response (mhd_connection, MHD_HTTP_NOT_FOUND, response); | 479 | res = MHD_queue_response (mhd_connection, MHD_HTTP_NOT_FOUND, response); |
479 | MHD_destroy_response (response); | 480 | MHD_destroy_response (response); |
@@ -488,6 +489,10 @@ found: | |||
488 | if (direction == _RECEIVE) | 489 | if (direction == _RECEIVE) |
489 | s->server_recv = sc; | 490 | s->server_recv = sc; |
490 | 491 | ||
492 | int to = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value / 1000); | ||
493 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Server: Setting Timeout to %u\n", to); | ||
494 | //MHD_set_connection_option (mhd_connection, MHD_CONNECTION_OPTION_TIMEOUT, to); | ||
495 | |||
491 | (*httpSessionCache) = sc; | 496 | (*httpSessionCache) = sc; |
492 | } | 497 | } |
493 | 498 | ||
@@ -512,8 +517,7 @@ found: | |||
512 | GNUNET_assert (s != NULL); | 517 | GNUNET_assert (s != NULL); |
513 | if (sc->direction == _SEND) | 518 | if (sc->direction == _SEND) |
514 | { | 519 | { |
515 | response = | 520 | response = MHD_create_response_from_callback (-1, 32 * 1024, &server_send_callback, |
516 | MHD_create_response_from_callback (-1, 32 * 1024, &mhd_send_callback, | ||
517 | s, NULL); | 521 | s, NULL); |
518 | res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response); | 522 | res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response); |
519 | MHD_destroy_response (response); | 523 | MHD_destroy_response (response); |
@@ -536,8 +540,8 @@ found: | |||
536 | { | 540 | { |
537 | #if VERBOSE_SERVER | 541 | #if VERBOSE_SERVER |
538 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 542 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
539 | "Server: peer `%s' PUT on address `%s' received %u bytes\n", | 543 | "Server: peer `%s' PUT on address `%s' received %Zu bytes\n", |
540 | GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen)); | 544 | GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen), *upload_data_size); |
541 | #endif | 545 | #endif |
542 | if ((GNUNET_TIME_absolute_get().abs_value < s->delay.abs_value)) | 546 | if ((GNUNET_TIME_absolute_get().abs_value < s->delay.abs_value)) |
543 | { | 547 | { |
@@ -551,7 +555,7 @@ found: | |||
551 | } | 555 | } |
552 | res = GNUNET_SERVER_mst_receive (s->msg_tk, s, upload_data, *upload_data_size, GNUNET_NO, GNUNET_NO); | 556 | res = GNUNET_SERVER_mst_receive (s->msg_tk, s, upload_data, *upload_data_size, GNUNET_NO, GNUNET_NO); |
553 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 557 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
554 | "Server: Received %u bytes\n", | 558 | "Server: Received %Zu bytes\n", |
555 | *upload_data_size); | 559 | *upload_data_size); |
556 | (*upload_data_size) = 0; | 560 | (*upload_data_size) = 0; |
557 | } | 561 | } |
@@ -573,6 +577,16 @@ found: | |||
573 | return res; | 577 | return res; |
574 | } | 578 | } |
575 | 579 | ||
580 | /** | ||
581 | * Function that queries MHD's select sets and | ||
582 | * starts the task waiting for them. | ||
583 | * @param plugin plugin | ||
584 | * @param daemon_handle the MHD daemon handle | ||
585 | * @return gnunet task identifier | ||
586 | */ | ||
587 | static GNUNET_SCHEDULER_TaskIdentifier | ||
588 | server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle); | ||
589 | |||
576 | static void | 590 | static void |
577 | server_disconnect_cb (void *cls, struct MHD_Connection *connection, | 591 | server_disconnect_cb (void *cls, struct MHD_Connection *connection, |
578 | void **httpSessionCache) | 592 | void **httpSessionCache) |
@@ -592,33 +606,37 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, | |||
592 | { | 606 | { |
593 | #if VERBOSE_SERVER | 607 | #if VERBOSE_SERVER |
594 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 608 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
595 | "Server: peer `%s' PUT on address `%s' disconnected\n", | 609 | "Server: peer `%s' GET on address `%s' disconnected\n", |
596 | GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen)); | 610 | GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen)); |
597 | #endif | 611 | #endif |
598 | s->server_send = NULL; | 612 | s->server_send = NULL; |
599 | /* FIXME miminimize timeout here */ | 613 | |
600 | if (s->server_recv != NULL) | 614 | if (s->server_recv != NULL) |
601 | { | 615 | { |
602 | tc = s->server_recv; | 616 | tc = s->server_recv; |
603 | tc->disconnect = GNUNET_YES; | 617 | tc->disconnect = GNUNET_YES; |
618 | MHD_set_connection_option (sc->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, 1); | ||
604 | } | 619 | } |
605 | } | 620 | } |
606 | if (sc->direction == _RECEIVE) | 621 | if (sc->direction == _RECEIVE) |
607 | { | 622 | { |
608 | #if VERBOSE_SERVER | 623 | #if VERBOSE_SERVER |
609 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 624 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
610 | "Server: peer `%s' GET on address `%s' disconnected\n", | 625 | "Server: peer `%s' PUT on address `%s' disconnected\n", |
611 | GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen)); | 626 | GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen)); |
612 | #endif | 627 | #endif |
613 | s->server_recv = NULL; | 628 | s->server_recv = NULL; |
614 | //MHD_ | ||
615 | if (s->server_send != NULL) | 629 | if (s->server_send != NULL) |
616 | { | 630 | { |
617 | tc = s->server_send; | 631 | tc = s->server_send; |
618 | tc->disconnect = GNUNET_YES; | 632 | tc->disconnect = GNUNET_YES; |
633 | MHD_set_connection_option (sc->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, 1); | ||
619 | } | 634 | } |
620 | if (s->msg_tk != NULL) | 635 | if (s->msg_tk != NULL) |
636 | { | ||
621 | GNUNET_SERVER_mst_destroy(s->msg_tk); | 637 | GNUNET_SERVER_mst_destroy(s->msg_tk); |
638 | s->msg_tk = NULL; | ||
639 | } | ||
622 | } | 640 | } |
623 | GNUNET_free (sc); | 641 | GNUNET_free (sc); |
624 | 642 | ||
@@ -635,6 +653,19 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, | |||
635 | } | 653 | } |
636 | plugin->cur_connections--; | 654 | plugin->cur_connections--; |
637 | 655 | ||
656 | if (plugin->server_v4_task != GNUNET_SCHEDULER_NO_TASK) | ||
657 | { | ||
658 | GNUNET_SCHEDULER_cancel(plugin->server_v4_task); | ||
659 | plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK; | ||
660 | } | ||
661 | plugin->server_v4_task = server_schedule (plugin, plugin->server_v4); | ||
662 | |||
663 | if (plugin->server_v6_task != GNUNET_SCHEDULER_NO_TASK) | ||
664 | { | ||
665 | GNUNET_SCHEDULER_cancel(plugin->server_v6_task); | ||
666 | plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK; | ||
667 | } | ||
668 | plugin->server_v6_task = server_schedule (plugin, plugin->server_v6); | ||
638 | 669 | ||
639 | if ((s->server_send == NULL) && (s->server_recv == NULL)) | 670 | if ((s->server_send == NULL) && (s->server_recv == NULL)) |
640 | { | 671 | { |
@@ -643,6 +674,11 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, | |||
643 | "Server: peer `%s' on address `%s' disconnected\n", | 674 | "Server: peer `%s' on address `%s' disconnected\n", |
644 | GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen)); | 675 | GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen)); |
645 | #endif | 676 | #endif |
677 | if (s->msg_tk != NULL) | ||
678 | { | ||
679 | GNUNET_SERVER_mst_destroy(s->msg_tk); | ||
680 | s->msg_tk = NULL; | ||
681 | } | ||
646 | 682 | ||
647 | notify_session_end(s->plugin, &s->target, s); | 683 | notify_session_end(s->plugin, &s->target, s); |
648 | } | 684 | } |
@@ -681,15 +717,7 @@ server_send (struct Session *s, struct HTTP_Message * msg) | |||
681 | return GNUNET_OK; | 717 | return GNUNET_OK; |
682 | } | 718 | } |
683 | 719 | ||
684 | /** | 720 | |
685 | * Function that queries MHD's select sets and | ||
686 | * starts the task waiting for them. | ||
687 | * @param plugin plugin | ||
688 | * @param daemon_handle the MHD daemon handle | ||
689 | * @return gnunet task identifier | ||
690 | */ | ||
691 | static GNUNET_SCHEDULER_TaskIdentifier | ||
692 | server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle); | ||
693 | 721 | ||
694 | /** | 722 | /** |
695 | * Call MHD IPv4 to process pending requests and then go back | 723 | * Call MHD IPv4 to process pending requests and then go back |