diff options
-rw-r--r-- | src/include/gnunet_protocols.h | 11 | ||||
-rw-r--r-- | src/include/gnunet_transport_service.h | 15 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_clients.c | 46 | ||||
-rw-r--r-- | src/transport/gnunet-transport.c | 37 | ||||
-rw-r--r-- | src/transport/transport.h | 20 | ||||
-rw-r--r-- | src/transport/transport_api_address_lookup.c | 203 | ||||
-rw-r--r-- | src/transport/transport_api_address_to_string.c | 10 |
7 files changed, 162 insertions, 180 deletions
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 81b5ce6b8..f386d8768 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -1020,12 +1020,12 @@ extern "C" | |||
1020 | /** | 1020 | /** |
1021 | * Request to look addresses of peers in server. | 1021 | * Request to look addresses of peers in server. |
1022 | */ | 1022 | */ |
1023 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP 367 | 1023 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING 367 |
1024 | 1024 | ||
1025 | /** | 1025 | /** |
1026 | * Response to the address lookup request. | 1026 | * Response to the address lookup request. |
1027 | */ | 1027 | */ |
1028 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY 368 | 1028 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY 368 |
1029 | 1029 | ||
1030 | /** | 1030 | /** |
1031 | * Register a client that wants to do blacklisting. | 1031 | * Register a client that wants to do blacklisting. |
@@ -1106,9 +1106,14 @@ extern "C" | |||
1106 | 1106 | ||
1107 | 1107 | ||
1108 | /** | 1108 | /** |
1109 | * Request to iterate over all known addresses. | ||
1110 | */ | ||
1111 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE 383 | ||
1112 | |||
1113 | /** | ||
1109 | * Message send by a peer to notify the other to keep the session alive. | 1114 | * Message send by a peer to notify the other to keep the session alive. |
1110 | */ | 1115 | */ |
1111 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON 383 | 1116 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON 384 |
1112 | 1117 | ||
1113 | 1118 | ||
1114 | /** | 1119 | /** |
diff --git a/src/include/gnunet_transport_service.h b/src/include/gnunet_transport_service.h index 7e7fc7fa6..98436065b 100644 --- a/src/include/gnunet_transport_service.h +++ b/src/include/gnunet_transport_service.h | |||
@@ -112,12 +112,8 @@ typedef void (*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls, | |||
112 | * Function to call with a binary format of an address | 112 | * Function to call with a binary format of an address |
113 | * | 113 | * |
114 | * @param cls closure | 114 | * @param cls closure |
115 | * @param peer peer identity | 115 | * @param address address |
116 | * @param transport transport plugin | ||
117 | * @param addr address | ||
118 | * @param addrlen address length | ||
119 | */ | 116 | */ |
120 | // FIXME: use GNUNET_HELLO_Address (as 2nd arg, replacing others) | ||
121 | // FIXME: use NULL for address on disconnect IF in monitor mode (one_shot = NO) | 117 | // FIXME: use NULL for address on disconnect IF in monitor mode (one_shot = NO) |
122 | typedef void (*GNUNET_TRANSPORT_AddressLookUpCallback) (void *cls, | 118 | typedef void (*GNUNET_TRANSPORT_AddressLookUpCallback) (void *cls, |
123 | const struct GNUNET_HELLO_Address *address); | 119 | const struct GNUNET_HELLO_Address *address); |
@@ -310,17 +306,18 @@ GNUNET_TRANSPORT_address_to_string_cancel (struct | |||
310 | 306 | ||
311 | 307 | ||
312 | /** | 308 | /** |
313 | * Return all the known addresses for a peer. | 309 | * Return all the known addresses for a specific peer or all peers. |
310 | * Returns continously all address if one_shot is set to GNUNET_NO | ||
311 | * | ||
314 | * CHANGE: Returns the address(es) that we are currently using for this | 312 | * CHANGE: Returns the address(es) that we are currently using for this |
315 | * peer. Upon completion, the 'AddressLookUpCallback' is called one more | 313 | * peer. Upon completion, the 'AddressLookUpCallback' is called one more |
316 | * time with 'NULL' for the address and the peer. After this, the operation must no | 314 | * time with 'NULL' for the address and the peer. After this, the operation must no |
317 | * longer be explicitly cancelled. | 315 | * longer be explicitly cancelled. |
318 | * TODO: change code that uses this API to see if this is fine... | ||
319 | * | 316 | * |
320 | * @param cfg configuration to use | 317 | * @param cfg configuration to use |
321 | * @param peer peer identity to look up the addresses of, CHANGE: allow NULL for all (connected) peers | 318 | * @param peer peer identity to look up the addresses of, CHANGE: allow NULL for all (connected) peers |
322 | * FIXME: @param one_shot GNUNET_YES to return the current state and then end (with NULL+NULL), | 319 | * @param one_shot GNUNET_YES to return the current state and then end (with NULL+NULL), |
323 | * GNUNET_NO to monitor the set of addresses used (continuously, must be explicitly cancelled) | 320 | * GNUNET_NO to monitor the set of addresses used (continuously, must be explicitly cancelled) |
324 | * @param timeout how long is the lookup allowed to take at most | 321 | * @param timeout how long is the lookup allowed to take at most |
325 | * @param peer_address_callback function to call with the results | 322 | * @param peer_address_callback function to call with the results |
326 | * @param peer_address_callback_cls closure for peer_address_callback | 323 | * @param peer_address_callback_cls closure for peer_address_callback |
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c index d60514565..7c50218e0 100644 --- a/src/transport/gnunet-service-transport_clients.c +++ b/src/transport/gnunet-service-transport_clients.c | |||
@@ -616,12 +616,12 @@ transmit_address_to_client (void *cls, const char *buf) | |||
616 | if (NULL == buf) | 616 | if (NULL == buf) |
617 | { | 617 | { |
618 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, | 618 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, |
619 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); | 619 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); |
620 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | 620 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); |
621 | return; | 621 | return; |
622 | } | 622 | } |
623 | GNUNET_SERVER_transmit_context_append_data (tc, buf, strlen (buf) + 1, | 623 | GNUNET_SERVER_transmit_context_append_data (tc, buf, strlen (buf) + 1, |
624 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); | 624 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); |
625 | } | 625 | } |
626 | 626 | ||
627 | 627 | ||
@@ -641,12 +641,12 @@ transmit_binary_to_client (void *cls, void *buf, size_t size) | |||
641 | if (NULL == buf) | 641 | if (NULL == buf) |
642 | { | 642 | { |
643 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, | 643 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, |
644 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); | 644 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE); |
645 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | 645 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); |
646 | return; | 646 | return; |
647 | } | 647 | } |
648 | GNUNET_SERVER_transmit_context_append_data (tc, buf, size, | 648 | GNUNET_SERVER_transmit_context_append_data (tc, buf, size, |
649 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); | 649 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE); |
650 | } | 650 | } |
651 | 651 | ||
652 | 652 | ||
@@ -658,7 +658,7 @@ transmit_binary_to_client (void *cls, void *buf, size_t size) | |||
658 | * @param message the resolution request | 658 | * @param message the resolution request |
659 | */ | 659 | */ |
660 | static void | 660 | static void |
661 | clients_handle_address_lookup (void *cls, struct GNUNET_SERVER_Client *client, | 661 | clients_handle_address_to_string (void *cls, struct GNUNET_SERVER_Client *client, |
662 | const struct GNUNET_MessageHeader *message) | 662 | const struct GNUNET_MessageHeader *message) |
663 | { | 663 | { |
664 | const struct AddressLookupMessage *alum; | 664 | const struct AddressLookupMessage *alum; |
@@ -702,7 +702,7 @@ clients_handle_address_lookup (void *cls, struct GNUNET_SERVER_Client *client, | |||
702 | if (NULL == papi) | 702 | if (NULL == papi) |
703 | { | 703 | { |
704 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, | 704 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, |
705 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); | 705 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); |
706 | GNUNET_SERVER_transmit_context_run (tc, rtimeout); | 706 | GNUNET_SERVER_transmit_context_run (tc, rtimeout); |
707 | return; | 707 | return; |
708 | } | 708 | } |
@@ -771,7 +771,7 @@ clients_handle_peer_address_lookup (void *cls, | |||
771 | GST_validation_get_addresses (&peer_address_lookup->peer, | 771 | GST_validation_get_addresses (&peer_address_lookup->peer, |
772 | &send_address_to_client, tc); | 772 | &send_address_to_client, tc); |
773 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, | 773 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, |
774 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); | 774 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE); |
775 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | 775 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); |
776 | } | 776 | } |
777 | 777 | ||
@@ -793,17 +793,26 @@ output_addresses (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
793 | struct GNUNET_SERVER_TransmitContext *tc = cls; | 793 | struct GNUNET_SERVER_TransmitContext *tc = cls; |
794 | struct AddressIterateResponseMessage *msg; | 794 | struct AddressIterateResponseMessage *msg; |
795 | size_t size; | 795 | size_t size; |
796 | size_t slen; | 796 | size_t tlen; |
797 | size_t alen; | ||
798 | char * addr; | ||
797 | 799 | ||
798 | slen = strlen (address->transport_name) + 1; | 800 | tlen = strlen (address->transport_name) + 1; |
799 | size = (sizeof (struct AddressIterateResponseMessage) + slen); | 801 | alen = address->address_length; |
802 | |||
803 | size = (sizeof (struct AddressIterateResponseMessage) + alen + tlen); | ||
800 | msg = GNUNET_malloc (size); | 804 | msg = GNUNET_malloc (size); |
801 | memcpy (&msg->peer, peer, sizeof (struct GNUNET_PeerIdentity)); | 805 | msg->addrlen = htonl (alen); |
802 | memcpy (&msg[0], address->transport_name, slen); | 806 | msg->pluginlen = htonl (tlen); |
803 | msg->addrlen = ntohs (address->address_length); | 807 | msg->peer = *peer; |
804 | msg->pluginlen = ntohs (slen); | 808 | |
805 | // FIXME: what about 'address->address'!? | 809 | addr = (char *) &msg[1]; |
810 | memcpy(addr,address->address, alen); | ||
811 | memcpy(&addr[alen], address->transport_name, tlen); | ||
812 | |||
806 | transmit_binary_to_client (tc, msg, size); | 813 | transmit_binary_to_client (tc, msg, size); |
814 | |||
815 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "output_addresses: peer `%s' transport %s address %s %s\n",GNUNET_i2s(&msg->peer), &addr[alen], GNUNET_a2s((struct sockaddr *) addr, alen), GNUNET_a2s((struct sockaddr *) address->address, address->address_length)); | ||
807 | GNUNET_free (msg); | 816 | GNUNET_free (msg); |
808 | } | 817 | } |
809 | 818 | ||
@@ -824,9 +833,10 @@ clients_handle_address_iterate (void *cls, struct GNUNET_SERVER_Client *client, | |||
824 | 833 | ||
825 | GNUNET_SERVER_disable_receive_done_warning (client); | 834 | GNUNET_SERVER_disable_receive_done_warning (client); |
826 | tc = GNUNET_SERVER_transmit_context_create (client); | 835 | tc = GNUNET_SERVER_transmit_context_create (client); |
836 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "clients_handle_address_iterate: \n"); | ||
827 | GST_neighbours_iterate (&output_addresses, tc); | 837 | GST_neighbours_iterate (&output_addresses, tc); |
828 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, | 838 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, |
829 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); | 839 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE); |
830 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | 840 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); |
831 | } | 841 | } |
832 | 842 | ||
@@ -849,8 +859,8 @@ GST_clients_start (struct GNUNET_SERVER_Handle *server) | |||
849 | {&clients_handle_request_connect, NULL, | 859 | {&clients_handle_request_connect, NULL, |
850 | GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT, | 860 | GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT, |
851 | sizeof (struct TransportRequestConnectMessage)}, | 861 | sizeof (struct TransportRequestConnectMessage)}, |
852 | {&clients_handle_address_lookup, NULL, | 862 | {&clients_handle_address_to_string, NULL, |
853 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP, 0}, | 863 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, 0}, |
854 | {&clients_handle_peer_address_lookup, NULL, | 864 | {&clients_handle_peer_address_lookup, NULL, |
855 | GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP, | 865 | GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP, |
856 | sizeof (struct PeerAddressLookupMessage)}, | 866 | sizeof (struct PeerAddressLookupMessage)}, |
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c index 1dc85a903..58d20e16d 100644 --- a/src/transport/gnunet-transport.c +++ b/src/transport/gnunet-transport.c | |||
@@ -150,6 +150,7 @@ struct TestContext | |||
150 | 150 | ||
151 | }; | 151 | }; |
152 | 152 | ||
153 | struct GNUNET_CONFIGURATION_Handle * cfg; | ||
153 | 154 | ||
154 | /** | 155 | /** |
155 | * Display the result of the test. | 156 | * Display the result of the test. |
@@ -432,6 +433,11 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
432 | traffic_received += ntohs (message->size); | 433 | traffic_received += ntohs (message->size); |
433 | } | 434 | } |
434 | 435 | ||
436 | void process_string (void *cls, | ||
437 | const char *address) | ||
438 | { | ||
439 | fprintf (stdout, _("process_string\n")); | ||
440 | } | ||
435 | 441 | ||
436 | /** | 442 | /** |
437 | * Function to call with a human-readable format of an address | 443 | * Function to call with a human-readable format of an address |
@@ -445,23 +451,23 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
445 | static void | 451 | static void |
446 | process_address (void *cls, const struct GNUNET_HELLO_Address *address) | 452 | process_address (void *cls, const struct GNUNET_HELLO_Address *address) |
447 | { | 453 | { |
448 | if ((address->transport_name != NULL) || | 454 | if (address == NULL) |
449 | ((address->address != NULL) && (address->address_length > 0))) | ||
450 | { | 455 | { |
451 | /* Call GNUNET_TRANSPORT_address_to_string to convert to human readable */ | 456 | return; |
452 | //GNUNET_TRANSPORT_address_to_string(cfg, address, GNUNET_NO) | ||
453 | |||
454 | #if 0 | ||
455 | fprintf (stdout, _("Peer `%s' plugin: `%s' address `%s'\n"), | ||
456 | (peer != NULL) ? GNUNET_i2s (peer) : "<unknown>", | ||
457 | (transport != NULL) ? transport : "<unknown>", ((addr != NULL) && | ||
458 | (addrlen > 0) && | ||
459 | (transport != | ||
460 | NULL)) ? | ||
461 | "how do i resolve the name without transport service?" : | ||
462 | "<unknown>"); | ||
463 | #endif | ||
464 | } | 457 | } |
458 | |||
459 | fprintf (stdout, _("Peer `%s'\n"), | ||
460 | GNUNET_i2s (&address->peer)); | ||
461 | |||
462 | /* Resolve address to string */ | ||
463 | /* | ||
464 | GNUNET_TRANSPORT_address_to_string (cfg, | ||
465 | address, | ||
466 | GNUNET_NO, | ||
467 | GNUNET_TIME_UNIT_MINUTES, | ||
468 | &process_string, | ||
469 | NULL); | ||
470 | */ | ||
465 | } | 471 | } |
466 | 472 | ||
467 | 473 | ||
@@ -477,6 +483,7 @@ static void | |||
477 | run (void *cls, char *const *args, const char *cfgfile, | 483 | run (void *cls, char *const *args, const char *cfgfile, |
478 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 484 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
479 | { | 485 | { |
486 | cfg = cfg; | ||
480 | if (test_configuration) | 487 | if (test_configuration) |
481 | { | 488 | { |
482 | do_test_configuration (cfg); | 489 | do_test_configuration (cfg); |
diff --git a/src/transport/transport.h b/src/transport/transport.h index 66f40cd06..97620a9b6 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h | |||
@@ -360,11 +360,24 @@ struct AddressIterateMessage | |||
360 | * timeout to give up. FIXME: remove in the future | 360 | * timeout to give up. FIXME: remove in the future |
361 | */ | 361 | */ |
362 | struct GNUNET_TIME_AbsoluteNBO timeout; | 362 | struct GNUNET_TIME_AbsoluteNBO timeout; |
363 | |||
364 | /** | ||
365 | * The identity of the peer to look up. | ||
366 | */ | ||
367 | struct GNUNET_PeerIdentity peer; | ||
368 | |||
369 | /** | ||
370 | * One shot call or continous replies? | ||
371 | */ | ||
372 | uint32_t one_shot; | ||
373 | |||
363 | }; | 374 | }; |
364 | 375 | ||
365 | /** | 376 | /** |
366 | * Message from the library to the transport service | 377 | * Message from the transport service to the library |
367 | * asking for human readable addresses known for a peer. | 378 | * containing binary addresses known for a peer. |
379 | * Memory layout: | ||
380 | * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]] | ||
368 | */ | 381 | */ |
369 | struct AddressIterateResponseMessage | 382 | struct AddressIterateResponseMessage |
370 | { | 383 | { |
@@ -378,7 +391,7 @@ struct AddressIterateResponseMessage | |||
378 | */ | 391 | */ |
379 | uint32_t reserved; | 392 | uint32_t reserved; |
380 | 393 | ||
381 | /** | 394 | /** |
382 | * Peer identity | 395 | * Peer identity |
383 | */ | 396 | */ |
384 | struct GNUNET_PeerIdentity peer; | 397 | struct GNUNET_PeerIdentity peer; |
@@ -392,6 +405,7 @@ struct AddressIterateResponseMessage | |||
392 | * length of the plugin name | 405 | * length of the plugin name |
393 | */ | 406 | */ |
394 | uint32_t pluginlen GNUNET_PACKED; | 407 | uint32_t pluginlen GNUNET_PACKED; |
408 | |||
395 | }; | 409 | }; |
396 | 410 | ||
397 | 411 | ||
diff --git a/src/transport/transport_api_address_lookup.c b/src/transport/transport_api_address_lookup.c index 385abd423..5904de5e2 100644 --- a/src/transport/transport_api_address_lookup.c +++ b/src/transport/transport_api_address_lookup.c | |||
@@ -65,7 +65,6 @@ struct GNUNET_TRANSPORT_PeerAddressLookupContext | |||
65 | struct GNUNET_TIME_Absolute timeout; | 65 | struct GNUNET_TIME_Absolute timeout; |
66 | }; | 66 | }; |
67 | 67 | ||
68 | |||
69 | /** | 68 | /** |
70 | * Function called with responses from the service. | 69 | * Function called with responses from the service. |
71 | * | 70 | * |
@@ -77,46 +76,61 @@ static void | |||
77 | peer_address_response_processor (void *cls, | 76 | peer_address_response_processor (void *cls, |
78 | const struct GNUNET_MessageHeader *msg) | 77 | const struct GNUNET_MessageHeader *msg) |
79 | { | 78 | { |
80 | struct GNUNET_TRANSPORT_PeerAddressLookupContext *alucb = cls; | 79 | struct GNUNET_TRANSPORT_PeerAddressLookupContext *pal_ctx = cls; |
80 | struct AddressIterateResponseMessage *air_msg = (struct AddressIterateResponseMessage *) &msg[1]; | ||
81 | const struct GNUNET_HELLO_Address *address; | 81 | const struct GNUNET_HELLO_Address *address; |
82 | uint16_t size; | 82 | uint16_t size; |
83 | 83 | if (air_msg == NULL) | |
84 | if (msg == NULL) | ||
85 | { | 84 | { |
86 | alucb->cb (alucb->cb_cls, NULL); | 85 | pal_ctx->cb (pal_ctx->cb_cls, NULL); |
87 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); | 86 | GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO); |
88 | GNUNET_free (alucb); | 87 | GNUNET_free (pal_ctx); |
89 | return; | 88 | return; |
90 | } | 89 | } |
91 | GNUNET_break (ntohs (msg->type) == | ||
92 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); | ||
93 | size = ntohs (msg->size); | 90 | size = ntohs (msg->size); |
91 | GNUNET_break (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE); | ||
94 | if (size == sizeof (struct GNUNET_MessageHeader)) | 92 | if (size == sizeof (struct GNUNET_MessageHeader)) |
95 | { | 93 | { |
96 | /* done! */ | 94 | /* done! */ |
97 | alucb->cb (alucb->cb_cls, NULL ); | 95 | pal_ctx->cb (pal_ctx->cb_cls, NULL ); |
98 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); | 96 | GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO); |
99 | GNUNET_free (alucb); | 97 | GNUNET_free (pal_ctx); |
100 | return; | 98 | return; |
101 | } | 99 | } |
102 | address = (const struct GNUNET_HELLO_Address *) &msg[1]; | 100 | |
103 | #if 0 | 101 | size_t tlen = ntohl(air_msg->pluginlen); |
104 | if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0') | 102 | size_t alen = ntohl(air_msg->addrlen); |
103 | |||
104 | if (size != sizeof (struct GNUNET_MessageHeader) + sizeof (struct AddressIterateResponseMessage) + tlen + alen) | ||
105 | { | ||
106 | GNUNET_break_op (0); | ||
107 | pal_ctx->cb (pal_ctx->cb_cls, NULL ); | ||
108 | GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO); | ||
109 | GNUNET_free (pal_ctx); | ||
110 | return; | ||
111 | } | ||
112 | |||
113 | char * addr = (char *) &air_msg[1]; | ||
114 | char * transport_name = &addr[alen]; | ||
115 | |||
116 | if (transport_name[tlen] != '\0') | ||
105 | { | 117 | { |
106 | /* invalid reply */ | 118 | GNUNET_break_op (0); |
107 | GNUNET_break (0); | 119 | pal_ctx->cb (pal_ctx->cb_cls, NULL ); |
108 | alucb->cb (alucb->cb_cls, NULL ); | 120 | GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO); |
109 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); | 121 | GNUNET_free (pal_ctx); |
110 | GNUNET_free (alucb); | ||
111 | return; | 122 | return; |
112 | } | 123 | } |
113 | #endif | 124 | |
125 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "peer %s transport_name: %s\n",GNUNET_i2s(&air_msg->peer), transport_name); | ||
126 | |||
127 | address = GNUNET_HELLO_address_allocate(&air_msg->peer, transport_name, addr, alen); | ||
128 | |||
114 | /* expect more replies */ | 129 | /* expect more replies */ |
115 | GNUNET_CLIENT_receive (alucb->client, &peer_address_response_processor, alucb, | 130 | GNUNET_CLIENT_receive (pal_ctx->client, &peer_address_response_processor, pal_ctx, |
116 | GNUNET_TIME_absolute_get_remaining (alucb->timeout)); | 131 | GNUNET_TIME_absolute_get_remaining (pal_ctx->timeout)); |
117 | 132 | ||
118 | /* REFACTOR FIX THIS */ | 133 | pal_ctx->cb (pal_ctx->cb_cls, address); |
119 | alucb->cb (alucb->cb_cls, address ); | ||
120 | } | 134 | } |
121 | 135 | ||
122 | 136 | ||
@@ -132,35 +146,45 @@ peer_address_response_processor (void *cls, | |||
132 | */ | 146 | */ |
133 | struct GNUNET_TRANSPORT_PeerAddressLookupContext * | 147 | struct GNUNET_TRANSPORT_PeerAddressLookupContext * |
134 | GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Handle *cfg, | 148 | GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Handle *cfg, |
135 | const struct GNUNET_PeerIdentity *peer, | 149 | const struct GNUNET_PeerIdentity *peer, |
136 | int one_shot, | 150 | int one_shot, |
137 | struct GNUNET_TIME_Relative timeout, | 151 | struct GNUNET_TIME_Relative timeout, |
138 | GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback, | 152 | GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback, |
139 | void *peer_address_callback_cls) | 153 | void *peer_address_callback_cls) |
140 | { | 154 | { |
141 | struct PeerAddressLookupMessage msg; | 155 | struct GNUNET_TRANSPORT_PeerAddressLookupContext *pal_ctx; |
142 | struct GNUNET_TRANSPORT_PeerAddressLookupContext *alc; | 156 | struct AddressIterateMessage msg; |
143 | struct GNUNET_CLIENT_Connection *client; | 157 | struct GNUNET_CLIENT_Connection *client; |
158 | struct GNUNET_TIME_Absolute abs_timeout; | ||
144 | 159 | ||
145 | client = GNUNET_CLIENT_connect ("transport", cfg); | 160 | client = GNUNET_CLIENT_connect ("transport", cfg); |
146 | if (client == NULL) | 161 | if (client == NULL) |
162 | { | ||
163 | peer_address_callback (peer_address_callback_cls, NULL); | ||
147 | return NULL; | 164 | return NULL; |
148 | msg.header.size = htons (sizeof (struct PeerAddressLookupMessage)); | 165 | } |
149 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP); | 166 | |
150 | msg.reserved = htonl (0); | 167 | abs_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
151 | msg.timeout = GNUNET_TIME_relative_hton (timeout); | 168 | |
152 | memcpy (&msg.peer, peer, sizeof (struct GNUNET_PeerIdentity)); | 169 | msg.header.size = htons (sizeof (struct AddressIterateMessage)); |
153 | alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerAddressLookupContext)); | 170 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE); |
154 | alc->cb = peer_address_callback; | 171 | msg.timeout = GNUNET_TIME_absolute_hton (abs_timeout); |
155 | alc->cb_cls = peer_address_callback_cls; | 172 | if (peer == NULL) |
156 | alc->timeout = GNUNET_TIME_relative_to_absolute (timeout); | 173 | memset (&msg.peer, 0 , sizeof (struct GNUNET_PeerIdentity)); |
157 | alc->client = client; | 174 | else |
175 | memcpy (&msg.peer, peer , sizeof (struct GNUNET_PeerIdentity)); | ||
176 | |||
177 | pal_ctx = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerAddressLookupContext)); | ||
178 | pal_ctx->cb = peer_address_callback; | ||
179 | pal_ctx->cb_cls = peer_address_callback_cls; | ||
180 | pal_ctx->timeout = abs_timeout; | ||
181 | pal_ctx->client = client; | ||
158 | GNUNET_assert (GNUNET_OK == | 182 | GNUNET_assert (GNUNET_OK == |
159 | GNUNET_CLIENT_transmit_and_get_response (client, &msg.header, | 183 | GNUNET_CLIENT_transmit_and_get_response (client, &msg.header, |
160 | timeout, GNUNET_YES, | 184 | timeout, GNUNET_YES, |
161 | &peer_address_response_processor, | 185 | &peer_address_response_processor, |
162 | alc)); | 186 | pal_ctx)); |
163 | return alc; | 187 | return pal_ctx; |
164 | } | 188 | } |
165 | 189 | ||
166 | 190 | ||
@@ -179,64 +203,7 @@ GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct | |||
179 | } | 203 | } |
180 | 204 | ||
181 | /** | 205 | /** |
182 | * Function called with responses from the service. | 206 | * Return all the known addresses for all peers. |
183 | * | ||
184 | * @param cls our 'struct AddressLookupCtx*' | ||
185 | * @param msg NULL on timeout or error, otherwise presumably a | ||
186 | * message with the human-readable peer and address | ||
187 | */ | ||
188 | static void | ||
189 | peer_address_iteration_response_processor (void *cls, | ||
190 | const struct GNUNET_MessageHeader *msg) | ||
191 | { | ||
192 | struct GNUNET_TRANSPORT_PeerAddressLookupContext *alucb = cls; | ||
193 | struct AddressIterateResponseMessage *arm; | ||
194 | struct GNUNET_HELLO_Address * address; | ||
195 | uint16_t size; | ||
196 | |||
197 | if (msg == NULL) | ||
198 | { | ||
199 | alucb->cb (alucb->cb_cls, NULL); | ||
200 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); | ||
201 | GNUNET_free (alucb); | ||
202 | return; | ||
203 | } | ||
204 | |||
205 | GNUNET_break (ntohs (msg->type) == | ||
206 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); | ||
207 | size = ntohs (msg->size); | ||
208 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message type %u size %u\n", | ||
209 | ntohs (msg->type), size); | ||
210 | if (size == sizeof (struct GNUNET_MessageHeader)) | ||
211 | { | ||
212 | /* done! */ | ||
213 | alucb->cb (alucb->cb_cls, NULL); | ||
214 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); | ||
215 | GNUNET_free (alucb); | ||
216 | return; | ||
217 | } | ||
218 | if (size < sizeof (struct AddressIterateResponseMessage)) | ||
219 | { | ||
220 | /* invalid reply */ | ||
221 | GNUNET_break (0); | ||
222 | alucb->cb (alucb->cb_cls, NULL); | ||
223 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); | ||
224 | GNUNET_free (alucb); | ||
225 | return; | ||
226 | } | ||
227 | |||
228 | arm = (struct AddressIterateResponseMessage *) &msg[1]; | ||
229 | address = (struct GNUNET_HELLO_Address *) &arm[1]; | ||
230 | |||
231 | /* expect more replies */ | ||
232 | GNUNET_CLIENT_receive (alucb->client, &peer_address_response_processor, alucb, | ||
233 | GNUNET_TIME_absolute_get_remaining (alucb->timeout)); | ||
234 | alucb->cb (alucb->cb_cls, address); | ||
235 | } | ||
236 | |||
237 | |||
238 | /** | ||
239 | * Return all the known addresses for a peer. | ||
240 | * | 207 | * |
241 | * @param cfg configuration to use | 208 | * @param cfg configuration to use |
242 | * @param timeout how long is the lookup allowed to take at most | 209 | * @param timeout how long is the lookup allowed to take at most |
@@ -250,32 +217,12 @@ GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
250 | peer_address_callback, | 217 | peer_address_callback, |
251 | void *peer_address_callback_cls) | 218 | void *peer_address_callback_cls) |
252 | { | 219 | { |
253 | struct AddressIterateMessage msg; | 220 | GNUNET_TRANSPORT_peer_get_active_addresses (cfg, |
254 | struct GNUNET_TIME_Absolute abs_timeout; | 221 | NULL, |
255 | struct GNUNET_TRANSPORT_PeerAddressLookupContext *peer_address_lookup_cb; | 222 | GNUNET_YES, |
256 | struct GNUNET_CLIENT_Connection *client; | 223 | timeout, |
257 | 224 | peer_address_callback, | |
258 | client = GNUNET_CLIENT_connect ("transport", cfg); | 225 | peer_address_callback_cls); |
259 | if (client == NULL) | ||
260 | { | ||
261 | peer_address_callback (peer_address_callback_cls, NULL); | ||
262 | return; | ||
263 | } | ||
264 | abs_timeout = GNUNET_TIME_relative_to_absolute (timeout); | ||
265 | |||
266 | msg.header.size = htons (sizeof (struct AddressIterateMessage)); | ||
267 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE); | ||
268 | msg.timeout = GNUNET_TIME_absolute_hton (abs_timeout); | ||
269 | peer_address_lookup_cb = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerAddressLookupContext)); | ||
270 | peer_address_lookup_cb->cb = peer_address_callback; | ||
271 | peer_address_lookup_cb->cb_cls = peer_address_callback_cls; | ||
272 | peer_address_lookup_cb->timeout = abs_timeout; | ||
273 | peer_address_lookup_cb->client = client; | ||
274 | GNUNET_assert (GNUNET_OK == | ||
275 | GNUNET_CLIENT_transmit_and_get_response (client, &msg.header, | ||
276 | timeout, GNUNET_YES, | ||
277 | &peer_address_iteration_response_processor, | ||
278 | peer_address_lookup_cb)); | ||
279 | } | 226 | } |
280 | 227 | ||
281 | /* end of transport_api_peer_address_lookup.c */ | 228 | /* end of transport_api_peer_address_lookup.c */ |
diff --git a/src/transport/transport_api_address_to_string.c b/src/transport/transport_api_address_to_string.c index 259c77152..2e5a34ce2 100644 --- a/src/transport/transport_api_address_to_string.c +++ b/src/transport/transport_api_address_to_string.c | |||
@@ -76,7 +76,7 @@ address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg) | |||
76 | return; | 76 | return; |
77 | } | 77 | } |
78 | GNUNET_break (ntohs (msg->type) == | 78 | GNUNET_break (ntohs (msg->type) == |
79 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); | 79 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE); |
80 | size = ntohs (msg->size); | 80 | size = ntohs (msg->size); |
81 | if (size == sizeof (struct GNUNET_MessageHeader)) | 81 | if (size == sizeof (struct GNUNET_MessageHeader)) |
82 | { | 82 | { |
@@ -108,10 +108,8 @@ address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg) | |||
108 | * | 108 | * |
109 | * @param cfg configuration to use | 109 | * @param cfg configuration to use |
110 | * @param address address to convert (binary format) | 110 | * @param address address to convert (binary format) |
111 | * @param addressLen number of bytes in address | ||
112 | * @param numeric should (IP) addresses be displayed in numeric form | 111 | * @param numeric should (IP) addresses be displayed in numeric form |
113 | * (otherwise do reverse DNS lookup) | 112 | * (otherwise do reverse DNS lookup) |
114 | * @param nameTrans name of the transport to which the address belongs | ||
115 | * @param timeout how long is the lookup allowed to take at most | 113 | * @param timeout how long is the lookup allowed to take at most |
116 | * @param aluc function to call with the results | 114 | * @param aluc function to call with the results |
117 | * @param aluc_cls closure for aluc | 115 | * @param aluc_cls closure for aluc |
@@ -132,6 +130,7 @@ GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cf | |||
132 | struct GNUNET_CLIENT_Connection *client; | 130 | struct GNUNET_CLIENT_Connection *client; |
133 | char *addrbuf; | 131 | char *addrbuf; |
134 | 132 | ||
133 | GNUNET_assert (address != NULL); | ||
135 | alen = GNUNET_HELLO_address_get_size (address); | 134 | alen = GNUNET_HELLO_address_get_size (address); |
136 | len = sizeof (struct AddressLookupMessage) + alen; | 135 | len = sizeof (struct AddressLookupMessage) + alen; |
137 | if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 136 | if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
@@ -139,12 +138,15 @@ GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cf | |||
139 | GNUNET_break (0); | 138 | GNUNET_break (0); |
140 | return NULL; | 139 | return NULL; |
141 | } | 140 | } |
141 | |||
142 | client = GNUNET_CLIENT_connect ("transport", cfg); | 142 | client = GNUNET_CLIENT_connect ("transport", cfg); |
143 | if (client == NULL) | 143 | if (client == NULL) |
144 | return NULL; | 144 | return NULL; |
145 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
146 | "GNUNET_TRANSPORT_address_to_string\n"); | ||
145 | msg = GNUNET_malloc (len); | 147 | msg = GNUNET_malloc (len); |
146 | msg->header.size = htons (len); | 148 | msg->header.size = htons (len); |
147 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP); | 149 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING); |
148 | msg->numeric_only = htonl (numeric); | 150 | msg->numeric_only = htonl (numeric); |
149 | msg->timeout = GNUNET_TIME_relative_hton (timeout); | 151 | msg->timeout = GNUNET_TIME_relative_hton (timeout); |
150 | msg->addrlen = htonl (alen); | 152 | msg->addrlen = htonl (alen); |