aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-communicator-udp.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-01-30 01:34:36 +0100
committerChristian Grothoff <christian@grothoff.org>2019-01-30 01:34:36 +0100
commita3dfb3954f1ae0ac7d0135af5e0562d71f25c036 (patch)
treeff4538db62b70f68494a0f94e3585bbe0d9bf4cf /src/transport/gnunet-communicator-udp.c
parentb7a32a5aadbddcf3a910b8ca12c962025bd7ab23 (diff)
downloadgnunet-a3dfb3954f1ae0ac7d0135af5e0562d71f25c036.tar.gz
gnunet-a3dfb3954f1ae0ac7d0135af5e0562d71f25c036.zip
deal with timeouts
Diffstat (limited to 'src/transport/gnunet-communicator-udp.c')
-rw-r--r--src/transport/gnunet-communicator-udp.c97
1 files changed, 74 insertions, 23 deletions
diff --git a/src/transport/gnunet-communicator-udp.c b/src/transport/gnunet-communicator-udp.c
index 3d1a02563..8265c4970 100644
--- a/src/transport/gnunet-communicator-udp.c
+++ b/src/transport/gnunet-communicator-udp.c
@@ -24,6 +24,17 @@
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 * 25 *
26 * TODO: 26 * TODO:
27 * - main sending logic
28 * - actual generation of ACKs (-> integrate with sending logic!)
29 * (specifically, ACKs should go as backchannel, let TNG
30 * decide how to send!)
31 * - handle ACKs from backchannel!
32 * - figure out what to do with MTU: 1280 for IPv6 is obvious;
33 * what for IPv4? 1500? Also, consider differences in
34 * headers for with/without box: need to give MIN of both
35 * to TNG (as TNG expects a fixed MTU!), or maybe
36 * we create a FRESH MQ while we have available BOXes SQNs?
37 * (otherwise padding will REALLY hurt)
27 * - support DNS names in BINDTO option (#5528) 38 * - support DNS names in BINDTO option (#5528)
28 * - support NAT connection reversal method (#5529) 39 * - support NAT connection reversal method (#5529)
29 * - support other UDP-specific NAT traversal methods 40 * - support other UDP-specific NAT traversal methods
@@ -807,6 +818,47 @@ reschedule_receiver_timeout (struct ReceiverAddress *receiver)
807 818
808 819
809/** 820/**
821 * Task run to check #receiver_heap and #sender_heap for timeouts.
822 *
823 * @param cls unused, NULL
824 */
825static void
826check_timeouts (void *cls)
827{
828 struct GNUNET_TIME_Relative st;
829 struct GNUNET_TIME_Relative rt;
830 struct GNUNET_TIME_Relative delay;
831 struct ReceiverAddress *receiver;
832 struct SenderAddress *sender;
833
834 (void) cls;
835 timeout_task = NULL;
836 rt = GNUNET_TIME_UNIT_FOREVER_REL;
837 while (NULL != (receiver = GNUNET_CONTAINER_heap_peek (receivers_heap)))
838 {
839 rt = GNUNET_TIME_absolute_get_remaining (receiver->timeout);
840 if (0 != rt.rel_value_us)
841 break;
842 receiver_destroy (receiver);
843 }
844 st = GNUNET_TIME_UNIT_FOREVER_REL;
845 while (NULL != (sender = GNUNET_CONTAINER_heap_peek (senders_heap)))
846 {
847 st = GNUNET_TIME_absolute_get_remaining (receiver->timeout);
848 if (0 != st.rel_value_us)
849 break;
850 sender_destroy (sender);
851 }
852 delay = GNUNET_TIME_relative_min (rt,
853 st);
854 if (delay.rel_value_us < GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
855 timeout_task = GNUNET_SCHEDULER_add_delayed (delay,
856 &check_timeouts,
857 NULL);
858}
859
860
861/**
810 * Calcualte cmac from master in @a ss. 862 * Calcualte cmac from master in @a ss.
811 * 863 *
812 * @param ss[in,out] data structure to complete 864 * @param ss[in,out] data structure to complete
@@ -1200,7 +1252,10 @@ setup_sender (const struct GNUNET_PeerIdentity *target,
1200 &find_sender_by_address, 1252 &find_sender_by_address,
1201 &sc); 1253 &sc);
1202 if (NULL != sc.sender) 1254 if (NULL != sc.sender)
1255 {
1256 reschedule_sender_timeout (sc.sender);
1203 return sc.sender; 1257 return sc.sender;
1258 }
1204 sender = GNUNET_new (struct SenderAddress); 1259 sender = GNUNET_new (struct SenderAddress);
1205 sender->target = *target; 1260 sender->target = *target;
1206 sender->address = GNUNET_memdup (address, 1261 sender->address = GNUNET_memdup (address,
@@ -1222,6 +1277,9 @@ setup_sender (const struct GNUNET_PeerIdentity *target,
1222 sender->nt = GNUNET_NT_scanner_get_type (is, 1277 sender->nt = GNUNET_NT_scanner_get_type (is,
1223 address, 1278 address,
1224 address_len); 1279 address_len);
1280 if (NULL == timeout_task)
1281 timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts,
1282 NULL);
1225 return sender; 1283 return sender;
1226} 1284}
1227 1285
@@ -1484,28 +1542,6 @@ udp_address_to_sockaddr (const char *bindto,
1484} 1542}
1485 1543
1486 1544
1487#if 0
1488/**
1489 *
1490 *
1491 */
1492static void
1493XXX_write (void *cls)
1494{
1495 ssize_t sent;
1496
1497 sent = GNUNET_NETWORK_socket_sendto (udp_sock,
1498 );
1499 if (-1 == sent)
1500 {
1501 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
1502 "send");
1503 return;
1504 }
1505}
1506#endif
1507
1508
1509/** 1545/**
1510 * Signature of functions implementing the sending functionality of a 1546 * Signature of functions implementing the sending functionality of a
1511 * message queue. 1547 * message queue.
@@ -1521,9 +1557,10 @@ mq_send (struct GNUNET_MQ_Handle *mq,
1521{ 1557{
1522 struct ReceiverAddress *receiver = impl_state; 1558 struct ReceiverAddress *receiver = impl_state;
1523 uint16_t msize = ntohs (msg->size); 1559 uint16_t msize = ntohs (msg->size);
1560 ssize_t sent;
1524 1561
1525 GNUNET_assert (mq == receiver->mq); 1562 GNUNET_assert (mq == receiver->mq);
1526 // FIXME: pick encryption method, encrypt and transmit and call MQ-send-contiue!! 1563 // FIXME: pick encryption method, encrypt and transmit!!
1527 1564
1528#if 0 1565#if 0
1529 /* compute 'tc' and append in encrypted format to cwrite_buf */ 1566 /* compute 'tc' and append in encrypted format to cwrite_buf */
@@ -1545,6 +1582,17 @@ mq_send (struct GNUNET_MQ_Handle *mq,
1545 sizeof (tc), 1582 sizeof (tc),
1546 &tc, 1583 &tc,
1547 sizeof (tc))); 1584 sizeof (tc)));
1585
1586 sent = GNUNET_NETWORK_socket_sendto (udp_sock,
1587 ...);
1588 GNUNET_MQ_impl_send_continue (mq);
1589 if (-1 == sent)
1590 {
1591 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
1592 "send");
1593 return;
1594 }
1595
1548#endif 1596#endif
1549 1597
1550 1598
@@ -1649,6 +1697,9 @@ receiver_setup (const struct GNUNET_PeerIdentity *target,
1649 NULL, 1697 NULL,
1650 &mq_error, 1698 &mq_error,
1651 receiver); 1699 receiver);
1700 if (NULL == timeout_task)
1701 timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts,
1702 NULL);
1652 GNUNET_STATISTICS_set (stats, 1703 GNUNET_STATISTICS_set (stats,
1653 "# receivers active", 1704 "# receivers active",
1654 GNUNET_CONTAINER_multipeermap_size (receivers), 1705 GNUNET_CONTAINER_multipeermap_size (receivers),