aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2010-07-01 08:43:07 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2010-07-01 08:43:07 +0000
commitbb8008b30082fc8096c3f407dd2e2f3e42442f47 (patch)
treed71cec03e40841117028ad0ae5d7d3098e20a0ad
parent7f892499d0af649861c9a4c06ffc778eba00635c (diff)
downloadgnunet-bb8008b30082fc8096c3f407dd2e2f3e42442f47.tar.gz
gnunet-bb8008b30082fc8096c3f407dd2e2f3e42442f47.zip
-rw-r--r--src/transport/plugin_transport_http.c64
1 files changed, 56 insertions, 8 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c
index 408023455..244c60fd8 100644
--- a/src/transport/plugin_transport_http.c
+++ b/src/transport/plugin_transport_http.c
@@ -338,6 +338,22 @@ struct Plugin
338 338
339 339
340/** 340/**
341 * Function called for a quick conversion of the binary address to
342 * a numeric address. Note that the caller must not free the
343 * address and that the next call to this function is allowed
344 * to override the address again.
345 *
346 * @param cls closure
347 * @param addr binary address
348 * @param addrlen length of the address
349 * @return string representing the same address
350 */
351static const char*
352http_plugin_address_to_string (void *cls,
353 const void *addr,
354 size_t addrlen);
355
356/**
341 * Create a new session 357 * Create a new session
342 * @param cls plugin as closure 358 * @param cls plugin as closure
343 * @param addr_in address the peer is using inbound 359 * @param addr_in address the peer is using inbound
@@ -496,7 +512,7 @@ static struct HTTP_Connection_out * session_check_outbound_address (void * cls,
496 */ 512 */
497static struct HTTP_Connection_in * session_check_inbound_address (void * cls, struct Session *cs, const void * addr, size_t addr_len) 513static struct HTTP_Connection_in * session_check_inbound_address (void * cls, struct Session *cs, const void * addr, size_t addr_len)
498{ 514{
499 //struct Plugin *plugin = cls; 515 struct Plugin *plugin = cls;
500 struct HTTP_Connection_in * cc = cs->inbound_connections_head; 516 struct HTTP_Connection_in * cc = cs->inbound_connections_head;
501 struct HTTP_Connection_in * con = NULL; 517 struct HTTP_Connection_in * con = NULL;
502 518
@@ -514,7 +530,8 @@ static struct HTTP_Connection_in * session_check_inbound_address (void * cls, st
514 } 530 }
515 cc=cc->next; 531 cc=cc->next;
516 } 532 }
517 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No connection info for this address was found\n",GNUNET_i2s(&cs->identity)); 533
534
518 if (con==NULL) 535 if (con==NULL)
519 { 536 {
520 con = GNUNET_malloc(sizeof(struct HTTP_Connection_in) + addr_len); 537 con = GNUNET_malloc(sizeof(struct HTTP_Connection_in) + addr_len);
@@ -525,6 +542,8 @@ static struct HTTP_Connection_in * session_check_inbound_address (void * cls, st
525 memcpy(con->addr, addr, addr_len); 542 memcpy(con->addr, addr, addr_len);
526 GNUNET_CONTAINER_DLL_insert(cs->inbound_connections_head,cs->inbound_connections_tail,con); 543 GNUNET_CONTAINER_DLL_insert(cs->inbound_connections_head,cs->inbound_connections_tail,con);
527 } 544 }
545
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));
528 return con; 547 return con;
529} 548}
530 549
@@ -545,7 +564,6 @@ static void requestCompletedCallback (void *cls, struct MHD_Connection * connect
545 con->is_bad_request = GNUNET_NO; 564 con->is_bad_request = GNUNET_NO;
546} 565}
547 566
548
549static void messageTokenizerCallback (void *cls, 567static void messageTokenizerCallback (void *cls,
550 void *client, 568 void *client,
551 const struct GNUNET_MessageHeader *message) 569 const struct GNUNET_MessageHeader *message)
@@ -554,10 +572,12 @@ static void messageTokenizerCallback (void *cls,
554 GNUNET_assert(con != NULL); 572 GNUNET_assert(con != NULL);
555 573
556 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 574 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
557 "Received message with type %u and size %u from `%s'\n", 575 "Received message with type %u and size %u from `%s' %s\n",
558 ntohs(message->type), 576 ntohs(message->type),
559 ntohs(message->size), 577 ntohs(message->size),
560 GNUNET_i2s(&(con->session->identity))); 578 GNUNET_i2s(&(con->session->identity)),http_plugin_address_to_string(con,con->addr,con->addrlen));
579
580
561 con->session->plugin->env->receive (con->session->plugin->env->cls, 581 con->session->plugin->env->receive (con->session->plugin->env->cls,
562 &con->session->identity, 582 &con->session->identity,
563 message, 1, con->session, 583 message, 1, con->session,
@@ -664,7 +684,7 @@ accessHandlerCallback (void *cls,
664 { 684 {
665 addrin6 = (struct sockaddr_in6 *) conn_info->client_addr; 685 addrin6 = (struct sockaddr_in6 *) conn_info->client_addr;
666 inet_ntop(addrin6->sin6_family, &(addrin6->sin6_addr),address,INET6_ADDRSTRLEN); 686 inet_ntop(addrin6->sin6_family, &(addrin6->sin6_addr),address,INET6_ADDRSTRLEN);
667 memcpy(&ipv6addr.ipv6_addr,&(addrin6->sin6_addr),sizeof(struct in_addr)); 687 memcpy(&ipv6addr.ipv6_addr,&(addrin6->sin6_addr),sizeof(struct in6_addr));
668 ipv6addr.u6_port = addrin6->sin6_port; 688 ipv6addr.u6_port = addrin6->sin6_port;
669 con = session_check_inbound_address (plugin, cs, &ipv6addr, sizeof (struct IPv6HttpAddress)); 689 con = session_check_inbound_address (plugin, cs, &ipv6addr, sizeof (struct IPv6HttpAddress));
670 } 690 }
@@ -998,6 +1018,8 @@ static size_t send_write_callback( void *stream, size_t size, size_t nmemb, void
998 */ 1018 */
999static size_t send_schedule(void *cls, struct Session* ses ); 1019static size_t send_schedule(void *cls, struct Session* ses );
1000 1020
1021
1022
1001/** 1023/**
1002 * Function setting up curl handle and selecting message to send 1024 * Function setting up curl handle and selecting message to send
1003 * @param cls plugin 1025 * @param cls plugin
@@ -1286,12 +1308,38 @@ http_plugin_send (void *cls,
1286 GNUNET_assert(cls !=NULL); 1308 GNUNET_assert(cls !=NULL);
1287 url = NULL; 1309 url = NULL;
1288 address = NULL; 1310 address = NULL;
1311 uint16_t port;
1312
1313 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 }
1289 1337
1290 /* get session from hashmap */ 1338 /* get session from hashmap */
1291 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Transport tells me to send %u bytes to %s, %u\n", msgbuf_size, GNUNET_i2s(target),addrlen);
1292 cs = session_get(plugin, target); 1339 cs = session_get(plugin, target);
1293 con = session_check_outbound_address(plugin, cs, addr, addrlen); 1340 con = session_check_outbound_address(plugin, cs, addr, addrlen);
1294 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Transport tells me to send %u bytes to peer `%s'\n",msgbuf_size,GNUNET_i2s(&cs->identity)); 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);
1342 GNUNET_free(address);
1295 1343
1296 /* create msg */ 1344 /* create msg */
1297 msg = GNUNET_malloc (sizeof (struct HTTP_Message) + msgbuf_size); 1345 msg = GNUNET_malloc (sizeof (struct HTTP_Message) + msgbuf_size);