aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_tcp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/plugin_transport_tcp.c')
-rw-r--r--src/transport/plugin_transport_tcp.c123
1 files changed, 74 insertions, 49 deletions
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index 310ac3483..4c2691e09 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -885,7 +885,7 @@ tcp_plugin_disconnect_session (void *cls,
885 GNUNET_assert (0 == session->bytes_in_queue); 885 GNUNET_assert (0 == session->bytes_in_queue);
886 notify_session_monitor (session->plugin, 886 notify_session_monitor (session->plugin,
887 session, 887 session,
888 GNUNET_TRANSPORT_SS_UP); 888 GNUNET_TRANSPORT_SS_DONE);
889 889
890 if (session->receive_delay_task != GNUNET_SCHEDULER_NO_TASK) 890 if (session->receive_delay_task != GNUNET_SCHEDULER_NO_TASK)
891 { 891 {
@@ -942,7 +942,7 @@ session_timeout (void *cls,
942 the monitor, it may think we're about to die ... */ 942 the monitor, it may think we're about to die ... */
943 notify_session_monitor (s->plugin, 943 notify_session_monitor (s->plugin,
944 s, 944 s,
945 GNUNET_TRANSPORT_SS_UP); 945 GNUNET_TRANSPORT_SS_UPDATE);
946 s->timeout_task = GNUNET_SCHEDULER_add_delayed (left, 946 s->timeout_task = GNUNET_SCHEDULER_add_delayed (left,
947 &session_timeout, 947 &session_timeout,
948 s); 948 s);
@@ -1030,6 +1030,9 @@ create_session (struct Plugin *plugin,
1030 session->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 1030 session->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1031 &session_timeout, 1031 &session_timeout,
1032 session); 1032 session);
1033 notify_session_monitor (session->plugin,
1034 session,
1035 GNUNET_TRANSPORT_SS_INIT);
1033 if (GNUNET_YES != is_nat) 1036 if (GNUNET_YES != is_nat)
1034 { 1037 {
1035 GNUNET_STATISTICS_update (plugin->env->stats, 1038 GNUNET_STATISTICS_update (plugin->env->stats,
@@ -1144,7 +1147,7 @@ do_transmit (void *cls, size_t size, void *buf)
1144 if (0 < ret) 1147 if (0 < ret)
1145 notify_session_monitor (session->plugin, 1148 notify_session_monitor (session->plugin,
1146 session, 1149 session,
1147 GNUNET_TRANSPORT_SS_UP); 1150 GNUNET_TRANSPORT_SS_UPDATE);
1148 return 0; 1151 return 0;
1149 } 1152 }
1150 /* copy all pending messages that would fit */ 1153 /* copy all pending messages that would fit */
@@ -1177,7 +1180,7 @@ do_transmit (void *cls, size_t size, void *buf)
1177 } 1180 }
1178 notify_session_monitor (session->plugin, 1181 notify_session_monitor (session->plugin,
1179 session, 1182 session,
1180 GNUNET_TRANSPORT_SS_UP); 1183 GNUNET_TRANSPORT_SS_UPDATE);
1181 /* schedule 'continuation' before callbacks so that callbacks that 1184 /* schedule 'continuation' before callbacks so that callbacks that
1182 * cancel everything don't cause us to use a session that no longer 1185 * cancel everything don't cause us to use a session that no longer
1183 * exists... */ 1186 * exists... */
@@ -1310,7 +1313,7 @@ tcp_plugin_send (void *cls,
1310 pm); 1313 pm);
1311 notify_session_monitor (session->plugin, 1314 notify_session_monitor (session->plugin,
1312 session, 1315 session,
1313 GNUNET_TRANSPORT_SS_UP); 1316 GNUNET_TRANSPORT_SS_UPDATE);
1314 session->msgs_in_queue++; 1317 session->msgs_in_queue++;
1315 session->bytes_in_queue += pm->message_size; 1318 session->bytes_in_queue += pm->message_size;
1316 process_pending_messages (session); 1319 process_pending_messages (session);
@@ -1410,12 +1413,12 @@ nat_connect_timeout (void *cls,
1410 struct Session *session = cls; 1413 struct Session *session = cls;
1411 1414
1412 session->nat_connection_timeout = GNUNET_SCHEDULER_NO_TASK; 1415 session->nat_connection_timeout = GNUNET_SCHEDULER_NO_TASK;
1413 LOG(GNUNET_ERROR_TYPE_DEBUG, 1416 LOG (GNUNET_ERROR_TYPE_DEBUG,
1414 "NAT WAIT connection to `%4s' at `%s' could not be established, removing session\n", 1417 "NAT WAIT connection to `%4s' at `%s' could not be established, removing session\n",
1415 GNUNET_i2s (&session->target), 1418 GNUNET_i2s (&session->target),
1416 tcp_plugin_address_to_string (NULL, 1419 tcp_plugin_address_to_string (NULL,
1417 session->address->address, 1420 session->address->address,
1418 session->address->address_length)); 1421 session->address->address_length));
1419 tcp_plugin_disconnect_session (session->plugin, 1422 tcp_plugin_disconnect_session (session->plugin,
1420 session); 1423 session);
1421} 1424}
@@ -1632,24 +1635,30 @@ tcp_plugin_get_session (void *cls,
1632 &address->peer))) 1635 &address->peer)))
1633 { 1636 {
1634 LOG (GNUNET_ERROR_TYPE_DEBUG, 1637 LOG (GNUNET_ERROR_TYPE_DEBUG,
1635 "Found valid IPv4 NAT address (creating session)!\n"); 1638 "Found valid IPv4 NAT address (creating session)!\n");
1636 session = create_session (plugin, address, NULL, GNUNET_YES); 1639 session = create_session (plugin,
1637 session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl ( 1640 address,
1638 ats.value); 1641 NULL,
1639 GNUNET_break( 1642 GNUNET_YES);
1640 session->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED); 1643 session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl (ats.value);
1644 GNUNET_break (session->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED);
1641 session->nat_connection_timeout = GNUNET_SCHEDULER_add_delayed (NAT_TIMEOUT, 1645 session->nat_connection_timeout = GNUNET_SCHEDULER_add_delayed (NAT_TIMEOUT,
1642 &nat_connect_timeout, session); 1646 &nat_connect_timeout,
1643 GNUNET_assert(session != NULL); 1647 session);
1644 GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (plugin->nat_wait_conns, 1648 GNUNET_assert(GNUNET_OK ==
1645 &session->target, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 1649 GNUNET_CONTAINER_multipeermap_put (plugin->nat_wait_conns,
1646 1650 &session->target,
1647 LOG(GNUNET_ERROR_TYPE_DEBUG, 1651 session,
1648 "Created NAT WAIT connection to `%4s' at `%s'\n", 1652 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1649 GNUNET_i2s (&session->target), GNUNET_a2s (sb, sbs));
1650 1653
1654 LOG (GNUNET_ERROR_TYPE_DEBUG,
1655 "Created NAT WAIT connection to `%4s' at `%s'\n",
1656 GNUNET_i2s (&session->target),
1657 GNUNET_a2s (sb, sbs));
1651 if (GNUNET_OK == GNUNET_NAT_run_client (plugin->nat, &a4)) 1658 if (GNUNET_OK == GNUNET_NAT_run_client (plugin->nat, &a4))
1659 {
1652 return session; 1660 return session;
1661 }
1653 else 1662 else
1654 { 1663 {
1655 LOG(GNUNET_ERROR_TYPE_DEBUG, 1664 LOG(GNUNET_ERROR_TYPE_DEBUG,
@@ -1714,24 +1723,28 @@ tcp_plugin_get_session (void *cls,
1714 if (plugin->cur_connections == plugin->max_connections) 1723 if (plugin->cur_connections == plugin->max_connections)
1715 GNUNET_SERVER_suspend (plugin->server); /* Maximum number of connections rechead */ 1724 GNUNET_SERVER_suspend (plugin->server); /* Maximum number of connections rechead */
1716 1725
1717 LOG(GNUNET_ERROR_TYPE_DEBUG, 1726 LOG (GNUNET_ERROR_TYPE_DEBUG,
1718 "Asked to transmit to `%4s', creating fresh session using address `%s'.\n", 1727 "Asked to transmit to `%4s', creating fresh session using address `%s'.\n",
1719 GNUNET_i2s (&address->peer), GNUNET_a2s (sb, sbs)); 1728 GNUNET_i2s (&address->peer), GNUNET_a2s (sb, sbs));
1720 1729
1721 session = create_session (plugin, address, 1730 session = create_session (plugin,
1731 address,
1722 GNUNET_SERVER_connect_socket (plugin->server, sa), 1732 GNUNET_SERVER_connect_socket (plugin->server, sa),
1723 GNUNET_NO); 1733 GNUNET_NO);
1724 session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl ( 1734 session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl (ats.value);
1725 ats.value); 1735 GNUNET_break (session->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED);
1726 GNUNET_break(session->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED);
1727 GNUNET_SERVER_client_set_user_context(session->client, session); 1736 GNUNET_SERVER_client_set_user_context(session->client, session);
1728 GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, &session->target, 1737 GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap,
1729 session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 1738 &session->target,
1730 LOG(GNUNET_ERROR_TYPE_DEBUG, 1739 session,
1731 "Creating new session for `%s' address `%s' session %p\n", 1740 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1732 GNUNET_i2s (&address->peer), 1741 LOG (GNUNET_ERROR_TYPE_DEBUG,
1733 tcp_plugin_address_to_string(NULL, address->address, address->address_length), 1742 "Creating new session for `%s' address `%s' session %p\n",
1734 session); 1743 GNUNET_i2s (&address->peer),
1744 tcp_plugin_address_to_string (NULL,
1745 address->address,
1746 address->address_length),
1747 session);
1735 /* Send TCP Welcome */ 1748 /* Send TCP Welcome */
1736 process_pending_messages (session); 1749 process_pending_messages (session);
1737 1750
@@ -2259,8 +2272,9 @@ handle_tcp_welcome (void *cls,
2259 { 2272 {
2260 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) 2273 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
2261 { 2274 {
2262 LOG(GNUNET_ERROR_TYPE_DEBUG, "Found existing session %p for peer `%s'\n", 2275 LOG (GNUNET_ERROR_TYPE_DEBUG,
2263 session, GNUNET_a2s (vaddr, alen)); 2276 "Found existing session %p for peer `%s'\n",
2277 session, GNUNET_a2s (vaddr, alen));
2264 GNUNET_free(vaddr); 2278 GNUNET_free(vaddr);
2265 } 2279 }
2266 } 2280 }
@@ -2305,21 +2319,27 @@ handle_tcp_welcome (void *cls,
2305 session = create_session (plugin, address, client, GNUNET_NO); 2319 session = create_session (plugin, address, client, GNUNET_NO);
2306 GNUNET_HELLO_address_free (address); 2320 GNUNET_HELLO_address_free (address);
2307 ats = plugin->env->get_address_type (plugin->env->cls, vaddr, alen); 2321 ats = plugin->env->get_address_type (plugin->env->cls, vaddr, alen);
2308 session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl ( 2322 session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl (ats.value);
2309 ats.value); 2323 LOG(GNUNET_ERROR_TYPE_DEBUG,
2310 LOG(GNUNET_ERROR_TYPE_DEBUG, "Creating new%s session %p for peer `%s' client %p \n", 2324 "Creating new%s session %p for peer `%s' client %p \n",
2311 GNUNET_HELLO_address_check_option (session->address, 2325 GNUNET_HELLO_address_check_option (session->address,
2312 GNUNET_HELLO_ADDRESS_INFO_INBOUND) ? " inbound" : "", session, 2326 GNUNET_HELLO_ADDRESS_INFO_INBOUND)
2327 ? " inbound" : "",
2328 session,
2313 tcp_plugin_address_to_string(NULL, (void *) session->address->address, 2329 tcp_plugin_address_to_string(NULL, (void *) session->address->address,
2314 session->address->address_length), 2330 session->address->address_length),
2315 client); 2331 client);
2316 GNUNET_free(vaddr); 2332 GNUNET_free(vaddr);
2317 GNUNET_SERVER_client_set_user_context(session->client, session); 2333 GNUNET_SERVER_client_set_user_context(session->client, session);
2318 GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, &session->target, 2334 GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap,
2319 session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 2335 &session->target,
2320 2336 session,
2337 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2321 /* Notify transport and ATS about new session */ 2338 /* Notify transport and ATS about new session */
2322 plugin->env->session_start (NULL, session->address, session, &ats, 1); 2339 plugin->env->session_start (NULL, session->address, session, &ats, 1);
2340 notify_session_monitor (plugin,
2341 session,
2342 GNUNET_TRANSPORT_SS_INIT);
2323 } 2343 }
2324 else 2344 else
2325 { 2345 {
@@ -2614,6 +2634,11 @@ send_session_info_iter (void *cls,
2614 2634
2615 notify_session_monitor (plugin, 2635 notify_session_monitor (plugin,
2616 session, 2636 session,
2637 GNUNET_TRANSPORT_SS_INIT);
2638 /* FIXME: cannot tell if this is up or not from current
2639 session state... */
2640 notify_session_monitor (plugin,
2641 session,
2617 GNUNET_TRANSPORT_SS_UP); 2642 GNUNET_TRANSPORT_SS_UP);
2618 return GNUNET_OK; 2643 return GNUNET_OK;
2619} 2644}