aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-01-26 14:09:44 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-01-26 14:09:44 +0000
commitd942e62f877b930e633e512e33548c387b97c726 (patch)
tree1b2ab3b098c3cab75fa3b9ce2740836c30db02b4 /src
parentf3dbebee8b087c25aab0cef0a0228845a8954596 (diff)
downloadgnunet-d942e62f877b930e633e512e33548c387b97c726.tar.gz
gnunet-d942e62f877b930e633e512e33548c387b97c726.zip
implemented session based sending in transport service (coexisting with old code)
Diffstat (limited to 'src')
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c122
-rw-r--r--src/transport/plugin_transport_http.c19
-rw-r--r--src/transport/plugin_transport_http_server.c5
3 files changed, 109 insertions, 37 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 3d35a52d2..ddbbe843a 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -630,6 +630,11 @@ send_with_plugin (const struct GNUNET_PeerIdentity *target, const char *msgbuf,
630 const struct GNUNET_HELLO_Address *address, int force_address, 630 const struct GNUNET_HELLO_Address *address, int force_address,
631 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) 631 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
632{ 632{
633#if TEST_NEW_CODE
634 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
635 "Call to depracted function send_with_plugin\n");
636#endif
637
633 struct GNUNET_TRANSPORT_PluginFunctions *papi; 638 struct GNUNET_TRANSPORT_PluginFunctions *papi;
634 size_t ret = GNUNET_SYSERR; 639 size_t ret = GNUNET_SYSERR;
635 640
@@ -787,10 +792,19 @@ try_transmission_to_peer (struct NeighbourMapEntry *n)
787 return; 792 return;
788 } 793 }
789 794
790 ret = 795#if TEST_NEW_CODE
791 send_with_plugin (&n->id, mq->message_buf, mq->message_buf_size, 0, 796 ret = send_with_session(n, n->session,
792 timeout, n->session, n->address, GNUNET_YES, 797 mq->message_buf, mq->message_buf_size,
793 &transmit_send_continuation, mq); 798 0, timeout,
799 &transmit_send_continuation, mq);
800#else
801 ret = send_with_plugin (&n->id,
802 mq->message_buf, mq->message_buf_size,
803 0, timeout,
804 n->session, n->address, GNUNET_YES,
805 &transmit_send_continuation, mq);
806#endif
807
794 if (ret == -1) 808 if (ret == -1)
795 { 809 {
796 /* failure, but 'send' would not call continuation in this case, 810 /* failure, but 'send' would not call continuation in this case,
@@ -849,9 +863,7 @@ send_disconnect_cont (void *cls, const struct GNUNET_PeerIdentity *target,
849 863
850 864
851static int 865static int
852send_disconnect (const struct GNUNET_PeerIdentity *target, 866send_disconnect (struct NeighbourMapEntry * n)
853 const struct GNUNET_HELLO_Address *address,
854 struct Session *session)
855{ 867{
856 size_t ret; 868 size_t ret;
857 struct SessionDisconnectMessage disconnect_msg; 869 struct SessionDisconnectMessage disconnect_msg;
@@ -880,11 +892,18 @@ send_disconnect (const struct GNUNET_PeerIdentity *target,
880 &disconnect_msg.purpose, 892 &disconnect_msg.purpose,
881 &disconnect_msg.signature)); 893 &disconnect_msg.signature));
882 894
883 ret = 895#if TEST_NEW_CODE
884 send_with_plugin (target, (const char *) &disconnect_msg, 896 ret = send_with_session (n,n->session,
885 sizeof (disconnect_msg), UINT32_MAX, 897 (const char *) &disconnect_msg, sizeof (disconnect_msg),
886 GNUNET_TIME_UNIT_FOREVER_REL, session, address, 898 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL,
899 &send_disconnect_cont, NULL);
900#else
901 ret = send_with_plugin (&n->id,
902 (const char *) &disconnect_msg, sizeof (disconnect_msg),
903 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL,
904 n->session, n->address,
887 GNUNET_YES, &send_disconnect_cont, NULL); 905 GNUNET_YES, &send_disconnect_cont, NULL);
906#endif
888 907
889 if (ret == GNUNET_SYSERR) 908 if (ret == GNUNET_SYSERR)
890 return GNUNET_SYSERR; 909 return GNUNET_SYSERR;
@@ -916,7 +935,7 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
916 /* send DISCONNECT MESSAGE */ 935 /* send DISCONNECT MESSAGE */
917 if (previous_state == S_CONNECTED) 936 if (previous_state == S_CONNECTED)
918 { 937 {
919 if (GNUNET_OK == send_disconnect (&n->id, n->address, n->session)) 938 if (GNUNET_OK == send_disconnect (n))
920 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent DISCONNECT_MSG to `%s'\n", 939 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent DISCONNECT_MSG to `%s'\n",
921 GNUNET_i2s (&n->id)); 940 GNUNET_i2s (&n->id));
922 else 941 else
@@ -1060,12 +1079,18 @@ neighbour_keepalive_task (void *cls,
1060 m.size = htons (sizeof (struct GNUNET_MessageHeader)); 1079 m.size = htons (sizeof (struct GNUNET_MessageHeader));
1061 m.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE); 1080 m.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE);
1062 1081
1063 1082#if TEST_NEW_CODE
1064 ret = 1083 ret = send_with_session (n,n->session,
1065 send_with_plugin (&n->id, (const void *) &m, sizeof (m), 1084 (const void *) &m, sizeof (m),
1085 UINT32_MAX /* priority */ ,
1086 GNUNET_TIME_UNIT_FOREVER_REL,
1087 NULL, NULL);
1088#else
1089 ret = send_with_plugin (&n->id, (const void *) &m, sizeof (m),
1066 UINT32_MAX /* priority */ , 1090 UINT32_MAX /* priority */ ,
1067 GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->address, 1091 GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->address,
1068 GNUNET_YES, NULL, NULL); 1092 GNUNET_YES, NULL, NULL);
1093#endif
1069 1094
1070 n->expect_latency_response = GNUNET_NO; 1095 n->expect_latency_response = GNUNET_NO;
1071 n->keep_alive_sent = GNUNET_TIME_absolute_get_zero (); 1096 n->keep_alive_sent = GNUNET_TIME_absolute_get_zero ();
@@ -1526,6 +1551,10 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1526 n->session, GNUNET_i2s (&n->id), GST_plugins_a2s (n->address)); 1551 n->session, GNUNET_i2s (&n->id), GST_plugins_a2s (n->address));
1527 n->session = session; 1552 n->session = session;
1528 } 1553 }
1554 /* remove this dummy */
1555 if (NULL != NULL) send_with_plugin (NULL, NULL, 0,
1556 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, NULL,
1557 NULL, GNUNET_YES, NULL, NULL);
1529#else 1558#else
1530 n->session = session; 1559 n->session = session;
1531 1560
@@ -1548,10 +1577,19 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1548 cc = GNUNET_malloc (sizeof (struct ContinutionContext)); 1577 cc = GNUNET_malloc (sizeof (struct ContinutionContext));
1549 cc->session = session; 1578 cc->session = session;
1550 cc->address = GNUNET_HELLO_address_copy (address); 1579 cc->address = GNUNET_HELLO_address_copy (address);
1551 ret = 1580
1552 send_with_plugin (peer, (const char *) &connect_msg, msg_len, 1581#if TEST_NEW_CODE
1553 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session, 1582 ret = send_with_session (n,n->session,
1554 address, GNUNET_YES, &send_connect_continuation, cc); 1583 (const char *) &connect_msg, msg_len,
1584 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL,
1585 &send_connect_continuation, cc);
1586#else
1587 ret =
1588 send_with_plugin (peer, (const char *) &connect_msg, msg_len,
1589 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session,
1590 address, GNUNET_YES, &send_connect_continuation, cc);
1591#endif
1592
1555 return GNUNET_NO; 1593 return GNUNET_NO;
1556 case S_CONNECT_RECV: 1594 case S_CONNECT_RECV:
1557 /* We received a CONNECT message and asked ATS for an address */ 1595 /* We received a CONNECT message and asked ATS for an address */
@@ -1592,11 +1630,21 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1592 cc = GNUNET_malloc (sizeof (struct ContinutionContext)); 1630 cc = GNUNET_malloc (sizeof (struct ContinutionContext));
1593 cc->session = session; 1631 cc->session = session;
1594 cc->address = GNUNET_HELLO_address_copy (address); 1632 cc->address = GNUNET_HELLO_address_copy (address);
1633
1634#if TEST_NEW_CODE
1635 ret = send_with_session(n, n->session,
1636 (const void *) &connect_msg, msg_len,
1637 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL,
1638 &send_switch_address_continuation, cc);
1639#else
1595 ret = 1640 ret =
1596 send_with_plugin (peer, (const char *) &connect_msg, msg_len, 1641 send_with_plugin (peer, (const char *) &connect_msg, msg_len,
1597 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session, 1642 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session,
1598 address, GNUNET_YES, 1643 address, GNUNET_YES,
1599 &send_switch_address_continuation, cc); 1644 &send_switch_address_continuation, cc);
1645#endif
1646
1647
1600 if (ret == GNUNET_SYSERR) 1648 if (ret == GNUNET_SYSERR)
1601 { 1649 {
1602 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1650 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -2060,10 +2108,22 @@ GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour)
2060 m.size = htons (sizeof (struct GNUNET_MessageHeader)); 2108 m.size = htons (sizeof (struct GNUNET_MessageHeader));
2061 m.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE); 2109 m.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE);
2062 2110
2063 send_with_plugin (&n->id, (const void *) &m, sizeof (m), 2111#if TEST_NEW_CODE
2064 UINT32_MAX /* priority */ , 2112 send_with_session(n, n->session,
2065 GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->address, 2113 (const void *) &m, sizeof (m),
2066 GNUNET_YES, NULL, NULL); 2114 UINT32_MAX,
2115 GNUNET_TIME_UNIT_FOREVER_REL,
2116 NULL, NULL);
2117#else
2118 send_with_plugin (&n->id,
2119 (const void *) &m, sizeof (m),
2120 UINT32_MAX /* priority */ ,
2121 GNUNET_TIME_UNIT_FOREVER_REL,
2122 n->session, n->address,
2123 GNUNET_YES, NULL, NULL);
2124#endif
2125
2126
2067} 2127}
2068 2128
2069/** 2129/**
@@ -2444,10 +2504,19 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2444 msg.size = htons (msg_len); 2504 msg.size = htons (msg_len);
2445 msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK); 2505 msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK);
2446 2506
2507#if TEST_NEW_CODE
2508 ret = send_with_session(n, n->session,
2509 (const char *) &msg, msg_len,
2510 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL,
2511 NULL, NULL);
2512#else
2447 ret = 2513 ret =
2448 send_with_plugin (&n->id, (const char *) &msg, msg_len, UINT32_MAX, 2514 send_with_plugin (&n->id,
2449 GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->address, 2515 (const char *) &msg, msg_len,
2450 GNUNET_YES, NULL, NULL); 2516 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL,
2517 n->session, n->address, GNUNET_YES,
2518 NULL, NULL);
2519#endif
2451 2520
2452 if (ret == GNUNET_SYSERR) 2521 if (ret == GNUNET_SYSERR)
2453 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2522 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -2496,7 +2565,6 @@ GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message,
2496 n = lookup_neighbour (peer); 2565 n = lookup_neighbour (peer);
2497 if (NULL == n) 2566 if (NULL == n)
2498 { 2567 {
2499 send_disconnect (peer, address, session);
2500 GNUNET_break (0); 2568 GNUNET_break (0);
2501 return; 2569 return;
2502 } 2570 }
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c
index f4729811c..fb9376526 100644
--- a/src/transport/plugin_transport_http.c
+++ b/src/transport/plugin_transport_http.c
@@ -532,7 +532,7 @@ notify_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
532} 532}
533 533
534/** 534/**
535 * Creates a new session the transport service will use to send data to the 535 * Creates a new outbound session the transport service will use to send data to the
536 * peer 536 * peer
537 * 537 *
538 * @param cls the plugin 538 * @param cls the plugin
@@ -579,7 +579,7 @@ http_get_session (void *cls,
579 s->addrlen = addrlen; 579 s->addrlen = addrlen;
580 s->next = NULL; 580 s->next = NULL;
581 s->next_receive = GNUNET_TIME_absolute_get_zero (); 581 s->next_receive = GNUNET_TIME_absolute_get_zero ();
582 582 s->inbound = GNUNET_NO;
583 s->ats_address_network_type = htonl (GNUNET_ATS_NET_UNSPECIFIED); 583 s->ats_address_network_type = htonl (GNUNET_ATS_NET_UNSPECIFIED);
584 584
585 /* Get ATS type */ 585 /* Get ATS type */
@@ -616,11 +616,12 @@ http_get_session (void *cls,
616 /* initiate new connection */ 616 /* initiate new connection */
617 if (GNUNET_SYSERR == client_connect (s)) 617 if (GNUNET_SYSERR == client_connect (s))
618 { 618 {
619 if (s != NULL) 619 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
620 { 620 "Cannot connect to peer `%s' address `%s''\n",
621 GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s); 621 http_plugin_address_to_string(NULL, s->addr, s->addrlen),
622 delete_session (s); 622 GNUNET_i2s (&s->target));
623 } 623 GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s);
624 delete_session (s);
624 return NULL; 625 return NULL;
625 } 626 }
626 627
@@ -676,8 +677,8 @@ http_plugin_send (void *cls,
676 { 677 {
677 if ((tmp == session) && 678 if ((tmp == session) &&
678 (0 == memcmp (&session->target, &tmp->target, sizeof (struct GNUNET_PeerIdentity))) && 679 (0 == memcmp (&session->target, &tmp->target, sizeof (struct GNUNET_PeerIdentity))) &&
679 (session->addrlen != tmp->addrlen) && 680 (session->addrlen == tmp->addrlen) &&
680 (0 != memcmp (session->addr, tmp->addr, tmp->addrlen))) 681 (0 == memcmp (session->addr, tmp->addr, tmp->addrlen)))
681 break; 682 break;
682 tmp = tmp->next; 683 tmp = tmp->next;
683 } 684 }
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c
index 3d09e866e..e90b26f72 100644
--- a/src/transport/plugin_transport_http_server.c
+++ b/src/transport/plugin_transport_http_server.c
@@ -379,7 +379,7 @@ server_lookup_session (struct Plugin *plugin,
379 struct GNUNET_PeerIdentity target; 379 struct GNUNET_PeerIdentity target;
380 int check = GNUNET_NO; 380 int check = GNUNET_NO;
381 uint32_t tag = 0; 381 uint32_t tag = 0;
382 int direction; 382 int direction = GNUNET_SYSERR;
383 383
384 conn_info = 384 conn_info =
385 MHD_get_connection_info (mhd_connection, 385 MHD_get_connection_info (mhd_connection,
@@ -410,7 +410,10 @@ server_lookup_session (struct Plugin *plugin,
410 else if (0 == strcmp (MHD_HTTP_METHOD_GET, method)) 410 else if (0 == strcmp (MHD_HTTP_METHOD_GET, method))
411 direction = _SEND; 411 direction = _SEND;
412 else 412 else
413 {
413 GNUNET_break_op (0); 414 GNUNET_break_op (0);
415 goto error;
416 }
414 417
415 418
416 if (check == GNUNET_NO) 419 if (check == GNUNET_NO)