aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-communicator-udp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/gnunet-communicator-udp.c')
-rw-r--r--src/transport/gnunet-communicator-udp.c692
1 files changed, 351 insertions, 341 deletions
diff --git a/src/transport/gnunet-communicator-udp.c b/src/transport/gnunet-communicator-udp.c
index f101d2d75..1db5bba6b 100644
--- a/src/transport/gnunet-communicator-udp.c
+++ b/src/transport/gnunet-communicator-udp.c
@@ -69,6 +69,12 @@
69#define INTERFACE_SCAN_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) 69#define INTERFACE_SCAN_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
70 70
71/** 71/**
72 * How long do we believe our addresses to remain up (before
73 * the other peer should revalidate).
74 */
75#define ADDRESS_VALIDITY_PERIOD GNUNET_TIME_UNIT_HOURS
76
77/**
72 * AES key size. 78 * AES key size.
73 */ 79 */
74#define AES_KEY_SIZE (256/8) 80#define AES_KEY_SIZE (256/8)
@@ -964,11 +970,11 @@ sender_destroy (struct SenderAddress *sender)
964 &sender->target, 970 &sender->target,
965 sender)); 971 sender));
966 GNUNET_assert (sender == 972 GNUNET_assert (sender ==
967 GNUNET_CONTAINER_heap_remove_node (sender->hn)); 973 GNUNET_CONTAINER_heap_remove_node (sender->hn));
968 GNUNET_STATISTICS_set (stats, 974 GNUNET_STATISTICS_set (stats,
969 "# senders active", 975 "# senders active",
970 GNUNET_CONTAINER_multipeermap_size (senders), 976 GNUNET_CONTAINER_multipeermap_size (senders),
971 GNUNET_NO); 977 GNUNET_NO);
972 GNUNET_free (sender->address); 978 GNUNET_free (sender->address);
973 GNUNET_free (sender); 979 GNUNET_free (sender);
974} 980}
@@ -992,22 +998,22 @@ get_iv_key (const struct GNUNET_HashCode *msec,
992 char res[AES_KEY_SIZE + AES_IV_SIZE]; 998 char res[AES_KEY_SIZE + AES_IV_SIZE];
993 999
994 GNUNET_CRYPTO_hkdf (res, 1000 GNUNET_CRYPTO_hkdf (res,
995 sizeof (res), 1001 sizeof (res),
996 GCRY_MD_SHA512, 1002 GCRY_MD_SHA512,
997 GCRY_MD_SHA256, 1003 GCRY_MD_SHA256,
998 &sid, 1004 &sid,
999 sizeof (sid), 1005 sizeof (sid),
1000 msec, 1006 msec,
1001 sizeof (*msec), 1007 sizeof (*msec),
1002 "UDP-IV-KEY", 1008 "UDP-IV-KEY",
1003 strlen ("UDP-IV-KEY"), 1009 strlen ("UDP-IV-KEY"),
1004 NULL, 0); 1010 NULL, 0);
1005 memcpy (key, 1011 memcpy (key,
1006 res, 1012 res,
1007 AES_KEY_SIZE); 1013 AES_KEY_SIZE);
1008 memcpy (iv, 1014 memcpy (iv,
1009 &res[AES_KEY_SIZE], 1015 &res[AES_KEY_SIZE],
1010 AES_IV_SIZE); 1016 AES_IV_SIZE);
1011} 1017}
1012 1018
1013 1019
@@ -1022,7 +1028,7 @@ reschedule_sender_timeout (struct SenderAddress *sender)
1022 sender->timeout 1028 sender->timeout
1023 = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 1029 = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1024 GNUNET_CONTAINER_heap_update_cost (sender->hn, 1030 GNUNET_CONTAINER_heap_update_cost (sender->hn,
1025 sender->timeout.abs_value_us); 1031 sender->timeout.abs_value_us);
1026} 1032}
1027 1033
1028 1034
@@ -1091,16 +1097,16 @@ static void
1091calculate_cmac (struct SharedSecret *ss) 1097calculate_cmac (struct SharedSecret *ss)
1092{ 1098{
1093 GNUNET_CRYPTO_hkdf (&ss->cmac, 1099 GNUNET_CRYPTO_hkdf (&ss->cmac,
1094 sizeof (ss->cmac), 1100 sizeof (ss->cmac),
1095 GCRY_MD_SHA512, 1101 GCRY_MD_SHA512,
1096 GCRY_MD_SHA256, 1102 GCRY_MD_SHA256,
1097 "CMAC", 1103 "CMAC",
1098 strlen ("CMAC"), 1104 strlen ("CMAC"),
1099 &ss->master, 1105 &ss->master,
1100 sizeof (ss->master), 1106 sizeof (ss->master),
1101 "UDP-CMAC", 1107 "UDP-CMAC",
1102 strlen ("UDP-CMAC"), 1108 strlen ("UDP-CMAC"),
1103 NULL, 0); 1109 NULL, 0);
1104} 1110}
1105 1111
1106 1112
@@ -1114,8 +1120,8 @@ calculate_cmac (struct SharedSecret *ss)
1114 */ 1120 */
1115static void 1121static void
1116pass_plaintext_to_core (struct SenderAddress *sender, 1122pass_plaintext_to_core (struct SenderAddress *sender,
1117 const void *plaintext, 1123 const void *plaintext,
1118 size_t plaintext_len) 1124 size_t plaintext_len)
1119{ 1125{
1120 const struct GNUNET_MessageHeader *hdr = plaintext; 1126 const struct GNUNET_MessageHeader *hdr = plaintext;
1121 1127
@@ -1126,10 +1132,11 @@ pass_plaintext_to_core (struct SenderAddress *sender,
1126 ntohs (hdr->size), 1132 ntohs (hdr->size),
1127 GNUNET_NO); 1133 GNUNET_NO);
1128 (void) GNUNET_TRANSPORT_communicator_receive (ch, 1134 (void) GNUNET_TRANSPORT_communicator_receive (ch,
1129 &sender->target, 1135 &sender->target,
1130 hdr, 1136 hdr,
1131 NULL /* no flow control possible */, 1137 ADDRESS_VALIDITY_PERIOD,
1132 NULL); 1138 NULL /* no flow control possible */,
1139 NULL);
1133 /* move on to next message, if any */ 1140 /* move on to next message, if any */
1134 plaintext_len -= ntohs (hdr->size); 1141 plaintext_len -= ntohs (hdr->size);
1135 if (plaintext_len < sizeof (*hdr)) 1142 if (plaintext_len < sizeof (*hdr))
@@ -1137,9 +1144,9 @@ pass_plaintext_to_core (struct SenderAddress *sender,
1137 hdr = plaintext + ntohs (hdr->size); 1144 hdr = plaintext + ntohs (hdr->size);
1138 } 1145 }
1139 GNUNET_STATISTICS_update (stats, 1146 GNUNET_STATISTICS_update (stats,
1140 "# bytes padding discarded", 1147 "# bytes padding discarded",
1141 plaintext_len, 1148 plaintext_len,
1142 GNUNET_NO); 1149 GNUNET_NO);
1143} 1150}
1144 1151
1145 1152
@@ -1153,26 +1160,26 @@ pass_plaintext_to_core (struct SenderAddress *sender,
1153 */ 1160 */
1154static void 1161static void
1155setup_cipher (const struct GNUNET_HashCode *msec, 1162setup_cipher (const struct GNUNET_HashCode *msec,
1156 uint32_t serial, 1163 uint32_t serial,
1157 gcry_cipher_hd_t *cipher) 1164 gcry_cipher_hd_t *cipher)
1158{ 1165{
1159 char key[AES_KEY_SIZE]; 1166 char key[AES_KEY_SIZE];
1160 char iv[AES_IV_SIZE]; 1167 char iv[AES_IV_SIZE];
1161 1168
1162 gcry_cipher_open (cipher, 1169 gcry_cipher_open (cipher,
1163 GCRY_CIPHER_AES256 /* low level: go for speed */, 1170 GCRY_CIPHER_AES256 /* low level: go for speed */,
1164 GCRY_CIPHER_MODE_GCM, 1171 GCRY_CIPHER_MODE_GCM,
1165 0 /* flags */); 1172 0 /* flags */);
1166 get_iv_key (msec, 1173 get_iv_key (msec,
1167 serial, 1174 serial,
1168 key, 1175 key,
1169 iv); 1176 iv);
1170 gcry_cipher_setkey (*cipher, 1177 gcry_cipher_setkey (*cipher,
1171 key, 1178 key,
1172 sizeof (key)); 1179 sizeof (key));
1173 gcry_cipher_setiv (*cipher, 1180 gcry_cipher_setiv (*cipher,
1174 iv, 1181 iv,
1175 sizeof (iv)); 1182 sizeof (iv));
1176} 1183}
1177 1184
1178 1185
@@ -1190,33 +1197,33 @@ setup_cipher (const struct GNUNET_HashCode *msec,
1190 */ 1197 */
1191static int 1198static int
1192try_decrypt (const struct SharedSecret *ss, 1199try_decrypt (const struct SharedSecret *ss,
1193 const char tag[GCM_TAG_SIZE], 1200 const char tag[GCM_TAG_SIZE],
1194 uint32_t serial, 1201 uint32_t serial,
1195 const char *in_buf, 1202 const char *in_buf,
1196 size_t in_buf_size, 1203 size_t in_buf_size,
1197 char *out_buf) 1204 char *out_buf)
1198{ 1205{
1199 gcry_cipher_hd_t cipher; 1206 gcry_cipher_hd_t cipher;
1200 1207
1201 setup_cipher (&ss->master, 1208 setup_cipher (&ss->master,
1202 serial, 1209 serial,
1203 &cipher); 1210 &cipher);
1204 GNUNET_assert (0 == 1211 GNUNET_assert (0 ==
1205 gcry_cipher_decrypt (cipher, 1212 gcry_cipher_decrypt (cipher,
1206 out_buf, 1213 out_buf,
1207 in_buf_size, 1214 in_buf_size,
1208 in_buf, 1215 in_buf,
1209 in_buf_size)); 1216 in_buf_size));
1210 if (0 != 1217 if (0 !=
1211 gcry_cipher_checktag (cipher, 1218 gcry_cipher_checktag (cipher,
1212 tag, 1219 tag,
1213 GCM_TAG_SIZE)) 1220 GCM_TAG_SIZE))
1214 { 1221 {
1215 gcry_cipher_close (cipher); 1222 gcry_cipher_close (cipher);
1216 GNUNET_STATISTICS_update (stats, 1223 GNUNET_STATISTICS_update (stats,
1217 "# AEAD authentication failures", 1224 "# AEAD authentication failures",
1218 1, 1225 1,
1219 GNUNET_NO); 1226 GNUNET_NO);
1220 return GNUNET_SYSERR; 1227 return GNUNET_SYSERR;
1221 } 1228 }
1222 gcry_cipher_close (cipher); 1229 gcry_cipher_close (cipher);
@@ -1237,8 +1244,8 @@ setup_shared_secret_dec (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral)
1237 1244
1238 ss = GNUNET_new (struct SharedSecret); 1245 ss = GNUNET_new (struct SharedSecret);
1239 GNUNET_CRYPTO_eddsa_ecdh (my_private_key, 1246 GNUNET_CRYPTO_eddsa_ecdh (my_private_key,
1240 ephemeral, 1247 ephemeral,
1241 &ss->master); 1248 &ss->master);
1242 return ss; 1249 return ss;
1243} 1250}
1244 1251
@@ -1258,18 +1265,18 @@ setup_shared_secret_enc (const struct GNUNET_CRYPTO_EcdhePrivateKey *ephemeral,
1258 1265
1259 ss = GNUNET_new (struct SharedSecret); 1266 ss = GNUNET_new (struct SharedSecret);
1260 GNUNET_CRYPTO_ecdh_eddsa (ephemeral, 1267 GNUNET_CRYPTO_ecdh_eddsa (ephemeral,
1261 &receiver->target.public_key, 1268 &receiver->target.public_key,
1262 &ss->master); 1269 &ss->master);
1263 calculate_cmac (ss); 1270 calculate_cmac (ss);
1264 ss->receiver = receiver; 1271 ss->receiver = receiver;
1265 GNUNET_CONTAINER_DLL_insert (receiver->ss_head, 1272 GNUNET_CONTAINER_DLL_insert (receiver->ss_head,
1266 receiver->ss_tail, 1273 receiver->ss_tail,
1267 ss); 1274 ss);
1268 receiver->num_secrets++; 1275 receiver->num_secrets++;
1269 GNUNET_STATISTICS_update (stats, 1276 GNUNET_STATISTICS_update (stats,
1270 "# Secrets active", 1277 "# Secrets active",
1271 1, 1278 1,
1272 GNUNET_NO); 1279 GNUNET_NO);
1273 return ss; 1280 return ss;
1274} 1281}
1275 1282
@@ -1297,8 +1304,8 @@ setup_receiver_mq (struct ReceiverAddress *receiver);
1297 */ 1304 */
1298static int 1305static int
1299handle_ack (void *cls, 1306handle_ack (void *cls,
1300 const struct GNUNET_PeerIdentity *pid, 1307 const struct GNUNET_PeerIdentity *pid,
1301 void *value) 1308 void *value)
1302{ 1309{
1303 const struct UDPAck *ack = cls; 1310 const struct UDPAck *ack = cls;
1304 struct ReceiverAddress *receiver = value; 1311 struct ReceiverAddress *receiver = value;
@@ -1309,8 +1316,8 @@ handle_ack (void *cls,
1309 ss = ss->next) 1316 ss = ss->next)
1310 { 1317 {
1311 if (0 == memcmp (&ack->cmac, 1318 if (0 == memcmp (&ack->cmac,
1312 &ss->cmac, 1319 &ss->cmac,
1313 sizeof (struct GNUNET_HashCode))) 1320 sizeof (struct GNUNET_HashCode)))
1314 { 1321 {
1315 uint32_t allowed; 1322 uint32_t allowed;
1316 1323
@@ -1318,21 +1325,21 @@ handle_ack (void *cls,
1318 1325
1319 if (allowed > ss->sequence_allowed) 1326 if (allowed > ss->sequence_allowed)
1320 { 1327 {
1321 receiver->acks_available += (allowed - ss->sequence_allowed); 1328 receiver->acks_available += (allowed - ss->sequence_allowed);
1322 if ((allowed - ss->sequence_allowed) 1329 if ((allowed - ss->sequence_allowed)
1323 == receiver->acks_available) 1330 == receiver->acks_available)
1324 { 1331 {
1325 /* we just incremented from zero => MTU change! */ 1332 /* we just incremented from zero => MTU change! */
1326 setup_receiver_mq (receiver); 1333 setup_receiver_mq (receiver);
1327 } 1334 }
1328 ss->sequence_allowed = allowed; 1335 ss->sequence_allowed = allowed;
1329 /* move ss to head to avoid discarding it anytime soon! */ 1336 /* move ss to head to avoid discarding it anytime soon! */
1330 GNUNET_CONTAINER_DLL_remove (receiver->ss_head, 1337 GNUNET_CONTAINER_DLL_remove (receiver->ss_head,
1331 receiver->ss_tail, 1338 receiver->ss_tail,
1332 ss); 1339 ss);
1333 GNUNET_CONTAINER_DLL_insert (receiver->ss_head, 1340 GNUNET_CONTAINER_DLL_insert (receiver->ss_head,
1334 receiver->ss_tail, 1341 receiver->ss_tail,
1335 ss); 1342 ss);
1336 } 1343 }
1337 return GNUNET_NO; 1344 return GNUNET_NO;
1338 } 1345 }
@@ -1351,8 +1358,8 @@ handle_ack (void *cls,
1351 */ 1358 */
1352static void 1359static void
1353try_handle_plaintext (struct SenderAddress *sender, 1360try_handle_plaintext (struct SenderAddress *sender,
1354 const void *buf, 1361 const void *buf,
1355 size_t buf_size) 1362 size_t buf_size)
1356{ 1363{
1357 const struct GNUNET_MessageHeader *hdr 1364 const struct GNUNET_MessageHeader *hdr
1358 = (const struct GNUNET_MessageHeader *) buf; 1365 = (const struct GNUNET_MessageHeader *) buf;
@@ -1370,23 +1377,23 @@ try_handle_plaintext (struct SenderAddress *sender,
1370 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK: 1377 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK:
1371 /* lookup master secret by 'cmac', then update sequence_max */ 1378 /* lookup master secret by 'cmac', then update sequence_max */
1372 GNUNET_CONTAINER_multipeermap_get_multiple (receivers, 1379 GNUNET_CONTAINER_multipeermap_get_multiple (receivers,
1373 &sender->target, 1380 &sender->target,
1374 &handle_ack, 1381 &handle_ack,
1375 (void *) ack); 1382 (void *) ack);
1376 /* There could be more messages after the ACK, handle those as well */ 1383 /* There could be more messages after the ACK, handle those as well */
1377 buf += ntohs (hdr->size); 1384 buf += ntohs (hdr->size);
1378 buf_size -= ntohs (hdr->size); 1385 buf_size -= ntohs (hdr->size);
1379 pass_plaintext_to_core (sender, 1386 pass_plaintext_to_core (sender,
1380 buf, 1387 buf,
1381 buf_size); 1388 buf_size);
1382 break; 1389 break;
1383 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD: 1390 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD:
1384 /* skip padding */ 1391 /* skip padding */
1385 break; 1392 break;
1386 default: 1393 default:
1387 pass_plaintext_to_core (sender, 1394 pass_plaintext_to_core (sender,
1388 buf, 1395 buf,
1389 buf_size); 1396 buf_size);
1390 } 1397 }
1391} 1398}
1392 1399
@@ -1413,7 +1420,7 @@ consider_ss_ack (struct SharedSecret *ss)
1413 1420
1414 while (ss->active_kce_count < KCN_TARGET) 1421 while (ss->active_kce_count < KCN_TARGET)
1415 kce_generate (ss, 1422 kce_generate (ss,
1416 ++ss->sequence_allowed); 1423 ++ss->sequence_allowed);
1417 ack.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK); 1424 ack.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK);
1418 ack.header.size = htons (sizeof (ack)); 1425 ack.header.size = htons (sizeof (ack));
1419 ack.sequence_max = htonl (ss->sequence_allowed); 1426 ack.sequence_max = htonl (ss->sequence_allowed);
@@ -1435,8 +1442,8 @@ consider_ss_ack (struct SharedSecret *ss)
1435 */ 1442 */
1436static void 1443static void
1437decrypt_box (const struct UDPBox *box, 1444decrypt_box (const struct UDPBox *box,
1438 size_t box_len, 1445 size_t box_len,
1439 struct KeyCacheEntry *kce) 1446 struct KeyCacheEntry *kce)
1440{ 1447{
1441 struct SharedSecret *ss = kce->ss; 1448 struct SharedSecret *ss = kce->ss;
1442 char out_buf[box_len - sizeof (*box)]; 1449 char out_buf[box_len - sizeof (*box)];
@@ -1444,11 +1451,11 @@ decrypt_box (const struct UDPBox *box,
1444 GNUNET_assert (NULL != ss->sender); 1451 GNUNET_assert (NULL != ss->sender);
1445 if (GNUNET_OK != 1452 if (GNUNET_OK !=
1446 try_decrypt (ss, 1453 try_decrypt (ss,
1447 box->gcm_tag, 1454 box->gcm_tag,
1448 kce->sequence_number, 1455 kce->sequence_number,
1449 (const char *) &box[1], 1456 (const char *) &box[1],
1450 sizeof (out_buf), 1457 sizeof (out_buf),
1451 out_buf)) 1458 out_buf))
1452 { 1459 {
1453 GNUNET_STATISTICS_update (stats, 1460 GNUNET_STATISTICS_update (stats,
1454 "# Decryption failures with valid KCE", 1461 "# Decryption failures with valid KCE",
@@ -1459,12 +1466,12 @@ decrypt_box (const struct UDPBox *box,
1459 } 1466 }
1460 kce_destroy (kce); 1467 kce_destroy (kce);
1461 GNUNET_STATISTICS_update (stats, 1468 GNUNET_STATISTICS_update (stats,
1462 "# bytes decrypted with BOX", 1469 "# bytes decrypted with BOX",
1463 sizeof (out_buf), 1470 sizeof (out_buf),
1464 GNUNET_NO); 1471 GNUNET_NO);
1465 try_handle_plaintext (ss->sender, 1472 try_handle_plaintext (ss->sender,
1466 out_buf, 1473 out_buf,
1467 sizeof (out_buf)); 1474 sizeof (out_buf));
1468 consider_ss_ack (ss); 1475 consider_ss_ack (ss);
1469} 1476}
1470 1477
@@ -1501,16 +1508,16 @@ struct SearchContext
1501 */ 1508 */
1502static int 1509static int
1503find_sender_by_address (void *cls, 1510find_sender_by_address (void *cls,
1504 const struct GNUNET_PeerIdentity *key, 1511 const struct GNUNET_PeerIdentity *key,
1505 void *value) 1512 void *value)
1506{ 1513{
1507 struct SearchContext *sc = cls; 1514 struct SearchContext *sc = cls;
1508 struct SenderAddress *sender = value; 1515 struct SenderAddress *sender = value;
1509 1516
1510 if ( (sender->address_len == sc->address_len) && 1517 if ( (sender->address_len == sc->address_len) &&
1511 (0 == memcmp (sender->address, 1518 (0 == memcmp (sender->address,
1512 sc->address, 1519 sc->address,
1513 sender->address_len)) ) 1520 sender->address_len)) )
1514 { 1521 {
1515 sc->sender = sender; 1522 sc->sender = sender;
1516 return GNUNET_NO; /* stop iterating! */ 1523 return GNUNET_NO; /* stop iterating! */
@@ -1532,8 +1539,8 @@ find_sender_by_address (void *cls,
1532 */ 1539 */
1533static struct SenderAddress * 1540static struct SenderAddress *
1534setup_sender (const struct GNUNET_PeerIdentity *target, 1541setup_sender (const struct GNUNET_PeerIdentity *target,
1535 const struct sockaddr *address, 1542 const struct sockaddr *address,
1536 socklen_t address_len) 1543 socklen_t address_len)
1537{ 1544{
1538 struct SenderAddress *sender; 1545 struct SenderAddress *sender;
1539 struct SearchContext sc = { 1546 struct SearchContext sc = {
@@ -1543,9 +1550,9 @@ setup_sender (const struct GNUNET_PeerIdentity *target,
1543 }; 1550 };
1544 1551
1545 GNUNET_CONTAINER_multipeermap_get_multiple (senders, 1552 GNUNET_CONTAINER_multipeermap_get_multiple (senders,
1546 target, 1553 target,
1547 &find_sender_by_address, 1554 &find_sender_by_address,
1548 &sc); 1555 &sc);
1549 if (NULL != sc.sender) 1556 if (NULL != sc.sender)
1550 { 1557 {
1551 reschedule_sender_timeout (sc.sender); 1558 reschedule_sender_timeout (sc.sender);
@@ -1554,27 +1561,27 @@ setup_sender (const struct GNUNET_PeerIdentity *target,
1554 sender = GNUNET_new (struct SenderAddress); 1561 sender = GNUNET_new (struct SenderAddress);
1555 sender->target = *target; 1562 sender->target = *target;
1556 sender->address = GNUNET_memdup (address, 1563 sender->address = GNUNET_memdup (address,
1557 address_len); 1564 address_len);
1558 sender->address_len = address_len; 1565 sender->address_len = address_len;
1559 (void) GNUNET_CONTAINER_multipeermap_put (senders, 1566 (void) GNUNET_CONTAINER_multipeermap_put (senders,
1560 &sender->target, 1567 &sender->target,
1561 sender, 1568 sender,
1562 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 1569 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1563 GNUNET_STATISTICS_set (stats, 1570 GNUNET_STATISTICS_set (stats,
1564 "# senders active", 1571 "# senders active",
1565 GNUNET_CONTAINER_multipeermap_size (receivers), 1572 GNUNET_CONTAINER_multipeermap_size (receivers),
1566 GNUNET_NO); 1573 GNUNET_NO);
1567 sender->timeout 1574 sender->timeout
1568 = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 1575 = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1569 sender->hn = GNUNET_CONTAINER_heap_insert (senders_heap, 1576 sender->hn = GNUNET_CONTAINER_heap_insert (senders_heap,
1570 sender, 1577 sender,
1571 sender->timeout.abs_value_us); 1578 sender->timeout.abs_value_us);
1572 sender->nt = GNUNET_NT_scanner_get_type (is, 1579 sender->nt = GNUNET_NT_scanner_get_type (is,
1573 address, 1580 address,
1574 address_len); 1581 address_len);
1575 if (NULL == timeout_task) 1582 if (NULL == timeout_task)
1576 timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts, 1583 timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts,
1577 NULL); 1584 NULL);
1578 return sender; 1585 return sender;
1579} 1586}
1580 1587
@@ -1759,11 +1766,11 @@ sock_read (void *cls)
1759 ss = setup_shared_secret_dec (&kx->ephemeral); 1766 ss = setup_shared_secret_dec (&kx->ephemeral);
1760 if (GNUNET_OK != 1767 if (GNUNET_OK !=
1761 try_decrypt (ss, 1768 try_decrypt (ss,
1762 kx->gcm_tag, 1769 kx->gcm_tag,
1763 0, 1770 0,
1764 &buf[sizeof (*kx)], 1771 &buf[sizeof (*kx)],
1765 sizeof (pbuf), 1772 sizeof (pbuf),
1766 pbuf)) 1773 pbuf))
1767 { 1774 {
1768 GNUNET_free (ss); 1775 GNUNET_free (ss);
1769 GNUNET_STATISTICS_update (stats, 1776 GNUNET_STATISTICS_update (stats,
@@ -1774,8 +1781,8 @@ sock_read (void *cls)
1774 } 1781 }
1775 uc = (const struct UDPConfirmation *) pbuf; 1782 uc = (const struct UDPConfirmation *) pbuf;
1776 if (GNUNET_OK != 1783 if (GNUNET_OK !=
1777 verify_confirmation (&kx->ephemeral, 1784 verify_confirmation (&kx->ephemeral,
1778 uc)) 1785 uc))
1779 { 1786 {
1780 GNUNET_break_op (0); 1787 GNUNET_break_op (0);
1781 GNUNET_free (ss); 1788 GNUNET_free (ss);
@@ -1787,24 +1794,24 @@ sock_read (void *cls)
1787 } 1794 }
1788 calculate_cmac (ss); 1795 calculate_cmac (ss);
1789 sender = setup_sender (&uc->sender, 1796 sender = setup_sender (&uc->sender,
1790 (const struct sockaddr *) &sa, 1797 (const struct sockaddr *) &sa,
1791 salen); 1798 salen);
1792 ss->sender = sender; 1799 ss->sender = sender;
1793 GNUNET_CONTAINER_DLL_insert (sender->ss_head, 1800 GNUNET_CONTAINER_DLL_insert (sender->ss_head,
1794 sender->ss_tail, 1801 sender->ss_tail,
1795 ss); 1802 ss);
1796 sender->num_secrets++; 1803 sender->num_secrets++;
1797 GNUNET_STATISTICS_update (stats, 1804 GNUNET_STATISTICS_update (stats,
1798 "# Secrets active", 1805 "# Secrets active",
1799 1, 1806 1,
1800 GNUNET_NO); 1807 GNUNET_NO);
1801 GNUNET_STATISTICS_update (stats, 1808 GNUNET_STATISTICS_update (stats,
1802 "# messages decrypted without BOX", 1809 "# messages decrypted without BOX",
1803 1, 1810 1,
1804 GNUNET_NO); 1811 GNUNET_NO);
1805 try_handle_plaintext (sender, 1812 try_handle_plaintext (sender,
1806 &uc[1], 1813 &uc[1],
1807 sizeof (pbuf) - sizeof (*uc)); 1814 sizeof (pbuf) - sizeof (*uc));
1808 consider_ss_ack (ss); 1815 consider_ss_ack (ss);
1809 if (sender->num_secrets > MAX_SECRETS) 1816 if (sender->num_secrets > MAX_SECRETS)
1810 secret_destroy (sender->ss_tail); 1817 secret_destroy (sender->ss_tail);
@@ -1821,7 +1828,7 @@ sock_read (void *cls)
1821 */ 1828 */
1822static struct sockaddr * 1829static struct sockaddr *
1823udp_address_to_sockaddr (const char *bindto, 1830udp_address_to_sockaddr (const char *bindto,
1824 socklen_t *sock_len) 1831 socklen_t *sock_len)
1825{ 1832{
1826 struct sockaddr *in; 1833 struct sockaddr *in;
1827 unsigned int port; 1834 unsigned int port;
@@ -1830,24 +1837,24 @@ udp_address_to_sockaddr (const char *bindto,
1830 char *cp; 1837 char *cp;
1831 1838
1832 if (1 == SSCANF (bindto, 1839 if (1 == SSCANF (bindto,
1833 "%u%1s", 1840 "%u%1s",
1834 &port, 1841 &port,
1835 dummy)) 1842 dummy))
1836 { 1843 {
1837 /* interpreting value as just a PORT number */ 1844 /* interpreting value as just a PORT number */
1838 if (port > UINT16_MAX) 1845 if (port > UINT16_MAX)
1839 { 1846 {
1840 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1847 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1841 "BINDTO specification `%s' invalid: value too large for port\n", 1848 "BINDTO specification `%s' invalid: value too large for port\n",
1842 bindto); 1849 bindto);
1843 return NULL; 1850 return NULL;
1844 } 1851 }
1845 if ( (GNUNET_NO == 1852 if ( (GNUNET_NO ==
1846 GNUNET_NETWORK_test_pf (PF_INET6)) || 1853 GNUNET_NETWORK_test_pf (PF_INET6)) ||
1847 (GNUNET_YES == 1854 (GNUNET_YES ==
1848 GNUNET_CONFIGURATION_get_value_yesno (cfg, 1855 GNUNET_CONFIGURATION_get_value_yesno (cfg,
1849 COMMUNICATOR_CONFIG_SECTION, 1856 COMMUNICATOR_CONFIG_SECTION,
1850 "DISABLE_V6")) ) 1857 "DISABLE_V6")) )
1851 { 1858 {
1852 struct sockaddr_in *i4; 1859 struct sockaddr_in *i4;
1853 1860
@@ -1877,16 +1884,16 @@ udp_address_to_sockaddr (const char *bindto,
1877 *colon = '\0'; 1884 *colon = '\0';
1878 colon++; 1885 colon++;
1879 if (1 == SSCANF (colon, 1886 if (1 == SSCANF (colon,
1880 "%u%1s", 1887 "%u%1s",
1881 &port, 1888 &port,
1882 dummy)) 1889 dummy))
1883 { 1890 {
1884 /* interpreting value as just a PORT number */ 1891 /* interpreting value as just a PORT number */
1885 if (port > UINT16_MAX) 1892 if (port > UINT16_MAX)
1886 { 1893 {
1887 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1894 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1888 "BINDTO specification `%s' invalid: value too large for port\n", 1895 "BINDTO specification `%s' invalid: value too large for port\n",
1889 bindto); 1896 bindto);
1890 GNUNET_free (cp); 1897 GNUNET_free (cp);
1891 return NULL; 1898 return NULL;
1892 } 1899 }
@@ -1894,8 +1901,8 @@ udp_address_to_sockaddr (const char *bindto,
1894 else 1901 else
1895 { 1902 {
1896 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1903 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1897 "BINDTO specification `%s' invalid: last ':' not followed by number\n", 1904 "BINDTO specification `%s' invalid: last ':' not followed by number\n",
1898 bindto); 1905 bindto);
1899 GNUNET_free (cp); 1906 GNUNET_free (cp);
1900 return NULL; 1907 return NULL;
1901 } 1908 }
@@ -1915,7 +1922,7 @@ udp_address_to_sockaddr (const char *bindto,
1915 { 1922 {
1916 v4.sin_port = htons ((uint16_t) port); 1923 v4.sin_port = htons ((uint16_t) port);
1917 in = GNUNET_memdup (&v4, 1924 in = GNUNET_memdup (&v4,
1918 sizeof (v4)); 1925 sizeof (v4));
1919 *sock_len = sizeof (v4); 1926 *sock_len = sizeof (v4);
1920 GNUNET_free (cp); 1927 GNUNET_free (cp);
1921 return in; 1928 return in;
@@ -1934,12 +1941,12 @@ udp_address_to_sockaddr (const char *bindto,
1934 cp[strlen (cp) -1] = '\0'; /* eat ']' */ 1941 cp[strlen (cp) -1] = '\0'; /* eat ']' */
1935 } 1942 }
1936 if (1 == inet_pton (AF_INET6, 1943 if (1 == inet_pton (AF_INET6,
1937 start, 1944 start,
1938 &v6)) 1945 &v6))
1939 { 1946 {
1940 v6.sin6_port = htons ((uint16_t) port); 1947 v6.sin6_port = htons ((uint16_t) port);
1941 in = GNUNET_memdup (&v6, 1948 in = GNUNET_memdup (&v6,
1942 sizeof (v6)); 1949 sizeof (v6));
1943 *sock_len = sizeof (v6); 1950 *sock_len = sizeof (v6);
1944 GNUNET_free (cp); 1951 GNUNET_free (cp);
1945 return in; 1952 return in;
@@ -1960,14 +1967,14 @@ udp_address_to_sockaddr (const char *bindto,
1960 */ 1967 */
1961static void 1968static void
1962do_pad (gcry_cipher_hd_t out_cipher, 1969do_pad (gcry_cipher_hd_t out_cipher,
1963 char *dgram, 1970 char *dgram,
1964 size_t pad_size) 1971 size_t pad_size)
1965{ 1972{
1966 char pad[pad_size]; 1973 char pad[pad_size];
1967 1974
1968 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, 1975 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
1969 pad, 1976 pad,
1970 sizeof (pad)); 1977 sizeof (pad));
1971 if (sizeof (pad) > sizeof (struct GNUNET_MessageHeader)) 1978 if (sizeof (pad) > sizeof (struct GNUNET_MessageHeader))
1972 { 1979 {
1973 struct GNUNET_MessageHeader hdr = { 1980 struct GNUNET_MessageHeader hdr = {
@@ -1980,11 +1987,11 @@ do_pad (gcry_cipher_hd_t out_cipher,
1980 sizeof (hdr)); 1987 sizeof (hdr));
1981 } 1988 }
1982 GNUNET_assert (0 == 1989 GNUNET_assert (0 ==
1983 gcry_cipher_encrypt (out_cipher, 1990 gcry_cipher_encrypt (out_cipher,
1984 dgram, 1991 dgram,
1985 sizeof (pad), 1992 sizeof (pad),
1986 pad, 1993 pad,
1987 sizeof (pad))); 1994 sizeof (pad)));
1988} 1995}
1989 1996
1990 1997
@@ -1998,8 +2005,8 @@ do_pad (gcry_cipher_hd_t out_cipher,
1998 */ 2005 */
1999static void 2006static void
2000mq_send (struct GNUNET_MQ_Handle *mq, 2007mq_send (struct GNUNET_MQ_Handle *mq,
2001 const struct GNUNET_MessageHeader *msg, 2008 const struct GNUNET_MessageHeader *msg,
2002 void *impl_state) 2009 void *impl_state)
2003{ 2010{
2004 struct ReceiverAddress *receiver = impl_state; 2011 struct ReceiverAddress *receiver = impl_state;
2005 uint16_t msize = ntohs (msg->size); 2012 uint16_t msize = ntohs (msg->size);
@@ -2021,21 +2028,21 @@ mq_send (struct GNUNET_MQ_Handle *mq,
2021 struct InitialKX kx; 2028 struct InitialKX kx;
2022 struct GNUNET_CRYPTO_EcdhePrivateKey epriv; 2029 struct GNUNET_CRYPTO_EcdhePrivateKey epriv;
2023 char dgram[receiver->mtu + 2030 char dgram[receiver->mtu +
2024 sizeof (uc) + 2031 sizeof (uc) +
2025 sizeof (kx)]; 2032 sizeof (kx)];
2026 size_t dpos; 2033 size_t dpos;
2027 gcry_cipher_hd_t out_cipher; 2034 gcry_cipher_hd_t out_cipher;
2028 struct SharedSecret *ss; 2035 struct SharedSecret *ss;
2029 2036
2030 /* setup key material */ 2037 /* setup key material */
2031 GNUNET_assert (GNUNET_OK == 2038 GNUNET_assert (GNUNET_OK ==
2032 GNUNET_CRYPTO_ecdhe_key_create2 (&epriv)); 2039 GNUNET_CRYPTO_ecdhe_key_create2 (&epriv));
2033 2040
2034 ss = setup_shared_secret_enc (&epriv, 2041 ss = setup_shared_secret_enc (&epriv,
2035 receiver); 2042 receiver);
2036 setup_cipher (&ss->master, 2043 setup_cipher (&ss->master,
2037 0, 2044 0,
2038 &out_cipher); 2045 &out_cipher);
2039 /* compute 'uc' */ 2046 /* compute 'uc' */
2040 uc.sender = my_identity; 2047 uc.sender = my_identity;
2041 uc.monotonic_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg)); 2048 uc.monotonic_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg));
@@ -2047,26 +2054,26 @@ mq_send (struct GNUNET_MQ_Handle *mq,
2047 &uhs.ephemeral); 2054 &uhs.ephemeral);
2048 uhs.monotonic_time = uc.monotonic_time; 2055 uhs.monotonic_time = uc.monotonic_time;
2049 GNUNET_assert (GNUNET_OK == 2056 GNUNET_assert (GNUNET_OK ==
2050 GNUNET_CRYPTO_eddsa_sign (my_private_key, 2057 GNUNET_CRYPTO_eddsa_sign (my_private_key,
2051 &uhs.purpose, 2058 &uhs.purpose,
2052 &uc.sender_sig)); 2059 &uc.sender_sig));
2053 /* Leave space for kx */ 2060 /* Leave space for kx */
2054 dpos = sizeof (struct GNUNET_CRYPTO_EcdhePublicKey); 2061 dpos = sizeof (struct GNUNET_CRYPTO_EcdhePublicKey);
2055 /* Append encrypted uc to dgram */ 2062 /* Append encrypted uc to dgram */
2056 GNUNET_assert (0 == 2063 GNUNET_assert (0 ==
2057 gcry_cipher_encrypt (out_cipher, 2064 gcry_cipher_encrypt (out_cipher,
2058 &dgram[dpos], 2065 &dgram[dpos],
2059 sizeof (uc), 2066 sizeof (uc),
2060 &uc, 2067 &uc,
2061 sizeof (uc))); 2068 sizeof (uc)));
2062 dpos += sizeof (uc); 2069 dpos += sizeof (uc);
2063 /* Append encrypted payload to dgram */ 2070 /* Append encrypted payload to dgram */
2064 GNUNET_assert (0 == 2071 GNUNET_assert (0 ==
2065 gcry_cipher_encrypt (out_cipher, 2072 gcry_cipher_encrypt (out_cipher,
2066 &dgram[dpos], 2073 &dgram[dpos],
2067 msize, 2074 msize,
2068 msg, 2075 msg,
2069 msize)); 2076 msize));
2070 dpos += msize; 2077 dpos += msize;
2071 do_pad (out_cipher, 2078 do_pad (out_cipher,
2072 &dgram[dpos], 2079 &dgram[dpos],
@@ -2074,21 +2081,21 @@ mq_send (struct GNUNET_MQ_Handle *mq,
2074 /* Datagram starts with kx */ 2081 /* Datagram starts with kx */
2075 kx.ephemeral = uhs.ephemeral; 2082 kx.ephemeral = uhs.ephemeral;
2076 GNUNET_assert (0 == 2083 GNUNET_assert (0 ==
2077 gcry_cipher_gettag (out_cipher, 2084 gcry_cipher_gettag (out_cipher,
2078 kx.gcm_tag, 2085 kx.gcm_tag,
2079 sizeof (kx.gcm_tag))); 2086 sizeof (kx.gcm_tag)));
2080 gcry_cipher_close (out_cipher); 2087 gcry_cipher_close (out_cipher);
2081 memcpy (dgram, 2088 memcpy (dgram,
2082 &kx, 2089 &kx,
2083 sizeof (kx)); 2090 sizeof (kx));
2084 if (-1 == 2091 if (-1 ==
2085 GNUNET_NETWORK_socket_sendto (udp_sock, 2092 GNUNET_NETWORK_socket_sendto (udp_sock,
2086 dgram, 2093 dgram,
2087 sizeof (dgram), 2094 sizeof (dgram),
2088 receiver->address, 2095 receiver->address,
2089 receiver->address_len)) 2096 receiver->address_len))
2090 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 2097 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
2091 "send"); 2098 "send");
2092 GNUNET_MQ_impl_send_continue (mq); 2099 GNUNET_MQ_impl_send_continue (mq);
2093 return; 2100 return;
2094 } /* End of KX encryption method */ 2101 } /* End of KX encryption method */
@@ -2116,34 +2123,34 @@ mq_send (struct GNUNET_MQ_Handle *mq,
2116 /* Append encrypted payload to dgram */ 2123 /* Append encrypted payload to dgram */
2117 dpos = sizeof (struct UDPBox); 2124 dpos = sizeof (struct UDPBox);
2118 GNUNET_assert (0 == 2125 GNUNET_assert (0 ==
2119 gcry_cipher_encrypt (out_cipher, 2126 gcry_cipher_encrypt (out_cipher,
2120 &dgram[dpos], 2127 &dgram[dpos],
2121 msize, 2128 msize,
2122 msg, 2129 msg,
2123 msize)); 2130 msize));
2124 dpos += msize; 2131 dpos += msize;
2125 do_pad (out_cipher, 2132 do_pad (out_cipher,
2126 &dgram[dpos], 2133 &dgram[dpos],
2127 sizeof (dgram) - dpos); 2134 sizeof (dgram) - dpos);
2128 GNUNET_assert (0 == 2135 GNUNET_assert (0 ==
2129 gcry_cipher_gettag (out_cipher, 2136 gcry_cipher_gettag (out_cipher,
2130 box->gcm_tag, 2137 box->gcm_tag,
2131 sizeof (box->gcm_tag))); 2138 sizeof (box->gcm_tag)));
2132 gcry_cipher_close (out_cipher); 2139 gcry_cipher_close (out_cipher);
2133 if (-1 == 2140 if (-1 ==
2134 GNUNET_NETWORK_socket_sendto (udp_sock, 2141 GNUNET_NETWORK_socket_sendto (udp_sock,
2135 dgram, 2142 dgram,
2136 sizeof (dgram), 2143 sizeof (dgram),
2137 receiver->address, 2144 receiver->address,
2138 receiver->address_len)) 2145 receiver->address_len))
2139 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 2146 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
2140 "send"); 2147 "send");
2141 GNUNET_MQ_impl_send_continue (mq); 2148 GNUNET_MQ_impl_send_continue (mq);
2142 receiver->acks_available--; 2149 receiver->acks_available--;
2143 if (0 == receiver->acks_available) 2150 if (0 == receiver->acks_available)
2144 { 2151 {
2145 /* We have no more ACKs => MTU change! */ 2152 /* We have no more ACKs => MTU change! */
2146 setup_receiver_mq (receiver); 2153 setup_receiver_mq (receiver);
2147 } 2154 }
2148 return; 2155 return;
2149 } 2156 }
@@ -2162,7 +2169,7 @@ mq_send (struct GNUNET_MQ_Handle *mq,
2162 */ 2169 */
2163static void 2170static void
2164mq_destroy (struct GNUNET_MQ_Handle *mq, 2171mq_destroy (struct GNUNET_MQ_Handle *mq,
2165 void *impl_state) 2172 void *impl_state)
2166{ 2173{
2167 struct ReceiverAddress *receiver = impl_state; 2174 struct ReceiverAddress *receiver = impl_state;
2168 2175
@@ -2182,7 +2189,7 @@ mq_destroy (struct GNUNET_MQ_Handle *mq,
2182 */ 2189 */
2183static void 2190static void
2184mq_cancel (struct GNUNET_MQ_Handle *mq, 2191mq_cancel (struct GNUNET_MQ_Handle *mq,
2185 void *impl_state) 2192 void *impl_state)
2186{ 2193{
2187 /* Cancellation is impossible with UDP; bail */ 2194 /* Cancellation is impossible with UDP; bail */
2188 GNUNET_assert (0); 2195 GNUNET_assert (0);
@@ -2200,14 +2207,14 @@ mq_cancel (struct GNUNET_MQ_Handle *mq,
2200 */ 2207 */
2201static void 2208static void
2202mq_error (void *cls, 2209mq_error (void *cls,
2203 enum GNUNET_MQ_Error error) 2210 enum GNUNET_MQ_Error error)
2204{ 2211{
2205 struct ReceiverAddress *receiver = cls; 2212 struct ReceiverAddress *receiver = cls;
2206 2213
2207 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2214 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2208 "MQ error in queue to %s: %d\n", 2215 "MQ error in queue to %s: %d\n",
2209 GNUNET_i2s (&receiver->target), 2216 GNUNET_i2s (&receiver->target),
2210 (int) error); 2217 (int) error);
2211 receiver_destroy (receiver); 2218 receiver_destroy (receiver);
2212} 2219}
2213 2220
@@ -2266,20 +2273,20 @@ setup_receiver_mq (struct ReceiverAddress *receiver)
2266 1404 (IPv4 + Box) bytes, depending on circumstances... */ 2273 1404 (IPv4 + Box) bytes, depending on circumstances... */
2267 receiver->mq 2274 receiver->mq
2268 = GNUNET_MQ_queue_for_callbacks (&mq_send, 2275 = GNUNET_MQ_queue_for_callbacks (&mq_send,
2269 &mq_destroy, 2276 &mq_destroy,
2270 &mq_cancel, 2277 &mq_cancel,
2271 receiver, 2278 receiver,
2272 NULL, 2279 NULL,
2273 &mq_error, 2280 &mq_error,
2274 receiver); 2281 receiver);
2275 receiver->qh 2282 receiver->qh
2276 = GNUNET_TRANSPORT_communicator_mq_add (ch, 2283 = GNUNET_TRANSPORT_communicator_mq_add (ch,
2277 &receiver->target, 2284 &receiver->target,
2278 receiver->foreign_addr, 2285 receiver->foreign_addr,
2279 receiver->mtu, 2286 receiver->mtu,
2280 receiver->nt, 2287 receiver->nt,
2281 GNUNET_TRANSPORT_CS_OUTBOUND, 2288 GNUNET_TRANSPORT_CS_OUTBOUND,
2282 receiver->mq); 2289 receiver->mq);
2283} 2290}
2284 2291
2285 2292
@@ -2287,7 +2294,10 @@ setup_receiver_mq (struct ReceiverAddress *receiver)
2287 * Setup a receiver for transmission. Setup the MQ processing and 2294 * Setup a receiver for transmission. Setup the MQ processing and
2288 * inform transport that the queue is ready. 2295 * inform transport that the queue is ready.
2289 * 2296 *
2290 * @param 2297 * @param target which peer are we talking to
2298 * @param address address of the peer
2299 * @param address_len number of bytes in @a address
2300 * @return handle for the address
2291 */ 2301 */
2292static struct ReceiverAddress * 2302static struct ReceiverAddress *
2293receiver_setup (const struct GNUNET_PeerIdentity *target, 2303receiver_setup (const struct GNUNET_PeerIdentity *target,
@@ -2323,7 +2333,7 @@ receiver_setup (const struct GNUNET_PeerIdentity *target,
2323 2333
2324 if (NULL == timeout_task) 2334 if (NULL == timeout_task)
2325 timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts, 2335 timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts,
2326 NULL); 2336 NULL);
2327 return receiver; 2337 return receiver;
2328} 2338}
2329 2339
@@ -2347,8 +2357,8 @@ receiver_setup (const struct GNUNET_PeerIdentity *target,
2347 */ 2357 */
2348static int 2358static int
2349mq_init (void *cls, 2359mq_init (void *cls,
2350 const struct GNUNET_PeerIdentity *peer, 2360 const struct GNUNET_PeerIdentity *peer,
2351 const char *address) 2361 const char *address)
2352{ 2362{
2353 struct ReceiverAddress *receiver; 2363 struct ReceiverAddress *receiver;
2354 const char *path; 2364 const char *path;
@@ -2356,18 +2366,18 @@ mq_init (void *cls,
2356 socklen_t in_len; 2366 socklen_t in_len;
2357 2367
2358 if (0 != strncmp (address, 2368 if (0 != strncmp (address,
2359 COMMUNICATOR_ADDRESS_PREFIX "-", 2369 COMMUNICATOR_ADDRESS_PREFIX "-",
2360 strlen (COMMUNICATOR_ADDRESS_PREFIX "-"))) 2370 strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
2361 { 2371 {
2362 GNUNET_break_op (0); 2372 GNUNET_break_op (0);
2363 return GNUNET_SYSERR; 2373 return GNUNET_SYSERR;
2364 } 2374 }
2365 path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")]; 2375 path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
2366 in = udp_address_to_sockaddr (path, 2376 in = udp_address_to_sockaddr (path,
2367 &in_len); 2377 &in_len);
2368 receiver = receiver_setup (peer, 2378 receiver = receiver_setup (peer,
2369 in, 2379 in,
2370 in_len); 2380 in_len);
2371 (void) receiver; 2381 (void) receiver;
2372 return GNUNET_OK; 2382 return GNUNET_OK;
2373} 2383}
@@ -2383,8 +2393,8 @@ mq_init (void *cls,
2383 */ 2393 */
2384static int 2394static int
2385get_receiver_delete_it (void *cls, 2395get_receiver_delete_it (void *cls,
2386 const struct GNUNET_PeerIdentity *target, 2396 const struct GNUNET_PeerIdentity *target,
2387 void *value) 2397 void *value)
2388{ 2398{
2389 struct ReceiverAddress *receiver = value; 2399 struct ReceiverAddress *receiver = value;
2390 2400
@@ -2405,8 +2415,8 @@ get_receiver_delete_it (void *cls,
2405 */ 2415 */
2406static int 2416static int
2407get_sender_delete_it (void *cls, 2417get_sender_delete_it (void *cls,
2408 const struct GNUNET_PeerIdentity *target, 2418 const struct GNUNET_PeerIdentity *target,
2409 void *value) 2419 void *value)
2410{ 2420{
2411 struct SenderAddress *sender = value; 2421 struct SenderAddress *sender = value;
2412 2422
@@ -2449,11 +2459,11 @@ do_shutdown (void *cls)
2449 udp_sock = NULL; 2459 udp_sock = NULL;
2450 } 2460 }
2451 GNUNET_CONTAINER_multipeermap_iterate (receivers, 2461 GNUNET_CONTAINER_multipeermap_iterate (receivers,
2452 &get_receiver_delete_it, 2462 &get_receiver_delete_it,
2453 NULL); 2463 NULL);
2454 GNUNET_CONTAINER_multipeermap_destroy (receivers); 2464 GNUNET_CONTAINER_multipeermap_destroy (receivers);
2455 GNUNET_CONTAINER_multipeermap_iterate (senders, 2465 GNUNET_CONTAINER_multipeermap_iterate (senders,
2456 &get_sender_delete_it, 2466 &get_sender_delete_it,
2457 NULL); 2467 NULL);
2458 GNUNET_CONTAINER_multipeermap_destroy (senders); 2468 GNUNET_CONTAINER_multipeermap_destroy (senders);
2459 GNUNET_CONTAINER_multishortmap_destroy (key_cache); 2469 GNUNET_CONTAINER_multishortmap_destroy (key_cache);
@@ -2472,7 +2482,7 @@ do_shutdown (void *cls)
2472 if (NULL != stats) 2482 if (NULL != stats)
2473 { 2483 {
2474 GNUNET_STATISTICS_destroy (stats, 2484 GNUNET_STATISTICS_destroy (stats,
2475 GNUNET_NO); 2485 GNUNET_NO);
2476 stats = NULL; 2486 stats = NULL;
2477 } 2487 }
2478 if (NULL != my_private_key) 2488 if (NULL != my_private_key)
@@ -2482,8 +2492,8 @@ do_shutdown (void *cls)
2482 } 2492 }
2483 if (NULL != is) 2493 if (NULL != is)
2484 { 2494 {
2485 GNUNET_NT_scanner_done (is); 2495 GNUNET_NT_scanner_done (is);
2486 is = NULL; 2496 is = NULL;
2487 } 2497 }
2488} 2498}
2489 2499
@@ -2513,9 +2523,9 @@ enc_notify_cb (void *cls,
2513 } 2523 }
2514 ack = (const struct UDPAck *) msg; 2524 ack = (const struct UDPAck *) msg;
2515 GNUNET_CONTAINER_multipeermap_get_multiple (receivers, 2525 GNUNET_CONTAINER_multipeermap_get_multiple (receivers,
2516 sender, 2526 sender,
2517 &handle_ack, 2527 &handle_ack,
2518 (void *) ack); 2528 (void *) ack);
2519} 2529}
2520 2530
2521 2531
@@ -2534,11 +2544,11 @@ enc_notify_cb (void *cls,
2534 */ 2544 */
2535static void 2545static void
2536nat_address_cb (void *cls, 2546nat_address_cb (void *cls,
2537 void **app_ctx, 2547 void **app_ctx,
2538 int add_remove, 2548 int add_remove,
2539 enum GNUNET_NAT_AddressClass ac, 2549 enum GNUNET_NAT_AddressClass ac,
2540 const struct sockaddr *addr, 2550 const struct sockaddr *addr,
2541 socklen_t addrlen) 2551 socklen_t addrlen)
2542{ 2552{
2543 char *my_addr; 2553 char *my_addr;
2544 struct GNUNET_TRANSPORT_AddressIdentifier *ai; 2554 struct GNUNET_TRANSPORT_AddressIdentifier *ai;
@@ -2556,9 +2566,9 @@ nat_address_cb (void *cls,
2556 addr, 2566 addr,
2557 addrlen); 2567 addrlen);
2558 ai = GNUNET_TRANSPORT_communicator_address_add (ch, 2568 ai = GNUNET_TRANSPORT_communicator_address_add (ch,
2559 my_addr, 2569 my_addr,
2560 nt, 2570 nt,
2561 GNUNET_TIME_UNIT_FOREVER_REL); 2571 GNUNET_TIME_UNIT_FOREVER_REL);
2562 GNUNET_free (my_addr); 2572 GNUNET_free (my_addr);
2563 *app_ctx = ai; 2573 *app_ctx = ai;
2564 } 2574 }
@@ -2584,7 +2594,7 @@ ifc_broadcast (void *cls)
2584 2594
2585 delay = BROADCAST_FREQUENCY; 2595 delay = BROADCAST_FREQUENCY;
2586 delay.rel_value_us = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 2596 delay.rel_value_us = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
2587 delay.rel_value_us); 2597 delay.rel_value_us);
2588 bi->broadcast_task 2598 bi->broadcast_task
2589 = GNUNET_SCHEDULER_add_delayed (INTERFACE_SCAN_FREQUENCY, 2599 = GNUNET_SCHEDULER_add_delayed (INTERFACE_SCAN_FREQUENCY,
2590 &ifc_broadcast, 2600 &ifc_broadcast,
@@ -2598,29 +2608,29 @@ ifc_broadcast (void *cls)
2598 ssize_t sent; 2608 ssize_t sent;
2599 2609
2600 if (GNUNET_OK != 2610 if (GNUNET_OK !=
2601 GNUNET_NETWORK_socket_setsockopt (udp_sock, 2611 GNUNET_NETWORK_socket_setsockopt (udp_sock,
2602 SOL_SOCKET, 2612 SOL_SOCKET,
2603 SO_BROADCAST, 2613 SO_BROADCAST,
2604 &yes, 2614 &yes,
2605 sizeof (int))) 2615 sizeof (int)))
2606 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 2616 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
2607 "setsockopt"); 2617 "setsockopt");
2608 sent = GNUNET_NETWORK_socket_sendto (udp_sock, 2618 sent = GNUNET_NETWORK_socket_sendto (udp_sock,
2609 &bi->bcm, 2619 &bi->bcm,
2610 sizeof (bi->bcm), 2620 sizeof (bi->bcm),
2611 bi->ba, 2621 bi->ba,
2612 bi->salen); 2622 bi->salen);
2613 if (-1 == sent) 2623 if (-1 == sent)
2614 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 2624 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
2615 "sendto"); 2625 "sendto");
2616 if (GNUNET_OK != 2626 if (GNUNET_OK !=
2617 GNUNET_NETWORK_socket_setsockopt (udp_sock, 2627 GNUNET_NETWORK_socket_setsockopt (udp_sock,
2618 SOL_SOCKET, 2628 SOL_SOCKET,
2619 SO_BROADCAST, 2629 SO_BROADCAST,
2620 &no, 2630 &no,
2621 sizeof (int))) 2631 sizeof (int)))
2622 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 2632 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
2623 "setsockopt"); 2633 "setsockopt");
2624 break; 2634 break;
2625 } 2635 }
2626 case AF_INET6: 2636 case AF_INET6:
@@ -2634,14 +2644,14 @@ ifc_broadcast (void *cls)
2634 dst.sin6_scope_id = ((struct sockaddr_in6*) bi->ba)->sin6_scope_id; 2644 dst.sin6_scope_id = ((struct sockaddr_in6*) bi->ba)->sin6_scope_id;
2635 2645
2636 sent = GNUNET_NETWORK_socket_sendto (udp_sock, 2646 sent = GNUNET_NETWORK_socket_sendto (udp_sock,
2637 &bi->bcm, 2647 &bi->bcm,
2638 sizeof (bi->bcm), 2648 sizeof (bi->bcm),
2639 (const struct sockaddr *) 2649 (const struct sockaddr *)
2640 &dst, 2650 &dst,
2641 sizeof (dst)); 2651 sizeof (dst));
2642 if (-1 == sent) 2652 if (-1 == sent)
2643 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 2653 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
2644 "sendto"); 2654 "sendto");
2645 break; 2655 break;
2646 } 2656 }
2647 default: 2657 default:
@@ -2679,8 +2689,8 @@ iface_proc (void *cls,
2679 (void) cls; 2689 (void) cls;
2680 (void) netmask; 2690 (void) netmask;
2681 network = GNUNET_NT_scanner_get_type (is, 2691 network = GNUNET_NT_scanner_get_type (is,
2682 addr, 2692 addr,
2683 addrlen); 2693 addrlen);
2684 if (GNUNET_NT_LOOPBACK == network) 2694 if (GNUNET_NT_LOOPBACK == network)
2685 { 2695 {
2686 /* Broadcasting on loopback does not make sense */ 2696 /* Broadcasting on loopback does not make sense */
@@ -2691,9 +2701,9 @@ iface_proc (void *cls,
2691 for (bi = bi_head; NULL != bi; bi = bi->next) 2701 for (bi = bi_head; NULL != bi; bi = bi->next)
2692 { 2702 {
2693 if ( (bi->salen == addrlen) && 2703 if ( (bi->salen == addrlen) &&
2694 (0 == memcmp (addr, 2704 (0 == memcmp (addr,
2695 bi->sa, 2705 bi->sa,
2696 addrlen)) ) 2706 addrlen)) )
2697 { 2707 {
2698 bi->found = GNUNET_YES; 2708 bi->found = GNUNET_YES;
2699 return GNUNET_OK; 2709 return GNUNET_OK;
@@ -2709,10 +2719,10 @@ iface_proc (void *cls,
2709 2719
2710 bi = GNUNET_new (struct BroadcastInterface); 2720 bi = GNUNET_new (struct BroadcastInterface);
2711 bi->sa = GNUNET_memdup (addr, 2721 bi->sa = GNUNET_memdup (addr,
2712 addrlen); 2722 addrlen);
2713 if (NULL != broadcast_addr) 2723 if (NULL != broadcast_addr)
2714 bi->ba = GNUNET_memdup (broadcast_addr, 2724 bi->ba = GNUNET_memdup (broadcast_addr,
2715 addrlen); 2725 addrlen);
2716 bi->salen = addrlen; 2726 bi->salen = addrlen;
2717 bi->found = GNUNET_YES; 2727 bi->found = GNUNET_YES;
2718 bi->bcm.sender = my_identity; 2728 bi->bcm.sender = my_identity;
@@ -2720,17 +2730,17 @@ iface_proc (void *cls,
2720 ubs.purpose.size = htonl (sizeof (ubs)); 2730 ubs.purpose.size = htonl (sizeof (ubs));
2721 ubs.sender = my_identity; 2731 ubs.sender = my_identity;
2722 GNUNET_CRYPTO_hash (addr, 2732 GNUNET_CRYPTO_hash (addr,
2723 addrlen, 2733 addrlen,
2724 &ubs.h_address); 2734 &ubs.h_address);
2725 GNUNET_assert (GNUNET_OK == 2735 GNUNET_assert (GNUNET_OK ==
2726 GNUNET_CRYPTO_eddsa_sign (my_private_key, 2736 GNUNET_CRYPTO_eddsa_sign (my_private_key,
2727 &ubs.purpose, 2737 &ubs.purpose,
2728 &bi->bcm.sender_sig)); 2738 &bi->bcm.sender_sig));
2729 bi->broadcast_task = GNUNET_SCHEDULER_add_now (&ifc_broadcast, 2739 bi->broadcast_task = GNUNET_SCHEDULER_add_now (&ifc_broadcast,
2730 bi); 2740 bi);
2731 GNUNET_CONTAINER_DLL_insert (bi_head, 2741 GNUNET_CONTAINER_DLL_insert (bi_head,
2732 bi_tail, 2742 bi_tail,
2733 bi); 2743 bi);
2734 if ( (AF_INET6 == addr->sa_family) && 2744 if ( (AF_INET6 == addr->sa_family) &&
2735 (NULL != broadcast_addr) ) 2745 (NULL != broadcast_addr) )
2736 { 2746 {
@@ -2740,7 +2750,7 @@ iface_proc (void *cls,
2740 2750
2741 GNUNET_assert (1 == 2751 GNUNET_assert (1 ==
2742 inet_pton (AF_INET6, 2752 inet_pton (AF_INET6,
2743 "FF05::13B", 2753 "FF05::13B",
2744 &bi->mcreq.ipv6mr_multiaddr)); 2754 &bi->mcreq.ipv6mr_multiaddr));
2745 2755
2746 /* http://tools.ietf.org/html/rfc2553#section-5.2: 2756 /* http://tools.ietf.org/html/rfc2553#section-5.2:
@@ -2760,10 +2770,10 @@ iface_proc (void *cls,
2760 if (GNUNET_OK != 2770 if (GNUNET_OK !=
2761 GNUNET_NETWORK_socket_setsockopt 2771 GNUNET_NETWORK_socket_setsockopt
2762 (udp_sock, 2772 (udp_sock,
2763 IPPROTO_IPV6, 2773 IPPROTO_IPV6,
2764 IPV6_JOIN_GROUP, 2774 IPV6_JOIN_GROUP,
2765 &bi->mcreq, 2775 &bi->mcreq,
2766 sizeof (bi->mcreq))) 2776 sizeof (bi->mcreq)))
2767 { 2777 {
2768 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 2778 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
2769 "setsockopt"); 2779 "setsockopt");
@@ -2789,7 +2799,7 @@ do_broadcast (void *cls)
2789 bi = bi->next) 2799 bi = bi->next)
2790 bi->found = GNUNET_NO; 2800 bi->found = GNUNET_NO;
2791 GNUNET_OS_network_interfaces_list (&iface_proc, 2801 GNUNET_OS_network_interfaces_list (&iface_proc,
2792 NULL); 2802 NULL);
2793 for (struct BroadcastInterface *bi = bi_head; 2803 for (struct BroadcastInterface *bi = bi_head;
2794 NULL != bi; 2804 NULL != bi;
2795 bi = bin) 2805 bi = bin)
@@ -2800,8 +2810,8 @@ do_broadcast (void *cls)
2800 } 2810 }
2801 broadcast_task 2811 broadcast_task
2802 = GNUNET_SCHEDULER_add_delayed (INTERFACE_SCAN_FREQUENCY, 2812 = GNUNET_SCHEDULER_add_delayed (INTERFACE_SCAN_FREQUENCY,
2803 &do_broadcast, 2813 &do_broadcast,
2804 NULL); 2814 NULL);
2805} 2815}
2806 2816
2807 2817
@@ -2829,10 +2839,10 @@ run (void *cls,
2829 cfg = c; 2839 cfg = c;
2830 if (GNUNET_OK != 2840 if (GNUNET_OK !=
2831 GNUNET_CONFIGURATION_get_value_filename (cfg, 2841 GNUNET_CONFIGURATION_get_value_filename (cfg,
2832 COMMUNICATOR_CONFIG_SECTION, 2842 COMMUNICATOR_CONFIG_SECTION,
2833 "BINDTO", 2843 "BINDTO",
2834 &bindto)) 2844 &bindto))
2835 { 2845 {
2836 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 2846 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
2837 COMMUNICATOR_CONFIG_SECTION, 2847 COMMUNICATOR_CONFIG_SECTION,
2838 "BINDTO"); 2848 "BINDTO");
@@ -2996,7 +3006,7 @@ main (int argc,
2996 3006
2997 if (GNUNET_OK != 3007 if (GNUNET_OK !=
2998 GNUNET_STRINGS_get_utf8_args (argc, argv, 3008 GNUNET_STRINGS_get_utf8_args (argc, argv,
2999 &argc, &argv)) 3009 &argc, &argv))
3000 return 2; 3010 return 2;
3001 3011
3002 ret = 3012 ret =