diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-06-22 11:55:40 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-06-22 11:55:40 +0000 |
commit | 5b670ea4bc5f24fd6c17563a899bfcbbd325ef1d (patch) | |
tree | c3ee7d5cfe3286cb0355327286e2c4e8838f72ac | |
parent | 84c619a19da6eb9f7aed41f66c78efe02f43661a (diff) | |
download | gnunet-5b670ea4bc5f24fd6c17563a899bfcbbd325ef1d.tar.gz gnunet-5b670ea4bc5f24fd6c17563a899bfcbbd325ef1d.zip |
-rw-r--r-- | src/transport/plugin_transport_http.c | 66 |
1 files changed, 32 insertions, 34 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index ad1c2b863..49e3d6f3f 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c | |||
@@ -40,7 +40,7 @@ | |||
40 | #include <curl/curl.h> | 40 | #include <curl/curl.h> |
41 | 41 | ||
42 | 42 | ||
43 | #define DEBUG_CURL GNUNET_NO | 43 | #define DEBUG_CURL GNUNET_YES |
44 | #define DEBUG_HTTP GNUNET_NO | 44 | #define DEBUG_HTTP GNUNET_NO |
45 | 45 | ||
46 | /** | 46 | /** |
@@ -178,7 +178,7 @@ struct Session | |||
178 | * To whom are we talking to (set to our identity | 178 | * To whom are we talking to (set to our identity |
179 | * if we are still waiting for the welcome message) | 179 | * if we are still waiting for the welcome message) |
180 | */ | 180 | */ |
181 | struct GNUNET_PeerIdentity sender; | 181 | struct GNUNET_PeerIdentity partner; |
182 | 182 | ||
183 | /** | 183 | /** |
184 | * Sender's ip address to distinguish between incoming connections | 184 | * Sender's ip address to distinguish between incoming connections |
@@ -332,7 +332,7 @@ static struct Session * find_session_by_pi( const struct GNUNET_PeerIdentity *pe | |||
332 | hc_peer = peer->hashPubKey; | 332 | hc_peer = peer->hashPubKey; |
333 | while (cur != NULL) | 333 | while (cur != NULL) |
334 | { | 334 | { |
335 | hc_current = cur->sender.hashPubKey; | 335 | hc_current = cur->partner.hashPubKey; |
336 | if ( 0 == GNUNET_CRYPTO_hash_cmp( &hc_peer, &hc_current)) | 336 | if ( 0 == GNUNET_CRYPTO_hash_cmp( &hc_peer, &hc_current)) |
337 | return cur; | 337 | return cur; |
338 | cur = plugin->sessions->next; | 338 | cur = plugin->sessions->next; |
@@ -383,8 +383,8 @@ static struct Session * create_session (struct sockaddr_in *addr_in, struct sock | |||
383 | { | 383 | { |
384 | memcpy(ses->addr_outbound, addr_out, sizeof (struct sockaddr_in)); | 384 | memcpy(ses->addr_outbound, addr_out, sizeof (struct sockaddr_in)); |
385 | } | 385 | } |
386 | memcpy(&ses->sender, peer, sizeof (struct GNUNET_PeerIdentity)); | 386 | memcpy(&ses->partner, peer, sizeof (struct GNUNET_PeerIdentity)); |
387 | GNUNET_CRYPTO_hash_to_enc(&ses->sender.hashPubKey,&(ses->hash)); | 387 | GNUNET_CRYPTO_hash_to_enc(&ses->partner.hashPubKey,&(ses->hash)); |
388 | ses->is_active = GNUNET_NO; | 388 | ses->is_active = GNUNET_NO; |
389 | ses->addr_inbound_str = NULL; | 389 | ses->addr_inbound_str = NULL; |
390 | ses->pending_inbound_msg = GNUNET_malloc( sizeof (struct HTTP_Message)); | 390 | ses->pending_inbound_msg = GNUNET_malloc( sizeof (struct HTTP_Message)); |
@@ -405,7 +405,7 @@ static void requestCompletedCallback (void *cls, struct MHD_Connection * connect | |||
405 | cs = *httpSessionCache; | 405 | cs = *httpSessionCache; |
406 | if (cs != NULL) | 406 | if (cs != NULL) |
407 | { | 407 | { |
408 | /*GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection from peer `%s' was terminated\n",GNUNET_i2s(&cs->sender));*/ | 408 | /*GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection from peer `%s' was terminated\n",GNUNET_i2s(&cs->partner));*/ |
409 | /* session set to inactive */ | 409 | /* session set to inactive */ |
410 | cs->is_active = GNUNET_NO; | 410 | cs->is_active = GNUNET_NO; |
411 | cs->is_put_in_progress = GNUNET_NO; | 411 | cs->is_put_in_progress = GNUNET_NO; |
@@ -423,7 +423,8 @@ static void messageTokenizerCallback (void *cls, | |||
423 | struct Session * cs; | 423 | struct Session * cs; |
424 | GNUNET_assert(cls != NULL); | 424 | GNUNET_assert(cls != NULL); |
425 | cs = (struct Session *) cls; | 425 | cs = (struct Session *) cls; |
426 | plugin->env->receive(plugin->env->cls, &(cs->sender), message, 1, NULL , cs->addr_inbound_str, strlen(cs->addr_inbound_str)); | 426 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Recieved message with type %u and size %u from `%s'\n",message->size,message->type, GNUNET_i2s(&(cs->partner))); |
427 | plugin->env->receive(plugin->env->cls, &(cs->partner), message, 1, NULL , cs->addr_inbound_str, strlen(cs->addr_inbound_str)); | ||
427 | } | 428 | } |
428 | 429 | ||
429 | /** | 430 | /** |
@@ -505,7 +506,7 @@ accessHandlerCallback (void *cls, | |||
505 | cs = plugin->sessions; | 506 | cs = plugin->sessions; |
506 | while ( NULL != cs) | 507 | while ( NULL != cs) |
507 | { | 508 | { |
508 | res = (0 == memcmp(&pi_in,&(cs->sender), sizeof (struct GNUNET_PeerIdentity))) ? GNUNET_YES : GNUNET_NO; | 509 | res = (0 == memcmp(&pi_in,&(cs->partner), sizeof (struct GNUNET_PeerIdentity))) ? GNUNET_YES : GNUNET_NO; |
509 | if ( GNUNET_YES == res) | 510 | if ( GNUNET_YES == res) |
510 | break; | 511 | break; |
511 | cs = cs->next; | 512 | cs = cs->next; |
@@ -533,7 +534,7 @@ accessHandlerCallback (void *cls, | |||
533 | cs_temp->next = cs; | 534 | cs_temp->next = cs; |
534 | plugin->session_count++; | 535 | plugin->session_count++; |
535 | } | 536 | } |
536 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"New Session `%s' inserted, count %u \n", GNUNET_i2s(&cs->sender), plugin->session_count); | 537 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"New Session for peer `%s' inserted, count %u \n", GNUNET_i2s(&cs->partner), plugin->session_count); |
537 | } | 538 | } |
538 | 539 | ||
539 | /* Set closure and update current session*/ | 540 | /* Set closure and update current session*/ |
@@ -557,7 +558,7 @@ accessHandlerCallback (void *cls, | |||
557 | if (cs->msgtok==NULL) | 558 | if (cs->msgtok==NULL) |
558 | cs->msgtok = GNUNET_SERVER_mst_create (GNUNET_SERVER_MAX_MESSAGE_SIZE, cs, &messageTokenizerCallback, cs); | 559 | cs->msgtok = GNUNET_SERVER_mst_create (GNUNET_SERVER_MAX_MESSAGE_SIZE, cs, &messageTokenizerCallback, cs); |
559 | } | 560 | } |
560 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Daemon has new an incoming `%s' request from peer `%s' (`%s')\n",method, GNUNET_i2s(&cs->sender),cs->addr_inbound_str); | 561 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Daemon has new an incoming `%s' request from peer `%s' (`%s')\n",method, GNUNET_i2s(&cs->partner),cs->addr_inbound_str); |
561 | } | 562 | } |
562 | else | 563 | else |
563 | { | 564 | { |
@@ -573,7 +574,7 @@ accessHandlerCallback (void *cls, | |||
573 | { | 574 | { |
574 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 575 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
575 | _("Incoming message from peer `%s', while existing message with %u bytes was not forwarded to transport'\n"), | 576 | _("Incoming message from peer `%s', while existing message with %u bytes was not forwarded to transport'\n"), |
576 | GNUNET_i2s(&cs->sender), cs->pending_inbound_msg->pos); | 577 | GNUNET_i2s(&cs->partner), cs->pending_inbound_msg->pos); |
577 | cs->pending_inbound_msg->pos = 0; | 578 | cs->pending_inbound_msg->pos = 0; |
578 | } | 579 | } |
579 | /* not yet ready */ | 580 | /* not yet ready */ |
@@ -1004,24 +1005,23 @@ static void send_execute (void *cls, | |||
1004 | case CURLMSG_DONE: | 1005 | case CURLMSG_DONE: |
1005 | if ( (msg->data.result != CURLE_OK) && | 1006 | if ( (msg->data.result != CURLE_OK) && |
1006 | (msg->data.result != CURLE_GOT_NOTHING) ) | 1007 | (msg->data.result != CURLE_GOT_NOTHING) ) |
1007 | { | 1008 | { |
1008 | |||
1009 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1009 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1010 | _("%s failed for `%s' at %s:%d: `%s'\n"), | 1010 | _("%s failed for `%s' at %s:%d: `%s'\n"), |
1011 | "curl_multi_perform", | 1011 | "curl_multi_perform", |
1012 | GNUNET_i2s(&cs->sender), | 1012 | GNUNET_i2s(&cs->partner), |
1013 | __FILE__, | 1013 | __FILE__, |
1014 | __LINE__, | 1014 | __LINE__, |
1015 | curl_easy_strerror (msg->data.result)); | 1015 | curl_easy_strerror (msg->data.result)); |
1016 | /* sending msg failed*/ | 1016 | /* sending msg failed*/ |
1017 | if (( NULL != cs->pending_outbound_msg) && ( NULL != cs->pending_outbound_msg->transmit_cont)) | 1017 | if (( NULL != cs->pending_outbound_msg) && ( NULL != cs->pending_outbound_msg->transmit_cont)) |
1018 | cs->pending_outbound_msg->transmit_cont (cs->pending_outbound_msg->transmit_cont_cls,&cs->sender,GNUNET_SYSERR); | 1018 | cs->pending_outbound_msg->transmit_cont (cs->pending_outbound_msg->transmit_cont_cls,&cs->partner,GNUNET_SYSERR); |
1019 | } | 1019 | } |
1020 | else | 1020 | else |
1021 | { | 1021 | { |
1022 | 1022 | ||
1023 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1023 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1024 | "Send to peer `%s' completed with code %u\n", GNUNET_i2s(&cs->sender),cs->pending_outbound_msg->http_result_code); | 1024 | "Send to peer `%s' completed with code %u\n", GNUNET_i2s(&cs->partner),cs->pending_outbound_msg->http_result_code); |
1025 | 1025 | ||
1026 | curl_easy_cleanup(cs->curl_handle); | 1026 | curl_easy_cleanup(cs->curl_handle); |
1027 | cs->curl_handle=NULL; | 1027 | cs->curl_handle=NULL; |
@@ -1031,23 +1031,22 @@ static void send_execute (void *cls, | |||
1031 | { | 1031 | { |
1032 | /* HTTP 1xx : Last message before here was informational */ | 1032 | /* HTTP 1xx : Last message before here was informational */ |
1033 | if ((cs->pending_outbound_msg->http_result_code >=100) && (cs->pending_outbound_msg->http_result_code < 200)) | 1033 | if ((cs->pending_outbound_msg->http_result_code >=100) && (cs->pending_outbound_msg->http_result_code < 200)) |
1034 | cs->pending_outbound_msg->transmit_cont (cs->pending_outbound_msg->transmit_cont_cls,&cs->sender,GNUNET_OK); | 1034 | cs->pending_outbound_msg->transmit_cont (cs->pending_outbound_msg->transmit_cont_cls,&cs->partner,GNUNET_OK); |
1035 | /* HTTP 2xx: successful operations */ | 1035 | /* HTTP 2xx: successful operations */ |
1036 | if ((cs->pending_outbound_msg->http_result_code >=200) && (cs->pending_outbound_msg->http_result_code < 300)) | 1036 | if ((cs->pending_outbound_msg->http_result_code >=200) && (cs->pending_outbound_msg->http_result_code < 300)) |
1037 | cs->pending_outbound_msg->transmit_cont (cs->pending_outbound_msg->transmit_cont_cls,&cs->sender,GNUNET_OK); | 1037 | cs->pending_outbound_msg->transmit_cont (cs->pending_outbound_msg->transmit_cont_cls,&cs->partner,GNUNET_OK); |
1038 | /* HTTP 3xx..5xx: error */ | 1038 | /* HTTP 3xx..5xx: error */ |
1039 | if ((cs->pending_outbound_msg->http_result_code >=300) && (cs->pending_outbound_msg->http_result_code < 600)) | 1039 | if ((cs->pending_outbound_msg->http_result_code >=300) && (cs->pending_outbound_msg->http_result_code < 600)) |
1040 | cs->pending_outbound_msg->transmit_cont (cs->pending_outbound_msg->transmit_cont_cls,&cs->sender,GNUNET_SYSERR); | 1040 | cs->pending_outbound_msg->transmit_cont (cs->pending_outbound_msg->transmit_cont_cls,&cs->partner,GNUNET_SYSERR); |
1041 | } | ||
1042 | if (GNUNET_OK != remove_http_message(cs, cs->pending_outbound_msg)) | ||
1043 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message could not be removed from session `%s'", GNUNET_i2s(&cs->sender)); | ||
1044 | |||
1045 | /* send pending messages */ | ||
1046 | if (cs->pending_outbound_msg != NULL) | ||
1047 | { | ||
1048 | send_select_init (cs); | ||
1049 | } | 1041 | } |
1050 | } | 1042 | } |
1043 | if (GNUNET_OK != remove_http_message(cs, cs->pending_outbound_msg)) | ||
1044 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message could not be removed from session `%s'", GNUNET_i2s(&cs->partner)); | ||
1045 | /* send pending messages */ | ||
1046 | if (cs->pending_outbound_msg != NULL) | ||
1047 | { | ||
1048 | send_select_init (cs); | ||
1049 | } | ||
1051 | return; | 1050 | return; |
1052 | default: | 1051 | default: |
1053 | break; | 1052 | break; |
@@ -1241,7 +1240,6 @@ http_plugin_send (void *cls, | |||
1241 | msg->transmit_cont = cont; | 1240 | msg->transmit_cont = cont; |
1242 | msg->transmit_cont_cls = cont_cls; | 1241 | msg->transmit_cont_cls = cont_cls; |
1243 | memcpy (msg->buf,msgbuf, msgbuf_size); | 1242 | memcpy (msg->buf,msgbuf, msgbuf_size); |
1244 | |||
1245 | /* insert created message in list of pending messages */ | 1243 | /* insert created message in list of pending messages */ |
1246 | if (ses->pending_outbound_msg == NULL) | 1244 | if (ses->pending_outbound_msg == NULL) |
1247 | { | 1245 | { |
@@ -1256,8 +1254,8 @@ http_plugin_send (void *cls, | |||
1256 | { | 1254 | { |
1257 | tmp->next = msg; | 1255 | tmp->next = msg; |
1258 | } | 1256 | } |
1259 | 1257 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Plugin: sending %u bytes of data from peer `%4.4s' to peer `%s'\n",msgbuf_size,(char *) &my_ascii_hash_ident,GNUNET_i2s(target)); | |
1260 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Plugin: sending %u bytes of data from peer `%s' to peer `%s'\n",msgbuf_size,GNUNET_i2s(plugin->env->my_identity),GNUNET_i2s(&ses->sender)); | 1258 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Plugin: url `%s'\n",url); |
1261 | if (msg == ses->pending_outbound_msg) | 1259 | if (msg == ses->pending_outbound_msg) |
1262 | { | 1260 | { |
1263 | bytes_sent = send_select_init (ses); | 1261 | bytes_sent = send_select_init (ses); |
@@ -1572,7 +1570,7 @@ libgnunet_plugin_transport_http_done (void *cls) | |||
1572 | 1570 | ||
1573 | while ( NULL != cs) | 1571 | while ( NULL != cs) |
1574 | { | 1572 | { |
1575 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Freeing session for peer `%s'\n",GNUNET_i2s(&cs->sender)); | 1573 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Freeing session for peer `%s'\n",GNUNET_i2s(&cs->partner)); |
1576 | 1574 | ||
1577 | cs_next = cs->next; | 1575 | cs_next = cs->next; |
1578 | 1576 | ||
@@ -1584,8 +1582,8 @@ libgnunet_plugin_transport_http_done (void *cls) | |||
1584 | while (cur != NULL) | 1582 | while (cur != NULL) |
1585 | { | 1583 | { |
1586 | tmp = cur->next; | 1584 | tmp = cur->next; |
1587 | if (NULL != cur->buf) | 1585 | GNUNET_free_non_null(cur->dest_url); |
1588 | GNUNET_free (cur->buf); | 1586 | GNUNET_free_non_null (cur->buf); |
1589 | GNUNET_free (cur); | 1587 | GNUNET_free (cur); |
1590 | cur = tmp; | 1588 | cur = tmp; |
1591 | } | 1589 | } |