diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-01-30 01:04:52 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-01-30 01:04:52 +0100 |
commit | b7a32a5aadbddcf3a910b8ca12c962025bd7ab23 (patch) | |
tree | fd4c4157db9bfed68fd16619414be8810f6ccbd7 /src/transport | |
parent | a945c5532d3737d5ebe18395d3ec8a6fad344e01 (diff) | |
download | gnunet-b7a32a5aadbddcf3a910b8ca12c962025bd7ab23.tar.gz gnunet-b7a32a5aadbddcf3a910b8ca12c962025bd7ab23.zip |
more work on UDP communicator
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/gnunet-communicator-udp.c | 144 |
1 files changed, 129 insertions, 15 deletions
diff --git a/src/transport/gnunet-communicator-udp.c b/src/transport/gnunet-communicator-udp.c index 23fb289bc..3d1a02563 100644 --- a/src/transport/gnunet-communicator-udp.c +++ b/src/transport/gnunet-communicator-udp.c | |||
@@ -548,7 +548,9 @@ receiver_destroy (struct ReceiverAddress *receiver) | |||
548 | GNUNET_CONTAINER_multipeermap_remove (receivers, | 548 | GNUNET_CONTAINER_multipeermap_remove (receivers, |
549 | &receiver->target, | 549 | &receiver->target, |
550 | receiver)); | 550 | receiver)); |
551 | // FIXME: remove from receiver_heap | 551 | GNUNET_assert (sender == |
552 | GNUNET_CONTAINER_heap_remove_node (receivers_heap, | ||
553 | receiver->hn)); | ||
552 | GNUNET_STATISTICS_set (stats, | 554 | GNUNET_STATISTICS_set (stats, |
553 | "# receivers active", | 555 | "# receivers active", |
554 | GNUNET_CONTAINER_multipeermap_size (receivers), | 556 | GNUNET_CONTAINER_multipeermap_size (receivers), |
@@ -693,7 +695,9 @@ sender_destroy (struct SenderAddress *sender) | |||
693 | GNUNET_CONTAINER_multipeermap_remove (senders, | 695 | GNUNET_CONTAINER_multipeermap_remove (senders, |
694 | &sender->target, | 696 | &sender->target, |
695 | sender)); | 697 | sender)); |
696 | // FIXME: remove from sender_heap | 698 | GNUNET_assert (sender == |
699 | GNUNET_CONTAINER_heap_remove_node (senders_heap, | ||
700 | sender->hn)); | ||
697 | GNUNET_STATISTICS_set (stats, | 701 | GNUNET_STATISTICS_set (stats, |
698 | "# senders active", | 702 | "# senders active", |
699 | GNUNET_CONTAINER_multipeermap_size (senders), | 703 | GNUNET_CONTAINER_multipeermap_size (senders), |
@@ -782,7 +786,8 @@ reschedule_sender_timeout (struct SenderAddress *sender) | |||
782 | { | 786 | { |
783 | sender->timeout | 787 | sender->timeout |
784 | = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 788 | = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
785 | // FIXME: update heap! | 789 | GNUNET_CONTAINER_heap_update_cost (sender->hn, |
790 | sender.timeout.abs_value_us); | ||
786 | } | 791 | } |
787 | 792 | ||
788 | 793 | ||
@@ -796,7 +801,8 @@ reschedule_receiver_timeout (struct ReceiverAddress *receiver) | |||
796 | { | 801 | { |
797 | receiver->timeout | 802 | receiver->timeout |
798 | = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 803 | = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
799 | // FIXME: update heap! | 804 | GNUNET_CONTAINER_heap_update_cost (receiver->hn, |
805 | receiver.timeout.abs_value_us); | ||
800 | } | 806 | } |
801 | 807 | ||
802 | 808 | ||
@@ -1117,6 +1123,110 @@ decrypt_box (const struct UDPBox *box, | |||
1117 | 1123 | ||
1118 | 1124 | ||
1119 | /** | 1125 | /** |
1126 | * Closure for #find_sender_by_address() | ||
1127 | */ | ||
1128 | struct SearchContext | ||
1129 | { | ||
1130 | /** | ||
1131 | * Address we are looking for. | ||
1132 | */ | ||
1133 | const struct sockaddr *address; | ||
1134 | |||
1135 | /** | ||
1136 | * Number of bytes in @e address. | ||
1137 | */ | ||
1138 | socklen_t address_len; | ||
1139 | |||
1140 | /** | ||
1141 | * Return value to set if we found a match. | ||
1142 | */ | ||
1143 | struct SenderAddress *sender; | ||
1144 | }; | ||
1145 | |||
1146 | |||
1147 | /** | ||
1148 | * Find existing `struct SenderAddress` by matching addresses. | ||
1149 | * | ||
1150 | * @param cls a `struct SearchContext` | ||
1151 | * @param key ignored, must match already | ||
1152 | * @param value a `struct SenderAddress` | ||
1153 | * @return #GNUNET_YES if not found (continue to search), #GNUNET_NO if found | ||
1154 | */ | ||
1155 | static int | ||
1156 | find_sender_by_address (void *cls, | ||
1157 | const struct GNUNET_PeerIdentity *key, | ||
1158 | void *value) | ||
1159 | { | ||
1160 | struct SearchContext *sc = cls; | ||
1161 | struct SenderAddress *sender = value; | ||
1162 | |||
1163 | if ( (sender->address_len == sc->address_len) && | ||
1164 | (0 == memcmp (sender->address, | ||
1165 | sc->address, | ||
1166 | sender->address_len)) ) | ||
1167 | { | ||
1168 | sc->sender = sender; | ||
1169 | return GNUNET_NO; /* stop iterating! */ | ||
1170 | } | ||
1171 | return GNUNET_YES; | ||
1172 | } | ||
1173 | |||
1174 | |||
1175 | /** | ||
1176 | * Create sender address for @a target. Note that we | ||
1177 | * might already have one, so a fresh one is only allocated | ||
1178 | * if one does not yet exist for @a address. | ||
1179 | * | ||
1180 | * @param target peer to generate address for | ||
1181 | * @param address target address | ||
1182 | * @param address_len number of bytes in @a address | ||
1183 | * @return data structure to keep track of key material for | ||
1184 | * decrypting data from @a target | ||
1185 | */ | ||
1186 | static struct SenderAddress * | ||
1187 | setup_sender (const struct GNUNET_PeerIdentity *target, | ||
1188 | const struct sockaddr *address, | ||
1189 | socklen_t address_len) | ||
1190 | { | ||
1191 | struct SenderAddress *sender; | ||
1192 | struct SearchContext sc = { | ||
1193 | .address = address, | ||
1194 | .address_len = address_len, | ||
1195 | .sender = NULL | ||
1196 | }; | ||
1197 | |||
1198 | GNUNET_CONTAINER_multihashmap_get_multiple (senders, | ||
1199 | target, | ||
1200 | &find_sender_by_address, | ||
1201 | &sc); | ||
1202 | if (NULL != sc.sender) | ||
1203 | return sc.sender; | ||
1204 | sender = GNUNET_new (struct SenderAddress); | ||
1205 | sender->target = *target; | ||
1206 | sender->address = GNUNET_memdup (address, | ||
1207 | address_len); | ||
1208 | sender->address_len = address_len; | ||
1209 | (void) GNUNET_CONTAINER_multihashmap_put (senders, | ||
1210 | &sender->target, | ||
1211 | sender, | ||
1212 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
1213 | GNUNET_STATISTICS_set (stats, | ||
1214 | "# senders active", | ||
1215 | GNUNET_CONTAINER_multipeermap_size (receivers), | ||
1216 | GNUNET_NO); | ||
1217 | sender->timeout | ||
1218 | = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | ||
1219 | sender->hn = GNUNET_CONTAINER_heap_insert (senders_heap, | ||
1220 | sender, | ||
1221 | sender.timeout.abs_value_us); | ||
1222 | sender->nt = GNUNET_NT_scanner_get_type (is, | ||
1223 | address, | ||
1224 | address_len); | ||
1225 | return sender; | ||
1226 | } | ||
1227 | |||
1228 | |||
1229 | /** | ||
1120 | * Socket read task. | 1230 | * Socket read task. |
1121 | * | 1231 | * |
1122 | * @param cls NULL | 1232 | * @param cls NULL |
@@ -1526,13 +1636,11 @@ receiver_setup (const struct GNUNET_PeerIdentity *target, | |||
1526 | &receiver->target, | 1636 | &receiver->target, |
1527 | receiver, | 1637 | receiver, |
1528 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 1638 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
1529 | // FIXME: add to receiver heap! | ||
1530 | GNUNET_STATISTICS_set (stats, | ||
1531 | "# receivers active", | ||
1532 | GNUNET_CONTAINER_multipeermap_size (receivers), | ||
1533 | GNUNET_NO); | ||
1534 | receiver->timeout | 1639 | receiver->timeout |
1535 | = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 1640 | = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
1641 | receiver->hn = GNUNET_CONTAINER_heap_insert (receivers_heap, | ||
1642 | receiver, | ||
1643 | receiver.timeout.abs_value_us); | ||
1536 | receiver->mq | 1644 | receiver->mq |
1537 | = GNUNET_MQ_queue_for_callbacks (&mq_send, | 1645 | = GNUNET_MQ_queue_for_callbacks (&mq_send, |
1538 | &mq_destroy, | 1646 | &mq_destroy, |
@@ -1541,6 +1649,10 @@ receiver_setup (const struct GNUNET_PeerIdentity *target, | |||
1541 | NULL, | 1649 | NULL, |
1542 | &mq_error, | 1650 | &mq_error, |
1543 | receiver); | 1651 | receiver); |
1652 | GNUNET_STATISTICS_set (stats, | ||
1653 | "# receivers active", | ||
1654 | GNUNET_CONTAINER_multipeermap_size (receivers), | ||
1655 | GNUNET_NO); | ||
1544 | { | 1656 | { |
1545 | char *foreign_addr; | 1657 | char *foreign_addr; |
1546 | 1658 | ||
@@ -1895,6 +2007,14 @@ run (void *cls, | |||
1895 | sto_len)); | 2007 | sto_len)); |
1896 | stats = GNUNET_STATISTICS_create ("C-UDP", | 2008 | stats = GNUNET_STATISTICS_create ("C-UDP", |
1897 | cfg); | 2009 | cfg); |
2010 | senders = GNUNET_CONTAINER_multipeermap_create (32, | ||
2011 | GNUNET_YES); | ||
2012 | receivers = GNUNET_CONTAINER_multipeermap_create (32, | ||
2013 | GNUNET_YES); | ||
2014 | senders_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | ||
2015 | receivers_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | ||
2016 | key_cache = GNUNET_CONTAINER_multishortmap_create (1024, | ||
2017 | GNUNET_YES); | ||
1898 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | 2018 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, |
1899 | NULL); | 2019 | NULL); |
1900 | is = GNUNET_NT_scanner_init (); | 2020 | is = GNUNET_NT_scanner_init (); |
@@ -1913,12 +2033,6 @@ run (void *cls, | |||
1913 | udp_sock, | 2033 | udp_sock, |
1914 | &sock_read, | 2034 | &sock_read, |
1915 | NULL); | 2035 | NULL); |
1916 | senders = GNUNET_CONTAINER_multipeermap_create (32, | ||
1917 | GNUNET_YES); | ||
1918 | receivers = GNUNET_CONTAINER_multipeermap_create (32, | ||
1919 | GNUNET_YES); | ||
1920 | key_cache = GNUNET_CONTAINER_multishortmap_create (1024, | ||
1921 | GNUNET_YES); | ||
1922 | ch = GNUNET_TRANSPORT_communicator_connect (cfg, | 2036 | ch = GNUNET_TRANSPORT_communicator_connect (cfg, |
1923 | COMMUNICATOR_CONFIG_SECTION, | 2037 | COMMUNICATOR_CONFIG_SECTION, |
1924 | COMMUNICATOR_ADDRESS_PREFIX, | 2038 | COMMUNICATOR_ADDRESS_PREFIX, |