diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-01-19 14:20:54 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-01-19 14:20:54 +0000 |
commit | b6dbf7e98bb79907562bf67d423b67a030b503e7 (patch) | |
tree | 4a63aa64d332add505dd167289630c4c5a385233 | |
parent | fff6dc1db59348e426b4c6cc5a5729080d93a163 (diff) | |
download | gnunet-b6dbf7e98bb79907562bf67d423b67a030b503e7.tar.gz gnunet-b6dbf7e98bb79907562bf67d423b67a030b503e7.zip |
pre-commit
-rw-r--r-- | src/transport/gnunet-service-transport.c | 434 | ||||
-rw-r--r-- | src/transport/plugin_transport.h | 46 | ||||
-rw-r--r-- | src/transport/plugin_transport_http.c | 17 | ||||
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 359 | ||||
-rw-r--r-- | src/transport/plugin_transport_template.c | 15 | ||||
-rw-r--r-- | src/transport/plugin_transport_udp.c | 348 | ||||
-rw-r--r-- | src/transport/test_plugin_transport.c | 146 | ||||
-rw-r--r-- | src/transport/test_plugin_transport_udp.c | 107 | ||||
-rw-r--r-- | src/transport/test_transport_api.c | 27 | ||||
-rw-r--r-- | src/transport/transport_api.c | 289 | ||||
-rw-r--r-- | src/transport/transport_api_address_lookup.c | 188 |
11 files changed, 965 insertions, 1011 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 6b8e0e7dd..acdac052c 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -223,7 +223,7 @@ struct MessageQueue | |||
223 | * How important is the message? | 223 | * How important is the message? |
224 | */ | 224 | */ |
225 | unsigned int priority; | 225 | unsigned int priority; |
226 | 226 | ||
227 | }; | 227 | }; |
228 | 228 | ||
229 | 229 | ||
@@ -672,7 +672,7 @@ transmit_to_client_callback (void *cls, size_t size, void *buf) | |||
672 | if (buf == NULL) | 672 | if (buf == NULL) |
673 | { | 673 | { |
674 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 674 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
675 | "Transmission to client failed, closing connection.\n"); | 675 | "Transmission to client failed, closing connection.\n"); |
676 | /* fatal error with client, free message queue! */ | 676 | /* fatal error with client, free message queue! */ |
677 | while (NULL != (q = client->message_queue_head)) | 677 | while (NULL != (q = client->message_queue_head)) |
678 | { | 678 | { |
@@ -693,8 +693,8 @@ transmit_to_client_callback (void *cls, size_t size, void *buf) | |||
693 | break; | 693 | break; |
694 | #if DEBUG_TRANSPORT | 694 | #if DEBUG_TRANSPORT |
695 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 695 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
696 | "Transmitting message of type %u to client.\n", | 696 | "Transmitting message of type %u to client.\n", |
697 | ntohs (msg->type)); | 697 | ntohs (msg->type)); |
698 | #endif | 698 | #endif |
699 | client->message_queue_head = q->next; | 699 | client->message_queue_head = q->next; |
700 | if (q->next == NULL) | 700 | if (q->next == NULL) |
@@ -815,9 +815,7 @@ try_alternative_plugins (struct NeighbourList *neighbour) | |||
815 | * disconnected or must we ask all plugins to | 815 | * disconnected or must we ask all plugins to |
816 | * disconnect? | 816 | * disconnect? |
817 | */ | 817 | */ |
818 | static void | 818 | static void disconnect_neighbour (struct NeighbourList *n, int check); |
819 | disconnect_neighbour (struct NeighbourList *n, | ||
820 | int check); | ||
821 | 819 | ||
822 | 820 | ||
823 | /** | 821 | /** |
@@ -827,8 +825,7 @@ disconnect_neighbour (struct NeighbourList *n, | |||
827 | * | 825 | * |
828 | * @param neighbour target peer for which to check the plugins | 826 | * @param neighbour target peer for which to check the plugins |
829 | */ | 827 | */ |
830 | static void | 828 | static void try_transmission_to_peer (struct NeighbourList *neighbour); |
831 | try_transmission_to_peer (struct NeighbourList *neighbour); | ||
832 | 829 | ||
833 | 830 | ||
834 | /** | 831 | /** |
@@ -867,13 +864,15 @@ transmit_send_continuation (void *cls, | |||
867 | GNUNET_assert (rl != NULL); | 864 | GNUNET_assert (rl != NULL); |
868 | if (result == GNUNET_OK) | 865 | if (result == GNUNET_OK) |
869 | { | 866 | { |
870 | rl->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 867 | rl->timeout = |
868 | GNUNET_TIME_relative_to_absolute | ||
869 | (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | ||
871 | } | 870 | } |
872 | else | 871 | else |
873 | { | 872 | { |
874 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 873 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
875 | "Transmission to peer `%s' failed, marking connection as down.\n", | 874 | "Transmission to peer `%s' failed, marking connection as down.\n", |
876 | GNUNET_i2s(target)); | 875 | GNUNET_i2s (target)); |
877 | rl->connected = GNUNET_NO; | 876 | rl->connected = GNUNET_NO; |
878 | } | 877 | } |
879 | if (!mq->internal_msg) | 878 | if (!mq->internal_msg) |
@@ -881,9 +880,8 @@ transmit_send_continuation (void *cls, | |||
881 | if (mq->client != NULL) | 880 | if (mq->client != NULL) |
882 | { | 881 | { |
883 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 882 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
884 | "Notifying client %p about failed transission to peer `%4s'.\n", | 883 | "Notifying client %p about failed transission to peer `%4s'.\n", |
885 | mq->client, | 884 | mq->client, GNUNET_i2s (target)); |
886 | GNUNET_i2s(target)); | ||
887 | send_ok_msg.header.size = htons (sizeof (send_ok_msg)); | 885 | send_ok_msg.header.size = htons (sizeof (send_ok_msg)); |
888 | send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); | 886 | send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); |
889 | send_ok_msg.success = htonl (result); | 887 | send_ok_msg.success = htonl (result); |
@@ -896,8 +894,8 @@ transmit_send_continuation (void *cls, | |||
896 | another message (if available) */ | 894 | another message (if available) */ |
897 | if (result == GNUNET_OK) | 895 | if (result == GNUNET_OK) |
898 | try_transmission_to_peer (n); | 896 | try_transmission_to_peer (n); |
899 | else | 897 | else |
900 | disconnect_neighbour (n, GNUNET_YES); | 898 | disconnect_neighbour (n, GNUNET_YES); |
901 | } | 899 | } |
902 | 900 | ||
903 | 901 | ||
@@ -958,9 +956,9 @@ try_transmission_to_peer (struct NeighbourList *neighbour) | |||
958 | rl->connect_attempts++; | 956 | rl->connect_attempts++; |
959 | rl->connected = GNUNET_YES; | 957 | rl->connected = GNUNET_YES; |
960 | #if DEBUG_TRANSPORT | 958 | #if DEBUG_TRANSPORT |
961 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 959 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
962 | "Establishing fresh connection with `%4s' via plugin `%s'\n", | 960 | "Establishing fresh connection with `%4s' via plugin `%s'\n", |
963 | GNUNET_i2s (&neighbour->id), rl->plugin->short_name); | 961 | GNUNET_i2s (&neighbour->id), rl->plugin->short_name); |
964 | #endif | 962 | #endif |
965 | } | 963 | } |
966 | neighbour->messages = mq->next; | 964 | neighbour->messages = mq->next; |
@@ -974,11 +972,11 @@ try_transmission_to_peer (struct NeighbourList *neighbour) | |||
974 | GNUNET_i2s (&neighbour->id), rl->plugin->short_name); | 972 | GNUNET_i2s (&neighbour->id), rl->plugin->short_name); |
975 | #endif | 973 | #endif |
976 | rl->plugin->api->send (rl->plugin->api->cls, | 974 | rl->plugin->api->send (rl->plugin->api->cls, |
977 | &neighbour->id, | 975 | &neighbour->id, |
978 | mq->priority, | 976 | mq->priority, |
979 | mq->message, | 977 | mq->message, |
980 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 978 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
981 | &transmit_send_continuation, mq); | 979 | &transmit_send_continuation, mq); |
982 | } | 980 | } |
983 | 981 | ||
984 | 982 | ||
@@ -993,7 +991,7 @@ try_transmission_to_peer (struct NeighbourList *neighbour) | |||
993 | */ | 991 | */ |
994 | static void | 992 | static void |
995 | transmit_to_peer (struct TransportClient *client, | 993 | transmit_to_peer (struct TransportClient *client, |
996 | unsigned int priority, | 994 | unsigned int priority, |
997 | const struct GNUNET_MessageHeader *msg, | 995 | const struct GNUNET_MessageHeader *msg, |
998 | int is_internal, struct NeighbourList *neighbour) | 996 | int is_internal, struct NeighbourList *neighbour) |
999 | { | 997 | { |
@@ -1100,8 +1098,7 @@ refresh_hello () | |||
1100 | 1098 | ||
1101 | #if DEBUG_TRANSPORT | 1099 | #if DEBUG_TRANSPORT |
1102 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 1100 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
1103 | "Refreshing my `%s'\n", | 1101 | "Refreshing my `%s'\n", "HELLO"); |
1104 | "HELLO"); | ||
1105 | #endif | 1102 | #endif |
1106 | gc.plug_pos = plugins; | 1103 | gc.plug_pos = plugins; |
1107 | gc.addr_pos = plugins != NULL ? plugins->addresses : NULL; | 1104 | gc.addr_pos = plugins != NULL ? plugins->addresses : NULL; |
@@ -1125,9 +1122,8 @@ refresh_hello () | |||
1125 | { | 1122 | { |
1126 | #if DEBUG_TRANSPORT | 1123 | #if DEBUG_TRANSPORT |
1127 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 1124 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
1128 | "Transmitting updated `%s' to neighbour `%4s'\n", | 1125 | "Transmitting updated `%s' to neighbour `%4s'\n", |
1129 | "HELLO", | 1126 | "HELLO", GNUNET_i2s (&npos->id)); |
1130 | GNUNET_i2s(&npos->id)); | ||
1131 | #endif | 1127 | #endif |
1132 | transmit_to_peer (NULL, 0, | 1128 | transmit_to_peer (NULL, 0, |
1133 | (const struct GNUNET_MessageHeader *) our_hello, | 1129 | (const struct GNUNET_MessageHeader *) our_hello, |
@@ -1264,7 +1260,7 @@ plugin_env_notify_address (void *cls, | |||
1264 | #if DEBUG_TRANSPORT | 1260 | #if DEBUG_TRANSPORT |
1265 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1261 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1266 | "Plugin `%s' informs us about a new address `%s'\n", name, | 1262 | "Plugin `%s' informs us about a new address `%s'\n", name, |
1267 | GNUNET_a2s(addr, addrlen)); | 1263 | GNUNET_a2s (addr, addrlen)); |
1268 | #endif | 1264 | #endif |
1269 | al = GNUNET_malloc (sizeof (struct AddressList) + addrlen); | 1265 | al = GNUNET_malloc (sizeof (struct AddressList) + addrlen); |
1270 | al->addr = &al[1]; | 1266 | al->addr = &al[1]; |
@@ -1294,7 +1290,7 @@ notify_clients_connect (const struct GNUNET_PeerIdentity *peer, | |||
1294 | #endif | 1290 | #endif |
1295 | cim.header.size = htons (sizeof (struct ConnectInfoMessage)); | 1291 | cim.header.size = htons (sizeof (struct ConnectInfoMessage)); |
1296 | cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); | 1292 | cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); |
1297 | cim.quota_out = htonl (GNUNET_CONSTANTS_DEFAULT_BPM_IN_OUT / (60*1000)); | 1293 | cim.quota_out = htonl (GNUNET_CONSTANTS_DEFAULT_BPM_IN_OUT / (60 * 1000)); |
1298 | cim.latency = GNUNET_TIME_relative_hton (latency); | 1294 | cim.latency = GNUNET_TIME_relative_hton (latency); |
1299 | memcpy (&cim.id, peer, sizeof (struct GNUNET_PeerIdentity)); | 1295 | memcpy (&cim.id, peer, sizeof (struct GNUNET_PeerIdentity)); |
1300 | cpos = clients; | 1296 | cpos = clients; |
@@ -1400,9 +1396,9 @@ cleanup_validation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1400 | "HELLO", GNUNET_i2s (&pid)); | 1396 | "HELLO", GNUNET_i2s (&pid)); |
1401 | #endif | 1397 | #endif |
1402 | GNUNET_PEERINFO_add_peer (cfg, sched, &pid, hello); | 1398 | GNUNET_PEERINFO_add_peer (cfg, sched, &pid, hello); |
1403 | n = find_neighbour (&pid); | 1399 | n = find_neighbour (&pid); |
1404 | if (NULL != n) | 1400 | if (NULL != n) |
1405 | try_transmission_to_peer (n); | 1401 | try_transmission_to_peer (n); |
1406 | GNUNET_free (hello); | 1402 | GNUNET_free (hello); |
1407 | while (NULL != (va = pos->addresses)) | 1403 | while (NULL != (va = pos->addresses)) |
1408 | { | 1404 | { |
@@ -1416,7 +1412,7 @@ cleanup_validation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1416 | else | 1412 | else |
1417 | pos = prev->next; | 1413 | pos = prev->next; |
1418 | continue; | 1414 | continue; |
1419 | } | 1415 | } |
1420 | prev = pos; | 1416 | prev = pos; |
1421 | pos = pos->next; | 1417 | pos = pos->next; |
1422 | } | 1418 | } |
@@ -1427,14 +1423,14 @@ cleanup_validation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1427 | { | 1423 | { |
1428 | first = pending_validations->timeout; | 1424 | first = pending_validations->timeout; |
1429 | pos = pending_validations; | 1425 | pos = pending_validations; |
1430 | while (pos != NULL) | 1426 | while (pos != NULL) |
1431 | { | 1427 | { |
1432 | first = GNUNET_TIME_absolute_min (first, pos->timeout); | 1428 | first = GNUNET_TIME_absolute_min (first, pos->timeout); |
1433 | pos = pos->next; | 1429 | pos = pos->next; |
1434 | } | 1430 | } |
1435 | GNUNET_SCHEDULER_add_delayed (sched, | 1431 | GNUNET_SCHEDULER_add_delayed (sched, |
1436 | GNUNET_TIME_absolute_get_remaining (first), | 1432 | GNUNET_TIME_absolute_get_remaining |
1437 | &cleanup_validation, NULL); | 1433 | (first), &cleanup_validation, NULL); |
1438 | } | 1434 | } |
1439 | } | 1435 | } |
1440 | 1436 | ||
@@ -1458,10 +1454,9 @@ cleanup_validation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1458 | */ | 1454 | */ |
1459 | static void | 1455 | static void |
1460 | plugin_env_notify_validation (void *cls, | 1456 | plugin_env_notify_validation (void *cls, |
1461 | const char *name, | 1457 | const char *name, |
1462 | const struct GNUNET_PeerIdentity *peer, | 1458 | const struct GNUNET_PeerIdentity *peer, |
1463 | uint32_t challenge, | 1459 | uint32_t challenge, const char *sender_addr) |
1464 | const char *sender_addr) | ||
1465 | { | 1460 | { |
1466 | unsigned int not_done; | 1461 | unsigned int not_done; |
1467 | int matched; | 1462 | int matched; |
@@ -1476,8 +1471,7 @@ plugin_env_notify_validation (void *cls, | |||
1476 | sizeof (struct | 1471 | sizeof (struct |
1477 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 1472 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
1478 | &id.hashPubKey); | 1473 | &id.hashPubKey); |
1479 | if (0 == | 1474 | if (0 == memcmp (peer, &id, sizeof (struct GNUNET_PeerIdentity))) |
1480 | memcmp (peer, &id, sizeof (struct GNUNET_PeerIdentity))) | ||
1481 | break; | 1475 | break; |
1482 | pos = pos->next; | 1476 | pos = pos->next; |
1483 | } | 1477 | } |
@@ -1487,7 +1481,7 @@ plugin_env_notify_validation (void *cls, | |||
1487 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1481 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1488 | _ | 1482 | _ |
1489 | ("Received validation response but have no record of any validation request for `%4s'. Ignoring.\n"), | 1483 | ("Received validation response but have no record of any validation request for `%4s'. Ignoring.\n"), |
1490 | GNUNET_i2s(peer)); | 1484 | GNUNET_i2s (peer)); |
1491 | return; | 1485 | return; |
1492 | } | 1486 | } |
1493 | not_done = 0; | 1487 | not_done = 0; |
@@ -1496,23 +1490,23 @@ plugin_env_notify_validation (void *cls, | |||
1496 | while (va != NULL) | 1490 | while (va != NULL) |
1497 | { | 1491 | { |
1498 | if (va->challenge == challenge) | 1492 | if (va->challenge == challenge) |
1499 | { | 1493 | { |
1500 | #if DEBUG_TRANSPORT | 1494 | #if DEBUG_TRANSPORT |
1501 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1495 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1502 | "Confirmed validity of address, peer `%4s' has address `%s'.\n", | 1496 | "Confirmed validity of address, peer `%4s' has address `%s'.\n", |
1503 | GNUNET_i2s (peer), | 1497 | GNUNET_i2s (peer), |
1504 | GNUNET_a2s ((const struct sockaddr*) &va[1], | 1498 | GNUNET_a2s ((const struct sockaddr *) &va[1], |
1505 | va->addr_len)); | 1499 | va->addr_len)); |
1506 | #endif | 1500 | #endif |
1507 | GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, | 1501 | GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, |
1508 | _("Another peer saw us using the address `%s' via `%s'. If this is not plausible, this address should be listed in the configuration as implausible to avoid MiM attacks.\n"), | 1502 | _ |
1509 | sender_addr, | 1503 | ("Another peer saw us using the address `%s' via `%s'. If this is not plausible, this address should be listed in the configuration as implausible to avoid MiM attacks.\n"), |
1510 | name); | 1504 | sender_addr, name); |
1511 | va->ok = GNUNET_YES; | 1505 | va->ok = GNUNET_YES; |
1512 | va->expiration = | 1506 | va->expiration = |
1513 | GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION); | 1507 | GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION); |
1514 | matched = GNUNET_YES; | 1508 | matched = GNUNET_YES; |
1515 | } | 1509 | } |
1516 | if (va->ok != GNUNET_YES) | 1510 | if (va->ok != GNUNET_YES) |
1517 | not_done++; | 1511 | not_done++; |
1518 | va = va->next; | 1512 | va = va->next; |
@@ -1529,24 +1523,20 @@ plugin_env_notify_validation (void *cls, | |||
1529 | { | 1523 | { |
1530 | #if DEBUG_TRANSPORT | 1524 | #if DEBUG_TRANSPORT |
1531 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1525 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1532 | "All addresses validated, will now construct `%s' for `%4s'.\n", | 1526 | "All addresses validated, will now construct `%s' for `%4s'.\n", |
1533 | "HELLO", | 1527 | "HELLO", GNUNET_i2s (peer)); |
1534 | GNUNET_i2s (peer)); | ||
1535 | #endif | 1528 | #endif |
1536 | pos->timeout.value = 0; | 1529 | pos->timeout.value = 0; |
1537 | GNUNET_SCHEDULER_add_with_priority (sched, | 1530 | GNUNET_SCHEDULER_add_with_priority (sched, |
1538 | GNUNET_SCHEDULER_PRIORITY_IDLE, | 1531 | GNUNET_SCHEDULER_PRIORITY_IDLE, |
1539 | &cleanup_validation, NULL); | 1532 | &cleanup_validation, NULL); |
1540 | } | 1533 | } |
1541 | else | 1534 | else |
1542 | { | 1535 | { |
1543 | #if DEBUG_TRANSPORT | 1536 | #if DEBUG_TRANSPORT |
1544 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1537 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1545 | "Still waiting for %u additional `%s' messages before constructing `%s' for `%4s'.\n", | 1538 | "Still waiting for %u additional `%s' messages before constructing `%s' for `%4s'.\n", |
1546 | not_done, | 1539 | not_done, "PONG", "HELLO", GNUNET_i2s (peer)); |
1547 | "PONG", | ||
1548 | "HELLO", | ||
1549 | GNUNET_i2s (peer)); | ||
1550 | #endif | 1540 | #endif |
1551 | } | 1541 | } |
1552 | } | 1542 | } |
@@ -1604,14 +1594,12 @@ run_validation (void *cls, | |||
1604 | return GNUNET_OK; | 1594 | return GNUNET_OK; |
1605 | } | 1595 | } |
1606 | GNUNET_CRYPTO_hash (&e->publicKey, | 1596 | GNUNET_CRYPTO_hash (&e->publicKey, |
1607 | sizeof (struct | 1597 | sizeof (struct |
1608 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 1598 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
1609 | &id.hashPubKey); | 1599 | &id.hashPubKey); |
1610 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1600 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1611 | "Scheduling validation of address `%s' via `%s' for `%4s'\n", | 1601 | "Scheduling validation of address `%s' via `%s' for `%4s'\n", |
1612 | GNUNET_a2s(addr, addrlen), | 1602 | GNUNET_a2s (addr, addrlen), tname, GNUNET_i2s (&id)); |
1613 | tname, | ||
1614 | GNUNET_i2s(&id)); | ||
1615 | 1603 | ||
1616 | va = GNUNET_malloc (sizeof (struct ValidationAddress) + addrlen); | 1604 | va = GNUNET_malloc (sizeof (struct ValidationAddress) + addrlen); |
1617 | va->next = e->addresses; | 1605 | va->next = e->addresses; |
@@ -1619,7 +1607,7 @@ run_validation (void *cls, | |||
1619 | va->transport_name = GNUNET_strdup (tname); | 1607 | va->transport_name = GNUNET_strdup (tname); |
1620 | va->addr_len = addrlen; | 1608 | va->addr_len = addrlen; |
1621 | va->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 1609 | va->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
1622 | (unsigned int) -1); | 1610 | (unsigned int) -1); |
1623 | memcpy (&va[1], addr, addrlen); | 1611 | memcpy (&va[1], addr, addrlen); |
1624 | return GNUNET_OK; | 1612 | return GNUNET_OK; |
1625 | } | 1613 | } |
@@ -1633,8 +1621,7 @@ run_validation (void *cls, | |||
1633 | static void | 1621 | static void |
1634 | check_hello_validated (void *cls, | 1622 | check_hello_validated (void *cls, |
1635 | const struct GNUNET_PeerIdentity *peer, | 1623 | const struct GNUNET_PeerIdentity *peer, |
1636 | const struct GNUNET_HELLO_Message *h, | 1624 | const struct GNUNET_HELLO_Message *h, uint32_t trust) |
1637 | uint32_t trust) | ||
1638 | { | 1625 | { |
1639 | struct CheckHelloValidatedContext *chvc = cls; | 1626 | struct CheckHelloValidatedContext *chvc = cls; |
1640 | struct ValidationAddress *va; | 1627 | struct ValidationAddress *va; |
@@ -1672,13 +1659,11 @@ check_hello_validated (void *cls, | |||
1672 | if (h != NULL) | 1659 | if (h != NULL) |
1673 | return; /* wait for next call */ | 1660 | return; /* wait for next call */ |
1674 | /* finally, transmit validation attempts */ | 1661 | /* finally, transmit validation attempts */ |
1675 | GNUNET_assert (GNUNET_OK == | 1662 | GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_id (chvc->hello, &apeer)); |
1676 | GNUNET_HELLO_get_id (chvc->hello, | ||
1677 | &apeer)); | ||
1678 | #if DEBUG_TRANSPORT | 1663 | #if DEBUG_TRANSPORT |
1679 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1664 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1680 | "Ready to validate addresses from `%s' message for peer `%4s'\n", | 1665 | "Ready to validate addresses from `%s' message for peer `%4s'\n", |
1681 | "HELLO", GNUNET_i2s (&apeer)); | 1666 | "HELLO", GNUNET_i2s (&apeer)); |
1682 | #endif | 1667 | #endif |
1683 | va = chvc->e->addresses; | 1668 | va = chvc->e->addresses; |
1684 | while (va != NULL) | 1669 | while (va != NULL) |
@@ -1688,25 +1673,24 @@ check_hello_validated (void *cls, | |||
1688 | "Establishing `%s' connection to validate `%s' address `%s' of `%4s'\n", | 1673 | "Establishing `%s' connection to validate `%s' address `%s' of `%4s'\n", |
1689 | va->transport_name, | 1674 | va->transport_name, |
1690 | "HELLO", | 1675 | "HELLO", |
1691 | GNUNET_a2s ((const struct sockaddr*) &va[1], | 1676 | GNUNET_a2s ((const struct sockaddr *) &va[1], |
1692 | va->addr_len), | 1677 | va->addr_len), GNUNET_i2s (&apeer)); |
1693 | GNUNET_i2s (&apeer)); | ||
1694 | #endif | 1678 | #endif |
1695 | tp = find_transport (va->transport_name); | 1679 | tp = find_transport (va->transport_name); |
1696 | GNUNET_assert (tp != NULL); | 1680 | GNUNET_assert (tp != NULL); |
1697 | if (GNUNET_OK != | 1681 | if (GNUNET_OK != |
1698 | tp->api->validate (tp->api->cls, | 1682 | tp->api->validate (tp->api->cls, |
1699 | &apeer, | 1683 | &apeer, |
1700 | va->challenge, | 1684 | va->challenge, |
1701 | HELLO_VERIFICATION_TIMEOUT, | 1685 | HELLO_VERIFICATION_TIMEOUT, |
1702 | &va[1], | 1686 | &va[1], va->addr_len)) |
1703 | va->addr_len)) | ||
1704 | va->ok = GNUNET_SYSERR; | 1687 | va->ok = GNUNET_SYSERR; |
1705 | va = va->next; | 1688 | va = va->next; |
1706 | } | 1689 | } |
1707 | GNUNET_SCHEDULER_add_delayed (sched, | 1690 | GNUNET_SCHEDULER_add_delayed (sched, |
1708 | GNUNET_TIME_absolute_get_remaining (chvc->e->timeout), | 1691 | GNUNET_TIME_absolute_get_remaining (chvc->e-> |
1709 | &cleanup_validation, NULL); | 1692 | timeout), |
1693 | &cleanup_validation, NULL); | ||
1710 | GNUNET_free (chvc); | 1694 | GNUNET_free (chvc); |
1711 | } | 1695 | } |
1712 | 1696 | ||
@@ -1767,10 +1751,10 @@ process_hello (struct TransportPlugin *plugin, | |||
1767 | { | 1751 | { |
1768 | /* TODO: call to stats? */ | 1752 | /* TODO: call to stats? */ |
1769 | #if DEBUG_TRANSPORT | 1753 | #if DEBUG_TRANSPORT |
1770 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1754 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1771 | "`%s' message for peer `%4s' is already pending; ignoring new message\n", | 1755 | "`%s' message for peer `%4s' is already pending; ignoring new message\n", |
1772 | "HELLO", GNUNET_i2s (&target)); | 1756 | "HELLO", GNUNET_i2s (&target)); |
1773 | #endif | 1757 | #endif |
1774 | return GNUNET_OK; | 1758 | return GNUNET_OK; |
1775 | } | 1759 | } |
1776 | e = e->next; | 1760 | e = e->next; |
@@ -1782,11 +1766,11 @@ process_hello (struct TransportPlugin *plugin, | |||
1782 | /* finally, check if HELLO was previously validated | 1766 | /* finally, check if HELLO was previously validated |
1783 | (continuation will then schedule actual validation) */ | 1767 | (continuation will then schedule actual validation) */ |
1784 | chvc->piter = GNUNET_PEERINFO_iterate (cfg, | 1768 | chvc->piter = GNUNET_PEERINFO_iterate (cfg, |
1785 | sched, | 1769 | sched, |
1786 | &target, | 1770 | &target, |
1787 | 0, | 1771 | 0, |
1788 | HELLO_VERIFICATION_TIMEOUT, | 1772 | HELLO_VERIFICATION_TIMEOUT, |
1789 | &check_hello_validated, chvc); | 1773 | &check_hello_validated, chvc); |
1790 | return GNUNET_OK; | 1774 | return GNUNET_OK; |
1791 | } | 1775 | } |
1792 | 1776 | ||
@@ -1805,29 +1789,27 @@ process_hello (struct TransportPlugin *plugin, | |||
1805 | * disconnect? | 1789 | * disconnect? |
1806 | */ | 1790 | */ |
1807 | static void | 1791 | static void |
1808 | disconnect_neighbour (struct NeighbourList *n, | 1792 | disconnect_neighbour (struct NeighbourList *n, int check) |
1809 | int check) | ||
1810 | { | 1793 | { |
1811 | struct ReadyList *rpos; | 1794 | struct ReadyList *rpos; |
1812 | struct NeighbourList *npos; | 1795 | struct NeighbourList *npos; |
1813 | struct NeighbourList *nprev; | 1796 | struct NeighbourList *nprev; |
1814 | struct MessageQueue *mq; | 1797 | struct MessageQueue *mq; |
1815 | 1798 | ||
1816 | if (GNUNET_YES == check) | 1799 | if (GNUNET_YES == check) |
1817 | { | 1800 | { |
1818 | rpos = n->plugins; | 1801 | rpos = n->plugins; |
1819 | while (NULL != rpos) | 1802 | while (NULL != rpos) |
1820 | { | 1803 | { |
1821 | if (GNUNET_YES == rpos->connected) | 1804 | if (GNUNET_YES == rpos->connected) |
1822 | return; /* still connected */ | 1805 | return; /* still connected */ |
1823 | rpos = rpos->next; | 1806 | rpos = rpos->next; |
1824 | } | 1807 | } |
1825 | } | 1808 | } |
1826 | 1809 | ||
1827 | #if DEBUG_TRANSPORT | 1810 | #if DEBUG_TRANSPORT |
1828 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 1811 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
1829 | "Disconnecting from `%4s'\n", | 1812 | "Disconnecting from `%4s'\n", GNUNET_i2s (&n->id)); |
1830 | GNUNET_i2s(&n->id)); | ||
1831 | #endif | 1813 | #endif |
1832 | /* remove n from neighbours list */ | 1814 | /* remove n from neighbours list */ |
1833 | nprev = NULL; | 1815 | nprev = NULL; |
@@ -1852,8 +1834,7 @@ disconnect_neighbour (struct NeighbourList *n, | |||
1852 | n->plugins = rpos->next; | 1834 | n->plugins = rpos->next; |
1853 | GNUNET_assert (rpos->neighbour == n); | 1835 | GNUNET_assert (rpos->neighbour == n); |
1854 | if (GNUNET_YES == rpos->connected) | 1836 | if (GNUNET_YES == rpos->connected) |
1855 | rpos->plugin->api->disconnect (rpos->plugin->api->cls, | 1837 | rpos->plugin->api->disconnect (rpos->plugin->api->cls, &n->id); |
1856 | &n->id); | ||
1857 | GNUNET_free (rpos); | 1838 | GNUNET_free (rpos); |
1858 | } | 1839 | } |
1859 | 1840 | ||
@@ -1865,8 +1846,7 @@ disconnect_neighbour (struct NeighbourList *n, | |||
1865 | GNUNET_free (mq); | 1846 | GNUNET_free (mq); |
1866 | } | 1847 | } |
1867 | if (n->timeout_task != GNUNET_SCHEDULER_NO_TASK) | 1848 | if (n->timeout_task != GNUNET_SCHEDULER_NO_TASK) |
1868 | GNUNET_SCHEDULER_cancel (sched, | 1849 | GNUNET_SCHEDULER_cancel (sched, n->timeout_task); |
1869 | n->timeout_task); | ||
1870 | /* finally, free n itself */ | 1850 | /* finally, free n itself */ |
1871 | GNUNET_free (n); | 1851 | GNUNET_free (n); |
1872 | } | 1852 | } |
@@ -1912,8 +1892,7 @@ neighbour_timeout_task (void *cls, | |||
1912 | 1892 | ||
1913 | #if DEBUG_TRANSPORT | 1893 | #if DEBUG_TRANSPORT |
1914 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 1894 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
1915 | "Neighbour `%4s' has timed out!\n", | 1895 | "Neighbour `%4s' has timed out!\n", GNUNET_i2s (&n->id)); |
1916 | GNUNET_i2s(&n->id)); | ||
1917 | #endif | 1896 | #endif |
1918 | n->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 1897 | n->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
1919 | disconnect_neighbour (n, GNUNET_NO); | 1898 | disconnect_neighbour (n, GNUNET_NO); |
@@ -1945,7 +1924,8 @@ setup_new_neighbour (const struct GNUNET_PeerIdentity *peer) | |||
1945 | n->id = *peer; | 1924 | n->id = *peer; |
1946 | n->last_quota_update = GNUNET_TIME_absolute_get (); | 1925 | n->last_quota_update = GNUNET_TIME_absolute_get (); |
1947 | n->peer_timeout = | 1926 | n->peer_timeout = |
1948 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 1927 | GNUNET_TIME_relative_to_absolute |
1928 | (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | ||
1949 | n->quota_in = (GNUNET_CONSTANTS_DEFAULT_BPM_IN_OUT + 59999) / (60 * 1000); | 1929 | n->quota_in = (GNUNET_CONSTANTS_DEFAULT_BPM_IN_OUT + 59999) / (60 * 1000); |
1950 | add_plugins (n); | 1930 | add_plugins (n); |
1951 | n->timeout_task = GNUNET_SCHEDULER_add_delayed (sched, | 1931 | n->timeout_task = GNUNET_SCHEDULER_add_delayed (sched, |
@@ -1995,25 +1975,23 @@ plugin_env_receive (void *cls, | |||
1995 | if (n == NULL) | 1975 | if (n == NULL) |
1996 | { | 1976 | { |
1997 | if (message == NULL) | 1977 | if (message == NULL) |
1998 | return; /* disconnect of peer already marked down */ | 1978 | return; /* disconnect of peer already marked down */ |
1999 | n = setup_new_neighbour (peer); | 1979 | n = setup_new_neighbour (peer); |
2000 | } | 1980 | } |
2001 | service_context = n->plugins; | 1981 | service_context = n->plugins; |
2002 | while ( (service_context != NULL) && | 1982 | while ((service_context != NULL) && (plugin != service_context->plugin)) |
2003 | (plugin != service_context->plugin) ) | ||
2004 | service_context = service_context->next; | 1983 | service_context = service_context->next; |
2005 | GNUNET_assert ((plugin->api->send == NULL) || | 1984 | GNUNET_assert ((plugin->api->send == NULL) || (service_context != NULL)); |
2006 | (service_context != NULL)); | ||
2007 | if (message == NULL) | 1985 | if (message == NULL) |
2008 | { | 1986 | { |
2009 | #if DEBUG_TRANSPORT | 1987 | #if DEBUG_TRANSPORT |
2010 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 1988 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
2011 | "Receive failed from `%4s', triggering disconnect\n", | 1989 | "Receive failed from `%4s', triggering disconnect\n", |
2012 | GNUNET_i2s(&n->id)); | 1990 | GNUNET_i2s (&n->id)); |
2013 | #endif | 1991 | #endif |
2014 | /* TODO: call stats */ | 1992 | /* TODO: call stats */ |
2015 | if (service_context != NULL) | 1993 | if (service_context != NULL) |
2016 | service_context->connected = GNUNET_NO; | 1994 | service_context->connected = GNUNET_NO; |
2017 | disconnect_neighbour (n, GNUNET_YES); | 1995 | disconnect_neighbour (n, GNUNET_YES); |
2018 | return; | 1996 | return; |
2019 | } | 1997 | } |
@@ -2031,7 +2009,9 @@ plugin_env_receive (void *cls, | |||
2031 | service_context->connect_attempts++; | 2009 | service_context->connect_attempts++; |
2032 | } | 2010 | } |
2033 | service_context->timeout | 2011 | service_context->timeout |
2034 | = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 2012 | = |
2013 | GNUNET_TIME_relative_to_absolute | ||
2014 | (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | ||
2035 | service_context->latency = latency; | 2015 | service_context->latency = latency; |
2036 | } | 2016 | } |
2037 | /* update traffic received amount ... */ | 2017 | /* update traffic received amount ... */ |
@@ -2039,9 +2019,10 @@ plugin_env_receive (void *cls, | |||
2039 | n->last_received += msize; | 2019 | n->last_received += msize; |
2040 | GNUNET_SCHEDULER_cancel (sched, n->timeout_task); | 2020 | GNUNET_SCHEDULER_cancel (sched, n->timeout_task); |
2041 | n->peer_timeout = | 2021 | n->peer_timeout = |
2042 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 2022 | GNUNET_TIME_relative_to_absolute |
2023 | (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | ||
2043 | n->timeout_task = | 2024 | n->timeout_task = |
2044 | GNUNET_SCHEDULER_add_delayed (sched, | 2025 | GNUNET_SCHEDULER_add_delayed (sched, |
2045 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 2026 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
2046 | &neighbour_timeout_task, n); | 2027 | &neighbour_timeout_task, n); |
2047 | update_quota (n); | 2028 | update_quota (n); |
@@ -2053,8 +2034,8 @@ plugin_env_receive (void *cls, | |||
2053 | _ | 2034 | _ |
2054 | ("Dropping incoming message due to repeated bandwidth quota violations.\n")); | 2035 | ("Dropping incoming message due to repeated bandwidth quota violations.\n")); |
2055 | /* TODO: call stats */ | 2036 | /* TODO: call stats */ |
2056 | GNUNET_assert ( (service_context == NULL) || | 2037 | GNUNET_assert ((service_context == NULL) || |
2057 | (NULL != service_context->neighbour) ); | 2038 | (NULL != service_context->neighbour)); |
2058 | return; | 2039 | return; |
2059 | } | 2040 | } |
2060 | switch (ntohs (message->type)) | 2041 | switch (ntohs (message->type)) |
@@ -2063,13 +2044,13 @@ plugin_env_receive (void *cls, | |||
2063 | #if DEBUG_TRANSPORT | 2044 | #if DEBUG_TRANSPORT |
2064 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2045 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2065 | "Receiving `%s' message from `%4s'.\n", "HELLO", | 2046 | "Receiving `%s' message from `%4s'.\n", "HELLO", |
2066 | GNUNET_i2s(peer)); | 2047 | GNUNET_i2s (peer)); |
2067 | #endif | 2048 | #endif |
2068 | process_hello (plugin, message); | 2049 | process_hello (plugin, message); |
2069 | #if DEBUG_TRANSPORT | 2050 | #if DEBUG_TRANSPORT |
2070 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2051 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2071 | "Sending `%s' message to connecting peer `%4s'.\n", "ACK", | 2052 | "Sending `%s' message to connecting peer `%4s'.\n", "ACK", |
2072 | GNUNET_i2s(peer)); | 2053 | GNUNET_i2s (peer)); |
2073 | #endif | 2054 | #endif |
2074 | transmit_to_peer (NULL, 0, &ack, GNUNET_YES, n); | 2055 | transmit_to_peer (NULL, 0, &ack, GNUNET_YES, n); |
2075 | break; | 2056 | break; |
@@ -2080,8 +2061,7 @@ plugin_env_receive (void *cls, | |||
2080 | #if DEBUG_TRANSPORT | 2061 | #if DEBUG_TRANSPORT |
2081 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2062 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2082 | "Received message of type %u from `%4s', sending to all clients.\n", | 2063 | "Received message of type %u from `%4s', sending to all clients.\n", |
2083 | ntohs (message->type), | 2064 | ntohs (message->type), GNUNET_i2s (peer)); |
2084 | GNUNET_i2s(peer)); | ||
2085 | #endif | 2065 | #endif |
2086 | /* transmit message to all clients */ | 2066 | /* transmit message to all clients */ |
2087 | im = GNUNET_malloc (sizeof (struct InboundMessage) + msize); | 2067 | im = GNUNET_malloc (sizeof (struct InboundMessage) + msize); |
@@ -2099,8 +2079,8 @@ plugin_env_receive (void *cls, | |||
2099 | } | 2079 | } |
2100 | GNUNET_free (im); | 2080 | GNUNET_free (im); |
2101 | } | 2081 | } |
2102 | GNUNET_assert ( (service_context == NULL) || | 2082 | GNUNET_assert ((service_context == NULL) || |
2103 | (NULL != service_context->neighbour) ); | 2083 | (NULL != service_context->neighbour)); |
2104 | } | 2084 | } |
2105 | 2085 | ||
2106 | 2086 | ||
@@ -2147,8 +2127,7 @@ handle_start (void *cls, | |||
2147 | { | 2127 | { |
2148 | #if DEBUG_TRANSPORT | 2128 | #if DEBUG_TRANSPORT |
2149 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2129 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2150 | "Sending our own `%s' to new client\n", | 2130 | "Sending our own `%s' to new client\n", "HELLO"); |
2151 | "HELLO"); | ||
2152 | #endif | 2131 | #endif |
2153 | transmit_to_client (c, | 2132 | transmit_to_client (c, |
2154 | (const struct GNUNET_MessageHeader *) our_hello, | 2133 | (const struct GNUNET_MessageHeader *) our_hello, |
@@ -2156,7 +2135,8 @@ handle_start (void *cls, | |||
2156 | /* tell new client about all existing connections */ | 2135 | /* tell new client about all existing connections */ |
2157 | cim.header.size = htons (sizeof (struct ConnectInfoMessage)); | 2136 | cim.header.size = htons (sizeof (struct ConnectInfoMessage)); |
2158 | cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); | 2137 | cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); |
2159 | cim.quota_out = htonl (GNUNET_CONSTANTS_DEFAULT_BPM_IN_OUT / (60 * 1000)); | 2138 | cim.quota_out = |
2139 | htonl (GNUNET_CONSTANTS_DEFAULT_BPM_IN_OUT / (60 * 1000)); | ||
2160 | cim.latency = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_ZERO); /* FIXME? */ | 2140 | cim.latency = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_ZERO); /* FIXME? */ |
2161 | im = GNUNET_malloc (sizeof (struct InboundMessage) + | 2141 | im = GNUNET_malloc (sizeof (struct InboundMessage) + |
2162 | sizeof (struct GNUNET_MessageHeader)); | 2142 | sizeof (struct GNUNET_MessageHeader)); |
@@ -2260,7 +2240,7 @@ handle_send (void *cls, | |||
2260 | ntohs (obmm->size), | 2240 | ntohs (obmm->size), |
2261 | ntohs (obmm->type), GNUNET_i2s (&obm->peer)); | 2241 | ntohs (obmm->type), GNUNET_i2s (&obm->peer)); |
2262 | #endif | 2242 | #endif |
2263 | transmit_to_peer (tc, ntohl(obm->priority), obmm, GNUNET_NO, n); | 2243 | transmit_to_peer (tc, ntohl (obm->priority), obmm, GNUNET_NO, n); |
2264 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 2244 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2265 | } | 2245 | } |
2266 | 2246 | ||
@@ -2328,36 +2308,33 @@ handle_try_connect (void *cls, | |||
2328 | #if DEBUG_TRANSPORT | 2308 | #if DEBUG_TRANSPORT |
2329 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2309 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2330 | "Received `%s' request from client %p asking to connect to `%4s'\n", | 2310 | "Received `%s' request from client %p asking to connect to `%4s'\n", |
2331 | "TRY_CONNECT", | 2311 | "TRY_CONNECT", client, GNUNET_i2s (&tcm->peer)); |
2332 | client, | ||
2333 | GNUNET_i2s (&tcm->peer)); | ||
2334 | #endif | 2312 | #endif |
2335 | if (NULL == find_neighbour (&tcm->peer)) | 2313 | if (NULL == find_neighbour (&tcm->peer)) |
2336 | setup_new_neighbour (&tcm->peer); | 2314 | setup_new_neighbour (&tcm->peer); |
2337 | #if DEBUG_TRANSPORT | 2315 | #if DEBUG_TRANSPORT |
2338 | else | 2316 | else |
2339 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2317 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2340 | "Client asked to connect to `%4s', but connection already exists\n", | 2318 | "Client asked to connect to `%4s', but connection already exists\n", |
2341 | "TRY_CONNECT", | 2319 | "TRY_CONNECT", GNUNET_i2s (&tcm->peer)); |
2342 | GNUNET_i2s (&tcm->peer)); | 2320 | #endif |
2343 | #endif | ||
2344 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 2321 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2345 | } | 2322 | } |
2346 | 2323 | ||
2347 | static void | 2324 | static void |
2348 | transmit_address_to_client (void *cls, const char *address) | 2325 | transmit_address_to_client (void *cls, const char *address) |
2349 | { | 2326 | { |
2350 | struct GNUNET_SERVER_TransmitContext *tc = cls; | 2327 | struct GNUNET_SERVER_TransmitContext *tc = cls; |
2351 | size_t slen; | 2328 | size_t slen; |
2352 | 2329 | ||
2353 | if (NULL == address) | 2330 | if (NULL == address) |
2354 | slen = 0; | 2331 | slen = 0; |
2355 | else | 2332 | else |
2356 | slen = strlen (address) + 1; | 2333 | slen = strlen (address) + 1; |
2357 | GNUNET_SERVER_transmit_context_append (tc, address, slen, | 2334 | GNUNET_SERVER_transmit_context_append (tc, address, slen, |
2358 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); | 2335 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); |
2359 | if (NULL == address) | 2336 | if (NULL == address) |
2360 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | 2337 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); |
2361 | } | 2338 | } |
2362 | 2339 | ||
2363 | /** | 2340 | /** |
@@ -2369,52 +2346,58 @@ transmit_address_to_client (void *cls, const char *address) | |||
2369 | */ | 2346 | */ |
2370 | static void | 2347 | static void |
2371 | handle_address_lookup (void *cls, | 2348 | handle_address_lookup (void *cls, |
2372 | struct GNUNET_SERVER_Client *client, | 2349 | struct GNUNET_SERVER_Client *client, |
2373 | const struct GNUNET_MessageHeader *message) | 2350 | const struct GNUNET_MessageHeader *message) |
2374 | { | 2351 | { |
2375 | const struct AddressLookupMessage *alum; | 2352 | const struct AddressLookupMessage *alum; |
2376 | struct TransportPlugin *lsPlugin; | 2353 | struct TransportPlugin *lsPlugin; |
2377 | const char *nameTransport; | 2354 | const char *nameTransport; |
2378 | const char *address; | 2355 | const char *address; |
2379 | uint16_t size; | 2356 | uint16_t size; |
2380 | struct GNUNET_SERVER_TransmitContext *tc; | 2357 | struct GNUNET_SERVER_TransmitContext *tc; |
2381 | 2358 | ||
2382 | size = ntohs (message->size); | 2359 | size = ntohs (message->size); |
2383 | if (size < sizeof(struct AddressLookupMessage)) | 2360 | if (size < sizeof (struct AddressLookupMessage)) |
2384 | { | 2361 | { |
2385 | GNUNET_break_op (0); | 2362 | GNUNET_break_op (0); |
2386 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2363 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2387 | return; | 2364 | return; |
2388 | } | 2365 | } |
2389 | alum = (const struct AddressLookupMessage *) message; | 2366 | alum = (const struct AddressLookupMessage *) message; |
2390 | uint32_t addressLen = ntohl(alum->addrlen); | 2367 | uint32_t addressLen = ntohl (alum->addrlen); |
2391 | if (size <= sizeof(struct AddressLookupMessage) + addressLen) | 2368 | if (size <= sizeof (struct AddressLookupMessage) + addressLen) |
2392 | { | 2369 | { |
2393 | GNUNET_break_op (0); | 2370 | GNUNET_break_op (0); |
2394 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2371 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2395 | return; | 2372 | return; |
2396 | } | 2373 | } |
2397 | address = (const char *)&alum[1]; | 2374 | address = (const char *) &alum[1]; |
2398 | nameTransport = (const char*)&address[addressLen]; | 2375 | nameTransport = (const char *) &address[addressLen]; |
2399 | if (nameTransport [size - sizeof (struct AddressLookupMessage) - addressLen -1] != '\0') | 2376 | if (nameTransport |
2400 | { | 2377 | [size - sizeof (struct AddressLookupMessage) - addressLen - 1] != '\0') |
2401 | GNUNET_break_op (0); | 2378 | { |
2402 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2379 | GNUNET_break_op (0); |
2403 | return; | 2380 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2404 | } | 2381 | return; |
2405 | struct GNUNET_TIME_Absolute timeout= GNUNET_TIME_absolute_ntoh(alum->timeout); | 2382 | } |
2406 | struct GNUNET_TIME_Relative rtimeout = GNUNET_TIME_absolute_get_remaining(timeout); | 2383 | struct GNUNET_TIME_Absolute timeout = |
2407 | lsPlugin = find_transport(nameTransport); | 2384 | GNUNET_TIME_absolute_ntoh (alum->timeout); |
2408 | if (NULL == lsPlugin) | 2385 | struct GNUNET_TIME_Relative rtimeout = |
2409 | { | 2386 | GNUNET_TIME_absolute_get_remaining (timeout); |
2410 | tc = GNUNET_SERVER_transmit_context_create (client); | 2387 | lsPlugin = find_transport (nameTransport); |
2411 | GNUNET_SERVER_transmit_context_append (tc, NULL, 0, GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); | 2388 | if (NULL == lsPlugin) |
2412 | GNUNET_SERVER_transmit_context_run (tc, rtimeout); | 2389 | { |
2413 | return; | 2390 | tc = GNUNET_SERVER_transmit_context_create (client); |
2414 | } | 2391 | GNUNET_SERVER_transmit_context_append (tc, NULL, 0, |
2415 | tc = GNUNET_SERVER_transmit_context_create (client); | 2392 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); |
2416 | lsPlugin->api->address_pretty_printer(cls, nameTransport, | 2393 | GNUNET_SERVER_transmit_context_run (tc, rtimeout); |
2417 | address, addressLen, GNUNET_YES, rtimeout, &transmit_address_to_client, tc); | 2394 | return; |
2395 | } | ||
2396 | tc = GNUNET_SERVER_transmit_context_create (client); | ||
2397 | lsPlugin->api->address_pretty_printer (cls, nameTransport, | ||
2398 | address, addressLen, GNUNET_YES, | ||
2399 | rtimeout, | ||
2400 | &transmit_address_to_client, tc); | ||
2418 | } | 2401 | } |
2419 | 2402 | ||
2420 | /** | 2403 | /** |
@@ -2435,7 +2418,7 @@ static struct GNUNET_SERVER_MessageHandler handlers[] = { | |||
2435 | sizeof (struct TryConnectMessage)}, | 2418 | sizeof (struct TryConnectMessage)}, |
2436 | {&handle_address_lookup, NULL, | 2419 | {&handle_address_lookup, NULL, |
2437 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP, | 2420 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP, |
2438 | 0 }, | 2421 | 0}, |
2439 | {NULL, NULL, 0, 0} | 2422 | {NULL, NULL, 0, 0} |
2440 | }; | 2423 | }; |
2441 | 2424 | ||
@@ -2455,7 +2438,8 @@ create_environment (struct TransportPlugin *plug) | |||
2455 | plug->env.receive = &plugin_env_receive; | 2438 | plug->env.receive = &plugin_env_receive; |
2456 | plug->env.notify_address = &plugin_env_notify_address; | 2439 | plug->env.notify_address = &plugin_env_notify_address; |
2457 | plug->env.notify_validation = &plugin_env_notify_validation; | 2440 | plug->env.notify_validation = &plugin_env_notify_validation; |
2458 | plug->env.default_quota_in = (GNUNET_CONSTANTS_DEFAULT_BPM_IN_OUT + 59999) / (60 * 1000); | 2441 | plug->env.default_quota_in = |
2442 | (GNUNET_CONSTANTS_DEFAULT_BPM_IN_OUT + 59999) / (60 * 1000); | ||
2459 | plug->env.max_connections = max_connect_per_transport; | 2443 | plug->env.max_connections = max_connect_per_transport; |
2460 | } | 2444 | } |
2461 | 2445 | ||
@@ -2545,8 +2529,7 @@ client_disconnect_notification (void *cls, | |||
2545 | * @param tc task context (unused) | 2529 | * @param tc task context (unused) |
2546 | */ | 2530 | */ |
2547 | static void | 2531 | static void |
2548 | unload_plugins (void *cls, | 2532 | unload_plugins (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
2549 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
2550 | { | 2533 | { |
2551 | struct TransportPlugin *plug; | 2534 | struct TransportPlugin *plug; |
2552 | struct AddressList *al; | 2535 | struct AddressList *al; |
@@ -2585,7 +2568,7 @@ unload_plugins (void *cls, | |||
2585 | static void | 2568 | static void |
2586 | run (void *cls, | 2569 | run (void *cls, |
2587 | struct GNUNET_SCHEDULER_Handle *s, | 2570 | struct GNUNET_SCHEDULER_Handle *s, |
2588 | struct GNUNET_SERVER_Handle *serv, | 2571 | struct GNUNET_SERVER_Handle *serv, |
2589 | const struct GNUNET_CONFIGURATION_Handle *c) | 2572 | const struct GNUNET_CONFIGURATION_Handle *c) |
2590 | { | 2573 | { |
2591 | char *plugs; | 2574 | char *plugs; |
@@ -2654,8 +2637,7 @@ run (void *cls, | |||
2654 | if (no_transports) | 2637 | if (no_transports) |
2655 | refresh_hello (); | 2638 | refresh_hello (); |
2656 | #if DEBUG_TRANSPORT | 2639 | #if DEBUG_TRANSPORT |
2657 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 2640 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Transport service ready.\n")); |
2658 | _("Transport service ready.\n")); | ||
2659 | #endif | 2641 | #endif |
2660 | /* process client requests */ | 2642 | /* process client requests */ |
2661 | GNUNET_SERVER_add_handlers (server, handlers); | 2643 | GNUNET_SERVER_add_handlers (server, handlers); |
@@ -2673,11 +2655,11 @@ int | |||
2673 | main (int argc, char *const *argv) | 2655 | main (int argc, char *const *argv) |
2674 | { | 2656 | { |
2675 | return (GNUNET_OK == | 2657 | return (GNUNET_OK == |
2676 | GNUNET_SERVICE_run (argc, | 2658 | GNUNET_SERVICE_run (argc, |
2677 | argv, | 2659 | argv, |
2678 | "transport", | 2660 | "transport", |
2679 | GNUNET_SERVICE_OPTION_NONE, | 2661 | GNUNET_SERVICE_OPTION_NONE, |
2680 | &run, NULL)) ? 0 : 1; | 2662 | &run, NULL)) ? 0 : 1; |
2681 | } | 2663 | } |
2682 | 2664 | ||
2683 | /* end of gnunet-service-transport.c */ | 2665 | /* end of gnunet-service-transport.c */ |
diff --git a/src/transport/plugin_transport.h b/src/transport/plugin_transport.h index 4cbf5e2e6..795d4ed25 100644 --- a/src/transport/plugin_transport.h +++ b/src/transport/plugin_transport.h | |||
@@ -60,12 +60,15 @@ | |||
60 | * @param message the message, NULL if peer was disconnected | 60 | * @param message the message, NULL if peer was disconnected |
61 | */ | 61 | */ |
62 | typedef void (*GNUNET_TRANSPORT_PluginReceiveCallback) (void *cls, | 62 | typedef void (*GNUNET_TRANSPORT_PluginReceiveCallback) (void *cls, |
63 | struct GNUNET_TIME_Relative | 63 | struct |
64 | latency, | 64 | GNUNET_TIME_Relative |
65 | const struct GNUNET_PeerIdentity | 65 | latency, |
66 | * peer, | 66 | const struct |
67 | const struct GNUNET_MessageHeader | 67 | GNUNET_PeerIdentity * |
68 | * message); | 68 | peer, |
69 | const struct | ||
70 | GNUNET_MessageHeader * | ||
71 | message); | ||
69 | 72 | ||
70 | 73 | ||
71 | /** | 74 | /** |
@@ -84,10 +87,13 @@ typedef void (*GNUNET_TRANSPORT_PluginReceiveCallback) (void *cls, | |||
84 | * by the other peer in human-readable format) | 87 | * by the other peer in human-readable format) |
85 | */ | 88 | */ |
86 | typedef void (*GNUNET_TRANSPORT_ValidationNotification) (void *cls, | 89 | typedef void (*GNUNET_TRANSPORT_ValidationNotification) (void *cls, |
87 | const char *name, | 90 | const char *name, |
88 | const struct GNUNET_PeerIdentity *peer, | 91 | const struct |
89 | uint32_t challenge, | 92 | GNUNET_PeerIdentity * |
90 | const char *sender_addr); | 93 | peer, |
94 | uint32_t challenge, | ||
95 | const char | ||
96 | *sender_addr); | ||
91 | 97 | ||
92 | 98 | ||
93 | 99 | ||
@@ -217,12 +223,12 @@ struct GNUNET_TRANSPORT_PluginEnvironment | |||
217 | */ | 223 | */ |
218 | typedef int | 224 | typedef int |
219 | (*GNUNET_TRANSPORT_ValidationFunction) (void *cls, | 225 | (*GNUNET_TRANSPORT_ValidationFunction) (void *cls, |
220 | const struct | 226 | const struct |
221 | GNUNET_PeerIdentity * target, | 227 | GNUNET_PeerIdentity * target, |
222 | uint32_t challenge, | 228 | uint32_t challenge, |
223 | struct GNUNET_TIME_Relative | 229 | struct GNUNET_TIME_Relative |
224 | timeout, const void *addr, | 230 | timeout, const void *addr, |
225 | size_t addrlen); | 231 | size_t addrlen); |
226 | 232 | ||
227 | /** | 233 | /** |
228 | * Function called by the GNUNET_TRANSPORT_TransmitFunction | 234 | * Function called by the GNUNET_TRANSPORT_TransmitFunction |
@@ -260,11 +266,11 @@ typedef void | |||
260 | * peer disconnected...); can be NULL | 266 | * peer disconnected...); can be NULL |
261 | * @param cont_cls closure for cont | 267 | * @param cont_cls closure for cont |
262 | */ | 268 | */ |
263 | typedef void | 269 | typedef void |
264 | (*GNUNET_TRANSPORT_TransmitFunction) (void *cls, | 270 | (*GNUNET_TRANSPORT_TransmitFunction) (void *cls, |
265 | const struct GNUNET_PeerIdentity * | 271 | const struct GNUNET_PeerIdentity * |
266 | target, | 272 | target, |
267 | unsigned int priority, | 273 | unsigned int priority, |
268 | const struct GNUNET_MessageHeader * | 274 | const struct GNUNET_MessageHeader * |
269 | msg, | 275 | msg, |
270 | struct GNUNET_TIME_Relative timeout, | 276 | struct GNUNET_TIME_Relative timeout, |
@@ -290,8 +296,8 @@ typedef void | |||
290 | */ | 296 | */ |
291 | typedef void | 297 | typedef void |
292 | (*GNUNET_TRANSPORT_DisconnectFunction) (void *cls, | 298 | (*GNUNET_TRANSPORT_DisconnectFunction) (void *cls, |
293 | const struct GNUNET_PeerIdentity * | 299 | const struct GNUNET_PeerIdentity * |
294 | target); | 300 | target); |
295 | 301 | ||
296 | 302 | ||
297 | /** | 303 | /** |
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index 5fd875623..e5f1361ac 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c | |||
@@ -1006,9 +1006,8 @@ receiveContentCallback (void *ptr, size_t size, size_t nmemb, void *ctx) | |||
1006 | cpy = sizeof (GNUNET_MessageHeader) - httpSession->cs.client.rpos1; | 1006 | cpy = sizeof (GNUNET_MessageHeader) - httpSession->cs.client.rpos1; |
1007 | if (cpy > have) | 1007 | if (cpy > have) |
1008 | cpy = have; | 1008 | cpy = have; |
1009 | memcpy (&httpSession->cs. | 1009 | memcpy (&httpSession->cs.client. |
1010 | client.rbuff1[httpSession->cs.client.rpos1], &inbuf[poff], | 1010 | rbuff1[httpSession->cs.client.rpos1], &inbuf[poff], cpy); |
1011 | cpy); | ||
1012 | httpSession->cs.client.rpos1 += cpy; | 1011 | httpSession->cs.client.rpos1 += cpy; |
1013 | have -= cpy; | 1012 | have -= cpy; |
1014 | poff += cpy; | 1013 | poff += cpy; |
@@ -1028,9 +1027,8 @@ receiveContentCallback (void *ptr, size_t size, size_t nmemb, void *ctx) | |||
1028 | httpSession->cs.client.rpos2; | 1027 | httpSession->cs.client.rpos2; |
1029 | if (cpy > have) | 1028 | if (cpy > have) |
1030 | cpy = have; | 1029 | cpy = have; |
1031 | memcpy (&httpSession->cs. | 1030 | memcpy (&httpSession->cs.client. |
1032 | client.rbuff2[httpSession->cs.client.rpos2], &inbuf[poff], | 1031 | rbuff2[httpSession->cs.client.rpos2], &inbuf[poff], cpy); |
1033 | cpy); | ||
1034 | have -= cpy; | 1032 | have -= cpy; |
1035 | poff += cpy; | 1033 | poff += cpy; |
1036 | httpSession->cs.client.rpos2 += cpy; | 1034 | httpSession->cs.client.rpos2 += cpy; |
@@ -1810,11 +1808,14 @@ curl_runner (void *unused) | |||
1810 | GNUNET_net_fdset_copy_native (hrs, rs); | 1808 | GNUNET_net_fdset_copy_native (hrs, rs); |
1811 | GNUNET_net_fdset_copy_native (hes, es); | 1809 | GNUNET_net_fdset_copy_native (hes, es); |
1812 | 1810 | ||
1813 | GNUNET_net_fdset_handle_set (signal_pipe[0], hrs); | 1811 | GNUNET_net_fdset_handle_set (signal_pipe[0], hrs); |
1814 | if (stats != NULL) | 1812 | if (stats != NULL) |
1815 | stats->change (stat_select_calls, 1); | 1813 | stats->change (stat_select_calls, 1); |
1816 | ret = | 1814 | ret = |
1817 | GNUNET_net_select (hrs, hws, hes, (have_tv == MHD_YES) ? timeout : GNUNET_TIME_UNIT_FOREVER_REL); | 1815 | GNUNET_net_select (hrs, hws, hes, |
1816 | (have_tv == | ||
1817 | MHD_YES) ? timeout : | ||
1818 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
1818 | if (ret == GNUNET_SYSERR) | 1819 | if (ret == GNUNET_SYSERR) |
1819 | { | 1820 | { |
1820 | GNUNET_GE_LOG_STRERROR (coreAPI->ectx, | 1821 | GNUNET_GE_LOG_STRERROR (coreAPI->ectx, |
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 2694b3f1e..d877a7f5b 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -421,9 +421,9 @@ find_session_by_target (struct Plugin *plugin, | |||
421 | 421 | ||
422 | ret = plugin->sessions; | 422 | ret = plugin->sessions; |
423 | while ((ret != NULL) && | 423 | while ((ret != NULL) && |
424 | ( (GNUNET_SYSERR == ret->expecting_welcome) || | 424 | ((GNUNET_SYSERR == ret->expecting_welcome) || |
425 | (0 != memcmp (target, | 425 | (0 != memcmp (target, |
426 | &ret->target, sizeof (struct GNUNET_PeerIdentity))))) | 426 | &ret->target, sizeof (struct GNUNET_PeerIdentity))))) |
427 | ret = ret->next; | 427 | ret = ret->next; |
428 | return ret; | 428 | return ret; |
429 | } | 429 | } |
@@ -538,24 +538,24 @@ do_transmit (void *cls, size_t size, void *buf) | |||
538 | { | 538 | { |
539 | #if DEBUG_TCP | 539 | #if DEBUG_TCP |
540 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 540 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
541 | "tcp", | 541 | "tcp", |
542 | "Timeout trying to transmit to peer `%4s', discarding message queue.\n", | 542 | "Timeout trying to transmit to peer `%4s', discarding message queue.\n", |
543 | GNUNET_i2s(&session->target)); | 543 | GNUNET_i2s (&session->target)); |
544 | #endif | 544 | #endif |
545 | /* timeout */ | 545 | /* timeout */ |
546 | while (NULL != (pm = session->pending_messages)) | 546 | while (NULL != (pm = session->pending_messages)) |
547 | { | 547 | { |
548 | session->pending_messages = pm->next; | 548 | session->pending_messages = pm->next; |
549 | #if DEBUG_TCP | 549 | #if DEBUG_TCP |
550 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 550 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
551 | "tcp", | 551 | "tcp", |
552 | "Failed to transmit message of type %u to `%4s'.\n", | 552 | "Failed to transmit message of type %u to `%4s'.\n", |
553 | ntohs(pm->msg->type), | 553 | ntohs (pm->msg->type), |
554 | GNUNET_i2s(&session->target)); | 554 | GNUNET_i2s (&session->target)); |
555 | #endif | 555 | #endif |
556 | if (pm->transmit_cont != NULL) | 556 | if (pm->transmit_cont != NULL) |
557 | pm->transmit_cont (pm->transmit_cont_cls, | 557 | pm->transmit_cont (pm->transmit_cont_cls, |
558 | &session->target, GNUNET_SYSERR); | 558 | &session->target, GNUNET_SYSERR); |
559 | GNUNET_free (pm); | 559 | GNUNET_free (pm); |
560 | } | 560 | } |
561 | return 0; | 561 | return 0; |
@@ -618,22 +618,20 @@ static void | |||
618 | process_pending_messages (struct Session *session) | 618 | process_pending_messages (struct Session *session) |
619 | { | 619 | { |
620 | GNUNET_assert (session->client != NULL); | 620 | GNUNET_assert (session->client != NULL); |
621 | if (session->pending_messages == NULL) | 621 | if (session->pending_messages == NULL) |
622 | return; | 622 | return; |
623 | if (session->transmit_handle != NULL) | 623 | if (session->transmit_handle != NULL) |
624 | return; | 624 | return; |
625 | session->transmit_handle | 625 | session->transmit_handle |
626 | = GNUNET_SERVER_notify_transmit_ready (session->client, | 626 | = GNUNET_SERVER_notify_transmit_ready (session->client, |
627 | ntohs (session-> | 627 | ntohs (session->pending_messages-> |
628 | pending_messages->msg-> | 628 | msg->size) + |
629 | size) + | 629 | (session->pending_messages-> |
630 | (session-> | 630 | is_welcome ? 0 : sizeof (struct |
631 | pending_messages->is_welcome ? 0 : | 631 | DataMessage)), |
632 | sizeof (struct DataMessage)), | ||
633 | GNUNET_TIME_absolute_get_remaining | 632 | GNUNET_TIME_absolute_get_remaining |
634 | (session-> | 633 | (session->pending_messages[0]. |
635 | pending_messages[0].timeout), | 634 | timeout), &do_transmit, session); |
636 | &do_transmit, session); | ||
637 | } | 635 | } |
638 | 636 | ||
639 | 637 | ||
@@ -652,8 +650,9 @@ process_pending_messages (struct Session *session) | |||
652 | */ | 650 | */ |
653 | static struct Session * | 651 | static struct Session * |
654 | connect_and_create_validation_session (struct Plugin *plugin, | 652 | connect_and_create_validation_session (struct Plugin *plugin, |
655 | const struct GNUNET_PeerIdentity *target, | 653 | const struct GNUNET_PeerIdentity |
656 | const void *addr, size_t addrlen) | 654 | *target, const void *addr, |
655 | size_t addrlen) | ||
657 | { | 656 | { |
658 | struct GNUNET_SERVER_Client *client; | 657 | struct GNUNET_SERVER_Client *client; |
659 | struct GNUNET_CONNECTION_Handle *conn; | 658 | struct GNUNET_CONNECTION_Handle *conn; |
@@ -663,24 +662,24 @@ connect_and_create_validation_session (struct Plugin *plugin, | |||
663 | if (addrlen == sizeof (struct sockaddr_in)) | 662 | if (addrlen == sizeof (struct sockaddr_in)) |
664 | af = AF_INET; | 663 | af = AF_INET; |
665 | else if (addrlen == sizeof (struct sockaddr_in6)) | 664 | else if (addrlen == sizeof (struct sockaddr_in6)) |
666 | af = AF_INET6; | 665 | af = AF_INET6; |
667 | else | 666 | else |
668 | { | 667 | { |
669 | GNUNET_break_op (0); | 668 | GNUNET_break_op (0); |
670 | return NULL; /* invalid address */ | 669 | return NULL; /* invalid address */ |
671 | } | 670 | } |
672 | conn = GNUNET_CONNECTION_create_from_sockaddr (plugin->env->sched, | 671 | conn = GNUNET_CONNECTION_create_from_sockaddr (plugin->env->sched, |
673 | af, | 672 | af, |
674 | addr, | 673 | addr, |
675 | addrlen, | 674 | addrlen, |
676 | GNUNET_SERVER_MAX_MESSAGE_SIZE); | 675 | GNUNET_SERVER_MAX_MESSAGE_SIZE); |
677 | if (conn == NULL) | 676 | if (conn == NULL) |
678 | { | 677 | { |
679 | #if DEBUG_TCP | 678 | #if DEBUG_TCP |
680 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 679 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
681 | "tcp", | 680 | "tcp", |
682 | "Failed to create connection to peer at `%s'.\n", | 681 | "Failed to create connection to peer at `%s'.\n", |
683 | GNUNET_a2s(addr, addrlen)); | 682 | GNUNET_a2s (addr, addrlen)); |
684 | #endif | 683 | #endif |
685 | return NULL; | 684 | return NULL; |
686 | } | 685 | } |
@@ -692,16 +691,15 @@ connect_and_create_validation_session (struct Plugin *plugin, | |||
692 | session->pending_messages = NULL; | 691 | session->pending_messages = NULL; |
693 | session->connect_alen = addrlen; | 692 | session->connect_alen = addrlen; |
694 | session->connect_addr = GNUNET_malloc (addrlen); | 693 | session->connect_addr = GNUNET_malloc (addrlen); |
695 | session->expecting_welcome = GNUNET_SYSERR; | 694 | session->expecting_welcome = GNUNET_SYSERR; |
696 | memcpy (session->connect_addr, addr, addrlen); | 695 | memcpy (session->connect_addr, addr, addrlen); |
697 | #if DEBUG_TCP | 696 | #if DEBUG_TCP |
698 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 697 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
699 | "tcp", | 698 | "tcp", |
700 | "Creating new session %p with `%s' for `%4s' based on `%s' request.\n", | 699 | "Creating new session %p with `%s' for `%4s' based on `%s' request.\n", |
701 | session, | 700 | session, |
702 | GNUNET_a2s (addr, addrlen), | 701 | GNUNET_a2s (addr, addrlen), |
703 | GNUNET_i2s (&session->target), | 702 | GNUNET_i2s (&session->target), "VALIDATE"); |
704 | "VALIDATE"); | ||
705 | #endif | 703 | #endif |
706 | return session; | 704 | return session; |
707 | } | 705 | } |
@@ -723,17 +721,18 @@ connect_and_create_validation_session (struct Plugin *plugin, | |||
723 | */ | 721 | */ |
724 | static int | 722 | static int |
725 | tcp_plugin_validate (void *cls, | 723 | tcp_plugin_validate (void *cls, |
726 | const struct GNUNET_PeerIdentity *target, | 724 | const struct GNUNET_PeerIdentity *target, |
727 | uint32_t challenge, | 725 | uint32_t challenge, |
728 | struct GNUNET_TIME_Relative timeout, | 726 | struct GNUNET_TIME_Relative timeout, |
729 | const void *addr, size_t addrlen) | 727 | const void *addr, size_t addrlen) |
730 | { | 728 | { |
731 | struct Plugin *plugin = cls; | 729 | struct Plugin *plugin = cls; |
732 | struct Session *session; | 730 | struct Session *session; |
733 | struct PendingMessage *pm; | 731 | struct PendingMessage *pm; |
734 | struct ValidationChallengeMessage *vcm; | 732 | struct ValidationChallengeMessage *vcm; |
735 | 733 | ||
736 | session = connect_and_create_validation_session (plugin, target, addr, addrlen); | 734 | session = |
735 | connect_and_create_validation_session (plugin, target, addr, addrlen); | ||
737 | if (session == NULL) | 736 | if (session == NULL) |
738 | { | 737 | { |
739 | #if DEBUG_TCP | 738 | #if DEBUG_TCP |
@@ -743,15 +742,15 @@ tcp_plugin_validate (void *cls, | |||
743 | return GNUNET_SYSERR; | 742 | return GNUNET_SYSERR; |
744 | } | 743 | } |
745 | pm = GNUNET_malloc (sizeof (struct PendingMessage) + | 744 | pm = GNUNET_malloc (sizeof (struct PendingMessage) + |
746 | sizeof (struct ValidationChallengeMessage) + addrlen); | 745 | sizeof (struct ValidationChallengeMessage) + addrlen); |
747 | pm->msg = (struct GNUNET_MessageHeader *) &pm[1]; | 746 | pm->msg = (struct GNUNET_MessageHeader *) &pm[1]; |
748 | pm->timeout = GNUNET_TIME_relative_to_absolute (timeout); | 747 | pm->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
749 | pm->is_welcome = GNUNET_YES; | 748 | pm->is_welcome = GNUNET_YES; |
750 | vcm = (struct ValidationChallengeMessage*) &pm[1]; | 749 | vcm = (struct ValidationChallengeMessage *) &pm[1]; |
751 | vcm->header.size = | 750 | vcm->header.size = |
752 | htons (sizeof (struct ValidationChallengeMessage) + addrlen); | 751 | htons (sizeof (struct ValidationChallengeMessage) + addrlen); |
753 | vcm->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_PING); | 752 | vcm->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_PING); |
754 | vcm->challenge = htonl(challenge); | 753 | vcm->challenge = htonl (challenge); |
755 | vcm->target = *target; | 754 | vcm->target = *target; |
756 | memcpy (&vcm[1], addr, addrlen); | 755 | memcpy (&vcm[1], addr, addrlen); |
757 | GNUNET_assert (session->pending_messages == NULL); | 756 | GNUNET_assert (session->pending_messages == NULL); |
@@ -778,12 +777,11 @@ disconnect_session (struct Session *session) | |||
778 | #if DEBUG_TCP | 777 | #if DEBUG_TCP |
779 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 778 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
780 | "tcp", | 779 | "tcp", |
781 | "Disconnecting from `%4s' at %s (session %p).\n", | 780 | "Disconnecting from `%4s' at %s (session %p).\n", |
782 | GNUNET_i2s(&session->target), | 781 | GNUNET_i2s (&session->target), |
783 | (session->connect_addr != NULL) ? | 782 | (session->connect_addr != NULL) ? |
784 | GNUNET_a2s(session->connect_addr, | 783 | GNUNET_a2s (session->connect_addr, |
785 | session->connect_alen) : "*", | 784 | session->connect_alen) : "*", session); |
786 | session); | ||
787 | #endif | 785 | #endif |
788 | /* remove from session list */ | 786 | /* remove from session list */ |
789 | prev = NULL; | 787 | prev = NULL; |
@@ -805,19 +803,20 @@ disconnect_session (struct Session *session) | |||
805 | } | 803 | } |
806 | if (session->transmit_handle != NULL) | 804 | if (session->transmit_handle != NULL) |
807 | { | 805 | { |
808 | GNUNET_CONNECTION_notify_transmit_ready_cancel (session->transmit_handle); | 806 | GNUNET_CONNECTION_notify_transmit_ready_cancel (session-> |
807 | transmit_handle); | ||
809 | session->transmit_handle = NULL; | 808 | session->transmit_handle = NULL; |
810 | } | 809 | } |
811 | while (NULL != (pm = session->pending_messages)) | 810 | while (NULL != (pm = session->pending_messages)) |
812 | { | 811 | { |
813 | #if DEBUG_TCP | 812 | #if DEBUG_TCP |
814 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 813 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
815 | "tcp", | 814 | "tcp", |
816 | pm->transmit_cont != NULL | 815 | pm->transmit_cont != NULL |
817 | ? "Could not deliver message of type %u to `%4s'.\n" | 816 | ? "Could not deliver message of type %u to `%4s'.\n" |
818 | : "Could not deliver message of type %u to `%4s', notifying.\n", | 817 | : |
819 | ntohs(pm->msg->type), | 818 | "Could not deliver message of type %u to `%4s', notifying.\n", |
820 | GNUNET_i2s(&session->target)); | 819 | ntohs (pm->msg->type), GNUNET_i2s (&session->target)); |
821 | #endif | 820 | #endif |
822 | session->pending_messages = pm->next; | 821 | session->pending_messages = pm->next; |
823 | if (NULL != pm->transmit_cont) | 822 | if (NULL != pm->transmit_cont) |
@@ -829,17 +828,17 @@ disconnect_session (struct Session *session) | |||
829 | { | 828 | { |
830 | #if DEBUG_TCP | 829 | #if DEBUG_TCP |
831 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 830 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
832 | "tcp", | 831 | "tcp", |
833 | "Notifying transport service about loss of data connection with `%4s'.\n", | 832 | "Notifying transport service about loss of data connection with `%4s'.\n", |
834 | GNUNET_i2s(&session->target)); | 833 | GNUNET_i2s (&session->target)); |
835 | #endif | 834 | #endif |
836 | /* Data session that actually went past the | 835 | /* Data session that actually went past the |
837 | initial handshake; transport service may | 836 | initial handshake; transport service may |
838 | know about this one, so we need to | 837 | know about this one, so we need to |
839 | notify transport service about disconnect */ | 838 | notify transport service about disconnect */ |
840 | session->plugin->env->receive (session->plugin->env->cls, | 839 | session->plugin->env->receive (session->plugin->env->cls, |
841 | GNUNET_TIME_UNIT_ZERO, | 840 | GNUNET_TIME_UNIT_ZERO, |
842 | &session->target, NULL); | 841 | &session->target, NULL); |
843 | } | 842 | } |
844 | if (session->client != NULL) | 843 | if (session->client != NULL) |
845 | { | 844 | { |
@@ -930,13 +929,13 @@ try_connect_to_address (void *cls, | |||
930 | cc->welcome = create_welcome (addrlen, addr, cc->plugin); | 929 | cc->welcome = create_welcome (addrlen, addr, cc->plugin); |
931 | cc->sa = | 930 | cc->sa = |
932 | GNUNET_CONNECTION_create_from_sockaddr (cc->plugin->env->sched, | 931 | GNUNET_CONNECTION_create_from_sockaddr (cc->plugin->env->sched, |
933 | af, addr, addrlen, | 932 | af, addr, addrlen, |
934 | GNUNET_SERVER_MAX_MESSAGE_SIZE); | 933 | GNUNET_SERVER_MAX_MESSAGE_SIZE); |
935 | #if DEBUG_TCP | 934 | #if DEBUG_TCP |
936 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 935 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
937 | "tcp", | 936 | "tcp", |
938 | "Connecting using address %s.\n", | 937 | "Connecting using address %s.\n", |
939 | GNUNET_a2s(addr, addrlen)); | 938 | GNUNET_a2s (addr, addrlen)); |
940 | #endif | 939 | #endif |
941 | return GNUNET_SYSERR; | 940 | return GNUNET_SYSERR; |
942 | } | 941 | } |
@@ -974,7 +973,7 @@ session_try_connect (void *cls, | |||
974 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 973 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
975 | "tcp", | 974 | "tcp", |
976 | "Now connected to `%4s', now processing messages.\n", | 975 | "Now connected to `%4s', now processing messages.\n", |
977 | GNUNET_i2s(&session->target)); | 976 | GNUNET_i2s (&session->target)); |
978 | #endif | 977 | #endif |
979 | process_pending_messages (session); | 978 | process_pending_messages (session); |
980 | } | 979 | } |
@@ -984,8 +983,7 @@ session_try_connect (void *cls, | |||
984 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 983 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
985 | "tcp", | 984 | "tcp", |
986 | "Failed to connect to `%4s' (no working `%s'), closing session.\n", | 985 | "Failed to connect to `%4s' (no working `%s'), closing session.\n", |
987 | GNUNET_i2s(&session->target), | 986 | GNUNET_i2s (&session->target), "HELLO"); |
988 | "HELLO"); | ||
989 | #endif | 987 | #endif |
990 | disconnect_session (session); | 988 | disconnect_session (session); |
991 | } | 989 | } |
@@ -1005,7 +1003,7 @@ session_try_connect (void *cls, | |||
1005 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1003 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1006 | "tcp", | 1004 | "tcp", |
1007 | "Asked to connect to `%4s', but have no addresses to try.\n", | 1005 | "Asked to connect to `%4s', but have no addresses to try.\n", |
1008 | GNUNET_i2s(&session->target)); | 1006 | GNUNET_i2s (&session->target)); |
1009 | #endif | 1007 | #endif |
1010 | return; | 1008 | return; |
1011 | } | 1009 | } |
@@ -1030,8 +1028,7 @@ session_try_connect (void *cls, | |||
1030 | #if DEBUG_TCP | 1028 | #if DEBUG_TCP |
1031 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1029 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1032 | "Connected to `%4s' for session %p\n", | 1030 | "Connected to `%4s' for session %p\n", |
1033 | GNUNET_i2s(&session->target), | 1031 | GNUNET_i2s (&session->target), session->client); |
1034 | session->client); | ||
1035 | #endif | 1032 | #endif |
1036 | if (session->client == NULL) | 1033 | if (session->client == NULL) |
1037 | { | 1034 | { |
@@ -1047,8 +1044,7 @@ session_try_connect (void *cls, | |||
1047 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1044 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1048 | "tcp", | 1045 | "tcp", |
1049 | "Connected to `%4s', now sending `%s' message.\n", | 1046 | "Connected to `%4s', now sending `%s' message.\n", |
1050 | GNUNET_i2s(&session->target), | 1047 | GNUNET_i2s (&session->target), "WELCOME"); |
1051 | "WELCOME"); | ||
1052 | #endif | 1048 | #endif |
1053 | } | 1049 | } |
1054 | 1050 | ||
@@ -1070,9 +1066,9 @@ session_try_connect (void *cls, | |||
1070 | * peer disconnected...) | 1066 | * peer disconnected...) |
1071 | * @param cont_cls closure for cont | 1067 | * @param cont_cls closure for cont |
1072 | */ | 1068 | */ |
1073 | static void | 1069 | static void |
1074 | tcp_plugin_send (void *cls, | 1070 | tcp_plugin_send (void *cls, |
1075 | const struct GNUNET_PeerIdentity *target, | 1071 | const struct GNUNET_PeerIdentity *target, |
1076 | unsigned int priority, | 1072 | unsigned int priority, |
1077 | const struct GNUNET_MessageHeader *msg, | 1073 | const struct GNUNET_MessageHeader *msg, |
1078 | struct GNUNET_TIME_Relative timeout, | 1074 | struct GNUNET_TIME_Relative timeout, |
@@ -1083,7 +1079,7 @@ tcp_plugin_send (void *cls, | |||
1083 | struct PendingMessage *pm; | 1079 | struct PendingMessage *pm; |
1084 | struct PendingMessage *pme; | 1080 | struct PendingMessage *pme; |
1085 | 1081 | ||
1086 | session = find_session_by_target (plugin, target); | 1082 | session = find_session_by_target (plugin, target); |
1087 | pm = GNUNET_malloc (sizeof (struct PendingMessage) + ntohs (msg->size)); | 1083 | pm = GNUNET_malloc (sizeof (struct PendingMessage) + ntohs (msg->size)); |
1088 | pm->msg = (struct GNUNET_MessageHeader *) &pm[1]; | 1084 | pm->msg = (struct GNUNET_MessageHeader *) &pm[1]; |
1089 | memcpy (pm->msg, msg, ntohs (msg->size)); | 1085 | memcpy (pm->msg, msg, ntohs (msg->size)); |
@@ -1108,9 +1104,10 @@ tcp_plugin_send (void *cls, | |||
1108 | session->expecting_welcome = GNUNET_YES; | 1104 | session->expecting_welcome = GNUNET_YES; |
1109 | session->pending_messages = pm; | 1105 | session->pending_messages = pm; |
1110 | session->ic = GNUNET_PEERINFO_iterate (plugin->env->cfg, | 1106 | session->ic = GNUNET_PEERINFO_iterate (plugin->env->cfg, |
1111 | plugin->env->sched, | 1107 | plugin->env->sched, |
1112 | target, | 1108 | target, |
1113 | 0, timeout, &session_try_connect, session); | 1109 | 0, timeout, &session_try_connect, |
1110 | session); | ||
1114 | return; | 1111 | return; |
1115 | } | 1112 | } |
1116 | GNUNET_assert (session != NULL); | 1113 | GNUNET_assert (session != NULL); |
@@ -1153,13 +1150,12 @@ tcp_plugin_send (void *cls, | |||
1153 | * to be cancelled | 1150 | * to be cancelled |
1154 | */ | 1151 | */ |
1155 | static void | 1152 | static void |
1156 | tcp_plugin_disconnect (void *cls, | 1153 | tcp_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) |
1157 | const struct GNUNET_PeerIdentity *target) | ||
1158 | { | 1154 | { |
1159 | struct Plugin *plugin = cls; | 1155 | struct Plugin *plugin = cls; |
1160 | struct Session *session; | 1156 | struct Session *session; |
1161 | struct PendingMessage *pm; | 1157 | struct PendingMessage *pm; |
1162 | 1158 | ||
1163 | session = find_session_by_target (plugin, target); | 1159 | session = find_session_by_target (plugin, target); |
1164 | if (session == NULL) | 1160 | if (session == NULL) |
1165 | { | 1161 | { |
@@ -1168,9 +1164,9 @@ tcp_plugin_disconnect (void *cls, | |||
1168 | } | 1164 | } |
1169 | #if DEBUG_TCP | 1165 | #if DEBUG_TCP |
1170 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1166 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1171 | "tcp", | 1167 | "tcp", |
1172 | "Asked to cancel session with `%4s'\n", | 1168 | "Asked to cancel session with `%4s'\n", |
1173 | GNUNET_i2s(target)); | 1169 | GNUNET_i2s (target)); |
1174 | #endif | 1170 | #endif |
1175 | pm = session->pending_messages; | 1171 | pm = session->pending_messages; |
1176 | while (pm != NULL) | 1172 | while (pm != NULL) |
@@ -1338,7 +1334,7 @@ tcp_plugin_set_receive_quota (void *cls, | |||
1338 | 1334 | ||
1339 | session = find_session_by_target (plugin, target); | 1335 | session = find_session_by_target (plugin, target); |
1340 | if (session == NULL) | 1336 | if (session == NULL) |
1341 | return; /* peer must have disconnected, ignore */ | 1337 | return; /* peer must have disconnected, ignore */ |
1342 | if (session->quota_in != quota_in) | 1338 | if (session->quota_in != quota_in) |
1343 | { | 1339 | { |
1344 | update_quota (session, GNUNET_YES); | 1340 | update_quota (session, GNUNET_YES); |
@@ -1408,7 +1404,7 @@ tcp_plugin_address_suggested (void *cls, const void *addr, size_t addrlen) | |||
1408 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1404 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1409 | "tcp", | 1405 | "tcp", |
1410 | "Informing transport service about my address `%s'.\n", | 1406 | "Informing transport service about my address `%s'.\n", |
1411 | GNUNET_a2s(addr, addrlen)); | 1407 | GNUNET_a2s (addr, addrlen)); |
1412 | #endif | 1408 | #endif |
1413 | plugin->env->notify_address (plugin->env->cls, | 1409 | plugin->env->notify_address (plugin->env->cls, |
1414 | "tcp", | 1410 | "tcp", |
@@ -1421,9 +1417,7 @@ tcp_plugin_address_suggested (void *cls, const void *addr, size_t addrlen) | |||
1421 | * Send a validation challenge response. | 1417 | * Send a validation challenge response. |
1422 | */ | 1418 | */ |
1423 | static size_t | 1419 | static size_t |
1424 | send_vcr (void *cls, | 1420 | send_vcr (void *cls, size_t size, void *buf) |
1425 | size_t size, | ||
1426 | void *buf) | ||
1427 | { | 1421 | { |
1428 | struct ValidationChallengeResponse *vcr = cls; | 1422 | struct ValidationChallengeResponse *vcr = cls; |
1429 | uint16_t msize; | 1423 | uint16_t msize; |
@@ -1433,7 +1427,7 @@ send_vcr (void *cls, | |||
1433 | GNUNET_free (vcr); | 1427 | GNUNET_free (vcr); |
1434 | return 0; | 1428 | return 0; |
1435 | } | 1429 | } |
1436 | msize = ntohs(vcr->header.size); | 1430 | msize = ntohs (vcr->header.size); |
1437 | GNUNET_assert (size >= msize); | 1431 | GNUNET_assert (size >= msize); |
1438 | memcpy (buf, vcr, msize); | 1432 | memcpy (buf, vcr, msize); |
1439 | GNUNET_free (vcr); | 1433 | GNUNET_free (vcr); |
@@ -1451,8 +1445,8 @@ send_vcr (void *cls, | |||
1451 | */ | 1445 | */ |
1452 | static void | 1446 | static void |
1453 | handle_tcp_ping (void *cls, | 1447 | handle_tcp_ping (void *cls, |
1454 | struct GNUNET_SERVER_Client *client, | 1448 | struct GNUNET_SERVER_Client *client, |
1455 | const struct GNUNET_MessageHeader *message) | 1449 | const struct GNUNET_MessageHeader *message) |
1456 | { | 1450 | { |
1457 | struct Plugin *plugin = cls; | 1451 | struct Plugin *plugin = cls; |
1458 | const struct ValidationChallengeMessage *vcm; | 1452 | const struct ValidationChallengeMessage *vcm; |
@@ -1463,14 +1457,11 @@ handle_tcp_ping (void *cls, | |||
1463 | 1457 | ||
1464 | #if DEBUG_TRANSPORT | 1458 | #if DEBUG_TRANSPORT |
1465 | if (GNUNET_OK == | 1459 | if (GNUNET_OK == |
1466 | GNUNET_SERVER_client_get_address (client, | 1460 | GNUNET_SERVER_client_get_address (client, (void **) &addr, &addrlen)) |
1467 | (void **) &addr, | ||
1468 | &addrlen)) | ||
1469 | { | 1461 | { |
1470 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 1462 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
1471 | "Processing `%s' from `%s'\n", | 1463 | "Processing `%s' from `%s'\n", |
1472 | "PING", | 1464 | "PING", GNUNET_a2s (addr, addrlen)); |
1473 | GNUNET_a2s (addr, addrlen)); | ||
1474 | GNUNET_free (addr); | 1465 | GNUNET_free (addr); |
1475 | } | 1466 | } |
1476 | #endif | 1467 | #endif |
@@ -1478,75 +1469,69 @@ handle_tcp_ping (void *cls, | |||
1478 | if (msize < sizeof (struct ValidationChallengeMessage)) | 1469 | if (msize < sizeof (struct ValidationChallengeMessage)) |
1479 | { | 1470 | { |
1480 | GNUNET_break_op (0); | 1471 | GNUNET_break_op (0); |
1481 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1472 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1482 | return; | 1473 | return; |
1483 | } | 1474 | } |
1484 | vcm = (const struct ValidationChallengeMessage *) message; | 1475 | vcm = (const struct ValidationChallengeMessage *) message; |
1485 | if (0 != memcmp (&vcm->target, | 1476 | if (0 != memcmp (&vcm->target, |
1486 | plugin->env->my_identity, sizeof (struct GNUNET_PeerIdentity))) | 1477 | plugin->env->my_identity, |
1478 | sizeof (struct GNUNET_PeerIdentity))) | ||
1487 | { | 1479 | { |
1488 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1480 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1489 | _("Received `%s' message not destined for me!\n"), "PING"); | 1481 | _("Received `%s' message not destined for me!\n"), "PING"); |
1490 | /* TODO: call statistics */ | 1482 | /* TODO: call statistics */ |
1491 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1483 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1492 | return; | 1484 | return; |
1493 | } | 1485 | } |
1494 | msize -= sizeof (struct ValidationChallengeMessage); | 1486 | msize -= sizeof (struct ValidationChallengeMessage); |
1495 | if (GNUNET_OK != | 1487 | if (GNUNET_OK != tcp_plugin_address_suggested (plugin, &vcm[1], msize)) |
1496 | tcp_plugin_address_suggested (plugin, &vcm[1], msize)) | ||
1497 | { | 1488 | { |
1498 | GNUNET_break_op (0); | 1489 | GNUNET_break_op (0); |
1499 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1490 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1500 | return; | 1491 | return; |
1501 | } | 1492 | } |
1502 | if (GNUNET_OK != | 1493 | if (GNUNET_OK != GNUNET_SERVER_client_get_address (client, &addr, &addrlen)) |
1503 | GNUNET_SERVER_client_get_address (client, | ||
1504 | &addr, | ||
1505 | &addrlen)) | ||
1506 | { | 1494 | { |
1507 | GNUNET_break (0); | 1495 | GNUNET_break (0); |
1508 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1496 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1509 | return; | 1497 | return; |
1510 | } | 1498 | } |
1511 | vcr = GNUNET_malloc (sizeof (struct ValidationChallengeResponse) + addrlen); | 1499 | vcr = GNUNET_malloc (sizeof (struct ValidationChallengeResponse) + addrlen); |
1512 | vcr->header.size = htons (sizeof (struct ValidationChallengeResponse) + addrlen); | 1500 | vcr->header.size = |
1501 | htons (sizeof (struct ValidationChallengeResponse) + addrlen); | ||
1513 | vcr->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_PONG); | 1502 | vcr->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_PONG); |
1514 | vcr->purpose.size = | 1503 | vcr->purpose.size = |
1515 | htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + | 1504 | htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + |
1516 | sizeof (uint32_t) + | 1505 | sizeof (uint32_t) + |
1517 | sizeof ( struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + | 1506 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + addrlen); |
1518 | addrlen); | ||
1519 | vcr->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_TCP_PING); | 1507 | vcr->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_TCP_PING); |
1520 | vcr->challenge = vcm->challenge; | 1508 | vcr->challenge = vcm->challenge; |
1521 | vcr->signer = *plugin->env->my_public_key; | 1509 | vcr->signer = *plugin->env->my_public_key; |
1522 | memcpy (&vcr[1], | 1510 | memcpy (&vcr[1], addr, addrlen); |
1523 | addr, | ||
1524 | addrlen); | ||
1525 | GNUNET_assert (GNUNET_OK == | 1511 | GNUNET_assert (GNUNET_OK == |
1526 | GNUNET_CRYPTO_rsa_sign (plugin->env->my_private_key, | 1512 | GNUNET_CRYPTO_rsa_sign (plugin->env->my_private_key, |
1527 | &vcr->purpose, | 1513 | &vcr->purpose, &vcr->signature)); |
1528 | &vcr->signature)); | ||
1529 | #if EXTRA_CHECKS | 1514 | #if EXTRA_CHECKS |
1530 | GNUNET_assert (GNUNET_OK == | 1515 | GNUNET_assert (GNUNET_OK == |
1531 | GNUNET_CRYPTO_rsa_verify | 1516 | GNUNET_CRYPTO_rsa_verify |
1532 | (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_TCP_PING, | 1517 | (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_TCP_PING, |
1533 | &vcr->purpose, | 1518 | &vcr->purpose, |
1534 | &vcr->signature, | 1519 | &vcr->signature, plugin->env->my_public_key)); |
1535 | plugin->env->my_public_key)); | ||
1536 | #endif | 1520 | #endif |
1537 | GNUNET_free (addr); | 1521 | GNUNET_free (addr); |
1538 | if (NULL == | 1522 | if (NULL == |
1539 | GNUNET_SERVER_notify_transmit_ready (client, | 1523 | GNUNET_SERVER_notify_transmit_ready (client, |
1540 | sizeof (struct ValidationChallengeResponse) + addrlen, | 1524 | sizeof (struct |
1541 | GNUNET_TIME_UNIT_SECONDS, | 1525 | ValidationChallengeResponse) |
1542 | &send_vcr, | 1526 | + addrlen, |
1543 | vcr)) | 1527 | GNUNET_TIME_UNIT_SECONDS, |
1528 | &send_vcr, vcr)) | ||
1544 | { | 1529 | { |
1545 | GNUNET_break (0); | 1530 | GNUNET_break (0); |
1546 | GNUNET_free (vcr); | 1531 | GNUNET_free (vcr); |
1547 | } | 1532 | } |
1548 | /* after a PING, we always close the connection */ | 1533 | /* after a PING, we always close the connection */ |
1549 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1534 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1550 | } | 1535 | } |
1551 | 1536 | ||
1552 | 1537 | ||
@@ -1559,8 +1544,8 @@ handle_tcp_ping (void *cls, | |||
1559 | */ | 1544 | */ |
1560 | static void | 1545 | static void |
1561 | handle_tcp_pong (void *cls, | 1546 | handle_tcp_pong (void *cls, |
1562 | struct GNUNET_SERVER_Client *client, | 1547 | struct GNUNET_SERVER_Client *client, |
1563 | const struct GNUNET_MessageHeader *message) | 1548 | const struct GNUNET_MessageHeader *message) |
1564 | { | 1549 | { |
1565 | struct Plugin *plugin = cls; | 1550 | struct Plugin *plugin = cls; |
1566 | const struct ValidationChallengeResponse *vcr; | 1551 | const struct ValidationChallengeResponse *vcr; |
@@ -1575,78 +1560,71 @@ handle_tcp_pong (void *cls, | |||
1575 | struct sockaddr *claddr; | 1560 | struct sockaddr *claddr; |
1576 | 1561 | ||
1577 | if (GNUNET_OK == | 1562 | if (GNUNET_OK == |
1578 | GNUNET_SERVER_client_get_address (client, | 1563 | GNUNET_SERVER_client_get_address (client, (void **) &claddr, &addrlen)) |
1579 | (void**) &claddr, | ||
1580 | &addrlen)) | ||
1581 | { | 1564 | { |
1582 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 1565 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
1583 | "Processing `%s' from `%s'\n", | 1566 | "Processing `%s' from `%s'\n", |
1584 | "PONG", | 1567 | "PONG", GNUNET_a2s (claddr, addrlen)); |
1585 | GNUNET_a2s (claddr, addrlen)); | ||
1586 | GNUNET_free (claddr); | 1568 | GNUNET_free (claddr); |
1587 | } | 1569 | } |
1588 | #endif | 1570 | #endif |
1589 | if (ntohs(message->size) < sizeof(struct ValidationChallengeResponse)) | 1571 | if (ntohs (message->size) < sizeof (struct ValidationChallengeResponse)) |
1590 | { | 1572 | { |
1591 | GNUNET_break_op (0); | 1573 | GNUNET_break_op (0); |
1592 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1574 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1593 | return; | 1575 | return; |
1594 | } | 1576 | } |
1595 | addrlen = ntohs(message->size) - sizeof(struct ValidationChallengeResponse); | 1577 | addrlen = |
1578 | ntohs (message->size) - sizeof (struct ValidationChallengeResponse); | ||
1596 | vcr = (const struct ValidationChallengeResponse *) message; | 1579 | vcr = (const struct ValidationChallengeResponse *) message; |
1597 | if ( (ntohl(vcr->purpose.size) != | 1580 | if ((ntohl (vcr->purpose.size) != |
1598 | sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + | 1581 | sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + |
1599 | sizeof (uint32_t) + | 1582 | sizeof (uint32_t) + |
1600 | sizeof ( struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + | 1583 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + addrlen)) |
1601 | addrlen)) | ||
1602 | { | 1584 | { |
1603 | GNUNET_break_op (0); | 1585 | GNUNET_break_op (0); |
1604 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1586 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1605 | return; | 1587 | return; |
1606 | } | 1588 | } |
1607 | if (GNUNET_OK != | 1589 | if (GNUNET_OK != |
1608 | GNUNET_CRYPTO_rsa_verify | 1590 | GNUNET_CRYPTO_rsa_verify |
1609 | (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_TCP_PING, | 1591 | (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_TCP_PING, |
1610 | &vcr->purpose, | 1592 | &vcr->purpose, &vcr->signature, &vcr->signer)) |
1611 | &vcr->signature, | ||
1612 | &vcr->signer)) | ||
1613 | { | 1593 | { |
1614 | GNUNET_break_op (0); | 1594 | GNUNET_break_op (0); |
1615 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1595 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1616 | return; | 1596 | return; |
1617 | } | 1597 | } |
1618 | GNUNET_CRYPTO_hash (&vcr->signer, | 1598 | GNUNET_CRYPTO_hash (&vcr->signer, |
1619 | sizeof( struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 1599 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
1620 | &peer.hashPubKey); | 1600 | &peer.hashPubKey); |
1621 | addr = (const struct sockaddr*) &vcr[1]; | 1601 | addr = (const struct sockaddr *) &vcr[1]; |
1622 | if (addrlen == sizeof (struct sockaddr_in)) | 1602 | if (addrlen == sizeof (struct sockaddr_in)) |
1623 | { | 1603 | { |
1624 | memcpy (&v4, addr, sizeof (struct sockaddr_in)); | 1604 | memcpy (&v4, addr, sizeof (struct sockaddr_in)); |
1625 | v4.sin_port = htons(check_port (plugin, ntohs (v4.sin_port))); | 1605 | v4.sin_port = htons (check_port (plugin, ntohs (v4.sin_port))); |
1626 | sender_addr = GNUNET_strdup (GNUNET_a2s((const struct sockaddr*) &v4, | 1606 | sender_addr = GNUNET_strdup (GNUNET_a2s ((const struct sockaddr *) &v4, |
1627 | addrlen)); | 1607 | addrlen)); |
1628 | } | 1608 | } |
1629 | else if (addrlen == sizeof (struct sockaddr_in6)) | 1609 | else if (addrlen == sizeof (struct sockaddr_in6)) |
1630 | { | 1610 | { |
1631 | memcpy (&v6, addr, sizeof (struct sockaddr_in6)); | 1611 | memcpy (&v6, addr, sizeof (struct sockaddr_in6)); |
1632 | v6.sin6_port = htons(check_port (plugin, ntohs (v6.sin6_port))); | 1612 | v6.sin6_port = htons (check_port (plugin, ntohs (v6.sin6_port))); |
1633 | sender_addr = GNUNET_strdup (GNUNET_a2s((const struct sockaddr*) &v6, | 1613 | sender_addr = GNUNET_strdup (GNUNET_a2s ((const struct sockaddr *) &v6, |
1634 | addrlen)); | 1614 | addrlen)); |
1635 | } | 1615 | } |
1636 | else | 1616 | else |
1637 | { | 1617 | { |
1638 | GNUNET_break_op (0); | 1618 | GNUNET_break_op (0); |
1639 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1619 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1640 | return; | 1620 | return; |
1641 | } | 1621 | } |
1642 | plugin->env->notify_validation (plugin->env->cls, | 1622 | plugin->env->notify_validation (plugin->env->cls, |
1643 | "tcp", | 1623 | "tcp", |
1644 | &peer, | 1624 | &peer, ntohl (vcr->challenge), sender_addr); |
1645 | ntohl(vcr->challenge), | ||
1646 | sender_addr); | ||
1647 | GNUNET_free (sender_addr); | 1625 | GNUNET_free (sender_addr); |
1648 | /* after a PONG, we always close the connection */ | 1626 | /* after a PONG, we always close the connection */ |
1649 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1627 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1650 | } | 1628 | } |
1651 | 1629 | ||
1652 | 1630 | ||
@@ -1685,8 +1663,7 @@ handle_tcp_welcome (void *cls, | |||
1685 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1663 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1686 | "tcp", | 1664 | "tcp", |
1687 | "Received `%s' message from `%4s/%p'.\n", "WELCOME", | 1665 | "Received `%s' message from `%4s/%p'.\n", "WELCOME", |
1688 | GNUNET_i2s(&wm->clientIdentity), | 1666 | GNUNET_i2s (&wm->clientIdentity), client); |
1689 | client); | ||
1690 | #endif | 1667 | #endif |
1691 | session_c = find_session_by_client (plugin, client); | 1668 | session_c = find_session_by_client (plugin, client); |
1692 | if (session_c == NULL) | 1669 | if (session_c == NULL) |
@@ -1809,8 +1786,7 @@ handle_tcp_data (void *cls, | |||
1809 | #if DEBUG_TCP | 1786 | #if DEBUG_TCP |
1810 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1787 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1811 | "tcp", "Receiving %u bytes from `%4s'.\n", | 1788 | "tcp", "Receiving %u bytes from `%4s'.\n", |
1812 | msize, | 1789 | msize, GNUNET_i2s (&session->target)); |
1813 | GNUNET_i2s(&session->target)); | ||
1814 | #endif | 1790 | #endif |
1815 | dm = (const struct DataMessage *) message; | 1791 | dm = (const struct DataMessage *) message; |
1816 | session->max_in_msg_counter = GNUNET_MAX (session->max_in_msg_counter, | 1792 | session->max_in_msg_counter = GNUNET_MAX (session->max_in_msg_counter, |
@@ -1848,8 +1824,7 @@ handle_tcp_data (void *cls, | |||
1848 | "Forwarding data of type %u to transport service.\n", | 1824 | "Forwarding data of type %u to transport service.\n", |
1849 | ntohs (msg->type)); | 1825 | ntohs (msg->type)); |
1850 | #endif | 1826 | #endif |
1851 | plugin->env->receive (plugin->env->cls, | 1827 | plugin->env->receive (plugin->env->cls, latency, &session->target, msg); |
1852 | latency, &session->target, msg); | ||
1853 | /* update bandwidth used */ | 1828 | /* update bandwidth used */ |
1854 | session->last_received += msize; | 1829 | session->last_received += msize; |
1855 | update_quota (session, GNUNET_NO); | 1830 | update_quota (session, GNUNET_NO); |
@@ -1910,11 +1885,10 @@ disconnect_notify (void *cls, struct GNUNET_SERVER_Client *client) | |||
1910 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1885 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1911 | "tcp", | 1886 | "tcp", |
1912 | "Destroying session of `%4s' with %s (%p) due to network-level disconnect.\n", | 1887 | "Destroying session of `%4s' with %s (%p) due to network-level disconnect.\n", |
1913 | GNUNET_i2s(&session->target), | 1888 | GNUNET_i2s (&session->target), |
1914 | (session->connect_addr != NULL) ? | 1889 | (session->connect_addr != NULL) ? |
1915 | GNUNET_a2s(session->connect_addr, | 1890 | GNUNET_a2s (session->connect_addr, |
1916 | session->connect_alen) : "*", | 1891 | session->connect_alen) : "*", client); |
1917 | client); | ||
1918 | #endif | 1892 | #endif |
1919 | disconnect_session (session); | 1893 | disconnect_session (session); |
1920 | } | 1894 | } |
@@ -1949,8 +1923,8 @@ process_interfaces (void *cls, | |||
1949 | } | 1923 | } |
1950 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO | | 1924 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO | |
1951 | GNUNET_ERROR_TYPE_BULK, | 1925 | GNUNET_ERROR_TYPE_BULK, |
1952 | "tcp", _("Found address `%s' (%s)\n"), | 1926 | "tcp", _("Found address `%s' (%s)\n"), |
1953 | GNUNET_a2s(addr, addrlen), name); | 1927 | GNUNET_a2s (addr, addrlen), name); |
1954 | plugin->env->notify_address (plugin->env->cls, | 1928 | plugin->env->notify_address (plugin->env->cls, |
1955 | "tcp", | 1929 | "tcp", |
1956 | addr, addrlen, GNUNET_TIME_UNIT_FOREVER_REL); | 1930 | addr, addrlen, GNUNET_TIME_UNIT_FOREVER_REL); |
@@ -1978,11 +1952,7 @@ process_hostname_ips (void *cls, | |||
1978 | plugin->hostname_dns = NULL; | 1952 | plugin->hostname_dns = NULL; |
1979 | return; | 1953 | return; |
1980 | } | 1954 | } |
1981 | process_interfaces (plugin, | 1955 | process_interfaces (plugin, "<hostname>", GNUNET_YES, addr, addrlen); |
1982 | "<hostname>", | ||
1983 | GNUNET_YES, | ||
1984 | addr, | ||
1985 | addrlen); | ||
1986 | } | 1956 | } |
1987 | 1957 | ||
1988 | 1958 | ||
@@ -2062,10 +2032,11 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2062 | plugin); | 2032 | plugin); |
2063 | GNUNET_OS_network_interfaces_list (&process_interfaces, plugin); | 2033 | GNUNET_OS_network_interfaces_list (&process_interfaces, plugin); |
2064 | plugin->hostname_dns = GNUNET_RESOLVER_hostname_resolve (env->sched, | 2034 | plugin->hostname_dns = GNUNET_RESOLVER_hostname_resolve (env->sched, |
2065 | env->cfg, | 2035 | env->cfg, |
2066 | AF_UNSPEC, | 2036 | AF_UNSPEC, |
2067 | HOSTNAME_RESOLVE_TIMEOUT, | 2037 | HOSTNAME_RESOLVE_TIMEOUT, |
2068 | &process_hostname_ips, plugin); | 2038 | &process_hostname_ips, |
2039 | plugin); | ||
2069 | return api; | 2040 | return api; |
2070 | } | 2041 | } |
2071 | 2042 | ||
@@ -2081,7 +2052,7 @@ libgnunet_plugin_transport_tcp_done (void *cls) | |||
2081 | struct Session *session; | 2052 | struct Session *session; |
2082 | 2053 | ||
2083 | while (NULL != (session = plugin->sessions)) | 2054 | while (NULL != (session = plugin->sessions)) |
2084 | disconnect_session (session); | 2055 | disconnect_session (session); |
2085 | if (NULL != plugin->hostname_dns) | 2056 | if (NULL != plugin->hostname_dns) |
2086 | { | 2057 | { |
2087 | GNUNET_RESOLVER_request_cancel (plugin->hostname_dns); | 2058 | GNUNET_RESOLVER_request_cancel (plugin->hostname_dns); |
diff --git a/src/transport/plugin_transport_template.c b/src/transport/plugin_transport_template.c index 69c27b923..69610283b 100644 --- a/src/transport/plugin_transport_template.c +++ b/src/transport/plugin_transport_template.c | |||
@@ -147,11 +147,10 @@ struct Plugin | |||
147 | */ | 147 | */ |
148 | static int | 148 | static int |
149 | template_plugin_validate (void *cls, | 149 | template_plugin_validate (void *cls, |
150 | const struct GNUNET_PeerIdentity *target, | 150 | const struct GNUNET_PeerIdentity *target, |
151 | uint32_t challenge, | 151 | uint32_t challenge, |
152 | struct GNUNET_TIME_Relative timeout, | 152 | struct GNUNET_TIME_Relative timeout, |
153 | const void *addr, | 153 | const void *addr, size_t addrlen) |
154 | size_t addrlen) | ||
155 | { | 154 | { |
156 | // FIXME | 155 | // FIXME |
157 | return GNUNET_SYSERR; | 156 | return GNUNET_SYSERR; |
@@ -173,10 +172,10 @@ template_plugin_validate (void *cls, | |||
173 | * peer disconnected...) | 172 | * peer disconnected...) |
174 | * @param cont_cls closure for cont | 173 | * @param cont_cls closure for cont |
175 | */ | 174 | */ |
176 | static void | 175 | static void |
177 | template_plugin_send (void *cls, | 176 | template_plugin_send (void *cls, |
178 | const struct GNUNET_PeerIdentity *target, | 177 | const struct GNUNET_PeerIdentity *target, |
179 | unsigned int priority, | 178 | unsigned int priority, |
180 | const struct GNUNET_MessageHeader *msg, | 179 | const struct GNUNET_MessageHeader *msg, |
181 | struct GNUNET_TIME_Relative timeout, | 180 | struct GNUNET_TIME_Relative timeout, |
182 | GNUNET_TRANSPORT_TransmitContinuation cont, | 181 | GNUNET_TRANSPORT_TransmitContinuation cont, |
@@ -197,7 +196,7 @@ template_plugin_send (void *cls, | |||
197 | */ | 196 | */ |
198 | static void | 197 | static void |
199 | template_plugin_disconnect (void *cls, | 198 | template_plugin_disconnect (void *cls, |
200 | const struct GNUNET_PeerIdentity *target) | 199 | const struct GNUNET_PeerIdentity *target) |
201 | { | 200 | { |
202 | // struct Plugin *plugin = cls; | 201 | // struct Plugin *plugin = cls; |
203 | // FIXME | 202 | // FIXME |
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index f20cd19df..345a98bec 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | (C) 2001, 2002, 2003, 2004, 2005, 2008 Christian Grothoff (and other contributing authors) | 3 | (C) 2010 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -166,7 +166,7 @@ struct Plugin | |||
166 | /* | 166 | /* |
167 | * FD Read set | 167 | * FD Read set |
168 | */ | 168 | */ |
169 | struct GNUNET_NETWORK_FDSet * rs; | 169 | struct GNUNET_NETWORK_FDSet *rs; |
170 | 170 | ||
171 | }; | 171 | }; |
172 | 172 | ||
@@ -242,7 +242,7 @@ static struct GNUNET_NETWORK_Handle *udp_sock; | |||
242 | * GNUNET_SYSERR if not. | 242 | * GNUNET_SYSERR if not. |
243 | */ | 243 | */ |
244 | int | 244 | int |
245 | udp_associate (struct Session * session) | 245 | udp_associate (struct Session *session) |
246 | { | 246 | { |
247 | return GNUNET_SYSERR; /* UDP connections can never be associated */ | 247 | return GNUNET_SYSERR; /* UDP connections can never be associated */ |
248 | } | 248 | } |
@@ -254,9 +254,7 @@ udp_associate (struct Session * session) | |||
254 | * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed | 254 | * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed |
255 | */ | 255 | */ |
256 | void | 256 | void |
257 | udp_disconnect (void *cls, | 257 | udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) |
258 | const struct GNUNET_PeerIdentity * | ||
259 | target) | ||
260 | { | 258 | { |
261 | return; | 259 | return; |
262 | } | 260 | } |
@@ -282,18 +280,20 @@ udp_transport_server_stop (void *cls) | |||
282 | } | 280 | } |
283 | 281 | ||
284 | static struct Session * | 282 | static struct Session * |
285 | find_session(void *cls, struct Session * session_list, const struct GNUNET_PeerIdentity *peer) | 283 | find_session (void *cls, struct Session *session_list, |
284 | const struct GNUNET_PeerIdentity *peer) | ||
286 | { | 285 | { |
287 | struct Plugin *plugin = cls; | 286 | struct Plugin *plugin = cls; |
288 | struct Session *pos; | 287 | struct Session *pos; |
289 | pos = session_list; | 288 | pos = session_list; |
290 | 289 | ||
291 | while (pos != NULL) | 290 | while (pos != NULL) |
292 | { | 291 | { |
293 | if (memcmp(peer, &pos->target, sizeof(struct GNUNET_PeerIdentity)) == 0) | 292 | if (memcmp (peer, &pos->target, sizeof (struct GNUNET_PeerIdentity)) == |
294 | return pos; | 293 | 0) |
295 | pos = pos->next; | 294 | return pos; |
296 | } | 295 | pos = pos->next; |
296 | } | ||
297 | 297 | ||
298 | return NULL; | 298 | return NULL; |
299 | } | 299 | } |
@@ -329,34 +329,37 @@ udp_plugin_send (void *cls, | |||
329 | int ssize; | 329 | int ssize; |
330 | size_t sent; | 330 | size_t sent; |
331 | 331 | ||
332 | session = find_session(plugin, plugin->sessions, target); | 332 | session = find_session (plugin, plugin->sessions, target); |
333 | 333 | ||
334 | if ((session == NULL) || (udp_sock == NULL)) | 334 | if ((session == NULL) || (udp_sock == NULL)) |
335 | return; | 335 | return; |
336 | 336 | ||
337 | /* Build the message to be sent */ | 337 | /* Build the message to be sent */ |
338 | message = GNUNET_malloc(sizeof(struct UDPMessage) + ntohs(msg->size)); | 338 | message = GNUNET_malloc (sizeof (struct UDPMessage) + ntohs (msg->size)); |
339 | ssize = sizeof(struct UDPMessage) + ntohs(msg->size); | 339 | ssize = sizeof (struct UDPMessage) + ntohs (msg->size); |
340 | 340 | ||
341 | #if DEBUG_UDP | 341 | #if DEBUG_UDP |
342 | GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, "udp", _ | 342 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ |
343 | ("In udp_send, ssize is %d\n"), ssize); | 343 | ("In udp_send, ssize is %d\n"), ssize); |
344 | #endif | 344 | #endif |
345 | message->header.size = htons(ssize); | 345 | message->header.size = htons (ssize); |
346 | message->header.type = htons(0); | 346 | message->header.type = htons (0); |
347 | memcpy (&message->sender, plugin->env->my_identity, sizeof(struct GNUNET_PeerIdentity)); | 347 | memcpy (&message->sender, plugin->env->my_identity, |
348 | sizeof (struct GNUNET_PeerIdentity)); | ||
348 | memcpy (&message[1], msg, ntohs (msg->size)); | 349 | memcpy (&message[1], msg, ntohs (msg->size)); |
349 | 350 | ||
350 | /* Actually send the message */ | 351 | /* Actually send the message */ |
351 | sent = GNUNET_NETWORK_socket_sendto (udp_sock, message, ssize, session->connect_addr, | 352 | sent = |
352 | session->connect_alen); | 353 | GNUNET_NETWORK_socket_sendto (udp_sock, message, ssize, |
354 | session->connect_addr, | ||
355 | session->connect_alen); | ||
353 | 356 | ||
354 | if (cont != NULL) | 357 | if (cont != NULL) |
355 | { | 358 | { |
356 | if (sent == GNUNET_SYSERR) | 359 | if (sent == GNUNET_SYSERR) |
357 | cont(cont_cls, target, GNUNET_SYSERR); | 360 | cont (cont_cls, target, GNUNET_SYSERR); |
358 | else | 361 | else |
359 | cont(cont_cls, target, GNUNET_OK); | 362 | cont (cont_cls, target, GNUNET_OK); |
360 | } | 363 | } |
361 | 364 | ||
362 | return; | 365 | return; |
@@ -372,30 +375,35 @@ udp_plugin_send (void *cls, | |||
372 | */ | 375 | */ |
373 | static void | 376 | static void |
374 | handle_udp_ping (void *cls, | 377 | handle_udp_ping (void *cls, |
375 | struct GNUNET_PeerIdentity *sender, struct sockaddr_storage * addr, size_t addrlen, | 378 | struct GNUNET_PeerIdentity *sender, |
379 | struct sockaddr_storage *addr, size_t addrlen, | ||
376 | const struct GNUNET_MessageHeader *message) | 380 | const struct GNUNET_MessageHeader *message) |
377 | { | 381 | { |
378 | struct Plugin *plugin = cls; | 382 | struct Plugin *plugin = cls; |
379 | struct Session *head = plugin->sessions; | 383 | struct Session *head = plugin->sessions; |
380 | const struct UDPPingMessage *ping = (const struct UDPPingMessage *)message; | 384 | const struct UDPPingMessage *ping = (const struct UDPPingMessage *) message; |
381 | struct UDPPongMessage *pong; | 385 | struct UDPPongMessage *pong; |
382 | struct Session *found; | 386 | struct Session *found; |
383 | 387 | ||
384 | #if DEBUG_UDP | 388 | #if DEBUG_UDP |
385 | GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, "udp", _ | 389 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ |
386 | ("handling ping, challenge is %d\n"), ntohs(ping->challenge)); | 390 | ("handling ping, challenge is %d\n"), |
391 | ntohs (ping->challenge)); | ||
387 | #endif | 392 | #endif |
388 | found = find_session(plugin, head, sender); | 393 | found = find_session (plugin, head, sender); |
389 | if (found != NULL) | 394 | if (found != NULL) |
390 | { | 395 | { |
391 | pong = GNUNET_malloc(sizeof(struct UDPPongMessage) + addrlen); | 396 | pong = GNUNET_malloc (sizeof (struct UDPPongMessage) + addrlen); |
392 | pong->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_PONG); | 397 | pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_PONG); |
393 | pong->header.size = htons(sizeof(struct UDPPongMessage) + addrlen); | 398 | pong->header.size = htons (sizeof (struct UDPPongMessage) + addrlen); |
394 | pong->challenge = ping->challenge; | 399 | pong->challenge = ping->challenge; |
395 | memcpy(&pong[1], addr, addrlen); | 400 | memcpy (&pong[1], addr, addrlen); |
396 | pong->addrlen = htons(addrlen); | 401 | pong->addrlen = htons (addrlen); |
397 | 402 | ||
398 | udp_plugin_send(plugin, sender, GNUNET_SCHEDULER_PRIORITY_DEFAULT, &pong->header, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30), NULL, NULL); | 403 | udp_plugin_send (plugin, sender, GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
404 | &pong->header, | ||
405 | GNUNET_TIME_relative_multiply | ||
406 | (GNUNET_TIME_UNIT_SECONDS, 30), NULL, NULL); | ||
399 | } | 407 | } |
400 | 408 | ||
401 | return; | 409 | return; |
@@ -417,49 +425,52 @@ handle_udp_pong (void *cls, | |||
417 | const struct GNUNET_MessageHeader *message) | 425 | const struct GNUNET_MessageHeader *message) |
418 | { | 426 | { |
419 | struct Plugin *plugin = cls; | 427 | struct Plugin *plugin = cls; |
420 | const struct UDPPongMessage *pong = (struct UDPPongMessage *)message; | 428 | const struct UDPPongMessage *pong = (struct UDPPongMessage *) message; |
421 | struct Session *found; | 429 | struct Session *found; |
422 | unsigned int addr_len; | 430 | unsigned int addr_len; |
423 | struct sockaddr_storage addr; | 431 | struct sockaddr_storage addr; |
424 | 432 | ||
425 | #if DEBUG_UDP | 433 | #if DEBUG_UDP |
426 | GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, "udp", _ | 434 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _("handling pong\n")); |
427 | ("handling pong\n")); | ||
428 | #endif | 435 | #endif |
429 | found = find_session(plugin, plugin->sessions, sender); | 436 | found = find_session (plugin, plugin->sessions, sender); |
430 | #if DEBUG_UDP | 437 | #if DEBUG_UDP |
431 | GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, "udp", _ | 438 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ |
432 | ("found->challenge %d, pong->challenge %d\n"), found->challenge, ntohs(pong->challenge)); | 439 | ("found->challenge %d, pong->challenge %d\n"), |
440 | found->challenge, ntohs (pong->challenge)); | ||
433 | #endif | 441 | #endif |
434 | if ((found != NULL) && (found->challenge == ntohs(pong->challenge))) | 442 | if ((found != NULL) && (found->challenge == ntohs (pong->challenge))) |
435 | { | 443 | { |
436 | found->validated = GNUNET_YES; | 444 | found->validated = GNUNET_YES; |
437 | addr_len = ntohs(pong->addrlen); | 445 | addr_len = ntohs (pong->addrlen); |
438 | #if DEBUG_UDP | 446 | #if DEBUG_UDP |
439 | GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, "udp", _ | 447 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ |
440 | ("found associated ping, addr is %u bytes\n"), addr_len); | 448 | ("found associated ping, addr is %u bytes\n"), |
449 | addr_len); | ||
441 | #endif | 450 | #endif |
442 | memcpy(&addr, &pong[1], addr_len); | 451 | memcpy (&addr, &pong[1], addr_len); |
443 | plugin->env->notify_validation(plugin->env->cls, "udp", sender, ntohs(pong->challenge), (char *)&addr); | 452 | plugin->env->notify_validation (plugin->env->cls, "udp", sender, |
453 | ntohs (pong->challenge), | ||
454 | (char *) &addr); | ||
444 | } | 455 | } |
445 | else | 456 | else |
446 | { | 457 | { |
447 | 458 | ||
448 | #if DEBUG_UDP | 459 | #if DEBUG_UDP |
449 | GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, "udp", _ | 460 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ |
450 | ("Session not found!\n")); | 461 | ("Session not found!\n")); |
451 | #endif | 462 | #endif |
452 | } | 463 | } |
453 | return; | 464 | return; |
454 | } | 465 | } |
455 | 466 | ||
456 | static void | 467 | static void |
457 | udp_plugin_select (void *cls, | 468 | udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
458 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
459 | { | 469 | { |
460 | struct Plugin *plugin = cls; | 470 | struct Plugin *plugin = cls; |
461 | struct GNUNET_TIME_Relative timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500); | 471 | struct GNUNET_TIME_Relative timeout = |
462 | char * buf; | 472 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500); |
473 | char *buf; | ||
463 | struct UDPMessage *msg; | 474 | struct UDPMessage *msg; |
464 | const struct GNUNET_MessageHeader *hdr; | 475 | const struct GNUNET_MessageHeader *hdr; |
465 | struct GNUNET_PeerIdentity *sender; | 476 | struct GNUNET_PeerIdentity *sender; |
@@ -468,88 +479,100 @@ udp_plugin_select (void *cls, | |||
468 | struct sockaddr_storage addr; | 479 | struct sockaddr_storage addr; |
469 | ssize_t ret; | 480 | ssize_t ret; |
470 | 481 | ||
471 | do | 482 | do |
472 | { | 483 | { |
473 | buflen = GNUNET_NETWORK_socket_recvfrom_amount(udp_sock); | 484 | buflen = GNUNET_NETWORK_socket_recvfrom_amount (udp_sock); |
474 | 485 | ||
475 | #if DEBUG_UDP | 486 | #if DEBUG_UDP |
476 | GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, "udp", _ | 487 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ |
477 | ("we expect to read %u bytes\n"), buflen); | 488 | ("we expect to read %u bytes\n"), buflen); |
478 | #endif | 489 | #endif |
479 | 490 | ||
480 | if (buflen == GNUNET_NO) | 491 | if (buflen == GNUNET_NO) |
481 | return; | 492 | return; |
482 | 493 | ||
483 | buf = GNUNET_malloc(buflen); | 494 | buf = GNUNET_malloc (buflen); |
484 | fromlen = sizeof(addr); | 495 | fromlen = sizeof (addr); |
485 | 496 | ||
486 | #if DEBUG_UDP | 497 | #if DEBUG_UDP |
487 | GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, "udp", _ | 498 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ |
488 | ("src_addr_len is %u\n"), fromlen); | 499 | ("src_addr_len is %u\n"), fromlen); |
489 | #endif | 500 | #endif |
490 | 501 | ||
491 | memset(&addr, 0, fromlen); | 502 | memset (&addr, 0, fromlen); |
492 | ret = GNUNET_NETWORK_socket_recvfrom(udp_sock, buf, buflen, (struct sockaddr *)&addr, &fromlen); | 503 | ret = |
504 | GNUNET_NETWORK_socket_recvfrom (udp_sock, buf, buflen, | ||
505 | (struct sockaddr *) &addr, &fromlen); | ||
493 | 506 | ||
494 | #if DEBUG_UDP | 507 | #if DEBUG_UDP |
495 | GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, "udp", _ | 508 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ |
496 | ("socket_recv returned %u, src_addr_len is %u\n"), ret, fromlen); | 509 | ("socket_recv returned %u, src_addr_len is %u\n"), ret, |
510 | fromlen); | ||
497 | #endif | 511 | #endif |
498 | 512 | ||
499 | if (ret <= 0) | 513 | if (ret <= 0) |
500 | { | 514 | { |
501 | GNUNET_free(buf); | 515 | GNUNET_free (buf); |
502 | return; | 516 | return; |
503 | } | 517 | } |
504 | 518 | ||
505 | msg = (struct UDPMessage *)buf; | 519 | msg = (struct UDPMessage *) buf; |
506 | 520 | ||
507 | #if DEBUG_UDP | 521 | #if DEBUG_UDP |
508 | GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, "udp", _ | 522 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ |
509 | ("header reports message size of %d\n"), ntohs(msg->header.size)); | 523 | ("header reports message size of %d\n"), |
524 | ntohs (msg->header.size)); | ||
510 | 525 | ||
511 | GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, "udp", _ | 526 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ |
512 | ("header reports message type of %d\n"), ntohs(msg->header.type)); | 527 | ("header reports message type of %d\n"), |
528 | ntohs (msg->header.type)); | ||
513 | #endif | 529 | #endif |
514 | /*if (ntohs(hdr->size) < sizeof(struct UDPMessage)) | 530 | /*if (ntohs(hdr->size) < sizeof(struct UDPMessage)) |
515 | { | 531 | { |
516 | GNUNET_free(buf); | 532 | GNUNET_free(buf); |
517 | GNUNET_NETWORK_fdset_zero(plugin->rs); | 533 | GNUNET_NETWORK_fdset_zero(plugin->rs); |
518 | GNUNET_NETWORK_fdset_set(plugin->rs, udp_sock); | 534 | GNUNET_NETWORK_fdset_set(plugin->rs, udp_sock); |
519 | break; | 535 | break; |
520 | }*/ | 536 | } */ |
521 | hdr = (const struct GNUNET_MessageHeader *)&msg[1]; | 537 | hdr = (const struct GNUNET_MessageHeader *) &msg[1]; |
522 | sender = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); | 538 | sender = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
523 | memcpy(sender, &msg->sender, sizeof(struct GNUNET_PeerIdentity)); | 539 | memcpy (sender, &msg->sender, sizeof (struct GNUNET_PeerIdentity)); |
524 | 540 | ||
525 | #if DEBUG_UDP | 541 | #if DEBUG_UDP |
526 | GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, "udp", _ | 542 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ |
527 | ("msg reports message size of %d\n"), ntohs(hdr->size)); | 543 | ("msg reports message size of %d\n"), |
544 | ntohs (hdr->size)); | ||
528 | 545 | ||
529 | GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, "udp", _ | 546 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ |
530 | ("msg reports message type of %d\n"), ntohs(hdr->type)); | 547 | ("msg reports message type of %d\n"), |
548 | ntohs (hdr->type)); | ||
531 | #endif | 549 | #endif |
532 | 550 | ||
533 | if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_PING) | 551 | if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_PING) |
534 | { | 552 | { |
535 | handle_udp_ping(plugin, sender, &addr, fromlen, hdr); | 553 | handle_udp_ping (plugin, sender, &addr, fromlen, hdr); |
536 | } | 554 | } |
537 | 555 | ||
538 | if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_PONG) | 556 | if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_PONG) |
539 | { | 557 | { |
540 | handle_udp_pong(plugin, sender, hdr); | 558 | handle_udp_pong (plugin, sender, hdr); |
541 | } | 559 | } |
542 | 560 | ||
543 | GNUNET_free(buf); | 561 | GNUNET_free (buf); |
544 | 562 | ||
545 | } | 563 | } |
546 | while (GNUNET_NETWORK_socket_select (plugin->rs, | 564 | while (GNUNET_NETWORK_socket_select (plugin->rs, |
547 | NULL, | 565 | NULL, |
548 | NULL, | 566 | NULL, |
549 | timeout) > 0 && GNUNET_NETWORK_fdset_isset(plugin->rs, udp_sock)); | 567 | timeout) > 0 |
550 | 568 | && GNUNET_NETWORK_fdset_isset (plugin->rs, udp_sock)); | |
551 | plugin->select_task = GNUNET_SCHEDULER_add_select(plugin->env->sched, GNUNET_SCHEDULER_PRIORITY_DEFAULT, GNUNET_SCHEDULER_NO_TASK, | 569 | |
552 | GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs, NULL, &udp_plugin_select, plugin); | 570 | plugin->select_task = |
571 | GNUNET_SCHEDULER_add_select (plugin->env->sched, | ||
572 | GNUNET_SCHEDULER_PRIORITY_DEFAULT, | ||
573 | GNUNET_SCHEDULER_NO_TASK, | ||
574 | GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs, | ||
575 | NULL, &udp_plugin_select, plugin); | ||
553 | 576 | ||
554 | } | 577 | } |
555 | 578 | ||
@@ -569,15 +592,16 @@ udp_transport_server_start (void *cls) | |||
569 | 592 | ||
570 | desc = NULL; | 593 | desc = NULL; |
571 | if (GNUNET_YES != | 594 | if (GNUNET_YES != |
572 | GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, "GNUNETD", "DISABLE-IPV6")) | 595 | GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, "GNUNETD", |
596 | "DISABLE-IPV6")) | ||
573 | { | 597 | { |
574 | desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 17); | 598 | desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 17); |
575 | if (desc != NULL) | 599 | if (desc != NULL) |
576 | { | 600 | { |
577 | memset (&serverAddrv6, 0, sizeof (serverAddrv6)); | 601 | memset (&serverAddrv6, 0, sizeof (serverAddrv6)); |
578 | #if HAVE_SOCKADDR_IN_SIN_LEN | 602 | #if HAVE_SOCKADDR_IN_SIN_LEN |
579 | serverAddrv6.sin6_len = sizeof (serverAddrv6); | 603 | serverAddrv6.sin6_len = sizeof (serverAddrv6); |
580 | #endif | 604 | #endif |
581 | serverAddrv6.sin6_family = AF_INET6; | 605 | serverAddrv6.sin6_family = AF_INET6; |
582 | serverAddrv6.sin6_addr = in6addr_any; | 606 | serverAddrv6.sin6_addr = in6addr_any; |
583 | serverAddrv6.sin6_port = htons (plugin->open_port); | 607 | serverAddrv6.sin6_port = htons (plugin->open_port); |
@@ -590,17 +614,15 @@ udp_transport_server_start (void *cls) | |||
590 | desc = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 17); | 614 | desc = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 17); |
591 | if (NULL == desc) | 615 | if (NULL == desc) |
592 | { | 616 | { |
593 | GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, | 617 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", "socket"); |
594 | "udp", | ||
595 | "socket"); | ||
596 | return NULL; | 618 | return NULL; |
597 | } | 619 | } |
598 | else | 620 | else |
599 | { | 621 | { |
600 | memset (&serverAddrv4, 0, sizeof (serverAddrv4)); | 622 | memset (&serverAddrv4, 0, sizeof (serverAddrv4)); |
601 | #if HAVE_SOCKADDR_IN_SIN_LEN | 623 | #if HAVE_SOCKADDR_IN_SIN_LEN |
602 | serverAddrv4.sin_len = sizeof (serverAddrv4); | 624 | serverAddrv4.sin_len = sizeof (serverAddrv4); |
603 | #endif | 625 | #endif |
604 | serverAddrv4.sin_family = AF_INET; | 626 | serverAddrv4.sin_family = AF_INET; |
605 | serverAddrv4.sin_addr.s_addr = INADDR_ANY; | 627 | serverAddrv4.sin_addr.s_addr = INADDR_ANY; |
606 | serverAddrv4.sin_port = htons (plugin->open_port); | 628 | serverAddrv4.sin_port = htons (plugin->open_port); |
@@ -611,16 +633,21 @@ udp_transport_server_start (void *cls) | |||
611 | 633 | ||
612 | if (desc != NULL) | 634 | if (desc != NULL) |
613 | { | 635 | { |
614 | GNUNET_assert(GNUNET_NETWORK_socket_bind(desc, serverAddr, addrlen) == GNUNET_OK); | 636 | GNUNET_assert (GNUNET_NETWORK_socket_bind (desc, serverAddr, addrlen) == |
637 | GNUNET_OK); | ||
615 | } | 638 | } |
616 | 639 | ||
617 | plugin->rs = GNUNET_NETWORK_fdset_create (); | 640 | plugin->rs = GNUNET_NETWORK_fdset_create (); |
618 | 641 | ||
619 | GNUNET_NETWORK_fdset_zero(plugin->rs); | 642 | GNUNET_NETWORK_fdset_zero (plugin->rs); |
620 | GNUNET_NETWORK_fdset_set(plugin->rs, desc); | 643 | GNUNET_NETWORK_fdset_set (plugin->rs, desc); |
621 | 644 | ||
622 | plugin->select_task = GNUNET_SCHEDULER_add_select(plugin->env->sched, GNUNET_SCHEDULER_PRIORITY_DEFAULT, GNUNET_SCHEDULER_NO_TASK, | 645 | plugin->select_task = |
623 | GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs, NULL, &udp_plugin_select, plugin); | 646 | GNUNET_SCHEDULER_add_select (plugin->env->sched, |
647 | GNUNET_SCHEDULER_PRIORITY_DEFAULT, | ||
648 | GNUNET_SCHEDULER_NO_TASK, | ||
649 | GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs, | ||
650 | NULL, &udp_plugin_select, plugin); | ||
624 | 651 | ||
625 | return desc; | 652 | return desc; |
626 | } | 653 | } |
@@ -641,10 +668,10 @@ udp_transport_server_start (void *cls) | |||
641 | */ | 668 | */ |
642 | static int | 669 | static int |
643 | udp_plugin_validate (void *cls, | 670 | udp_plugin_validate (void *cls, |
644 | const struct GNUNET_PeerIdentity *target, | 671 | const struct GNUNET_PeerIdentity *target, |
645 | uint32_t challenge, | 672 | uint32_t challenge, |
646 | struct GNUNET_TIME_Relative timeout, | 673 | struct GNUNET_TIME_Relative timeout, |
647 | const void *addr, size_t addrlen) | 674 | const void *addr, size_t addrlen) |
648 | { | 675 | { |
649 | struct Plugin *plugin = cls; | 676 | struct Plugin *plugin = cls; |
650 | struct Session *new_session; | 677 | struct Session *new_session; |
@@ -653,32 +680,37 @@ udp_plugin_validate (void *cls, | |||
653 | if (addrlen <= 0) | 680 | if (addrlen <= 0) |
654 | return GNUNET_SYSERR; | 681 | return GNUNET_SYSERR; |
655 | 682 | ||
656 | new_session = GNUNET_malloc(sizeof(struct Session)); | 683 | new_session = GNUNET_malloc (sizeof (struct Session)); |
657 | new_session->connect_addr = GNUNET_malloc(addrlen); | 684 | new_session->connect_addr = GNUNET_malloc (addrlen); |
658 | memcpy(new_session->connect_addr, addr, addrlen); | 685 | memcpy (new_session->connect_addr, addr, addrlen); |
659 | new_session->connect_alen = addrlen; | 686 | new_session->connect_alen = addrlen; |
660 | #if DEBUG_UDP | 687 | #if DEBUG_UDP |
661 | if (memcmp(target, plugin->env->my_identity, sizeof(struct GNUNET_PeerIdentity)) == 0) | 688 | if (memcmp |
689 | (target, plugin->env->my_identity, | ||
690 | sizeof (struct GNUNET_PeerIdentity)) == 0) | ||
662 | { | 691 | { |
663 | GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, "udp", _ | 692 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ |
664 | ("definitely adding self to session list... hmmm\n")); | 693 | ("definitely adding self to session list... hmmm\n")); |
665 | } | 694 | } |
666 | #endif | 695 | #endif |
667 | memcpy(&new_session->target, target, sizeof(struct GNUNET_PeerIdentity)); | 696 | memcpy (&new_session->target, target, sizeof (struct GNUNET_PeerIdentity)); |
668 | new_session->challenge = challenge; | 697 | new_session->challenge = challenge; |
669 | new_session->validated = GNUNET_NO; | 698 | new_session->validated = GNUNET_NO; |
670 | new_session->next = plugin->sessions; | 699 | new_session->next = plugin->sessions; |
671 | plugin->sessions = new_session; | 700 | plugin->sessions = new_session; |
672 | 701 | ||
673 | msg = GNUNET_malloc (sizeof (struct UDPPongMessage)); | 702 | msg = GNUNET_malloc (sizeof (struct UDPPongMessage)); |
674 | msg->header.size = htons(sizeof(struct UDPPongMessage)); | 703 | msg->header.size = htons (sizeof (struct UDPPongMessage)); |
675 | msg->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_PING); | 704 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_PING); |
676 | msg->challenge = htons(challenge); | 705 | msg->challenge = htons (challenge); |
677 | #if DEBUG_UDP | 706 | #if DEBUG_UDP |
678 | GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, "udp", _ | 707 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ |
679 | ("In validate, header size is %d, type %d, challenge %u\n"), ntohs(msg->header.size), ntohs(msg->header.type), ntohl(msg->challenge)); | 708 | ("In validate, header size is %d, type %d, challenge %u\n"), |
709 | ntohs (msg->header.size), ntohs (msg->header.type), | ||
710 | ntohl (msg->challenge)); | ||
680 | #endif | 711 | #endif |
681 | udp_plugin_send(plugin, target, GNUNET_SCHEDULER_PRIORITY_DEFAULT, &msg->header, timeout, NULL, NULL); | 712 | udp_plugin_send (plugin, target, GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
713 | &msg->header, timeout, NULL, NULL); | ||
682 | 714 | ||
683 | return GNUNET_OK; | 715 | return GNUNET_OK; |
684 | } | 716 | } |
@@ -766,39 +798,41 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
766 | service = GNUNET_SERVICE_start ("transport-udp", env->sched, env->cfg); | 798 | service = GNUNET_SERVICE_start ("transport-udp", env->sched, env->cfg); |
767 | if (service == NULL) | 799 | if (service == NULL) |
768 | { | 800 | { |
769 | GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, "udp", _ | 801 | GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "udp", _ |
770 | ("Failed to start service for `%s' transport plugin.\n"), "udp"); | 802 | ("Failed to start service for `%s' transport plugin.\n"), |
803 | "udp"); | ||
771 | return NULL; | 804 | return NULL; |
772 | } | 805 | } |
773 | aport = 0; | 806 | aport = 0; |
774 | if ((GNUNET_OK != | 807 | if ((GNUNET_OK != |
775 | GNUNET_CONFIGURATION_get_value_number (env->cfg, | 808 | GNUNET_CONFIGURATION_get_value_number (env->cfg, |
776 | "transport-udp", | 809 | "transport-udp", |
777 | "PORT", | 810 | "PORT", |
778 | &bport)) || | 811 | &bport)) || |
779 | (bport > 65535) || | 812 | (bport > 65535) || |
780 | ((GNUNET_OK == | 813 | ((GNUNET_OK == |
781 | GNUNET_CONFIGURATION_get_value_number (env->cfg, | 814 | GNUNET_CONFIGURATION_get_value_number (env->cfg, |
782 | "transport-udp", | 815 | "transport-udp", |
783 | "ADVERTISED-PORT", | 816 | "ADVERTISED-PORT", |
784 | &aport)) && (aport > 65535))) | 817 | &aport)) && (aport > 65535))) |
785 | { | 818 | { |
786 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 819 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, |
787 | "udp", | 820 | "udp", |
788 | _ | 821 | _ |
789 | ("Require valid port number for service `%s' in configuration!\n"), | 822 | ("Require valid port number for service `%s' in configuration!\n"), |
790 | "transport-udp"); | 823 | "transport-udp"); |
791 | GNUNET_SERVICE_stop (service); | 824 | GNUNET_SERVICE_stop (service); |
792 | return NULL; | 825 | return NULL; |
793 | } | 826 | } |
794 | if (aport == 0) | 827 | if (aport == 0) |
795 | aport = bport; | 828 | aport = bport; |
796 | 829 | ||
797 | mtu = 1240; | 830 | mtu = 1240; |
798 | if (mtu < 1200) | 831 | if (mtu < 1200) |
799 | GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, | 832 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, |
800 | "udp", | 833 | "udp", |
801 | _("MTU %llu for `%s' is probably too low!\n"), mtu, "UDP"); | 834 | _("MTU %llu for `%s' is probably too low!\n"), mtu, |
835 | "UDP"); | ||
802 | 836 | ||
803 | plugin = GNUNET_malloc (sizeof (struct Plugin)); | 837 | plugin = GNUNET_malloc (sizeof (struct Plugin)); |
804 | plugin->open_port = bport; | 838 | plugin->open_port = bport; |
@@ -818,9 +852,9 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
818 | api->cost_estimate = 17; /* TODO: ATS */ | 852 | api->cost_estimate = 17; /* TODO: ATS */ |
819 | plugin->service = service; | 853 | plugin->service = service; |
820 | 854 | ||
821 | udp_sock = udp_transport_server_start(plugin); | 855 | udp_sock = udp_transport_server_start (plugin); |
822 | 856 | ||
823 | GNUNET_assert(udp_sock != NULL); | 857 | GNUNET_assert (udp_sock != NULL); |
824 | 858 | ||
825 | return api; | 859 | return api; |
826 | } | 860 | } |
@@ -831,7 +865,7 @@ libgnunet_plugin_transport_udp_done (void *cls) | |||
831 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; | 865 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; |
832 | struct Plugin *plugin = api->cls; | 866 | struct Plugin *plugin = api->cls; |
833 | 867 | ||
834 | udp_transport_server_stop(plugin); | 868 | udp_transport_server_stop (plugin); |
835 | if (NULL != hostname_dns) | 869 | if (NULL != hostname_dns) |
836 | { | 870 | { |
837 | GNUNET_RESOLVER_request_cancel (hostname_dns); | 871 | GNUNET_RESOLVER_request_cancel (hostname_dns); |
diff --git a/src/transport/test_plugin_transport.c b/src/transport/test_plugin_transport.c index d4183fc27..407150d3a 100644 --- a/src/transport/test_plugin_transport.c +++ b/src/transport/test_plugin_transport.c | |||
@@ -93,24 +93,20 @@ static int ok; | |||
93 | * Initialize Environment for this plugin | 93 | * Initialize Environment for this plugin |
94 | */ | 94 | */ |
95 | static void | 95 | static void |
96 | receive(void *cls, | 96 | receive (void *cls, |
97 | struct GNUNET_TIME_Relative | 97 | struct GNUNET_TIME_Relative |
98 | latency, | 98 | latency, |
99 | const struct GNUNET_PeerIdentity | 99 | const struct GNUNET_PeerIdentity |
100 | * peer, | 100 | *peer, const struct GNUNET_MessageHeader *message) |
101 | const struct GNUNET_MessageHeader | ||
102 | * message) | ||
103 | { | 101 | { |
104 | /* do nothing */ | 102 | /* do nothing */ |
105 | } | 103 | } |
106 | 104 | ||
107 | void notify_address(void *cls, | 105 | void |
108 | const char *name, | 106 | notify_address (void *cls, |
109 | const void *addr, | 107 | const char *name, |
110 | size_t addrlen, | 108 | const void *addr, |
111 | struct | 109 | size_t addrlen, struct GNUNET_TIME_Relative expires) |
112 | GNUNET_TIME_Relative | ||
113 | expires) | ||
114 | { | 110 | { |
115 | } | 111 | } |
116 | 112 | ||
@@ -122,19 +118,19 @@ void notify_address(void *cls, | |||
122 | * @param cfg configuration to use | 118 | * @param cfg configuration to use |
123 | */ | 119 | */ |
124 | static void | 120 | static void |
125 | unload_plugins (void *cls, | 121 | unload_plugins (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) |
126 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 122 | { |
127 | { | 123 | GNUNET_assert (NULL == |
128 | GNUNET_assert (NULL == GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_tcp",api)); | 124 | GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_tcp", |
125 | api)); | ||
129 | if (my_private_key != NULL) | 126 | if (my_private_key != NULL) |
130 | GNUNET_CRYPTO_rsa_key_free (my_private_key); | 127 | GNUNET_CRYPTO_rsa_key_free (my_private_key); |
131 | 128 | ||
132 | } | 129 | } |
133 | 130 | ||
134 | 131 | ||
135 | static void | 132 | static void |
136 | unload_task (void *cls, | 133 | unload_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
137 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
138 | { | 134 | { |
139 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 135 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
140 | unload_plugins (NULL, cfg); | 136 | unload_plugins (NULL, cfg); |
@@ -144,12 +140,11 @@ unload_task (void *cls, | |||
144 | static GNUNET_SCHEDULER_TaskIdentifier validation_timeout_task; | 140 | static GNUNET_SCHEDULER_TaskIdentifier validation_timeout_task; |
145 | 141 | ||
146 | 142 | ||
147 | static void | 143 | static void |
148 | validation_notification (void *cls, | 144 | validation_notification (void *cls, |
149 | const char *name, | 145 | const char *name, |
150 | const struct GNUNET_PeerIdentity *peer, | 146 | const struct GNUNET_PeerIdentity *peer, |
151 | uint32_t challenge, | 147 | uint32_t challenge, const char *sender_addr) |
152 | const char *sender_addr) | ||
153 | { | 148 | { |
154 | if (validation_timeout_task != GNUNET_SCHEDULER_NO_TASK) | 149 | if (validation_timeout_task != GNUNET_SCHEDULER_NO_TASK) |
155 | { | 150 | { |
@@ -158,24 +153,23 @@ validation_notification (void *cls, | |||
158 | } | 153 | } |
159 | 154 | ||
160 | GNUNET_assert (challenge == 42); | 155 | GNUNET_assert (challenge == 42); |
161 | 156 | ||
162 | ok = 0; /* if the last test succeeded, report success */ | 157 | ok = 0; /* if the last test succeeded, report success */ |
163 | GNUNET_SCHEDULER_add_continuation (sched, | 158 | GNUNET_SCHEDULER_add_continuation (sched, |
164 | &unload_task, | 159 | &unload_task, |
165 | (void*) cfg, | 160 | (void *) cfg, |
166 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 161 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
167 | } | 162 | } |
168 | 163 | ||
169 | 164 | ||
170 | static void | 165 | static void |
171 | validation_failed (void *cls, | 166 | validation_failed (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
172 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
173 | { | 167 | { |
174 | validation_timeout_task = GNUNET_SCHEDULER_NO_TASK; | 168 | validation_timeout_task = GNUNET_SCHEDULER_NO_TASK; |
175 | GNUNET_break (0); /* output error */ | 169 | GNUNET_break (0); /* output error */ |
176 | /* the "validation_notification" was not called | 170 | /* the "validation_notification" was not called |
177 | in a timely fashion; we should set an error | 171 | in a timely fashion; we should set an error |
178 | code for main and shut down */ | 172 | code for main and shut down */ |
179 | unload_plugins (NULL, cfg); | 173 | unload_plugins (NULL, cfg); |
180 | } | 174 | } |
181 | 175 | ||
@@ -198,42 +192,36 @@ static void | |||
198 | test_validation () | 192 | test_validation () |
199 | { | 193 | { |
200 | struct sockaddr_in soaddr; | 194 | struct sockaddr_in soaddr; |
201 | 195 | ||
202 | memset (&soaddr, 0, sizeof(soaddr)); | 196 | memset (&soaddr, 0, sizeof (soaddr)); |
203 | #if HAVE_SOCKADDR_IN_SIN_LEN | 197 | #if HAVE_SOCKADDR_IN_SIN_LEN |
204 | soaddr.sin_len = sizeof (soaddr); | 198 | soaddr.sin_len = sizeof (soaddr); |
205 | #endif | 199 | #endif |
206 | soaddr.sin_family = AF_INET; | 200 | soaddr.sin_family = AF_INET; |
207 | soaddr.sin_port = htons(2368 /* FIXME: get from config! */); | 201 | soaddr.sin_port = htons (2368 /* FIXME: get from config! */ ); |
208 | soaddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); | 202 | soaddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
209 | api->validate (api->cls, | 203 | api->validate (api->cls, |
210 | &my_identity, | 204 | &my_identity, 42, TIMEOUT, &soaddr, sizeof (soaddr)); |
211 | 42, | ||
212 | TIMEOUT, | ||
213 | &soaddr, | ||
214 | sizeof(soaddr)); | ||
215 | /* add job to catch failure (timeout) */ | 205 | /* add job to catch failure (timeout) */ |
216 | validation_timeout_task = | 206 | validation_timeout_task = |
217 | GNUNET_SCHEDULER_add_delayed (sched, | 207 | GNUNET_SCHEDULER_add_delayed (sched, TIMEOUT, &validation_failed, NULL); |
218 | TIMEOUT, | ||
219 | &validation_failed, | ||
220 | NULL); | ||
221 | } | 208 | } |
222 | 209 | ||
223 | 210 | ||
224 | static void setup_plugin_environment() | 211 | static void |
212 | setup_plugin_environment () | ||
225 | { | 213 | { |
226 | env.cfg = cfg; | 214 | env.cfg = cfg; |
227 | env.sched = sched; | 215 | env.sched = sched; |
228 | env.my_public_key = &my_public_key; | 216 | env.my_public_key = &my_public_key; |
229 | env.my_private_key = my_private_key; | 217 | env.my_private_key = my_private_key; |
230 | env.my_identity = &my_identity; | 218 | env.my_identity = &my_identity; |
231 | env.cls=&env; | 219 | env.cls = &env; |
232 | env.receive=&receive; | 220 | env.receive = &receive; |
233 | env.notify_address=¬ify_address; | 221 | env.notify_address = ¬ify_address; |
234 | env.notify_validation = &validation_notification; | 222 | env.notify_validation = &validation_notification; |
235 | env.max_connections = max_connect_per_transport; | 223 | env.max_connections = max_connect_per_transport; |
236 | } | 224 | } |
237 | 225 | ||
238 | 226 | ||
239 | /** | 227 | /** |
@@ -247,9 +235,8 @@ static void | |||
247 | run (void *cls, | 235 | run (void *cls, |
248 | struct GNUNET_SCHEDULER_Handle *s, | 236 | struct GNUNET_SCHEDULER_Handle *s, |
249 | char *const *args, | 237 | char *const *args, |
250 | const char *cfgfile, | 238 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) |
251 | const struct GNUNET_CONFIGURATION_Handle *c) | 239 | { |
252 | { | ||
253 | unsigned long long tneigh; | 240 | unsigned long long tneigh; |
254 | char *keyfile; | 241 | char *keyfile; |
255 | char *libname; | 242 | char *libname; |
@@ -268,7 +255,8 @@ run (void *cls, | |||
268 | "HOSTKEY", &keyfile))) | 255 | "HOSTKEY", &keyfile))) |
269 | { | 256 | { |
270 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 257 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
271 | _("Transport service is lacking key configuration settings. Exiting.\n")); | 258 | _ |
259 | ("Transport service is lacking key configuration settings. Exiting.\n")); | ||
272 | GNUNET_SCHEDULER_shutdown (s); | 260 | GNUNET_SCHEDULER_shutdown (s); |
273 | return; | 261 | return; |
274 | } | 262 | } |
@@ -278,25 +266,23 @@ run (void *cls, | |||
278 | if (my_private_key == NULL) | 266 | if (my_private_key == NULL) |
279 | { | 267 | { |
280 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 268 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
281 | _("Transport service could not access hostkey. Exiting.\n")); | 269 | _ |
270 | ("Transport service could not access hostkey. Exiting.\n")); | ||
282 | GNUNET_SCHEDULER_shutdown (s); | 271 | GNUNET_SCHEDULER_shutdown (s); |
283 | return; | 272 | return; |
284 | } | 273 | } |
285 | GNUNET_CRYPTO_rsa_key_get_public (my_private_key, | 274 | GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); |
286 | &my_public_key); | ||
287 | GNUNET_CRYPTO_hash (&my_public_key, | 275 | GNUNET_CRYPTO_hash (&my_public_key, |
288 | sizeof (my_public_key), | 276 | sizeof (my_public_key), &my_identity.hashPubKey); |
289 | &my_identity.hashPubKey); | 277 | |
290 | 278 | ||
291 | 279 | ||
292 | 280 | /* load plugins... */ | |
293 | /* load plugins... */ | 281 | setup_plugin_environment (); |
294 | setup_plugin_environment(); | 282 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading tcp transport plugin\n")); |
295 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
296 | _("Loading tcp transport plugin\n")); | ||
297 | GNUNET_asprintf (&libname, "libgnunet_plugin_transport_tcp"); | 283 | GNUNET_asprintf (&libname, "libgnunet_plugin_transport_tcp"); |
298 | 284 | ||
299 | api = GNUNET_PLUGIN_load(libname, &env); | 285 | api = GNUNET_PLUGIN_load (libname, &env); |
300 | GNUNET_free (libname); | 286 | GNUNET_free (libname); |
301 | if (api == NULL) | 287 | if (api == NULL) |
302 | { | 288 | { |
@@ -304,7 +290,7 @@ run (void *cls, | |||
304 | _("Failed to load transport plugin for tcp\n")); | 290 | _("Failed to load transport plugin for tcp\n")); |
305 | /* FIXME: set some error code for main */ | 291 | /* FIXME: set some error code for main */ |
306 | return; | 292 | return; |
307 | } | 293 | } |
308 | test_validation (); | 294 | test_validation (); |
309 | } | 295 | } |
310 | 296 | ||
@@ -334,22 +320,20 @@ main (int argc, char *const *argv) | |||
334 | "WARNING", | 320 | "WARNING", |
335 | #endif | 321 | #endif |
336 | NULL | 322 | NULL |
337 | }; | 323 | }; |
338 | GNUNET_log_setup ("test-plugin-transport", | 324 | GNUNET_log_setup ("test-plugin-transport", |
339 | #if VERBOSE | 325 | #if VERBOSE |
340 | "DEBUG", | 326 | "DEBUG", |
341 | #else | 327 | #else |
342 | "WARNING", | 328 | "WARNING", |
343 | #endif | 329 | #endif |
344 | NULL); | 330 | NULL); |
345 | ok = 1; /* set to fail */ | 331 | ok = 1; /* set to fail */ |
346 | ret = (GNUNET_OK == | 332 | ret = (GNUNET_OK == |
347 | GNUNET_PROGRAM_run (5, | 333 | GNUNET_PROGRAM_run (5, |
348 | argv_prog, | 334 | argv_prog, |
349 | "test-plugin-transport", | 335 | "test-plugin-transport", |
350 | "testcase", | 336 | "testcase", options, &run, NULL)) ? ok : 1; |
351 | options, | ||
352 | &run, NULL)) ? ok : 1; | ||
353 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-plugin-transport"); | 337 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-plugin-transport"); |
354 | return ret; | 338 | return ret; |
355 | } | 339 | } |
diff --git a/src/transport/test_plugin_transport_udp.c b/src/transport/test_plugin_transport_udp.c index 27140a311..62e12e1cd 100644 --- a/src/transport/test_plugin_transport_udp.c +++ b/src/transport/test_plugin_transport_udp.c | |||
@@ -94,24 +94,20 @@ static int ok; | |||
94 | * Initialize Environment for this plugin | 94 | * Initialize Environment for this plugin |
95 | */ | 95 | */ |
96 | static void | 96 | static void |
97 | receive(void *cls, | 97 | receive (void *cls, |
98 | struct GNUNET_TIME_Relative | 98 | struct GNUNET_TIME_Relative |
99 | latency, | 99 | latency, |
100 | const struct GNUNET_PeerIdentity | 100 | const struct GNUNET_PeerIdentity |
101 | * peer, | 101 | *peer, const struct GNUNET_MessageHeader *message) |
102 | const struct GNUNET_MessageHeader | ||
103 | * message) | ||
104 | { | 102 | { |
105 | /* do nothing */ | 103 | /* do nothing */ |
106 | } | 104 | } |
107 | 105 | ||
108 | void notify_address(void *cls, | 106 | void |
109 | const char *name, | 107 | notify_address (void *cls, |
110 | const void *addr, | 108 | const char *name, |
111 | size_t addrlen, | 109 | const void *addr, |
112 | struct | 110 | size_t addrlen, struct GNUNET_TIME_Relative expires) |
113 | GNUNET_TIME_Relative | ||
114 | expires) | ||
115 | { | 111 | { |
116 | } | 112 | } |
117 | 113 | ||
@@ -123,10 +119,11 @@ void notify_address(void *cls, | |||
123 | * @param cfg configuration to use | 119 | * @param cfg configuration to use |
124 | */ | 120 | */ |
125 | static void | 121 | static void |
126 | unload_plugins (void *cls, | 122 | unload_plugins (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) |
127 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
128 | { | 123 | { |
129 | GNUNET_assert (NULL == GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_udp",api)); | 124 | GNUNET_assert (NULL == |
125 | GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_udp", | ||
126 | api)); | ||
130 | if (my_private_key != NULL) | 127 | if (my_private_key != NULL) |
131 | GNUNET_CRYPTO_rsa_key_free (my_private_key); | 128 | GNUNET_CRYPTO_rsa_key_free (my_private_key); |
132 | 129 | ||
@@ -134,8 +131,7 @@ unload_plugins (void *cls, | |||
134 | 131 | ||
135 | 132 | ||
136 | static void | 133 | static void |
137 | unload_task (void *cls, | 134 | unload_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
138 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
139 | { | 135 | { |
140 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 136 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
141 | unload_plugins (NULL, cfg); | 137 | unload_plugins (NULL, cfg); |
@@ -149,8 +145,7 @@ static void | |||
149 | validation_notification (void *cls, | 145 | validation_notification (void *cls, |
150 | const char *name, | 146 | const char *name, |
151 | const struct GNUNET_PeerIdentity *peer, | 147 | const struct GNUNET_PeerIdentity *peer, |
152 | uint32_t challenge, | 148 | uint32_t challenge, const char *sender_addr) |
153 | const char *sender_addr) | ||
154 | { | 149 | { |
155 | if (validation_timeout_task != GNUNET_SCHEDULER_NO_TASK) | 150 | if (validation_timeout_task != GNUNET_SCHEDULER_NO_TASK) |
156 | { | 151 | { |
@@ -160,21 +155,20 @@ validation_notification (void *cls, | |||
160 | 155 | ||
161 | GNUNET_assert (challenge == 42); | 156 | GNUNET_assert (challenge == 42); |
162 | 157 | ||
163 | ok = 0; /* if the last test succeeded, report success */ | 158 | ok = 0; /* if the last test succeeded, report success */ |
164 | 159 | ||
165 | GNUNET_SCHEDULER_add_continuation (sched, | 160 | GNUNET_SCHEDULER_add_continuation (sched, |
166 | &unload_task, | 161 | &unload_task, |
167 | (void*) cfg, | 162 | (void *) cfg, |
168 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 163 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
169 | } | 164 | } |
170 | 165 | ||
171 | 166 | ||
172 | static void | 167 | static void |
173 | validation_failed (void *cls, | 168 | validation_failed (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
174 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
175 | { | 169 | { |
176 | validation_timeout_task = GNUNET_SCHEDULER_NO_TASK; | 170 | validation_timeout_task = GNUNET_SCHEDULER_NO_TASK; |
177 | GNUNET_break (0); /* output error */ | 171 | GNUNET_break (0); /* output error */ |
178 | /* the "validation_notification" was not called | 172 | /* the "validation_notification" was not called |
179 | in a timely fashion; we should set an error | 173 | in a timely fashion; we should set an error |
180 | code for main and shut down */ | 174 | code for main and shut down */ |
@@ -201,43 +195,38 @@ test_validation () | |||
201 | { | 195 | { |
202 | struct sockaddr_in soaddr; | 196 | struct sockaddr_in soaddr; |
203 | 197 | ||
204 | memset (&soaddr, 0, sizeof(soaddr)); | 198 | memset (&soaddr, 0, sizeof (soaddr)); |
205 | #if HAVE_SOCKADDR_IN_SIN_LEN | 199 | #if HAVE_SOCKADDR_IN_SIN_LEN |
206 | soaddr.sin_len = sizeof (soaddr); | 200 | soaddr.sin_len = sizeof (soaddr); |
207 | #endif | 201 | #endif |
208 | soaddr.sin_family = AF_INET; | 202 | soaddr.sin_family = AF_INET; |
209 | soaddr.sin_port = htons(2368 /* FIXME: get from config! */); | 203 | soaddr.sin_port = htons (2368 /* FIXME: get from config! */ ); |
210 | soaddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); | 204 | soaddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
211 | 205 | ||
212 | /* add job to catch failure (timeout) */ | 206 | /* add job to catch failure (timeout) */ |
213 | validation_timeout_task = | 207 | validation_timeout_task = |
214 | GNUNET_SCHEDULER_add_delayed (sched, | 208 | GNUNET_SCHEDULER_add_delayed (sched, TIMEOUT, &validation_failed, NULL); |
215 | TIMEOUT, | ||
216 | &validation_failed, | ||
217 | NULL); | ||
218 | 209 | ||
219 | api->validate (api->cls, | 210 | api->validate (api->cls, |
220 | &my_identity, | 211 | &my_identity, 42, TIMEOUT, &soaddr, sizeof (soaddr)); |
221 | 42, | ||
222 | TIMEOUT, | ||
223 | &soaddr, | ||
224 | sizeof(soaddr)); | ||
225 | } | 212 | } |
226 | 213 | ||
227 | 214 | ||
228 | static void setup_plugin_environment() | 215 | static void |
216 | setup_plugin_environment () | ||
229 | { | 217 | { |
230 | env.cfg = cfg; | 218 | env.cfg = cfg; |
231 | env.sched = sched; | 219 | env.sched = sched; |
232 | env.my_public_key = &my_public_key; | 220 | env.my_public_key = &my_public_key; |
233 | env.my_private_key = my_private_key; | 221 | env.my_private_key = my_private_key; |
234 | env.my_identity = &my_identity; | 222 | env.my_identity = &my_identity; |
235 | env.cls=&env; | 223 | env.cls = &env; |
236 | env.receive=&receive; | 224 | env.receive = &receive; |
237 | env.notify_address=¬ify_address; | 225 | env.notify_address = ¬ify_address; |
238 | env.notify_validation = &validation_notification; | 226 | env.notify_validation = &validation_notification; |
239 | env.max_connections = max_connect_per_transport; | 227 | env.max_connections = max_connect_per_transport; |
240 | } | 228 | } |
229 | |||
241 | static int retx; | 230 | static int retx; |
242 | 231 | ||
243 | /** | 232 | /** |
@@ -251,8 +240,7 @@ static void | |||
251 | run (void *cls, | 240 | run (void *cls, |
252 | struct GNUNET_SCHEDULER_Handle *s, | 241 | struct GNUNET_SCHEDULER_Handle *s, |
253 | char *const *args, | 242 | char *const *args, |
254 | const char *cfgfile, | 243 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) |
255 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
256 | { | 244 | { |
257 | unsigned long long tneigh; | 245 | unsigned long long tneigh; |
258 | char *keyfile; | 246 | char *keyfile; |
@@ -272,7 +260,8 @@ run (void *cls, | |||
272 | "HOSTKEY", &keyfile))) | 260 | "HOSTKEY", &keyfile))) |
273 | { | 261 | { |
274 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 262 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
275 | _("Transport service is lacking key configuration settings. Exiting.\n")); | 263 | _ |
264 | ("Transport service is lacking key configuration settings. Exiting.\n")); | ||
276 | GNUNET_SCHEDULER_shutdown (s); | 265 | GNUNET_SCHEDULER_shutdown (s); |
277 | return; | 266 | return; |
278 | } | 267 | } |
@@ -282,23 +271,21 @@ run (void *cls, | |||
282 | if (my_private_key == NULL) | 271 | if (my_private_key == NULL) |
283 | { | 272 | { |
284 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 273 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
285 | _("Transport service could not access hostkey. Exiting.\n")); | 274 | _ |
275 | ("Transport service could not access hostkey. Exiting.\n")); | ||
286 | GNUNET_SCHEDULER_shutdown (s); | 276 | GNUNET_SCHEDULER_shutdown (s); |
287 | return; | 277 | return; |
288 | } | 278 | } |
289 | GNUNET_CRYPTO_rsa_key_get_public (my_private_key, | 279 | GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); |
290 | &my_public_key); | ||
291 | GNUNET_CRYPTO_hash (&my_public_key, | 280 | GNUNET_CRYPTO_hash (&my_public_key, |
292 | sizeof (my_public_key), | 281 | sizeof (my_public_key), &my_identity.hashPubKey); |
293 | &my_identity.hashPubKey); | ||
294 | 282 | ||
295 | /* load plugins... */ | 283 | /* load plugins... */ |
296 | setup_plugin_environment(); | 284 | setup_plugin_environment (); |
297 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 285 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading udp transport plugin\n")); |
298 | _("Loading udp transport plugin\n")); | ||
299 | GNUNET_asprintf (&libname, "libgnunet_plugin_transport_udp"); | 286 | GNUNET_asprintf (&libname, "libgnunet_plugin_transport_udp"); |
300 | 287 | ||
301 | api = GNUNET_PLUGIN_load(libname, &env); | 288 | api = GNUNET_PLUGIN_load (libname, &env); |
302 | GNUNET_free (libname); | 289 | GNUNET_free (libname); |
303 | if (api == NULL) | 290 | if (api == NULL) |
304 | { | 291 | { |
@@ -344,14 +331,12 @@ main (int argc, char *const *argv) | |||
344 | "WARNING", | 331 | "WARNING", |
345 | #endif | 332 | #endif |
346 | NULL); | 333 | NULL); |
347 | ok = 1; /* set to fail */ | 334 | ok = 1; /* set to fail */ |
348 | ret = (GNUNET_OK == | 335 | ret = (GNUNET_OK == |
349 | GNUNET_PROGRAM_run (5, | 336 | GNUNET_PROGRAM_run (5, |
350 | argv_prog, | 337 | argv_prog, |
351 | "test-plugin-transport", | 338 | "test-plugin-transport", |
352 | "testcase", | 339 | "testcase", options, &run, NULL)) ? ok : 1; |
353 | options, | ||
354 | &run, NULL)) ? ok : 1; | ||
355 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-plugin-transport"); | 340 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-plugin-transport"); |
356 | return ret; | 341 | return ret; |
357 | } | 342 | } |
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c index 90e12d75b..a5afc5fe4 100644 --- a/src/transport/test_transport_api.c +++ b/src/transport/test_transport_api.c | |||
@@ -120,10 +120,8 @@ notify_connect (void *cls, | |||
120 | const struct GNUNET_PeerIdentity *peer, | 120 | const struct GNUNET_PeerIdentity *peer, |
121 | struct GNUNET_TIME_Relative latency) | 121 | struct GNUNET_TIME_Relative latency) |
122 | { | 122 | { |
123 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 123 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
124 | "Peer `%4s' connected to us (%p)!\n", | 124 | "Peer `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls); |
125 | GNUNET_i2s(peer), | ||
126 | cls); | ||
127 | GNUNET_assert ((ok >= 1) && (ok <= 6)); | 125 | GNUNET_assert ((ok >= 1) && (ok <= 6)); |
128 | OKPP; | 126 | OKPP; |
129 | } | 127 | } |
@@ -197,14 +195,15 @@ exchange_hello_last (void *cls, | |||
197 | GNUNET_assert (message != NULL); | 195 | GNUNET_assert (message != NULL); |
198 | GNUNET_assert (GNUNET_OK == | 196 | GNUNET_assert (GNUNET_OK == |
199 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) | 197 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) |
200 | message, &me->id)); | 198 | message, &me->id)); |
201 | GNUNET_TRANSPORT_offer_hello (p1.th, message); | 199 | GNUNET_TRANSPORT_offer_hello (p1.th, message); |
202 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 200 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
203 | "Finished exchanging HELLOs, now waiting for transmission!\n"); | 201 | "Finished exchanging HELLOs, now waiting for transmission!\n"); |
204 | /* both HELLOs exchanged, get ready to test transmission! */ | 202 | /* both HELLOs exchanged, get ready to test transmission! */ |
205 | GNUNET_TRANSPORT_notify_transmit_ready (p1.th, | 203 | GNUNET_TRANSPORT_notify_transmit_ready (p1.th, |
206 | &p2.id, | 204 | &p2.id, |
207 | 256, 0, TIMEOUT, ¬ify_ready, &p1); | 205 | 256, 0, TIMEOUT, ¬ify_ready, |
206 | &p1); | ||
208 | } | 207 | } |
209 | 208 | ||
210 | 209 | ||
@@ -223,10 +222,8 @@ exchange_hello (void *cls, | |||
223 | GNUNET_assert (message != NULL); | 222 | GNUNET_assert (message != NULL); |
224 | GNUNET_assert (GNUNET_OK == | 223 | GNUNET_assert (GNUNET_OK == |
225 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) | 224 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) |
226 | message, &me->id)); | 225 | message, &me->id)); |
227 | GNUNET_TRANSPORT_get_hello (p2.th, | 226 | GNUNET_TRANSPORT_get_hello (p2.th, TIMEOUT, &exchange_hello_last, &p2); |
228 | TIMEOUT, | ||
229 | &exchange_hello_last, &p2); | ||
230 | } | 227 | } |
231 | 228 | ||
232 | 229 | ||
@@ -234,16 +231,14 @@ static void | |||
234 | run (void *cls, | 231 | run (void *cls, |
235 | struct GNUNET_SCHEDULER_Handle *s, | 232 | struct GNUNET_SCHEDULER_Handle *s, |
236 | char *const *args, | 233 | char *const *args, |
237 | const char *cfgfile, | 234 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
238 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
239 | { | 235 | { |
240 | GNUNET_assert (ok == 1); | 236 | GNUNET_assert (ok == 1); |
241 | OKPP; | 237 | OKPP; |
242 | sched = s; | 238 | sched = s; |
243 | setup_peer (&p1, "test_transport_api_peer1.conf"); | 239 | setup_peer (&p1, "test_transport_api_peer1.conf"); |
244 | setup_peer (&p2, "test_transport_api_peer2.conf"); | 240 | setup_peer (&p2, "test_transport_api_peer2.conf"); |
245 | GNUNET_TRANSPORT_get_hello (p1.th, | 241 | GNUNET_TRANSPORT_get_hello (p1.th, TIMEOUT, &exchange_hello, &p1); |
246 | TIMEOUT, &exchange_hello, &p1); | ||
247 | } | 242 | } |
248 | 243 | ||
249 | 244 | ||
@@ -253,7 +248,7 @@ stop_arm (struct PeerContext *p) | |||
253 | #if START_ARM | 248 | #if START_ARM |
254 | if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) | 249 | if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) |
255 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 250 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
256 | GNUNET_OS_process_wait(p->arm_pid); | 251 | GNUNET_OS_process_wait (p->arm_pid); |
257 | #endif | 252 | #endif |
258 | GNUNET_CONFIGURATION_destroy (p->cfg); | 253 | GNUNET_CONFIGURATION_destroy (p->cfg); |
259 | } | 254 | } |
@@ -296,7 +291,7 @@ main (int argc, char *argv[]) | |||
296 | #endif | 291 | #endif |
297 | NULL); | 292 | NULL); |
298 | ret = check (); | 293 | ret = check (); |
299 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-1"); | 294 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-1"); |
300 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-2"); | 295 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-2"); |
301 | return ret; | 296 | return ret; |
302 | } | 297 | } |
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c index 7adec78c9..155347bf0 100644 --- a/src/transport/transport_api.c +++ b/src/transport/transport_api.c | |||
@@ -379,7 +379,7 @@ transport_notify_ready (void *cls, size_t size, void *buf) | |||
379 | { | 379 | { |
380 | #if DEBUG_TRANSPORT | 380 | #if DEBUG_TRANSPORT |
381 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 381 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
382 | "Could not transmit to transport service, cancelling pending requests\n"); | 382 | "Could not transmit to transport service, cancelling pending requests\n"); |
383 | #endif | 383 | #endif |
384 | th = h->connect_ready_head; | 384 | th = h->connect_ready_head; |
385 | if (th->next != NULL) | 385 | if (th->next != NULL) |
@@ -391,17 +391,16 @@ transport_notify_ready (void *cls, size_t size, void *buf) | |||
391 | n->transmit_handle = NULL; | 391 | n->transmit_handle = NULL; |
392 | } | 392 | } |
393 | if (th->notify_delay_task != GNUNET_SCHEDULER_NO_TASK) | 393 | if (th->notify_delay_task != GNUNET_SCHEDULER_NO_TASK) |
394 | { | 394 | { |
395 | GNUNET_SCHEDULER_cancel (h->sched, | 395 | GNUNET_SCHEDULER_cancel (h->sched, th->notify_delay_task); |
396 | th->notify_delay_task); | 396 | th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK; |
397 | th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK; | 397 | } |
398 | } | ||
399 | GNUNET_assert (0 == th->notify (th->notify_cls, 0, NULL)); | 398 | GNUNET_assert (0 == th->notify (th->notify_cls, 0, NULL)); |
400 | GNUNET_free (th); | 399 | GNUNET_free (th); |
401 | if (h->connect_ready_head != NULL) | 400 | if (h->connect_ready_head != NULL) |
402 | schedule_transmission (h); /* FIXME: is this ok? */ | 401 | schedule_transmission (h); /* FIXME: is this ok? */ |
403 | return 0; | 402 | return 0; |
404 | } | 403 | } |
405 | #if DEBUG_TRANSPORT | 404 | #if DEBUG_TRANSPORT |
406 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 405 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
407 | "Ready to transmit %u bytes to transport service\n", size); | 406 | "Ready to transmit %u bytes to transport service\n", size); |
@@ -415,11 +414,10 @@ transport_notify_ready (void *cls, size_t size, void *buf) | |||
415 | { | 414 | { |
416 | th = h->connect_ready_head; | 415 | th = h->connect_ready_head; |
417 | if (th->notify_delay_task != GNUNET_SCHEDULER_NO_TASK) | 416 | if (th->notify_delay_task != GNUNET_SCHEDULER_NO_TASK) |
418 | { | 417 | { |
419 | GNUNET_SCHEDULER_cancel (h->sched, | 418 | GNUNET_SCHEDULER_cancel (h->sched, th->notify_delay_task); |
420 | th->notify_delay_task); | 419 | th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK; |
421 | th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK; | 420 | } |
422 | } | ||
423 | GNUNET_assert (th->notify_size <= size); | 421 | GNUNET_assert (th->notify_size <= size); |
424 | if (th->next != NULL) | 422 | if (th->next != NULL) |
425 | th->next->prev = NULL; | 423 | th->next->prev = NULL; |
@@ -458,18 +456,17 @@ schedule_transmission (struct GNUNET_TRANSPORT_Handle *h) | |||
458 | if (h->client == NULL) | 456 | if (h->client == NULL) |
459 | { | 457 | { |
460 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 458 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
461 | "Could not yet schedule transmission: we are not yet connected to the transport service!\n"); | 459 | "Could not yet schedule transmission: we are not yet connected to the transport service!\n"); |
462 | return; /* not yet connected */ | 460 | return; /* not yet connected */ |
463 | } | 461 | } |
464 | th = h->connect_ready_head; | 462 | th = h->connect_ready_head; |
465 | if (th == NULL) | 463 | if (th == NULL) |
466 | return; /* no request pending */ | 464 | return; /* no request pending */ |
467 | if (th->notify_delay_task != GNUNET_SCHEDULER_NO_TASK) | 465 | if (th->notify_delay_task != GNUNET_SCHEDULER_NO_TASK) |
468 | { | 466 | { |
469 | /* remove existing time out task, will be integrated | 467 | /* remove existing time out task, will be integrated |
470 | with transmit_ready notification! */ | 468 | with transmit_ready notification! */ |
471 | GNUNET_SCHEDULER_cancel (h->sched, | 469 | GNUNET_SCHEDULER_cancel (h->sched, th->notify_delay_task); |
472 | th->notify_delay_task); | ||
473 | th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK; | 470 | th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK; |
474 | } | 471 | } |
475 | h->transmission_scheduled = GNUNET_YES; | 472 | h->transmission_scheduled = GNUNET_YES; |
@@ -477,7 +474,7 @@ schedule_transmission (struct GNUNET_TRANSPORT_Handle *h) | |||
477 | th->notify_size, | 474 | th->notify_size, |
478 | GNUNET_TIME_absolute_get_remaining | 475 | GNUNET_TIME_absolute_get_remaining |
479 | (th->timeout), | 476 | (th->timeout), |
480 | GNUNET_NO, | 477 | GNUNET_NO, |
481 | &transport_notify_ready, | 478 | &transport_notify_ready, |
482 | h); | 479 | h); |
483 | GNUNET_assert (NULL != h->network_handle); | 480 | GNUNET_assert (NULL != h->network_handle); |
@@ -564,8 +561,7 @@ remove_from_any_list (struct GNUNET_TRANSPORT_TransmitHandle *th) | |||
564 | * @param th handle for a request to transmit once we | 561 | * @param th handle for a request to transmit once we |
565 | * have connected | 562 | * have connected |
566 | */ | 563 | */ |
567 | static void | 564 | static void try_connect (struct GNUNET_TRANSPORT_TransmitHandle *th); |
568 | try_connect (struct GNUNET_TRANSPORT_TransmitHandle *th); | ||
569 | 565 | ||
570 | 566 | ||
571 | /** | 567 | /** |
@@ -575,7 +571,8 @@ try_connect (struct GNUNET_TRANSPORT_TransmitHandle *th); | |||
575 | * TransmitHandle. | 571 | * TransmitHandle. |
576 | */ | 572 | */ |
577 | static void | 573 | static void |
578 | peer_transmit_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 574 | peer_transmit_timeout (void *cls, |
575 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
579 | { | 576 | { |
580 | struct GNUNET_TRANSPORT_TransmitHandle *th = cls; | 577 | struct GNUNET_TRANSPORT_TransmitHandle *th = cls; |
581 | 578 | ||
@@ -583,9 +580,9 @@ peer_transmit_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
583 | if (th->neighbour != NULL) | 580 | if (th->neighbour != NULL) |
584 | th->neighbour->transmit_handle = NULL; | 581 | th->neighbour->transmit_handle = NULL; |
585 | #if DEBUG_TRANSPORT | 582 | #if DEBUG_TRANSPORT |
586 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 583 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
587 | "Request for transmission to peer `%s' timed out.\n", | 584 | "Request for transmission to peer `%s' timed out.\n", |
588 | GNUNET_i2s(&th->target)); | 585 | GNUNET_i2s (&th->target)); |
589 | #endif | 586 | #endif |
590 | remove_from_any_list (th); | 587 | remove_from_any_list (th); |
591 | th->notify (th->notify_cls, 0, NULL); | 588 | th->notify (th->notify_cls, 0, NULL); |
@@ -619,9 +616,8 @@ schedule_control_transmit (struct GNUNET_TRANSPORT_Handle *h, | |||
619 | 616 | ||
620 | #if DEBUG_TRANSPORT | 617 | #if DEBUG_TRANSPORT |
621 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 618 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
622 | "Control transmit of %u bytes within %llums requested\n", | 619 | "Control transmit of %u bytes within %llums requested\n", |
623 | size, | 620 | size, (unsigned long long) timeout.value); |
624 | (unsigned long long) timeout.value); | ||
625 | #endif | 621 | #endif |
626 | th = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_TransmitHandle)); | 622 | th = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_TransmitHandle)); |
627 | th->handle = h; | 623 | th->handle = h; |
@@ -629,10 +625,9 @@ schedule_control_transmit (struct GNUNET_TRANSPORT_Handle *h, | |||
629 | th->notify_cls = notify_cls; | 625 | th->notify_cls = notify_cls; |
630 | th->timeout = GNUNET_TIME_relative_to_absolute (timeout); | 626 | th->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
631 | th->notify_size = size; | 627 | th->notify_size = size; |
632 | th->notify_delay_task | 628 | th->notify_delay_task |
633 | = GNUNET_SCHEDULER_add_delayed (h->sched, | 629 | = GNUNET_SCHEDULER_add_delayed (h->sched, |
634 | timeout, | 630 | timeout, &peer_transmit_timeout, th); |
635 | &peer_transmit_timeout, th); | ||
636 | if (at_head) | 631 | if (at_head) |
637 | { | 632 | { |
638 | th->next = h->connect_ready_head; | 633 | th->next = h->connect_ready_head; |
@@ -798,14 +793,16 @@ hello_wait_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
798 | { | 793 | { |
799 | #if DEBUG_TRANSPORT | 794 | #if DEBUG_TRANSPORT |
800 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 795 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
801 | _("First attempt to obtain `%s' from transport service failed, will try again for %llums.\n"), | 796 | _ |
802 | "HELLO", | 797 | ("First attempt to obtain `%s' from transport service failed, will try again for %llums.\n"), |
803 | GNUNET_TIME_absolute_get_remaining (hwl->timeout).value); | 798 | "HELLO", |
799 | GNUNET_TIME_absolute_get_remaining (hwl->timeout).value); | ||
804 | #endif | 800 | #endif |
805 | hwl->task = GNUNET_SCHEDULER_add_delayed (hwl->handle->sched, | 801 | hwl->task = GNUNET_SCHEDULER_add_delayed (hwl->handle->sched, |
806 | GNUNET_TIME_absolute_get_remaining (hwl->timeout), | 802 | GNUNET_TIME_absolute_get_remaining |
803 | (hwl->timeout), | ||
807 | &hello_wait_timeout, hwl); | 804 | &hello_wait_timeout, hwl); |
808 | return; | 805 | return; |
809 | } | 806 | } |
810 | /* signal timeout */ | 807 | /* signal timeout */ |
811 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 808 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -988,14 +985,13 @@ request_connect (void *cls, size_t size, void *buf) | |||
988 | #if DEBUG_TRANSPORT | 985 | #if DEBUG_TRANSPORT |
989 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 986 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
990 | "Failed to transmit `%s' request for `%4s' to service.\n", | 987 | "Failed to transmit `%s' request for `%4s' to service.\n", |
991 | "TRY_CONNECT", | 988 | "TRY_CONNECT", GNUNET_i2s (&th->target)); |
992 | GNUNET_i2s(&th->target)); | ||
993 | #endif | 989 | #endif |
994 | if (th->notify_delay_task != GNUNET_SCHEDULER_NO_TASK) | 990 | if (th->notify_delay_task != GNUNET_SCHEDULER_NO_TASK) |
995 | { | 991 | { |
996 | GNUNET_SCHEDULER_cancel (h->sched, th->notify_delay_task); | 992 | GNUNET_SCHEDULER_cancel (h->sched, th->notify_delay_task); |
997 | th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK; | 993 | th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK; |
998 | } | 994 | } |
999 | th->notify (th->notify_cls, 0, NULL); | 995 | th->notify (th->notify_cls, 0, NULL); |
1000 | GNUNET_free (th); | 996 | GNUNET_free (th); |
1001 | return 0; | 997 | return 0; |
@@ -1004,7 +1000,7 @@ request_connect (void *cls, size_t size, void *buf) | |||
1004 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1000 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1005 | "Transmitting `%s' message for `%4s' (need connection in %llu ms).\n", | 1001 | "Transmitting `%s' message for `%4s' (need connection in %llu ms).\n", |
1006 | "TRY_CONNECT", GNUNET_i2s (&th->target), | 1002 | "TRY_CONNECT", GNUNET_i2s (&th->target), |
1007 | GNUNET_TIME_absolute_get_remaining (th->timeout).value); | 1003 | GNUNET_TIME_absolute_get_remaining (th->timeout).value); |
1008 | #endif | 1004 | #endif |
1009 | GNUNET_assert (size >= sizeof (struct TryConnectMessage)); | 1005 | GNUNET_assert (size >= sizeof (struct TryConnectMessage)); |
1010 | tcm = buf; | 1006 | tcm = buf; |
@@ -1014,9 +1010,9 @@ request_connect (void *cls, size_t size, void *buf) | |||
1014 | memcpy (&tcm->peer, &th->target, sizeof (struct GNUNET_PeerIdentity)); | 1010 | memcpy (&tcm->peer, &th->target, sizeof (struct GNUNET_PeerIdentity)); |
1015 | th->notify_delay_task | 1011 | th->notify_delay_task |
1016 | = GNUNET_SCHEDULER_add_delayed (h->sched, | 1012 | = GNUNET_SCHEDULER_add_delayed (h->sched, |
1017 | GNUNET_TIME_absolute_get_remaining | 1013 | GNUNET_TIME_absolute_get_remaining |
1018 | (th->timeout), | 1014 | (th->timeout), |
1019 | &peer_transmit_timeout, th); | 1015 | &peer_transmit_timeout, th); |
1020 | insert_transmit_handle (&h->connect_wait_head, th); | 1016 | insert_transmit_handle (&h->connect_wait_head, th); |
1021 | return sizeof (struct TryConnectMessage); | 1017 | return sizeof (struct TryConnectMessage); |
1022 | } | 1018 | } |
@@ -1033,7 +1029,7 @@ request_connect (void *cls, size_t size, void *buf) | |||
1033 | static void | 1029 | static void |
1034 | try_connect (struct GNUNET_TRANSPORT_TransmitHandle *th) | 1030 | try_connect (struct GNUNET_TRANSPORT_TransmitHandle *th) |
1035 | { | 1031 | { |
1036 | GNUNET_assert (th->notify_delay_task == GNUNET_SCHEDULER_NO_TASK); | 1032 | GNUNET_assert (th->notify_delay_task == GNUNET_SCHEDULER_NO_TASK); |
1037 | schedule_control_transmit (th->handle, | 1033 | schedule_control_transmit (th->handle, |
1038 | sizeof (struct TryConnectMessage), | 1034 | sizeof (struct TryConnectMessage), |
1039 | GNUNET_NO, | 1035 | GNUNET_NO, |
@@ -1050,10 +1046,9 @@ try_connect (struct GNUNET_TRANSPORT_TransmitHandle *th) | |||
1050 | * @param tc scheduler information about why we were triggered (not used) | 1046 | * @param tc scheduler information about why we were triggered (not used) |
1051 | */ | 1047 | */ |
1052 | static void | 1048 | static void |
1053 | try_connect_task (void *cls, | 1049 | try_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1054 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1055 | { | 1050 | { |
1056 | struct GNUNET_TRANSPORT_TransmitHandle *th = cls; | 1051 | struct GNUNET_TRANSPORT_TransmitHandle *th = cls; |
1057 | 1052 | ||
1058 | th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK; | 1053 | th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK; |
1059 | try_connect (th); | 1054 | try_connect (th); |
@@ -1079,14 +1074,12 @@ remove_neighbour (struct GNUNET_TRANSPORT_Handle *h, | |||
1079 | #if DEBUG_TRANSPORT | 1074 | #if DEBUG_TRANSPORT |
1080 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1075 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1081 | "Removing neighbour `%s' from list of connected peers.\n", | 1076 | "Removing neighbour `%s' from list of connected peers.\n", |
1082 | GNUNET_i2s (peer)); | 1077 | GNUNET_i2s (peer)); |
1083 | #endif | 1078 | #endif |
1084 | prev = NULL; | 1079 | prev = NULL; |
1085 | pos = h->neighbours; | 1080 | pos = h->neighbours; |
1086 | while ((pos != NULL) && | 1081 | while ((pos != NULL) && |
1087 | (0 != memcmp (peer, | 1082 | (0 != memcmp (peer, &pos->id, sizeof (struct GNUNET_PeerIdentity)))) |
1088 | &pos->id, | ||
1089 | sizeof (struct GNUNET_PeerIdentity)))) | ||
1090 | { | 1083 | { |
1091 | prev = pos; | 1084 | prev = pos; |
1092 | pos = pos->next; | 1085 | pos = pos->next; |
@@ -1105,29 +1098,31 @@ remove_neighbour (struct GNUNET_TRANSPORT_Handle *h, | |||
1105 | pos->transmit_handle = NULL; | 1098 | pos->transmit_handle = NULL; |
1106 | th->neighbour = NULL; | 1099 | th->neighbour = NULL; |
1107 | remove_from_any_list (th); | 1100 | remove_from_any_list (th); |
1108 | if (GNUNET_TIME_absolute_get_remaining (th->timeout).value <= CONNECT_RETRY_TIMEOUT.value) | 1101 | if (GNUNET_TIME_absolute_get_remaining (th->timeout).value <= |
1109 | { | 1102 | CONNECT_RETRY_TIMEOUT.value) |
1110 | /* signal error */ | 1103 | { |
1111 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1104 | /* signal error */ |
1112 | _("Connection with `%4s' failed and timeout was in the past, giving up on message delivery.\n"), | 1105 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1113 | GNUNET_i2s (peer)); | 1106 | _ |
1114 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == th->notify_delay_task); | 1107 | ("Connection with `%4s' failed and timeout was in the past, giving up on message delivery.\n"), |
1115 | peer_transmit_timeout (th, NULL); | 1108 | GNUNET_i2s (peer)); |
1116 | } | 1109 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == th->notify_delay_task); |
1110 | peer_transmit_timeout (th, NULL); | ||
1111 | } | ||
1117 | else | 1112 | else |
1118 | { | 1113 | { |
1119 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1114 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1120 | _("Connection with `%4s' failed, will keep trying for %llu ms to deliver message\n"), | 1115 | _ |
1121 | GNUNET_i2s (peer), | 1116 | ("Connection with `%4s' failed, will keep trying for %llu ms to deliver message\n"), |
1122 | GNUNET_TIME_absolute_get_remaining (th->timeout).value); | 1117 | GNUNET_i2s (peer), |
1123 | /* try again in a bit */ | 1118 | GNUNET_TIME_absolute_get_remaining (th->timeout).value); |
1124 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == th->notify_delay_task); | 1119 | /* try again in a bit */ |
1125 | th->notify_delay_task | 1120 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == th->notify_delay_task); |
1126 | = GNUNET_SCHEDULER_add_delayed (h->sched, | 1121 | th->notify_delay_task |
1127 | CONNECT_RETRY_TIMEOUT, | 1122 | = GNUNET_SCHEDULER_add_delayed (h->sched, |
1128 | &try_connect_task, | 1123 | CONNECT_RETRY_TIMEOUT, |
1129 | th); | 1124 | &try_connect_task, th); |
1130 | } | 1125 | } |
1131 | } | 1126 | } |
1132 | if (h->nc_cb != NULL) | 1127 | if (h->nc_cb != NULL) |
1133 | h->nd_cb (h->cls, peer); | 1128 | h->nd_cb (h->cls, peer); |
@@ -1170,12 +1165,11 @@ reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1170 | if (pos->next != NULL) | 1165 | if (pos->next != NULL) |
1171 | pos->next->prev = pos->prev; | 1166 | pos->next->prev = pos->prev; |
1172 | GNUNET_assert (pos->neighbour == NULL); | 1167 | GNUNET_assert (pos->neighbour == NULL); |
1173 | if (GNUNET_SCHEDULER_NO_TASK != pos->notify_delay_task) | 1168 | if (GNUNET_SCHEDULER_NO_TASK != pos->notify_delay_task) |
1174 | { | 1169 | { |
1175 | GNUNET_SCHEDULER_cancel (h->sched, | 1170 | GNUNET_SCHEDULER_cancel (h->sched, pos->notify_delay_task); |
1176 | pos->notify_delay_task); | 1171 | pos->notify_delay_task = GNUNET_SCHEDULER_NO_TASK; |
1177 | pos->notify_delay_task = GNUNET_SCHEDULER_NO_TASK; | 1172 | } |
1178 | } | ||
1179 | GNUNET_free (pos); | 1173 | GNUNET_free (pos); |
1180 | break; | 1174 | break; |
1181 | } | 1175 | } |
@@ -1184,8 +1178,7 @@ reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1184 | schedule_control_transmit (h, | 1178 | schedule_control_transmit (h, |
1185 | sizeof (struct GNUNET_MessageHeader), | 1179 | sizeof (struct GNUNET_MessageHeader), |
1186 | GNUNET_YES, | 1180 | GNUNET_YES, |
1187 | GNUNET_TIME_UNIT_FOREVER_REL, | 1181 | GNUNET_TIME_UNIT_FOREVER_REL, &send_start, NULL); |
1188 | &send_start, NULL); | ||
1189 | GNUNET_CLIENT_receive (h->client, | 1182 | GNUNET_CLIENT_receive (h->client, |
1190 | &demultiplexer, h, GNUNET_TIME_UNIT_FOREVER_REL); | 1183 | &demultiplexer, h, GNUNET_TIME_UNIT_FOREVER_REL); |
1191 | } | 1184 | } |
@@ -1292,8 +1285,7 @@ schedule_request (struct GNUNET_TRANSPORT_TransmitHandle *th) | |||
1292 | #if DEBUG_TRANSPORT | 1285 | #if DEBUG_TRANSPORT |
1293 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1286 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1294 | "Would need %llu ms before bandwidth is available for delivery to `%4s', that is too long. Signaling timeout.\n", | 1287 | "Would need %llu ms before bandwidth is available for delivery to `%4s', that is too long. Signaling timeout.\n", |
1295 | duration.value, | 1288 | duration.value, GNUNET_i2s (&th->target)); |
1296 | GNUNET_i2s(&th->target)); | ||
1297 | #endif | 1289 | #endif |
1298 | remove_from_wait_list (th); | 1290 | remove_from_wait_list (th); |
1299 | th->notify (th->notify_cls, 0, NULL); | 1291 | th->notify (th->notify_cls, 0, NULL); |
@@ -1303,8 +1295,7 @@ schedule_request (struct GNUNET_TRANSPORT_TransmitHandle *th) | |||
1303 | #if DEBUG_TRANSPORT | 1295 | #if DEBUG_TRANSPORT |
1304 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1296 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1305 | "Need more bandwidth, delaying delivery to `%4s' by %llu ms\n", | 1297 | "Need more bandwidth, delaying delivery to `%4s' by %llu ms\n", |
1306 | GNUNET_i2s(&th->target), | 1298 | GNUNET_i2s (&th->target), duration.value); |
1307 | duration.value); | ||
1308 | #endif | 1299 | #endif |
1309 | th->notify_delay_task | 1300 | th->notify_delay_task |
1310 | = GNUNET_SCHEDULER_add_delayed (h->sched, | 1301 | = GNUNET_SCHEDULER_add_delayed (h->sched, |
@@ -1328,14 +1319,16 @@ schedule_request (struct GNUNET_TRANSPORT_TransmitHandle *th) | |||
1328 | th->notify_delay_task | 1319 | th->notify_delay_task |
1329 | = GNUNET_SCHEDULER_add_delayed (h->sched, | 1320 | = GNUNET_SCHEDULER_add_delayed (h->sched, |
1330 | GNUNET_TIME_absolute_get_remaining | 1321 | GNUNET_TIME_absolute_get_remaining |
1331 | (th->timeout), &peer_transmit_timeout, th); | 1322 | (th->timeout), &peer_transmit_timeout, |
1323 | th); | ||
1332 | return; | 1324 | return; |
1333 | } | 1325 | } |
1334 | n->transmit_ok = GNUNET_NO; | 1326 | n->transmit_ok = GNUNET_NO; |
1335 | remove_from_wait_list (th); | 1327 | remove_from_wait_list (th); |
1336 | #if DEBUG_TRANSPORT | 1328 | #if DEBUG_TRANSPORT |
1337 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Moving message for `%4s' to ready list\n", | 1329 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1338 | GNUNET_i2s(&n->id)); | 1330 | "Moving message for `%4s' to ready list\n", |
1331 | GNUNET_i2s (&n->id)); | ||
1339 | #endif | 1332 | #endif |
1340 | insert_transmit_handle (&h->connect_ready_head, th); | 1333 | insert_transmit_handle (&h->connect_ready_head, th); |
1341 | if (GNUNET_NO == h->transmission_scheduled) | 1334 | if (GNUNET_NO == h->transmission_scheduled) |
@@ -1394,24 +1387,23 @@ add_neighbour (struct GNUNET_TRANSPORT_Handle *h, | |||
1394 | if (GNUNET_YES == n->received_ack) | 1387 | if (GNUNET_YES == n->received_ack) |
1395 | { | 1388 | { |
1396 | #if DEBUG_TRANSPORT | 1389 | #if DEBUG_TRANSPORT |
1397 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1390 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1398 | "Found pending request for `%4s' will trigger it now.\n", | 1391 | "Found pending request for `%4s' will trigger it now.\n", |
1399 | GNUNET_i2s (&pos->target)); | 1392 | GNUNET_i2s (&pos->target)); |
1400 | #endif | 1393 | #endif |
1401 | if (pos->notify_delay_task != GNUNET_SCHEDULER_NO_TASK) | 1394 | if (pos->notify_delay_task != GNUNET_SCHEDULER_NO_TASK) |
1402 | { | 1395 | { |
1403 | GNUNET_SCHEDULER_cancel (h->sched, pos->notify_delay_task); | 1396 | GNUNET_SCHEDULER_cancel (h->sched, pos->notify_delay_task); |
1404 | pos->notify_delay_task = GNUNET_SCHEDULER_NO_TASK; | 1397 | pos->notify_delay_task = GNUNET_SCHEDULER_NO_TASK; |
1405 | } | 1398 | } |
1406 | schedule_request (pos); | 1399 | schedule_request (pos); |
1407 | } | 1400 | } |
1408 | else | 1401 | else |
1409 | { | 1402 | { |
1410 | #if DEBUG_TRANSPORT | 1403 | #if DEBUG_TRANSPORT |
1411 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1404 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1412 | "Found pending request for `%4s' but still need `%s' before proceeding.\n", | 1405 | "Found pending request for `%4s' but still need `%s' before proceeding.\n", |
1413 | GNUNET_i2s (&pos->target), | 1406 | GNUNET_i2s (&pos->target), "ACK"); |
1414 | "ACK"); | ||
1415 | #endif | 1407 | #endif |
1416 | } | 1408 | } |
1417 | break; | 1409 | break; |
@@ -1470,8 +1462,7 @@ GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle) | |||
1470 | struct GNUNET_CLIENT_Connection *client; | 1462 | struct GNUNET_CLIENT_Connection *client; |
1471 | 1463 | ||
1472 | #if DEBUG_TRANSPORT | 1464 | #if DEBUG_TRANSPORT |
1473 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1465 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n"); |
1474 | "Transport disconnect called!\n"); | ||
1475 | #endif | 1466 | #endif |
1476 | while (NULL != (th = handle->connect_ready_head)) | 1467 | while (NULL != (th = handle->connect_ready_head)) |
1477 | { | 1468 | { |
@@ -1499,15 +1490,15 @@ GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle) | |||
1499 | { | 1490 | { |
1500 | handle->neighbours = n->next; | 1491 | handle->neighbours = n->next; |
1501 | if (NULL != (th = n->transmit_handle)) | 1492 | if (NULL != (th = n->transmit_handle)) |
1502 | { | 1493 | { |
1503 | if (th->notify_delay_task != GNUNET_SCHEDULER_NO_TASK) | 1494 | if (th->notify_delay_task != GNUNET_SCHEDULER_NO_TASK) |
1504 | { | 1495 | { |
1505 | GNUNET_SCHEDULER_cancel (handle->sched, th->notify_delay_task); | 1496 | GNUNET_SCHEDULER_cancel (handle->sched, th->notify_delay_task); |
1506 | th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK; | 1497 | th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK; |
1507 | } | 1498 | } |
1508 | th->notify (th->notify_cls, 0, NULL); | 1499 | th->notify (th->notify_cls, 0, NULL); |
1509 | GNUNET_free (th); | 1500 | GNUNET_free (th); |
1510 | } | 1501 | } |
1511 | GNUNET_free (n); | 1502 | GNUNET_free (n); |
1512 | } | 1503 | } |
1513 | while (NULL != (hwl = handle->hwl_head)) | 1504 | while (NULL != (hwl = handle->hwl_head)) |
@@ -1515,8 +1506,9 @@ GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle) | |||
1515 | handle->hwl_head = hwl->next; | 1506 | handle->hwl_head = hwl->next; |
1516 | GNUNET_SCHEDULER_cancel (handle->sched, hwl->task); | 1507 | GNUNET_SCHEDULER_cancel (handle->sched, hwl->task); |
1517 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1508 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1518 | _("Disconnect while trying to obtain `%s' from transport service.\n"), | 1509 | _ |
1519 | "HELLO"); | 1510 | ("Disconnect while trying to obtain `%s' from transport service.\n"), |
1511 | "HELLO"); | ||
1520 | if (hwl->rec != NULL) | 1512 | if (hwl->rec != NULL) |
1521 | hwl->rec (hwl->rec_cls, GNUNET_TIME_UNIT_ZERO, NULL, NULL); | 1513 | hwl->rec (hwl->rec_cls, GNUNET_TIME_UNIT_ZERO, NULL, NULL); |
1522 | GNUNET_free (hwl); | 1514 | GNUNET_free (hwl); |
@@ -1528,7 +1520,8 @@ GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle) | |||
1528 | } | 1520 | } |
1529 | GNUNET_free_non_null (handle->my_hello); | 1521 | GNUNET_free_non_null (handle->my_hello); |
1530 | handle->my_hello = NULL; | 1522 | handle->my_hello = NULL; |
1531 | GNUNET_ARM_stop_services (handle->cfg, handle->sched, "transport", "peerinfo", NULL); | 1523 | GNUNET_ARM_stop_services (handle->cfg, handle->sched, "transport", |
1524 | "peerinfo", NULL); | ||
1532 | if (NULL != handle->network_handle) | 1525 | if (NULL != handle->network_handle) |
1533 | { | 1526 | { |
1534 | GNUNET_CLIENT_notify_transmit_ready_cancel (handle->network_handle); | 1527 | GNUNET_CLIENT_notify_transmit_ready_cancel (handle->network_handle); |
@@ -1582,14 +1575,15 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1582 | GNUNET_CLIENT_notify_transmit_ready_cancel (h->network_handle); | 1575 | GNUNET_CLIENT_notify_transmit_ready_cancel (h->network_handle); |
1583 | h->network_handle = NULL; | 1576 | h->network_handle = NULL; |
1584 | h->transmission_scheduled = GNUNET_NO; | 1577 | h->transmission_scheduled = GNUNET_NO; |
1585 | th = h->connect_ready_head; | 1578 | th = h->connect_ready_head; |
1586 | /* add timeout again, we cancelled the transmit_ready task! */ | 1579 | /* add timeout again, we cancelled the transmit_ready task! */ |
1587 | GNUNET_assert (th->notify_delay_task == GNUNET_SCHEDULER_NO_TASK); | 1580 | GNUNET_assert (th->notify_delay_task == |
1588 | th->notify_delay_task | 1581 | GNUNET_SCHEDULER_NO_TASK); |
1589 | = GNUNET_SCHEDULER_add_delayed (h->sched, | 1582 | th->notify_delay_task = |
1590 | GNUNET_TIME_absolute_get_remaining(th->timeout), | 1583 | GNUNET_SCHEDULER_add_delayed (h->sched, |
1591 | &peer_transmit_timeout, | 1584 | GNUNET_TIME_absolute_get_remaining |
1592 | th); | 1585 | (th->timeout), |
1586 | &peer_transmit_timeout, th); | ||
1593 | } | 1587 | } |
1594 | GNUNET_CLIENT_disconnect (h->client); | 1588 | GNUNET_CLIENT_disconnect (h->client); |
1595 | h->client = NULL; | 1589 | h->client = NULL; |
@@ -1611,7 +1605,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1611 | case GNUNET_MESSAGE_TYPE_HELLO: | 1605 | case GNUNET_MESSAGE_TYPE_HELLO: |
1612 | if (GNUNET_OK != | 1606 | if (GNUNET_OK != |
1613 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) msg, | 1607 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) msg, |
1614 | &me)) | 1608 | &me)) |
1615 | { | 1609 | { |
1616 | GNUNET_break (0); | 1610 | GNUNET_break (0); |
1617 | break; | 1611 | break; |
@@ -1680,7 +1674,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1680 | #if DEBUG_TRANSPORT | 1674 | #if DEBUG_TRANSPORT |
1681 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1675 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1682 | "Receiving `%s' message, transmission %s.\n", "SEND_OK", | 1676 | "Receiving `%s' message, transmission %s.\n", "SEND_OK", |
1683 | ntohl(okm->success) == GNUNET_OK ? "succeeded" : "failed"); | 1677 | ntohl (okm->success) == GNUNET_OK ? "succeeded" : "failed"); |
1684 | #endif | 1678 | #endif |
1685 | n = find_neighbour (h, &okm->peer); | 1679 | n = find_neighbour (h, &okm->peer); |
1686 | GNUNET_assert (n != NULL); | 1680 | GNUNET_assert (n != NULL); |
@@ -1690,12 +1684,11 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1690 | #if DEBUG_TRANSPORT | 1684 | #if DEBUG_TRANSPORT |
1691 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1685 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1692 | "Processing pending message for `%4s'\n", | 1686 | "Processing pending message for `%4s'\n", |
1693 | GNUNET_i2s(&n->id)); | 1687 | GNUNET_i2s (&n->id)); |
1694 | #endif | 1688 | #endif |
1695 | GNUNET_SCHEDULER_cancel (h->sched, | 1689 | GNUNET_SCHEDULER_cancel (h->sched, |
1696 | n->transmit_handle->notify_delay_task); | 1690 | n->transmit_handle->notify_delay_task); |
1697 | n->transmit_handle->notify_delay_task = | 1691 | n->transmit_handle->notify_delay_task = GNUNET_SCHEDULER_NO_TASK; |
1698 | GNUNET_SCHEDULER_NO_TASK; | ||
1699 | GNUNET_assert (GNUNET_YES == n->received_ack); | 1692 | GNUNET_assert (GNUNET_YES == n->received_ack); |
1700 | schedule_request (n->transmit_handle); | 1693 | schedule_request (n->transmit_handle); |
1701 | } | 1694 | } |
@@ -1857,7 +1850,7 @@ GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle | |||
1857 | *handle, | 1850 | *handle, |
1858 | const struct GNUNET_PeerIdentity | 1851 | const struct GNUNET_PeerIdentity |
1859 | *target, size_t size, | 1852 | *target, size_t size, |
1860 | unsigned int priority, | 1853 | unsigned int priority, |
1861 | struct GNUNET_TIME_Relative timeout, | 1854 | struct GNUNET_TIME_Relative timeout, |
1862 | GNUNET_CONNECTION_TransmitReadyNotify | 1855 | GNUNET_CONNECTION_TransmitReadyNotify |
1863 | notify, void *notify_cls) | 1856 | notify, void *notify_cls) |
@@ -1879,9 +1872,8 @@ GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle | |||
1879 | size, GNUNET_i2s (target)); | 1872 | size, GNUNET_i2s (target)); |
1880 | #endif | 1873 | #endif |
1881 | n = find_neighbour (handle, target); | 1874 | n = find_neighbour (handle, target); |
1882 | if ( (n != NULL) && | 1875 | if ((n != NULL) && (n->transmit_handle != NULL)) |
1883 | (n->transmit_handle != NULL) ) | 1876 | return NULL; /* already have a request pending for this peer! */ |
1884 | return NULL; /* already have a request pending for this peer! */ | ||
1885 | ctw = GNUNET_malloc (sizeof (struct ClientTransmitWrapper)); | 1877 | ctw = GNUNET_malloc (sizeof (struct ClientTransmitWrapper)); |
1886 | th = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_TransmitHandle)); | 1878 | th = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_TransmitHandle)); |
1887 | ctw->notify = notify; | 1879 | ctw->notify = notify; |
@@ -1915,7 +1907,7 @@ GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle | |||
1915 | 1907 | ||
1916 | #if DEBUG_TRANSPORT | 1908 | #if DEBUG_TRANSPORT |
1917 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1909 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1918 | "Transmission request queued for transmission to transport service.\n"); | 1910 | "Transmission request queued for transmission to transport service.\n"); |
1919 | #endif | 1911 | #endif |
1920 | GNUNET_assert (NULL == n->transmit_handle); | 1912 | GNUNET_assert (NULL == n->transmit_handle); |
1921 | n->transmit_handle = th; | 1913 | n->transmit_handle = th; |
@@ -1923,23 +1915,22 @@ GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle | |||
1923 | { | 1915 | { |
1924 | #if DEBUG_TRANSPORT | 1916 | #if DEBUG_TRANSPORT |
1925 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1917 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1926 | "Connection to `%4s' is not yet confirmed connected, scheduling timeout (%llu ms) only.\n", | 1918 | "Connection to `%4s' is not yet confirmed connected, scheduling timeout (%llu ms) only.\n", |
1927 | GNUNET_i2s (target), timeout.value); | 1919 | GNUNET_i2s (target), timeout.value); |
1928 | #endif | 1920 | #endif |
1929 | th->notify_delay_task | 1921 | th->notify_delay_task |
1930 | = GNUNET_SCHEDULER_add_delayed (handle->sched, | 1922 | = GNUNET_SCHEDULER_add_delayed (handle->sched, |
1931 | timeout, &peer_transmit_timeout, th); | 1923 | timeout, &peer_transmit_timeout, th); |
1932 | return th; | 1924 | return th; |
1933 | } | 1925 | } |
1934 | 1926 | ||
1935 | #if DEBUG_TRANSPORT | 1927 | #if DEBUG_TRANSPORT |
1936 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1928 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1937 | "Peer `%4s' is ready to receive, scheduling message for delivery now.\n", | 1929 | "Peer `%4s' is ready to receive, scheduling message for delivery now.\n", |
1938 | GNUNET_i2s (target)); | 1930 | GNUNET_i2s (target)); |
1939 | #endif | 1931 | #endif |
1940 | th->notify_delay_task | 1932 | th->notify_delay_task |
1941 | = GNUNET_SCHEDULER_add_now (handle->sched, | 1933 | = GNUNET_SCHEDULER_add_now (handle->sched, &transmit_ready, th); |
1942 | &transmit_ready, th); | ||
1943 | return th; | 1934 | return th; |
1944 | } | 1935 | } |
1945 | 1936 | ||
@@ -1956,9 +1947,9 @@ GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct | |||
1956 | 1947 | ||
1957 | #if DEBUG_TRANSPORT | 1948 | #if DEBUG_TRANSPORT |
1958 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1949 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1959 | "Transmission request of %u bytes to `%4s' was cancelled.\n", | 1950 | "Transmission request of %u bytes to `%4s' was cancelled.\n", |
1960 | th->notify_size - sizeof(struct OutboundMessage), | 1951 | th->notify_size - sizeof (struct OutboundMessage), |
1961 | GNUNET_i2s (&th->target)); | 1952 | GNUNET_i2s (&th->target)); |
1962 | #endif | 1953 | #endif |
1963 | GNUNET_assert (th->notify == &client_notify_wrapper); | 1954 | GNUNET_assert (th->notify == &client_notify_wrapper); |
1964 | remove_from_any_list (th); | 1955 | remove_from_any_list (th); |
diff --git a/src/transport/transport_api_address_lookup.c b/src/transport/transport_api_address_lookup.c index 1c0cf7340..961ee0713 100644 --- a/src/transport/transport_api_address_lookup.c +++ b/src/transport/transport_api_address_lookup.c | |||
@@ -9,108 +9,114 @@ | |||
9 | #include "transport.h" | 9 | #include "transport.h" |
10 | 10 | ||
11 | // FIXME: document | 11 | // FIXME: document |
12 | struct AddressLookUpCB { | 12 | struct AddressLookUpCB |
13 | GNUNET_TRANSPORT_AddressLookUpCallback cb; | 13 | { |
14 | void *cls; | 14 | GNUNET_TRANSPORT_AddressLookUpCallback cb; |
15 | struct GNUNET_TIME_Absolute timeout; | 15 | void *cls; |
16 | struct GNUNET_CLIENT_Connection *client; | 16 | struct GNUNET_TIME_Absolute timeout; |
17 | struct GNUNET_CLIENT_Connection *client; | ||
17 | }; | 18 | }; |
18 | 19 | ||
19 | 20 | ||
20 | // FIXME: document | 21 | // FIXME: document |
21 | static void | 22 | static void |
22 | address_response_processor(void *cls, const struct | 23 | address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg) |
23 | GNUNET_MessageHeader * msg) | ||
24 | { | 24 | { |
25 | struct AddressLookUpCB *alucb = cls; | 25 | struct AddressLookUpCB *alucb = cls; |
26 | const char *address; | 26 | const char *address; |
27 | uint16_t size; | 27 | uint16_t size; |
28 | 28 | ||
29 | if (msg == NULL) | 29 | if (msg == NULL) |
30 | { | 30 | { |
31 | /* timeout */ | 31 | /* timeout */ |
32 | alucb->cb (alucb->cls, NULL); | 32 | alucb->cb (alucb->cls, NULL); |
33 | GNUNET_CLIENT_disconnect (alucb->client); | 33 | GNUNET_CLIENT_disconnect (alucb->client); |
34 | GNUNET_free (alucb); | 34 | GNUNET_free (alucb); |
35 | return; | 35 | return; |
36 | } | 36 | } |
37 | size = ntohs(msg->size); | 37 | size = ntohs (msg->size); |
38 | if (size == sizeof(struct GNUNET_MessageHeader)) | 38 | if (size == sizeof (struct GNUNET_MessageHeader)) |
39 | { | 39 | { |
40 | /* last reply */ | 40 | /* last reply */ |
41 | address = NULL; | 41 | address = NULL; |
42 | } | 42 | } |
43 | else | 43 | else |
44 | { | 44 | { |
45 | address = (const char*) &msg[1]; | 45 | address = (const char *) &msg[1]; |
46 | if (address[size - sizeof(struct GNUNET_MessageHeader) - 1] != '\0') | 46 | if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0') |
47 | { | 47 | { |
48 | /* invalid reply */ | 48 | /* invalid reply */ |
49 | GNUNET_break_op (0); | 49 | GNUNET_break_op (0); |
50 | alucb->cb (alucb->cls, NULL); | 50 | alucb->cb (alucb->cls, NULL); |
51 | GNUNET_CLIENT_disconnect (alucb->client); | 51 | GNUNET_CLIENT_disconnect (alucb->client); |
52 | GNUNET_free (alucb); | 52 | GNUNET_free (alucb); |
53 | return; | 53 | return; |
54 | } | 54 | } |
55 | else | 55 | else |
56 | { | 56 | { |
57 | /* expect more replies */ | 57 | /* expect more replies */ |
58 | GNUNET_CLIENT_receive (alucb->client, &address_response_processor, alucb, | 58 | GNUNET_CLIENT_receive (alucb->client, &address_response_processor, |
59 | GNUNET_TIME_absolute_get_remaining (alucb->timeout)); | 59 | alucb, |
60 | } | 60 | GNUNET_TIME_absolute_get_remaining (alucb-> |
61 | } | 61 | timeout)); |
62 | alucb->cb (alucb->cls, address); | 62 | } |
63 | if (address == NULL) | 63 | } |
64 | { | 64 | alucb->cb (alucb->cls, address); |
65 | /* done! */ | 65 | if (address == NULL) |
66 | GNUNET_CLIENT_disconnect (alucb->client); | 66 | { |
67 | GNUNET_free (alucb); | 67 | /* done! */ |
68 | } | 68 | GNUNET_CLIENT_disconnect (alucb->client); |
69 | GNUNET_free (alucb); | ||
70 | } | ||
69 | } | 71 | } |
70 | 72 | ||
71 | void | 73 | void |
72 | GNUNET_TRANSPORT_address_lookup (struct GNUNET_SCHEDULER_Handle *sched, | 74 | GNUNET_TRANSPORT_address_lookup (struct GNUNET_SCHEDULER_Handle *sched, |
73 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 75 | const struct GNUNET_CONFIGURATION_Handle |
74 | const char * address, | 76 | *cfg, const char *address, size_t addressLen, |
75 | size_t addressLen, | 77 | const char *nameTrans, |
76 | const char * nameTrans, | 78 | struct GNUNET_TIME_Relative timeout, |
77 | struct GNUNET_TIME_Relative timeout, | 79 | GNUNET_TRANSPORT_AddressLookUpCallback aluc, |
78 | GNUNET_TRANSPORT_AddressLookUpCallback aluc, | 80 | void *aluc_cls) |
79 | void *aluc_cls) | ||
80 | { | 81 | { |
81 | size_t len = sizeof (struct AddressLookupMessage) + addressLen + strlen (nameTrans) + 1; | 82 | size_t len = |
82 | struct AddressLookupMessage *msg; | 83 | sizeof (struct AddressLookupMessage) + addressLen + strlen (nameTrans) + |
83 | struct GNUNET_TIME_Absolute abs_timeout; | 84 | 1; |
84 | struct AddressLookUpCB *aluCB; | 85 | struct AddressLookupMessage *msg; |
85 | struct GNUNET_CLIENT_Connection *client; | 86 | struct GNUNET_TIME_Absolute abs_timeout; |
87 | struct AddressLookUpCB *aluCB; | ||
88 | struct GNUNET_CLIENT_Connection *client; | ||
86 | 89 | ||
87 | if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 90 | if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
88 | { | 91 | { |
89 | GNUNET_break (0); | 92 | GNUNET_break (0); |
90 | aluc (aluc_cls, NULL); | 93 | aluc (aluc_cls, NULL); |
91 | return; | 94 | return; |
92 | } | 95 | } |
93 | client = GNUNET_CLIENT_connect (sched, "transport", cfg); | 96 | client = GNUNET_CLIENT_connect (sched, "transport", cfg); |
94 | if (client == NULL) | 97 | if (client == NULL) |
95 | { | 98 | { |
96 | aluc (aluc_cls, NULL); | 99 | aluc (aluc_cls, NULL); |
97 | return; | 100 | return; |
98 | } | 101 | } |
99 | abs_timeout = GNUNET_TIME_relative_to_absolute(timeout); | 102 | abs_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
100 | msg = GNUNET_malloc (len); | 103 | msg = GNUNET_malloc (len); |
101 | msg->header->size = htons (len); | 104 | msg->header->size = htons (len); |
102 | msg->header->type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP); | 105 | msg->header->type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP); |
103 | msg->timeout = GNUNET_TIME_absolute_hton(abs_timeout); | 106 | msg->timeout = GNUNET_TIME_absolute_hton (abs_timeout); |
104 | msg->addrlen = htonl (addressLen); | 107 | msg->addrlen = htonl (addressLen); |
105 | char *addrbuf = (char*) &msg[1]; | 108 | char *addrbuf = (char *) &msg[1]; |
106 | memcpy (addrbuf, address, addressLen); | 109 | memcpy (addrbuf, address, addressLen); |
107 | char *tbuf = &addrbuf[addressLen]; | 110 | char *tbuf = &addrbuf[addressLen]; |
108 | memcpy (tbuf, nameTrans, strlen(nameTrans) + 1); | 111 | memcpy (tbuf, nameTrans, strlen (nameTrans) + 1); |
109 | aluCB = GNUNET_malloc (sizeof (struct AddressLookUpCB)); | 112 | aluCB = GNUNET_malloc (sizeof (struct AddressLookUpCB)); |
110 | aluCB->cb = aluc; | 113 | aluCB->cb = aluc; |
111 | aluCB->cb_cls = aluc_cls; | 114 | aluCB->cb_cls = aluc_cls; |
112 | aluCB->timeout = abs_timeout; | 115 | aluCB->timeout = abs_timeout; |
113 | aluCB->client = client; | 116 | aluCB->client = client; |
114 | GNUNET_CLIENT_transmit_and_get_response(client, msg->header, timeout, GNUNET_YES, &address_response_processor, aluCB); | 117 | GNUNET_CLIENT_transmit_and_get_response (client, msg->header, timeout, |
115 | GNUNET_free(msg); | 118 | GNUNET_YES, |
119 | &address_response_processor, | ||
120 | aluCB); | ||
121 | GNUNET_free (msg); | ||
116 | } | 122 | } |