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.c110
1 files changed, 67 insertions, 43 deletions
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index a08edbade..1630c48b1 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -93,7 +93,7 @@ struct Session
93 */ 93 */
94 struct GNUNET_PeerIdentity target; 94 struct GNUNET_PeerIdentity target;
95 95
96 struct FragmentationContext * frag_ctx; 96 struct UDP_FragmentationContext * frag_ctx;
97 97
98 /** 98 /**
99 * Address of the other peer 99 * Address of the other peer
@@ -225,15 +225,33 @@ struct DefragContext
225 225
226 226
227/** 227/**
228 * Closure for 'process_inbound_tokenized_messages' 228 * Context to send fragmented messages
229 */ 229 */
230struct FragmentationContext 230struct UDP_FragmentationContext
231{ 231{
232 struct FragmentationContext * next; 232 /**
233 struct FragmentationContext * prev; 233 * Next in linked list
234 */
235 struct UDP_FragmentationContext * next;
236
237 /**
238 * Previous in linked list
239 */
240 struct UDP_FragmentationContext * prev;
234 241
242 /**
243 * The plugin
244 */
235 struct Plugin * plugin; 245 struct Plugin * plugin;
246
247 /**
248 * Handle for GNUNET_FRAGMENT context
249 */
236 struct GNUNET_FRAGMENT_Context * frag; 250 struct GNUNET_FRAGMENT_Context * frag;
251
252 /**
253 * The session this fragmentation context belongs to
254 */
237 struct Session * session; 255 struct Session * session;
238 256
239 /** 257 /**
@@ -246,13 +264,19 @@ struct FragmentationContext
246 */ 264 */
247 void *cont_cls; 265 void *cont_cls;
248 266
267 /**
268 * Message timeout
269 */
249 struct GNUNET_TIME_Absolute timeout; 270 struct GNUNET_TIME_Absolute timeout;
250 271
251 size_t bytes_to_send; 272 /**
273 * Payload size of original unfragmented message
274 */
275 size_t payload_size;
252}; 276};
253 277
254 278
255struct UDPMessageWrapper 279struct UDP_MessageWrapper
256{ 280{
257 /** 281 /**
258 * Session this message belongs to 282 * Session this message belongs to
@@ -263,13 +287,13 @@ struct UDPMessageWrapper
263 * DLL of messages 287 * DLL of messages
264 * previous element 288 * previous element
265 */ 289 */
266 struct UDPMessageWrapper *prev; 290 struct UDP_MessageWrapper *prev;
267 291
268 /** 292 /**
269 * DLL of messages 293 * DLL of messages
270 * previous element 294 * previous element
271 */ 295 */
272 struct UDPMessageWrapper *next; 296 struct UDP_MessageWrapper *next;
273 297
274 /** 298 /**
275 * Message with size msg_size including UDP specific overhead 299 * Message with size msg_size including UDP specific overhead
@@ -282,7 +306,7 @@ struct UDPMessageWrapper
282 size_t msg_size; 306 size_t msg_size;
283 307
284 /** 308 /**
285 * Amount of bytes used on wire to send this message 309 * Payload size of original message
286 */ 310 */
287 size_t payload_size; 311 size_t payload_size;
288 312
@@ -306,7 +330,7 @@ struct UDPMessageWrapper
306 * frag_ctx == NULL if transport <= MTU 330 * frag_ctx == NULL if transport <= MTU
307 * frag_ctx != NULL if transport > MTU 331 * frag_ctx != NULL if transport > MTU
308 */ 332 */
309 struct FragmentationContext *frag_ctx; 333 struct UDP_FragmentationContext *frag_ctx;
310}; 334};
311 335
312 336
@@ -390,7 +414,7 @@ static void
390schedule_select (struct Plugin *plugin) 414schedule_select (struct Plugin *plugin)
391{ 415{
392 struct GNUNET_TIME_Relative min_delay; 416 struct GNUNET_TIME_Relative min_delay;
393 struct UDPMessageWrapper *udpw; 417 struct UDP_MessageWrapper *udpw;
394 418
395 if (NULL != plugin->sockv4) 419 if (NULL != plugin->sockv4)
396 { 420 {
@@ -655,11 +679,11 @@ udp_plugin_address_pretty_printer (void *cls, const char *type,
655 679
656 680
657static void 681static void
658call_continuation (struct UDPMessageWrapper *udpw, int result) 682call_continuation (struct UDP_MessageWrapper *udpw, int result)
659{ 683{
660 LOG (GNUNET_ERROR_TYPE_DEBUG, 684 LOG (GNUNET_ERROR_TYPE_DEBUG,
661 "Calling continuation for %u byte message to `%s' with result %s\n", 685 "Calling continuation for %u byte message to `%s' with result %s\n",
662 udpw->msg_size, GNUNET_i2s (&udpw->session->target), 686 udpw->payload_size, GNUNET_i2s (&udpw->session->target),
663 (GNUNET_OK == result) ? "OK" : "SYSERR"); 687 (GNUNET_OK == result) ? "OK" : "SYSERR");
664 if (NULL != udpw->cont) 688 if (NULL != udpw->cont)
665 { 689 {
@@ -774,8 +798,8 @@ free_session (struct Session *s)
774static void 798static void
775disconnect_session (struct Session *s) 799disconnect_session (struct Session *s)
776{ 800{
777 struct UDPMessageWrapper *udpw; 801 struct UDP_MessageWrapper *udpw;
778 struct UDPMessageWrapper *next; 802 struct UDP_MessageWrapper *next;
779 803
780 GNUNET_assert (GNUNET_YES != s->in_destroy); 804 GNUNET_assert (GNUNET_YES != s->in_destroy);
781 LOG (GNUNET_ERROR_TYPE_DEBUG, 805 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1141,7 +1165,7 @@ udp_plugin_get_session (void *cls,
1141 1165
1142 1166
1143static void 1167static void
1144enqueue (struct Plugin *plugin, struct UDPMessageWrapper * udpw) 1168enqueue (struct Plugin *plugin, struct UDP_MessageWrapper * udpw)
1145{ 1169{
1146 1170
1147 if (udpw->session->addrlen == sizeof (struct sockaddr_in)) 1171 if (udpw->session->addrlen == sizeof (struct sockaddr_in))
@@ -1164,7 +1188,7 @@ send_next_fragment (void *cls,
1164 const struct GNUNET_PeerIdentity *target, 1188 const struct GNUNET_PeerIdentity *target,
1165 int result) 1189 int result)
1166{ 1190{
1167 struct UDPMessageWrapper *udpw = cls; 1191 struct UDP_MessageWrapper *udpw = cls;
1168 1192
1169 GNUNET_FRAGMENT_context_transmission_done (udpw->frag_ctx->frag); 1193 GNUNET_FRAGMENT_context_transmission_done (udpw->frag_ctx->frag);
1170} 1194}
@@ -1182,18 +1206,18 @@ send_next_fragment (void *cls,
1182static void 1206static void
1183enqueue_fragment (void *cls, const struct GNUNET_MessageHeader *msg) 1207enqueue_fragment (void *cls, const struct GNUNET_MessageHeader *msg)
1184{ 1208{
1185 struct FragmentationContext *frag_ctx = cls; 1209 struct UDP_FragmentationContext *frag_ctx = cls;
1186 struct Plugin *plugin = frag_ctx->plugin; 1210 struct Plugin *plugin = frag_ctx->plugin;
1187 struct UDPMessageWrapper * udpw; 1211 struct UDP_MessageWrapper * udpw;
1188 size_t msg_len = ntohs (msg->size); 1212 size_t msg_len = ntohs (msg->size);
1189 1213
1190 LOG (GNUNET_ERROR_TYPE_DEBUG, 1214 LOG (GNUNET_ERROR_TYPE_DEBUG,
1191 "Enqueuing fragment with %u bytes %u\n", msg_len , sizeof (struct UDPMessageWrapper)); 1215 "Enqueuing fragment with %u bytes\n", msg_len);
1192 udpw = GNUNET_malloc (sizeof (struct UDPMessageWrapper) + msg_len); 1216 udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + msg_len);
1193 udpw->session = frag_ctx->session; 1217 udpw->session = frag_ctx->session;
1194 udpw->msg_buf = (char *) &udpw[1]; 1218 udpw->msg_buf = (char *) &udpw[1];
1195
1196 udpw->msg_size = msg_len; 1219 udpw->msg_size = msg_len;
1220 udpw->payload_size = msg_len; /*FIXME: minus fragment overhead */
1197 udpw->cont = &send_next_fragment; 1221 udpw->cont = &send_next_fragment;
1198 udpw->cont_cls = udpw; 1222 udpw->cont_cls = udpw;
1199 udpw->timeout = frag_ctx->timeout; 1223 udpw->timeout = frag_ctx->timeout;
@@ -1241,7 +1265,7 @@ udp_plugin_send (void *cls,
1241{ 1265{
1242 struct Plugin *plugin = cls; 1266 struct Plugin *plugin = cls;
1243 size_t udpmlen = msgbuf_size + sizeof (struct UDPMessage); 1267 size_t udpmlen = msgbuf_size + sizeof (struct UDPMessage);
1244 struct UDPMessageWrapper * udpw; 1268 struct UDP_MessageWrapper * udpw;
1245 struct UDPMessage *udp; 1269 struct UDPMessage *udp;
1246 char mbuf[udpmlen]; 1270 char mbuf[udpmlen];
1247 GNUNET_assert (plugin != NULL); 1271 GNUNET_assert (plugin != NULL);
@@ -1285,10 +1309,11 @@ udp_plugin_send (void *cls,
1285 reschedule_session_timeout(s); 1309 reschedule_session_timeout(s);
1286 if (udpmlen <= UDP_MTU) 1310 if (udpmlen <= UDP_MTU)
1287 { 1311 {
1288 udpw = GNUNET_malloc (sizeof (struct UDPMessageWrapper) + udpmlen); 1312 udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + udpmlen);
1289 udpw->session = s; 1313 udpw->session = s;
1290 udpw->msg_buf = (char *) &udpw[1]; 1314 udpw->msg_buf = (char *) &udpw[1];
1291 udpw->msg_size = udpmlen; 1315 udpw->msg_size = udpmlen; /* message size with UDP overhead */
1316 udpw->payload_size = msgbuf_size; /* message size without UDP overhead */
1292 udpw->timeout = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), to); 1317 udpw->timeout = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), to);
1293 udpw->cont = cont; 1318 udpw->cont = cont;
1294 udpw->cont_cls = cont_cls; 1319 udpw->cont_cls = cont_cls;
@@ -1304,14 +1329,14 @@ udp_plugin_send (void *cls,
1304 if (s->frag_ctx != NULL) 1329 if (s->frag_ctx != NULL)
1305 return GNUNET_SYSERR; 1330 return GNUNET_SYSERR;
1306 memcpy (&udp[1], msgbuf, msgbuf_size); 1331 memcpy (&udp[1], msgbuf, msgbuf_size);
1307 struct FragmentationContext * frag_ctx = GNUNET_malloc(sizeof (struct FragmentationContext)); 1332 struct UDP_FragmentationContext * frag_ctx = GNUNET_malloc(sizeof (struct UDP_FragmentationContext));
1308 1333
1309 frag_ctx->plugin = plugin; 1334 frag_ctx->plugin = plugin;
1310 frag_ctx->session = s; 1335 frag_ctx->session = s;
1311 frag_ctx->cont = cont; 1336 frag_ctx->cont = cont;
1312 frag_ctx->cont_cls = cont_cls; 1337 frag_ctx->cont_cls = cont_cls;
1313 frag_ctx->timeout = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), to); 1338 frag_ctx->timeout = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), to);
1314 frag_ctx->bytes_to_send = udpmlen; 1339 frag_ctx->payload_size = msgbuf_size; /* unfragmented message size without UDP overhead */
1315 frag_ctx->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats, 1340 frag_ctx->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats,
1316 UDP_MTU, 1341 UDP_MTU,
1317 &plugin->tracker, 1342 &plugin->tracker,
@@ -1582,7 +1607,7 @@ ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg)
1582 size_t msize = sizeof (struct UDP_ACK_Message) + ntohs (msg->size); 1607 size_t msize = sizeof (struct UDP_ACK_Message) + ntohs (msg->size);
1583 struct UDP_ACK_Message *udp_ack; 1608 struct UDP_ACK_Message *udp_ack;
1584 uint32_t delay = 0; 1609 uint32_t delay = 0;
1585 struct UDPMessageWrapper *udpw; 1610 struct UDP_MessageWrapper *udpw;
1586 struct Session *s; 1611 struct Session *s;
1587 1612
1588 struct LookupContext l_ctx; 1613 struct LookupContext l_ctx;
@@ -1607,7 +1632,7 @@ ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg)
1607 AF_INET) ? sizeof (struct sockaddr_in) : sizeof (struct 1632 AF_INET) ? sizeof (struct sockaddr_in) : sizeof (struct
1608 sockaddr_in6)), 1633 sockaddr_in6)),
1609 delay); 1634 delay);
1610 udpw = GNUNET_malloc (sizeof (struct UDPMessageWrapper) + msize); 1635 udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + msize);
1611 udpw->msg_size = msize; 1636 udpw->msg_size = msize;
1612 udpw->session = s; 1637 udpw->session = s;
1613 udpw->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; 1638 udpw->timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
@@ -1698,8 +1723,8 @@ read_process_ack (struct Plugin *plugin,
1698 GNUNET_a2s ((const struct sockaddr *) addr, fromlen)); 1723 GNUNET_a2s ((const struct sockaddr *) addr, fromlen));
1699 s->last_expected_delay = GNUNET_FRAGMENT_context_destroy (s->frag_ctx->frag); 1724 s->last_expected_delay = GNUNET_FRAGMENT_context_destroy (s->frag_ctx->frag);
1700 1725
1701 struct UDPMessageWrapper * udpw; 1726 struct UDP_MessageWrapper * udpw;
1702 struct UDPMessageWrapper * tmp; 1727 struct UDP_MessageWrapper * tmp;
1703 if (s->addrlen == sizeof (struct sockaddr_in6)) 1728 if (s->addrlen == sizeof (struct sockaddr_in6))
1704 { 1729 {
1705 udpw = plugin->ipv6_queue_head; 1730 udpw = plugin->ipv6_queue_head;
@@ -1893,7 +1918,7 @@ udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock)
1893 ssize_t sent; 1918 ssize_t sent;
1894 size_t slen; 1919 size_t slen;
1895 struct GNUNET_TIME_Absolute max; 1920 struct GNUNET_TIME_Absolute max;
1896 struct UDPMessageWrapper *udpw = NULL; 1921 struct UDP_MessageWrapper *udpw = NULL;
1897 static int network_down_error; 1922 static int network_down_error;
1898 1923
1899 if (sock == plugin->sockv4) 1924 if (sock == plugin->sockv4)
@@ -1924,8 +1949,8 @@ udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock)
1924 if (udpw->frag_ctx != NULL) 1949 if (udpw->frag_ctx != NULL)
1925 { 1950 {
1926 LOG (GNUNET_ERROR_TYPE_DEBUG, 1951 LOG (GNUNET_ERROR_TYPE_DEBUG,
1927 "Fragmented message for peer `%s' with size %u timed out\n", 1952 "Fragment for message for peer `%s' with size %u timed out\n",
1928 GNUNET_i2s(&udpw->session->target), udpw->frag_ctx->bytes_to_send); 1953 GNUNET_i2s(&udpw->session->target), udpw->frag_ctx->payload_size);
1929 udpw->session->last_expected_delay = GNUNET_FRAGMENT_context_destroy (udpw->frag_ctx->frag); 1954 udpw->session->last_expected_delay = GNUNET_FRAGMENT_context_destroy (udpw->frag_ctx->frag);
1930 GNUNET_free (udpw->frag_ctx); 1955 GNUNET_free (udpw->frag_ctx);
1931 udpw->session->frag_ctx = NULL; 1956 udpw->session->frag_ctx = NULL;
@@ -1934,7 +1959,7 @@ udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock)
1934 { 1959 {
1935 LOG (GNUNET_ERROR_TYPE_DEBUG, 1960 LOG (GNUNET_ERROR_TYPE_DEBUG,
1936 "Message for peer `%s' with size %u timed out\n", 1961 "Message for peer `%s' with size %u timed out\n",
1937 GNUNET_i2s(&udpw->session->target), udpw->msg_size); 1962 GNUNET_i2s(&udpw->session->target), udpw->payload_size);
1938 } 1963 }
1939 1964
1940 if (sock == plugin->sockv4) 1965 if (sock == plugin->sockv4)
@@ -1958,7 +1983,7 @@ udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock)
1958 /* this message is not delayed */ 1983 /* this message is not delayed */
1959 LOG (GNUNET_ERROR_TYPE_DEBUG, 1984 LOG (GNUNET_ERROR_TYPE_DEBUG,
1960 "Message for peer `%s' (%u bytes) is not delayed \n", 1985 "Message for peer `%s' (%u bytes) is not delayed \n",
1961 GNUNET_i2s(&udpw->session->target), udpw->msg_size); 1986 GNUNET_i2s(&udpw->session->target), udpw->payload_size);
1962 break; 1987 break;
1963 } 1988 }
1964 else 1989 else
@@ -1966,8 +1991,7 @@ udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock)
1966 /* this message is delayed, try next */ 1991 /* this message is delayed, try next */
1967 LOG (GNUNET_ERROR_TYPE_DEBUG, 1992 LOG (GNUNET_ERROR_TYPE_DEBUG,
1968 "Message for peer `%s' (%u bytes) is delayed for %llu \n", 1993 "Message for peer `%s' (%u bytes) is delayed for %llu \n",
1969 GNUNET_i2s(&udpw->session->target), udpw->msg_size, 1994 GNUNET_i2s(&udpw->session->target), udpw->payload_size, delta);
1970 delta);
1971 udpw = udpw->next; 1995 udpw = udpw->next;
1972 } 1996 }
1973 } 1997 }
@@ -2020,7 +2044,7 @@ udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock)
2020 { 2044 {
2021 LOG (GNUNET_ERROR_TYPE_WARNING, 2045 LOG (GNUNET_ERROR_TYPE_WARNING,
2022 "UDP could not transmit %u-byte message to `%s': `%s'\n", 2046 "UDP could not transmit %u-byte message to `%s': `%s'\n",
2023 (unsigned int) (udpw->msg_size), GNUNET_a2s (sa, slen), 2047 (unsigned int) (udpw->payload_size), GNUNET_a2s (sa, slen),
2024 STRERROR (errno)); 2048 STRERROR (errno));
2025 } 2049 }
2026 call_continuation(udpw, GNUNET_SYSERR); 2050 call_continuation(udpw, GNUNET_SYSERR);
@@ -2507,11 +2531,11 @@ libgnunet_plugin_transport_udp_done (void *cls)
2507 } 2531 }
2508 2532
2509 /* Clean up leftover messages */ 2533 /* Clean up leftover messages */
2510 struct UDPMessageWrapper * udpw; 2534 struct UDP_MessageWrapper * udpw;
2511 udpw = plugin->ipv4_queue_head; 2535 udpw = plugin->ipv4_queue_head;
2512 while (udpw != NULL) 2536 while (udpw != NULL)
2513 { 2537 {
2514 struct UDPMessageWrapper *tmp = udpw->next; 2538 struct UDP_MessageWrapper *tmp = udpw->next;
2515 GNUNET_CONTAINER_DLL_remove(plugin->ipv4_queue_head, plugin->ipv4_queue_tail, udpw); 2539 GNUNET_CONTAINER_DLL_remove(plugin->ipv4_queue_head, plugin->ipv4_queue_tail, udpw);
2516 call_continuation(udpw, GNUNET_SYSERR); 2540 call_continuation(udpw, GNUNET_SYSERR);
2517 GNUNET_free (udpw); 2541 GNUNET_free (udpw);
@@ -2520,7 +2544,7 @@ libgnunet_plugin_transport_udp_done (void *cls)
2520 udpw = plugin->ipv6_queue_head; 2544 udpw = plugin->ipv6_queue_head;
2521 while (udpw != NULL) 2545 while (udpw != NULL)
2522 { 2546 {
2523 struct UDPMessageWrapper *tmp = udpw->next; 2547 struct UDP_MessageWrapper *tmp = udpw->next;
2524 GNUNET_CONTAINER_DLL_remove(plugin->ipv6_queue_head, plugin->ipv6_queue_tail, udpw); 2548 GNUNET_CONTAINER_DLL_remove(plugin->ipv6_queue_head, plugin->ipv6_queue_tail, udpw);
2525 call_continuation(udpw, GNUNET_SYSERR); 2549 call_continuation(udpw, GNUNET_SYSERR);
2526 GNUNET_free (udpw); 2550 GNUNET_free (udpw);