diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-07-01 09:03:57 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-07-01 09:03:57 +0000 |
commit | 1126614c4ff98bb9ed25fff15b8e39759f9dc333 (patch) | |
tree | b1908c854203d9c2907deeea024e1d2ce17060a4 /src | |
parent | c2c2321102d8b2ce8cd3cba888138a6be86e2b87 (diff) | |
download | gnunet-1126614c4ff98bb9ed25fff15b8e39759f9dc333.tar.gz gnunet-1126614c4ff98bb9ed25fff15b8e39759f9dc333.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/plugin_transport_http.c | 81 |
1 files changed, 19 insertions, 62 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index 244c60fd8..c6fcc1c7d 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c | |||
@@ -426,32 +426,14 @@ static struct Session * session_get (void * cls, const struct GNUNET_PeerIdentit | |||
426 | static char * create_url(void * cls, const void * addr, size_t addrlen) | 426 | static char * create_url(void * cls, const void * addr, size_t addrlen) |
427 | { | 427 | { |
428 | struct Plugin *plugin = cls; | 428 | struct Plugin *plugin = cls; |
429 | char *address; | ||
430 | char *url = NULL; | 429 | char *url = NULL; |
431 | 430 | ||
432 | GNUNET_assert ((addr!=NULL) && (addrlen != 0)); | 431 | GNUNET_assert ((addr!=NULL) && (addrlen != 0)); |
433 | if (addrlen == (sizeof (struct IPv4HttpAddress))) | 432 | GNUNET_asprintf(&url, |
434 | { | 433 | "http://%s/%s", |
435 | address = GNUNET_malloc(INET_ADDRSTRLEN + 1); | 434 | http_plugin_address_to_string(NULL, addr, addrlen), |
436 | inet_ntop(AF_INET, &((struct IPv4HttpAddress *) addr)->ipv4_addr,address,INET_ADDRSTRLEN); | 435 | (char *) (&plugin->my_ascii_hash_ident)); |
437 | GNUNET_asprintf (&url, | 436 | |
438 | "http://%s:%u/%s", | ||
439 | address, | ||
440 | ntohs(((struct IPv4HttpAddress *) addr)->u_port), | ||
441 | (char *) (&plugin->my_ascii_hash_ident)); | ||
442 | GNUNET_free(address); | ||
443 | } | ||
444 | else if (addrlen == (sizeof (struct IPv6HttpAddress))) | ||
445 | { | ||
446 | address = GNUNET_malloc(INET6_ADDRSTRLEN + 1); | ||
447 | inet_ntop(AF_INET6, &((struct IPv6HttpAddress *) addr)->ipv6_addr,address,INET6_ADDRSTRLEN); | ||
448 | GNUNET_asprintf(&url, | ||
449 | "http://%s:%u/%s", | ||
450 | address, | ||
451 | ntohs(((struct IPv6HttpAddress *) addr)->u6_port), | ||
452 | (char *) (&plugin->my_ascii_hash_ident)); | ||
453 | GNUNET_free(address); | ||
454 | } | ||
455 | return url; | 437 | return url; |
456 | } | 438 | } |
457 | 439 | ||
@@ -504,7 +486,7 @@ static struct HTTP_Connection_out * session_check_outbound_address (void * cls, | |||
504 | /** | 486 | /** |
505 | * Check if session already knows this address for a inbound connection to this peer | 487 | * Check if session already knows this address for a inbound connection to this peer |
506 | * If address not in session, add it to the session | 488 | * If address not in session, add it to the session |
507 | * @param cls the plugin used | 489 | * @param cls not needed, can be NULL |
508 | * @param cs the session | 490 | * @param cs the session |
509 | * @param addr address | 491 | * @param addr address |
510 | * @param addr_len address length | 492 | * @param addr_len address length |
@@ -512,7 +494,6 @@ static struct HTTP_Connection_out * session_check_outbound_address (void * cls, | |||
512 | */ | 494 | */ |
513 | static struct HTTP_Connection_in * session_check_inbound_address (void * cls, struct Session *cs, const void * addr, size_t addr_len) | 495 | static struct HTTP_Connection_in * session_check_inbound_address (void * cls, struct Session *cs, const void * addr, size_t addr_len) |
514 | { | 496 | { |
515 | struct Plugin *plugin = cls; | ||
516 | struct HTTP_Connection_in * cc = cs->inbound_connections_head; | 497 | struct HTTP_Connection_in * cc = cs->inbound_connections_head; |
517 | struct HTTP_Connection_in * con = NULL; | 498 | struct HTTP_Connection_in * con = NULL; |
518 | 499 | ||
@@ -543,7 +524,9 @@ static struct HTTP_Connection_in * session_check_inbound_address (void * cls, st | |||
543 | GNUNET_CONTAINER_DLL_insert(cs->inbound_connections_head,cs->inbound_connections_tail,con); | 524 | GNUNET_CONTAINER_DLL_insert(cs->inbound_connections_head,cs->inbound_connections_tail,con); |
544 | } | 525 | } |
545 | 526 | ||
546 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection info for inbound address %s (%s:%u) was found\n",GNUNET_i2s(&cs->identity),http_plugin_address_to_string(plugin,con->addr,con->addrlen)); | 527 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection info for inbound address %s (%s) was found\n", |
528 | GNUNET_i2s(&cs->identity), | ||
529 | http_plugin_address_to_string(NULL,con->addr,con->addrlen)); | ||
547 | return con; | 530 | return con; |
548 | } | 531 | } |
549 | 532 | ||
@@ -575,7 +558,7 @@ static void messageTokenizerCallback (void *cls, | |||
575 | "Received message with type %u and size %u from `%s' %s\n", | 558 | "Received message with type %u and size %u from `%s' %s\n", |
576 | ntohs(message->type), | 559 | ntohs(message->type), |
577 | ntohs(message->size), | 560 | ntohs(message->size), |
578 | GNUNET_i2s(&(con->session->identity)),http_plugin_address_to_string(con,con->addr,con->addrlen)); | 561 | GNUNET_i2s(&(con->session->identity)),http_plugin_address_to_string(NULL,con->addr,con->addrlen)); |
579 | 562 | ||
580 | 563 | ||
581 | con->session->plugin->env->receive (con->session->plugin->env->cls, | 564 | con->session->plugin->env->receive (con->session->plugin->env->cls, |
@@ -638,7 +621,6 @@ accessHandlerCallback (void *cls, | |||
638 | 621 | ||
639 | GNUNET_assert(cls !=NULL); | 622 | GNUNET_assert(cls !=NULL); |
640 | send_error_to_client = GNUNET_NO; | 623 | send_error_to_client = GNUNET_NO; |
641 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"accessHandlerCallback\n"); | ||
642 | if (NULL == *httpSessionCache) | 624 | if (NULL == *httpSessionCache) |
643 | { | 625 | { |
644 | /* check url for peer identity , if invalid send HTTP 404*/ | 626 | /* check url for peer identity , if invalid send HTTP 404*/ |
@@ -694,7 +676,10 @@ accessHandlerCallback (void *cls, | |||
694 | if (con->msgtok==NULL) | 676 | if (con->msgtok==NULL) |
695 | con->msgtok = GNUNET_SERVER_mst_create (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, &messageTokenizerCallback, con); | 677 | con->msgtok = GNUNET_SERVER_mst_create (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, &messageTokenizerCallback, con); |
696 | 678 | ||
697 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Daemon has new an incoming `%s' request from peer `%s' (`%s')\n",method, GNUNET_i2s(&cs->identity),address); | 679 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Daemon has new an incoming `%s' request from peer `%s' (`%s')\n", |
680 | method, | ||
681 | GNUNET_i2s(&cs->identity), | ||
682 | http_plugin_address_to_string(NULL, con->addr, con->addrlen)); | ||
698 | } | 683 | } |
699 | 684 | ||
700 | if ((*upload_data_size == 0) && (con->is_put_in_progress==GNUNET_NO)) | 685 | if ((*upload_data_size == 0) && (con->is_put_in_progress==GNUNET_NO)) |
@@ -1298,48 +1283,21 @@ http_plugin_send (void *cls, | |||
1298 | void *cont_cls) | 1283 | void *cont_cls) |
1299 | { | 1284 | { |
1300 | struct Plugin *plugin = cls; | 1285 | struct Plugin *plugin = cls; |
1301 | char *address; | ||
1302 | char *url; | ||
1303 | struct Session *cs; | 1286 | struct Session *cs; |
1304 | struct HTTP_Message *msg; | 1287 | struct HTTP_Message *msg; |
1305 | struct HTTP_Connection_out *con; | 1288 | struct HTTP_Connection_out *con; |
1306 | //unsigned int ret; | 1289 | //unsigned int ret; |
1307 | 1290 | ||
1308 | GNUNET_assert(cls !=NULL); | 1291 | GNUNET_assert(cls !=NULL); |
1309 | url = NULL; | ||
1310 | address = NULL; | ||
1311 | uint16_t port; | ||
1312 | |||
1313 | GNUNET_assert ((addr!=NULL) && (addrlen != 0)); | 1292 | GNUNET_assert ((addr!=NULL) && (addrlen != 0)); |
1314 | if (addrlen == (sizeof (struct IPv4HttpAddress))) | ||
1315 | { | ||
1316 | port = ntohs(((struct IPv4HttpAddress *) addr)->u_port); | ||
1317 | address = GNUNET_malloc(INET_ADDRSTRLEN + 1); | ||
1318 | inet_ntop(AF_INET, &((struct IPv4HttpAddress *) addr)->ipv4_addr,address,INET_ADDRSTRLEN); | ||
1319 | GNUNET_asprintf (&url, | ||
1320 | "http://%s:%u/%s", | ||
1321 | address, | ||
1322 | port , | ||
1323 | (char *) (&plugin->my_ascii_hash_ident)); | ||
1324 | } | ||
1325 | else if (addrlen == (sizeof (struct IPv6HttpAddress))) | ||
1326 | { | ||
1327 | port = ntohs(((struct IPv6HttpAddress *) addr)->u6_port); | ||
1328 | address = GNUNET_malloc(INET6_ADDRSTRLEN + 1); | ||
1329 | inet_ntop(AF_INET6, &((struct IPv6HttpAddress *) addr)->ipv6_addr,address,INET6_ADDRSTRLEN); | ||
1330 | GNUNET_asprintf(&url, | ||
1331 | "http://%s:%u/%s", | ||
1332 | address, | ||
1333 | port, | ||
1334 | (char *) (&plugin->my_ascii_hash_ident)); | ||
1335 | |||
1336 | } | ||
1337 | 1293 | ||
1338 | /* get session from hashmap */ | 1294 | /* get session from hashmap */ |
1339 | cs = session_get(plugin, target); | 1295 | cs = session_get(plugin, target); |
1340 | con = session_check_outbound_address(plugin, cs, addr, addrlen); | 1296 | con = session_check_outbound_address(plugin, cs, addr, addrlen); |
1341 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Transport tells me to send %u bytes to `%s' %s:%u session: %X\n",msgbuf_size,GNUNET_i2s(&cs->identity),address,port,session); | 1297 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Transport tells me to send %u bytes to `%s' (%s), session: %X\n", |
1342 | GNUNET_free(address); | 1298 | msgbuf_size, GNUNET_i2s(&cs->identity), |
1299 | http_plugin_address_to_string(NULL, addr, addrlen), | ||
1300 | session); | ||
1343 | 1301 | ||
1344 | /* create msg */ | 1302 | /* create msg */ |
1345 | msg = GNUNET_malloc (sizeof (struct HTTP_Message) + msgbuf_size); | 1303 | msg = GNUNET_malloc (sizeof (struct HTTP_Message) + msgbuf_size); |
@@ -1548,10 +1506,9 @@ http_plugin_address_to_string (void *cls, | |||
1548 | struct sockaddr_in6 a6; | 1506 | struct sockaddr_in6 a6; |
1549 | char * address; | 1507 | char * address; |
1550 | char * ret; | 1508 | char * ret; |
1551 | unsigned int port; | 1509 | uint16_t port; |
1552 | unsigned int res; | 1510 | unsigned int res; |
1553 | 1511 | ||
1554 | GNUNET_assert(cls !=NULL); | ||
1555 | if (addrlen == sizeof (struct IPv6HttpAddress)) | 1512 | if (addrlen == sizeof (struct IPv6HttpAddress)) |
1556 | { | 1513 | { |
1557 | address = GNUNET_malloc (INET6_ADDRSTRLEN); | 1514 | address = GNUNET_malloc (INET6_ADDRSTRLEN); |