aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_udp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/plugin_transport_udp.c')
-rw-r--r--src/transport/plugin_transport_udp.c331
1 files changed, 206 insertions, 125 deletions
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index 477efc0a1..38210f322 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -508,7 +508,9 @@ notify_session_monitor (struct Plugin *plugin,
508 struct GNUNET_TRANSPORT_SessionInfo info; 508 struct GNUNET_TRANSPORT_SessionInfo info;
509 509
510 if (NULL == plugin->sic) 510 if (NULL == plugin->sic)
511 return; 511 return;
512 if (GNUNET_YES == session->in_destroy)
513 return; /* already destroyed, just RC>0 left-over actions */
512 memset (&info, 0, sizeof (info)); 514 memset (&info, 0, sizeof (info));
513 info.state = state; 515 info.state = state;
514 info.is_inbound = GNUNET_SYSERR; /* hard to say */ 516 info.is_inbound = GNUNET_SYSERR; /* hard to say */
@@ -935,7 +937,8 @@ call_continuation (struct UDP_MessageWrapper *udpw,
935 937
936 LOG (GNUNET_ERROR_TYPE_DEBUG, 938 LOG (GNUNET_ERROR_TYPE_DEBUG,
937 "Calling continuation for %u byte message to `%s' with result %s\n", 939 "Calling continuation for %u byte message to `%s' with result %s\n",
938 udpw->payload_size, GNUNET_i2s (&udpw->session->target), 940 udpw->payload_size,
941 GNUNET_i2s (&udpw->session->target),
939 (GNUNET_OK == result) ? "OK" : "SYSERR"); 942 (GNUNET_OK == result) ? "OK" : "SYSERR");
940 943
941 if (udpw->msg_size >= udpw->payload_size) 944 if (udpw->msg_size >= udpw->payload_size)
@@ -952,63 +955,97 @@ call_continuation (struct UDP_MessageWrapper *udpw,
952 if (NULL != udpw->cont) 955 if (NULL != udpw->cont)
953 { 956 {
954 /* Transport continuation */ 957 /* Transport continuation */
955 udpw->cont (udpw->cont_cls, &udpw->session->target, result, 958 udpw->cont (udpw->cont_cls,
956 udpw->payload_size, udpw->msg_size); 959 &udpw->session->target,
960 result,
961 udpw->payload_size,
962 udpw->msg_size);
957 } 963 }
958 GNUNET_STATISTICS_update (plugin->env->stats, 964 GNUNET_STATISTICS_update (plugin->env->stats,
959 "# UDP, unfragmented msgs, messages, sent, success", 1, GNUNET_NO); 965 "# UDP, unfragmented msgs, messages, sent, success",
966 1,
967 GNUNET_NO);
960 GNUNET_STATISTICS_update (plugin->env->stats, 968 GNUNET_STATISTICS_update (plugin->env->stats,
961 "# UDP, unfragmented msgs, bytes payload, sent, success", 969 "# UDP, unfragmented msgs, bytes payload, sent, success",
962 udpw->payload_size, GNUNET_NO); 970 udpw->payload_size,
971 GNUNET_NO);
963 GNUNET_STATISTICS_update (plugin->env->stats, 972 GNUNET_STATISTICS_update (plugin->env->stats,
964 "# UDP, unfragmented msgs, bytes overhead, sent, success", overhead, 973 "# UDP, unfragmented msgs, bytes overhead, sent, success",
965 GNUNET_NO); 974 overhead,
975 GNUNET_NO);
966 GNUNET_STATISTICS_update (plugin->env->stats, 976 GNUNET_STATISTICS_update (plugin->env->stats,
967 "# UDP, total, bytes overhead, sent", overhead, GNUNET_NO); 977 "# UDP, total, bytes overhead, sent",
978 overhead,
979 GNUNET_NO);
968 GNUNET_STATISTICS_update (plugin->env->stats, 980 GNUNET_STATISTICS_update (plugin->env->stats,
969 "# UDP, total, bytes payload, sent", udpw->payload_size, GNUNET_NO); 981 "# UDP, total, bytes payload, sent",
982 udpw->payload_size,
983 GNUNET_NO);
970 break; 984 break;
971 case UMT_MSG_FRAGMENTED_COMPLETE: 985 case UMT_MSG_FRAGMENTED_COMPLETE:
972 GNUNET_assert(NULL != udpw->frag_ctx); 986 GNUNET_assert(NULL != udpw->frag_ctx);
973 if (udpw->frag_ctx->cont != NULL ) 987 if (udpw->frag_ctx->cont != NULL )
974 udpw->frag_ctx->cont (udpw->frag_ctx->cont_cls, &udpw->session->target, 988 udpw->frag_ctx->cont (udpw->frag_ctx->cont_cls,
975 GNUNET_OK, udpw->frag_ctx->payload_size, 989 &udpw->session->target,
976 udpw->frag_ctx->on_wire_size); 990 GNUNET_OK,
991 udpw->frag_ctx->payload_size,
992 udpw->frag_ctx->on_wire_size);
977 GNUNET_STATISTICS_update (plugin->env->stats, 993 GNUNET_STATISTICS_update (plugin->env->stats,
978 "# UDP, fragmented msgs, messages, sent, success", 1, GNUNET_NO); 994 "# UDP, fragmented msgs, messages, sent, success",
995 1,
996 GNUNET_NO);
979 GNUNET_STATISTICS_update (plugin->env->stats, 997 GNUNET_STATISTICS_update (plugin->env->stats,
980 "# UDP, fragmented msgs, bytes payload, sent, success", 998 "# UDP, fragmented msgs, bytes payload, sent, success",
981 udpw->payload_size, GNUNET_NO); 999 udpw->payload_size,
1000 GNUNET_NO);
982 GNUNET_STATISTICS_update (plugin->env->stats, 1001 GNUNET_STATISTICS_update (plugin->env->stats,
983 "# UDP, fragmented msgs, bytes overhead, sent, success", overhead, 1002 "# UDP, fragmented msgs, bytes overhead, sent, success",
984 GNUNET_NO); 1003 overhead,
1004 GNUNET_NO);
985 GNUNET_STATISTICS_update (plugin->env->stats, 1005 GNUNET_STATISTICS_update (plugin->env->stats,
986 "# UDP, total, bytes overhead, sent", overhead, GNUNET_NO); 1006 "# UDP, total, bytes overhead, sent",
1007 overhead,
1008 GNUNET_NO);
987 GNUNET_STATISTICS_update (plugin->env->stats, 1009 GNUNET_STATISTICS_update (plugin->env->stats,
988 "# UDP, total, bytes payload, sent", udpw->payload_size, GNUNET_NO); 1010 "# UDP, total, bytes payload, sent",
1011 udpw->payload_size,
1012 GNUNET_NO);
989 GNUNET_STATISTICS_update (plugin->env->stats, 1013 GNUNET_STATISTICS_update (plugin->env->stats,
990 "# UDP, fragmented msgs, messages, pending", -1, GNUNET_NO); 1014 "# UDP, fragmented msgs, messages, pending",
1015 -1,
1016 GNUNET_NO);
991 break; 1017 break;
992 case UMT_MSG_FRAGMENTED: 1018 case UMT_MSG_FRAGMENTED:
993 /* Fragmented message: enqueue next fragment */ 1019 /* Fragmented message: enqueue next fragment */
994 if (NULL != udpw->cont) 1020 if (NULL != udpw->cont)
995 udpw->cont (udpw->cont_cls, &udpw->session->target, result, 1021 udpw->cont (udpw->cont_cls,
996 udpw->payload_size, udpw->msg_size); 1022 &udpw->session->target,
1023 result,
1024 udpw->payload_size,
1025 udpw->msg_size);
997 GNUNET_STATISTICS_update (plugin->env->stats, 1026 GNUNET_STATISTICS_update (plugin->env->stats,
998 "# UDP, fragmented msgs, fragments, sent, success", 1, GNUNET_NO); 1027 "# UDP, fragmented msgs, fragments, sent, success",
1028 1,
1029 GNUNET_NO);
999 GNUNET_STATISTICS_update (plugin->env->stats, 1030 GNUNET_STATISTICS_update (plugin->env->stats,
1000 "# UDP, fragmented msgs, fragments bytes, sent, success", 1031 "# UDP, fragmented msgs, fragments bytes, sent, success",
1001 udpw->msg_size, GNUNET_NO); 1032 udpw->msg_size,
1033 GNUNET_NO);
1002 break; 1034 break;
1003 case UMT_MSG_ACK: 1035 case UMT_MSG_ACK:
1004 /* No continuation */ 1036 /* No continuation */
1005 GNUNET_STATISTICS_update (plugin->env->stats, 1037 GNUNET_STATISTICS_update (plugin->env->stats,
1006 "# UDP, ACK msgs, messages, sent, success", 1, GNUNET_NO); 1038 "# UDP, ACK msgs, messages, sent, success",
1039 1,
1040 GNUNET_NO);
1007 GNUNET_STATISTICS_update (plugin->env->stats, 1041 GNUNET_STATISTICS_update (plugin->env->stats,
1008 "# UDP, ACK msgs, bytes overhead, sent, success", overhead, 1042 "# UDP, ACK msgs, bytes overhead, sent, success",
1009 GNUNET_NO); 1043 overhead,
1044 GNUNET_NO);
1010 GNUNET_STATISTICS_update (plugin->env->stats, 1045 GNUNET_STATISTICS_update (plugin->env->stats,
1011 "# UDP, total, bytes overhead, sent", overhead, GNUNET_NO); 1046 "# UDP, total, bytes overhead, sent",
1047 overhead,
1048 GNUNET_NO);
1012 break; 1049 break;
1013 default: 1050 default:
1014 GNUNET_break(0); 1051 GNUNET_break(0);
@@ -1021,50 +1058,71 @@ call_continuation (struct UDP_MessageWrapper *udpw,
1021 case UMT_MSG_UNFRAGMENTED: 1058 case UMT_MSG_UNFRAGMENTED:
1022 /* Unfragmented message: failed to send */ 1059 /* Unfragmented message: failed to send */
1023 if (NULL != udpw->cont) 1060 if (NULL != udpw->cont)
1024 udpw->cont (udpw->cont_cls, &udpw->session->target, result, 1061 udpw->cont (udpw->cont_cls,
1025 udpw->payload_size, overhead); 1062 &udpw->session->target,
1063 result,
1064 udpw->payload_size,
1065 overhead);
1026 GNUNET_STATISTICS_update (plugin->env->stats, 1066 GNUNET_STATISTICS_update (plugin->env->stats,
1027 "# UDP, unfragmented msgs, messages, sent, failure", 1, GNUNET_NO); 1067 "# UDP, unfragmented msgs, messages, sent, failure",
1068 1,
1069 GNUNET_NO);
1028 GNUNET_STATISTICS_update (plugin->env->stats, 1070 GNUNET_STATISTICS_update (plugin->env->stats,
1029 "# UDP, unfragmented msgs, bytes payload, sent, failure", 1071 "# UDP, unfragmented msgs, bytes payload, sent, failure",
1030 udpw->payload_size, GNUNET_NO); 1072 udpw->payload_size,
1073 GNUNET_NO);
1031 GNUNET_STATISTICS_update (plugin->env->stats, 1074 GNUNET_STATISTICS_update (plugin->env->stats,
1032 "# UDP, unfragmented msgs, bytes overhead, sent, failure", overhead, 1075 "# UDP, unfragmented msgs, bytes overhead, sent, failure",
1033 GNUNET_NO); 1076 overhead,
1077 GNUNET_NO);
1034 break; 1078 break;
1035 case UMT_MSG_FRAGMENTED_COMPLETE: 1079 case UMT_MSG_FRAGMENTED_COMPLETE:
1036 GNUNET_assert(NULL != udpw->frag_ctx); 1080 GNUNET_assert (NULL != udpw->frag_ctx);
1037 if (udpw->frag_ctx->cont != NULL ) 1081 if (udpw->frag_ctx->cont != NULL)
1038 udpw->frag_ctx->cont (udpw->frag_ctx->cont_cls, &udpw->session->target, 1082 udpw->frag_ctx->cont (udpw->frag_ctx->cont_cls,
1039 GNUNET_SYSERR, udpw->frag_ctx->payload_size, 1083 &udpw->session->target,
1040 udpw->frag_ctx->on_wire_size); 1084 GNUNET_SYSERR,
1085 udpw->frag_ctx->payload_size,
1086 udpw->frag_ctx->on_wire_size);
1041 GNUNET_STATISTICS_update (plugin->env->stats, 1087 GNUNET_STATISTICS_update (plugin->env->stats,
1042 "# UDP, fragmented msgs, messages, sent, failure", 1, GNUNET_NO); 1088 "# UDP, fragmented msgs, messages, sent, failure",
1089 1,
1090 GNUNET_NO);
1043 GNUNET_STATISTICS_update (plugin->env->stats, 1091 GNUNET_STATISTICS_update (plugin->env->stats,
1044 "# UDP, fragmented msgs, bytes payload, sent, failure", 1092 "# UDP, fragmented msgs, bytes payload, sent, failure",
1045 udpw->payload_size, GNUNET_NO); 1093 udpw->payload_size,
1094 GNUNET_NO);
1046 GNUNET_STATISTICS_update (plugin->env->stats, 1095 GNUNET_STATISTICS_update (plugin->env->stats,
1047 "# UDP, fragmented msgs, bytes payload, sent, failure", overhead, 1096 "# UDP, fragmented msgs, bytes payload, sent, failure",
1048 GNUNET_NO); 1097 overhead,
1098 GNUNET_NO);
1049 GNUNET_STATISTICS_update (plugin->env->stats, 1099 GNUNET_STATISTICS_update (plugin->env->stats,
1050 "# UDP, fragmented msgs, bytes payload, sent, failure", overhead, 1100 "# UDP, fragmented msgs, bytes payload, sent, failure",
1051 GNUNET_NO); 1101 overhead,
1102 GNUNET_NO);
1052 GNUNET_STATISTICS_update (plugin->env->stats, 1103 GNUNET_STATISTICS_update (plugin->env->stats,
1053 "# UDP, fragmented msgs, messages, pending", -1, GNUNET_NO); 1104 "# UDP, fragmented msgs, messages, pending",
1105 -1,
1106 GNUNET_NO);
1054 break; 1107 break;
1055 case UMT_MSG_FRAGMENTED: 1108 case UMT_MSG_FRAGMENTED:
1056 GNUNET_assert(NULL != udpw->frag_ctx); 1109 GNUNET_assert (NULL != udpw->frag_ctx);
1057 /* Fragmented message: failed to send */ 1110 /* Fragmented message: failed to send */
1058 GNUNET_STATISTICS_update (plugin->env->stats, 1111 GNUNET_STATISTICS_update (plugin->env->stats,
1059 "# UDP, fragmented msgs, fragments, sent, failure", 1, GNUNET_NO); 1112 "# UDP, fragmented msgs, fragments, sent, failure",
1113 1,
1114 GNUNET_NO);
1060 GNUNET_STATISTICS_update (plugin->env->stats, 1115 GNUNET_STATISTICS_update (plugin->env->stats,
1061 "# UDP, fragmented msgs, fragments bytes, sent, failure", 1116 "# UDP, fragmented msgs, fragments bytes, sent, failure",
1062 udpw->msg_size, GNUNET_NO); 1117 udpw->msg_size,
1118 GNUNET_NO);
1063 break; 1119 break;
1064 case UMT_MSG_ACK: 1120 case UMT_MSG_ACK:
1065 /* ACK message: failed to send */ 1121 /* ACK message: failed to send */
1066 GNUNET_STATISTICS_update (plugin->env->stats, 1122 GNUNET_STATISTICS_update (plugin->env->stats,
1067 "# UDP, ACK msgs, messages, sent, failure", 1, GNUNET_NO); 1123 "# UDP, ACK msgs, messages, sent, failure",
1124 1,
1125 GNUNET_NO);
1068 break; 1126 break;
1069 default: 1127 default:
1070 GNUNET_break(0); 1128 GNUNET_break(0);
@@ -1224,7 +1282,14 @@ dequeue (struct Plugin *plugin,
1224 1282
1225 1283
1226/** 1284/**
1227 * FIXME. 1285 * We have completed our (attempt) to transmit a message
1286 * that had to be fragmented -- either because we got an
1287 * ACK saying that all fragments were received, or because
1288 * of timeout / disconnect. Clean up our state.
1289 *
1290 * @param fc fragmentation context to clean up
1291 * @param result #GNUNET_OK if we succeeded (got ACK),
1292 * #GNUNET_SYSERR if the transmission failed
1228 */ 1293 */
1229static void 1294static void
1230fragmented_message_done (struct UDP_FragmentationContext *fc, 1295fragmented_message_done (struct UDP_FragmentationContext *fc,
@@ -1258,11 +1323,13 @@ fragmented_message_done (struct UDP_FragmentationContext *fc,
1258 while (NULL != udpw) 1323 while (NULL != udpw)
1259 { 1324 {
1260 tmp = udpw->next; 1325 tmp = udpw->next;
1261 if ((udpw->frag_ctx != NULL )&& (udpw->frag_ctx == s->frag_ctx)){ 1326 if ( (udpw->frag_ctx != NULL) &&
1262 dequeue (plugin, udpw); 1327 (udpw->frag_ctx == s->frag_ctx) )
1263 call_continuation (udpw, GNUNET_SYSERR); 1328 {
1264 GNUNET_free (udpw); 1329 dequeue (plugin, udpw);
1265 } 1330 call_continuation (udpw, GNUNET_SYSERR);
1331 GNUNET_free (udpw);
1332 }
1266 udpw = tmp; 1333 udpw = tmp;
1267 } 1334 }
1268 } 1335 }
@@ -1559,34 +1626,9 @@ reschedule_session_timeout (struct Session *s)
1559 1626
1560 1627
1561/** 1628/**
1562 * FIXME.
1563 */
1564static struct Session *
1565create_session (struct Plugin *plugin,
1566 const struct GNUNET_HELLO_Address *address)
1567{
1568 struct Session *s;
1569
1570 s = GNUNET_new (struct Session);
1571 s->plugin = plugin;
1572 s->address = GNUNET_HELLO_address_copy (address);
1573 s->target = address->peer;
1574 s->last_expected_ack_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
1575 250);
1576 s->last_expected_msg_delay = GNUNET_TIME_UNIT_MILLISECONDS;
1577 s->flow_delay_from_other_peer = GNUNET_TIME_UNIT_ZERO_ABS;
1578 s->flow_delay_for_other_peer = GNUNET_TIME_UNIT_ZERO;
1579 s->timeout = GNUNET_TIME_relative_to_absolute (UDP_SESSION_TIME_OUT);
1580 s->timeout_task = GNUNET_SCHEDULER_add_delayed (UDP_SESSION_TIME_OUT,
1581 &session_timeout, s);
1582 return s;
1583}
1584
1585
1586/**
1587 * Function obtain the network type for a session 1629 * Function obtain the network type for a session
1588 * 1630 *
1589 * @param cls closure ('struct Plugin*') 1631 * @param cls closure (`struct Plugin *`)
1590 * @param session the session 1632 * @param session the session
1591 * @return the network type 1633 * @return the network type
1592 */ 1634 */
@@ -1740,7 +1782,18 @@ udp_plugin_create_session (void *cls,
1740 struct Plugin *plugin = cls; 1782 struct Plugin *plugin = cls;
1741 struct Session *s; 1783 struct Session *s;
1742 1784
1743 s = create_session (plugin, address); 1785 s = GNUNET_new (struct Session);
1786 s->plugin = plugin;
1787 s->address = GNUNET_HELLO_address_copy (address);
1788 s->target = address->peer;
1789 s->last_expected_ack_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
1790 250);
1791 s->last_expected_msg_delay = GNUNET_TIME_UNIT_MILLISECONDS;
1792 s->flow_delay_from_other_peer = GNUNET_TIME_UNIT_ZERO_ABS;
1793 s->flow_delay_for_other_peer = GNUNET_TIME_UNIT_ZERO;
1794 s->timeout = GNUNET_TIME_relative_to_absolute (UDP_SESSION_TIME_OUT);
1795 s->timeout_task = GNUNET_SCHEDULER_add_delayed (UDP_SESSION_TIME_OUT,
1796 &session_timeout, s);
1744 s->scope = network_type; 1797 s->scope = network_type;
1745 1798
1746 LOG (GNUNET_ERROR_TYPE_DEBUG, 1799 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1768,7 +1821,7 @@ udp_plugin_create_session (void *cls,
1768 * notify the plugin that a session is still active and in use and 1821 * notify the plugin that a session is still active and in use and
1769 * therefore the session timeout for this session has to be updated 1822 * therefore the session timeout for this session has to be updated
1770 * 1823 *
1771 * @param cls closure 1824 * @param cls closure with the `struct Plugin`
1772 * @param peer which peer was the session for 1825 * @param peer which peer was the session for
1773 * @param session which session is being updated 1826 * @param session which session is being updated
1774 */ 1827 */
@@ -1796,7 +1849,7 @@ udp_plugin_update_session_timeout (void *cls,
1796 * Creates a new outbound session the transport service will use to 1849 * Creates a new outbound session the transport service will use to
1797 * send data to the peer. 1850 * send data to the peer.
1798 * 1851 *
1799 * @param cls the plugin 1852 * @param cls the `struct Plugin *`
1800 * @param address the address 1853 * @param address the address
1801 * @return the session or NULL of max connections exceeded 1854 * @return the session or NULL of max connections exceeded
1802 */ 1855 */
@@ -1812,16 +1865,20 @@ udp_plugin_get_session (void *cls,
1812 1865
1813 if (NULL == address) 1866 if (NULL == address)
1814 { 1867 {
1815 GNUNET_break(0); 1868 GNUNET_break (0);
1816 return NULL; 1869 return NULL;
1817 } 1870 }
1818 if ( (address->address_length != sizeof(struct IPv4UdpAddress)) && 1871 if ( (address->address_length != sizeof(struct IPv4UdpAddress)) &&
1819 (address->address_length != sizeof(struct IPv6UdpAddress)) ) 1872 (address->address_length != sizeof(struct IPv6UdpAddress)) )
1873 {
1874 GNUNET_break_op (0);
1820 return NULL; 1875 return NULL;
1876 }
1821 if (NULL != (s = udp_plugin_lookup_session (cls, 1877 if (NULL != (s = udp_plugin_lookup_session (cls,
1822 address))) 1878 address)))
1823 return s; 1879 return s;
1824 1880
1881 /* need to create new session */
1825 if (sizeof (struct IPv4UdpAddress) == address->address_length) 1882 if (sizeof (struct IPv4UdpAddress) == address->address_length)
1826 { 1883 {
1827 struct sockaddr_in v4; 1884 struct sockaddr_in v4;
@@ -1838,7 +1895,7 @@ udp_plugin_get_session (void *cls,
1838 (const struct sockaddr *) &v4, 1895 (const struct sockaddr *) &v4,
1839 sizeof (v4)); 1896 sizeof (v4));
1840 } 1897 }
1841 else if (sizeof (struct IPv6UdpAddress) == address->address_length) 1898 if (sizeof (struct IPv6UdpAddress) == address->address_length)
1842 { 1899 {
1843 struct sockaddr_in6 v6; 1900 struct sockaddr_in6 v6;
1844 1901
@@ -1854,9 +1911,9 @@ udp_plugin_get_session (void *cls,
1854 (const struct sockaddr *) &v6, 1911 (const struct sockaddr *) &v6,
1855 sizeof (v6)); 1912 sizeof (v6));
1856 } 1913 }
1857 1914 return udp_plugin_create_session (cls,
1858 /* otherwise create new */ 1915 address,
1859 return udp_plugin_create_session (cls, address, network_type); 1916 network_type);
1860} 1917}
1861 1918
1862 1919
@@ -2007,8 +2064,6 @@ udp_plugin_send (void *cls,
2007 struct UDP_MessageWrapper * udpw; 2064 struct UDP_MessageWrapper * udpw;
2008 struct UDPMessage *udp; 2065 struct UDPMessage *udp;
2009 char mbuf[udpmlen]; 2066 char mbuf[udpmlen];
2010 GNUNET_assert(plugin != NULL);
2011 GNUNET_assert(s != NULL);
2012 2067
2013 if ( (s->address->address_length == sizeof(struct IPv6UdpAddress)) && 2068 if ( (s->address->address_length == sizeof(struct IPv6UdpAddress)) &&
2014 (plugin->sockv6 == NULL) ) 2069 (plugin->sockv6 == NULL) )
@@ -2239,6 +2294,7 @@ process_udp_message (struct Plugin *plugin,
2239 struct Session *s; 2294 struct Session *s;
2240 struct GNUNET_HELLO_Address *address; 2295 struct GNUNET_HELLO_Address *address;
2241 2296
2297 GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != network_type);
2242 if (0 != ntohl (msg->reserved)) 2298 if (0 != ntohl (msg->reserved))
2243 { 2299 {
2244 GNUNET_break_op(0); 2300 GNUNET_break_op(0);
@@ -2486,7 +2542,6 @@ read_process_ack (struct Plugin *plugin,
2486 udp_addr, 2542 udp_addr,
2487 udp_addr_len)); 2543 udp_addr_len));
2488 2544
2489
2490 /* Remove fragmented message after successful sending */ 2545 /* Remove fragmented message after successful sending */
2491 fragmented_message_done (s->frag_ctx, 2546 fragmented_message_done (s->frag_ctx,
2492 GNUNET_OK); 2547 GNUNET_OK);
@@ -2734,24 +2789,30 @@ udp_select_read (struct Plugin *plugin,
2734 2789
2735 2790
2736/** 2791/**
2737 * FIXME. 2792 * Removes messages from the transmission queue that have
2793 * timed out, and then selects a message that should be
2794 * transmitted next.
2795 *
2796 * @param plugin the UDP plugin
2797 * @param sock which socket should we process the queue for (v4 or v6)
2798 * @return message selected for transmission, or NULL for none
2738 */ 2799 */
2739static struct UDP_MessageWrapper * 2800static struct UDP_MessageWrapper *
2740remove_timeout_messages_and_select (struct UDP_MessageWrapper *head, 2801remove_timeout_messages_and_select (struct Plugin *plugin,
2741 struct GNUNET_NETWORK_Handle *sock) 2802 struct GNUNET_NETWORK_Handle *sock)
2742{ 2803{
2743 struct UDP_MessageWrapper *udpw = NULL; 2804 struct UDP_MessageWrapper *udpw = NULL;
2744 struct GNUNET_TIME_Relative remaining; 2805 struct GNUNET_TIME_Relative remaining;
2745 struct Session *session; 2806 struct Session *session;
2746 struct Plugin *plugin;
2747 int removed; 2807 int removed;
2748 2808
2749 removed = GNUNET_NO; 2809 removed = GNUNET_NO;
2750 udpw = head; 2810 udpw = (sock == plugin->sockv4)
2811 ? plugin->ipv4_queue_head
2812 : plugin->ipv6_queue_head;
2751 while (NULL != udpw) 2813 while (NULL != udpw)
2752 { 2814 {
2753 session = udpw->session; 2815 session = udpw->session;
2754 plugin = session->plugin;
2755 /* Find messages with timeout */ 2816 /* Find messages with timeout */
2756 remaining = GNUNET_TIME_absolute_get_remaining (udpw->timeout); 2817 remaining = GNUNET_TIME_absolute_get_remaining (udpw->timeout);
2757 if (GNUNET_TIME_UNIT_ZERO.rel_value_us == remaining.rel_value_us) 2818 if (GNUNET_TIME_UNIT_ZERO.rel_value_us == remaining.rel_value_us)
@@ -2797,12 +2858,13 @@ remove_timeout_messages_and_select (struct UDP_MessageWrapper *head,
2797 "# UDP, total, messages, sent, timeout", 2858 "# UDP, total, messages, sent, timeout",
2798 1, 2859 1,
2799 GNUNET_NO); 2860 GNUNET_NO);
2800 call_continuation (udpw, GNUNET_SYSERR); 2861 call_continuation (udpw,
2862 GNUNET_SYSERR);
2801 LOG (GNUNET_ERROR_TYPE_DEBUG, 2863 LOG (GNUNET_ERROR_TYPE_DEBUG,
2802 "Fragment for message for peer `%s' with size %u timed out\n", 2864 "Fragment for message for peer `%s' with size %u timed out\n",
2803 GNUNET_i2s (&udpw->session->target), 2865 GNUNET_i2s (&udpw->session->target),
2804 udpw->frag_ctx->payload_size); 2866 udpw->frag_ctx->payload_size);
2805 2867
2806 GNUNET_STATISTICS_update (plugin->env->stats, 2868 GNUNET_STATISTICS_update (plugin->env->stats,
2807 "# UDP, fragmented msgs, messages, sent, timeout", 2869 "# UDP, fragmented msgs, messages, sent, timeout",
2808 1, 2870 1,
@@ -2812,7 +2874,8 @@ remove_timeout_messages_and_select (struct UDP_MessageWrapper *head,
2812 udpw->frag_ctx->payload_size, 2874 udpw->frag_ctx->payload_size,
2813 GNUNET_NO); 2875 GNUNET_NO);
2814 /* Remove fragmented message due to timeout */ 2876 /* Remove fragmented message due to timeout */
2815 fragmented_message_done (udpw->frag_ctx, GNUNET_SYSERR); 2877 fragmented_message_done (udpw->frag_ctx,
2878 GNUNET_SYSERR);
2816 break; 2879 break;
2817 case UMT_MSG_ACK: 2880 case UMT_MSG_ACK:
2818 GNUNET_STATISTICS_update (plugin->env->stats, 2881 GNUNET_STATISTICS_update (plugin->env->stats,
@@ -2827,10 +2890,12 @@ remove_timeout_messages_and_select (struct UDP_MessageWrapper *head,
2827 "ACK Message for peer `%s' with size %u timed out\n", 2890 "ACK Message for peer `%s' with size %u timed out\n",
2828 GNUNET_i2s (&udpw->session->target), 2891 GNUNET_i2s (&udpw->session->target),
2829 udpw->payload_size); 2892 udpw->payload_size);
2830 call_continuation (udpw, GNUNET_SYSERR); 2893 call_continuation (udpw,
2894 GNUNET_SYSERR);
2831 removed = GNUNET_YES; 2895 removed = GNUNET_YES;
2832 dequeue (plugin, udpw); 2896 dequeue (plugin,
2833 GNUNET_free(udpw); 2897 udpw);
2898 GNUNET_free (udpw);
2834 break; 2899 break;
2835 default: 2900 default:
2836 break; 2901 break;
@@ -2867,8 +2932,10 @@ remove_timeout_messages_and_select (struct UDP_MessageWrapper *head,
2867 /* Message is delayed, try next */ 2932 /* Message is delayed, try next */
2868 LOG (GNUNET_ERROR_TYPE_DEBUG, 2933 LOG (GNUNET_ERROR_TYPE_DEBUG,
2869 "Message for peer `%s' (%u bytes) is delayed for %s\n", 2934 "Message for peer `%s' (%u bytes) is delayed for %s\n",
2870 GNUNET_i2s (&udpw->session->target), udpw->payload_size, 2935 GNUNET_i2s (&udpw->session->target),
2871 GNUNET_STRINGS_relative_time_to_string (remaining, GNUNET_YES)); 2936 udpw->payload_size,
2937 GNUNET_STRINGS_relative_time_to_string (remaining,
2938 GNUNET_YES));
2872 udpw = udpw->next; 2939 udpw = udpw->next;
2873 } 2940 }
2874 } 2941 }
@@ -2931,7 +2998,12 @@ analyze_send_error (struct Plugin *plugin,
2931 2998
2932 2999
2933/** 3000/**
2934 * FIXME. 3001 * It is time to try to transmit a UDP message. Select one
3002 * and send.
3003 *
3004 * @param plugin the plugin
3005 * @param sock which socket (v4/v6) to send on
3006 * @return number of bytes transmitted, #GNUNET_SYSERR on failure
2935 */ 3007 */
2936static size_t 3008static size_t
2937udp_select_send (struct Plugin *plugin, 3009udp_select_send (struct Plugin *plugin,
@@ -2947,9 +3019,7 @@ udp_select_send (struct Plugin *plugin,
2947 struct UDP_MessageWrapper *udpw; 3019 struct UDP_MessageWrapper *udpw;
2948 3020
2949 /* Find message to send */ 3021 /* Find message to send */
2950 udpw = remove_timeout_messages_and_select ((sock == plugin->sockv4) 3022 udpw = remove_timeout_messages_and_select (plugin,
2951 ? plugin->ipv4_queue_head
2952 : plugin->ipv6_queue_head,
2953 sock); 3023 sock);
2954 if (NULL == udpw) 3024 if (NULL == udpw)
2955 return 0; /* No message to send */ 3025 return 0; /* No message to send */
@@ -2963,7 +3033,9 @@ udp_select_send (struct Plugin *plugin,
2963 a4.sin_len = sizeof (a4); 3033 a4.sin_len = sizeof (a4);
2964#endif 3034#endif
2965 a4.sin_port = u4->u4_port; 3035 a4.sin_port = u4->u4_port;
2966 memcpy (&a4.sin_addr, &u4->ipv4_addr, sizeof(struct in_addr)); 3036 memcpy (&a4.sin_addr,
3037 &u4->ipv4_addr,
3038 sizeof(struct in_addr));
2967 a = (struct sockaddr *) &a4; 3039 a = (struct sockaddr *) &a4;
2968 slen = sizeof (a4); 3040 slen = sizeof (a4);
2969 } 3041 }
@@ -2982,15 +3054,16 @@ udp_select_send (struct Plugin *plugin,
2982 } 3054 }
2983 else 3055 else
2984 { 3056 {
2985 call_continuation (udpw, GNUNET_OK); 3057 call_continuation (udpw,
2986 dequeue (plugin, udpw); 3058 GNUNET_OK);
3059 dequeue (plugin,
3060 udpw);
2987 notify_session_monitor (plugin, 3061 notify_session_monitor (plugin,
2988 udpw->session, 3062 udpw->session,
2989 GNUNET_TRANSPORT_SS_UPDATE); 3063 GNUNET_TRANSPORT_SS_UPDATE);
2990 GNUNET_free (udpw); 3064 GNUNET_free (udpw);
2991 return GNUNET_SYSERR; 3065 return GNUNET_SYSERR;
2992 } 3066 }
2993
2994 sent = GNUNET_NETWORK_socket_sendto (sock, 3067 sent = GNUNET_NETWORK_socket_sendto (sock,
2995 udpw->msg_buf, 3068 udpw->msg_buf,
2996 udpw->msg_size, 3069 udpw->msg_size,
@@ -2999,12 +3072,20 @@ udp_select_send (struct Plugin *plugin,
2999 if (GNUNET_SYSERR == sent) 3072 if (GNUNET_SYSERR == sent)
3000 { 3073 {
3001 /* Failure */ 3074 /* Failure */
3002 analyze_send_error (plugin, a, slen, errno); 3075 analyze_send_error (plugin,
3003 call_continuation (udpw, GNUNET_SYSERR); 3076 a,
3077 slen,
3078 errno);
3079 call_continuation (udpw,
3080 GNUNET_SYSERR);
3004 GNUNET_STATISTICS_update (plugin->env->stats, 3081 GNUNET_STATISTICS_update (plugin->env->stats,
3005 "# UDP, total, bytes, sent, failure", sent, GNUNET_NO); 3082 "# UDP, total, bytes, sent, failure",
3083 sent,
3084 GNUNET_NO);
3006 GNUNET_STATISTICS_update (plugin->env->stats, 3085 GNUNET_STATISTICS_update (plugin->env->stats,
3007 "# UDP, total, messages, sent, failure", 1, GNUNET_NO); 3086 "# UDP, total, messages, sent, failure",
3087 1,
3088 GNUNET_NO);
3008 } 3089 }
3009 else 3090 else
3010 { 3091 {
@@ -3032,7 +3113,7 @@ udp_select_send (struct Plugin *plugin,
3032 notify_session_monitor (plugin, 3113 notify_session_monitor (plugin,
3033 udpw->session, 3114 udpw->session,
3034 GNUNET_TRANSPORT_SS_UPDATE); 3115 GNUNET_TRANSPORT_SS_UPDATE);
3035 GNUNET_free(udpw); 3116 GNUNET_free (udpw);
3036 return sent; 3117 return sent;
3037} 3118}
3038 3119