aboutsummaryrefslogtreecommitdiff
path: root/src/core/gnunet-service-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/gnunet-service-core.c')
-rw-r--r--src/core/gnunet-service-core.c808
1 files changed, 362 insertions, 446 deletions
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c
index 95e182448..e97e9fe46 100644
--- a/src/core/gnunet-service-core.c
+++ b/src/core/gnunet-service-core.c
@@ -821,21 +821,17 @@ static unsigned long long bandwidth_target_out_bps;
821 */ 821 */
822static void 822static void
823derive_auth_key (struct GNUNET_CRYPTO_AuthKey *akey, 823derive_auth_key (struct GNUNET_CRYPTO_AuthKey *akey,
824 const struct GNUNET_CRYPTO_AesSessionKey *skey, 824 const struct GNUNET_CRYPTO_AesSessionKey *skey, uint32_t seed,
825 uint32_t seed, struct GNUNET_TIME_Absolute creation_time) 825 struct GNUNET_TIME_Absolute creation_time)
826{ 826{
827 static const char ctx[] = "authentication key"; 827 static const char ctx[] = "authentication key";
828 struct GNUNET_TIME_AbsoluteNBO ctbe; 828 struct GNUNET_TIME_AbsoluteNBO ctbe;
829 829
830 830
831 ctbe = GNUNET_TIME_absolute_hton (creation_time); 831 ctbe = GNUNET_TIME_absolute_hton (creation_time);
832 GNUNET_CRYPTO_hmac_derive_key (akey, 832 GNUNET_CRYPTO_hmac_derive_key (akey, skey, &seed, sizeof (seed), &skey->key,
833 skey, 833 sizeof (skey->key), &ctbe, sizeof (ctbe), ctx,
834 &seed, 834 sizeof (ctx), NULL);
835 sizeof (seed),
836 &skey->key,
837 sizeof (skey->key),
838 &ctbe, sizeof (ctbe), ctx, sizeof (ctx), NULL);
839} 835}
840 836
841 837
@@ -849,13 +845,10 @@ derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv,
849{ 845{
850 static const char ctx[] = "initialization vector"; 846 static const char ctx[] = "initialization vector";
851 847
852 GNUNET_CRYPTO_aes_derive_iv (iv, 848 GNUNET_CRYPTO_aes_derive_iv (iv, skey, &seed, sizeof (seed),
853 skey,
854 &seed,
855 sizeof (seed),
856 &identity->hashPubKey.bits, 849 &identity->hashPubKey.bits,
857 sizeof (identity->hashPubKey.bits), 850 sizeof (identity->hashPubKey.bits), ctx,
858 ctx, sizeof (ctx), NULL); 851 sizeof (ctx), NULL);
859} 852}
860 853
861/** 854/**
@@ -868,13 +861,9 @@ derive_pong_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv,
868{ 861{
869 static const char ctx[] = "pong initialization vector"; 862 static const char ctx[] = "pong initialization vector";
870 863
871 GNUNET_CRYPTO_aes_derive_iv (iv, 864 GNUNET_CRYPTO_aes_derive_iv (iv, skey, &seed, sizeof (seed),
872 skey,
873 &seed,
874 sizeof (seed),
875 &identity->hashPubKey.bits, 865 &identity->hashPubKey.bits,
876 sizeof (identity->hashPubKey.bits), 866 sizeof (identity->hashPubKey.bits), &challenge,
877 &challenge,
878 sizeof (challenge), ctx, sizeof (ctx), NULL); 867 sizeof (challenge), ctx, sizeof (ctx), NULL);
879} 868}
880 869
@@ -926,8 +915,8 @@ update_preference_sum (unsigned long long inc)
926 return; /* done! */ 915 return; /* done! */
927 /* overflow! compensate by cutting all values in half! */ 916 /* overflow! compensate by cutting all values in half! */
928 preference_sum = 0; 917 preference_sum = 0;
929 GNUNET_CONTAINER_multihashmap_iterate (neighbours, 918 GNUNET_CONTAINER_multihashmap_iterate (neighbours, &update_preference,
930 &update_preference, &preference_sum); 919 &preference_sum);
931 GNUNET_STATISTICS_set (stats, gettext_noop ("# total peer preference"), 920 GNUNET_STATISTICS_set (stats, gettext_noop ("# total peer preference"),
932 preference_sum, GNUNET_NO); 921 preference_sum, GNUNET_NO);
933} 922}
@@ -956,8 +945,8 @@ find_neighbour (const struct GNUNET_PeerIdentity *peer)
956 * client's queue is getting too large? 945 * client's queue is getting too large?
957 */ 946 */
958static void 947static void
959send_to_client (struct Client *client, 948send_to_client (struct Client *client, const struct GNUNET_MessageHeader *msg,
960 const struct GNUNET_MessageHeader *msg, int can_drop) 949 int can_drop)
961{ 950{
962#if DEBUG_CORE_CLIENT 951#if DEBUG_CORE_CLIENT
963 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 952 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -965,8 +954,7 @@ send_to_client (struct Client *client,
965 (unsigned int) ntohs (msg->size), 954 (unsigned int) ntohs (msg->size),
966 (unsigned int) ntohs (msg->type)); 955 (unsigned int) ntohs (msg->type));
967#endif 956#endif
968 GNUNET_SERVER_notification_context_unicast (notifier, 957 GNUNET_SERVER_notification_context_unicast (notifier, client->client_handle,
969 client->client_handle,
970 msg, can_drop); 958 msg, can_drop);
971} 959}
972 960
@@ -980,8 +968,8 @@ send_to_client (struct Client *client,
980 * @param options mask to use 968 * @param options mask to use
981 */ 969 */
982static void 970static void
983send_to_all_clients (const struct GNUNET_MessageHeader *msg, 971send_to_all_clients (const struct GNUNET_MessageHeader *msg, int can_drop,
984 int can_drop, int options) 972 int options)
985{ 973{
986 struct Client *c; 974 struct Client *c;
987 975
@@ -1019,17 +1007,19 @@ handle_peer_status_change (struct Neighbour *n)
1019 if ((!n->is_connected) || (n->status != PEER_STATE_KEY_CONFIRMED)) 1007 if ((!n->is_connected) || (n->status != PEER_STATE_KEY_CONFIRMED))
1020 return; 1008 return;
1021#if DEBUG_CORE > 1 1009#if DEBUG_CORE > 1
1022 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1010 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' changed status\n",
1023 "Peer `%4s' changed status\n", GNUNET_i2s (&n->peer)); 1011 GNUNET_i2s (&n->peer));
1024#endif 1012#endif
1025 size = sizeof (struct PeerStatusNotifyMessage) + 1013 size =
1014 sizeof (struct PeerStatusNotifyMessage) +
1026 n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information); 1015 n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
1027 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 1016 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1028 { 1017 {
1029 GNUNET_break (0); 1018 GNUNET_break (0);
1030 /* recovery strategy: throw away performance data */ 1019 /* recovery strategy: throw away performance data */
1031 GNUNET_array_grow (n->ats, n->ats_count, 0); 1020 GNUNET_array_grow (n->ats, n->ats_count, 0);
1032 size = sizeof (struct PeerStatusNotifyMessage) + 1021 size =
1022 sizeof (struct PeerStatusNotifyMessage) +
1033 n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information); 1023 n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
1034 } 1024 }
1035 psnm = (struct PeerStatusNotifyMessage *) buf; 1025 psnm = (struct PeerStatusNotifyMessage *) buf;
@@ -1041,16 +1031,14 @@ handle_peer_status_change (struct Neighbour *n)
1041 psnm->peer = n->peer; 1031 psnm->peer = n->peer;
1042 psnm->ats_count = htonl (n->ats_count); 1032 psnm->ats_count = htonl (n->ats_count);
1043 ats = &psnm->ats; 1033 ats = &psnm->ats;
1044 memcpy (ats, 1034 memcpy (ats, n->ats,
1045 n->ats,
1046 n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); 1035 n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
1047 ats[n->ats_count].type = htonl (0); 1036 ats[n->ats_count].type = htonl (0);
1048 ats[n->ats_count].value = htonl (0); 1037 ats[n->ats_count].value = htonl (0);
1049 send_to_all_clients (&psnm->header, 1038 send_to_all_clients (&psnm->header, GNUNET_YES,
1050 GNUNET_YES, GNUNET_CORE_OPTION_SEND_STATUS_CHANGE); 1039 GNUNET_CORE_OPTION_SEND_STATUS_CHANGE);
1051 GNUNET_STATISTICS_update (stats, 1040 GNUNET_STATISTICS_update (stats, gettext_noop ("# peer status changes"), 1,
1052 gettext_noop ("# peer status changes"), 1041 GNUNET_NO);
1053 1, GNUNET_NO);
1054} 1042}
1055 1043
1056 1044
@@ -1149,10 +1137,9 @@ compute_type_map_message ()
1149 hdr = GNUNET_malloc (dlen + sizeof (struct GNUNET_MessageHeader)); 1137 hdr = GNUNET_malloc (dlen + sizeof (struct GNUNET_MessageHeader));
1150 hdr->size = htons ((uint16_t) dlen + sizeof (struct GNUNET_MessageHeader)); 1138 hdr->size = htons ((uint16_t) dlen + sizeof (struct GNUNET_MessageHeader));
1151 tmp = (char *) &hdr[1]; 1139 tmp = (char *) &hdr[1];
1152 if ((Z_OK != compress2 ((Bytef *) tmp, 1140 if ((Z_OK !=
1153 &dlen, (const Bytef *) my_type_map, 1141 compress2 ((Bytef *) tmp, &dlen, (const Bytef *) my_type_map,
1154 sizeof (my_type_map), 9)) || 1142 sizeof (my_type_map), 9)) || (dlen >= sizeof (my_type_map)))
1155 (dlen >= sizeof (my_type_map)))
1156 { 1143 {
1157 dlen = sizeof (my_type_map); 1144 dlen = sizeof (my_type_map);
1158 memcpy (tmp, my_type_map, sizeof (my_type_map)); 1145 memcpy (tmp, my_type_map, sizeof (my_type_map));
@@ -1220,8 +1207,7 @@ broadcast_my_type_map ()
1220 * Handle CORE_SEND_REQUEST message. 1207 * Handle CORE_SEND_REQUEST message.
1221 */ 1208 */
1222static void 1209static void
1223handle_client_send_request (void *cls, 1210handle_client_send_request (void *cls, struct GNUNET_SERVER_Client *client,
1224 struct GNUNET_SERVER_Client *client,
1225 const struct GNUNET_MessageHeader *message) 1211 const struct GNUNET_MessageHeader *message)
1226{ 1212{
1227 const struct SendMessageRequest *req; 1213 const struct SendMessageRequest *req;
@@ -1230,13 +1216,12 @@ handle_client_send_request (void *cls,
1230 struct ClientActiveRequest *car; 1216 struct ClientActiveRequest *car;
1231 1217
1232 req = (const struct SendMessageRequest *) message; 1218 req = (const struct SendMessageRequest *) message;
1233 if (0 == memcmp (&req->peer, 1219 if (0 ==
1234 &my_identity, sizeof (struct GNUNET_PeerIdentity))) 1220 memcmp (&req->peer, &my_identity, sizeof (struct GNUNET_PeerIdentity)))
1235 n = &self; 1221 n = &self;
1236 else 1222 else
1237 n = find_neighbour (&req->peer); 1223 n = find_neighbour (&req->peer);
1238 if ((n == NULL) || 1224 if ((n == NULL) || (GNUNET_YES != n->is_connected) ||
1239 (GNUNET_YES != n->is_connected) ||
1240 (n->status != PEER_STATE_KEY_CONFIRMED)) 1225 (n->status != PEER_STATE_KEY_CONFIRMED))
1241 { 1226 {
1242 /* neighbour must have disconnected since request was issued, 1227 /* neighbour must have disconnected since request was issued,
@@ -1297,8 +1282,8 @@ handle_client_send_request (void *cls,
1297 * Notify client about an existing connection to one of our neighbours. 1282 * Notify client about an existing connection to one of our neighbours.
1298 */ 1283 */
1299static int 1284static int
1300notify_client_about_neighbour (void *cls, 1285notify_client_about_neighbour (void *cls, const GNUNET_HashCode * key,
1301 const GNUNET_HashCode * key, void *value) 1286 void *value)
1302{ 1287{
1303 struct Client *c = cls; 1288 struct Client *c = cls;
1304 struct Neighbour *n = value; 1289 struct Neighbour *n = value;
@@ -1307,14 +1292,16 @@ notify_client_about_neighbour (void *cls,
1307 struct GNUNET_TRANSPORT_ATS_Information *ats; 1292 struct GNUNET_TRANSPORT_ATS_Information *ats;
1308 struct ConnectNotifyMessage *cnm; 1293 struct ConnectNotifyMessage *cnm;
1309 1294
1310 size = sizeof (struct ConnectNotifyMessage) + 1295 size =
1296 sizeof (struct ConnectNotifyMessage) +
1311 (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); 1297 (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
1312 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 1298 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1313 { 1299 {
1314 GNUNET_break (0); 1300 GNUNET_break (0);
1315 /* recovery strategy: throw away performance data */ 1301 /* recovery strategy: throw away performance data */
1316 GNUNET_array_grow (n->ats, n->ats_count, 0); 1302 GNUNET_array_grow (n->ats, n->ats_count, 0);
1317 size = sizeof (struct ConnectNotifyMessage) + 1303 size =
1304 sizeof (struct ConnectNotifyMessage) +
1318 (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); 1305 (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
1319 } 1306 }
1320 cnm = (struct ConnectNotifyMessage *) buf; 1307 cnm = (struct ConnectNotifyMessage *) buf;
@@ -1322,16 +1309,15 @@ notify_client_about_neighbour (void *cls,
1322 cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT); 1309 cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT);
1323 cnm->ats_count = htonl (n->ats_count); 1310 cnm->ats_count = htonl (n->ats_count);
1324 ats = &cnm->ats; 1311 ats = &cnm->ats;
1325 memcpy (ats, 1312 memcpy (ats, n->ats,
1326 n->ats,
1327 sizeof (struct GNUNET_TRANSPORT_ATS_Information) * n->ats_count); 1313 sizeof (struct GNUNET_TRANSPORT_ATS_Information) * n->ats_count);
1328 ats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 1314 ats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
1329 ats[n->ats_count].value = htonl (0); 1315 ats[n->ats_count].value = htonl (0);
1330 if (n->status == PEER_STATE_KEY_CONFIRMED) 1316 if (n->status == PEER_STATE_KEY_CONFIRMED)
1331 { 1317 {
1332#if DEBUG_CORE_CLIENT 1318#if DEBUG_CORE_CLIENT
1333 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1319 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message to client.\n",
1334 "Sending `%s' message to client.\n", "NOTIFY_CONNECT"); 1320 "NOTIFY_CONNECT");
1335#endif 1321#endif
1336 cnm->peer = n->peer; 1322 cnm->peer = n->peer;
1337 send_to_client (c, &cnm->header, GNUNET_NO); 1323 send_to_client (c, &cnm->header, GNUNET_NO);
@@ -1345,8 +1331,7 @@ notify_client_about_neighbour (void *cls,
1345 * Handle CORE_INIT request. 1331 * Handle CORE_INIT request.
1346 */ 1332 */
1347static void 1333static void
1348handle_client_init (void *cls, 1334handle_client_init (void *cls, struct GNUNET_SERVER_Client *client,
1349 struct GNUNET_SERVER_Client *client,
1350 const struct GNUNET_MessageHeader *message) 1335 const struct GNUNET_MessageHeader *message)
1351{ 1336{
1352 const struct InitMessage *im; 1337 const struct InitMessage *im;
@@ -1401,19 +1386,18 @@ handle_client_init (void *cls,
1401 c->options = ntohl (im->options); 1386 c->options = ntohl (im->options);
1402#if DEBUG_CORE_CLIENT 1387#if DEBUG_CORE_CLIENT
1403 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1388 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1404 "Client %p is interested in %u message types\n", 1389 "Client %p is interested in %u message types\n", c,
1405 c, (unsigned int) c->tcnt); 1390 (unsigned int) c->tcnt);
1406#endif 1391#endif
1407 /* send init reply message */ 1392 /* send init reply message */
1408 irm.header.size = htons (sizeof (struct InitReplyMessage)); 1393 irm.header.size = htons (sizeof (struct InitReplyMessage));
1409 irm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY); 1394 irm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY);
1410 irm.reserved = htonl (0); 1395 irm.reserved = htonl (0);
1411 memcpy (&irm.publicKey, 1396 memcpy (&irm.publicKey, &my_public_key,
1412 &my_public_key,
1413 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 1397 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
1414#if DEBUG_CORE_CLIENT 1398#if DEBUG_CORE_CLIENT
1415 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message to client.\n",
1416 "Sending `%s' message to client.\n", "INIT_REPLY"); 1400 "INIT_REPLY");
1417#endif 1401#endif
1418 send_to_client (c, &irm.header, GNUNET_NO); 1402 send_to_client (c, &irm.header, GNUNET_NO);
1419 if (0 != (c->options & GNUNET_CORE_OPTION_SEND_CONNECT)) 1403 if (0 != (c->options & GNUNET_CORE_OPTION_SEND_CONNECT))
@@ -1435,8 +1419,8 @@ handle_client_init (void *cls,
1435 * @return GNUNET_YES (continue iteration) 1419 * @return GNUNET_YES (continue iteration)
1436 */ 1420 */
1437static int 1421static int
1438destroy_active_client_request (void *cls, 1422destroy_active_client_request (void *cls, const GNUNET_HashCode * key,
1439 const GNUNET_HashCode * key, void *value) 1423 void *value)
1440{ 1424{
1441 struct ClientActiveRequest *car = value; 1425 struct ClientActiveRequest *car = value;
1442 struct Neighbour *n; 1426 struct Neighbour *n;
@@ -1532,14 +1516,16 @@ queue_connect_message (void *cls, const GNUNET_HashCode * key, void *value)
1532 cnm = (struct ConnectNotifyMessage *) buf; 1516 cnm = (struct ConnectNotifyMessage *) buf;
1533 if (n->status != PEER_STATE_KEY_CONFIRMED) 1517 if (n->status != PEER_STATE_KEY_CONFIRMED)
1534 return GNUNET_OK; 1518 return GNUNET_OK;
1535 size = sizeof (struct ConnectNotifyMessage) + 1519 size =
1520 sizeof (struct ConnectNotifyMessage) +
1536 (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); 1521 (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
1537 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 1522 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1538 { 1523 {
1539 GNUNET_break (0); 1524 GNUNET_break (0);
1540 /* recovery strategy: throw away performance data */ 1525 /* recovery strategy: throw away performance data */
1541 GNUNET_array_grow (n->ats, n->ats_count, 0); 1526 GNUNET_array_grow (n->ats, n->ats_count, 0);
1542 size = sizeof (struct PeerStatusNotifyMessage) + 1527 size =
1528 sizeof (struct PeerStatusNotifyMessage) +
1543 n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information); 1529 n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
1544 } 1530 }
1545 cnm = (struct ConnectNotifyMessage *) buf; 1531 cnm = (struct ConnectNotifyMessage *) buf;
@@ -1547,14 +1533,13 @@ queue_connect_message (void *cls, const GNUNET_HashCode * key, void *value)
1547 cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT); 1533 cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT);
1548 cnm->ats_count = htonl (n->ats_count); 1534 cnm->ats_count = htonl (n->ats_count);
1549 ats = &cnm->ats; 1535 ats = &cnm->ats;
1550 memcpy (ats, 1536 memcpy (ats, n->ats,
1551 n->ats,
1552 n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); 1537 n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
1553 ats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 1538 ats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
1554 ats[n->ats_count].value = htonl (0); 1539 ats[n->ats_count].value = htonl (0);
1555#if DEBUG_CORE_CLIENT 1540#if DEBUG_CORE_CLIENT
1556 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1541 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message to client.\n",
1557 "Sending `%s' message to client.\n", "NOTIFY_CONNECT"); 1542 "NOTIFY_CONNECT");
1558#endif 1543#endif
1559 cnm->peer = n->peer; 1544 cnm->peer = n->peer;
1560 GNUNET_SERVER_transmit_context_append_message (tc, &cnm->header); 1545 GNUNET_SERVER_transmit_context_append_message (tc, &cnm->header);
@@ -1570,8 +1555,7 @@ queue_connect_message (void *cls, const GNUNET_HashCode * key, void *value)
1570 * @param message iteration request message 1555 * @param message iteration request message
1571 */ 1556 */
1572static void 1557static void
1573handle_client_iterate_peers (void *cls, 1558handle_client_iterate_peers (void *cls, struct GNUNET_SERVER_Client *client,
1574 struct GNUNET_SERVER_Client *client,
1575 const struct GNUNET_MessageHeader *message) 1559 const struct GNUNET_MessageHeader *message)
1576{ 1560{
1577 struct GNUNET_MessageHeader done_msg; 1561 struct GNUNET_MessageHeader done_msg;
@@ -1603,8 +1587,7 @@ handle_client_iterate_peers (void *cls,
1603 * @param message iteration request message 1587 * @param message iteration request message
1604 */ 1588 */
1605static void 1589static void
1606handle_client_have_peer (void *cls, 1590handle_client_have_peer (void *cls, struct GNUNET_SERVER_Client *client,
1607 struct GNUNET_SERVER_Client *client,
1608 const struct GNUNET_MessageHeader *message) 1591 const struct GNUNET_MessageHeader *message)
1609{ 1592{
1610 struct GNUNET_MessageHeader done_msg; 1593 struct GNUNET_MessageHeader done_msg;
@@ -1613,8 +1596,7 @@ handle_client_have_peer (void *cls,
1613 1596
1614 tc = GNUNET_SERVER_transmit_context_create (client); 1597 tc = GNUNET_SERVER_transmit_context_create (client);
1615 peer = (struct GNUNET_PeerIdentity *) &message[1]; 1598 peer = (struct GNUNET_PeerIdentity *) &message[1];
1616 GNUNET_CONTAINER_multihashmap_get_multiple (neighbours, 1599 GNUNET_CONTAINER_multihashmap_get_multiple (neighbours, &peer->hashPubKey,
1617 &peer->hashPubKey,
1618 &queue_connect_message, tc); 1600 &queue_connect_message, tc);
1619 done_msg.size = htons (sizeof (struct GNUNET_MessageHeader)); 1601 done_msg.size = htons (sizeof (struct GNUNET_MessageHeader));
1620 done_msg.type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END); 1602 done_msg.type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END);
@@ -1631,8 +1613,7 @@ handle_client_have_peer (void *cls,
1631 * @param message iteration request message 1613 * @param message iteration request message
1632 */ 1614 */
1633static void 1615static void
1634handle_client_request_info (void *cls, 1616handle_client_request_info (void *cls, struct GNUNET_SERVER_Client *client,
1635 struct GNUNET_SERVER_Client *client,
1636 const struct GNUNET_MessageHeader *message) 1617 const struct GNUNET_MessageHeader *message)
1637{ 1618{
1638 const struct RequestInfoMessage *rcm; 1619 const struct RequestInfoMessage *rcm;
@@ -1646,8 +1627,8 @@ handle_client_request_info (void *cls,
1646 1627
1647 rdelay = GNUNET_TIME_relative_get_zero (); 1628 rdelay = GNUNET_TIME_relative_get_zero ();
1648#if DEBUG_CORE_CLIENT 1629#if DEBUG_CORE_CLIENT
1649 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1630 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core service receives `%s' request.\n",
1650 "Core service receives `%s' request.\n", "REQUEST_INFO"); 1631 "REQUEST_INFO");
1651#endif 1632#endif
1652 pos = clients; 1633 pos = clients;
1653 while (pos != NULL) 1634 while (pos != NULL)
@@ -1676,8 +1657,9 @@ handle_client_request_info (void *cls,
1676 GNUNET_BANDWIDTH_value_min (n->bw_out_internal_limit, 1657 GNUNET_BANDWIDTH_value_min (n->bw_out_internal_limit,
1677 n->bw_out_external_limit).value__) 1658 n->bw_out_external_limit).value__)
1678 { 1659 {
1679 n->bw_out = GNUNET_BANDWIDTH_value_min (n->bw_out_internal_limit, 1660 n->bw_out =
1680 n->bw_out_external_limit); 1661 GNUNET_BANDWIDTH_value_min (n->bw_out_internal_limit,
1662 n->bw_out_external_limit);
1681 GNUNET_BANDWIDTH_tracker_update_quota (&n->available_recv_window, 1663 GNUNET_BANDWIDTH_tracker_update_quota (&n->available_recv_window,
1682 n->bw_out); 1664 n->bw_out);
1683 GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out); 1665 GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out);
@@ -1690,8 +1672,9 @@ handle_client_request_info (void *cls,
1690 } 1672 }
1691 else if (want_reserv > 0) 1673 else if (want_reserv > 0)
1692 { 1674 {
1693 rdelay = GNUNET_BANDWIDTH_tracker_get_delay (&n->available_recv_window, 1675 rdelay =
1694 want_reserv); 1676 GNUNET_BANDWIDTH_tracker_get_delay (&n->available_recv_window,
1677 want_reserv);
1695 if (rdelay.rel_value == 0) 1678 if (rdelay.rel_value == 0)
1696 got_reserv = want_reserv; 1679 got_reserv = want_reserv;
1697 else 1680 else
@@ -1711,9 +1694,8 @@ handle_client_request_info (void *cls,
1711#if DEBUG_CORE_QUOTA 1694#if DEBUG_CORE_QUOTA
1712 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1695 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1713 "Received reservation request for %d bytes for peer `%4s', reserved %d bytes, suggesting delay of %llu ms\n", 1696 "Received reservation request for %d bytes for peer `%4s', reserved %d bytes, suggesting delay of %llu ms\n",
1714 (int) want_reserv, 1697 (int) want_reserv, GNUNET_i2s (&rcm->peer), (int) got_reserv,
1715 GNUNET_i2s (&rcm->peer), 1698 (unsigned long long) rdelay.rel_value);
1716 (int) got_reserv, (unsigned long long) rdelay.rel_value);
1717#endif 1699#endif
1718 cim.reserved_amount = htonl (got_reserv); 1700 cim.reserved_amount = htonl (got_reserv);
1719 cim.reserve_delay = GNUNET_TIME_relative_hton (rdelay); 1701 cim.reserve_delay = GNUNET_TIME_relative_hton (rdelay);
@@ -1737,8 +1719,8 @@ handle_client_request_info (void *cls,
1737 cim.peer = rcm->peer; 1719 cim.peer = rcm->peer;
1738 cim.rim_id = rcm->rim_id; 1720 cim.rim_id = rcm->rim_id;
1739#if DEBUG_CORE_CLIENT 1721#if DEBUG_CORE_CLIENT
1740 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1722 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message to client.\n",
1741 "Sending `%s' message to client.\n", "CONFIGURATION_INFO"); 1723 "CONFIGURATION_INFO");
1742#endif 1724#endif
1743 send_to_client (pos, &cim.header, GNUNET_NO); 1725 send_to_client (pos, &cim.header, GNUNET_NO);
1744 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1726 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -1808,8 +1790,7 @@ free_neighbour (struct Neighbour *n)
1808 if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) 1790 if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK)
1809 GNUNET_SCHEDULER_cancel (n->keep_alive_task); 1791 GNUNET_SCHEDULER_cancel (n->keep_alive_task);
1810 if (n->status == PEER_STATE_KEY_CONFIRMED) 1792 if (n->status == PEER_STATE_KEY_CONFIRMED)
1811 GNUNET_STATISTICS_update (stats, 1793 GNUNET_STATISTICS_update (stats, gettext_noop ("# established sessions"),
1812 gettext_noop ("# established sessions"),
1813 -1, GNUNET_NO); 1794 -1, GNUNET_NO);
1814 GNUNET_array_grow (n->ats, n->ats_count, 0); 1795 GNUNET_array_grow (n->ats, n->ats_count, 0);
1815 GNUNET_free_non_null (n->public_key); 1796 GNUNET_free_non_null (n->public_key);
@@ -1851,18 +1832,17 @@ do_encrypt (struct Neighbour *n,
1851 return GNUNET_NO; 1832 return GNUNET_NO;
1852 } 1833 }
1853 GNUNET_assert (size == 1834 GNUNET_assert (size ==
1854 GNUNET_CRYPTO_aes_encrypt (in, 1835 GNUNET_CRYPTO_aes_encrypt (in, (uint16_t) size,
1855 (uint16_t) size,
1856 &n->encrypt_key, iv, out)); 1836 &n->encrypt_key, iv, out));
1857 GNUNET_STATISTICS_update (stats, gettext_noop ("# bytes encrypted"), size, 1837 GNUNET_STATISTICS_update (stats, gettext_noop ("# bytes encrypted"), size,
1858 GNUNET_NO); 1838 GNUNET_NO);
1859#if DEBUG_CORE > 2 1839#if DEBUG_CORE > 2
1860 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1840 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1861 "Encrypted %u bytes for `%4s' using key %u, IV %u\n", 1841 "Encrypted %u bytes for `%4s' using key %u, IV %u\n",
1862 (unsigned int) size, 1842 (unsigned int) size, GNUNET_i2s (&n->peer),
1863 GNUNET_i2s (&n->peer), 1843 (unsigned int) n->encrypt_key.crc32, GNUNET_CRYPTO_crc32_n (iv,
1864 (unsigned int) n->encrypt_key.crc32, 1844 sizeof
1865 GNUNET_CRYPTO_crc32_n (iv, sizeof (iv))); 1845 (iv)));
1866#endif 1846#endif
1867 return GNUNET_OK; 1847 return GNUNET_OK;
1868} 1848}
@@ -1902,38 +1882,36 @@ send_keep_alive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1902 me->deadline = GNUNET_TIME_relative_to_absolute (MAX_PING_DELAY); 1882 me->deadline = GNUNET_TIME_relative_to_absolute (MAX_PING_DELAY);
1903 me->priority = PING_PRIORITY; 1883 me->priority = PING_PRIORITY;
1904 me->size = sizeof (struct PingMessage); 1884 me->size = sizeof (struct PingMessage);
1905 GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, 1885 GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, n->encrypted_tail,
1906 n->encrypted_tail, n->encrypted_tail, me); 1886 n->encrypted_tail, me);
1907 pm = (struct PingMessage *) &me[1]; 1887 pm = (struct PingMessage *) &me[1];
1908 pm->header.size = htons (sizeof (struct PingMessage)); 1888 pm->header.size = htons (sizeof (struct PingMessage));
1909 pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING); 1889 pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING);
1910 pm->iv_seed = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 1890 pm->iv_seed =
1911 UINT32_MAX); 1891 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
1912 derive_iv (&iv, &n->encrypt_key, pm->iv_seed, &n->peer); 1892 derive_iv (&iv, &n->encrypt_key, pm->iv_seed, &n->peer);
1913 pp.challenge = n->ping_challenge; 1893 pp.challenge = n->ping_challenge;
1914 pp.target = n->peer; 1894 pp.target = n->peer;
1915#if DEBUG_HANDSHAKE 1895#if DEBUG_HANDSHAKE
1916 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1896 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1917 "Encrypting `%s' message with challenge %u for `%4s' using key %u, IV %u (salt %u).\n", 1897 "Encrypting `%s' message with challenge %u for `%4s' using key %u, IV %u (salt %u).\n",
1918 "PING", 1898 "PING", (unsigned int) n->ping_challenge, GNUNET_i2s (&n->peer),
1919 (unsigned int) n->ping_challenge, 1899 (unsigned int) n->encrypt_key.crc32, GNUNET_CRYPTO_crc32_n (&iv,
1920 GNUNET_i2s (&n->peer), 1900 sizeof
1921 (unsigned int) n->encrypt_key.crc32, 1901 (iv)),
1922 GNUNET_CRYPTO_crc32_n (&iv, sizeof (iv)), pm->iv_seed); 1902 pm->iv_seed);
1923#endif 1903#endif
1924 do_encrypt (n, 1904 do_encrypt (n, &iv, &pp.target, &pm->target,
1925 &iv, 1905 sizeof (struct PingMessage) - ((void *) &pm->target -
1926 &pp.target, 1906 (void *) pm));
1927 &pm->target,
1928 sizeof (struct PingMessage) -
1929 ((void *) &pm->target - (void *) pm));
1930 process_encrypted_neighbour_queue (n); 1907 process_encrypted_neighbour_queue (n);
1931 /* reschedule PING job */ 1908 /* reschedule PING job */
1932 left = GNUNET_TIME_absolute_get_remaining (get_neighbour_timeout (n)); 1909 left = GNUNET_TIME_absolute_get_remaining (get_neighbour_timeout (n));
1933 retry = GNUNET_TIME_relative_max (GNUNET_TIME_relative_divide (left, 2), 1910 retry =
1934 MIN_PING_FREQUENCY); 1911 GNUNET_TIME_relative_max (GNUNET_TIME_relative_divide (left, 2),
1935 n->keep_alive_task 1912 MIN_PING_FREQUENCY);
1936 = GNUNET_SCHEDULER_add_delayed (retry, &send_keep_alive, n); 1913 n->keep_alive_task =
1914 GNUNET_SCHEDULER_add_delayed (retry, &send_keep_alive, n);
1937 1915
1938} 1916}
1939 1917
@@ -1973,16 +1951,15 @@ consider_free_neighbour (struct Neighbour *n)
1973 { 1951 {
1974 if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK) 1952 if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK)
1975 GNUNET_SCHEDULER_cancel (n->dead_clean_task); 1953 GNUNET_SCHEDULER_cancel (n->dead_clean_task);
1976 n->dead_clean_task = GNUNET_SCHEDULER_add_delayed (left, 1954 n->dead_clean_task =
1977 &consider_free_task, n); 1955 GNUNET_SCHEDULER_add_delayed (left, &consider_free_task, n);
1978 return; 1956 return;
1979 } 1957 }
1980 /* actually free the neighbour... */ 1958 /* actually free the neighbour... */
1981 GNUNET_assert (GNUNET_YES == 1959 GNUNET_assert (GNUNET_YES ==
1982 GNUNET_CONTAINER_multihashmap_remove (neighbours, 1960 GNUNET_CONTAINER_multihashmap_remove (neighbours,
1983 &n->peer.hashPubKey, n)); 1961 &n->peer.hashPubKey, n));
1984 GNUNET_STATISTICS_set (stats, 1962 GNUNET_STATISTICS_set (stats, gettext_noop ("# neighbour entries allocated"),
1985 gettext_noop ("# neighbour entries allocated"),
1986 GNUNET_CONTAINER_multihashmap_size (neighbours), 1963 GNUNET_CONTAINER_multihashmap_size (neighbours),
1987 GNUNET_NO); 1964 GNUNET_NO);
1988 free_neighbour (n); 1965 free_neighbour (n);
@@ -2029,9 +2006,9 @@ notify_encrypted_transmit_ready (void *cls, size_t size, void *buf)
2029#if DEBUG_CORE 2006#if DEBUG_CORE
2030 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2007 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2031 "Copied message of type %u and size %u into transport buffer for `%4s'\n", 2008 "Copied message of type %u and size %u into transport buffer for `%4s'\n",
2032 (unsigned int) 2009 (unsigned int) ntohs (((struct GNUNET_MessageHeader *) &m[1])->
2033 ntohs (((struct GNUNET_MessageHeader *) &m[1])->type), 2010 type), (unsigned int) ret,
2034 (unsigned int) ret, GNUNET_i2s (&n->peer)); 2011 GNUNET_i2s (&n->peer));
2035#endif 2012#endif
2036 process_encrypted_neighbour_queue (n); 2013 process_encrypted_neighbour_queue (n);
2037 } 2014 }
@@ -2040,9 +2017,8 @@ notify_encrypted_transmit_ready (void *cls, size_t size, void *buf)
2040#if DEBUG_CORE 2017#if DEBUG_CORE
2041 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2018 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2042 "Transmission of message of type %u and size %u failed\n", 2019 "Transmission of message of type %u and size %u failed\n",
2043 (unsigned int) 2020 (unsigned int) ntohs (((struct GNUNET_MessageHeader *) &m[1])->
2044 ntohs (((struct GNUNET_MessageHeader *) &m[1])->type), 2021 type), (unsigned int) m->size);
2045 (unsigned int) m->size);
2046#endif 2022#endif
2047 } 2023 }
2048 GNUNET_free (m); 2024 GNUNET_free (m);
@@ -2094,14 +2070,13 @@ process_encrypted_neighbour_queue (struct Neighbour *n)
2094#if DEBUG_CORE > 1 2070#if DEBUG_CORE > 1
2095 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2071 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2096 "Asking transport for transmission of %u bytes to `%4s' in next %llu ms\n", 2072 "Asking transport for transmission of %u bytes to `%4s' in next %llu ms\n",
2097 (unsigned int) m->size, 2073 (unsigned int) m->size, GNUNET_i2s (&n->peer),
2098 GNUNET_i2s (&n->peer), 2074 (unsigned long long) GNUNET_TIME_absolute_get_remaining (m->
2099 (unsigned long long) 2075 deadline).
2100 GNUNET_TIME_absolute_get_remaining (m->deadline).rel_value); 2076 rel_value);
2101#endif 2077#endif
2102 n->th = 2078 n->th =
2103 GNUNET_TRANSPORT_notify_transmit_ready (transport, &n->peer, 2079 GNUNET_TRANSPORT_notify_transmit_ready (transport, &n->peer, m->size,
2104 m->size,
2105 m->priority, 2080 m->priority,
2106 GNUNET_TIME_absolute_get_remaining 2081 GNUNET_TIME_absolute_get_remaining
2107 (m->deadline), 2082 (m->deadline),
@@ -2153,16 +2128,15 @@ do_decrypt (struct Neighbour *n,
2153 GNUNET_break (0); 2128 GNUNET_break (0);
2154 return GNUNET_SYSERR; 2129 return GNUNET_SYSERR;
2155 } 2130 }
2156 GNUNET_STATISTICS_update (stats, 2131 GNUNET_STATISTICS_update (stats, gettext_noop ("# bytes decrypted"), size,
2157 gettext_noop ("# bytes decrypted"), 2132 GNUNET_NO);
2158 size, GNUNET_NO);
2159#if DEBUG_CORE > 1 2133#if DEBUG_CORE > 1
2160 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2134 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2161 "Decrypted %u bytes from `%4s' using key %u, IV %u\n", 2135 "Decrypted %u bytes from `%4s' using key %u, IV %u\n",
2162 (unsigned int) size, 2136 (unsigned int) size, GNUNET_i2s (&n->peer),
2163 GNUNET_i2s (&n->peer), 2137 (unsigned int) n->decrypt_key.crc32, GNUNET_CRYPTO_crc32_n (iv,
2164 (unsigned int) n->decrypt_key.crc32, 2138 sizeof
2165 GNUNET_CRYPTO_crc32_n (iv, sizeof (*iv))); 2139 (*iv)));
2166#endif 2140#endif
2167 return GNUNET_OK; 2141 return GNUNET_OK;
2168} 2142}
@@ -2186,8 +2160,8 @@ do_decrypt (struct Neighbour *n,
2186 * defer scheduling overall; in that case, retry_time is set. 2160 * defer scheduling overall; in that case, retry_time is set.
2187 */ 2161 */
2188static size_t 2162static size_t
2189select_messages (struct Neighbour *n, 2163select_messages (struct Neighbour *n, size_t size,
2190 size_t size, struct GNUNET_TIME_Relative *retry_time) 2164 struct GNUNET_TIME_Relative *retry_time)
2191{ 2165{
2192 struct MessageEntry *pos; 2166 struct MessageEntry *pos;
2193 struct MessageEntry *min; 2167 struct MessageEntry *min;
@@ -2253,8 +2227,8 @@ select_messages (struct Neighbour *n,
2253 { 2227 {
2254 // FIXME: HUH? Check! 2228 // FIXME: HUH? Check!
2255 t = pos->deadline; 2229 t = pos->deadline;
2256 avail += GNUNET_BANDWIDTH_value_get_available_until (n->bw_out, 2230 avail +=
2257 delta); 2231 GNUNET_BANDWIDTH_value_get_available_until (n->bw_out, delta);
2258 } 2232 }
2259 if (avail < pos->size) 2233 if (avail < pos->size)
2260 { 2234 {
@@ -2267,9 +2241,10 @@ select_messages (struct Neighbour *n,
2267 /* update slack, considering both its absolute deadline 2241 /* update slack, considering both its absolute deadline
2268 * and relative deadlines caused by other messages 2242 * and relative deadlines caused by other messages
2269 * with their respective load */ 2243 * with their respective load */
2270 slack = GNUNET_TIME_relative_min (slack, 2244 slack =
2271 GNUNET_BANDWIDTH_value_get_delay_for 2245 GNUNET_TIME_relative_min (slack,
2272 (n->bw_out, avail)); 2246 GNUNET_BANDWIDTH_value_get_delay_for
2247 (n->bw_out, avail));
2273 if (pos->deadline.abs_value <= now.abs_value) 2248 if (pos->deadline.abs_value <= now.abs_value)
2274 { 2249 {
2275 /* now or never */ 2250 /* now or never */
@@ -2278,9 +2253,10 @@ select_messages (struct Neighbour *n,
2278 else if (GNUNET_YES == pos->got_slack) 2253 else if (GNUNET_YES == pos->got_slack)
2279 { 2254 {
2280 /* should be soon now! */ 2255 /* should be soon now! */
2281 slack = GNUNET_TIME_relative_min (slack, 2256 slack =
2282 GNUNET_TIME_absolute_get_remaining 2257 GNUNET_TIME_relative_min (slack,
2283 (pos->slack_deadline)); 2258 GNUNET_TIME_absolute_get_remaining
2259 (pos->slack_deadline));
2284 } 2260 }
2285 else 2261 else
2286 { 2262 {
@@ -2289,9 +2265,10 @@ select_messages (struct Neighbour *n,
2289 GNUNET_TIME_absolute_get_difference 2265 GNUNET_TIME_absolute_get_difference
2290 (now, pos->deadline)); 2266 (now, pos->deadline));
2291 pos->got_slack = GNUNET_YES; 2267 pos->got_slack = GNUNET_YES;
2292 pos->slack_deadline = GNUNET_TIME_absolute_min (pos->deadline, 2268 pos->slack_deadline =
2293 GNUNET_TIME_relative_to_absolute 2269 GNUNET_TIME_absolute_min (pos->deadline,
2294 (GNUNET_CONSTANTS_MAX_CORK_DELAY)); 2270 GNUNET_TIME_relative_to_absolute
2271 (GNUNET_CONSTANTS_MAX_CORK_DELAY));
2295 } 2272 }
2296 } 2273 }
2297 } 2274 }
@@ -2336,8 +2313,8 @@ select_messages (struct Neighbour *n,
2336#if DEBUG_CORE 2313#if DEBUG_CORE
2337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2314 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2338 "Deferring transmission for %llums due to underfull message buffer size (%u/%u)\n", 2315 "Deferring transmission for %llums due to underfull message buffer size (%u/%u)\n",
2339 (unsigned long long) retry_time->rel_value, 2316 (unsigned long long) retry_time->rel_value, (unsigned int) off,
2340 (unsigned int) off, (unsigned int) size); 2317 (unsigned int) size);
2341#endif 2318#endif
2342 return 0; 2319 return 0;
2343 } 2320 }
@@ -2371,9 +2348,8 @@ select_messages (struct Neighbour *n,
2371#if DEBUG_CORE 2348#if DEBUG_CORE
2372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2349 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2373 "Selected %llu/%llu bytes of %u/%u plaintext messages for transmission to `%4s'.\n", 2350 "Selected %llu/%llu bytes of %u/%u plaintext messages for transmission to `%4s'.\n",
2374 (unsigned long long) off, (unsigned long long) tsize, 2351 (unsigned long long) off, (unsigned long long) tsize, queue_size,
2375 queue_size, (unsigned int) MAX_PEER_QUEUE_SIZE, 2352 (unsigned int) MAX_PEER_QUEUE_SIZE, GNUNET_i2s (&n->peer));
2376 GNUNET_i2s (&n->peer));
2377#endif 2353#endif
2378 return off; 2354 return off;
2379} 2355}
@@ -2392,9 +2368,7 @@ select_messages (struct Neighbour *n,
2392 * @return number of bytes written to buf (can be zero) 2368 * @return number of bytes written to buf (can be zero)
2393 */ 2369 */
2394static size_t 2370static size_t
2395batch_message (struct Neighbour *n, 2371batch_message (struct Neighbour *n, char *buf, size_t size,
2396 char *buf,
2397 size_t size,
2398 struct GNUNET_TIME_Absolute *deadline, 2372 struct GNUNET_TIME_Absolute *deadline,
2399 struct GNUNET_TIME_Relative *retry_time, unsigned int *priority) 2373 struct GNUNET_TIME_Relative *retry_time, unsigned int *priority)
2400{ 2374{
@@ -2439,10 +2413,11 @@ batch_message (struct Neighbour *n,
2439 GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct NotifyTrafficMessage)) 2413 GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct NotifyTrafficMessage))
2440 { 2414 {
2441 memcpy (&ntm[1], &pos[1], pos->size); 2415 memcpy (&ntm[1], &pos[1], pos->size);
2442 ntm->header.size = htons (sizeof (struct NotifyTrafficMessage) + 2416 ntm->header.size =
2443 sizeof (struct GNUNET_MessageHeader)); 2417 htons (sizeof (struct NotifyTrafficMessage) +
2444 send_to_all_clients (&ntm->header, 2418 sizeof (struct GNUNET_MessageHeader));
2445 GNUNET_YES, GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND); 2419 send_to_all_clients (&ntm->header, GNUNET_YES,
2420 GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND);
2446 } 2421 }
2447 else 2422 else
2448 { 2423 {
@@ -2450,10 +2425,10 @@ batch_message (struct Neighbour *n,
2450 * least the 'hdr' type */ 2425 * least the 'hdr' type */
2451 memcpy (&ntm[1], &pos[1], sizeof (struct GNUNET_MessageHeader)); 2426 memcpy (&ntm[1], &pos[1], sizeof (struct GNUNET_MessageHeader));
2452 } 2427 }
2453 ntm->header.size = htons (sizeof (struct NotifyTrafficMessage) + 2428 ntm->header.size =
2454 pos->size); 2429 htons (sizeof (struct NotifyTrafficMessage) + pos->size);
2455 send_to_all_clients (&ntm->header, 2430 send_to_all_clients (&ntm->header, GNUNET_YES,
2456 GNUNET_YES, GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND); 2431 GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND);
2457#if DEBUG_HANDSHAKE 2432#if DEBUG_HANDSHAKE
2458 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2433 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2459 "Encrypting %u bytes with message of type %u and size %u\n", 2434 "Encrypting %u bytes with message of type %u and size %u\n",
@@ -2461,8 +2436,8 @@ batch_message (struct Neighbour *n,
2461 (unsigned int) 2436 (unsigned int)
2462 ntohs (((const struct GNUNET_MessageHeader *) &pos[1])->type), 2437 ntohs (((const struct GNUNET_MessageHeader *) &pos[1])->type),
2463 (unsigned int) 2438 (unsigned int)
2464 ntohs (((const struct GNUNET_MessageHeader *) 2439 ntohs (((const struct GNUNET_MessageHeader *) &pos[1])->
2465 &pos[1])->size)); 2440 size));
2466#endif 2441#endif
2467 /* copy for encrypted transmission */ 2442 /* copy for encrypted transmission */
2468 memcpy (&buf[ret], &pos[1], pos->size); 2443 memcpy (&buf[ret], &pos[1], pos->size);
@@ -2473,8 +2448,9 @@ batch_message (struct Neighbour *n,
2473 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2448 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2474 "Adding plaintext message of size %u with deadline %llu ms to batch\n", 2449 "Adding plaintext message of size %u with deadline %llu ms to batch\n",
2475 (unsigned int) pos->size, 2450 (unsigned int) pos->size,
2476 (unsigned long long) 2451 (unsigned long long) GNUNET_TIME_absolute_get_remaining (pos->
2477 GNUNET_TIME_absolute_get_remaining (pos->deadline).rel_value); 2452 deadline).
2453 rel_value);
2478#endif 2454#endif
2479 deadline->abs_value = 2455 deadline->abs_value =
2480 GNUNET_MIN (deadline->abs_value, pos->deadline.abs_value); 2456 GNUNET_MIN (deadline->abs_value, pos->deadline.abs_value);
@@ -2584,8 +2560,8 @@ set_key_retry_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2584 struct Neighbour *n = cls; 2560 struct Neighbour *n = cls;
2585 2561
2586#if DEBUG_CORE 2562#if DEBUG_CORE
2587 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2563 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Retrying key transmission to `%4s'\n",
2588 "Retrying key transmission to `%4s'\n", GNUNET_i2s (&n->peer)); 2564 GNUNET_i2s (&n->peer));
2589#endif 2565#endif
2590 n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; 2566 n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK;
2591 n->set_key_retry_frequency = 2567 n->set_key_retry_frequency =
@@ -2632,9 +2608,9 @@ process_plaintext_neighbour_queue (struct Neighbour *n)
2632 return; 2608 return;
2633 case PEER_STATE_KEY_SENT: 2609 case PEER_STATE_KEY_SENT:
2634 if (n->retry_set_key_task == GNUNET_SCHEDULER_NO_TASK) 2610 if (n->retry_set_key_task == GNUNET_SCHEDULER_NO_TASK)
2635 n->retry_set_key_task 2611 n->retry_set_key_task =
2636 = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency, 2612 GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency,
2637 &set_key_retry_task, n); 2613 &set_key_retry_task, n);
2638#if DEBUG_CORE 2614#if DEBUG_CORE
2639 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2615 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2640 "Not yet connected to `%4s', deferring processing of plaintext messages.\n", 2616 "Not yet connected to `%4s', deferring processing of plaintext messages.\n",
@@ -2643,9 +2619,9 @@ process_plaintext_neighbour_queue (struct Neighbour *n)
2643 return; 2619 return;
2644 case PEER_STATE_KEY_RECEIVED: 2620 case PEER_STATE_KEY_RECEIVED:
2645 if (n->retry_set_key_task == GNUNET_SCHEDULER_NO_TASK) 2621 if (n->retry_set_key_task == GNUNET_SCHEDULER_NO_TASK)
2646 n->retry_set_key_task 2622 n->retry_set_key_task =
2647 = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency, 2623 GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency,
2648 &set_key_retry_task, n); 2624 &set_key_retry_task, n);
2649#if DEBUG_CORE 2625#if DEBUG_CORE
2650 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2626 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2651 "Not yet connected to `%4s', deferring processing of plaintext messages.\n", 2627 "Not yet connected to `%4s', deferring processing of plaintext messages.\n",
@@ -2680,10 +2656,10 @@ process_plaintext_neighbour_queue (struct Neighbour *n)
2680 deadline = GNUNET_TIME_UNIT_FOREVER_ABS; 2656 deadline = GNUNET_TIME_UNIT_FOREVER_ABS;
2681 priority = 0; 2657 priority = 0;
2682 used = sizeof (struct EncryptedMessage); 2658 used = sizeof (struct EncryptedMessage);
2683 used += batch_message (n, 2659 used +=
2684 &pbuf[used], 2660 batch_message (n, &pbuf[used],
2685 GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE, 2661 GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE, &deadline,
2686 &deadline, &retry_time, &priority); 2662 &retry_time, &priority);
2687 if (used == sizeof (struct EncryptedMessage)) 2663 if (used == sizeof (struct EncryptedMessage))
2688 { 2664 {
2689#if DEBUG_CORE > 1 2665#if DEBUG_CORE > 1
@@ -2693,8 +2669,8 @@ process_plaintext_neighbour_queue (struct Neighbour *n)
2693#endif 2669#endif
2694 /* no messages selected for sending, try again later... */ 2670 /* no messages selected for sending, try again later... */
2695 n->retry_plaintext_task = 2671 n->retry_plaintext_task =
2696 GNUNET_SCHEDULER_add_delayed (retry_time, 2672 GNUNET_SCHEDULER_add_delayed (retry_time, &retry_plaintext_processing,
2697 &retry_plaintext_processing, n); 2673 n);
2698 return; 2674 return;
2699 } 2675 }
2700#if DEBUG_CORE_QUOTA 2676#if DEBUG_CORE_QUOTA
@@ -2729,10 +2705,7 @@ process_plaintext_neighbour_queue (struct Neighbour *n)
2729 GNUNET_TIME_absolute_get_remaining (deadline).rel_value); 2705 GNUNET_TIME_absolute_get_remaining (deadline).rel_value);
2730#endif 2706#endif
2731 GNUNET_assert (GNUNET_OK == 2707 GNUNET_assert (GNUNET_OK ==
2732 do_encrypt (n, 2708 do_encrypt (n, &iv, &ph->sequence_number, &em->sequence_number,
2733 &iv,
2734 &ph->sequence_number,
2735 &em->sequence_number,
2736 used - ENCRYPTED_HEADER_SIZE)); 2709 used - ENCRYPTED_HEADER_SIZE));
2737 derive_auth_key (&auth_key, &n->encrypt_key, ph->iv_seed, 2710 derive_auth_key (&auth_key, &n->encrypt_key, ph->iv_seed,
2738 n->encrypt_key_created); 2711 n->encrypt_key_created);
@@ -2747,8 +2720,8 @@ process_plaintext_neighbour_queue (struct Neighbour *n)
2747 GNUNET_h2s (&em->hmac)); 2720 GNUNET_h2s (&em->hmac));
2748#endif 2721#endif
2749 /* append to transmission list */ 2722 /* append to transmission list */
2750 GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, 2723 GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, n->encrypted_tail,
2751 n->encrypted_tail, n->encrypted_tail, me); 2724 n->encrypted_tail, me);
2752 process_encrypted_neighbour_queue (n); 2725 process_encrypted_neighbour_queue (n);
2753 schedule_peer_messages (n); 2726 schedule_peer_messages (n);
2754} 2727}
@@ -2761,9 +2734,9 @@ process_plaintext_neighbour_queue (struct Neighbour *n)
2761 * @param cls neighbour for the quota update 2734 * @param cls neighbour for the quota update
2762 * @param tc context 2735 * @param tc context
2763 */ 2736 */
2764static void 2737static void neighbour_quota_update (void *cls,
2765neighbour_quota_update (void *cls, 2738 const struct GNUNET_SCHEDULER_TaskContext
2766 const struct GNUNET_SCHEDULER_TaskContext *tc); 2739 *tc);
2767 2740
2768 2741
2769/** 2742/**
@@ -2775,9 +2748,9 @@ static void
2775schedule_quota_update (struct Neighbour *n) 2748schedule_quota_update (struct Neighbour *n)
2776{ 2749{
2777 GNUNET_assert (n->quota_update_task == GNUNET_SCHEDULER_NO_TASK); 2750 GNUNET_assert (n->quota_update_task == GNUNET_SCHEDULER_NO_TASK);
2778 n->quota_update_task 2751 n->quota_update_task =
2779 = GNUNET_SCHEDULER_add_delayed (QUOTA_UPDATE_FREQUENCY, 2752 GNUNET_SCHEDULER_add_delayed (QUOTA_UPDATE_FREQUENCY,
2780 &neighbour_quota_update, n); 2753 &neighbour_quota_update, n);
2781} 2754}
2782 2755
2783 2756
@@ -2808,12 +2781,11 @@ create_neighbour (const struct GNUNET_PeerIdentity *pid)
2808 n->bw_out = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT; 2781 n->bw_out = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT;
2809 n->bw_out_internal_limit = GNUNET_BANDWIDTH_value_init (UINT32_MAX); 2782 n->bw_out_internal_limit = GNUNET_BANDWIDTH_value_init (UINT32_MAX);
2810 n->bw_out_external_limit = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT; 2783 n->bw_out_external_limit = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT;
2811 n->ping_challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 2784 n->ping_challenge =
2812 UINT32_MAX); 2785 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
2813 GNUNET_assert (GNUNET_OK == 2786 GNUNET_assert (GNUNET_OK ==
2814 GNUNET_CONTAINER_multihashmap_put (neighbours, 2787 GNUNET_CONTAINER_multihashmap_put (neighbours,
2815 &n->peer.hashPubKey, 2788 &n->peer.hashPubKey, n,
2816 n,
2817 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 2789 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
2818 GNUNET_STATISTICS_set (stats, gettext_noop ("# neighbour entries allocated"), 2790 GNUNET_STATISTICS_set (stats, gettext_noop ("# neighbour entries allocated"),
2819 GNUNET_CONTAINER_multihashmap_size (neighbours), 2791 GNUNET_CONTAINER_multihashmap_size (neighbours),
@@ -2832,8 +2804,7 @@ create_neighbour (const struct GNUNET_PeerIdentity *pid)
2832 * @param message the "struct SendMessage" 2804 * @param message the "struct SendMessage"
2833 */ 2805 */
2834static void 2806static void
2835handle_client_send (void *cls, 2807handle_client_send (void *cls, struct GNUNET_SERVER_Client *client,
2836 struct GNUNET_SERVER_Client *client,
2837 const struct GNUNET_MessageHeader *message) 2808 const struct GNUNET_MessageHeader *message)
2838{ 2809{
2839 const struct SendMessage *sm; 2810 const struct SendMessage *sm;
@@ -2852,8 +2823,7 @@ handle_client_send (void *cls,
2852 sizeof (struct SendMessage) + sizeof (struct GNUNET_MessageHeader)) 2823 sizeof (struct SendMessage) + sizeof (struct GNUNET_MessageHeader))
2853 { 2824 {
2854 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2825 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2855 "msize is %u, should be at least %u (in %s:%d)\n", 2826 "msize is %u, should be at least %u (in %s:%d)\n", msize,
2856 msize,
2857 sizeof (struct SendMessage) + 2827 sizeof (struct SendMessage) +
2858 sizeof (struct GNUNET_MessageHeader), __FILE__, __LINE__); 2828 sizeof (struct GNUNET_MessageHeader), __FILE__, __LINE__);
2859 GNUNET_break (0); 2829 GNUNET_break (0);
@@ -2867,17 +2837,14 @@ handle_client_send (void *cls,
2867 memcmp (&sm->peer, &my_identity, sizeof (struct GNUNET_PeerIdentity))) 2837 memcmp (&sm->peer, &my_identity, sizeof (struct GNUNET_PeerIdentity)))
2868 { 2838 {
2869 /* loopback */ 2839 /* loopback */
2870 GNUNET_SERVER_mst_receive (mst, 2840 GNUNET_SERVER_mst_receive (mst, &self, (const char *) &sm[1], msize,
2871 &self, 2841 GNUNET_YES, GNUNET_NO);
2872 (const char *) &sm[1],
2873 msize, GNUNET_YES, GNUNET_NO);
2874 if (client != NULL) 2842 if (client != NULL)
2875 GNUNET_SERVER_receive_done (client, GNUNET_OK); 2843 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2876 return; 2844 return;
2877 } 2845 }
2878 n = find_neighbour (&sm->peer); 2846 n = find_neighbour (&sm->peer);
2879 if ((n == NULL) || 2847 if ((n == NULL) || (GNUNET_YES != n->is_connected) ||
2880 (GNUNET_YES != n->is_connected) ||
2881 (n->status != PEER_STATE_KEY_CONFIRMED)) 2848 (n->status != PEER_STATE_KEY_CONFIRMED))
2882 { 2849 {
2883 /* attempt to send message to peer that is not connected anymore 2850 /* attempt to send message to peer that is not connected anymore
@@ -2932,8 +2899,7 @@ handle_client_send (void *cls,
2932#if DEBUG_CORE 2899#if DEBUG_CORE
2933 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2900 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2934 "Queue full (%u/%u), discarding new request (%u bytes of type %u)\n", 2901 "Queue full (%u/%u), discarding new request (%u bytes of type %u)\n",
2935 queue_size, 2902 queue_size, (unsigned int) MAX_PEER_QUEUE_SIZE,
2936 (unsigned int) MAX_PEER_QUEUE_SIZE,
2937 (unsigned int) msize, (unsigned int) ntohs (message->type)); 2903 (unsigned int) msize, (unsigned int) ntohs (message->type));
2938#endif 2904#endif
2939 GNUNET_STATISTICS_update (stats, 2905 GNUNET_STATISTICS_update (stats,
@@ -3004,15 +2970,14 @@ handle_client_send (void *cls,
3004 * @param message the "struct ConnectMessage" 2970 * @param message the "struct ConnectMessage"
3005 */ 2971 */
3006static void 2972static void
3007handle_client_request_connect (void *cls, 2973handle_client_request_connect (void *cls, struct GNUNET_SERVER_Client *client,
3008 struct GNUNET_SERVER_Client *client,
3009 const struct GNUNET_MessageHeader *message) 2974 const struct GNUNET_MessageHeader *message)
3010{ 2975{
3011 const struct ConnectMessage *cm = (const struct ConnectMessage *) message; 2976 const struct ConnectMessage *cm = (const struct ConnectMessage *) message;
3012 struct Neighbour *n; 2977 struct Neighbour *n;
3013 2978
3014 if (0 == memcmp (&cm->peer, 2979 if (0 ==
3015 &my_identity, sizeof (struct GNUNET_PeerIdentity))) 2980 memcmp (&cm->peer, &my_identity, sizeof (struct GNUNET_PeerIdentity)))
3016 { 2981 {
3017 /* In this case a client has asked us to connect to ourselves, not really an error! */ 2982 /* In this case a client has asked us to connect to ourselves, not really an error! */
3018 GNUNET_SERVER_receive_done (client, GNUNET_OK); 2983 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -3025,8 +2990,8 @@ handle_client_request_connect (void *cls,
3025 "REQUEST_CONNECT", GNUNET_i2s (&cm->peer)); 2990 "REQUEST_CONNECT", GNUNET_i2s (&cm->peer));
3026#endif 2991#endif
3027 GNUNET_STATISTICS_update (stats, 2992 GNUNET_STATISTICS_update (stats,
3028 gettext_noop ("# connection requests received"), 2993 gettext_noop ("# connection requests received"), 1,
3029 1, GNUNET_NO); 2994 GNUNET_NO);
3030 GNUNET_SERVER_receive_done (client, GNUNET_OK); 2995 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3031 n = find_neighbour (&cm->peer); 2996 n = find_neighbour (&cm->peer);
3032 if ((n == NULL) || (GNUNET_YES != n->is_connected)) 2997 if ((n == NULL) || (GNUNET_YES != n->is_connected))
@@ -3054,8 +3019,7 @@ handle_client_request_connect (void *cls,
3054 * @param err_msg NULL if successful, otherwise contains error message 3019 * @param err_msg NULL if successful, otherwise contains error message
3055 */ 3020 */
3056static void 3021static void
3057process_hello_retry_send_key (void *cls, 3022process_hello_retry_send_key (void *cls, const struct GNUNET_PeerIdentity *peer,
3058 const struct GNUNET_PeerIdentity *peer,
3059 const struct GNUNET_HELLO_Message *hello, 3023 const struct GNUNET_HELLO_Message *hello,
3060 const char *err_msg) 3024 const char *err_msg)
3061{ 3025{
@@ -3071,8 +3035,7 @@ process_hello_retry_send_key (void *cls,
3071 if (peer == NULL) 3035 if (peer == NULL)
3072 { 3036 {
3073#if DEBUG_CORE 3037#if DEBUG_CORE
3074 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3038 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Entered `%s' and `%s' is NULL!\n",
3075 "Entered `%s' and `%s' is NULL!\n",
3076 "process_hello_retry_send_key", "peer"); 3039 "process_hello_retry_send_key", "peer");
3077#endif 3040#endif
3078 n->pitr = NULL; 3041 n->pitr = NULL;
@@ -3101,16 +3064,15 @@ process_hello_retry_send_key (void *cls,
3101 ("# Delayed connecting due to lack of public key"), 3064 ("# Delayed connecting due to lack of public key"),
3102 1, GNUNET_NO); 3065 1, GNUNET_NO);
3103 if (GNUNET_SCHEDULER_NO_TASK == n->retry_set_key_task) 3066 if (GNUNET_SCHEDULER_NO_TASK == n->retry_set_key_task)
3104 n->retry_set_key_task 3067 n->retry_set_key_task =
3105 = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency, 3068 GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency,
3106 &set_key_retry_task, n); 3069 &set_key_retry_task, n);
3107 } 3070 }
3108 return; 3071 return;
3109 } 3072 }
3110 3073
3111#if DEBUG_CORE 3074#if DEBUG_CORE
3112 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3075 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Entered `%s' for peer `%4s'\n",
3113 "Entered `%s' for peer `%4s'\n",
3114 "process_hello_retry_send_key", GNUNET_i2s (peer)); 3076 "process_hello_retry_send_key", GNUNET_i2s (peer));
3115#endif 3077#endif
3116 if (n->public_key != NULL) 3078 if (n->public_key != NULL)
@@ -3196,11 +3158,11 @@ send_key (struct Neighbour *n)
3196 GNUNET_i2s (&n->peer)); 3158 GNUNET_i2s (&n->peer));
3197#endif 3159#endif
3198 GNUNET_assert (n->pitr == NULL); 3160 GNUNET_assert (n->pitr == NULL);
3199 n->pitr = GNUNET_PEERINFO_iterate (peerinfo, 3161 n->pitr =
3200 &n->peer, 3162 GNUNET_PEERINFO_iterate (peerinfo, &n->peer,
3201 GNUNET_TIME_relative_multiply 3163 GNUNET_TIME_relative_multiply
3202 (GNUNET_TIME_UNIT_SECONDS, 20), 3164 (GNUNET_TIME_UNIT_SECONDS, 20),
3203 &process_hello_retry_send_key, n); 3165 &process_hello_retry_send_key, n);
3204 return; 3166 return;
3205 } 3167 }
3206 pos = n->encrypted_head; 3168 pos = n->encrypted_head;
@@ -3212,8 +3174,8 @@ send_key (struct Neighbour *n)
3212 { 3174 {
3213#if DEBUG_CORE 3175#if DEBUG_CORE
3214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3176 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3215 "`%s' message for `%4s' queued already\n", 3177 "`%s' message for `%4s' queued already\n", "SET_KEY",
3216 "SET_KEY", GNUNET_i2s (&n->peer)); 3178 GNUNET_i2s (&n->peer));
3217#endif 3179#endif
3218 goto trigger_processing; 3180 goto trigger_processing;
3219 } 3181 }
@@ -3257,13 +3219,15 @@ send_key (struct Neighbour *n)
3257 me->is_setkey = GNUNET_YES; 3219 me->is_setkey = GNUNET_YES;
3258 me->got_slack = GNUNET_YES; /* do not defer this one! */ 3220 me->got_slack = GNUNET_YES; /* do not defer this one! */
3259 me->sender_status = n->status; 3221 me->sender_status = n->status;
3260 GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, 3222 GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, n->encrypted_tail,
3261 n->encrypted_tail, n->encrypted_tail, me); 3223 n->encrypted_tail, me);
3262 sm = (struct SetKeyMessage *) &me[1]; 3224 sm = (struct SetKeyMessage *) &me[1];
3263 sm->header.size = htons (sizeof (struct SetKeyMessage)); 3225 sm->header.size = htons (sizeof (struct SetKeyMessage));
3264 sm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SET_KEY); 3226 sm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SET_KEY);
3265 sm->sender_status = htonl ((int32_t) ((n->status == PEER_STATE_DOWN) ? 3227 sm->sender_status =
3266 PEER_STATE_KEY_SENT : n->status)); 3228 htonl ((int32_t)
3229 ((n->status ==
3230 PEER_STATE_DOWN) ? PEER_STATE_KEY_SENT : n->status));
3267 sm->purpose.size = 3231 sm->purpose.size =
3268 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + 3232 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
3269 sizeof (struct GNUNET_TIME_AbsoluteNBO) + 3233 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
@@ -3291,18 +3255,13 @@ send_key (struct Neighbour *n)
3291#if DEBUG_HANDSHAKE 3255#if DEBUG_HANDSHAKE
3292 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3293 "Encrypting `%s' and `%s' messages with challenge %u for `%4s' using key %u, IV %u (salt %u).\n", 3257 "Encrypting `%s' and `%s' messages with challenge %u for `%4s' using key %u, IV %u (salt %u).\n",
3294 "SET_KEY", "PING", 3258 "SET_KEY", "PING", (unsigned int) n->ping_challenge,
3295 (unsigned int) n->ping_challenge, 3259 GNUNET_i2s (&n->peer), (unsigned int) n->encrypt_key.crc32,
3296 GNUNET_i2s (&n->peer),
3297 (unsigned int) n->encrypt_key.crc32,
3298 GNUNET_CRYPTO_crc32_n (&iv, sizeof (iv)), pm->iv_seed); 3260 GNUNET_CRYPTO_crc32_n (&iv, sizeof (iv)), pm->iv_seed);
3299#endif 3261#endif
3300 do_encrypt (n, 3262 do_encrypt (n, &iv, &pp.target, &pm->target,
3301 &iv, 3263 sizeof (struct PingMessage) - ((void *) &pm->target -
3302 &pp.target, 3264 (void *) pm));
3303 &pm->target,
3304 sizeof (struct PingMessage) -
3305 ((void *) &pm->target - (void *) pm));
3306 GNUNET_STATISTICS_update (stats, 3265 GNUNET_STATISTICS_update (stats,
3307 gettext_noop 3266 gettext_noop
3308 ("# SET_KEY and PING messages created"), 1, 3267 ("# SET_KEY and PING messages created"), 1,
@@ -3310,18 +3269,18 @@ send_key (struct Neighbour *n)
3310#if DEBUG_CORE 3269#if DEBUG_CORE
3311 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3312 "Have %llu ms left for `%s' transmission.\n", 3271 "Have %llu ms left for `%s' transmission.\n",
3313 (unsigned long long) 3272 (unsigned long long) GNUNET_TIME_absolute_get_remaining (me->
3314 GNUNET_TIME_absolute_get_remaining (me->deadline).rel_value, 3273 deadline).
3315 "SET_KEY"); 3274 rel_value, "SET_KEY");
3316#endif 3275#endif
3317trigger_processing: 3276trigger_processing:
3318 /* trigger queue processing */ 3277 /* trigger queue processing */
3319 process_encrypted_neighbour_queue (n); 3278 process_encrypted_neighbour_queue (n);
3320 if ((n->status != PEER_STATE_KEY_CONFIRMED) && 3279 if ((n->status != PEER_STATE_KEY_CONFIRMED) &&
3321 (GNUNET_SCHEDULER_NO_TASK == n->retry_set_key_task)) 3280 (GNUNET_SCHEDULER_NO_TASK == n->retry_set_key_task))
3322 n->retry_set_key_task 3281 n->retry_set_key_task =
3323 = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency, 3282 GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency,
3324 &set_key_retry_task, n); 3283 &set_key_retry_task, n);
3325} 3284}
3326 3285
3327 3286
@@ -3334,11 +3293,9 @@ trigger_processing:
3334 * @param ats performance data 3293 * @param ats performance data
3335 * @param ats_count number of entries in ats (excluding 0-termination) 3294 * @param ats_count number of entries in ats (excluding 0-termination)
3336 */ 3295 */
3337static void 3296static void handle_set_key (struct Neighbour *n, const struct SetKeyMessage *m,
3338handle_set_key (struct Neighbour *n, 3297 const struct GNUNET_TRANSPORT_ATS_Information *ats,
3339 const struct SetKeyMessage *m, 3298 uint32_t ats_count);
3340 const struct GNUNET_TRANSPORT_ATS_Information *ats,
3341 uint32_t ats_count);
3342 3299
3343 3300
3344 3301
@@ -3450,8 +3407,7 @@ update_neighbour_performance (struct Neighbour *n,
3450 * @param ats_count number of entries in ats (excluding 0-termination) 3407 * @param ats_count number of entries in ats (excluding 0-termination)
3451 */ 3408 */
3452static void 3409static void
3453handle_ping (struct Neighbour *n, 3410handle_ping (struct Neighbour *n, const struct PingMessage *m,
3454 const struct PingMessage *m,
3455 const struct GNUNET_TRANSPORT_ATS_Information *ats, 3411 const struct GNUNET_TRANSPORT_ATS_Information *ats,
3456 uint32_t ats_count) 3412 uint32_t ats_count)
3457{ 3413{
@@ -3463,32 +3419,28 @@ handle_ping (struct Neighbour *n,
3463 3419
3464#if DEBUG_CORE 3420#if DEBUG_CORE
3465 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3421 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3466 "Core service receives `%s' request from `%4s'.\n", 3422 "Core service receives `%s' request from `%4s'.\n", "PING",
3467 "PING", GNUNET_i2s (&n->peer)); 3423 GNUNET_i2s (&n->peer));
3468#endif 3424#endif
3469 derive_iv (&iv, &n->decrypt_key, m->iv_seed, &my_identity); 3425 derive_iv (&iv, &n->decrypt_key, m->iv_seed, &my_identity);
3470 if (GNUNET_OK != 3426 if (GNUNET_OK !=
3471 do_decrypt (n, 3427 do_decrypt (n, &iv, &m->target, &t.target,
3472 &iv, 3428 sizeof (struct PingMessage) - ((void *) &m->target -
3473 &m->target, 3429 (void *) m)))
3474 &t.target,
3475 sizeof (struct PingMessage) -
3476 ((void *) &m->target - (void *) m)))
3477 return; 3430 return;
3478#if DEBUG_HANDSHAKE 3431#if DEBUG_HANDSHAKE
3479 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3432 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3480 "Decrypted `%s' to `%4s' with challenge %u decrypted using key %u, IV %u (salt %u)\n", 3433 "Decrypted `%s' to `%4s' with challenge %u decrypted using key %u, IV %u (salt %u)\n",
3481 "PING", 3434 "PING", GNUNET_i2s (&t.target), (unsigned int) t.challenge,
3482 GNUNET_i2s (&t.target), 3435 (unsigned int) n->decrypt_key.crc32, GNUNET_CRYPTO_crc32_n (&iv,
3483 (unsigned int) t.challenge, 3436 sizeof
3484 (unsigned int) n->decrypt_key.crc32, 3437 (iv)),
3485 GNUNET_CRYPTO_crc32_n (&iv, sizeof (iv)), m->iv_seed); 3438 m->iv_seed);
3486#endif 3439#endif
3487 GNUNET_STATISTICS_update (stats, 3440 GNUNET_STATISTICS_update (stats, gettext_noop ("# PING messages decrypted"),
3488 gettext_noop ("# PING messages decrypted"),
3489 1, GNUNET_NO); 3441 1, GNUNET_NO);
3490 if (0 != memcmp (&t.target, 3442 if (0 !=
3491 &my_identity, sizeof (struct GNUNET_PeerIdentity))) 3443 memcmp (&t.target, &my_identity, sizeof (struct GNUNET_PeerIdentity)))
3492 { 3444 {
3493 char sender[9]; 3445 char sender[9];
3494 char peer[9]; 3446 char peer[9];
@@ -3505,8 +3457,8 @@ handle_ping (struct Neighbour *n,
3505 update_neighbour_performance (n, ats, ats_count); 3457 update_neighbour_performance (n, ats, ats_count);
3506 me = GNUNET_malloc (sizeof (struct MessageEntry) + 3458 me = GNUNET_malloc (sizeof (struct MessageEntry) +
3507 sizeof (struct PongMessage)); 3459 sizeof (struct PongMessage));
3508 GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, 3460 GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, n->encrypted_tail,
3509 n->encrypted_tail, n->encrypted_tail, me); 3461 n->encrypted_tail, me);
3510 me->deadline = GNUNET_TIME_relative_to_absolute (MAX_PONG_DELAY); 3462 me->deadline = GNUNET_TIME_relative_to_absolute (MAX_PONG_DELAY);
3511 me->priority = PONG_PRIORITY; 3463 me->priority = PONG_PRIORITY;
3512 me->size = sizeof (struct PongMessage); 3464 me->size = sizeof (struct PongMessage);
@@ -3519,22 +3471,19 @@ handle_ping (struct Neighbour *n,
3519 tp->iv_seed = 3471 tp->iv_seed =
3520 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); 3472 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
3521 derive_pong_iv (&iv, &n->encrypt_key, tp->iv_seed, t.challenge, &n->peer); 3473 derive_pong_iv (&iv, &n->encrypt_key, tp->iv_seed, t.challenge, &n->peer);
3522 do_encrypt (n, 3474 do_encrypt (n, &iv, &tx.challenge, &tp->challenge,
3523 &iv, 3475 sizeof (struct PongMessage) - ((void *) &tp->challenge -
3524 &tx.challenge, 3476 (void *) tp));
3525 &tp->challenge, 3477 GNUNET_STATISTICS_update (stats, gettext_noop ("# PONG messages created"), 1,
3526 sizeof (struct PongMessage) - 3478 GNUNET_NO);
3527 ((void *) &tp->challenge - (void *) tp));
3528 GNUNET_STATISTICS_update (stats,
3529 gettext_noop ("# PONG messages created"),
3530 1, GNUNET_NO);
3531#if DEBUG_HANDSHAKE 3479#if DEBUG_HANDSHAKE
3532 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3480 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3533 "Encrypting `%s' with challenge %u using key %u, IV %u (salt %u)\n", 3481 "Encrypting `%s' with challenge %u using key %u, IV %u (salt %u)\n",
3534 "PONG", 3482 "PONG", (unsigned int) t.challenge,
3535 (unsigned int) t.challenge, 3483 (unsigned int) n->encrypt_key.crc32, GNUNET_CRYPTO_crc32_n (&iv,
3536 (unsigned int) n->encrypt_key.crc32, 3484 sizeof
3537 GNUNET_CRYPTO_crc32_n (&iv, sizeof (iv)), tp->iv_seed); 3485 (iv)),
3486 tp->iv_seed);
3538#endif 3487#endif
3539 /* trigger queue processing */ 3488 /* trigger queue processing */
3540 process_encrypted_neighbour_queue (n); 3489 process_encrypted_neighbour_queue (n);
@@ -3550,8 +3499,7 @@ handle_ping (struct Neighbour *n,
3550 * @param ats_count number of entries in ats (excluding 0-termination) 3499 * @param ats_count number of entries in ats (excluding 0-termination)
3551 */ 3500 */
3552static void 3501static void
3553handle_pong (struct Neighbour *n, 3502handle_pong (struct Neighbour *n, const struct PongMessage *m,
3554 const struct PongMessage *m,
3555 const struct GNUNET_TRANSPORT_ATS_Information *ats, 3503 const struct GNUNET_TRANSPORT_ATS_Information *ats,
3556 uint32_t ats_count) 3504 uint32_t ats_count)
3557{ 3505{
@@ -3564,47 +3512,41 @@ handle_pong (struct Neighbour *n,
3564 3512
3565#if DEBUG_HANDSHAKE 3513#if DEBUG_HANDSHAKE
3566 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3514 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3567 "Core service receives `%s' response from `%4s'.\n", 3515 "Core service receives `%s' response from `%4s'.\n", "PONG",
3568 "PONG", GNUNET_i2s (&n->peer)); 3516 GNUNET_i2s (&n->peer));
3569#endif 3517#endif
3570 /* mark as garbage, just to be sure */ 3518 /* mark as garbage, just to be sure */
3571 memset (&t, 255, sizeof (t)); 3519 memset (&t, 255, sizeof (t));
3572 derive_pong_iv (&iv, &n->decrypt_key, m->iv_seed, n->ping_challenge, 3520 derive_pong_iv (&iv, &n->decrypt_key, m->iv_seed, n->ping_challenge,
3573 &my_identity); 3521 &my_identity);
3574 if (GNUNET_OK != 3522 if (GNUNET_OK !=
3575 do_decrypt (n, 3523 do_decrypt (n, &iv, &m->challenge, &t.challenge,
3576 &iv, 3524 sizeof (struct PongMessage) - ((void *) &m->challenge -
3577 &m->challenge, 3525 (void *) m)))
3578 &t.challenge,
3579 sizeof (struct PongMessage) -
3580 ((void *) &m->challenge - (void *) m)))
3581 { 3526 {
3582 GNUNET_break_op (0); 3527 GNUNET_break_op (0);
3583 return; 3528 return;
3584 } 3529 }
3585 GNUNET_STATISTICS_update (stats, 3530 GNUNET_STATISTICS_update (stats, gettext_noop ("# PONG messages decrypted"),
3586 gettext_noop ("# PONG messages decrypted"),
3587 1, GNUNET_NO); 3531 1, GNUNET_NO);
3588#if DEBUG_HANDSHAKE 3532#if DEBUG_HANDSHAKE
3589 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3533 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3590 "Decrypted `%s' from `%4s' with challenge %u using key %u, IV %u (salt %u)\n", 3534 "Decrypted `%s' from `%4s' with challenge %u using key %u, IV %u (salt %u)\n",
3591 "PONG", 3535 "PONG", GNUNET_i2s (&t.target), (unsigned int) t.challenge,
3592 GNUNET_i2s (&t.target), 3536 (unsigned int) n->decrypt_key.crc32, GNUNET_CRYPTO_crc32_n (&iv,
3593 (unsigned int) t.challenge, 3537 sizeof
3594 (unsigned int) n->decrypt_key.crc32, 3538 (iv)),
3595 GNUNET_CRYPTO_crc32_n (&iv, sizeof (iv)), m->iv_seed); 3539 m->iv_seed);
3596#endif 3540#endif
3597 if ((0 != memcmp (&t.target, 3541 if ((0 != memcmp (&t.target, &n->peer, sizeof (struct GNUNET_PeerIdentity)))
3598 &n->peer, 3542 || (n->ping_challenge != t.challenge))
3599 sizeof (struct GNUNET_PeerIdentity))) ||
3600 (n->ping_challenge != t.challenge))
3601 { 3543 {
3602 /* PONG malformed */ 3544 /* PONG malformed */
3603#if DEBUG_CORE 3545#if DEBUG_CORE
3604 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3546 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3605 "Received malformed `%s' wanted sender `%4s' with challenge %u\n", 3547 "Received malformed `%s' wanted sender `%4s' with challenge %u\n",
3606 "PONG", 3548 "PONG", GNUNET_i2s (&n->peer),
3607 GNUNET_i2s (&n->peer), (unsigned int) n->ping_challenge); 3549 (unsigned int) n->ping_challenge);
3608 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3550 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3609 "Received malformed `%s' received from `%4s' with challenge %u\n", 3551 "Received malformed `%s' received from `%4s' with challenge %u\n",
3610 "PONG", GNUNET_i2s (&t.target), (unsigned int) t.challenge); 3552 "PONG", GNUNET_i2s (&t.target), (unsigned int) t.challenge);
@@ -3636,16 +3578,17 @@ handle_pong (struct Neighbour *n,
3636 if (n->bw_out_external_limit.value__ != t.inbound_bw_limit.value__) 3578 if (n->bw_out_external_limit.value__ != t.inbound_bw_limit.value__)
3637 { 3579 {
3638 n->bw_out_external_limit = t.inbound_bw_limit; 3580 n->bw_out_external_limit = t.inbound_bw_limit;
3639 n->bw_out = GNUNET_BANDWIDTH_value_min (n->bw_out_external_limit, 3581 n->bw_out =
3640 n->bw_out_internal_limit); 3582 GNUNET_BANDWIDTH_value_min (n->bw_out_external_limit,
3583 n->bw_out_internal_limit);
3641 GNUNET_BANDWIDTH_tracker_update_quota (&n->available_send_window, 3584 GNUNET_BANDWIDTH_tracker_update_quota (&n->available_send_window,
3642 n->bw_out); 3585 n->bw_out);
3643 GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out); 3586 GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out);
3644 } 3587 }
3645#if DEBUG_CORE 3588#if DEBUG_CORE
3646 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3589 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3647 "Confirmed key via `%s' message for peer `%4s'\n", 3590 "Confirmed key via `%s' message for peer `%4s'\n", "PONG",
3648 "PONG", GNUNET_i2s (&n->peer)); 3591 GNUNET_i2s (&n->peer));
3649#endif 3592#endif
3650 if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK) 3593 if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK)
3651 { 3594 {
@@ -3653,14 +3596,16 @@ handle_pong (struct Neighbour *n,
3653 n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; 3596 n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK;
3654 } 3597 }
3655 update_neighbour_performance (n, ats, ats_count); 3598 update_neighbour_performance (n, ats, ats_count);
3656 size = sizeof (struct ConnectNotifyMessage) + 3599 size =
3600 sizeof (struct ConnectNotifyMessage) +
3657 (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); 3601 (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
3658 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 3602 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
3659 { 3603 {
3660 GNUNET_break (0); 3604 GNUNET_break (0);
3661 /* recovery strategy: throw away performance data */ 3605 /* recovery strategy: throw away performance data */
3662 GNUNET_array_grow (n->ats, n->ats_count, 0); 3606 GNUNET_array_grow (n->ats, n->ats_count, 0);
3663 size = sizeof (struct PeerStatusNotifyMessage) + 3607 size =
3608 sizeof (struct PeerStatusNotifyMessage) +
3664 n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information); 3609 n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
3665 } 3610 }
3666 cnm = (struct ConnectNotifyMessage *) buf; 3611 cnm = (struct ConnectNotifyMessage *) buf;
@@ -3669,21 +3614,19 @@ handle_pong (struct Neighbour *n,
3669 cnm->ats_count = htonl (n->ats_count); 3614 cnm->ats_count = htonl (n->ats_count);
3670 cnm->peer = n->peer; 3615 cnm->peer = n->peer;
3671 mats = &cnm->ats; 3616 mats = &cnm->ats;
3672 memcpy (mats, 3617 memcpy (mats, n->ats,
3673 n->ats,
3674 n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); 3618 n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
3675 mats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 3619 mats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
3676 mats[n->ats_count].value = htonl (0); 3620 mats[n->ats_count].value = htonl (0);
3677 send_to_all_clients (&cnm->header, 3621 send_to_all_clients (&cnm->header, GNUNET_NO,
3678 GNUNET_NO, GNUNET_CORE_OPTION_SEND_CONNECT); 3622 GNUNET_CORE_OPTION_SEND_CONNECT);
3679 process_encrypted_neighbour_queue (n); 3623 process_encrypted_neighbour_queue (n);
3680 /* fall-through! */ 3624 /* fall-through! */
3681 case PEER_STATE_KEY_CONFIRMED: 3625 case PEER_STATE_KEY_CONFIRMED:
3682 n->last_activity = GNUNET_TIME_absolute_get (); 3626 n->last_activity = GNUNET_TIME_absolute_get ();
3683 if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) 3627 if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK)
3684 GNUNET_SCHEDULER_cancel (n->keep_alive_task); 3628 GNUNET_SCHEDULER_cancel (n->keep_alive_task);
3685 n->keep_alive_task 3629 n->keep_alive_task =
3686 =
3687 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide 3630 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide
3688 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 3631 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
3689 2), &send_keep_alive, n); 3632 2), &send_keep_alive, n);
@@ -3706,8 +3649,7 @@ handle_pong (struct Neighbour *n,
3706 * @param ats_count number of entries in ats (excluding 0-termination) 3649 * @param ats_count number of entries in ats (excluding 0-termination)
3707 */ 3650 */
3708static void 3651static void
3709handle_set_key (struct Neighbour *n, 3652handle_set_key (struct Neighbour *n, const struct SetKeyMessage *m,
3710 const struct SetKeyMessage *m,
3711 const struct GNUNET_TRANSPORT_ATS_Information *ats, 3653 const struct GNUNET_TRANSPORT_ATS_Information *ats,
3712 uint32_t ats_count) 3654 uint32_t ats_count)
3713{ 3655{
@@ -3720,8 +3662,8 @@ handle_set_key (struct Neighbour *n,
3720 3662
3721#if DEBUG_CORE 3663#if DEBUG_CORE
3722 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3664 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3723 "Core service receives `%s' request from `%4s'.\n", 3665 "Core service receives `%s' request from `%4s'.\n", "SET_KEY",
3724 "SET_KEY", GNUNET_i2s (&n->peer)); 3666 GNUNET_i2s (&n->peer));
3725#endif 3667#endif
3726 if (n->public_key == NULL) 3668 if (n->public_key == NULL)
3727 { 3669 {
@@ -3743,18 +3685,17 @@ handle_set_key (struct Neighbour *n,
3743 /* lookup n's public key, then try again */ 3685 /* lookup n's public key, then try again */
3744 GNUNET_assert (n->skm == NULL); 3686 GNUNET_assert (n->skm == NULL);
3745 n->skm = m_cpy; 3687 n->skm = m_cpy;
3746 n->pitr = GNUNET_PEERINFO_iterate (peerinfo, 3688 n->pitr =
3747 &n->peer, 3689 GNUNET_PEERINFO_iterate (peerinfo, &n->peer, GNUNET_TIME_UNIT_MINUTES,
3748 GNUNET_TIME_UNIT_MINUTES, 3690 &process_hello_retry_handle_set_key, n);
3749 &process_hello_retry_handle_set_key, n);
3750 GNUNET_STATISTICS_update (stats, 3691 GNUNET_STATISTICS_update (stats,
3751 gettext_noop 3692 gettext_noop
3752 ("# SET_KEY messages deferred (need public key)"), 3693 ("# SET_KEY messages deferred (need public key)"),
3753 1, GNUNET_NO); 3694 1, GNUNET_NO);
3754 return; 3695 return;
3755 } 3696 }
3756 if (0 != memcmp (&m->target, 3697 if (0 !=
3757 &my_identity, sizeof (struct GNUNET_PeerIdentity))) 3698 memcmp (&m->target, &my_identity, sizeof (struct GNUNET_PeerIdentity)))
3758 { 3699 {
3759 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3700 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3760 _ 3701 _
@@ -3768,8 +3709,8 @@ handle_set_key (struct Neighbour *n,
3768 sizeof (struct GNUNET_CRYPTO_RsaEncryptedData) + 3709 sizeof (struct GNUNET_CRYPTO_RsaEncryptedData) +
3769 sizeof (struct GNUNET_PeerIdentity)) || 3710 sizeof (struct GNUNET_PeerIdentity)) ||
3770 (GNUNET_OK != 3711 (GNUNET_OK !=
3771 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_SET_KEY, 3712 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_SET_KEY, &m->purpose,
3772 &m->purpose, &m->signature, n->public_key))) 3713 &m->signature, n->public_key)))
3773 { 3714 {
3774 /* invalid signature */ 3715 /* invalid signature */
3775 GNUNET_break_op (0); 3716 GNUNET_break_op (0);
@@ -3789,11 +3730,10 @@ handle_set_key (struct Neighbour *n,
3789#if DEBUG_CORE 3730#if DEBUG_CORE
3790 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting key material.\n"); 3731 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting key material.\n");
3791#endif 3732#endif
3792 if ((GNUNET_CRYPTO_rsa_decrypt (my_private_key, 3733 if ((GNUNET_CRYPTO_rsa_decrypt
3793 &m->encrypted_key, 3734 (my_private_key, &m->encrypted_key, &k,
3794 &k, 3735 sizeof (struct GNUNET_CRYPTO_AesSessionKey)) !=
3795 sizeof (struct GNUNET_CRYPTO_AesSessionKey)) 3736 sizeof (struct GNUNET_CRYPTO_AesSessionKey)) ||
3796 != sizeof (struct GNUNET_CRYPTO_AesSessionKey)) ||
3797 (GNUNET_OK != GNUNET_CRYPTO_aes_check_session_key (&k))) 3737 (GNUNET_OK != GNUNET_CRYPTO_aes_check_session_key (&k)))
3798 { 3738 {
3799 /* failed to decrypt !? */ 3739 /* failed to decrypt !? */
@@ -3801,8 +3741,8 @@ handle_set_key (struct Neighbour *n,
3801 return; 3741 return;
3802 } 3742 }
3803 GNUNET_STATISTICS_update (stats, 3743 GNUNET_STATISTICS_update (stats,
3804 gettext_noop ("# SET_KEY messages decrypted"), 3744 gettext_noop ("# SET_KEY messages decrypted"), 1,
3805 1, GNUNET_NO); 3745 GNUNET_NO);
3806 n->decrypt_key = k; 3746 n->decrypt_key = k;
3807 if (n->decrypt_key_created.abs_value != t.abs_value) 3747 if (n->decrypt_key_created.abs_value != t.abs_value)
3808 { 3748 {
@@ -3879,10 +3819,11 @@ handle_set_key (struct Neighbour *n,
3879 * @param msize number of bytes in buf to transmit 3819 * @param msize number of bytes in buf to transmit
3880 */ 3820 */
3881static void 3821static void
3882send_p2p_message_to_client (struct Neighbour *sender, 3822send_p2p_message_to_client (struct Neighbour *sender, struct Client *client,
3883 struct Client *client, const void *m, size_t msize) 3823 const void *m, size_t msize)
3884{ 3824{
3885 size_t size = msize + sizeof (struct NotifyTrafficMessage) + 3825 size_t size =
3826 msize + sizeof (struct NotifyTrafficMessage) +
3886 (sender->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); 3827 (sender->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
3887 char buf[size]; 3828 char buf[size];
3888 struct NotifyTrafficMessage *ntm; 3829 struct NotifyTrafficMessage *ntm;
@@ -3894,15 +3835,16 @@ send_p2p_message_to_client (struct Neighbour *sender,
3894 GNUNET_break (0); 3835 GNUNET_break (0);
3895 /* recovery strategy: throw performance data away... */ 3836 /* recovery strategy: throw performance data away... */
3896 GNUNET_array_grow (sender->ats, sender->ats_count, 0); 3837 GNUNET_array_grow (sender->ats, sender->ats_count, 0);
3897 size = msize + sizeof (struct NotifyTrafficMessage) + 3838 size =
3839 msize + sizeof (struct NotifyTrafficMessage) +
3898 (sender->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); 3840 (sender->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
3899 } 3841 }
3900#if DEBUG_CORE 3842#if DEBUG_CORE
3901 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3843 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3902 "Core service passes message from `%4s' of type %u to client.\n", 3844 "Core service passes message from `%4s' of type %u to client.\n",
3903 GNUNET_i2s (&sender->peer), 3845 GNUNET_i2s (&sender->peer),
3904 (unsigned int) 3846 (unsigned int) ntohs (((const struct GNUNET_MessageHeader *) m)->
3905 ntohs (((const struct GNUNET_MessageHeader *) m)->type)); 3847 type));
3906#endif 3848#endif
3907 ntm = (struct NotifyTrafficMessage *) buf; 3849 ntm = (struct NotifyTrafficMessage *) buf;
3908 ntm->header.size = htons (size); 3850 ntm->header.size = htons (size);
@@ -3910,8 +3852,7 @@ send_p2p_message_to_client (struct Neighbour *sender,
3910 ntm->ats_count = htonl (sender->ats_count); 3852 ntm->ats_count = htonl (sender->ats_count);
3911 ntm->peer = sender->peer; 3853 ntm->peer = sender->peer;
3912 ats = &ntm->ats; 3854 ats = &ntm->ats;
3913 memcpy (ats, 3855 memcpy (ats, sender->ats,
3914 sender->ats,
3915 sizeof (struct GNUNET_TRANSPORT_ATS_Information) * sender->ats_count); 3856 sizeof (struct GNUNET_TRANSPORT_ATS_Information) * sender->ats_count);
3916 ats[sender->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 3857 ats[sender->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
3917 ats[sender->ats_count].value = htonl (0); 3858 ats[sender->ats_count].value = htonl (0);
@@ -3945,8 +3886,7 @@ deliver_message (void *cls, void *client, const struct GNUNET_MessageHeader *m)
3945 "Received encapsulated message of type %u and size %u from `%4s'\n", 3886 "Received encapsulated message of type %u and size %u from `%4s'\n",
3946 (unsigned int) type, ntohs (m->size), GNUNET_i2s (&sender->peer)); 3887 (unsigned int) type, ntohs (m->size), GNUNET_i2s (&sender->peer));
3947#endif 3888#endif
3948 GNUNET_snprintf (buf, 3889 GNUNET_snprintf (buf, sizeof (buf),
3949 sizeof (buf),
3950 gettext_noop ("# bytes of messages of type %u received"), 3890 gettext_noop ("# bytes of messages of type %u received"),
3951 (unsigned int) type); 3891 (unsigned int) type);
3952 GNUNET_STATISTICS_update (stats, buf, msize, GNUNET_NO); 3892 GNUNET_STATISTICS_update (stats, buf, msize, GNUNET_NO);
@@ -4010,8 +3950,7 @@ deliver_message (void *cls, void *client, const struct GNUNET_MessageHeader *m)
4010 * @param ats_count number of entries in ats (excluding 0-termination) 3950 * @param ats_count number of entries in ats (excluding 0-termination)
4011 */ 3951 */
4012static void 3952static void
4013handle_encrypted_message (struct Neighbour *n, 3953handle_encrypted_message (struct Neighbour *n, const struct EncryptedMessage *m,
4014 const struct EncryptedMessage *m,
4015 const struct GNUNET_TRANSPORT_ATS_Information *ats, 3954 const struct GNUNET_TRANSPORT_ATS_Information *ats,
4016 uint32_t ats_count) 3955 uint32_t ats_count)
4017{ 3956{
@@ -4030,10 +3969,10 @@ handle_encrypted_message (struct Neighbour *n,
4030 "ENCRYPTED_MESSAGE", GNUNET_i2s (&n->peer)); 3969 "ENCRYPTED_MESSAGE", GNUNET_i2s (&n->peer));
4031#endif 3970#endif
4032 /* validate hash */ 3971 /* validate hash */
4033 derive_auth_key (&auth_key, 3972 derive_auth_key (&auth_key, &n->decrypt_key, m->iv_seed,
4034 &n->decrypt_key, m->iv_seed, n->decrypt_key_created); 3973 n->decrypt_key_created);
4035 GNUNET_CRYPTO_hmac (&auth_key, 3974 GNUNET_CRYPTO_hmac (&auth_key, &m->sequence_number,
4036 &m->sequence_number, size - ENCRYPTED_HEADER_SIZE, &ph); 3975 size - ENCRYPTED_HEADER_SIZE, &ph);
4037#if DEBUG_HANDSHAKE 3976#if DEBUG_HANDSHAKE
4038 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3977 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4039 "Re-Authenticated %u bytes of ciphertext (`%u'): `%s'\n", 3978 "Re-Authenticated %u bytes of ciphertext (`%u'): `%s'\n",
@@ -4052,10 +3991,8 @@ handle_encrypted_message (struct Neighbour *n,
4052 derive_iv (&iv, &n->decrypt_key, m->iv_seed, &my_identity); 3991 derive_iv (&iv, &n->decrypt_key, m->iv_seed, &my_identity);
4053 /* decrypt */ 3992 /* decrypt */
4054 if (GNUNET_OK != 3993 if (GNUNET_OK !=
4055 do_decrypt (n, 3994 do_decrypt (n, &iv, &m->sequence_number, &buf[ENCRYPTED_HEADER_SIZE],
4056 &iv, 3995 size - ENCRYPTED_HEADER_SIZE))
4057 &m->sequence_number,
4058 &buf[ENCRYPTED_HEADER_SIZE], size - ENCRYPTED_HEADER_SIZE))
4059 return; 3996 return;
4060 pt = (struct EncryptedMessage *) buf; 3997 pt = (struct EncryptedMessage *) buf;
4061 3998
@@ -4116,8 +4053,7 @@ handle_encrypted_message (struct Neighbour *n,
4116 MAX_MESSAGE_AGE.rel_value) 4053 MAX_MESSAGE_AGE.rel_value)
4117 { 4054 {
4118 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 4055 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
4119 _ 4056 _("Message received far too old (%llu ms). Content ignored.\n"),
4120 ("Message received far too old (%llu ms). Content ignored.\n"),
4121 GNUNET_TIME_absolute_get_duration (t).rel_value); 4057 GNUNET_TIME_absolute_get_duration (t).rel_value);
4122 GNUNET_STATISTICS_update (stats, 4058 GNUNET_STATISTICS_update (stats,
4123 gettext_noop 4059 gettext_noop
@@ -4136,8 +4072,9 @@ handle_encrypted_message (struct Neighbour *n,
4136 GNUNET_i2s (&n->peer)); 4072 GNUNET_i2s (&n->peer));
4137#endif 4073#endif
4138 n->bw_out_external_limit = pt->inbound_bw_limit; 4074 n->bw_out_external_limit = pt->inbound_bw_limit;
4139 n->bw_out = GNUNET_BANDWIDTH_value_min (n->bw_out_external_limit, 4075 n->bw_out =
4140 n->bw_out_internal_limit); 4076 GNUNET_BANDWIDTH_value_min (n->bw_out_external_limit,
4077 n->bw_out_internal_limit);
4141 GNUNET_BANDWIDTH_tracker_update_quota (&n->available_send_window, 4078 GNUNET_BANDWIDTH_tracker_update_quota (&n->available_send_window,
4142 n->bw_out); 4079 n->bw_out);
4143 GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out); 4080 GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out);
@@ -4145,8 +4082,7 @@ handle_encrypted_message (struct Neighbour *n,
4145 n->last_activity = GNUNET_TIME_absolute_get (); 4082 n->last_activity = GNUNET_TIME_absolute_get ();
4146 if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) 4083 if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK)
4147 GNUNET_SCHEDULER_cancel (n->keep_alive_task); 4084 GNUNET_SCHEDULER_cancel (n->keep_alive_task);
4148 n->keep_alive_task 4085 n->keep_alive_task =
4149 =
4150 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide 4086 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide
4151 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 4087 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
4152 2), &send_keep_alive, n); 4088 2), &send_keep_alive, n);
@@ -4155,13 +4091,10 @@ handle_encrypted_message (struct Neighbour *n,
4155 size - sizeof (struct EncryptedMessage), GNUNET_NO); 4091 size - sizeof (struct EncryptedMessage), GNUNET_NO);
4156 handle_peer_status_change (n); 4092 handle_peer_status_change (n);
4157 update_neighbour_performance (n, ats, ats_count); 4093 update_neighbour_performance (n, ats, ats_count);
4158 if (GNUNET_OK != GNUNET_SERVER_mst_receive (mst, 4094 if (GNUNET_OK !=
4159 n, 4095 GNUNET_SERVER_mst_receive (mst, n, &buf[sizeof (struct EncryptedMessage)],
4160 &buf[sizeof 4096 size - sizeof (struct EncryptedMessage),
4161 (struct EncryptedMessage)], 4097 GNUNET_YES, GNUNET_NO))
4162 size -
4163 sizeof (struct EncryptedMessage),
4164 GNUNET_YES, GNUNET_NO))
4165 GNUNET_break_op (0); 4098 GNUNET_break_op (0);
4166} 4099}
4167 4100
@@ -4176,8 +4109,7 @@ handle_encrypted_message (struct Neighbour *n,
4176 * @param ats_count number of entries in ats (excluding 0-termination) 4109 * @param ats_count number of entries in ats (excluding 0-termination)
4177 */ 4110 */
4178static void 4111static void
4179handle_transport_receive (void *cls, 4112handle_transport_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
4180 const struct GNUNET_PeerIdentity *peer,
4181 const struct GNUNET_MessageHeader *message, 4113 const struct GNUNET_MessageHeader *message,
4182 const struct GNUNET_TRANSPORT_ATS_Information *ats, 4114 const struct GNUNET_TRANSPORT_ATS_Information *ats,
4183 uint32_t ats_count) 4115 uint32_t ats_count)
@@ -4218,14 +4150,13 @@ handle_transport_receive (void *cls,
4218 GNUNET_break_op (0); 4150 GNUNET_break_op (0);
4219 return; 4151 return;
4220 } 4152 }
4221 GNUNET_STATISTICS_update (stats, 4153 GNUNET_STATISTICS_update (stats, gettext_noop ("# session keys received"),
4222 gettext_noop ("# session keys received"),
4223 1, GNUNET_NO); 4154 1, GNUNET_NO);
4224 handle_set_key (n, (const struct SetKeyMessage *) message, ats, ats_count); 4155 handle_set_key (n, (const struct SetKeyMessage *) message, ats, ats_count);
4225 break; 4156 break;
4226 case GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE: 4157 case GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE:
4227 if (size < sizeof (struct EncryptedMessage) + 4158 if (size <
4228 sizeof (struct GNUNET_MessageHeader)) 4159 sizeof (struct EncryptedMessage) + sizeof (struct GNUNET_MessageHeader))
4229 { 4160 {
4230 GNUNET_break_op (0); 4161 GNUNET_break_op (0);
4231 return; 4162 return;
@@ -4240,9 +4171,8 @@ handle_transport_receive (void *cls,
4240 send_key (n); 4171 send_key (n);
4241 return; 4172 return;
4242 } 4173 }
4243 handle_encrypted_message (n, 4174 handle_encrypted_message (n, (const struct EncryptedMessage *) message, ats,
4244 (const struct EncryptedMessage *) message, 4175 ats_count);
4245 ats, ats_count);
4246 break; 4176 break;
4247 case GNUNET_MESSAGE_TYPE_CORE_PING: 4177 case GNUNET_MESSAGE_TYPE_CORE_PING:
4248 if (size != sizeof (struct PingMessage)) 4178 if (size != sizeof (struct PingMessage))
@@ -4303,15 +4233,13 @@ handle_transport_receive (void *cls,
4303 changed = GNUNET_YES; 4233 changed = GNUNET_YES;
4304 if (!up) 4234 if (!up)
4305 { 4235 {
4306 GNUNET_STATISTICS_update (stats, 4236 GNUNET_STATISTICS_update (stats, gettext_noop ("# established sessions"),
4307 gettext_noop ("# established sessions"),
4308 1, GNUNET_NO); 4237 1, GNUNET_NO);
4309 n->time_established = now; 4238 n->time_established = now;
4310 } 4239 }
4311 if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) 4240 if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK)
4312 GNUNET_SCHEDULER_cancel (n->keep_alive_task); 4241 GNUNET_SCHEDULER_cancel (n->keep_alive_task);
4313 n->keep_alive_task 4242 n->keep_alive_task =
4314 =
4315 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide 4243 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide
4316 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 4244 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
4317 2), &send_keep_alive, n); 4245 2), &send_keep_alive, n);
@@ -4411,10 +4339,8 @@ neighbour_quota_update (void *cls,
4411#if DEBUG_CORE_QUOTA 4339#if DEBUG_CORE_QUOTA
4412 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4413 "Current quota for `%4s' is %u/%llu b/s in (old: %u b/s) / %u out (%u internal)\n", 4341 "Current quota for `%4s' is %u/%llu b/s in (old: %u b/s) / %u out (%u internal)\n",
4414 GNUNET_i2s (&n->peer), 4342 GNUNET_i2s (&n->peer), (unsigned int) ntohl (q_in.value__),
4415 (unsigned int) ntohl (q_in.value__), 4343 bandwidth_target_out_bps, (unsigned int) ntohl (n->bw_in.value__),
4416 bandwidth_target_out_bps,
4417 (unsigned int) ntohl (n->bw_in.value__),
4418 (unsigned int) ntohl (n->bw_out.value__), 4344 (unsigned int) ntohl (n->bw_out.value__),
4419 (unsigned int) ntohl (n->bw_out_internal_limit.value__)); 4345 (unsigned int) ntohl (n->bw_out_internal_limit.value__));
4420#endif 4346#endif
@@ -4470,17 +4396,17 @@ handle_transport_notify_connect (void *cls,
4470 n = create_neighbour (peer); 4396 n = create_neighbour (peer);
4471 } 4397 }
4472 GNUNET_STATISTICS_update (stats, 4398 GNUNET_STATISTICS_update (stats,
4473 gettext_noop ("# peers connected (transport)"), 4399 gettext_noop ("# peers connected (transport)"), 1,
4474 1, GNUNET_NO); 4400 GNUNET_NO);
4475 n->is_connected = GNUNET_YES; 4401 n->is_connected = GNUNET_YES;
4476 update_neighbour_performance (n, ats, ats_count); 4402 update_neighbour_performance (n, ats, ats_count);
4477 GNUNET_BANDWIDTH_tracker_init (&n->available_send_window, 4403 GNUNET_BANDWIDTH_tracker_init (&n->available_send_window, n->bw_out,
4478 n->bw_out, MAX_WINDOW_TIME_S); 4404 MAX_WINDOW_TIME_S);
4479 GNUNET_BANDWIDTH_tracker_init (&n->available_recv_window, 4405 GNUNET_BANDWIDTH_tracker_init (&n->available_recv_window, n->bw_in,
4480 n->bw_in, MAX_WINDOW_TIME_S); 4406 MAX_WINDOW_TIME_S);
4481#if DEBUG_CORE 4407#if DEBUG_CORE
4482 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4408 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received connection from `%4s'.\n",
4483 "Received connection from `%4s'.\n", GNUNET_i2s (&n->peer)); 4409 GNUNET_i2s (&n->peer));
4484#endif 4410#endif
4485 GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out); 4411 GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out);
4486 send_key (n); 4412 send_key (n);
@@ -4552,8 +4478,8 @@ handle_transport_notify_disconnect (void *cls,
4552 } 4478 }
4553 4479
4554 GNUNET_STATISTICS_update (stats, 4480 GNUNET_STATISTICS_update (stats,
4555 gettext_noop ("# peers connected (transport)"), 4481 gettext_noop ("# peers connected (transport)"), -1,
4556 -1, GNUNET_NO); 4482 GNUNET_NO);
4557 if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK) 4483 if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK)
4558 GNUNET_SCHEDULER_cancel (n->dead_clean_task); 4484 GNUNET_SCHEDULER_cancel (n->dead_clean_task);
4559 left = 4485 left =
@@ -4595,8 +4521,8 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
4595 GNUNET_assert (transport != NULL); 4521 GNUNET_assert (transport != NULL);
4596 GNUNET_TRANSPORT_disconnect (transport); 4522 GNUNET_TRANSPORT_disconnect (transport);
4597 transport = NULL; 4523 transport = NULL;
4598 GNUNET_CONTAINER_multihashmap_iterate (neighbours, 4524 GNUNET_CONTAINER_multihashmap_iterate (neighbours, &free_neighbour_helper,
4599 &free_neighbour_helper, NULL); 4525 NULL);
4600 GNUNET_CONTAINER_multihashmap_destroy (neighbours); 4526 GNUNET_CONTAINER_multihashmap_destroy (neighbours);
4601 neighbours = NULL; 4527 neighbours = NULL;
4602 GNUNET_STATISTICS_set (stats, gettext_noop ("# neighbour entries allocated"), 4528 GNUNET_STATISTICS_set (stats, gettext_noop ("# neighbour entries allocated"),
@@ -4624,8 +4550,7 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
4624 * @param c configuration to use 4550 * @param c configuration to use
4625 */ 4551 */
4626static void 4552static void
4627run (void *cls, 4553run (void *cls, struct GNUNET_SERVER_Handle *server,
4628 struct GNUNET_SERVER_Handle *server,
4629 const struct GNUNET_CONFIGURATION_Handle *c) 4554 const struct GNUNET_CONFIGURATION_Handle *c)
4630{ 4555{
4631 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 4556 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
@@ -4656,19 +4581,14 @@ run (void *cls,
4656 cfg = c; 4581 cfg = c;
4657 /* parse configuration */ 4582 /* parse configuration */
4658 if ((GNUNET_OK != 4583 if ((GNUNET_OK !=
4659 GNUNET_CONFIGURATION_get_value_number (c, 4584 GNUNET_CONFIGURATION_get_value_number (c, "CORE", "TOTAL_QUOTA_IN",
4660 "CORE",
4661 "TOTAL_QUOTA_IN",
4662 &bandwidth_target_in_bps)) || 4585 &bandwidth_target_in_bps)) ||
4663 (GNUNET_OK != 4586 (GNUNET_OK !=
4664 GNUNET_CONFIGURATION_get_value_number (c, 4587 GNUNET_CONFIGURATION_get_value_number (c, "CORE", "TOTAL_QUOTA_OUT",
4665 "CORE",
4666 "TOTAL_QUOTA_OUT",
4667 &bandwidth_target_out_bps)) || 4588 &bandwidth_target_out_bps)) ||
4668 (GNUNET_OK != 4589 (GNUNET_OK !=
4669 GNUNET_CONFIGURATION_get_value_filename (c, 4590 GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY",
4670 "GNUNETD", 4591 &keyfile)))
4671 "HOSTKEY", &keyfile)))
4672 { 4592 {
4673 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 4593 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
4674 _ 4594 _
@@ -4697,29 +4617,27 @@ run (void *cls,
4697 } 4617 }
4698 neighbours = GNUNET_CONTAINER_multihashmap_create (128); 4618 neighbours = GNUNET_CONTAINER_multihashmap_create (128);
4699 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); 4619 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
4700 GNUNET_CRYPTO_hash (&my_public_key, 4620 GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key),
4701 sizeof (my_public_key), &my_identity.hashPubKey); 4621 &my_identity.hashPubKey);
4702 self.public_key = &my_public_key; 4622 self.public_key = &my_public_key;
4703 self.peer = my_identity; 4623 self.peer = my_identity;
4704 self.last_activity = GNUNET_TIME_UNIT_FOREVER_ABS; 4624 self.last_activity = GNUNET_TIME_UNIT_FOREVER_ABS;
4705 self.status = PEER_STATE_KEY_CONFIRMED; 4625 self.status = PEER_STATE_KEY_CONFIRMED;
4706 self.is_connected = GNUNET_YES; 4626 self.is_connected = GNUNET_YES;
4707 /* setup notification */ 4627 /* setup notification */
4708 notifier = GNUNET_SERVER_notification_context_create (server, 4628 notifier =
4709 MAX_NOTIFY_QUEUE); 4629 GNUNET_SERVER_notification_context_create (server, MAX_NOTIFY_QUEUE);
4710 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); 4630 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
4711 /* setup transport connection */ 4631 /* setup transport connection */
4712 transport = GNUNET_TRANSPORT_connect (cfg, 4632 transport =
4713 &my_identity, 4633 GNUNET_TRANSPORT_connect (cfg, &my_identity, NULL,
4714 NULL, 4634 &handle_transport_receive,
4715 &handle_transport_receive, 4635 &handle_transport_notify_connect,
4716 &handle_transport_notify_connect, 4636 &handle_transport_notify_disconnect);
4717 &handle_transport_notify_disconnect);
4718 GNUNET_assert (NULL != transport); 4637 GNUNET_assert (NULL != transport);
4719 stats = GNUNET_STATISTICS_create ("core", cfg); 4638 stats = GNUNET_STATISTICS_create ("core", cfg);
4720 4639
4721 GNUNET_STATISTICS_set (stats, 4640 GNUNET_STATISTICS_set (stats, gettext_noop ("# discarded CORE_SEND requests"),
4722 gettext_noop ("# discarded CORE_SEND requests"),
4723 0, GNUNET_NO); 4641 0, GNUNET_NO);
4724 GNUNET_STATISTICS_set (stats, 4642 GNUNET_STATISTICS_set (stats,
4725 gettext_noop 4643 gettext_noop
@@ -4727,12 +4645,12 @@ run (void *cls,
4727 GNUNET_NO); 4645 GNUNET_NO);
4728 4646
4729 mst = GNUNET_SERVER_mst_create (&deliver_message, NULL); 4647 mst = GNUNET_SERVER_mst_create (&deliver_message, NULL);
4730 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 4648 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task,
4731 &cleaning_task, NULL); 4649 NULL);
4732 /* process client requests */ 4650 /* process client requests */
4733 GNUNET_SERVER_add_handlers (server, handlers); 4651 GNUNET_SERVER_add_handlers (server, handlers);
4734 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 4652 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Core service of `%4s' ready.\n"),
4735 _("Core service of `%4s' ready.\n"), GNUNET_i2s (&my_identity)); 4653 GNUNET_i2s (&my_identity));
4736} 4654}
4737 4655
4738 4656
@@ -4748,10 +4666,8 @@ int
4748main (int argc, char *const *argv) 4666main (int argc, char *const *argv)
4749{ 4667{
4750 return (GNUNET_OK == 4668 return (GNUNET_OK ==
4751 GNUNET_SERVICE_run (argc, 4669 GNUNET_SERVICE_run (argc, argv, "core", GNUNET_SERVICE_OPTION_NONE,
4752 argv, 4670 &run, NULL)) ? 0 : 1;
4753 "core",
4754 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
4755} 4671}
4756 4672
4757/* end of gnunet-service-core.c */ 4673/* end of gnunet-service-core.c */