From 83b19539f4d322b43683f5838b72e9ec2c8e6073 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 4 Nov 2011 14:00:32 +0000 Subject: curly wars / auto-indentation --- src/ats-test/test_transport_ats_multiple_peers.c | 3 +- src/ats/ats.h | 53 +- src/ats/ats_api.c | 160 +-- src/ats/ats_api_peer_change_preference.c | 51 +- src/ats/ats_api_performance.c | 225 ++- src/ats/ats_api_scheduling.c | 302 ++-- src/ats/gnunet-service-ats.c | 49 +- src/ats/gnunet-service-ats_addresses.c | 236 ++-- src/ats/gnunet-service-ats_addresses.h | 20 +- src/ats/gnunet-service-ats_math.h | 9 +- src/ats/gnunet-service-ats_performance.c | 109 +- src/ats/gnunet-service-ats_performance.h | 20 +- src/ats/gnunet-service-ats_reservations.c | 56 +- src/ats/gnunet-service-ats_reservations.h | 7 +- src/ats/gnunet-service-ats_scheduling.c | 177 ++- src/ats/gnunet-service-ats_scheduling.h | 27 +- src/ats/test_ats_api_bandwidth_consumption.c | 131 +- src/ats/test_ats_api_scheduling.c | 105 +- src/ats/test_ats_api_update_address.c | 3 +- src/block/block.c | 25 +- src/block/plugin_block_dht.c | 24 +- src/block/plugin_block_dns.c | 3 +- src/block/plugin_block_fs.c | 48 +- src/block/plugin_block_test.c | 14 +- src/chat/gnunet-service-chat.c | 27 +- src/core/core_api.c | 29 +- src/core/core_api_iterate_peers.c | 6 +- src/core/gnunet-core-list-connections.c | 2 +- src/core/gnunet-service-core.c | 8 +- src/core/gnunet-service-core.h | 2 +- src/core/gnunet-service-core_clients.c | 281 ++-- src/core/gnunet-service-core_clients.h | 39 +- src/core/gnunet-service-core_kx.c | 378 +++-- src/core/gnunet-service-core_kx.h | 25 +- src/core/gnunet-service-core_neighbours.c | 58 +- src/core/gnunet-service-core_neighbours.h | 6 +- src/core/gnunet-service-core_sessions.c | 242 ++-- src/core/gnunet-service-core_sessions.h | 25 +- src/core/gnunet-service-core_typemap.c | 60 +- src/core/gnunet-service-core_typemap.h | 20 +- src/core/test_core_api.c | 23 +- src/core/test_core_api_reliability.c | 19 +- src/core/test_core_api_send_to_self.c | 4 +- src/core/test_core_api_start_only.c | 15 +- src/core/test_core_quota_compliance.c | 76 +- src/datacache/datacache.c | 14 +- src/datacache/plugin_datacache_sqlite.c | 85 +- src/datastore/plugin_datastore_sqlite.c | 30 +- src/datastore/test_datastore_api.c | 6 +- src/dht/dht_api.c | 52 +- src/dht/gnunet-dht-get.c | 12 +- src/dht/gnunet-dht-put.c | 6 +- src/dht/gnunet-service-dht.c | 44 +- src/dht/gnunet-service-dht_clients.c | 491 +++---- src/dht/gnunet-service-dht_clients.h | 17 +- src/dht/gnunet-service-dht_datacache.c | 121 +- src/dht/gnunet-service-dht_datacache.h | 28 +- src/dht/gnunet-service-dht_hello.c | 36 +- src/dht/gnunet-service-dht_neighbours.c | 982 +++++++------ src/dht/gnunet-service-dht_neighbours.h | 52 +- src/dht/gnunet-service-dht_nse.c | 10 +- src/dht/gnunet-service-dht_routing.c | 144 +- src/dht/gnunet-service-dht_routing.h | 27 +- src/dht/test_dht_2dtorus.c | 208 ++- src/dht/test_dht_api.c | 16 +- src/dht/test_dht_multipeer.c | 210 ++- src/dht/test_dht_twopeer.c | 30 +- src/dht/test_dht_twopeer_get_put.c | 22 +- src/dht/test_dht_twopeer_path_tracking.c | 24 +- src/dht/test_dht_twopeer_put_get.c | 21 +- src/dv/gnunet-service-dv.c | 40 +- src/dv/plugin_transport_dv.c | 4 +- src/dv/test_transport_api_dv.c | 12 +- src/fragmentation/fragmentation.c | 2 +- src/fragmentation/test_fragmentation.c | 8 +- src/fs/fs_file_information.c | 112 +- src/fs/fs_uri.c | 22 +- src/fs/gnunet-fs.c | 27 +- src/fs/gnunet-service-fs.c | 42 +- src/fs/gnunet-service-fs_cp.c | 85 +- src/fs/gnunet-service-fs_cp.h | 7 +- src/fs/gnunet-service-fs_indexing.c | 9 +- src/fs/gnunet-service-fs_lc.c | 3 +- src/fs/gnunet-service-fs_pe.c | 90 +- src/fs/gnunet-service-fs_pr.c | 91 +- src/fs/gnunet-service-fs_pr.h | 4 +- src/fs/gnunet-service-fs_put.c | 6 +- src/hello/hello.c | 4 +- src/hostlist/gnunet-daemon-hostlist.c | 4 +- src/hostlist/hostlist-client.c | 4 +- src/hostlist/hostlist-server.c | 2 +- src/hostlist/test_gnunet_daemon_hostlist.c | 3 +- .../test_gnunet_daemon_hostlist_learning.c | 6 +- .../test_gnunet_daemon_hostlist_reconnect.c | 3 +- src/include/gnunet_ats_service.h | 185 +-- src/include/gnunet_block_lib.h | 4 +- src/include/gnunet_common.h | 8 +- src/include/gnunet_core_service.h | 14 +- src/include/gnunet_dht_service.h | 11 +- src/include/gnunet_mesh_service.h | 8 +- src/include/gnunet_plugin_lib.h | 14 +- src/include/gnunet_server_lib.h | 3 +- src/include/gnunet_strings_lib.h | 4 +- src/include/gnunet_transport_service.h | 10 +- src/mesh/gnunet-service-mesh.c | 905 ++++++------ src/mesh/mesh_api.c | 40 +- src/mesh/mesh_protocol.h | 2 +- src/mesh/mesh_tunnel_tree.c | 334 ++--- src/mesh/mesh_tunnel_tree.h | 49 +- src/mesh/test_mesh_api.c | 3 +- src/mesh/test_mesh_local_2.c | 7 +- src/mesh/test_mesh_small.c | 335 ++--- src/mesh/test_mesh_small_unicast_far.c | 111 +- src/mesh/test_mesh_tree_api.c | 142 +- src/nat/nat.c | 6 +- src/nat/test_nat_test.c | 3 +- src/nse/gnunet-nse-profiler.c | 12 +- src/nse/gnunet-service-nse.c | 17 +- src/statistics/statistics_api.c | 702 +++++----- src/testing/test_testing_connect.c | 6 +- src/testing/test_testing_reconnect.c | 12 +- src/testing/test_testing_topology.c | 11 +- src/testing/testing.c | 7 +- src/testing/testing_group.c | 25 +- src/testing/testing_peergroup.c | 7 +- src/topology/gnunet-daemon-topology.c | 13 +- src/transport/gnunet-service-transport.c | 146 +- src/transport/gnunet-service-transport_blacklist.c | 4 +- src/transport/gnunet-service-transport_clients.c | 46 +- src/transport/gnunet-service-transport_hello.c | 3 +- .../gnunet-service-transport_neighbours.c | 886 ++++++------ .../gnunet-service-transport_neighbours.h | 68 +- .../gnunet-service-transport_validation.c | 53 +- .../gnunet-transport-connect-running-peers.c | 24 +- src/transport/gnunet-transport-wlan-helper.c | 4 +- src/transport/gnunet-transport.c | 242 ++-- src/transport/gnunet_wlan_sender.c | 254 ++-- src/transport/plugin_transport_http.c | 263 ++-- src/transport/plugin_transport_http.h | 20 +- src/transport/plugin_transport_http_client.c | 181 +-- src/transport/plugin_transport_http_server.c | 327 +++-- src/transport/plugin_transport_sat_constants.h | 20 +- src/transport/plugin_transport_tcp.c | 31 +- src/transport/plugin_transport_udp.c | 477 ++++--- src/transport/plugin_transport_udp_new.c | 222 +-- src/transport/plugin_transport_unix.c | 5 +- src/transport/plugin_transport_wlan.c | 413 +++--- src/transport/test_quota_compliance.c | 161 ++- src/transport/test_transport_api.c | 82 +- src/transport/test_transport_api_disconnect.c | 98 +- src/transport/test_transport_api_limited_sockets.c | 28 +- src/transport/test_transport_api_reliability.c | 88 +- src/transport/test_transport_api_timeout.c | 43 +- src/transport/test_transport_api_unreliability.c | 45 +- .../test_transport_api_unreliability_constant.c | 41 +- src/transport/test_transport_startonly.c | 14 +- src/transport/test_transport_testing.c | 68 +- src/transport/transport-testing.c | 134 +- src/transport/transport-testing.h | 36 +- src/transport/transport_api.c | 4 +- src/transport/transport_api_address_iterate.c | 5 +- src/util/bandwidth.c | 141 +- src/util/bio.c | 253 ++-- src/util/client.c | 804 ++++++----- src/util/common_allocation.c | 56 +- src/util/common_logging.c | 400 +++--- src/util/configuration.c | 768 +++++------ src/util/connection.c | 1015 +++++++------- src/util/container_bloomfilter.c | 260 ++-- src/util/container_heap.c | 201 ++- src/util/container_meta_data.c | 792 ++++++----- src/util/container_multihashmap.c | 235 ++-- src/util/container_slist.c | 72 +- src/util/crypto_aes.c | 77 +- src/util/crypto_crc.c | 12 +- src/util/crypto_hash.c | 214 ++- src/util/crypto_hkdf.c | 118 +- src/util/crypto_kdf.c | 14 +- src/util/crypto_ksk.c | 513 ++++--- src/util/crypto_random.c | 199 ++- src/util/crypto_rsa.c | 753 +++++----- src/util/disk.c | 1437 ++++++++++---------- src/util/getopt.c | 1018 +++++++------- src/util/getopt_helpers.c | 171 ++- src/util/gnunet-config-diff.c | 8 +- src/util/gnunet-resolver.c | 6 +- src/util/gnunet-service-resolver.c | 411 +++--- src/util/load.c | 46 +- src/util/network.c | 1072 +++++++-------- src/util/os_installation.c | 274 ++-- src/util/os_network.c | 365 +++-- src/util/os_priority.c | 1110 ++++++++------- src/util/peer.c | 102 +- src/util/perf_crypto_hash.c | 20 +- src/util/plugin.c | 143 +- src/util/program.c | 108 +- src/util/pseudonym.c | 277 ++-- src/util/resolver_api.c | 598 ++++---- src/util/scheduler.c | 825 ++++++----- src/util/server.c | 769 +++++------ src/util/server_mst.c | 264 ++-- src/util/server_nc.c | 205 ++- src/util/server_tc.c | 76 +- src/util/service.c | 1406 ++++++++++--------- src/util/signal.c | 16 +- src/util/strings.c | 404 +++--- src/util/test_bio.c | 55 +- src/util/test_client.c | 56 +- src/util/test_common_allocation.c | 24 +- src/util/test_common_logging.c | 53 +- src/util/test_common_logging_dummy.c | 4 +- src/util/test_common_logging_runtime_loglevels.c | 364 ++--- src/util/test_configuration.c | 477 ++++--- src/util/test_connection.c | 64 +- src/util/test_connection_addressing.c | 69 +- src/util/test_connection_receive_cancel.c | 22 +- src/util/test_connection_timeout.c | 43 +- src/util/test_connection_timeout_no_connect.c | 16 +- src/util/test_connection_transmit_cancel.c | 15 +- src/util/test_container_bloomfilter.c | 206 ++- src/util/test_container_heap.c | 14 +- src/util/test_container_meta_data.c | 256 ++-- src/util/test_container_multihashmap.c | 29 +- src/util/test_container_slist.c | 93 +- src/util/test_crypto_aes.c | 120 +- src/util/test_crypto_aes_weak.c | 127 +- src/util/test_crypto_hash.c | 13 +- src/util/test_crypto_hkdf.c | 94 +- src/util/test_crypto_ksk.c | 192 ++- src/util/test_crypto_random.c | 18 +- src/util/test_crypto_rsa.c | 210 ++- src/util/test_disk.c | 101 +- src/util/test_getopt.c | 68 +- src/util/test_os_network.c | 8 +- src/util/test_os_priority.c | 12 +- src/util/test_os_start_process.c | 78 +- src/util/test_peer.c | 46 +- src/util/test_plugin.c | 6 +- src/util/test_program.c | 18 +- src/util/test_pseudonym.c | 46 +- src/util/test_resolver_api.c | 267 ++-- src/util/test_scheduler.c | 16 +- src/util/test_scheduler_delay.c | 20 +- src/util/test_server.c | 45 +- src/util/test_server_disconnect.c | 21 +- src/util/test_server_with_client.c | 58 +- src/util/test_server_with_client_unix.c | 52 +- src/util/test_service.c | 77 +- src/util/test_strings.c | 24 +- src/util/test_time.c | 52 +- src/util/time.c | 62 +- src/util/winproc.c | 227 ++-- src/vpn/gnunet-daemon-exit.c | 178 +-- src/vpn/gnunet-daemon-vpn-dns.c | 41 +- src/vpn/gnunet-daemon-vpn-helper.c | 315 +++-- src/vpn/gnunet-daemon-vpn.c | 111 +- src/vpn/gnunet-dns-parser.c | 182 +-- src/vpn/gnunet-service-dns-p.h | 3 +- src/vpn/gnunet-service-dns.c | 676 ++++----- 259 files changed, 18265 insertions(+), 19233 deletions(-) (limited to 'src') diff --git a/src/ats-test/test_transport_ats_multiple_peers.c b/src/ats-test/test_transport_ats_multiple_peers.c index c79454411..4d32dc462 100644 --- a/src/ats-test/test_transport_ats_multiple_peers.c +++ b/src/ats-test/test_transport_ats_multiple_peers.c @@ -605,8 +605,7 @@ send_task_f (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static void notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { send_task = GNUNET_SCHEDULER_add_now (&send_task_f, NULL); } diff --git a/src/ats/ats.h b/src/ats/ats.h index 3ae6fdb65..5b9fa8696 100644 --- a/src/ats/ats.h +++ b/src/ats/ats.h @@ -31,13 +31,12 @@ enum StartFlag { - + START_FLAG_SCHEDULING = 0, START_FLAG_PERFORMANCE_WITH_PIC = 1, START_FLAG_PERFORMANCE_NO_PIC = 2 - }; @@ -55,7 +54,7 @@ struct ClientStartMessage struct RequestAddressMessage { struct GNUNET_MessageHeader header; - + uint32_t reserved GNUNET_PACKED; struct GNUNET_PeerIdentity peer; @@ -77,10 +76,10 @@ struct AddressUpdateMessage uint32_t session_id GNUNET_PACKED; /* followed by: - - struct GNUNET_ATS_Information [ats_count]; - - char address[address_length] - - char plugin_name[plugin_name_length] (including '\0'-termination). - */ + * - struct GNUNET_ATS_Information [ats_count]; + * - char address[address_length] + * - char plugin_name[plugin_name_length] (including '\0'-termination). + */ }; @@ -99,9 +98,9 @@ struct AddressUseMessage uint32_t session_id GNUNET_PACKED; /* followed by: - - char address[address_length] - - char plugin_name[plugin_name_length] (including '\0'-termination). - */ + * - char address[address_length] + * - char plugin_name[plugin_name_length] (including '\0'-termination). + */ }; @@ -121,9 +120,9 @@ struct AddressDestroyedMessage uint32_t session_id GNUNET_PACKED; /* followed by: - - char address[address_length] - - char plugin_name[plugin_name_length] (including '\0'-termination). - */ + * - char address[address_length] + * - char plugin_name[plugin_name_length] (including '\0'-termination). + */ }; @@ -143,14 +142,14 @@ struct AddressSuggestionMessage uint32_t session_id GNUNET_PACKED; struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out; - + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; /* followed by: - - struct GNUNET_ATS_Information [ats_count]; - - char address[address_length] - - char plugin_name[plugin_name_length] (including '\0'-termination). - */ + * - struct GNUNET_ATS_Information [ats_count]; + * - char address[address_length] + * - char plugin_name[plugin_name_length] (including '\0'-termination). + */ }; @@ -168,14 +167,14 @@ struct PeerInformationMessage uint16_t plugin_name_length GNUNET_PACKED; struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out; - + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; - /* followed by: - - struct GNUNET_ATS_Information [ats_count]; - - char address[address_length] - - char plugin_name[plugin_name_length] (including '\0'-termination). - */ + /* followed by: + * - struct GNUNET_ATS_Information [ats_count]; + * - char address[address_length] + * - char plugin_name[plugin_name_length] (including '\0'-termination). + */ }; @@ -222,7 +221,7 @@ struct PreferenceInformation uint32_t preference_kind GNUNET_PACKED; float preference_value GNUNET_PACKED; - + }; @@ -234,8 +233,8 @@ struct ChangePreferenceMessage struct GNUNET_PeerIdentity peer; - /* followed by 'num_preferences' - struct PreferenceInformation values */ + /* followed by 'num_preferences' + * struct PreferenceInformation values */ }; diff --git a/src/ats/ats_api.c b/src/ats/ats_api.c index 61d3895d2..e25f9a8ec 100644 --- a/src/ats/ats_api.c +++ b/src/ats/ats_api.c @@ -138,26 +138,22 @@ set_bw_connections (void *cls, const GNUNET_HashCode * key, void *value) GNUNET_assert (GNUNET_SYSERR != ar->connected); /* FIXME: ||1 because we currently NEVER get 'connected' events... */ - if ( (GNUNET_YES == ar->connected) || 1) + if ((GNUNET_YES == ar->connected) || 1) { ar->bandwidth_in = sbc->bw_in; ar->bandwidth_out = sbc->bw_out; GNUNET_BANDWIDTH_tracker_update_quota (&ar->available_recv_window, ar->bandwidth_in); LOG (GNUNET_ERROR_TYPE_DEBUG, - "Bandwidth assigned to peer %s is i:%u/o:%u bytes/s\n", - GNUNET_i2s ((const struct GNUNET_PeerIdentity *) key), - ntohl (ar->bandwidth_in.value__), - ntohl (ar->bandwidth_out.value__)); + "Bandwidth assigned to peer %s is i:%u/o:%u bytes/s\n", + GNUNET_i2s ((const struct GNUNET_PeerIdentity *) key), + ntohl (ar->bandwidth_in.value__), ntohl (ar->bandwidth_out.value__)); if (NULL != sbc->atc->alloc_cb) sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls, (const struct GNUNET_PeerIdentity *) key, - ar->plugin_name, ar->plugin_addr, - ar->plugin_addr_len, - ar->session, - ar->bandwidth_out, - ar->bandwidth_in, - NULL, 0); + ar->plugin_name, ar->plugin_addr, ar->plugin_addr_len, + ar->session, ar->bandwidth_out, ar->bandwidth_in, + NULL, 0); } else if (ntohl (ar->bandwidth_out.value__) > 0) { @@ -166,17 +162,16 @@ set_bw_connections (void *cls, const GNUNET_HashCode * key, void *value) if (NULL != sbc->atc->alloc_cb) sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls, (const struct GNUNET_PeerIdentity *) key, - ar->plugin_name, ar->plugin_addr, - ar->plugin_addr_len, ar->session, ar->bandwidth_out, - ar->bandwidth_in, NULL, 0); + ar->plugin_name, ar->plugin_addr, ar->plugin_addr_len, + ar->session, ar->bandwidth_out, ar->bandwidth_in, + NULL, 0); } else LOG (GNUNET_ERROR_TYPE_DEBUG, - "Not communicating bandwidth assigned to peer %s: not connected and bw is: i:%u/o:%u bytes/s\n", - GNUNET_i2s ((const struct GNUNET_PeerIdentity *) key), - ntohl (ar->bandwidth_in.value__), - ntohl (ar->bandwidth_out.value__)); - + "Not communicating bandwidth assigned to peer %s: not connected and bw is: i:%u/o:%u bytes/s\n", + GNUNET_i2s ((const struct GNUNET_PeerIdentity *) key), + ntohl (ar->bandwidth_in.value__), ntohl (ar->bandwidth_out.value__)); + return GNUNET_YES; } @@ -205,9 +200,8 @@ update_bandwidth_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) bwc.bw_out = GNUNET_BANDWIDTH_value_init (atc->total_bps_out / ac); LOG (GNUNET_ERROR_TYPE_DEBUG, "Trivial implementation: bandwidth assigned to each peer is i:%u/o:%u bytes/s\n", - ntohl (bwc.bw_in.value__), - ntohl (bwc.bw_out.value__)); - GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &set_bw_connections, &bwc); + ntohl (bwc.bw_in.value__), ntohl (bwc.bw_out.value__)); + GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &set_bw_connections, &bwc); } @@ -244,9 +238,8 @@ suggest_address (void *cls, const GNUNET_HashCode * key, void *value) #if DEBUG_ATS LOG (GNUNET_ERROR_TYPE_DEBUG, "Suggesting address for peer `%s', starting with i:%u/o:%u bytes/s\n", - GNUNET_h2s (key), - asc->atc->total_bps_in/32, - asc->atc->total_bps_out/32); + GNUNET_h2s (key), asc->atc->total_bps_in / 32, + asc->atc->total_bps_out / 32); #endif /* trivial strategy: pick first available address... */ @@ -285,8 +278,8 @@ GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *atc, struct GNUNET_ATS_SuggestionContext *asc; #if DEBUG_ATS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Looking up suggested address for peer `%s'\n", GNUNET_i2s (peer)); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Looking up suggested address for peer `%s'\n", + GNUNET_i2s (peer)); #endif asc = GNUNET_malloc (sizeof (struct GNUNET_ATS_SuggestionContext)); asc->cb = cb; @@ -441,70 +434,70 @@ update_session (void *cls, const GNUNET_HashCode * key, void *value) if (0 != strcmp (arnew->plugin_name, arold->plugin_name)) return GNUNET_YES; - if (! (((arnew->session == arold->session) && (arnew->session != NULL)) || - ((arold->session == NULL) && - (arold->plugin_addr_len == arnew->plugin_addr_len) && - (0 == - memcmp (arold->plugin_addr, arnew->plugin_addr, - arnew->plugin_addr_len))))) - return GNUNET_YES; /* no match */ + if (! + (((arnew->session == arold->session) && (arnew->session != NULL)) || + ((arold->session == NULL) && + (arold->plugin_addr_len == arnew->plugin_addr_len) && + (0 == + memcmp (arold->plugin_addr, arnew->plugin_addr, + arnew->plugin_addr_len))))) + return GNUNET_YES; /* no match */ /* records match */ #if DEBUG_ATS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Updating session for peer `%s' plugin `%s'\n", GNUNET_h2s (key), - arold->plugin_name); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating session for peer `%s' plugin `%s'\n", + GNUNET_h2s (key), arold->plugin_name); #endif if (arnew->session != arold->session) - { - arold->session = arnew->session; - } + { + arold->session = arnew->session; + } if ((arnew->connected == GNUNET_YES) && (arold->connected == GNUNET_NO)) - { - arold->connected = GNUNET_YES; - } - + { + arold->connected = GNUNET_YES; + } + /* Update existing value */ c_new = 0; while (c_new < arnew->ats_count) + { + c_old = 0; + found = GNUNET_NO; + while (c_old < arold->ats_count) { - c_old = 0; - found = GNUNET_NO; - while (c_old < arold->ats_count) + if (arold->ats[c_old].type == arnew->ats[c_new].type) { - if (arold->ats[c_old].type == arnew->ats[c_new].type) - { #if DEBUG_ATS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Found type %i, old value=%i new value=%i\n", - ntohl (arold->ats[c_old].type), ntohl (arold->ats[c_old].value), - ntohl (arnew->ats[c_new].value)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Found type %i, old value=%i new value=%i\n", + ntohl (arold->ats[c_old].type), ntohl (arold->ats[c_old].value), + ntohl (arnew->ats[c_new].value)); #endif - arold->ats[c_old].value = arnew->ats[c_new].value; - found = GNUNET_YES; - } - c_old++; + arold->ats[c_old].value = arnew->ats[c_new].value; + found = GNUNET_YES; } - /* Add new value */ - if (found == GNUNET_NO) - { + c_old++; + } + /* Add new value */ + if (found == GNUNET_NO) + { #if DEBUG_ATS - LOG (GNUNET_ERROR_TYPE_DEBUG, "Added new type %i new value=%i\n", - ntohl (arnew->ats[c_new].type), ntohl (arnew->ats[c_new].value)); - LOG (GNUNET_ERROR_TYPE_DEBUG, "Old array size: %u\n", arold->ats_count); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Added new type %i new value=%i\n", + ntohl (arnew->ats[c_new].type), ntohl (arnew->ats[c_new].value)); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Old array size: %u\n", arold->ats_count); #endif - GNUNET_array_grow (arold->ats, arold->ats_count, arold->ats_count + 1); - GNUNET_assert (arold->ats_count >= 2); - arold->ats[arold->ats_count - 2].type = arnew->ats[c_new].type; - arold->ats[arold->ats_count - 2].value = arnew->ats[c_new].value; - arold->ats[arold->ats_count - 1].type = htonl (0); - arold->ats[arold->ats_count - 1].value = htonl (0); + GNUNET_array_grow (arold->ats, arold->ats_count, arold->ats_count + 1); + GNUNET_assert (arold->ats_count >= 2); + arold->ats[arold->ats_count - 2].type = arnew->ats[c_new].type; + arold->ats[arold->ats_count - 2].value = arnew->ats[c_new].value; + arold->ats[arold->ats_count - 1].type = htonl (0); + arold->ats[arold->ats_count - 1].value = htonl (0); #if DEBUG_ATS - LOG (GNUNET_ERROR_TYPE_DEBUG, "New array size: %i\n", arold->ats_count); + LOG (GNUNET_ERROR_TYPE_DEBUG, "New array size: %i\n", arold->ats_count); #endif - } - c_new++; } - + c_new++; + } + update_bandwidth_assignment (usc->atc, arold); return GNUNET_NO; } @@ -538,9 +531,8 @@ create_allocation_record (const char *plugin_name, struct Session *session, MAX_WINDOW_TIME_S); GNUNET_assert (ats_count > 0); GNUNET_array_grow (ar->ats, ar->ats_count, ats_count); - memcpy (ar->ats, ats, - ats_count * sizeof (struct GNUNET_ATS_Information)); - ar->connected = GNUNET_SYSERR; /* aka: not known / no change */ + memcpy (ar->ats, ats, ats_count * sizeof (struct GNUNET_ATS_Information)); + ar->connected = GNUNET_SYSERR; /* aka: not known / no change */ return ar; } @@ -594,11 +586,9 @@ GNUNET_ATS_peer_connect (struct GNUNET_ATS_SchedulingHandle *atc, struct UpdateSessionContext usc; #if DEBUG_ATS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Connected to peer %s\n", - GNUNET_i2s (peer)); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Connected to peer %s\n", GNUNET_i2s (peer)); #endif - + (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &disconnect_peer, atc); ar = create_allocation_record (plugin_name, session, plugin_addr, @@ -632,8 +622,7 @@ GNUNET_ATS_peer_disconnect (struct GNUNET_ATS_SchedulingHandle *atc, const struct GNUNET_PeerIdentity *peer) { #if DEBUG_ATS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Disconnected from peer %s\n", + LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnected from peer %s\n", GNUNET_i2s (peer)); #endif (void) GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers, @@ -768,9 +757,8 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *atc, struct UpdateSessionContext usc; #if DEBUG_ATS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Updating address for peer `%s', plugin `%s'\n", GNUNET_i2s (peer), - plugin_name); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating address for peer `%s', plugin `%s'\n", + GNUNET_i2s (peer), plugin_name); #endif ar = create_allocation_record (plugin_name, session, plugin_addr, plugin_addr_len, ats, ats_count); @@ -783,7 +771,7 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *atc, return; } #if DEBUG_ATS - LOG (GNUNET_ERROR_TYPE_DEBUG, + LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding new address for peer `%s', plugin `%s'\n", GNUNET_i2s (peer), plugin_name); #endif diff --git a/src/ats/ats_api_peer_change_preference.c b/src/ats/ats_api_peer_change_preference.c index 322727e63..7290ebb7a 100644 --- a/src/ats/ats_api_peer_change_preference.c +++ b/src/ats/ats_api_peer_change_preference.c @@ -49,17 +49,16 @@ struct GNUNET_ATS_InformationRequestContext GNUNET_ATS_PeerConfigurationInfoCallback info; void *info_cls; - + struct GNUNET_PeerIdentity peer; - + GNUNET_SCHEDULER_TaskIdentifier task; }; static void -exec_pcp (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +exec_pcp (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_ATS_InformationRequestContext *irc = cls; int32_t want_reserv; @@ -69,16 +68,13 @@ exec_pcp (void *cls, rdelay = GNUNET_TIME_UNIT_ZERO; want_reserv = irc->amount; - ar = GNUNET_CONTAINER_multihashmap_get (irc->h->peers, &irc->peer.hashPubKey); + ar = GNUNET_CONTAINER_multihashmap_get (irc->h->peers, &irc->peer.hashPubKey); if (NULL == ar) { /* attempt to change preference on peer that is not connected */ /* FIXME: this can happen if the 'service' didn't yet tell us about - a new connection, fake it! */ - irc->info (irc->info_cls, - &irc->peer, - want_reserv, - rdelay); + * a new connection, fake it! */ + irc->info (irc->info_cls, &irc->peer, want_reserv, rdelay); GNUNET_free (irc); return; } @@ -89,21 +85,18 @@ exec_pcp (void *cls, else if (want_reserv > 0) { rdelay = - GNUNET_BANDWIDTH_tracker_get_delay (&ar->available_recv_window, - want_reserv); + GNUNET_BANDWIDTH_tracker_get_delay (&ar->available_recv_window, + want_reserv); if (rdelay.rel_value == 0) got_reserv = want_reserv; else - got_reserv = 0; /* all or nothing */ + got_reserv = 0; /* all or nothing */ } else got_reserv = 0; GNUNET_BANDWIDTH_tracker_consume (&ar->available_recv_window, got_reserv); - irc->info (irc->info_cls, - &irc->peer, - got_reserv, - rdelay); + irc->info (irc->info_cls, &irc->peer, got_reserv, rdelay); GNUNET_free (irc); } @@ -125,10 +118,10 @@ exec_pcp (void *cls, */ struct GNUNET_ATS_InformationRequestContext * GNUNET_ATS_peer_change_preference (struct GNUNET_ATS_SchedulingHandle *h, - const struct GNUNET_PeerIdentity *peer, - int32_t amount, uint64_t preference, - GNUNET_ATS_PeerConfigurationInfoCallback - info, void *info_cls) + const struct GNUNET_PeerIdentity *peer, + int32_t amount, uint64_t preference, + GNUNET_ATS_PeerConfigurationInfoCallback + info, void *info_cls) { struct GNUNET_ATS_InformationRequestContext *irc; @@ -157,8 +150,8 @@ GNUNET_ATS_peer_change_preference (struct GNUNET_ATS_SchedulingHandle *h, */ void GNUNET_ATS_peer_change_preference_cancel (struct - GNUNET_ATS_InformationRequestContext - *irc) + GNUNET_ATS_InformationRequestContext + *irc) { GNUNET_SCHEDULER_cancel (irc->task); GNUNET_free (irc); @@ -219,10 +212,10 @@ change_preference_send_continuation (void *cls, int success) */ struct GNUNET_ATS_InformationRequestContext * GNUNET_ATS_peer_change_preference (struct GNUNET_ATS_SchedulingHandle *h, - const struct GNUNET_PeerIdentity *peer, - int32_t amount, uint64_t preference, - GNUNET_ATS_PeerConfigurationInfoCallback - info, void *info_cls) + const struct GNUNET_PeerIdentity *peer, + int32_t amount, uint64_t preference, + GNUNET_ATS_PeerConfigurationInfoCallback + info, void *info_cls) { struct GNUNET_ATS_InformationRequestContext *irc; struct PeerRecord *pr; @@ -287,8 +280,8 @@ GNUNET_ATS_peer_change_preference (struct GNUNET_ATS_SchedulingHandle *h, */ void GNUNET_ATS_peer_change_preference_cancel (struct - GNUNET_ATS_InformationRequestContext - *irc) + GNUNET_ATS_InformationRequestContext + *irc) { struct GNUNET_ATS_SchedulingHandle *h = irc->h; struct PeerRecord *pr = irc->pr; diff --git a/src/ats/ats_api_performance.c b/src/ats/ats_api_performance.c index ba124fe21..ca489e4a6 100644 --- a/src/ats/ats_api_performance.c +++ b/src/ats/ats_api_performance.c @@ -37,12 +37,12 @@ struct PendingMessage /** * Kept in a DLL. - */ + */ struct PendingMessage *next; /** * Kept in a DLL. - */ + */ struct PendingMessage *prev; /** @@ -52,7 +52,7 @@ struct PendingMessage /** * Is this the 'ATS_START' message? - */ + */ int is_init; }; @@ -65,19 +65,19 @@ struct GNUNET_ATS_ReservationContext /** * Kept in a DLL. - */ + */ struct GNUNET_ATS_ReservationContext *next; /** * Kept in a DLL. - */ + */ struct GNUNET_ATS_ReservationContext *prev; /** * Target peer. */ struct GNUNET_PeerIdentity peer; - + /** * Desired reservation */ @@ -110,7 +110,7 @@ struct GNUNET_ATS_ReservationContext */ struct GNUNET_ATS_PerformanceHandle { - + /** * Our configuration. */ @@ -120,7 +120,7 @@ struct GNUNET_ATS_PerformanceHandle * Callback to invoke on performance changes. */ GNUNET_ATS_PeerInformationCallback infocb; - + /** * Closure for 'infocb'. */ @@ -158,9 +158,9 @@ struct GNUNET_ATS_PerformanceHandle /** * Task to trigger reconnect. - */ + */ GNUNET_SCHEDULER_TaskIdentifier task; - + }; @@ -180,8 +180,7 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph); * @param tc scheduler context */ static void -reconnect_task (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_ATS_PerformanceHandle *ph = cls; @@ -209,9 +208,7 @@ do_transmit (struct GNUNET_ATS_PerformanceHandle *ph); * @return number of bytes copied into buf */ static size_t -transmit_message_to_ats (void *cls, - size_t size, - void *buf) +transmit_message_to_ats (void *cls, size_t size, void *buf) { struct GNUNET_ATS_PerformanceHandle *ph = cls; struct PendingMessage *p; @@ -221,15 +218,12 @@ transmit_message_to_ats (void *cls, ph->th = NULL; ret = 0; cbuf = buf; - while ( (NULL != (p = ph->pending_head)) && - (p->size <= size) ) + while ((NULL != (p = ph->pending_head)) && (p->size <= size)) { - memcpy (&cbuf[ret], &p[1], p->size); + memcpy (&cbuf[ret], &p[1], p->size); ret += p->size; size -= p->size; - GNUNET_CONTAINER_DLL_remove (ph->pending_head, - ph->pending_tail, - p); + GNUNET_CONTAINER_DLL_remove (ph->pending_head, ph->pending_tail, p); GNUNET_free (p); } do_transmit (ph); @@ -253,12 +247,12 @@ do_transmit (struct GNUNET_ATS_PerformanceHandle *ph) if (NULL == (p = ph->pending_head)) return; if (NULL == ph->client) - return; /* currently reconnecting */ - ph->th = GNUNET_CLIENT_notify_transmit_ready (ph->client, - p->size, - GNUNET_TIME_UNIT_FOREVER_REL, - GNUNET_YES, - &transmit_message_to_ats, ph); + return; /* currently reconnecting */ + ph->th = + GNUNET_CLIENT_notify_transmit_ready (ph->client, p->size, + GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_YES, &transmit_message_to_ats, + ph); } @@ -271,7 +265,7 @@ do_transmit (struct GNUNET_ATS_PerformanceHandle *ph) */ static int process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, - const struct GNUNET_MessageHeader *msg) + const struct GNUNET_MessageHeader *msg) { const struct PeerInformationMessage *pi; const struct GNUNET_ATS_Information *atsi; @@ -285,37 +279,31 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, { GNUNET_break (0); return GNUNET_SYSERR; - } + } if (ntohs (msg->size) < sizeof (struct PeerInformationMessage)) { GNUNET_break (0); return GNUNET_SYSERR; } - pi = (const struct PeerInformationMessage*) msg; + pi = (const struct PeerInformationMessage *) msg; ats_count = ntohl (pi->ats_count); address_length = ntohs (pi->address_length); plugin_name_length = ntohs (pi->plugin_name_length); - atsi = (const struct GNUNET_ATS_Information*) &pi[1]; - address = (const char*) &atsi[ats_count]; + atsi = (const struct GNUNET_ATS_Information *) &pi[1]; + address = (const char *) &atsi[ats_count]; plugin_name = &address[address_length]; - if ( (address_length + - plugin_name_length + - ats_count * sizeof (struct GNUNET_ATS_Information) + - sizeof (struct PeerInformationMessage) != ntohs (msg->size)) || - (ats_count > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) || - (plugin_name[plugin_name_length - 1] != '\0') ) + if ((address_length + plugin_name_length + + ats_count * sizeof (struct GNUNET_ATS_Information) + + sizeof (struct PeerInformationMessage) != ntohs (msg->size)) || + (ats_count > + GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) + || (plugin_name[plugin_name_length - 1] != '\0')) { GNUNET_break (0); return GNUNET_SYSERR; } - ph->infocb (ph->infocb_cls, - &pi->peer, - plugin_name, - address, address_length, - pi->bandwidth_out, - pi->bandwidth_in, - atsi, - ats_count); + ph->infocb (ph->infocb_cls, &pi->peer, plugin_name, address, address_length, + pi->bandwidth_out, pi->bandwidth_in, atsi, ats_count); return GNUNET_OK; } @@ -329,7 +317,7 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, */ static int process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph, - const struct GNUNET_MessageHeader *msg) + const struct GNUNET_MessageHeader *msg) { const struct ReservationResultMessage *rr; struct GNUNET_ATS_ReservationContext *rc; @@ -340,28 +328,21 @@ process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph, GNUNET_break (0); return GNUNET_SYSERR; } - rr = (const struct ReservationResultMessage*) msg; + rr = (const struct ReservationResultMessage *) msg; amount = ntohl (rr->amount); rc = ph->reservation_head; - if (0 != memcmp (&rr->peer, - &rc->peer, - sizeof (struct GNUNET_PeerIdentity))) + if (0 != memcmp (&rr->peer, &rc->peer, sizeof (struct GNUNET_PeerIdentity))) { GNUNET_break (0); return GNUNET_SYSERR; } - GNUNET_CONTAINER_DLL_remove (ph->reservation_head, - ph->reservation_tail, - rc); - if ( (amount == 0) || - (rc->rcb != NULL) ) + GNUNET_CONTAINER_DLL_remove (ph->reservation_head, ph->reservation_tail, rc); + if ((amount == 0) || (rc->rcb != NULL)) { /* tell client if not cancelled */ if (rc->rcb != NULL) - rc->rcb (rc->rcb_cls, - &rr->peer, - amount, - GNUNET_TIME_relative_ntoh (rr->res_delay)); + rc->rcb (rc->rcb_cls, &rr->peer, amount, + GNUNET_TIME_relative_ntoh (rr->res_delay)); GNUNET_free (rc); return GNUNET_OK; } @@ -369,7 +350,7 @@ process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph, if (GNUNET_YES != rc->undo) { GNUNET_free (rc); - return GNUNET_OK; /* do not try to undo failed undos or negative amounts */ + return GNUNET_OK; /* do not try to undo failed undos or negative amounts */ } GNUNET_free (rc); (void) GNUNET_ATS_reserve_bandwidth (ph, &rr->peer, -amount, NULL, NULL); @@ -385,12 +366,11 @@ process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph, * @param msg message received, NULL on timeout or fatal error */ static void -process_ats_message (void *cls, - const struct GNUNET_MessageHeader *msg) +process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg) { struct GNUNET_ATS_PerformanceHandle *ph = cls; - if (NULL == msg) + if (NULL == msg) goto reconnect; switch (ntohs (msg->type)) { @@ -400,22 +380,22 @@ process_ats_message (void *cls, break; case GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT: if (GNUNET_OK != process_rr_message (ph, msg)) - goto reconnect; + goto reconnect; break; default: GNUNET_break (0); goto reconnect; return; } - GNUNET_CLIENT_receive (ph->client, - &process_ats_message, ph, - GNUNET_TIME_UNIT_FOREVER_REL); + GNUNET_CLIENT_receive (ph->client, &process_ats_message, ph, + GNUNET_TIME_UNIT_FOREVER_REL); return; - reconnect: +reconnect: GNUNET_CLIENT_disconnect (ph->client, GNUNET_NO); ph->client = NULL; - ph->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, - &reconnect_task, ph); + ph->task = + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect_task, + ph); } @@ -433,25 +413,22 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph) GNUNET_assert (NULL == ph->client); ph->client = GNUNET_CLIENT_connect ("ats", ph->cfg); GNUNET_assert (NULL != ph->client); - GNUNET_CLIENT_receive (ph->client, - &process_ats_message, ph, - GNUNET_TIME_UNIT_FOREVER_REL); - if ( (NULL == (p = ph->pending_head)) || - (GNUNET_YES != p->is_init) ) + GNUNET_CLIENT_receive (ph->client, &process_ats_message, ph, + GNUNET_TIME_UNIT_FOREVER_REL); + if ((NULL == (p = ph->pending_head)) || (GNUNET_YES != p->is_init)) { p = GNUNET_malloc (sizeof (struct PendingMessage) + - sizeof (struct ClientStartMessage)); + sizeof (struct ClientStartMessage)); p->size = sizeof (struct ClientStartMessage); p->is_init = GNUNET_YES; init = (struct ClientStartMessage *) &p[1]; init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START); init->header.size = htons (sizeof (struct ClientStartMessage)); - init->start_flag = htonl ((ph->infocb == NULL) - ? START_FLAG_PERFORMANCE_NO_PIC - : START_FLAG_PERFORMANCE_WITH_PIC); - GNUNET_CONTAINER_DLL_insert (ph->pending_head, - ph->pending_tail, - p); + init->start_flag = + htonl ((ph->infocb == + NULL) ? START_FLAG_PERFORMANCE_NO_PIC : + START_FLAG_PERFORMANCE_WITH_PIC); + GNUNET_CONTAINER_DLL_insert (ph->pending_head, ph->pending_tail, p); } do_transmit (ph); } @@ -468,8 +445,8 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph) */ struct GNUNET_ATS_PerformanceHandle * GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg, - GNUNET_ATS_PeerInformationCallback infocb, - void *infocb_cls) + GNUNET_ATS_PeerInformationCallback infocb, + void *infocb_cls) { struct GNUNET_ATS_PerformanceHandle *ph; @@ -492,22 +469,19 @@ GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph) { struct PendingMessage *p; struct GNUNET_ATS_ReservationContext *rc; - + while (NULL != (p = ph->pending_head)) { - GNUNET_CONTAINER_DLL_remove (ph->pending_head, - ph->pending_tail, - p); + GNUNET_CONTAINER_DLL_remove (ph->pending_head, ph->pending_tail, p); GNUNET_free (p); } while (NULL != (rc = ph->reservation_head)) { - GNUNET_CONTAINER_DLL_remove (ph->reservation_head, - ph->reservation_tail, - rc); + GNUNET_CONTAINER_DLL_remove (ph->reservation_head, ph->reservation_tail, + rc); GNUNET_break (NULL == rc->rcb); GNUNET_free (rc); - } + } if (GNUNET_SCHEDULER_NO_TASK != ph->task) { GNUNET_SCHEDULER_cancel (ph->task); @@ -538,10 +512,9 @@ GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph) */ struct GNUNET_ATS_ReservationContext * GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph, - const struct GNUNET_PeerIdentity *peer, - int32_t amount, - GNUNET_ATS_ReservationCallback rcb, - void *rcb_cls) + const struct GNUNET_PeerIdentity *peer, + int32_t amount, + GNUNET_ATS_ReservationCallback rcb, void *rcb_cls) { struct GNUNET_ATS_ReservationContext *rc; struct PendingMessage *p; @@ -552,24 +525,21 @@ GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph, rc->peer = *peer; rc->rcb = rcb; rc->rcb_cls = rcb_cls; - if ( (rcb != NULL) && (amount > 0) ) + if ((rcb != NULL) && (amount > 0)) rc->undo = GNUNET_YES; - GNUNET_CONTAINER_DLL_insert_tail (ph->reservation_head, - ph->reservation_tail, - rc); - - p = GNUNET_malloc (sizeof (struct PendingMessage) + - sizeof (struct ReservationRequestMessage)); + GNUNET_CONTAINER_DLL_insert_tail (ph->reservation_head, ph->reservation_tail, + rc); + + p = GNUNET_malloc (sizeof (struct PendingMessage) + + sizeof (struct ReservationRequestMessage)); p->size = sizeof (struct ReservationRequestMessage); p->is_init = GNUNET_NO; - m = (struct ReservationRequestMessage*) &p[1]; + m = (struct ReservationRequestMessage *) &p[1]; m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST); m->header.size = htons (sizeof (struct ReservationRequestMessage)); m->amount = htonl (amount); m->peer = *peer; - GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, - ph->pending_tail, - p); + GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, ph->pending_tail, p); do_transmit (ph); return rc; } @@ -581,8 +551,7 @@ GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph, * @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call */ void -GNUNET_ATS_reserve_bandwidth_cancel (struct - GNUNET_ATS_ReservationContext *rc) +GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc) { rc->rcb = NULL; } @@ -591,15 +560,14 @@ GNUNET_ATS_reserve_bandwidth_cancel (struct /** * Change preferences for the given peer. Preference changes are forgotten if peers * disconnect. - * + * * @param ph performance handle * @param peer identifies the peer * @param ... 0-terminated specification of the desired changes */ void GNUNET_ATS_change_preference (struct GNUNET_ATS_PerformanceHandle *ph, - const struct GNUNET_PeerIdentity *peer, - ...) + const struct GNUNET_PeerIdentity *peer, ...) { struct PendingMessage *p; struct ChangePreferenceMessage *m; @@ -611,60 +579,63 @@ GNUNET_ATS_change_preference (struct GNUNET_ATS_PerformanceHandle *ph, count = 0; va_start (ap, peer); - while (GNUNET_ATS_PREFERENCE_END != (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind))) + while (GNUNET_ATS_PREFERENCE_END != + (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind))) { switch (kind) { case GNUNET_ATS_PREFERENCE_BANDWIDTH: count++; (void) va_arg (ap, double); + break; case GNUNET_ATS_PREFERENCE_LATENCY: count++; (void) va_arg (ap, double); + break; default: - GNUNET_assert (0); + GNUNET_assert (0); } } va_end (ap); - msize = count * sizeof (struct PreferenceInformation) + - sizeof (struct ChangePreferenceMessage); - p = GNUNET_malloc (sizeof (struct PendingMessage) + - msize); + msize = + count * sizeof (struct PreferenceInformation) + + sizeof (struct ChangePreferenceMessage); + p = GNUNET_malloc (sizeof (struct PendingMessage) + msize); p->size = msize; p->is_init = GNUNET_NO; - m = (struct ChangePreferenceMessage*) &p[1]; + m = (struct ChangePreferenceMessage *) &p[1]; m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE); m->header.size = htons (msize); m->num_preferences = htonl (count); m->peer = *peer; - pi = (struct PreferenceInformation*) &m[1]; + pi = (struct PreferenceInformation *) &m[1]; count = 0; va_start (ap, peer); - while (GNUNET_ATS_PREFERENCE_END != (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind))) + while (GNUNET_ATS_PREFERENCE_END != + (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind))) { pi[count].preference_kind = htonl (kind); switch (kind) { case GNUNET_ATS_PREFERENCE_BANDWIDTH: pi[count].preference_value = (float) va_arg (ap, double); + count++; break; case GNUNET_ATS_PREFERENCE_LATENCY: pi[count].preference_value = (float) va_arg (ap, double); + count++; break; default: - GNUNET_assert (0); + GNUNET_assert (0); } } va_end (ap); - GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, - ph->pending_tail, - p); + GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, ph->pending_tail, p); do_transmit (ph); } /* end of ats_api_performance.c */ - diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c index b342d9657..2eeb99dad 100644 --- a/src/ats/ats_api_scheduling.c +++ b/src/ats/ats_api_scheduling.c @@ -37,12 +37,12 @@ struct PendingMessage /** * Kept in a DLL. - */ + */ struct PendingMessage *next; /** * Kept in a DLL. - */ + */ struct PendingMessage *prev; /** @@ -52,7 +52,7 @@ struct PendingMessage /** * Is this the 'ATS_START' message? - */ + */ int is_init; }; @@ -84,7 +84,7 @@ struct SessionRecord */ struct GNUNET_ATS_SchedulingHandle { - + /** * Our configuration. */ @@ -94,7 +94,7 @@ struct GNUNET_ATS_SchedulingHandle * Callback to invoke on suggestions. */ GNUNET_ATS_AddressSuggestionCallback suggest_cb; - + /** * Closure for 'suggest_cb'. */ @@ -130,9 +130,9 @@ struct GNUNET_ATS_SchedulingHandle /** * Task to trigger reconnect. - */ + */ GNUNET_SCHEDULER_TaskIdentifier task; - + /** * Size of the session array. */ @@ -161,8 +161,7 @@ reconnect (struct GNUNET_ATS_SchedulingHandle *sh); * @param tc scheduler context */ static void -reconnect_task (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_ATS_SchedulingHandle *sh = cls; @@ -182,8 +181,9 @@ force_reconnect (struct GNUNET_ATS_SchedulingHandle *sh) sh->reconnect = GNUNET_NO; GNUNET_CLIENT_disconnect (sh->client, GNUNET_NO); sh->client = NULL; - sh->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, - &reconnect_task, sh); + sh->task = + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect_task, + sh); } @@ -205,8 +205,7 @@ do_transmit (struct GNUNET_ATS_SchedulingHandle *sh); * @param msg message received, NULL on timeout or fatal error */ static void -process_ats_message (void *cls, - const struct GNUNET_MessageHeader *msg); +process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg); /** @@ -218,9 +217,7 @@ process_ats_message (void *cls, * @return number of bytes copied into buf */ static size_t -transmit_message_to_ats (void *cls, - size_t size, - void *buf) +transmit_message_to_ats (void *cls, size_t size, void *buf) { struct GNUNET_ATS_SchedulingHandle *sh = cls; struct PendingMessage *p; @@ -228,26 +225,22 @@ transmit_message_to_ats (void *cls, char *cbuf; sh->th = NULL; - if ( (size == 0) || (buf == NULL)) + if ((size == 0) || (buf == NULL)) { force_reconnect (sh); return 0; } ret = 0; cbuf = buf; - while ( (NULL != (p = sh->pending_head)) && - (p->size <= size) ) + while ((NULL != (p = sh->pending_head)) && (p->size <= size)) { - memcpy (&cbuf[ret], &p[1], p->size); + memcpy (&cbuf[ret], &p[1], p->size); ret += p->size; size -= p->size; - GNUNET_CONTAINER_DLL_remove (sh->pending_head, - sh->pending_tail, - p); + GNUNET_CONTAINER_DLL_remove (sh->pending_head, sh->pending_tail, p); if (GNUNET_YES == p->is_init) - GNUNET_CLIENT_receive (sh->client, - &process_ats_message, sh, - GNUNET_TIME_UNIT_FOREVER_REL); + GNUNET_CLIENT_receive (sh->client, &process_ats_message, sh, + GNUNET_TIME_UNIT_FOREVER_REL); GNUNET_free (p); } do_transmit (sh); @@ -271,12 +264,12 @@ do_transmit (struct GNUNET_ATS_SchedulingHandle *sh) if (NULL == (p = sh->pending_head)) return; if (NULL == sh->client) - return; /* currently reconnecting */ - sh->th = GNUNET_CLIENT_notify_transmit_ready (sh->client, - p->size, - GNUNET_TIME_UNIT_FOREVER_REL, - GNUNET_NO, - &transmit_message_to_ats, sh); + return; /* currently reconnecting */ + sh->th = + GNUNET_CLIENT_notify_transmit_ready (sh->client, p->size, + GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_NO, &transmit_message_to_ats, + sh); } @@ -288,10 +281,9 @@ do_transmit (struct GNUNET_ATS_SchedulingHandle *sh) * @param peer peer the session belongs to * @return the session object (or NULL) */ -static struct Session* -find_session (struct GNUNET_ATS_SchedulingHandle *sh, - uint32_t session_id, - const struct GNUNET_PeerIdentity *peer) +static struct Session * +find_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id, + const struct GNUNET_PeerIdentity *peer) { if (session_id >= sh->session_array_size) { @@ -300,9 +292,9 @@ find_session (struct GNUNET_ATS_SchedulingHandle *sh, } if (session_id == 0) return NULL; - if (0 != memcmp (peer, - &sh->session_array[session_id].peer, - sizeof (struct GNUNET_PeerIdentity))) + if (0 != + memcmp (peer, &sh->session_array[session_id].peer, + sizeof (struct GNUNET_PeerIdentity))) { GNUNET_break (0); sh->reconnect = GNUNET_YES; @@ -321,36 +313,33 @@ find_session (struct GNUNET_ATS_SchedulingHandle *sh, * @param peer peer the session belongs to * @return the session id */ -static uint32_t -get_session_id (struct GNUNET_ATS_SchedulingHandle *sh, - struct Session *session, - const struct GNUNET_PeerIdentity *peer) +static uint32_t +get_session_id (struct GNUNET_ATS_SchedulingHandle *sh, struct Session *session, + const struct GNUNET_PeerIdentity *peer) { unsigned int i; unsigned int f; - + if (NULL == session) return 0; f = 0; - for (i=1;isession_array_size;i++) + for (i = 1; i < sh->session_array_size; i++) { if (session == sh->session_array[i].session) { - GNUNET_assert (0 == memcmp (peer, - &sh->session_array[i].peer, - sizeof (struct GNUNET_PeerIdentity))); + GNUNET_assert (0 == + memcmp (peer, &sh->session_array[i].peer, + sizeof (struct GNUNET_PeerIdentity))); return i; } - if ( (f == 0) && - (sh->session_array[i].slot_used == GNUNET_NO) ) + if ((f == 0) && (sh->session_array[i].slot_used == GNUNET_NO)) f = i; } if (f == 0) - { + { f = sh->session_array_size; - GNUNET_array_grow (sh->session_array, - sh->session_array_size, - sh->session_array_size * 2); + GNUNET_array_grow (sh->session_array, sh->session_array_size, + sh->session_array_size * 2); } GNUNET_assert (f > 0); sh->session_array[f].session = session; @@ -369,17 +358,16 @@ get_session_id (struct GNUNET_ATS_SchedulingHandle *sh, * @param peer peer the session belongs to */ static void -remove_session (struct GNUNET_ATS_SchedulingHandle *sh, - uint32_t session_id, - const struct GNUNET_PeerIdentity *peer) +remove_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id, + const struct GNUNET_PeerIdentity *peer) { if (0 == session_id) return; GNUNET_assert (session_id < sh->session_array_size); GNUNET_assert (GNUNET_YES == sh->session_array[session_id].slot_used); - GNUNET_assert (0 == memcmp (peer, - &sh->session_array[session_id].peer, - sizeof (struct GNUNET_PeerIdentity))); + GNUNET_assert (0 == + memcmp (peer, &sh->session_array[session_id].peer, + sizeof (struct GNUNET_PeerIdentity))); sh->session_array[session_id].session = NULL; } @@ -393,9 +381,8 @@ remove_session (struct GNUNET_ATS_SchedulingHandle *sh, * @param peer peer the session belongs to */ static void -release_session (struct GNUNET_ATS_SchedulingHandle *sh, - uint32_t session_id, - const struct GNUNET_PeerIdentity *peer) +release_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id, + const struct GNUNET_PeerIdentity *peer) { if (session_id >= sh->session_array_size) { @@ -403,28 +390,25 @@ release_session (struct GNUNET_ATS_SchedulingHandle *sh, sh->reconnect = GNUNET_YES; return; } - if (0 != memcmp (peer, - &sh->session_array[session_id].peer, - sizeof (struct GNUNET_PeerIdentity))) + if (0 != + memcmp (peer, &sh->session_array[session_id].peer, + sizeof (struct GNUNET_PeerIdentity))) { GNUNET_break (0); sh->reconnect = GNUNET_YES; return; } sh->session_array[session_id].slot_used = GNUNET_NO; - memset (&sh->session_array[session_id].peer, - 0, - sizeof (struct GNUNET_PeerIdentity)); + memset (&sh->session_array[session_id].peer, 0, + sizeof (struct GNUNET_PeerIdentity)); } static void process_release_message (struct GNUNET_ATS_SchedulingHandle *sh, - const struct SessionReleaseMessage *srm) + const struct SessionReleaseMessage *srm) { - release_session (sh, - ntohl (srm->session_id), - &srm->peer); + release_session (sh, ntohl (srm->session_id), &srm->peer); } @@ -436,8 +420,7 @@ process_release_message (struct GNUNET_ATS_SchedulingHandle *sh, * @param msg message received, NULL on timeout or fatal error */ static void -process_ats_message (void *cls, - const struct GNUNET_MessageHeader *msg) +process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg) { struct GNUNET_ATS_SchedulingHandle *sh = cls; const struct AddressSuggestionMessage *m; @@ -448,60 +431,52 @@ process_ats_message (void *cls, uint16_t plugin_name_length; uint32_t ats_count; - if (NULL == msg) + if (NULL == msg) { force_reconnect (sh); return; } - if ( (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE) && - (ntohs (msg->size) == sizeof (struct SessionReleaseMessage)) ) + if ((ntohs (msg->type) == GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE) && + (ntohs (msg->size) == sizeof (struct SessionReleaseMessage))) { - process_release_message (sh, - (const struct SessionReleaseMessage*) msg); - GNUNET_CLIENT_receive (sh->client, - &process_ats_message, sh, - GNUNET_TIME_UNIT_FOREVER_REL); + process_release_message (sh, (const struct SessionReleaseMessage *) msg); + GNUNET_CLIENT_receive (sh->client, &process_ats_message, sh, + GNUNET_TIME_UNIT_FOREVER_REL); if (GNUNET_YES == sh->reconnect) force_reconnect (sh); return; } - if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION) || - (ntohs (msg->size) <= sizeof (struct AddressSuggestionMessage)) ) + if ((ntohs (msg->type) != GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION) || + (ntohs (msg->size) <= sizeof (struct AddressSuggestionMessage))) { GNUNET_break (0); force_reconnect (sh); return; } - m = (const struct AddressSuggestionMessage*) msg; + m = (const struct AddressSuggestionMessage *) msg; ats_count = ntohl (m->ats_count); address_length = ntohs (m->address_length); - atsi = (const struct GNUNET_ATS_Information*) &m[1]; - address = (const char*) &atsi[ats_count]; + atsi = (const struct GNUNET_ATS_Information *) &m[1]; + address = (const char *) &atsi[ats_count]; plugin_name = &address[address_length]; plugin_name_length = ntohs (m->plugin_name_length); - if ( (address_length + - plugin_name_length + - ats_count * sizeof (struct GNUNET_ATS_Information) + - sizeof (struct AddressSuggestionMessage) != ntohs (msg->size)) || - (ats_count > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) || - (plugin_name[plugin_name_length - 1] != '\0') ) + if ((address_length + plugin_name_length + + ats_count * sizeof (struct GNUNET_ATS_Information) + + sizeof (struct AddressSuggestionMessage) != ntohs (msg->size)) || + (ats_count > + GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) + || (plugin_name[plugin_name_length - 1] != '\0')) { GNUNET_break (0); force_reconnect (sh); return; } - sh->suggest_cb (sh->suggest_cb_cls, - &m->peer, - plugin_name, - address, address_length, - find_session (sh, ntohl (m->session_id), &m->peer), - m->bandwidth_out, - m->bandwidth_in, - atsi, - ats_count); - GNUNET_CLIENT_receive (sh->client, - &process_ats_message, sh, - GNUNET_TIME_UNIT_FOREVER_REL); + sh->suggest_cb (sh->suggest_cb_cls, &m->peer, plugin_name, address, + address_length, find_session (sh, ntohl (m->session_id), + &m->peer), m->bandwidth_out, + m->bandwidth_in, atsi, ats_count); + GNUNET_CLIENT_receive (sh->client, &process_ats_message, sh, + GNUNET_TIME_UNIT_FOREVER_REL); if (GNUNET_YES == sh->reconnect) force_reconnect (sh); } @@ -521,20 +496,17 @@ reconnect (struct GNUNET_ATS_SchedulingHandle *sh) GNUNET_assert (NULL == sh->client); sh->client = GNUNET_CLIENT_connect ("ats", sh->cfg); GNUNET_assert (NULL != sh->client); - if ( (NULL == (p = sh->pending_head)) || - (GNUNET_YES != p->is_init) ) + if ((NULL == (p = sh->pending_head)) || (GNUNET_YES != p->is_init)) { p = GNUNET_malloc (sizeof (struct PendingMessage) + - sizeof (struct ClientStartMessage)); + sizeof (struct ClientStartMessage)); p->size = sizeof (struct ClientStartMessage); p->is_init = GNUNET_YES; init = (struct ClientStartMessage *) &p[1]; init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START); init->header.size = htons (sizeof (struct ClientStartMessage)); init->start_flag = htonl (START_FLAG_SCHEDULING); - GNUNET_CONTAINER_DLL_insert (sh->pending_head, - sh->pending_tail, - p); + GNUNET_CONTAINER_DLL_insert (sh->pending_head, sh->pending_tail, p); } do_transmit (sh); } @@ -550,8 +522,8 @@ reconnect (struct GNUNET_ATS_SchedulingHandle *sh) */ struct GNUNET_ATS_SchedulingHandle * GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg, - GNUNET_ATS_AddressSuggestionCallback suggest_cb, - void *suggest_cb_cls) + GNUNET_ATS_AddressSuggestionCallback suggest_cb, + void *suggest_cb_cls) { struct GNUNET_ATS_SchedulingHandle *sh; @@ -559,9 +531,7 @@ GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg, sh->cfg = cfg; sh->suggest_cb = suggest_cb; sh->suggest_cb_cls = suggest_cb_cls; - GNUNET_array_grow (sh->session_array, - sh->session_array_size, - 4); + GNUNET_array_grow (sh->session_array, sh->session_array_size, 4); reconnect (sh); return sh; } @@ -579,9 +549,7 @@ GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh) while (NULL != (p = sh->pending_head)) { - GNUNET_CONTAINER_DLL_remove (sh->pending_head, - sh->pending_tail, - p); + GNUNET_CONTAINER_DLL_remove (sh->pending_head, sh->pending_tail, p); GNUNET_free (p); } if (NULL != sh->client) @@ -594,9 +562,7 @@ GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh) GNUNET_SCHEDULER_cancel (sh->task); sh->task = GNUNET_SCHEDULER_NO_TASK; } - GNUNET_array_grow (sh->session_array, - sh->session_array_size, - 0); + GNUNET_array_grow (sh->session_array, sh->session_array_size, 0); GNUNET_free (sh); } @@ -616,17 +582,15 @@ GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh, struct RequestAddressMessage *m; p = GNUNET_malloc (sizeof (struct PendingMessage) + - sizeof (struct RequestAddressMessage)); + sizeof (struct RequestAddressMessage)); p->size = sizeof (struct RequestAddressMessage); p->is_init = GNUNET_NO; - m = (struct RequestAddressMessage*) &p[1]; + m = (struct RequestAddressMessage *) &p[1]; m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS); m->header.size = htons (sizeof (struct RequestAddressMessage)); m->reserved = htonl (0); m->peer = *peer; - GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, - sh->pending_tail, - p); + GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p); do_transmit (sh); } @@ -651,9 +615,8 @@ GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh, void GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh, const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, - const void *plugin_addr, size_t plugin_addr_len, - struct Session *session, + const char *plugin_name, const void *plugin_addr, + size_t plugin_addr_len, struct Session *session, const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { @@ -664,21 +627,23 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh, size_t namelen; size_t msize; - namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1; - msize = sizeof (struct AddressUpdateMessage) + plugin_addr_len + - ats_count * sizeof (struct GNUNET_ATS_Information) + namelen; - if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || - (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || - (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || - (ats_count >= GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) ) + namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1; + msize = + sizeof (struct AddressUpdateMessage) + plugin_addr_len + + ats_count * sizeof (struct GNUNET_ATS_Information) + namelen; + if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || + (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || + (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || + (ats_count >= + GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information))) { GNUNET_break (0); return; } - p = GNUNET_malloc (sizeof (struct PendingMessage) + msize); + p = GNUNET_malloc (sizeof (struct PendingMessage) + msize); p->size = msize; p->is_init = GNUNET_NO; - m = (struct AddressUpdateMessage*) &p[1]; + m = (struct AddressUpdateMessage *) &p[1]; m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE); m->header.size = htons (msize); m->ats_count = htonl (ats_count); @@ -686,14 +651,12 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh, m->address_length = htons (plugin_addr_len); m->plugin_name_length = htons (namelen); m->session_id = htonl (get_session_id (sh, session, peer)); - am = (struct GNUNET_ATS_Information*) &m[1]; + am = (struct GNUNET_ATS_Information *) &m[1]; memcpy (am, ats, ats_count * sizeof (struct GNUNET_ATS_Information)); pm = (char *) &am[ats_count]; memcpy (pm, plugin_addr, plugin_addr_len); memcpy (&pm[plugin_addr_len], plugin_name, namelen); - GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, - sh->pending_tail, - p); + GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p); do_transmit (sh); } @@ -712,12 +675,10 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh, */ void GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh, - const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, - const void *plugin_addr, - size_t plugin_addr_len, - struct Session *session, - int in_use) + const struct GNUNET_PeerIdentity *peer, + const char *plugin_name, const void *plugin_addr, + size_t plugin_addr_len, struct Session *session, + int in_use) { struct PendingMessage *p; struct AddressUseMessage *m; @@ -727,30 +688,28 @@ GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh, namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1; msize = sizeof (struct AddressUseMessage) + plugin_addr_len + namelen; - if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || - (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || - (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ) + if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || + (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || + (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE)) { GNUNET_break (0); return; } - p = GNUNET_malloc (sizeof (struct PendingMessage) + msize); + p = GNUNET_malloc (sizeof (struct PendingMessage) + msize); p->size = msize; p->is_init = GNUNET_NO; - m = (struct AddressUseMessage*) &p[1]; + m = (struct AddressUseMessage *) &p[1]; m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE); m->header.size = htons (msize); m->peer = *peer; - m->in_use = htons(in_use); + m->in_use = htons (in_use); m->address_length = htons (plugin_addr_len); m->plugin_name_length = htons (namelen); m->session_id = htonl (get_session_id (sh, session, peer)); pm = (char *) &m[1]; memcpy (pm, plugin_addr, plugin_addr_len); memcpy (&pm[plugin_addr_len], plugin_name, namelen); - GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, - sh->pending_tail, - p); + GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p); do_transmit (sh); } @@ -768,10 +727,8 @@ GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh, void GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh, const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, - const void *plugin_addr, - size_t plugin_addr_len, - struct Session *session) + const char *plugin_name, const void *plugin_addr, + size_t plugin_addr_len, struct Session *session) { struct PendingMessage *p; struct AddressDestroyedMessage *m; @@ -780,20 +737,19 @@ GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh, size_t msize; uint32_t session_id; - namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1; - msize = sizeof (struct AddressDestroyedMessage) + plugin_addr_len + - namelen; - if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || - (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || - (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ) + namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1; + msize = sizeof (struct AddressDestroyedMessage) + plugin_addr_len + namelen; + if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || + (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || + (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE)) { GNUNET_break (0); return; } - p = GNUNET_malloc (sizeof (struct PendingMessage) + msize); + p = GNUNET_malloc (sizeof (struct PendingMessage) + msize); p->size = msize; p->is_init = GNUNET_NO; - m = (struct AddressDestroyedMessage*) &p[1]; + m = (struct AddressDestroyedMessage *) &p[1]; m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED); m->header.size = htons (msize); m->reserved = htonl (0); @@ -804,9 +760,7 @@ GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh, pm = (char *) &m[1]; memcpy (pm, plugin_addr, plugin_addr_len); memcpy (&pm[plugin_addr_len], plugin_name, namelen); - GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, - sh->pending_tail, - p); + GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p); do_transmit (sh); remove_session (sh, session_id, peer); } diff --git a/src/ats/gnunet-service-ats.c b/src/ats/gnunet-service-ats.c index 563550ece..ec374aef8 100644 --- a/src/ats/gnunet-service-ats.c +++ b/src/ats/gnunet-service-ats.c @@ -48,14 +48,13 @@ struct GNUNET_STATISTICS_Handle *GSA_stats; */ static void handle_ats_start (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) + const struct GNUNET_MessageHeader *message) { - const struct ClientStartMessage * msg = (const struct ClientStartMessage *) message; + const struct ClientStartMessage *msg = + (const struct ClientStartMessage *) message; enum StartFlag flag; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received `%s' message\n", - "ATS_START"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ATS_START"); flag = ntohl (msg->start_flag); switch (flag) { @@ -77,7 +76,7 @@ handle_ats_start (void *cls, struct GNUNET_SERVER_Client *client, GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } - GNUNET_SERVER_receive_done (client, GNUNET_OK); + GNUNET_SERVER_receive_done (client, GNUNET_OK); } @@ -131,20 +130,22 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, const struct GNUNET_CONFIGURATION_Handle *cfg) { static const struct GNUNET_SERVER_MessageHandler handlers[] = { - { &handle_ats_start, NULL, - GNUNET_MESSAGE_TYPE_ATS_START, sizeof (struct ClientStartMessage)}, - { &GAS_handle_request_address, NULL, - GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS, sizeof (struct RequestAddressMessage)}, - { &GAS_handle_address_update, NULL, - GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE, 0}, - { &GAS_handle_address_in_use, NULL, - GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE, 0}, - { &GAS_handle_address_destroyed, NULL, - GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED, 0}, - { &GAS_handle_reservation_request, NULL, - GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST, sizeof (struct ReservationRequestMessage)}, - { &GAS_handle_preference_change, NULL, - GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE, 0}, + {&handle_ats_start, NULL, + GNUNET_MESSAGE_TYPE_ATS_START, sizeof (struct ClientStartMessage)}, + {&GAS_handle_request_address, NULL, + GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS, + sizeof (struct RequestAddressMessage)}, + {&GAS_handle_address_update, NULL, + GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE, 0}, + {&GAS_handle_address_in_use, NULL, + GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE, 0}, + {&GAS_handle_address_destroyed, NULL, + GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED, 0}, + {&GAS_handle_reservation_request, NULL, + GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST, + sizeof (struct ReservationRequestMessage)}, + {&GAS_handle_preference_change, NULL, + GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE, 0}, {NULL, NULL, 0, 0} }; GSA_stats = GNUNET_STATISTICS_create ("ats", cfg); @@ -152,9 +153,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, GAS_performance_init (server); GAS_scheduling_init (server); GAS_addresses_init (cfg); - GNUNET_SERVER_disconnect_notify (server, - &client_disconnect_handler, - NULL); + GNUNET_SERVER_disconnect_notify (server, &client_disconnect_handler, NULL); GNUNET_SERVER_add_handlers (server, handlers); GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task, NULL); @@ -172,8 +171,8 @@ int main (int argc, char *const *argv) { return (GNUNET_OK == - GNUNET_SERVICE_run (argc, argv, "ats", - GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; + GNUNET_SERVICE_run (argc, argv, "ats", GNUNET_SERVICE_OPTION_NONE, + &run, NULL)) ? 0 : 1; } /* end of gnunet-service-ats.c */ diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 99dc0e17a..22304aa6d 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c @@ -42,11 +42,11 @@ struct ATS_Address uint32_t ats_count; - const void * addr; + const void *addr; - char * plugin; + char *plugin; - struct GNUNET_ATS_Information * ats; + struct GNUNET_ATS_Information *ats; struct GNUNET_TIME_Relative atsp_latency; @@ -74,7 +74,7 @@ struct ATS_Address }; -static struct GNUNET_CONTAINER_MultiHashMap * addresses; +static struct GNUNET_CONTAINER_MultiHashMap *addresses; static unsigned long long total_quota_in; @@ -92,10 +92,8 @@ static unsigned int active_addr_count; * @param value the 'struct ATS_Address' * @return GNUNET_OK (continue to iterate) */ -static int -update_bw_it (void *cls, - const GNUNET_HashCode * key, - void *value) +static int +update_bw_it (void *cls, const GNUNET_HashCode * key, void *value) { struct ATS_Address *aa = value; @@ -104,24 +102,18 @@ update_bw_it (void *cls, GNUNET_assert (active_addr_count > 0); aa->assigned_bw_in.value__ = htonl (total_quota_in / active_addr_count); aa->assigned_bw_out.value__ = htonl (total_quota_out / active_addr_count); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "New bandwidth for peer %s is %u/%u\n", - GNUNET_i2s (&aa->peer), - ntohl (aa->assigned_bw_in.value__), - ntohl (aa->assigned_bw_out.value__)); - GAS_scheduling_transmit_address_suggestion (&aa->peer, - aa->plugin, - aa->addr, aa->addr_len, - aa->session_id, - aa->ats, aa->ats_count, - aa->assigned_bw_out, aa->assigned_bw_in); - GAS_reservations_set_bandwidth (&aa->peer, - aa->assigned_bw_in); - GAS_performance_notify_clients (&aa->peer, - aa->plugin, - aa->addr, aa->addr_len, - aa->ats, aa->ats_count, - aa->assigned_bw_out, aa->assigned_bw_in); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New bandwidth for peer %s is %u/%u\n", + GNUNET_i2s (&aa->peer), ntohl (aa->assigned_bw_in.value__), + ntohl (aa->assigned_bw_out.value__)); + GAS_scheduling_transmit_address_suggestion (&aa->peer, aa->plugin, aa->addr, + aa->addr_len, aa->session_id, + aa->ats, aa->ats_count, + aa->assigned_bw_out, + aa->assigned_bw_in); + GAS_reservations_set_bandwidth (&aa->peer, aa->assigned_bw_in); + GAS_performance_notify_clients (&aa->peer, aa->plugin, aa->addr, aa->addr_len, + aa->ats, aa->ats_count, aa->assigned_bw_out, + aa->assigned_bw_in); return GNUNET_OK; } @@ -134,18 +126,12 @@ static void recalculate_assigned_bw () { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Recalculating bandwidth for all active connections\n"); - GNUNET_STATISTICS_update (GSA_stats, - "# bandwidth recalculations performed", - 1, - GNUNET_NO); - GNUNET_STATISTICS_set (GSA_stats, - "# active addresses", - active_addr_count, - GNUNET_NO); - GNUNET_CONTAINER_multihashmap_iterate (addresses, - &update_bw_it, - NULL); + "Recalculating bandwidth for all active connections\n"); + GNUNET_STATISTICS_update (GSA_stats, "# bandwidth recalculations performed", + 1, GNUNET_NO); + GNUNET_STATISTICS_set (GSA_stats, "# active addresses", active_addr_count, + GNUNET_NO); + GNUNET_CONTAINER_multihashmap_iterate (addresses, &update_bw_it, NULL); } @@ -161,10 +147,10 @@ destroy_address (struct ATS_Address *addr) int ret; ret = GNUNET_NO; - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove(addresses, - &addr->peer.hashPubKey, - addr)); + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove (addresses, + &addr->peer.hashPubKey, + addr)); if (GNUNET_YES == addr->active) { active_addr_count--; @@ -180,24 +166,22 @@ destroy_address (struct ATS_Address *addr) struct CompareAddressContext { - const struct ATS_Address * search; - struct ATS_Address * result; + const struct ATS_Address *search; + struct ATS_Address *result; }; -static int -compare_address_it (void *cls, - const GNUNET_HashCode * key, - void *value) +static int +compare_address_it (void *cls, const GNUNET_HashCode * key, void *value) { - struct CompareAddressContext * cac = cls; - struct ATS_Address * aa = value; - - if ( ( (aa->addr_len != cac->search->addr_len) || - (0 != strcmp(aa->plugin, cac->search->plugin)) || - (0 != memcmp (aa->addr, cac->search->addr, aa->addr_len)) ) && - ( (aa->session_id != cac->search->session_id) || - (cac->search->session_id == 0) )) + struct CompareAddressContext *cac = cls; + struct ATS_Address *aa = value; + + if (((aa->addr_len != cac->search->addr_len) || + (0 != strcmp (aa->plugin, cac->search->plugin)) || + (0 != memcmp (aa->addr, cac->search->addr, aa->addr_len))) && + ((aa->session_id != cac->search->session_id) || + (cac->search->session_id == 0))) return GNUNET_YES; cac->result = aa; return GNUNET_NO; @@ -205,7 +189,7 @@ compare_address_it (void *cls, /** - * Find an existing equivalent address record. + * Find an existing equivalent address record. * Compares by peer identity and network address OR by session ID * (one of the two must match). * @@ -215,34 +199,31 @@ compare_address_it (void *cls, */ struct ATS_Address * find_address (const struct GNUNET_PeerIdentity *peer, - const struct ATS_Address * addr) + const struct ATS_Address *addr) { struct CompareAddressContext cac; cac.result = NULL; cac.search = addr; - GNUNET_CONTAINER_multihashmap_get_multiple(addresses, - &peer->hashPubKey, - compare_address_it, - &cac); + GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey, + compare_address_it, &cac); return cac.result; } void GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, - const void *plugin_addr, size_t plugin_addr_len, - uint32_t session_id, - const struct GNUNET_ATS_Information *atsi, - uint32_t atsi_count) + const char *plugin_name, const void *plugin_addr, + size_t plugin_addr_len, uint32_t session_id, + const struct GNUNET_ATS_Information *atsi, + uint32_t atsi_count) { - struct ATS_Address * aa; - struct ATS_Address * old; + struct ATS_Address *aa; + struct ATS_Address *old; uint32_t i; aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len); - aa->ats = GNUNET_malloc(atsi_count * sizeof (struct GNUNET_ATS_Information)); + aa->ats = GNUNET_malloc (atsi_count * sizeof (struct GNUNET_ATS_Information)); aa->peer = *peer; aa->addr_len = plugin_addr_len; aa->ats_count = atsi_count; @@ -256,19 +237,17 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, { GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (addresses, - &peer->hashPubKey, - aa, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Added new address for peer `%s' %X\n", - GNUNET_i2s (peer), aa); + &peer->hashPubKey, aa, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added new address for peer `%s' %X\n", + GNUNET_i2s (peer), aa); old = aa; } else { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Updated existing address for peer `%s' %X \n", - GNUNET_i2s (peer), old); + "Updated existing address for peer `%s' %X \n", + GNUNET_i2s (peer), old); GNUNET_free_non_null (old->ats); old->session_id = session_id; old->ats = NULL; @@ -278,7 +257,7 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, GNUNET_free (aa->plugin); GNUNET_free (aa); } - for (i=0;iaddr_len > 0) ) + if ((aa.session_id == session_id) && (session_id != 0) && (res->addr_len > 0)) { /* just session died */ res->session_id = 0; @@ -350,10 +325,9 @@ GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer, return; } /* destroy address entirely (either was only session or was - not even with a session) */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Deleting address for peer `%s': `%s'\n", - GNUNET_i2s (peer), plugin_name); + * not even with a session) */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting address for peer `%s': `%s'\n", + GNUNET_i2s (peer), plugin_name); if (GNUNET_YES == destroy_address (res)) recalculate_assigned_bw (); } @@ -362,29 +336,27 @@ GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer, /** * Find a "good" address to use for a peer. If we already have an existing * address, we stick to it. Otherwise, we pick by lowest distance and then - * by lowest latency. - * + * by lowest latency. + * * @param cls the 'struct ATS_Address**' where we store the result * @param key unused * @param value another 'struct ATS_Address*' to consider using * @return GNUNET_OK (continue to iterate) */ -static int -find_address_it (void *cls, - const GNUNET_HashCode * key, - void *value) +static int +find_address_it (void *cls, const GNUNET_HashCode * key, void *value) { struct ATS_Address **ap = cls; - struct ATS_Address * aa = (struct ATS_Address *) value; - struct ATS_Address * ab = *ap; + struct ATS_Address *aa = (struct ATS_Address *) value; + struct ATS_Address *ab = *ap; if (NULL == ab) { *ap = aa; return GNUNET_OK; } - if ( (ntohl (ab->assigned_bw_in.value__) == 0) && - (ntohl (aa->assigned_bw_in.value__) > 0) ) + if ((ntohl (ab->assigned_bw_in.value__) == 0) && + (ntohl (aa->assigned_bw_in.value__) > 0)) { /* stick to existing connection */ *ap = aa; @@ -410,19 +382,16 @@ find_address_it (void *cls, void GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer) { - struct ATS_Address * aa; + struct ATS_Address *aa; aa = NULL; - GNUNET_CONTAINER_multihashmap_get_multiple (addresses, - &peer->hashPubKey, - &find_address_it, - &aa); + GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey, + &find_address_it, &aa); if (aa == NULL) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Cannot suggest address for peer `%s'\n", - GNUNET_i2s (peer)); - return; + "Cannot suggest address for peer `%s'\n", GNUNET_i2s (peer)); + return; } if (aa->active == GNUNET_NO) { @@ -433,11 +402,11 @@ GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer) else { /* just to be sure... */ - GAS_scheduling_transmit_address_suggestion (peer, aa->plugin, - aa->addr, aa->addr_len, - aa->session_id, - aa->ats, aa->ats_count, - aa->assigned_bw_out, aa->assigned_bw_in); + GAS_scheduling_transmit_address_suggestion (peer, aa->plugin, aa->addr, + aa->addr_len, aa->session_id, + aa->ats, aa->ats_count, + aa->assigned_bw_out, + aa->assigned_bw_in); } } @@ -446,8 +415,8 @@ GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer) // not with 'addresses' in the future... void GAS_addresses_change_preference (const struct GNUNET_PeerIdentity *peer, - enum GNUNET_ATS_PreferenceKind kind, - float score) + enum GNUNET_ATS_PreferenceKind kind, + float score) { // do nothing for now... } @@ -462,16 +431,14 @@ void GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg) { GNUNET_assert (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_number (cfg, - "core", - "TOTAL_QUOTA_IN", - &total_quota_in)); + GNUNET_CONFIGURATION_get_value_number (cfg, "core", + "TOTAL_QUOTA_IN", + &total_quota_in)); GNUNET_assert (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_number (cfg, - "core", - "TOTAL_QUOTA_OUT", - &total_quota_out)); - addresses = GNUNET_CONTAINER_multihashmap_create(128); + GNUNET_CONFIGURATION_get_value_number (cfg, "core", + "TOTAL_QUOTA_OUT", + &total_quota_out)); + addresses = GNUNET_CONTAINER_multihashmap_create (128); } @@ -483,12 +450,10 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg) * @param value the 'struct ATS_Address' to free * @return GNUNET_OK (continue to iterate) */ -static int -free_address_it (void *cls, - const GNUNET_HashCode * key, - void *value) +static int +free_address_it (void *cls, const GNUNET_HashCode * key, void *value) { - struct ATS_Address * aa = value; + struct ATS_Address *aa = value; destroy_address (aa); return GNUNET_OK; @@ -499,8 +464,7 @@ void GAS_addresses_destroy_all () { if (addresses != NULL) - GNUNET_CONTAINER_multihashmap_iterate(addresses, - &free_address_it, NULL); + GNUNET_CONTAINER_multihashmap_iterate (addresses, &free_address_it, NULL); GNUNET_assert (active_addr_count == 0); } diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h index 1d218ba57..7fde42d96 100644 --- a/src/ats/gnunet-service-ats_addresses.h +++ b/src/ats/gnunet-service-ats_addresses.h @@ -28,7 +28,7 @@ #define GNUNET_SERVICE_ATS_ADDRESSES_H #include "gnunet_util_lib.h" -#include "gnunet_ats_service.h" +#include "gnunet_ats_service.h" #include "ats.h" /** @@ -48,18 +48,16 @@ GAS_addresses_done (void); void GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, - const void *plugin_addr, size_t plugin_addr_len, - uint32_t session_id, - const struct GNUNET_ATS_Information *atsi, - uint32_t atsi_count); + const char *plugin_name, const void *plugin_addr, + size_t plugin_addr_len, uint32_t session_id, + const struct GNUNET_ATS_Information *atsi, + uint32_t atsi_count); void GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, - const void *plugin_addr, size_t plugin_addr_len, - uint32_t session_id); + const char *plugin_name, const void *plugin_addr, + size_t plugin_addr_len, uint32_t session_id); void @@ -78,8 +76,8 @@ GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer); // not with 'addresses' in the future... void GAS_addresses_change_preference (const struct GNUNET_PeerIdentity *peer, - enum GNUNET_ATS_PreferenceKind kind, - float score); + enum GNUNET_ATS_PreferenceKind kind, + float score); /* FIXME: add performance request API */ diff --git a/src/ats/gnunet-service-ats_math.h b/src/ats/gnunet-service-ats_math.h index 1324c30d0..0ec85f3f0 100644 --- a/src/ats/gnunet-service-ats_math.h +++ b/src/ats/gnunet-service-ats_math.h @@ -67,11 +67,10 @@ struct ATS_mechanism; struct ATS_peer; -typedef void (*GNUNET_ATS_AddressNotification) (struct ATS_peer ** - peers, int *c_p, - struct ATS_mechanism - ** mechanisms, - int *c_m); +typedef void (*GNUNET_ATS_AddressNotification) (struct ATS_peer ** peers, + int *c_p, + struct ATS_mechanism ** + mechanisms, int *c_m); typedef void (*GNUNET_ATS_ResultCallback) (void); diff --git a/src/ats/gnunet-service-ats_performance.c b/src/ats/gnunet-service-ats_performance.c index 0fa08ac4b..4b8d23720 100644 --- a/src/ats/gnunet-service-ats_performance.c +++ b/src/ats/gnunet-service-ats_performance.c @@ -40,13 +40,13 @@ struct PerformanceClient /** * Next in doubly-linked list. */ - struct PerformanceClient * next; + struct PerformanceClient *next; /** * Previous in doubly-linked list. */ - struct PerformanceClient * prev; - + struct PerformanceClient *prev; + /** * Actual handle to the client. */ @@ -69,7 +69,7 @@ static struct PerformanceClient *pc_head; * Tail of linked list of all clients to this service. */ static struct PerformanceClient *pc_tail; - + /** * Context for sending messages to performance clients. */ @@ -82,10 +82,10 @@ static struct GNUNET_SERVER_NotificationContext *nc; * @param client server handle * @return internal handle */ -static struct PerformanceClient * +static struct PerformanceClient * find_client (struct GNUNET_SERVER_Client *client) { - struct PerformanceClient * pc; + struct PerformanceClient *pc; for (pc = pc_head; pc != NULL; pc = pc->next) if (pc->client == client) @@ -101,9 +101,9 @@ find_client (struct GNUNET_SERVER_Client *client) */ void GAS_performance_add_client (struct GNUNET_SERVER_Client *client, - enum StartFlag flag) + enum StartFlag flag) { - struct PerformanceClient * pc; + struct PerformanceClient *pc; GNUNET_break (NULL == find_client (client)); pc = GNUNET_malloc (sizeof (struct PerformanceClient)); @@ -111,7 +111,7 @@ GAS_performance_add_client (struct GNUNET_SERVER_Client *client, pc->flag = flag; GNUNET_SERVER_notification_context_add (nc, client); GNUNET_SERVER_client_keep (client); - GNUNET_CONTAINER_DLL_insert(pc_head, pc_tail, pc); + GNUNET_CONTAINER_DLL_insert (pc_head, pc_tail, pc); } @@ -124,7 +124,7 @@ GAS_performance_add_client (struct GNUNET_SERVER_Client *client, void GAS_performance_remove_client (struct GNUNET_SERVER_Client *client) { - struct PerformanceClient * pc; + struct PerformanceClient *pc; pc = find_client (client); if (NULL == pc) @@ -150,25 +150,30 @@ GAS_performance_remove_client (struct GNUNET_SERVER_Client *client) */ void GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, - const void *plugin_addr, size_t plugin_addr_len, - const struct GNUNET_ATS_Information *atsi, - uint32_t atsi_count, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) + const char *plugin_name, + const void *plugin_addr, size_t plugin_addr_len, + const struct GNUNET_ATS_Information *atsi, + uint32_t atsi_count, + struct GNUNET_BANDWIDTH_Value32NBO + bandwidth_out, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) { struct PerformanceClient *pc; struct PeerInformationMessage *msg; size_t plugin_name_length = strlen (plugin_name) + 1; - size_t msize = sizeof (struct PeerInformationMessage) + atsi_count * sizeof (struct GNUNET_ATS_Information) - + plugin_addr_len + plugin_name_length; + size_t msize = + sizeof (struct PeerInformationMessage) + + atsi_count * sizeof (struct GNUNET_ATS_Information) + plugin_addr_len + + plugin_name_length; char buf[msize]; struct GNUNET_ATS_Information *atsp; char *addrp; GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); - GNUNET_assert (atsi_count < GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)); - msg = (struct PeerInformationMessage*) buf; + GNUNET_assert (atsi_count < + GNUNET_SERVER_MAX_MESSAGE_SIZE / + sizeof (struct GNUNET_ATS_Information)); + msg = (struct PeerInformationMessage *) buf; msg->header.size = htons (msize); msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION); msg->ats_count = htonl (atsi_count); @@ -177,22 +182,19 @@ GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer, msg->plugin_name_length = htons (plugin_name_length); msg->bandwidth_out = bandwidth_out; msg->bandwidth_in = bandwidth_in; - atsp = (struct GNUNET_ATS_Information* ) &msg[1]; + atsp = (struct GNUNET_ATS_Information *) &msg[1]; memcpy (atsp, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count); - addrp = (char*) &atsp[atsi_count]; + addrp = (char *) &atsp[atsi_count]; memcpy (addrp, plugin_addr, plugin_addr_len); strcpy (&addrp[plugin_addr_len], plugin_name); for (pc = pc_head; pc != NULL; pc = pc->next) if (pc->flag == START_FLAG_PERFORMANCE_WITH_PIC) { - GNUNET_SERVER_notification_context_unicast (nc, - pc->client, - &msg->header, - GNUNET_YES); + GNUNET_SERVER_notification_context_unicast (nc, pc->client, &msg->header, + GNUNET_YES); GNUNET_STATISTICS_update (GSA_stats, - "# performance updates given to clients", - 1, - GNUNET_NO); + "# performance updates given to clients", 1, + GNUNET_NO); } } @@ -206,9 +208,10 @@ GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer, */ void GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) + const struct GNUNET_MessageHeader *message) { - const struct ReservationRequestMessage * msg = (const struct ReservationRequestMessage *) message; + const struct ReservationRequestMessage *msg = + (const struct ReservationRequestMessage *) message; struct ReservationResultMessage result; int32_t amount; struct GNUNET_TIME_Relative res_delay; @@ -220,12 +223,10 @@ GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client, GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received `%s' message\n", - "RESERVATION_REQUEST"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", + "RESERVATION_REQUEST"); amount = (int32_t) ntohl (msg->amount); - res_delay = GAS_reservations_reserve (&msg->peer, - amount); + res_delay = GAS_reservations_reserve (&msg->peer, amount); if (res_delay.rel_value > 0) amount = 0; result.header.size = htons (sizeof (struct ReservationResultMessage)); @@ -233,14 +234,10 @@ GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client, result.amount = htonl (amount); result.peer = msg->peer; result.res_delay = GNUNET_TIME_relative_hton (res_delay); - GNUNET_STATISTICS_update (GSA_stats, - "# reservation requests processed", - 1, - GNUNET_NO); - GNUNET_SERVER_notification_context_unicast (nc, - client, - &result.header, - GNUNET_NO); + GNUNET_STATISTICS_update (GSA_stats, "# reservation requests processed", 1, + GNUNET_NO); + GNUNET_SERVER_notification_context_unicast (nc, client, &result.header, + GNUNET_NO); GNUNET_SERVER_receive_done (client, GNUNET_OK); } @@ -254,15 +251,16 @@ GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client, */ void GAS_handle_preference_change (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) + const struct GNUNET_MessageHeader *message) { - const struct ChangePreferenceMessage * msg; + const struct ChangePreferenceMessage *msg; const struct PreferenceInformation *pi; uint16_t msize; uint32_t nump; uint32_t i; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "PREFERENCE_CHANGE"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", + "PREFERENCE_CHANGE"); msize = ntohs (message->size); if (msize < sizeof (struct ChangePreferenceMessage)) { @@ -272,21 +270,22 @@ GAS_handle_preference_change (void *cls, struct GNUNET_SERVER_Client *client, } msg = (const struct ChangePreferenceMessage *) message; nump = ntohl (msg->num_preferences); - if (msize != sizeof (struct ChangePreferenceMessage) + nump * sizeof (struct PreferenceInformation)) + if (msize != + sizeof (struct ChangePreferenceMessage) + + nump * sizeof (struct PreferenceInformation)) { GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } - GNUNET_STATISTICS_update (GSA_stats, - "# preference change requests processed", - 1, - GNUNET_NO); + GNUNET_STATISTICS_update (GSA_stats, "# preference change requests processed", + 1, GNUNET_NO); pi = (const struct PreferenceInformation *) &msg[1]; - for (i=0;ipeer, - (enum GNUNET_ATS_PreferenceKind) ntohl (pi[i].preference_kind), - pi[i].preference_value); + (enum GNUNET_ATS_PreferenceKind) + ntohl (pi[i].preference_kind), + pi[i].preference_value); GNUNET_SERVER_receive_done (client, GNUNET_OK); } diff --git a/src/ats/gnunet-service-ats_performance.h b/src/ats/gnunet-service-ats_performance.h index 5988bff44..44d02452b 100644 --- a/src/ats/gnunet-service-ats_performance.h +++ b/src/ats/gnunet-service-ats_performance.h @@ -39,7 +39,7 @@ */ void GAS_performance_add_client (struct GNUNET_SERVER_Client *client, - enum StartFlag flag); + enum StartFlag flag); /** @@ -67,12 +67,14 @@ GAS_performance_remove_client (struct GNUNET_SERVER_Client *client); */ void GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, - const void *plugin_addr, size_t plugin_addr_len, - const struct GNUNET_ATS_Information *atsi, - uint32_t atsi_count, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in); + const char *plugin_name, + const void *plugin_addr, size_t plugin_addr_len, + const struct GNUNET_ATS_Information *atsi, + uint32_t atsi_count, + struct GNUNET_BANDWIDTH_Value32NBO + bandwidth_out, + struct GNUNET_BANDWIDTH_Value32NBO + bandwidth_in); /** @@ -84,7 +86,7 @@ GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer, */ void GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message); + const struct GNUNET_MessageHeader *message); /** @@ -96,7 +98,7 @@ GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client, */ void GAS_handle_preference_change (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message); + const struct GNUNET_MessageHeader *message); /** diff --git a/src/ats/gnunet-service-ats_reservations.c b/src/ats/gnunet-service-ats_reservations.c index 492751254..f40e54516 100644 --- a/src/ats/gnunet-service-ats_reservations.c +++ b/src/ats/gnunet-service-ats_reservations.c @@ -27,7 +27,7 @@ #include "gnunet-service-ats_reservations.h" /** - * Number of seconds that available bandwidth carries over + * Number of seconds that available bandwidth carries over * (can accumulate). */ #define MAX_BANDWIDTH_CARRY_S 5 @@ -52,32 +52,27 @@ static struct GNUNET_CONTAINER_MultiHashMap *trackers; */ struct GNUNET_TIME_Relative GAS_reservations_reserve (const struct GNUNET_PeerIdentity *peer, - int32_t amount) + int32_t amount) { struct GNUNET_BANDWIDTH_Tracker *tracker; struct GNUNET_TIME_Relative ret; - tracker = GNUNET_CONTAINER_multihashmap_get (trackers, - &peer->hashPubKey); + tracker = GNUNET_CONTAINER_multihashmap_get (trackers, &peer->hashPubKey); if (NULL == tracker) - return GNUNET_TIME_UNIT_ZERO; /* not connected, satisfy now */ + return GNUNET_TIME_UNIT_ZERO; /* not connected, satisfy now */ if (amount >= 0) { - ret = GNUNET_BANDWIDTH_tracker_get_delay (tracker, - amount); + ret = GNUNET_BANDWIDTH_tracker_get_delay (tracker, amount); if (ret.rel_value > 0) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Delay to satisfy reservation for %d bytes is %llu ms\n", - (int) amount, - (unsigned long long) ret.rel_value); + "Delay to satisfy reservation for %d bytes is %llu ms\n", + (int) amount, (unsigned long long) ret.rel_value); return ret; } } (void) GNUNET_BANDWIDTH_tracker_consume (tracker, amount); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Reserved %d bytes\n", - (int) amount); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reserved %d bytes\n", (int) amount); return GNUNET_TIME_UNIT_ZERO; } @@ -85,42 +80,37 @@ GAS_reservations_reserve (const struct GNUNET_PeerIdentity *peer, /** * Set the amount of bandwidth the other peer could currently transmit * to us (as far as we know) to the given value. - * + * * @param peer identity of the peer * @param bandwidth_in currently available bandwidth from that peer to * this peer (estimate) */ void GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) { struct GNUNET_BANDWIDTH_Tracker *tracker; - tracker = GNUNET_CONTAINER_multihashmap_get (trackers, - &peer->hashPubKey); + tracker = GNUNET_CONTAINER_multihashmap_get (trackers, &peer->hashPubKey); if (0 == ntohl (bandwidth_in.value__)) { GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (trackers, - &peer->hashPubKey, - tracker)); + GNUNET_CONTAINER_multihashmap_remove (trackers, + &peer->hashPubKey, + tracker)); GNUNET_free (tracker); return; } if (NULL == tracker) { tracker = GNUNET_malloc (sizeof (struct GNUNET_BANDWIDTH_Tracker)); - GNUNET_BANDWIDTH_tracker_init (tracker, - bandwidth_in, - MAX_BANDWIDTH_CARRY_S); - GNUNET_CONTAINER_multihashmap_put (trackers, - &peer->hashPubKey, - tracker, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); + GNUNET_BANDWIDTH_tracker_init (tracker, bandwidth_in, + MAX_BANDWIDTH_CARRY_S); + GNUNET_CONTAINER_multihashmap_put (trackers, &peer->hashPubKey, tracker, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); return; } - GNUNET_BANDWIDTH_tracker_update_quota (tracker, - bandwidth_in); + GNUNET_BANDWIDTH_tracker_update_quota (tracker, bandwidth_in); } @@ -130,7 +120,7 @@ GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer, void GAS_reservations_init () { - trackers = GNUNET_CONTAINER_multihashmap_create(128); + trackers = GNUNET_CONTAINER_multihashmap_create (128); } @@ -142,10 +132,8 @@ GAS_reservations_init () * @param value the 'struct GNUNET_BANDWIDTH_Tracker' to free * @return GNUNET_OK (continue to iterate) */ -static int -free_tracker (void *cls, - const GNUNET_HashCode * key, - void *value) +static int +free_tracker (void *cls, const GNUNET_HashCode * key, void *value) { struct GNUNET_BANDWIDTH_Tracker *tracker = value; diff --git a/src/ats/gnunet-service-ats_reservations.h b/src/ats/gnunet-service-ats_reservations.h index 5112f8213..5ddec9bd6 100644 --- a/src/ats/gnunet-service-ats_reservations.h +++ b/src/ats/gnunet-service-ats_reservations.h @@ -32,14 +32,15 @@ /** * Set the amount of bandwidth the other peer could currently transmit * to us (as far as we know) to the given value. - * + * * @param peer identity of the peer * @param bandwidth_in currently available bandwidth from that peer to * this peer (estimate) */ void GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in); + struct GNUNET_BANDWIDTH_Value32NBO + bandwidth_in); /** @@ -55,7 +56,7 @@ GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer, */ struct GNUNET_TIME_Relative GAS_reservations_reserve (const struct GNUNET_PeerIdentity *peer, - int32_t amount); + int32_t amount); /** diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c index bb95182c8..4af44e29b 100644 --- a/src/ats/gnunet-service-ats_scheduling.c +++ b/src/ats/gnunet-service-ats_scheduling.c @@ -46,7 +46,7 @@ static struct GNUNET_SERVER_Client *my_client; * Register a new scheduling client. * * @param client handle of the new client - * @return GNUNET_OK on success, GNUNET_SYSERR on error + * @return GNUNET_OK on success, GNUNET_SYSERR on error */ int GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client) @@ -54,7 +54,7 @@ GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client) if (my_client != NULL) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "This ATS already has a scheduling client, refusing new scheduling client for now.\n"); + "This ATS already has a scheduling client, refusing new scheduling client for now.\n"); return GNUNET_SYSERR; } my_client = client; @@ -96,32 +96,37 @@ GAS_scheduling_remove_client (struct GNUNET_SERVER_Client *client) * @param bandwidth_in assigned inbound bandwidth */ void -GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, - const void *plugin_addr, size_t plugin_addr_len, - uint32_t session_id, - const struct GNUNET_ATS_Information *atsi, - uint32_t atsi_count, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) +GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity + *peer, const char *plugin_name, + const void *plugin_addr, + size_t plugin_addr_len, + uint32_t session_id, + const struct GNUNET_ATS_Information + *atsi, uint32_t atsi_count, + struct GNUNET_BANDWIDTH_Value32NBO + bandwidth_out, + struct GNUNET_BANDWIDTH_Value32NBO + bandwidth_in) { struct AddressSuggestionMessage *msg; size_t plugin_name_length = strlen (plugin_name) + 1; - size_t msize = sizeof (struct AddressSuggestionMessage) + atsi_count * sizeof (struct GNUNET_ATS_Information) - + plugin_addr_len + plugin_name_length; + size_t msize = + sizeof (struct AddressSuggestionMessage) + + atsi_count * sizeof (struct GNUNET_ATS_Information) + plugin_addr_len + + plugin_name_length; char buf[msize]; struct GNUNET_ATS_Information *atsp; char *addrp; if (my_client == NULL) return; - GNUNET_STATISTICS_update (GSA_stats, - "# address suggestions made", - 1, - GNUNET_NO); + GNUNET_STATISTICS_update (GSA_stats, "# address suggestions made", 1, + GNUNET_NO); GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); - GNUNET_assert (atsi_count < GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)); - msg = (struct AddressSuggestionMessage*) buf; + GNUNET_assert (atsi_count < + GNUNET_SERVER_MAX_MESSAGE_SIZE / + sizeof (struct GNUNET_ATS_Information)); + msg = (struct AddressSuggestionMessage *) buf; msg->header.size = htons (msize); msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION); msg->ats_count = htonl (atsi_count); @@ -131,15 +136,13 @@ GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *pe msg->session_id = htonl (session_id); msg->bandwidth_out = bandwidth_out; msg->bandwidth_in = bandwidth_in; - atsp = (struct GNUNET_ATS_Information* ) &msg[1]; + atsp = (struct GNUNET_ATS_Information *) &msg[1]; memcpy (atsp, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count); - addrp = (char*) &atsp[atsi_count]; + addrp = (char *) &atsp[atsi_count]; memcpy (addrp, plugin_addr, plugin_addr_len); strcpy (&addrp[plugin_addr_len], plugin_name); - GNUNET_SERVER_notification_context_unicast (nc, - my_client, - &msg->header, - GNUNET_YES); + GNUNET_SERVER_notification_context_unicast (nc, my_client, &msg->header, + GNUNET_YES); } @@ -152,16 +155,15 @@ GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *pe */ void GAS_handle_request_address (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) - + const struct GNUNET_MessageHeader *message) { - const struct RequestAddressMessage * msg = (const struct RequestAddressMessage *) message; + const struct RequestAddressMessage *msg = + (const struct RequestAddressMessage *) message; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "REQUEST_ADDRESS"); - GNUNET_STATISTICS_update (GSA_stats, - "# address requests received", - 1, - GNUNET_NO); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", + "REQUEST_ADDRESS"); + GNUNET_STATISTICS_update (GSA_stats, "# address requests received", 1, + GNUNET_NO); GNUNET_break (0 == ntohl (msg->reserved)); GAS_addresses_request_address (&msg->peer); GNUNET_SERVER_receive_done (client, GNUNET_OK); @@ -177,9 +179,9 @@ GAS_handle_request_address (void *cls, struct GNUNET_SERVER_Client *client, */ void GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) + const struct GNUNET_MessageHeader *message) { - const struct AddressUpdateMessage * m; + const struct AddressUpdateMessage *m; const struct GNUNET_ATS_Information *atsi; const char *address; const char *plugin_name; @@ -188,9 +190,8 @@ GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client, uint32_t ats_count; uint16_t size; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received `%s' message\n", - "ADDRESS_UPDATE"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", + "ADDRESS_UPDATE"); size = ntohs (message->size); if (size < sizeof (struct AddressUpdateMessage)) { @@ -198,38 +199,31 @@ GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client, GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } - m = (const struct AddressUpdateMessage*) message; + m = (const struct AddressUpdateMessage *) message; ats_count = ntohl (m->ats_count); address_length = ntohs (m->address_length); - plugin_name_length = ntohs (m->plugin_name_length); - atsi = (const struct GNUNET_ATS_Information*) &m[1]; - address = (const char*) &atsi[ats_count]; + plugin_name_length = ntohs (m->plugin_name_length); + atsi = (const struct GNUNET_ATS_Information *) &m[1]; + address = (const char *) &atsi[ats_count]; if (plugin_name_length != 0) plugin_name = &address[address_length]; else plugin_name = ""; - if ( (address_length + - plugin_name_length + - ats_count * sizeof (struct GNUNET_ATS_Information) + - sizeof (struct AddressUpdateMessage) != ntohs (message->size)) || - (ats_count > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) || - (plugin_name[plugin_name_length - 1] != '\0') ) + if ((address_length + plugin_name_length + + ats_count * sizeof (struct GNUNET_ATS_Information) + + sizeof (struct AddressUpdateMessage) != ntohs (message->size)) || + (ats_count > + GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) + || (plugin_name[plugin_name_length - 1] != '\0')) { GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } - GNUNET_STATISTICS_update (GSA_stats, - "# address updates received", - 1, - GNUNET_NO); - GAS_addresses_update (&m->peer, - plugin_name, - address, - address_length, - ntohl (m->session_id), - atsi, - ats_count); + GNUNET_STATISTICS_update (GSA_stats, "# address updates received", 1, + GNUNET_NO); + GAS_addresses_update (&m->peer, plugin_name, address, address_length, + ntohl (m->session_id), atsi, ats_count); GNUNET_SERVER_receive_done (client, GNUNET_OK); } @@ -245,7 +239,7 @@ void GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { - const struct AddressUseMessage * m; + const struct AddressUseMessage *m; const char *address; const char *plugin_name; uint16_t address_length; @@ -253,8 +247,7 @@ GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client, uint16_t size; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received `%s' message\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ADDRESS_IN_USE"); size = ntohs (message->size); if (size < sizeof (struct AddressUseMessage)) @@ -263,21 +256,20 @@ GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client, GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } - m = (const struct AddressUseMessage*) message; + m = (const struct AddressUseMessage *) message; address_length = ntohs (m->address_length); plugin_name_length = ntohs (m->plugin_name_length); - address = (const char*) &m[1]; + address = (const char *) &m[1]; if (plugin_name_length != 0) plugin_name = &address[address_length]; else plugin_name = ""; - if ( (address_length + - plugin_name_length + - sizeof (struct AddressUseMessage) != ntohs (message->size)) || - (plugin_name[plugin_name_length - 1] != '\0') ) + if ((address_length + plugin_name_length + + sizeof (struct AddressUseMessage) != ntohs (message->size)) || + (plugin_name[plugin_name_length - 1] != '\0')) { GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); @@ -306,10 +298,9 @@ GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client, */ void GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) - + const struct GNUNET_MessageHeader *message) { - const struct AddressDestroyedMessage * m; + const struct AddressDestroyedMessage *m; struct SessionReleaseMessage srm; const char *address; const char *plugin_name; @@ -317,60 +308,50 @@ GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client, uint16_t plugin_name_length; uint16_t size; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received `%s' message of size %u %u\n", - "ADDRESS_DESTROYED", ntohs (message->size), sizeof (struct AddressDestroyedMessage)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message of size %u %u\n", + "ADDRESS_DESTROYED", ntohs (message->size), + sizeof (struct AddressDestroyedMessage)); size = ntohs (message->size); - if ( (size < sizeof (struct AddressDestroyedMessage)) || - (client != my_client) ) + if ((size < sizeof (struct AddressDestroyedMessage)) || (client != my_client)) { GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } - m = (const struct AddressDestroyedMessage*) message; + m = (const struct AddressDestroyedMessage *) message; GNUNET_break (0 == ntohl (m->reserved)); address_length = ntohs (m->address_length); - plugin_name_length = ntohs (m->plugin_name_length); - address = (const char*) &m[1]; + plugin_name_length = ntohs (m->plugin_name_length); + address = (const char *) &m[1]; if (plugin_name_length != 0) plugin_name = &address[address_length]; else plugin_name = ""; - if ( (address_length + - plugin_name_length + - sizeof (struct AddressDestroyedMessage) != ntohs (message->size))) + if ((address_length + plugin_name_length + + sizeof (struct AddressDestroyedMessage) != ntohs (message->size))) { GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; - } - if ( (plugin_name_length != 0) && - (plugin_name[plugin_name_length - 1] != '\0') ) + } + if ((plugin_name_length != 0) && + (plugin_name[plugin_name_length - 1] != '\0')) { GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } - GNUNET_STATISTICS_update (GSA_stats, - "# addresses destroyed", - 1, - GNUNET_NO); - GAS_addresses_destroy (&m->peer, - plugin_name, - address, - address_length, - ntohl (m->session_id)); + GNUNET_STATISTICS_update (GSA_stats, "# addresses destroyed", 1, GNUNET_NO); + GAS_addresses_destroy (&m->peer, plugin_name, address, address_length, + ntohl (m->session_id)); if (0 != ntohl (m->session_id)) { srm.header.type = ntohs (GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE); srm.header.size = ntohs (sizeof (struct SessionReleaseMessage)); srm.session_id = m->session_id; srm.peer = m->peer; - GNUNET_SERVER_notification_context_unicast (nc, - client, - &srm.header, - GNUNET_NO); + GNUNET_SERVER_notification_context_unicast (nc, client, &srm.header, + GNUNET_NO); } GNUNET_SERVER_receive_done (client, GNUNET_OK); } @@ -382,7 +363,7 @@ GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client, * @param server handle to our server */ void -GAS_scheduling_init (struct GNUNET_SERVER_Handle *server) +GAS_scheduling_init (struct GNUNET_SERVER_Handle *server) { nc = GNUNET_SERVER_notification_context_create (server, 128); } diff --git a/src/ats/gnunet-service-ats_scheduling.h b/src/ats/gnunet-service-ats_scheduling.h index 7eeaba8b3..44ac705e3 100644 --- a/src/ats/gnunet-service-ats_scheduling.h +++ b/src/ats/gnunet-service-ats_scheduling.h @@ -34,7 +34,7 @@ * Register a new scheduling client. * * @param client handle of the new client - * @return GNUNET_OK on success, GNUNET_SYSERR on error + * @return GNUNET_OK on success, GNUNET_SYSERR on error */ int GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client); @@ -65,14 +65,17 @@ GAS_scheduling_remove_client (struct GNUNET_SERVER_Client *client); * @param bandwidth_in assigned inbound bandwidth */ void -GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, - const void *plugin_addr, size_t plugin_addr_len, - uint32_t session_id, - const struct GNUNET_ATS_Information *atsi, - uint32_t atsi_count, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in); +GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity + *peer, const char *plugin_name, + const void *plugin_addr, + size_t plugin_addr_len, + uint32_t session_id, + const struct GNUNET_ATS_Information + *atsi, uint32_t atsi_count, + struct GNUNET_BANDWIDTH_Value32NBO + bandwidth_out, + struct GNUNET_BANDWIDTH_Value32NBO + bandwidth_in); /** @@ -84,7 +87,7 @@ GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *pe */ void GAS_handle_request_address (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message); + const struct GNUNET_MessageHeader *message); @@ -97,7 +100,7 @@ GAS_handle_request_address (void *cls, struct GNUNET_SERVER_Client *client, */ void GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message); + const struct GNUNET_MessageHeader *message); /** @@ -120,7 +123,7 @@ GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client, */ void GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message); + const struct GNUNET_MessageHeader *message); /** diff --git a/src/ats/test_ats_api_bandwidth_consumption.c b/src/ats/test_ats_api_bandwidth_consumption.c index d2a7b53dc..1eb57fcc8 100644 --- a/src/ats/test_ats_api_bandwidth_consumption.c +++ b/src/ats/test_ats_api_bandwidth_consumption.c @@ -44,9 +44,9 @@ static struct GNUNET_ATS_PerformanceHandle *atp; struct GNUNET_ATS_ReservationContext *sh; -static struct GNUNET_OS_Process * arm_proc; +static struct GNUNET_OS_Process *arm_proc; -static struct PeerContext * p; +static struct PeerContext *p; static uint32_t bw_in; @@ -56,23 +56,23 @@ static int ret; struct Address { - char * plugin; + char *plugin; size_t plugin_len; - void * addr; + void *addr; size_t addr_len; - struct GNUNET_ATS_Information * ats; + struct GNUNET_ATS_Information *ats; int ats_count; - void *session; + void *session; }; struct PeerContext { struct GNUNET_PeerIdentity id; - struct Address * addr; + struct Address *addr; }; @@ -94,12 +94,12 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) if (consume_task != GNUNET_SCHEDULER_NO_TASK) { - GNUNET_SCHEDULER_cancel(consume_task); + GNUNET_SCHEDULER_cancel (consume_task); consume_task = GNUNET_SCHEDULER_NO_TASK; } if (sh != NULL) - GNUNET_ATS_reserve_bandwidth_cancel(sh); + GNUNET_ATS_reserve_bandwidth_cancel (sh); if (ats != NULL) GNUNET_ATS_scheduling_done (ats); @@ -120,13 +120,13 @@ end () { if (die_task != GNUNET_SCHEDULER_NO_TASK) { - GNUNET_SCHEDULER_cancel(die_task); + GNUNET_SCHEDULER_cancel (die_task); die_task = GNUNET_SCHEDULER_NO_TASK; } if (consume_task != GNUNET_SCHEDULER_NO_TASK) { - GNUNET_SCHEDULER_cancel(consume_task); + GNUNET_SCHEDULER_cancel (consume_task); consume_task = GNUNET_SCHEDULER_NO_TASK; } @@ -142,41 +142,25 @@ end () stop_arm (); } -void performance_cb (void *cls, - const struct - GNUNET_PeerIdentity * - peer, - const char *plugin_name, - const void *plugin_addr, - size_t plugin_addr_len, - struct - GNUNET_BANDWIDTH_Value32NBO - bandwidth_out, - struct - GNUNET_BANDWIDTH_Value32NBO - bandwidth_in, - const struct - GNUNET_ATS_Information - * ats, - uint32_t ats_count) +void +performance_cb (void *cls, const struct GNUNET_PeerIdentity *peer, + const char *plugin_name, const void *plugin_addr, + size_t plugin_addr_len, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { } -void reservation_cb (void *cls, - const struct - GNUNET_PeerIdentity * - peer, - int32_t amount, - struct - GNUNET_TIME_Relative - res_delay) +void +reservation_cb (void *cls, const struct GNUNET_PeerIdentity *peer, + int32_t amount, struct GNUNET_TIME_Relative res_delay) { sh = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS reserved bandwidth of %i to peer `%s' in %llu ms\n", - amount, - GNUNET_i2s (peer), - res_delay.rel_value); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "ATS reserved bandwidth of %i to peer `%s' in %llu ms\n", amount, + GNUNET_i2s (peer), res_delay.rel_value); } static void @@ -184,51 +168,43 @@ consume_bandwidth (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { consume_task = GNUNET_SCHEDULER_NO_TASK; int32_t to_reserve = 500; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to reserver bandwidth of %i to peer `%s' in %llu ms\n", - to_reserve, - GNUNET_i2s (&p->id)); - sh = GNUNET_ATS_reserve_bandwidth (atp, &p->id, to_reserve, &reservation_cb, NULL); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Trying to reserver bandwidth of %i to peer `%s' in %llu ms\n", + to_reserve, GNUNET_i2s (&p->id)); + + sh = GNUNET_ATS_reserve_bandwidth (atp, &p->id, to_reserve, &reservation_cb, + NULL); } static void -address_suggest_cb (void *cls, - const struct - GNUNET_PeerIdentity * - peer, - const char *plugin_name, - const void *plugin_addr, - size_t plugin_addr_len, - struct Session * session, - struct - GNUNET_BANDWIDTH_Value32NBO - bandwidth_out, - struct - GNUNET_BANDWIDTH_Value32NBO - bandwidth_in, - const struct - GNUNET_ATS_Information - * ats, +address_suggest_cb (void *cls, const struct GNUNET_PeerIdentity *peer, + const char *plugin_name, const void *plugin_addr, + size_t plugin_addr_len, struct Session *session, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS suggested address for peer `%s'\n", GNUNET_i2s (peer)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS suggested address for peer `%s'\n", + GNUNET_i2s (peer)); bw_in = ntohl (bandwidth_in.value__); bw_out = ntohl (bandwidth_out.value__); - consume_task = GNUNET_SCHEDULER_add_now(&consume_bandwidth, NULL); + consume_task = GNUNET_SCHEDULER_add_now (&consume_bandwidth, NULL); } void start_arm (const char *cfgname) { - arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", - "gnunet-service-arm", + arm_proc = + GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + "gnunet-service-arm", #if VERBOSE_ARM - "-L", "DEBUG", + "-L", "DEBUG", #endif - "-c", cfgname, NULL); + "-c", cfgname, NULL); } static void @@ -238,7 +214,7 @@ check (void *cls, char *const *args, const char *cfgfile, ret = GNUNET_SYSERR; struct Address *addr; - die_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_badly, NULL); + die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); start_arm (cfgfile); ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); @@ -257,25 +233,28 @@ check (void *cls, char *const *args, const char *cfgfile, { ret = GNUNET_SYSERR; GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to init ATS performance\n"); - end_badly(NULL, NULL); + end_badly (NULL, NULL); GNUNET_free (p); GNUNET_free (addr); return; } /* set up peer */ - GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p->id.hashPubKey); + GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, + &p->id.hashPubKey); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", GNUNET_i2s (&p->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", + GNUNET_i2s (&p->id)); p->addr = addr; addr->plugin = "test"; addr->session = NULL; addr->addr = NULL; addr->addr_len = 0; - GNUNET_ATS_address_update(ats, &p->id, addr->plugin, addr->addr, addr->addr_len, addr->session, NULL, 0); + GNUNET_ATS_address_update (ats, &p->id, addr->plugin, addr->addr, + addr->addr_len, addr->session, NULL, 0); - GNUNET_ATS_suggest_address(ats, &p->id); + GNUNET_ATS_suggest_address (ats, &p->id); } int @@ -297,8 +276,8 @@ main (int argc, char *argv[]) }; GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, - "test_ats_api_bandwidth_consumption", "nohelp", options, &check, - NULL); + "test_ats_api_bandwidth_consumption", "nohelp", options, + &check, NULL); return ret; diff --git a/src/ats/test_ats_api_scheduling.c b/src/ats/test_ats_api_scheduling.c index 201855283..a2ee7f060 100644 --- a/src/ats/test_ats_api_scheduling.c +++ b/src/ats/test_ats_api_scheduling.c @@ -44,7 +44,7 @@ static GNUNET_SCHEDULER_TaskIdentifier die_task; static struct GNUNET_ATS_SchedulingHandle *ats; -struct GNUNET_OS_Process * arm_proc; +struct GNUNET_OS_Process *arm_proc; @@ -52,23 +52,23 @@ static int ret; struct Address { - char * plugin; + char *plugin; size_t plugin_len; - void * addr; + void *addr; size_t addr_len; - struct GNUNET_ATS_Information * ats; + struct GNUNET_ATS_Information *ats; int ats_count; - void *session; + void *session; }; struct PeerContext { struct GNUNET_PeerIdentity id; - struct Address * addr; + struct Address *addr; }; struct Address addr[2]; @@ -105,7 +105,7 @@ end () GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); if (die_task != GNUNET_SCHEDULER_NO_TASK) { - GNUNET_SCHEDULER_cancel(die_task); + GNUNET_SCHEDULER_cancel (die_task); die_task = GNUNET_SCHEDULER_NO_TASK; } @@ -118,29 +118,19 @@ end () static void -address_suggest_cb (void *cls, - const struct - GNUNET_PeerIdentity * - peer, - const char *plugin_name, - const void *plugin_addr, - size_t plugin_addr_len, - struct Session * session, - struct - GNUNET_BANDWIDTH_Value32NBO - bandwidth_out, - struct - GNUNET_BANDWIDTH_Value32NBO - bandwidth_in, - const struct - GNUNET_ATS_Information - * ats, +address_suggest_cb (void *cls, const struct GNUNET_PeerIdentity *peer, + const char *plugin_name, const void *plugin_addr, + size_t plugin_addr_len, struct Session *session, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS suggests address `%s'\n", GNUNET_i2s (peer)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS suggests address `%s'\n", + GNUNET_i2s (peer)); - GNUNET_assert (0 == memcmp (peer, &p[0].id, sizeof (struct GNUNET_PeerIdentity))); + GNUNET_assert (0 == + memcmp (peer, &p[0].id, sizeof (struct GNUNET_PeerIdentity))); GNUNET_assert (0 == strcmp (plugin_name, addr[0].plugin)); GNUNET_assert (plugin_addr_len == addr[0].addr_len); GNUNET_assert (0 == memcmp (plugin_addr, addr[0].plugin, plugin_addr_len)); @@ -148,27 +138,28 @@ address_suggest_cb (void *cls, /* TODO ats merge - GNUNET_assert (ats_count == 2); - GNUNET_assert (atsi[0].type == htons (1)); - GNUNET_assert (atsi[0].type == htons (2)); - GNUNET_assert (atsi[1].type == htons (2)); - GNUNET_assert (atsi[1].type == htons (2)); - */ + * GNUNET_assert (ats_count == 2); + * GNUNET_assert (atsi[0].type == htons (1)); + * GNUNET_assert (atsi[0].type == htons (2)); + * GNUNET_assert (atsi[1].type == htons (2)); + * GNUNET_assert (atsi[1].type == htons (2)); + */ ret = 0; - GNUNET_SCHEDULER_add_now(&end, NULL); + GNUNET_SCHEDULER_add_now (&end, NULL); } void start_arm (const char *cfgname) { - arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", - "gnunet-service-arm", + arm_proc = + GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + "gnunet-service-arm", #if VERBOSE_ARM - "-L", "DEBUG", + "-L", "DEBUG", #endif - "-c", cfgname, NULL); + "-c", cfgname, NULL); } static void @@ -177,7 +168,7 @@ check (void *cls, char *const *args, const char *cfgfile, { ret = GNUNET_SYSERR; - die_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_badly, NULL); + die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); start_arm (cfgfile); ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); @@ -190,27 +181,33 @@ check (void *cls, char *const *args, const char *cfgfile, } /* set up peer */ - GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p[0].id.hashPubKey); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", GNUNET_i2s (&p[0].id)); + GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, + &p[0].id.hashPubKey); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", + GNUNET_i2s (&p[0].id)); - GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p[1].id.hashPubKey); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", GNUNET_i2s (&p[1].id)); + GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, + &p[1].id.hashPubKey); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", + GNUNET_i2s (&p[1].id)); addr[0].plugin = "test"; addr[0].session = NULL; - addr[0].addr = strdup("test"); + addr[0].addr = strdup ("test"); addr[0].addr_len = 4; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing address creation\n"); - GNUNET_ATS_address_update(ats, &p[0].id, addr[0].plugin, addr[0].addr, addr[0].addr_len, addr[0].session, NULL, 0); + GNUNET_ATS_address_update (ats, &p[0].id, addr[0].plugin, addr[0].addr, + addr[0].addr_len, addr[0].session, NULL, 0); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing ATS info creation\n"); atsi[0].type = htonl (GNUNET_ATS_UTILIZATION_UP); atsi[0].value = htonl (1024); - GNUNET_ATS_address_update(ats, &p[0].id, addr[0].plugin, addr[0].addr, addr[0].addr_len, addr[0].session, atsi, 1); + GNUNET_ATS_address_update (ats, &p[0].id, addr[0].plugin, addr[0].addr, + addr[0].addr_len, addr[0].session, atsi, 1); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing ATS info update\n"); @@ -220,14 +217,18 @@ check (void *cls, char *const *args, const char *cfgfile, atsi[1].type = htonl (GNUNET_ATS_UTILIZATION_DOWN); atsi[1].value = htonl (1024); - GNUNET_ATS_address_update(ats, &p[0].id, addr[0].plugin, addr[0].addr, addr[0].addr_len, addr[0].session, atsi, 2); + GNUNET_ATS_address_update (ats, &p[0].id, addr[0].plugin, addr[0].addr, + addr[0].addr_len, addr[0].session, atsi, 2); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing manual address deletion \n"); - GNUNET_ATS_address_update(ats, &p[1].id, addr[0].plugin, addr[0].addr, addr[0].addr_len, addr[0].session, NULL, 0); - GNUNET_ATS_address_destroyed (ats, &p[1].id, addr[0].plugin, addr[0].addr, addr[0].addr_len, addr[0].session ); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requesting peer `%s'\n", GNUNET_i2s (&p[0].id)); - GNUNET_ATS_suggest_address(ats, &p[0].id); + GNUNET_ATS_address_update (ats, &p[1].id, addr[0].plugin, addr[0].addr, + addr[0].addr_len, addr[0].session, NULL, 0); + GNUNET_ATS_address_destroyed (ats, &p[1].id, addr[0].plugin, addr[0].addr, + addr[0].addr_len, addr[0].session); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requesting peer `%s'\n", + GNUNET_i2s (&p[0].id)); + GNUNET_ATS_suggest_address (ats, &p[0].id); } int diff --git a/src/ats/test_ats_api_update_address.c b/src/ats/test_ats_api_update_address.c index 78011d492..f23747962 100644 --- a/src/ats/test_ats_api_update_address.c +++ b/src/ats/test_ats_api_update_address.c @@ -121,8 +121,7 @@ suggest_cb (void *cls, const struct GNUNET_PeerIdentity *peer, const char *plugin_name, const void *plugin_addr, size_t plugin_addr_len, struct Session *session, struct GNUNET_BANDWIDTH_Value32NBO bandwidth, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { struct ExpectedValues *ex = cls; diff --git a/src/block/block.c b/src/block/block.c index 582c13eb3..7c447f072 100644 --- a/src/block/block.c +++ b/src/block/block.c @@ -96,17 +96,14 @@ GNUNET_BLOCK_mingle_hash (const GNUNET_HashCode * in, uint32_t mingle_number, * @param lib_ret the plugin API */ static void -add_plugin (void *cls, - const char *library_name, - void *lib_ret) +add_plugin (void *cls, const char *library_name, void *lib_ret) { struct GNUNET_BLOCK_Context *ctx = cls; struct GNUNET_BLOCK_PluginFunctions *api = lib_ret; struct Plugin *plugin; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Loading block plugin `%s'\n"), - library_name); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading block plugin `%s'\n"), + library_name); plugin = GNUNET_malloc (sizeof (struct Plugin)); plugin->api = api; plugin->library_name = GNUNET_strdup (library_name); @@ -128,10 +125,7 @@ GNUNET_BLOCK_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg) ctx = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_Context)); ctx->cfg = cfg; - GNUNET_PLUGIN_load_all ("libgnunet_plugin_block_", - NULL, - &add_plugin, - ctx); + GNUNET_PLUGIN_load_all ("libgnunet_plugin_block_", NULL, &add_plugin, ctx); return ctx; } @@ -147,7 +141,7 @@ GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx) unsigned int i; struct Plugin *plugin; - for (i = 0; inum_plugins;i++) + for (i = 0; i < ctx->num_plugins; i++) { plugin = ctx->plugins[i]; GNUNET_break (NULL == @@ -174,7 +168,7 @@ find_plugin (struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type) unsigned int i; unsigned int j; - for (i=0;inum_plugins;i++) + for (i = 0; i < ctx->num_plugins; i++) { plugin = ctx->plugins[i]; j = 0; @@ -291,8 +285,8 @@ compute_bloomfilter_size (unsigned int entry_count) */ struct GNUNET_CONTAINER_BloomFilter * GNUNET_BLOCK_construct_bloomfilter (int32_t bf_mutator, - const GNUNET_HashCode *seen_results, - unsigned int seen_results_count) + const GNUNET_HashCode * seen_results, + unsigned int seen_results_count) { struct GNUNET_CONTAINER_BloomFilter *bf; GNUNET_HashCode mhash; @@ -300,7 +294,8 @@ GNUNET_BLOCK_construct_bloomfilter (int32_t bf_mutator, size_t nsize; nsize = compute_bloomfilter_size (seen_results_count); - bf = GNUNET_CONTAINER_bloomfilter_init (NULL, nsize, GNUNET_CONSTANTS_BLOOMFILTER_K); + bf = GNUNET_CONTAINER_bloomfilter_init (NULL, nsize, + GNUNET_CONSTANTS_BLOOMFILTER_K); for (i = 0; i < seen_results_count; i++) { GNUNET_BLOCK_mingle_hash (&seen_results[i], bf_mutator, &mhash); diff --git a/src/block/plugin_block_dht.c b/src/block/plugin_block_dht.c index c58615b72..f574e6d06 100644 --- a/src/block/plugin_block_dht.c +++ b/src/block/plugin_block_dht.c @@ -77,19 +77,21 @@ block_plugin_dht_evaluate (void *cls, enum GNUNET_BLOCK_Type type, if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid)) return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; if (NULL != bf) + { + GNUNET_BLOCK_mingle_hash (&pid.hashPubKey, bf_mutator, &mhash); + if (NULL != *bf) + { + if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash)) + return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; + } + else { - GNUNET_BLOCK_mingle_hash (&pid.hashPubKey, bf_mutator, &mhash); - if (NULL != *bf) - { - if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash)) - return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; - } - else - { - *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, GNUNET_CONSTANTS_BLOOMFILTER_K); - } - GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash); + *bf = + GNUNET_CONTAINER_bloomfilter_init (NULL, 8, + GNUNET_CONSTANTS_BLOOMFILTER_K); } + GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash); + } return GNUNET_BLOCK_EVALUATION_OK_MORE; } diff --git a/src/block/plugin_block_dns.c b/src/block/plugin_block_dns.c index 8e8aa3047..b33b3798a 100644 --- a/src/block/plugin_block_dns.c +++ b/src/block/plugin_block_dns.c @@ -86,7 +86,8 @@ block_plugin_dns_evaluate (void *cls, enum GNUNET_BLOCK_Type type, } if (GNUNET_TIME_relative_get_zero ().rel_value == - GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (rec->expiration_time)).rel_value) + GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh + (rec->expiration_time)).rel_value) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DNS-Block is invalid: Timeout\n"); return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; diff --git a/src/block/plugin_block_fs.c b/src/block/plugin_block_fs.c index 5a0e90a92..c1b4ad7c8 100644 --- a/src/block/plugin_block_fs.c +++ b/src/block/plugin_block_fs.c @@ -91,20 +91,20 @@ block_plugin_fs_evaluate (void *cls, enum GNUNET_BLOCK_Type type, if (reply_block == NULL) return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; if (NULL != bf) + { + GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash); + GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash); + if (NULL != *bf) + { + if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash)) + return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; + } + else { - GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash); - GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash); - if (NULL != *bf) - { - if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash)) - return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; - } - else - { - *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K); - } - GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash); + *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K); } + GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash); + } return GNUNET_BLOCK_EVALUATION_OK_MORE; case GNUNET_BLOCK_TYPE_FS_SBLOCK: if (xquery_size != sizeof (GNUNET_HashCode)) @@ -132,20 +132,20 @@ block_plugin_fs_evaluate (void *cls, enum GNUNET_BLOCK_Type type, return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; } if (NULL != bf) + { + GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash); + GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash); + if (NULL != *bf) + { + if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash)) + return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; + } + else { - GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash); - GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash); - if (NULL != *bf) - { - if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash)) - return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; - } - else - { - *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K); - } - GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash); + *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K); } + GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash); + } return GNUNET_BLOCK_EVALUATION_OK_MORE; default: return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; diff --git a/src/block/plugin_block_test.c b/src/block/plugin_block_test.c index 0c769b837..08d3096dc 100644 --- a/src/block/plugin_block_test.c +++ b/src/block/plugin_block_test.c @@ -75,14 +75,14 @@ block_plugin_test_evaluate (void *cls, enum GNUNET_BLOCK_Type type, GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash); GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash); if (NULL != *bf) - { - if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash)) - return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; - } + { + if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash)) + return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; + } else - { - *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K); - } + { + *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K); + } GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash); } return GNUNET_BLOCK_EVALUATION_OK_MORE; diff --git a/src/chat/gnunet-service-chat.c b/src/chat/gnunet-service-chat.c index a3637e454..fb127b2f0 100644 --- a/src/chat/gnunet-service-chat.c +++ b/src/chat/gnunet-service-chat.c @@ -989,9 +989,8 @@ static int handle_p2p_join_notification (void *cls, const struct GNUNET_PeerIdentity *other, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information - *atsi, - unsigned int atsi_count) + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { const struct P2PJoinNotificationMessage *p2p_jnmsg; char *room_name; @@ -1107,9 +1106,8 @@ static int handle_p2p_leave_notification (void *cls, const struct GNUNET_PeerIdentity *other, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information - *atsi, - unsigned int atsi_count) + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { const struct P2PLeaveNotificationMessage *p2p_lnmsg; GNUNET_HashCode id; @@ -1190,9 +1188,8 @@ static int handle_p2p_message_notification (void *cls, const struct GNUNET_PeerIdentity *other, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information - *atsi, - unsigned int atsi_count) + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { const struct P2PReceiveNotificationMessage *p2p_rnmsg; struct P2PReceiveNotificationMessage *my_p2p_rnmsg; @@ -1343,7 +1340,7 @@ static int handle_p2p_sync_request (void *cls, const struct GNUNET_PeerIdentity *other, const struct GNUNET_MessageHeader *message, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { struct ChatClient *entry; struct GNUNET_CORE_TransmitHandle *th; @@ -1386,9 +1383,8 @@ static int handle_p2p_confirmation_receipt (void *cls, const struct GNUNET_PeerIdentity *other, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information - *atsi, - unsigned int atsi_count) + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { const struct P2PConfirmationReceiptMessage *p2p_crmsg; struct P2PConfirmationReceiptMessage *my_p2p_crmsg; @@ -1530,7 +1526,7 @@ transmit_sync_request_to_peer (void *cls, size_t size, void *buf) static void peer_connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { struct ConnectedPeer *cp; struct GNUNET_CORE_TransmitHandle *th; @@ -1716,8 +1712,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, core = GNUNET_CORE_connect (cfg, QUEUE_SIZE, NULL, &core_init, &peer_connect_handler, &peer_disconnect_handler, - NULL, GNUNET_NO, NULL, GNUNET_NO, - p2p_handlers); + NULL, GNUNET_NO, NULL, GNUNET_NO, p2p_handlers); GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task, NULL); diff --git a/src/core/core_api.c b/src/core/core_api.c index 57c2932a2..f3f4cea54 100644 --- a/src/core/core_api.c +++ b/src/core/core_api.c @@ -781,7 +781,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) const struct GNUNET_MessageHeader *em; const struct SendMessageReady *smr; const struct GNUNET_CORE_MessageHandler *mh; - const struct GNUNET_ATS_Information* ats; + const struct GNUNET_ATS_Information *ats; GNUNET_CORE_StartupCallback init; struct PeerRecord *pr; struct GNUNET_CORE_TransmitHandle *th; @@ -864,8 +864,8 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) cnm = (const struct ConnectNotifyMessage *) msg; ats_count = ntohl (cnm->ats_count); if (msize != - sizeof (struct ConnectNotifyMessage) + - ats_count * sizeof (struct GNUNET_ATS_Information)) + sizeof (struct ConnectNotifyMessage) + + ats_count * sizeof (struct GNUNET_ATS_Information)) { GNUNET_break (0); reconnect_later (h); @@ -896,11 +896,9 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) GNUNET_CONTAINER_multihashmap_put (h->peers, &cnm->peer.hashPubKey, pr, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); - ats = (const struct GNUNET_ATS_Information*) &cnm[1]; + ats = (const struct GNUNET_ATS_Information *) &cnm[1]; if (NULL != h->connects) - h->connects (h->cls, &cnm->peer, - ats, - ats_count); + h->connects (h->cls, &cnm->peer, ats, ats_count); break; case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT: if (msize != sizeof (struct DisconnectNotifyMessage)) @@ -949,8 +947,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) sizeof (struct NotifyTrafficMessage) + ats_count * sizeof (struct GNUNET_ATS_Information) + sizeof (struct GNUNET_MessageHeader)) || - (GNUNET_ATS_ARRAY_TERMINATOR != - ntohl ((&ntm->ats)[ats_count].type))) + (GNUNET_ATS_ARRAY_TERMINATOR != ntohl ((&ntm->ats)[ats_count].type))) { GNUNET_break (0); reconnect_later (h); @@ -986,23 +983,22 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) continue; if ((mh->expected_size != ntohs (em->size)) && (mh->expected_size != 0)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unexpected message size for message of type %u\n", - mh->type); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unexpected message size for message of type %u\n", + mh->type); GNUNET_break_op (0); continue; } if (GNUNET_OK != h->handlers[hpos].callback (h->cls, &ntm->peer, em, &ntm->ats, - ats_count)) + ats_count)) { /* error in processing, do not process other messages! */ break; } } if (NULL != h->inbound_notify) - h->inbound_notify (h->cls, &ntm->peer, em, &ntm->ats, - ats_count); + h->inbound_notify (h->cls, &ntm->peer, em, &ntm->ats, ats_count); break; case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND: if (msize < sizeof (struct NotifyTrafficMessage)) @@ -1023,8 +1019,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) sizeof (struct NotifyTrafficMessage) + ats_count * sizeof (struct GNUNET_ATS_Information) + sizeof (struct GNUNET_MessageHeader)) || - (GNUNET_ATS_ARRAY_TERMINATOR != - ntohl ((&ntm->ats)[ats_count].type))) + (GNUNET_ATS_ARRAY_TERMINATOR != ntohl ((&ntm->ats)[ats_count].type))) { GNUNET_break (0); reconnect_later (h); diff --git a/src/core/core_api_iterate_peers.c b/src/core/core_api_iterate_peers.c index 7bf40a678..7b28842fd 100644 --- a/src/core/core_api_iterate_peers.c +++ b/src/core/core_api_iterate_peers.c @@ -101,7 +101,7 @@ receive_info (void *cls, const struct GNUNET_MessageHeader *msg) ats_count = ntohl (connect_message->ats_count); if (msize != sizeof (struct ConnectNotifyMessage) + - ats_count * sizeof (struct GNUNET_ATS_Information)) + ats_count * sizeof (struct GNUNET_ATS_Information)) { GNUNET_break (0); if (request_context->peer_cb != NULL) @@ -113,8 +113,8 @@ receive_info (void *cls, const struct GNUNET_MessageHeader *msg) /* Normal case */ if (request_context->peer_cb != NULL) request_context->peer_cb (request_context->cb_cls, &connect_message->peer, - (const struct GNUNET_ATS_Information *) &connect_message[1], - ats_count); + (const struct GNUNET_ATS_Information *) + &connect_message[1], ats_count); GNUNET_CLIENT_receive (request_context->client, &receive_info, request_context, GNUNET_TIME_UNIT_FOREVER_REL); } diff --git a/src/core/gnunet-core-list-connections.c b/src/core/gnunet-core-list-connections.c index 9665110a3..79490bcc5 100644 --- a/src/core/gnunet-core-list-connections.c +++ b/src/core/gnunet-core-list-connections.c @@ -124,7 +124,7 @@ process_resolved_address (void *cls, const char *address) static void connected_peer_callback (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { struct PrintContext *pc; diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c index 5bec671ec..2eb71c257 100644 --- a/src/core/gnunet-service-core.c +++ b/src/core/gnunet-service-core.c @@ -57,8 +57,7 @@ static void cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { #if DEBUG_CORE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Core service shutting down.\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core service shutting down.\n"); #endif GSC_CLIENTS_done (); GSC_NEIGHBOURS_done (); @@ -85,13 +84,12 @@ static void run (void *cls, struct GNUNET_SERVER_Handle *server, const struct GNUNET_CONFIGURATION_Handle *c) { - GSC_cfg = c; + GSC_cfg = c; GSC_stats = GNUNET_STATISTICS_create ("core", GSC_cfg); GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task, NULL); GSC_TYPEMAP_init (); - if ( (GNUNET_OK != GSC_KX_init ()) || - (GNUNET_OK != GSC_NEIGHBOURS_init ()) ) + if ((GNUNET_OK != GSC_KX_init ()) || (GNUNET_OK != GSC_NEIGHBOURS_init ())) { GNUNET_SCHEDULER_shutdown (); return; diff --git a/src/core/gnunet-service-core.h b/src/core/gnunet-service-core.h index d4e43a457..e48ad8bad 100644 --- a/src/core/gnunet-service-core.h +++ b/src/core/gnunet-service-core.h @@ -37,7 +37,7 @@ struct GSC_Client; /** * Record kept for each request for transmission issued by a - * client that is still pending. (This struct is used by + * client that is still pending. (This struct is used by * both the 'CLIENTS' and 'SESSIONS' subsystems.) */ struct GSC_ClientActiveRequest diff --git a/src/core/gnunet-service-core_clients.c b/src/core/gnunet-service-core_clients.c index 22201514a..3201b71f0 100644 --- a/src/core/gnunet-service-core_clients.c +++ b/src/core/gnunet-service-core_clients.c @@ -146,9 +146,8 @@ find_client (struct GNUNET_SERVER_Client *client) * client's queue is getting too large? */ static void -send_to_client (struct GSC_Client *client, - const struct GNUNET_MessageHeader *msg, - int can_drop) +send_to_client (struct GSC_Client *client, + const struct GNUNET_MessageHeader *msg, int can_drop) { #if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -171,8 +170,8 @@ send_to_client (struct GSC_Client *client, */ void GSC_CLIENTS_send_to_client (struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *msg, - int can_drop) + const struct GNUNET_MessageHeader *msg, + int can_drop) { struct GSC_Client *c; @@ -194,14 +193,13 @@ GSC_CLIENTS_send_to_client (struct GNUNET_SERVER_Client *client, * @return GNUNET_YES if 'c' is interested, GNUNET_NO if not. */ static int -type_match (uint16_t type, - struct GSC_Client *c) +type_match (uint16_t type, struct GSC_Client *c) { unsigned int i; if (c->tcnt == 0) - return GNUNET_YES; /* peer without handlers matches ALL */ - for (i=0;itcnt;i++) + return GNUNET_YES; /* peer without handlers matches ALL */ + for (i = 0; i < c->tcnt; i++) if (type == c->types[i]) return GNUNET_YES; return GNUNET_NO; @@ -219,30 +217,27 @@ type_match (uint16_t type, */ static void send_to_all_clients (const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_MessageHeader *msg, - int can_drop, - int options, - uint16_t type) + const struct GNUNET_MessageHeader *msg, int can_drop, + int options, uint16_t type) { struct GSC_Client *c; for (c = client_head; c != NULL; c = c->next) { - if ( (0 == (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) && - (GNUNET_YES == type_match (type, c)) ) - continue; /* not the full message, but we'd like the full one! */ - if ( (0 == (c->options & options)) && - (GNUNET_YES != type_match (type, c)) ) - continue; /* neither options nor type match permit the message */ + if ((0 == (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) && + (GNUNET_YES == type_match (type, c))) + continue; /* not the full message, but we'd like the full one! */ + if ((0 == (c->options & options)) && (GNUNET_YES != type_match (type, c))) + continue; /* neither options nor type match permit the message */ #if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending message to client interested in messages of type %u.\n", - (unsigned int) type); + "Sending message to client interested in messages of type %u.\n", + (unsigned int) type); #endif #if DEBUG_CONNECTS GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_contains (c->connectmap, - &sender->hashPubKey)); + GNUNET_CONTAINER_multihashmap_contains (c->connectmap, + &sender->hashPubKey)); #endif send_to_client (c, msg, can_drop); } @@ -295,22 +290,20 @@ handle_client_init (void *cls, struct GNUNET_SERVER_Client *client, #if DEBUG_CONNECTS c->connectmap = GNUNET_CONTAINER_multihashmap_create (16); GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_put (c->connectmap, - &GSC_my_identity.hashPubKey, - NULL, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + GNUNET_CONTAINER_multihashmap_put (c->connectmap, + &GSC_my_identity.hashPubKey, + NULL, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); #endif wtypes = (uint16_t *) & c[1]; for (i = 0; i < c->tcnt; i++) wtypes[i] = ntohs (types[i]); GSC_TYPEMAP_add (wtypes, c->tcnt); - GNUNET_CONTAINER_DLL_insert (client_head, - client_tail, - c); + GNUNET_CONTAINER_DLL_insert (client_head, client_tail, c); #if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client connecting to core service is interested in %u message types\n", + "Client connecting to core service is interested in %u message types\n", (unsigned int) c->tcnt); #endif /* send init reply message */ @@ -352,8 +345,8 @@ handle_client_send_request (void *cls, struct GNUNET_SERVER_Client *client, c->requests = GNUNET_CONTAINER_multihashmap_create (16); #if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client asked for transmission to `%s'\n", - GNUNET_i2s (&req->peer)); + "Client asked for transmission to `%s'\n", + GNUNET_i2s (&req->peer)); #endif car = GNUNET_CONTAINER_multihashmap_get (c->requests, &req->peer.hashPubKey); if (car == NULL) @@ -378,7 +371,8 @@ handle_client_send_request (void *cls, struct GNUNET_SERVER_Client *client, car->smr_id = req->smr_id; car->was_solicited = GNUNET_NO; if (0 == - memcmp (&req->peer, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity))) + memcmp (&req->peer, &GSC_my_identity, + sizeof (struct GNUNET_PeerIdentity))) GSC_CLIENTS_solicit_request (car); else GSC_SESSIONS_queue_request (car); @@ -394,7 +388,7 @@ struct TokenizerContext /** * Active request handle for the message. - */ + */ struct GSC_ClientActiveRequest *car; /** @@ -440,42 +434,39 @@ handle_client_send (void *cls, struct GNUNET_SERVER_Client *client, GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } - tc.car = GNUNET_CONTAINER_multihashmap_get (c->requests, &sm->peer.hashPubKey); + tc.car = + GNUNET_CONTAINER_multihashmap_get (c->requests, &sm->peer.hashPubKey); if (NULL == tc.car) { /* Must have been that we first approved the request, then got disconnected - (which triggered removal of the 'car') and now the client gives us a message - just *before* the client learns about the disconnect. Theoretically, we - might also now be *again* connected. So this can happen (but should be - rare). If it does happen, the message is discarded. */ - GNUNET_STATISTICS_update (GSC_stats, - gettext_noop ("# messages discarded (session disconnected)"), - 1, - GNUNET_NO); + * (which triggered removal of the 'car') and now the client gives us a message + * just *before* the client learns about the disconnect. Theoretically, we + * might also now be *again* connected. So this can happen (but should be + * rare). If it does happen, the message is discarded. */ + GNUNET_STATISTICS_update (GSC_stats, + gettext_noop + ("# messages discarded (session disconnected)"), + 1, GNUNET_NO); GNUNET_SERVER_receive_done (client, GNUNET_OK); return; } GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (c->requests, - &sm->peer.hashPubKey, - tc.car)); + GNUNET_CONTAINER_multihashmap_remove (c->requests, + &sm->peer.hashPubKey, + tc.car)); tc.cork = ntohl (sm->cork); #if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client asked for transmission of %u bytes to `%s' %s\n", - msize, - GNUNET_i2s (&sm->peer), - tc.cork ? "now" : ""); + "Client asked for transmission of %u bytes to `%s' %s\n", msize, + GNUNET_i2s (&sm->peer), tc.cork ? "now" : ""); #endif - GNUNET_SERVER_mst_receive (client_mst, - &tc, - (const char*) &sm[1], msize, - GNUNET_YES, - GNUNET_NO); + GNUNET_SERVER_mst_receive (client_mst, &tc, (const char *) &sm[1], msize, + GNUNET_YES, GNUNET_NO); if (0 != - memcmp (&tc.car->target, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity))) + memcmp (&tc.car->target, &GSC_my_identity, + sizeof (struct GNUNET_PeerIdentity))) GSC_SESSIONS_dequeue_request (tc.car); - GNUNET_free (tc.car); + GNUNET_free (tc.car); GNUNET_SERVER_receive_done (client, GNUNET_OK); } @@ -492,37 +483,35 @@ handle_client_send (void *cls, struct GNUNET_SERVER_Client *client, */ static void client_tokenizer_callback (void *cls, void *client, - const struct GNUNET_MessageHeader *message) + const struct GNUNET_MessageHeader *message) { struct TokenizerContext *tc = client; struct GSC_ClientActiveRequest *car = tc->car; if (0 == - memcmp (&car->target, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity))) + memcmp (&car->target, &GSC_my_identity, + sizeof (struct GNUNET_PeerIdentity))) { #if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Delivering message of type %u to myself\n", - ntohs (message->type)); + "Delivering message of type %u to myself\n", + ntohs (message->type)); #endif - GSC_CLIENTS_deliver_message (&GSC_my_identity, - NULL, 0, - message, - ntohs (message->size), - GNUNET_CORE_OPTION_SEND_FULL_INBOUND | GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND); - GSC_CLIENTS_deliver_message (&GSC_my_identity, - NULL, 0, - message, - sizeof (struct GNUNET_MessageHeader), - GNUNET_CORE_OPTION_SEND_HDR_INBOUND | GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND); + GSC_CLIENTS_deliver_message (&GSC_my_identity, NULL, 0, message, + ntohs (message->size), + GNUNET_CORE_OPTION_SEND_FULL_INBOUND | + GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND); + GSC_CLIENTS_deliver_message (&GSC_my_identity, NULL, 0, message, + sizeof (struct GNUNET_MessageHeader), + GNUNET_CORE_OPTION_SEND_HDR_INBOUND | + GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND); } else { #if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Delivering message of type %u to %s\n", - ntohs (message->type), - GNUNET_i2s (&car->target)); + "Delivering message of type %u to %s\n", ntohs (message->type), + GNUNET_i2s (&car->target)); #endif GSC_SESSIONS_transmit (car, message, tc->cork); } @@ -544,9 +533,10 @@ destroy_active_client_request (void *cls, const GNUNET_HashCode * key, struct GSC_ClientActiveRequest *car = value; GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (car->client_handle->requests, - &car->target.hashPubKey, - car)); + GNUNET_CONTAINER_multihashmap_remove (car-> + client_handle->requests, + &car->target.hashPubKey, + car)); GSC_SESSIONS_dequeue_request (car); GNUNET_free (car); return GNUNET_YES; @@ -560,8 +550,7 @@ destroy_active_client_request (void *cls, const GNUNET_HashCode * key, * @param client identification of the client */ static void -handle_client_disconnect (void *cls, - struct GNUNET_SERVER_Client *client) +handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) { struct GSC_Client *c; @@ -573,10 +562,8 @@ handle_client_disconnect (void *cls, #endif c = find_client (client); if (c == NULL) - return; /* client never sent INIT */ - GNUNET_CONTAINER_DLL_remove (client_head, - client_tail, - c); + return; /* client never sent INIT */ + GNUNET_CONTAINER_DLL_remove (client_head, client_tail, c); if (c->requests != NULL) { GNUNET_CONTAINER_multihashmap_iterate (c->requests, @@ -613,8 +600,9 @@ GSC_CLIENTS_solicit_request (struct GSC_ClientActiveRequest *car) smr.peer = car->target; #if DEBUG_CONNECTS GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_contains (c->connectmap, - &car->target.hashPubKey)); + GNUNET_CONTAINER_multihashmap_contains (c->connectmap, + &car-> + target.hashPubKey)); #endif send_to_client (c, &smr.header, GNUNET_NO); } @@ -632,9 +620,10 @@ void GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car) { GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (car->client_handle->requests, - &car->target.hashPubKey, - car)); + GNUNET_CONTAINER_multihashmap_remove (car-> + client_handle->requests, + &car->target.hashPubKey, + car)); GNUNET_free (car); } @@ -654,11 +643,12 @@ GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car) */ void GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client, - const struct GNUNET_PeerIdentity *neighbour, - const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count, - const struct GSC_TypeMap *tmap_old, - const struct GSC_TypeMap *tmap_new) + const struct GNUNET_PeerIdentity + *neighbour, + const struct GNUNET_ATS_Information + *atsi, unsigned int atsi_count, + const struct GSC_TypeMap *tmap_old, + const struct GSC_TypeMap *tmap_new) { struct ConnectNotifyMessage *cnm; size_t size; @@ -673,43 +663,41 @@ GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client, if (old_match == new_match) { GNUNET_assert (old_match == - GNUNET_CONTAINER_multihashmap_contains (client->connectmap, - &neighbour->hashPubKey)); - return; /* no change */ + GNUNET_CONTAINER_multihashmap_contains (client->connectmap, + &neighbour->hashPubKey)); + return; /* no change */ } if (old_match == GNUNET_NO) { - /* send connect */ + /* send connect */ #if DEBUG_CONNECTS GNUNET_assert (GNUNET_NO == - GNUNET_CONTAINER_multihashmap_contains (client->connectmap, - &neighbour->hashPubKey)); + GNUNET_CONTAINER_multihashmap_contains (client->connectmap, + &neighbour->hashPubKey)); GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_put (client->connectmap, - &neighbour->hashPubKey, - NULL, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + GNUNET_CONTAINER_multihashmap_put (client->connectmap, + &neighbour->hashPubKey, + NULL, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); #endif size = - sizeof (struct ConnectNotifyMessage) + - (atsi_count) * sizeof (struct GNUNET_ATS_Information); + sizeof (struct ConnectNotifyMessage) + + (atsi_count) * sizeof (struct GNUNET_ATS_Information); if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) - { - GNUNET_break (0); - /* recovery strategy: throw away performance data */ - atsi_count = 0; - size = sizeof (struct ConnectNotifyMessage); - } + { + GNUNET_break (0); + /* recovery strategy: throw away performance data */ + atsi_count = 0; + size = sizeof (struct ConnectNotifyMessage); + } cnm = (struct ConnectNotifyMessage *) buf; cnm->header.size = htons (size); cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT); cnm->ats_count = htonl (atsi_count); - a = (struct GNUNET_ATS_Information* ) &cnm[1]; - memcpy (a, atsi, - sizeof (struct GNUNET_ATS_Information) * atsi_count); + a = (struct GNUNET_ATS_Information *) &cnm[1]; + memcpy (a, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count); #if DEBUG_CORE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending `%s' message to client.\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message to client.\n", "NOTIFY_CONNECT"); #endif cnm->peer = *neighbour; @@ -720,12 +708,12 @@ GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client, /* send disconnect */ #if DEBUG_CONNECTS GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_contains (client->connectmap, - &neighbour->hashPubKey)); + GNUNET_CONTAINER_multihashmap_contains (client->connectmap, + &neighbour->hashPubKey)); GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (client->connectmap, - &neighbour->hashPubKey, - NULL)); + GNUNET_CONTAINER_multihashmap_remove (client->connectmap, + &neighbour->hashPubKey, + NULL)); #endif dcm.header.size = htons (sizeof (struct DisconnectNotifyMessage)); dcm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT); @@ -748,27 +736,27 @@ GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client, * @param tmap_new updated type map for the neighbour, NULL for disconnect */ void -GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity *neighbour, - const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count, - const struct GSC_TypeMap *tmap_old, - const struct GSC_TypeMap *tmap_new) +GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity + *neighbour, + const struct GNUNET_ATS_Information + *atsi, unsigned int atsi_count, + const struct GSC_TypeMap *tmap_old, + const struct GSC_TypeMap *tmap_new) { struct GSC_Client *c; for (c = client_head; c != NULL; c = c->next) - GSC_CLIENTS_notify_client_about_neighbour (c, neighbour, atsi, - atsi_count, - tmap_old, tmap_new); + GSC_CLIENTS_notify_client_about_neighbour (c, neighbour, atsi, atsi_count, + tmap_old, tmap_new); } /** * Deliver P2P message to interested clients. Caller must have checked - * that the sending peer actually lists the given message type as one + * that the sending peer actually lists the given message type as one * of its types. * - * @param sender peer who sent us the message + * @param sender peer who sent us the message * @param atsi performance information about neighbour * @param atsi_count number of entries in 'ats' array * @param msg the message @@ -778,13 +766,13 @@ GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity *ne */ void GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count, - const struct GNUNET_MessageHeader *msg, - uint16_t msize, - int options) + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count, + const struct GNUNET_MessageHeader *msg, + uint16_t msize, int options) { - size_t size = msize + sizeof (struct NotifyTrafficMessage) + + size_t size = + msize + sizeof (struct NotifyTrafficMessage) + atsi_count * sizeof (struct GNUNET_ATS_Information); char buf[size]; struct NotifyTrafficMessage *ntm; @@ -793,8 +781,8 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender, if (0 == options) { GNUNET_snprintf (buf, sizeof (buf), - gettext_noop ("# bytes of messages of type %u received"), - (unsigned int) ntohs (msg->type)); + gettext_noop ("# bytes of messages of type %u received"), + (unsigned int) ntohs (msg->type)); GNUNET_STATISTICS_update (GSC_stats, buf, msize, GNUNET_NO); } if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) @@ -807,8 +795,7 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender, #if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core service passes message from `%4s' of type %u to client.\n", - GNUNET_i2s (sender), - (unsigned int) ntohs (msg->type)); + GNUNET_i2s (sender), (unsigned int) ntohs (msg->type)); #endif GSC_SESSIONS_add_to_typemap (sender, ntohs (msg->type)); ntm = (struct NotifyTrafficMessage *) buf; @@ -817,14 +804,12 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender, ntm->ats_count = htonl (atsi_count); ntm->peer = *sender; a = &ntm->ats; - memcpy (a, atsi, - sizeof (struct GNUNET_ATS_Information) * atsi_count); + memcpy (a, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count); a[atsi_count].type = htonl (GNUNET_ATS_ARRAY_TERMINATOR); a[atsi_count].value = htonl (0); memcpy (&a[atsi_count + 1], msg, msize); - send_to_all_clients (sender, - &ntm->header, GNUNET_YES, - options, ntohs (msg->type)); + send_to_all_clients (sender, &ntm->header, GNUNET_YES, options, + ntohs (msg->type)); } @@ -871,7 +856,7 @@ GSC_CLIENTS_done () { struct GSC_Client *c; - while (NULL != (c = client_head)) + while (NULL != (c = client_head)) handle_client_disconnect (NULL, c->client_handle); if (NULL != notifier) { diff --git a/src/core/gnunet-service-core_clients.h b/src/core/gnunet-service-core_clients.h index 2385efc05..bdad20da8 100644 --- a/src/core/gnunet-service-core_clients.h +++ b/src/core/gnunet-service-core_clients.h @@ -41,8 +41,8 @@ */ void GSC_CLIENTS_send_to_client (struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *msg, - int can_drop); + const struct GNUNET_MessageHeader *msg, + int can_drop); /** @@ -59,11 +59,12 @@ GSC_CLIENTS_send_to_client (struct GNUNET_SERVER_Client *client, */ void GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client, - const struct GNUNET_PeerIdentity *neighbour, - const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count, - const struct GSC_TypeMap *tmap_old, - const struct GSC_TypeMap *tmap_new); + const struct GNUNET_PeerIdentity + *neighbour, + const struct GNUNET_ATS_Information + *atsi, unsigned int atsi_count, + const struct GSC_TypeMap *tmap_old, + const struct GSC_TypeMap *tmap_new); /** @@ -78,19 +79,20 @@ GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client, * @param tmap_new updated type map for the neighbour, NULL for disconnect */ void -GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity *neighbour, - const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count, - const struct GSC_TypeMap *tmap_old, - const struct GSC_TypeMap *tmap_new); +GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity + *neighbour, + const struct GNUNET_ATS_Information + *atsi, unsigned int atsi_count, + const struct GSC_TypeMap *tmap_old, + const struct GSC_TypeMap *tmap_new); /** * Deliver P2P message to interested clients. Caller must have checked - * that the sending peer actually lists the given message type as one + * that the sending peer actually lists the given message type as one * of its types. * - * @param sender peer who sent us the message + * @param sender peer who sent us the message * @param atsi performance information about neighbour * @param atsi_count number of entries in 'ats' array * @param msg the message @@ -100,11 +102,10 @@ GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity *ne */ void GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count, - const struct GNUNET_MessageHeader *msg, - uint16_t msize, - int options); + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count, + const struct GNUNET_MessageHeader *msg, + uint16_t msize, int options); /** diff --git a/src/core/gnunet-service-core_kx.c b/src/core/gnunet-service-core_kx.c index 7d27378ac..d49e06e2a 100644 --- a/src/core/gnunet-service-core_kx.c +++ b/src/core/gnunet-service-core_kx.c @@ -112,7 +112,7 @@ struct PongMessage * first field after header (this is where we start to encrypt!). */ uint32_t challenge GNUNET_PACKED; - + /** * Reserved, always 'GNUNET_BANDWIDTH_VALUE_MAX'. */ @@ -495,8 +495,8 @@ do_encrypt (struct GSC_KeyExchangeInfo *kx, "Encrypted %u bytes for `%4s' using key %u, IV %u\n", (unsigned int) size, GNUNET_i2s (&kx->peer), (unsigned int) kx->encrypt_key.crc32, GNUNET_CRYPTO_crc32_n (iv, - sizeof - (iv))); + sizeof + (iv))); #endif return GNUNET_OK; } @@ -526,14 +526,14 @@ do_decrypt (struct GSC_KeyExchangeInfo *kx, GNUNET_break (0); return GNUNET_NO; } - if ((kx->status != KX_STATE_KEY_RECEIVED) && - (kx->status != KX_STATE_UP)) + if ((kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP)) { GNUNET_break_op (0); return GNUNET_SYSERR; } if (size != - GNUNET_CRYPTO_aes_decrypt (in, (uint16_t) size, &kx->decrypt_key, iv, out)) + GNUNET_CRYPTO_aes_decrypt (in, (uint16_t) size, &kx->decrypt_key, iv, + out)) { GNUNET_break (0); return GNUNET_SYSERR; @@ -545,8 +545,8 @@ do_decrypt (struct GSC_KeyExchangeInfo *kx, "Decrypted %u bytes from `%4s' using key %u, IV %u\n", (unsigned int) size, GNUNET_i2s (&kx->peer), (unsigned int) kx->decrypt_key.crc32, GNUNET_CRYPTO_crc32_n (iv, - sizeof - (*iv))); + sizeof + (*iv))); #endif return GNUNET_OK; } @@ -573,7 +573,8 @@ set_key_retry_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) struct GSC_KeyExchangeInfo *kx = cls; kx->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; - kx->set_key_retry_frequency = GNUNET_TIME_relative_multiply (kx->set_key_retry_frequency, 2); + kx->set_key_retry_frequency = + GNUNET_TIME_relative_multiply (kx->set_key_retry_frequency, 2); send_key (kx); } @@ -590,8 +591,7 @@ set_key_retry_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) */ static void process_hello (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Message *hello, - const char *err_msg) + const struct GNUNET_HELLO_Message *hello, const char *err_msg) { struct GSC_KeyExchangeInfo *kx = cls; struct SetKeyMessage *skm; @@ -607,19 +607,19 @@ process_hello (void *cls, const struct GNUNET_PeerIdentity *peer, { kx->pitr = NULL; if (kx->public_key != NULL) - return; /* done here */ + return; /* done here */ #if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Failed to obtain public key for peer `%4s', delaying processing of SET_KEY\n", - GNUNET_i2s (&kx->peer)); + "Failed to obtain public key for peer `%4s', delaying processing of SET_KEY\n", + GNUNET_i2s (&kx->peer)); #endif GNUNET_STATISTICS_update (GSC_stats, - gettext_noop - ("# Delayed connecting due to lack of public key"), - 1, GNUNET_NO); + gettext_noop + ("# Delayed connecting due to lack of public key"), + 1, GNUNET_NO); kx->retry_set_key_task = - GNUNET_SCHEDULER_add_delayed (kx->set_key_retry_frequency, - &set_key_retry_task, kx); + GNUNET_SCHEDULER_add_delayed (kx->set_key_retry_frequency, + &set_key_retry_task, kx); return; } if (kx->public_key != NULL) @@ -661,22 +661,19 @@ GSC_KX_start (const struct GNUNET_PeerIdentity *pid) struct GSC_KeyExchangeInfo *kx; #if DEBUG_CORE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Initiating key exchange with `%s'\n", - GNUNET_i2s (pid)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initiating key exchange with `%s'\n", + GNUNET_i2s (pid)); #endif - GNUNET_STATISTICS_update (GSC_stats, - gettext_noop ("# key exchanges initiated"), - 1, - GNUNET_NO); + GNUNET_STATISTICS_update (GSC_stats, + gettext_noop ("# key exchanges initiated"), 1, + GNUNET_NO); kx = GNUNET_malloc (sizeof (struct GSC_KeyExchangeInfo)); kx->peer = *pid; kx->set_key_retry_frequency = INITIAL_SET_KEY_RETRY_FREQUENCY; - kx->pitr = GNUNET_PEERINFO_iterate (peerinfo, - pid, - GNUNET_TIME_UNIT_FOREVER_REL /* timeout? */, - &process_hello, - kx); + kx->pitr = + GNUNET_PEERINFO_iterate (peerinfo, pid, + GNUNET_TIME_UNIT_FOREVER_REL /* timeout? */ , + &process_hello, kx); return kx; } @@ -689,10 +686,8 @@ GSC_KX_start (const struct GNUNET_PeerIdentity *pid) void GSC_KX_stop (struct GSC_KeyExchangeInfo *kx) { - GNUNET_STATISTICS_update (GSC_stats, - gettext_noop ("# key exchanges stopped"), - 1, - GNUNET_NO); + GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# key exchanges stopped"), + 1, GNUNET_NO); if (kx->pitr != NULL) { GNUNET_PEERINFO_iterate_cancel (kx->pitr); @@ -726,7 +721,7 @@ GSC_KX_stop (struct GSC_KeyExchangeInfo *kx) */ void GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, - const struct GNUNET_MessageHeader *msg) + const struct GNUNET_MessageHeader *msg) { const struct SetKeyMessage *m; struct GNUNET_TIME_Absolute t; @@ -735,16 +730,16 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, struct PongMessage *pong; enum KxStateMachine sender_status; uint16_t size; - + size = ntohs (msg->size); if (size != sizeof (struct SetKeyMessage)) - { - GNUNET_break_op (0); - return; - } - m = (const struct SetKeyMessage*) msg; + { + GNUNET_break_op (0); + return; + } + m = (const struct SetKeyMessage *) msg; GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# session keys received"), - 1, GNUNET_NO); + 1, GNUNET_NO); #if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -754,15 +749,16 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, if (kx->public_key == NULL) { GNUNET_free_non_null (kx->skm_received); - kx->skm_received = (struct SetKeyMessage*) GNUNET_copy_message (msg); + kx->skm_received = (struct SetKeyMessage *) GNUNET_copy_message (msg); return; } if (0 != - memcmp (&m->target, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity))) + memcmp (&m->target, &GSC_my_identity, + sizeof (struct GNUNET_PeerIdentity))) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - _("`%s' is for `%s', not for me. Ignoring.\n"), - "SET_KEY", GNUNET_i2s (&m->target)); + _("`%s' is for `%s', not for me. Ignoring.\n"), "SET_KEY", + GNUNET_i2s (&m->target)); return; } if ((ntohl (m->purpose.size) != @@ -779,8 +775,7 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, return; } t = GNUNET_TIME_absolute_ntoh (m->creation_time); - if (((kx->status == KX_STATE_KEY_RECEIVED) || - (kx->status == KX_STATE_UP)) && + if (((kx->status == KX_STATE_KEY_RECEIVED) || (kx->status == KX_STATE_UP)) && (t.abs_value < kx->decrypt_key_created.abs_value)) { /* this could rarely happen due to massive re-ordering of @@ -803,9 +798,8 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, gettext_noop ("# SET_KEY messages decrypted"), 1, GNUNET_NO); #if DEBUG_CORE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received SET_KEY from `%s'\n", - GNUNET_i2s (&kx->peer)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received SET_KEY from `%s'\n", + GNUNET_i2s (&kx->peer)); #endif kx->decrypt_key = k; if (kx->decrypt_key_created.abs_value != t.abs_value) @@ -831,9 +825,9 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, /* we're not up, so we are already doing 'send_key' */ break; case KX_STATE_UP: - if ( (sender_status == KX_STATE_DOWN) || - (sender_status == KX_STATE_KEY_SENT) ) - send_key (kx); /* we are up, but other peer is not! */ + if ((sender_status == KX_STATE_DOWN) || + (sender_status == KX_STATE_KEY_SENT)) + send_key (kx); /* we are up, but other peer is not! */ break; default: GNUNET_break (0); @@ -865,7 +859,7 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, */ void GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx, - const struct GNUNET_MessageHeader *msg) + const struct GNUNET_MessageHeader *msg) { const struct PingMessage *m; struct PingMessage t; @@ -876,22 +870,21 @@ GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx, msize = ntohs (msg->size); if (msize != sizeof (struct PingMessage)) - { - GNUNET_break_op (0); - return; - } - GNUNET_STATISTICS_update (GSC_stats, - gettext_noop ("# PING messages received"), - 1, GNUNET_NO); - if ( (kx->status != KX_STATE_KEY_RECEIVED) && - (kx->status != KX_STATE_UP) ) - { - /* defer */ - GNUNET_free_non_null (kx->ping_received); - kx->ping_received = (struct PingMessage*) GNUNET_copy_message (msg); - return; - } - m = (const struct PingMessage*) msg; + { + GNUNET_break_op (0); + return; + } + GNUNET_STATISTICS_update (GSC_stats, + gettext_noop ("# PING messages received"), 1, + GNUNET_NO); + if ((kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP)) + { + /* defer */ + GNUNET_free_non_null (kx->ping_received); + kx->ping_received = (struct PingMessage *) GNUNET_copy_message (msg); + return; + } + m = (const struct PingMessage *) msg; #if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core service receives `%s' request from `%4s'.\n", "PING", @@ -915,15 +908,15 @@ GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx, GNUNET_snprintf (sender, sizeof (sender), "%8s", GNUNET_i2s (&kx->peer)); GNUNET_snprintf (peer, sizeof (peer), "%8s", GNUNET_i2s (&t.target)); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Received PING from `%s' for different identity: I am `%s', PONG identity: `%s'\n"), + _ + ("Received PING from `%s' for different identity: I am `%s', PONG identity: `%s'\n"), sender, GNUNET_i2s (&GSC_my_identity), peer); GNUNET_break_op (0); return; } #if DEBUG_CORE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received PING from `%s'\n", - GNUNET_i2s (&kx->peer)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received PING from `%s'\n", + GNUNET_i2s (&kx->peer)); #endif /* construct PONG */ tx.reserved = GNUNET_BANDWIDTH_VALUE_MAX; @@ -937,12 +930,10 @@ GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx, do_encrypt (kx, &iv, &tx.challenge, &tp.challenge, sizeof (struct PongMessage) - ((void *) &tp.challenge - (void *) &tp)); - GNUNET_STATISTICS_update (GSC_stats, - gettext_noop ("# PONG messages created"), 1, - GNUNET_NO); - GSC_NEIGHBOURS_transmit (&kx->peer, - &tp.header, - GNUNET_TIME_UNIT_FOREVER_REL /* FIXME: timeout */); + GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# PONG messages created"), + 1, GNUNET_NO); + GSC_NEIGHBOURS_transmit (&kx->peer, &tp.header, + GNUNET_TIME_UNIT_FOREVER_REL /* FIXME: timeout */ ); } @@ -963,21 +954,22 @@ setup_fresh_setkey (struct GSC_KeyExchangeInfo *kx) skm->header.size = htons (sizeof (struct SetKeyMessage)); skm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SET_KEY); skm->purpose.size = - htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + - sizeof (struct GNUNET_TIME_AbsoluteNBO) + - sizeof (struct GNUNET_CRYPTO_RsaEncryptedData) + - sizeof (struct GNUNET_PeerIdentity)); + htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + + sizeof (struct GNUNET_TIME_AbsoluteNBO) + + sizeof (struct GNUNET_CRYPTO_RsaEncryptedData) + + sizeof (struct GNUNET_PeerIdentity)); skm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_SET_KEY); skm->creation_time = GNUNET_TIME_absolute_hton (kx->encrypt_key_created); skm->target = kx->peer; GNUNET_assert (GNUNET_OK == - GNUNET_CRYPTO_rsa_encrypt (&kx->encrypt_key, - sizeof (struct - GNUNET_CRYPTO_AesSessionKey), - kx->public_key, &skm->encrypted_key)); + GNUNET_CRYPTO_rsa_encrypt (&kx->encrypt_key, + sizeof (struct + GNUNET_CRYPTO_AesSessionKey), + kx->public_key, + &skm->encrypted_key)); GNUNET_assert (GNUNET_OK == - GNUNET_CRYPTO_rsa_sign (my_private_key, &skm->purpose, - &skm->signature)); + GNUNET_CRYPTO_rsa_sign (my_private_key, &skm->purpose, + &skm->signature)); } @@ -997,13 +989,13 @@ setup_fresh_ping (struct GSC_KeyExchangeInfo *kx) pm->header.size = htons (sizeof (struct PingMessage)); pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING); pm->iv_seed = - GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); derive_iv (&iv, &kx->encrypt_key, pm->iv_seed, &kx->peer); pp.challenge = kx->ping_challenge; pp.target = kx->peer; do_encrypt (kx, &iv, &pp.target, &pm->target, - sizeof (struct PingMessage) - ((void *) &pm->target - - (void *) pm)); + sizeof (struct PingMessage) - ((void *) &pm->target - + (void *) pm)); } @@ -1024,33 +1016,29 @@ send_keep_alive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) kx->keep_alive_task = GNUNET_SCHEDULER_NO_TASK; left = GNUNET_TIME_absolute_get_remaining (kx->timeout); if (left.rel_value == 0) - { - GNUNET_STATISTICS_update (GSC_stats, - gettext_noop ("# sessions terminated by timeout"), - 1, - GNUNET_NO); + { + GNUNET_STATISTICS_update (GSC_stats, + gettext_noop ("# sessions terminated by timeout"), + 1, GNUNET_NO); GSC_SESSIONS_end (&kx->peer); kx->status = KX_STATE_DOWN; return; } #if DEBUG_CORE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending KEEPALIVE to `%s'\n", - GNUNET_i2s (&kx->peer)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending KEEPALIVE to `%s'\n", + GNUNET_i2s (&kx->peer)); #endif - GNUNET_STATISTICS_update (GSC_stats, - gettext_noop ("# keepalive messages sent"), - 1, - GNUNET_NO); + GNUNET_STATISTICS_update (GSC_stats, + gettext_noop ("# keepalive messages sent"), 1, + GNUNET_NO); setup_fresh_ping (kx); - GSC_NEIGHBOURS_transmit (&kx->peer, - &kx->ping.header, - kx->set_key_retry_frequency); + GSC_NEIGHBOURS_transmit (&kx->peer, &kx->ping.header, + kx->set_key_retry_frequency); retry = GNUNET_TIME_relative_max (GNUNET_TIME_relative_divide (left, 2), MIN_PING_FREQUENCY); kx->keep_alive_task = - GNUNET_SCHEDULER_add_delayed (retry, &send_keep_alive, kx); + GNUNET_SCHEDULER_add_delayed (retry, &send_keep_alive, kx); } @@ -1064,13 +1052,15 @@ send_keep_alive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static void update_timeout (struct GSC_KeyExchangeInfo *kx) { - kx->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); + kx->timeout = + GNUNET_TIME_relative_to_absolute + (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); if (kx->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (kx->keep_alive_task); kx->keep_alive_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide - (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, - 2), &send_keep_alive, kx); + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide + (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, + 2), &send_keep_alive, kx); } @@ -1081,7 +1071,8 @@ update_timeout (struct GSC_KeyExchangeInfo *kx) * @param m the encrypted PONG message itself */ void -GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, const struct GNUNET_MessageHeader *msg) +GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, + const struct GNUNET_MessageHeader *msg) { const struct PongMessage *m; struct PongMessage t; @@ -1095,19 +1086,19 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, const struct GNUNET_MessageH GNUNET_break_op (0); return; } - GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# PONG messages received"), - 1, GNUNET_NO); - if ( (kx->status != KX_STATE_KEY_RECEIVED) && - (kx->status != KX_STATE_UP) ) + GNUNET_STATISTICS_update (GSC_stats, + gettext_noop ("# PONG messages received"), 1, + GNUNET_NO); + if ((kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP)) { if (kx->status == KX_STATE_KEY_SENT) { GNUNET_free_non_null (kx->pong_received); - kx->pong_received = (struct PongMessage*) GNUNET_copy_message (msg); + kx->pong_received = (struct PongMessage *) GNUNET_copy_message (msg); } return; } - m = (const struct PongMessage*) msg; + m = (const struct PongMessage *) msg; #if DEBUG_HANDSHAKE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core service receives `%s' response from `%4s'.\n", "PONG", @@ -1125,8 +1116,9 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, const struct GNUNET_MessageH GNUNET_break_op (0); return; } - GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# PONG messages decrypted"), - 1, GNUNET_NO); + GNUNET_STATISTICS_update (GSC_stats, + gettext_noop ("# PONG messages decrypted"), 1, + GNUNET_NO); if ((0 != memcmp (&t.target, &kx->peer, sizeof (struct GNUNET_PeerIdentity))) || (kx->ping_challenge != t.challenge)) { @@ -1143,9 +1135,8 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, const struct GNUNET_MessageH return; } #if DEBUG_CORE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received PONG from `%s'\n", - GNUNET_i2s (&kx->peer)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received PONG from `%s'\n", + GNUNET_i2s (&kx->peer)); #endif switch (kx->status) { @@ -1170,7 +1161,8 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, const struct GNUNET_MessageH { emsg = kx->emsg_received; kx->emsg_received = NULL; - GSC_KX_handle_encrypted_message (kx, &emsg->header, NULL, 0 /* FIXME: ATSI */); + GSC_KX_handle_encrypted_message (kx, &emsg->header, NULL, + 0 /* FIXME: ATSI */ ); GNUNET_free (emsg); } update_timeout (kx); @@ -1194,20 +1186,20 @@ static void send_key (struct GSC_KeyExchangeInfo *kx) { GNUNET_assert (kx->retry_set_key_task == GNUNET_SCHEDULER_NO_TASK); - if (KX_STATE_UP == kx->status) - return; /* nothing to do */ + if (KX_STATE_UP == kx->status) + return; /* nothing to do */ if (kx->public_key == NULL) { /* lookup public key, then try again */ #if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Trying to obtain public key for `%s'\n", - GNUNET_i2s (&kx->peer)); + "Trying to obtain public key for `%s'\n", + GNUNET_i2s (&kx->peer)); #endif kx->pitr = - GNUNET_PEERINFO_iterate (peerinfo, &kx->peer, - GNUNET_TIME_UNIT_FOREVER_REL /* timeout? */, - &process_hello, kx); + GNUNET_PEERINFO_iterate (peerinfo, &kx->peer, + GNUNET_TIME_UNIT_FOREVER_REL /* timeout? */ , + &process_hello, kx); return; } @@ -1215,14 +1207,14 @@ send_key (struct GSC_KeyExchangeInfo *kx) switch (kx->status) { case KX_STATE_DOWN: - kx->status = KX_STATE_KEY_SENT; + kx->status = KX_STATE_KEY_SENT; /* setup SET KEY message */ setup_fresh_setkey (kx); setup_fresh_ping (kx); GNUNET_STATISTICS_update (GSC_stats, - gettext_noop - ("# SET_KEY and PING messages created"), 1, - GNUNET_NO); + gettext_noop + ("# SET_KEY and PING messages created"), 1, + GNUNET_NO); break; case KX_STATE_KEY_SENT: break; @@ -1239,19 +1231,16 @@ send_key (struct GSC_KeyExchangeInfo *kx) /* always update sender status in SET KEY message */ kx->skm.sender_status = htonl ((int32_t) kx->status); #if DEBUG_CORE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending SET_KEY and PING to `%s'\n", - GNUNET_i2s (&kx->peer)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending SET_KEY and PING to `%s'\n", + GNUNET_i2s (&kx->peer)); #endif - GSC_NEIGHBOURS_transmit (&kx->peer, - &kx->skm.header, - kx->set_key_retry_frequency); - GSC_NEIGHBOURS_transmit (&kx->peer, - &kx->ping.header, - kx->set_key_retry_frequency); + GSC_NEIGHBOURS_transmit (&kx->peer, &kx->skm.header, + kx->set_key_retry_frequency); + GSC_NEIGHBOURS_transmit (&kx->peer, &kx->ping.header, + kx->set_key_retry_frequency); kx->retry_set_key_task = - GNUNET_SCHEDULER_add_delayed (kx->set_key_retry_frequency, - &set_key_retry_task, kx); + GNUNET_SCHEDULER_add_delayed (kx->set_key_retry_frequency, + &set_key_retry_task, kx); } @@ -1264,18 +1253,17 @@ send_key (struct GSC_KeyExchangeInfo *kx) */ void GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, - const void *payload, - size_t payload_size) + const void *payload, size_t payload_size) { size_t used = payload_size + sizeof (struct EncryptedMessage); - char pbuf[used]; /* plaintext */ - char cbuf[used]; /* ciphertext */ + char pbuf[used]; /* plaintext */ + char cbuf[used]; /* ciphertext */ struct EncryptedMessage *em; /* encrypted message */ struct EncryptedMessage *ph; /* plaintext header */ struct GNUNET_CRYPTO_AesInitializationVector iv; struct GNUNET_CRYPTO_AuthKey auth_key; - ph = (struct EncryptedMessage*) pbuf; + ph = (struct EncryptedMessage *) pbuf; ph->iv_seed = htonl (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX)); @@ -1290,22 +1278,20 @@ GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, em->iv_seed = ph->iv_seed; derive_iv (&iv, &kx->encrypt_key, ph->iv_seed, &kx->peer); GNUNET_assert (GNUNET_OK == - do_encrypt (kx, &iv, &ph->sequence_number, &em->sequence_number, + do_encrypt (kx, &iv, &ph->sequence_number, + &em->sequence_number, used - ENCRYPTED_HEADER_SIZE)); #if DEBUG_CORE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Encrypted %u bytes for %s\n", - used - ENCRYPTED_HEADER_SIZE, - GNUNET_i2s (&kx->peer)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypted %u bytes for %s\n", + used - ENCRYPTED_HEADER_SIZE, GNUNET_i2s (&kx->peer)); #endif derive_auth_key (&auth_key, &kx->encrypt_key, ph->iv_seed, kx->encrypt_key_created); GNUNET_CRYPTO_hmac (&auth_key, &em->sequence_number, used - ENCRYPTED_HEADER_SIZE, &em->hmac); - GSC_NEIGHBOURS_transmit (&kx->peer, - &em->header, - GNUNET_TIME_UNIT_FOREVER_REL); -} + GSC_NEIGHBOURS_transmit (&kx->peer, &em->header, + GNUNET_TIME_UNIT_FOREVER_REL); +} /** @@ -1313,7 +1299,7 @@ GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, */ struct DeliverMessageContext { - + /** * Performance information for the connection. */ @@ -1330,7 +1316,7 @@ struct DeliverMessageContext uint32_t atsi_count; }; - + /** * We received an encrypted message. Decrypt, validate and * pass on to the appropriate clients. @@ -1341,10 +1327,10 @@ struct DeliverMessageContext * @param atsi_count number of entries in ats (excluding 0-termination) */ void -GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx, - const struct GNUNET_MessageHeader *msg, - const struct GNUNET_ATS_Information *atsi, - uint32_t atsi_count) +GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx, + const struct GNUNET_MessageHeader *msg, + const struct GNUNET_ATS_Information *atsi, + uint32_t atsi_count) { const struct EncryptedMessage *m; struct EncryptedMessage *pt; /* plaintext */ @@ -1363,21 +1349,20 @@ GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx, GNUNET_break_op (0); return; } - m = (const struct EncryptedMessage*) msg; - if ( (kx->status != KX_STATE_KEY_RECEIVED) && - (kx->status != KX_STATE_UP) ) + m = (const struct EncryptedMessage *) msg; + if ((kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP)) { GNUNET_STATISTICS_update (GSC_stats, - gettext_noop - ("# failed to decrypt message (no session key)"), - 1, GNUNET_NO); + gettext_noop + ("# failed to decrypt message (no session key)"), + 1, GNUNET_NO); return; } if (kx->status == KX_STATE_KEY_RECEIVED) { /* defer */ GNUNET_free_non_null (kx->ping_received); - kx->emsg_received = (struct EncryptedMessage*) GNUNET_copy_message (msg); + kx->emsg_received = (struct EncryptedMessage *) GNUNET_copy_message (msg); return; } /* validate hash */ @@ -1398,10 +1383,8 @@ GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx, size - ENCRYPTED_HEADER_SIZE)) return; #if DEBUG_CORE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Decrypted %u bytes from %s\n", - size - ENCRYPTED_HEADER_SIZE, - GNUNET_i2s (&kx->peer)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypted %u bytes from %s\n", + size - ENCRYPTED_HEADER_SIZE, GNUNET_i2s (&kx->peer)); #endif pt = (struct EncryptedMessage *) buf; @@ -1480,7 +1463,8 @@ GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx, dmc.atsi_count = atsi_count; dmc.peer = &kx->peer; if (GNUNET_OK != - GNUNET_SERVER_mst_receive (mst, &dmc, &buf[sizeof (struct EncryptedMessage)], + GNUNET_SERVER_mst_receive (mst, &dmc, + &buf[sizeof (struct EncryptedMessage)], size - sizeof (struct EncryptedMessage), GNUNET_YES, GNUNET_NO)) GNUNET_break_op (0); @@ -1490,7 +1474,7 @@ GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx, /** * Deliver P2P message to interested clients. * Invokes send twice, once for clients that want the full message, and once - * for clients that only want the header + * for clients that only want the header * * @param cls always NULL * @param client who sent us the message (struct GSC_KeyExchangeInfo) @@ -1505,20 +1489,15 @@ deliver_message (void *cls, void *client, const struct GNUNET_MessageHeader *m) { case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP: case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP: - GSC_SESSIONS_set_typemap (dmc->peer, - m); + GSC_SESSIONS_set_typemap (dmc->peer, m); return; default: - GSC_CLIENTS_deliver_message (dmc->peer, - dmc->atsi, dmc->atsi_count, - m, - ntohs (m->size), - GNUNET_CORE_OPTION_SEND_FULL_INBOUND); - GSC_CLIENTS_deliver_message (dmc->peer, - dmc->atsi, dmc->atsi_count, - m, - sizeof (struct GNUNET_MessageHeader), - GNUNET_CORE_OPTION_SEND_HDR_INBOUND); + GSC_CLIENTS_deliver_message (dmc->peer, dmc->atsi, dmc->atsi_count, m, + ntohs (m->size), + GNUNET_CORE_OPTION_SEND_FULL_INBOUND); + GSC_CLIENTS_deliver_message (dmc->peer, dmc->atsi, dmc->atsi_count, m, + sizeof (struct GNUNET_MessageHeader), + GNUNET_CORE_OPTION_SEND_HDR_INBOUND); } } @@ -1528,17 +1507,18 @@ deliver_message (void *cls, void *client, const struct GNUNET_MessageHeader *m) * * @return GNUNET_OK on success, GNUNET_SYSERR on failure */ -int +int GSC_KX_init () { char *keyfile; if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (GSC_cfg, "GNUNETD", "HOSTKEY", - &keyfile)) + &keyfile)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Core service is lacking HOSTKEY configuration setting. Exiting.\n")); + _ + ("Core service is lacking HOSTKEY configuration setting. Exiting.\n")); return GNUNET_SYSERR; } my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); @@ -1569,7 +1549,7 @@ GSC_KX_init () /** * Shutdown KX subsystem. */ -void +void GSC_KX_done () { if (my_private_key != NULL) diff --git a/src/core/gnunet-service-core_kx.h b/src/core/gnunet-service-core_kx.h index 0e963ef7a..5ecd2c17f 100644 --- a/src/core/gnunet-service-core_kx.h +++ b/src/core/gnunet-service-core_kx.h @@ -44,8 +44,8 @@ struct GSC_KeyExchangeInfo; * @param msg the set key message we received */ void -GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, - const struct GNUNET_MessageHeader *msg); +GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, + const struct GNUNET_MessageHeader *msg); /** @@ -56,8 +56,8 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, * @param msg the encrypted PING message itself */ void -GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx, - const struct GNUNET_MessageHeader *msg); +GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx, + const struct GNUNET_MessageHeader *msg); /** @@ -68,7 +68,7 @@ GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx, */ void GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, - const struct GNUNET_MessageHeader *msg); + const struct GNUNET_MessageHeader *msg); /** @@ -80,8 +80,7 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, */ void GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, - const void *payload, - size_t payload_size); + const void *payload, size_t payload_size); /** @@ -94,10 +93,10 @@ GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, * @param atsi_count number of entries in ats (excluding 0-termination) */ void -GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx, - const struct GNUNET_MessageHeader *msg, - const struct GNUNET_ATS_Information *atsi, - uint32_t atsi_count); +GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx, + const struct GNUNET_MessageHeader *msg, + const struct GNUNET_ATS_Information *atsi, + uint32_t atsi_count); /** @@ -124,14 +123,14 @@ GSC_KX_stop (struct GSC_KeyExchangeInfo *kx); * * @return GNUNET_OK on success, GNUNET_SYSERR on failure */ -int +int GSC_KX_init (void); /** * Shutdown KX subsystem. */ -void +void GSC_KX_done (void); #endif diff --git a/src/core/gnunet-service-core_neighbours.c b/src/core/gnunet-service-core_neighbours.c index d7ce91a88..5014298bf 100644 --- a/src/core/gnunet-service-core_neighbours.c +++ b/src/core/gnunet-service-core_neighbours.c @@ -158,10 +158,10 @@ free_neighbour (struct Neighbour *n) GNUNET_TRANSPORT_notify_transmit_ready_cancel (n->th); n->th = NULL; } - GNUNET_STATISTICS_update (GSC_stats, - gettext_noop ("# sessions terminated by transport disconnect"), - 1, - GNUNET_NO); + GNUNET_STATISTICS_update (GSC_stats, + gettext_noop + ("# sessions terminated by transport disconnect"), + 1, GNUNET_NO); GSC_SESSIONS_end (&n->peer); if (NULL != n->kxinfo) { @@ -175,8 +175,9 @@ free_neighbour (struct Neighbour *n) } GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (neighbours, - &n->peer.hashPubKey, n)); - GNUNET_STATISTICS_set (GSC_stats, gettext_noop ("# neighbour entries allocated"), + &n->peer.hashPubKey, n)); + GNUNET_STATISTICS_set (GSC_stats, + gettext_noop ("# neighbour entries allocated"), GNUNET_CONTAINER_multihashmap_size (neighbours), GNUNET_NO); GNUNET_free (n); @@ -239,10 +240,10 @@ transmit_ready (void *cls, size_t size, void *buf) ret = m->size; #if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Copied message of type %u and size %u into transport buffer for `%4s'\n", - (unsigned int) - ntohs (((struct GNUNET_MessageHeader *) &m[1])->type), - (unsigned int) ret, GNUNET_i2s (&n->peer)); + "Copied message of type %u and size %u into transport buffer for `%4s'\n", + (unsigned int) + ntohs (((struct GNUNET_MessageHeader *) &m[1])->type), + (unsigned int) ret, GNUNET_i2s (&n->peer)); #endif GNUNET_free (m); process_queue (n); @@ -271,7 +272,7 @@ process_queue (struct Neighbour *n) if (m == NULL) { /* notify sessions that the queue is empty and more messages - could thus be queued now */ + * could thus be queued now */ GSC_SESSIONS_solicit (&n->peer); return; } @@ -283,12 +284,10 @@ process_queue (struct Neighbour *n) GNUNET_TIME_absolute_get_remaining (m->deadline).rel_value); #endif n->th = - GNUNET_TRANSPORT_notify_transmit_ready (transport, &n->peer, m->size, - 0, - GNUNET_TIME_absolute_get_remaining - (m->deadline), - &transmit_ready, - n); + GNUNET_TRANSPORT_notify_transmit_ready (transport, &n->peer, m->size, 0, + GNUNET_TIME_absolute_get_remaining + (m->deadline), &transmit_ready, + n); if (n->th != NULL) return; /* message request too large or duplicate request */ @@ -313,8 +312,8 @@ process_queue (struct Neighbour *n) static void handle_transport_notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Information - *atsi, uint32_t atsi_count) + const struct GNUNET_ATS_Information *atsi, + uint32_t atsi_count) { struct Neighbour *n; @@ -340,7 +339,8 @@ handle_transport_notify_connect (void *cls, GNUNET_CONTAINER_multihashmap_put (neighbours, &n->peer.hashPubKey, n, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - GNUNET_STATISTICS_set (GSC_stats, gettext_noop ("# neighbour entries allocated"), + GNUNET_STATISTICS_set (GSC_stats, + gettext_noop ("# neighbour entries allocated"), GNUNET_CONTAINER_multihashmap_size (neighbours), GNUNET_NO); n->kxinfo = GSC_KX_start (peer); @@ -423,9 +423,7 @@ handle_transport_receive (void *cls, const struct GNUNET_PeerIdentity *peer, GSC_KX_handle_pong (n->kxinfo, message); break; case GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE: - GSC_KX_handle_encrypted_message (n->kxinfo, - message, atsi, - atsi_count); + GSC_KX_handle_encrypted_message (n->kxinfo, message, atsi, atsi_count); break; default: GNUNET_log (GNUNET_ERROR_TYPE_WARNING, @@ -438,15 +436,15 @@ handle_transport_receive (void *cls, const struct GNUNET_PeerIdentity *peer, /** * Transmit the given message to the given target. - * + * * @param target peer that should receive the message (must be connected) * @param msg message to transmit * @param timeout by when should the transmission be done? */ void GSC_NEIGHBOURS_transmit (const struct GNUNET_PeerIdentity *target, - const struct GNUNET_MessageHeader *msg, - struct GNUNET_TIME_Relative timeout) + const struct GNUNET_MessageHeader *msg, + struct GNUNET_TIME_Relative timeout) { struct NeighbourMessageEntry *me; struct Neighbour *n; @@ -463,9 +461,7 @@ GSC_NEIGHBOURS_transmit (const struct GNUNET_PeerIdentity *target, me->deadline = GNUNET_TIME_relative_to_absolute (timeout); me->size = msize; memcpy (&me[1], msg, msize); - GNUNET_CONTAINER_DLL_insert_tail (n->message_head, - n->message_tail, - me); + GNUNET_CONTAINER_DLL_insert_tail (n->message_head, n->message_tail, me); process_queue (n); } @@ -478,8 +474,7 @@ GSC_NEIGHBOURS_init () { neighbours = GNUNET_CONTAINER_multihashmap_create (128); transport = - GNUNET_TRANSPORT_connect (GSC_cfg, - &GSC_my_identity, NULL, + GNUNET_TRANSPORT_connect (GSC_cfg, &GSC_my_identity, NULL, &handle_transport_receive, &handle_transport_notify_connect, &handle_transport_notify_disconnect); @@ -530,4 +525,3 @@ GSC_NEIGHBOURS_done () } /* end of gnunet-service-core_neighbours.c */ - diff --git a/src/core/gnunet-service-core_neighbours.h b/src/core/gnunet-service-core_neighbours.h index 36682770e..d613c46a5 100644 --- a/src/core/gnunet-service-core_neighbours.h +++ b/src/core/gnunet-service-core_neighbours.h @@ -35,15 +35,15 @@ * when the message queue is empty). Outbound quotas and memory * bounds will then be enfoced (as GSC_SESSION_solicit is only called * if sufficient banwdith is available). - * + * * @param target peer that should receive the message (must be connected) * @param msg message to transmit * @param timeout by when should the transmission be done? */ void GSC_NEIGHBOURS_transmit (const struct GNUNET_PeerIdentity *target, - const struct GNUNET_MessageHeader *msg, - struct GNUNET_TIME_Relative timeout); + const struct GNUNET_MessageHeader *msg, + struct GNUNET_TIME_Relative timeout); /** diff --git a/src/core/gnunet-service-core_sessions.c b/src/core/gnunet-service-core_sessions.c index a8f7bf6bf..108fd47cf 100644 --- a/src/core/gnunet-service-core_sessions.c +++ b/src/core/gnunet-service-core_sessions.c @@ -20,7 +20,7 @@ /** * @file core/gnunet-service-core_sessions.c - * @brief code for managing of 'encrypted' sessions (key exchange done) + * @brief code for managing of 'encrypted' sessions (key exchange done) * @author Christian Grothoff */ #include "platform.h" @@ -133,7 +133,7 @@ struct Session /** * Is the neighbour queue empty and thus ready for us - * to transmit an encrypted message? + * to transmit an encrypted message? */ int ready_to_transmit; @@ -162,7 +162,7 @@ find_session (const struct GNUNET_PeerIdentity *peer) /** * End the session with the given peer (we are no longer - * connected). + * connected). * * @param pid identity of peer to kill session with */ @@ -176,8 +176,7 @@ GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid) if (NULL == session) return; #if DEBUG_CORE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Destroying session for peer `%4s'\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying session for peer `%4s'\n", GNUNET_i2s (&session->peer)); #endif if (GNUNET_SCHEDULER_NO_TASK != session->cork_task) @@ -188,22 +187,21 @@ GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid) while (NULL != (car = session->active_client_request_head)) { GNUNET_CONTAINER_DLL_remove (session->active_client_request_head, - session->active_client_request_tail, - car); + session->active_client_request_tail, car); GSC_CLIENTS_reject_request (car); } GNUNET_SCHEDULER_cancel (session->typemap_task); - GSC_CLIENTS_notify_clients_about_neighbour (&session->peer, - NULL, 0 /* FIXME: ATSI */, - session->tmap, - NULL); + GSC_CLIENTS_notify_clients_about_neighbour (&session->peer, NULL, + 0 /* FIXME: ATSI */ , + session->tmap, NULL); GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (sessions, - &session->peer.hashPubKey, session)); - GNUNET_STATISTICS_set (GSC_stats, - gettext_noop ("# entries in session map"), - GNUNET_CONTAINER_multihashmap_size (sessions), - GNUNET_NO); + &session-> + peer.hashPubKey, + session)); + GNUNET_STATISTICS_set (GSC_stats, gettext_noop ("# entries in session map"), + GNUNET_CONTAINER_multihashmap_size (sessions), + GNUNET_NO); GSC_TYPEMAP_destroy (session->tmap); session->tmap = NULL; GNUNET_free (session); @@ -216,10 +214,9 @@ GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid) * * @param cls the 'struct Session*' * @param tc unused - */ + */ static void -transmit_typemap_task (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +transmit_typemap_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct Session *session = cls; struct GNUNET_MessageHeader *hdr; @@ -227,19 +224,15 @@ transmit_typemap_task (void *cls, delay = TYPEMAP_FREQUENCY; /* randomize a bit to avoid spont. sync */ - delay.rel_value += GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, - 1000); - session->typemap_task = GNUNET_SCHEDULER_add_delayed (delay, - &transmit_typemap_task, - session); - GNUNET_STATISTICS_update (GSC_stats, - gettext_noop ("# type map refreshes sent"), - 1, - GNUNET_NO); + delay.rel_value += + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000); + session->typemap_task = + GNUNET_SCHEDULER_add_delayed (delay, &transmit_typemap_task, session); + GNUNET_STATISTICS_update (GSC_stats, + gettext_noop ("# type map refreshes sent"), 1, + GNUNET_NO); hdr = GSC_TYPEMAP_compute_type_map_message (); - GSC_KX_encrypt_and_transmit (session->kxinfo, - hdr, - ntohs (hdr->size)); + GSC_KX_encrypt_and_transmit (session->kxinfo, hdr, ntohs (hdr->size)); GNUNET_free (hdr); } @@ -252,33 +245,30 @@ transmit_typemap_task (void *cls, */ void GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer, - struct GSC_KeyExchangeInfo *kx) + struct GSC_KeyExchangeInfo *kx) { struct Session *session; #if DEBUG_CORE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Creating session for peer `%4s'\n", GNUNET_i2s (peer)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating session for peer `%4s'\n", + GNUNET_i2s (peer)); #endif session = GNUNET_malloc (sizeof (struct Session)); session->tmap = GSC_TYPEMAP_create (); session->peer = *peer; session->kxinfo = kx; session->time_established = GNUNET_TIME_absolute_get (); - session->typemap_task = GNUNET_SCHEDULER_add_now (&transmit_typemap_task, - session); + session->typemap_task = + GNUNET_SCHEDULER_add_now (&transmit_typemap_task, session); GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put (sessions, - &peer->hashPubKey, session, + GNUNET_CONTAINER_multihashmap_put (sessions, &peer->hashPubKey, + session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - GNUNET_STATISTICS_set (GSC_stats, - gettext_noop ("# entries in session map"), - GNUNET_CONTAINER_multihashmap_size (sessions), - GNUNET_NO); - GSC_CLIENTS_notify_clients_about_neighbour (peer, - NULL, 0 /* FIXME: ATSI */, - NULL, - session->tmap); + GNUNET_STATISTICS_set (GSC_stats, gettext_noop ("# entries in session map"), + GNUNET_CONTAINER_multihashmap_size (sessions), + GNUNET_NO); + GSC_CLIENTS_notify_clients_about_neighbour (peer, NULL, 0 /* FIXME: ATSI */ , + NULL, session->tmap); } @@ -286,23 +276,20 @@ GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer, * Notify the given client about the session (client is new). * * @param cls the 'struct GSC_Client' - * @param key peer identity + * @param key peer identity * @param value the 'struct Session' * @return GNUNET_OK (continue to iterate) */ static int -notify_client_about_session (void *cls, - const GNUNET_HashCode *key, - void *value) +notify_client_about_session (void *cls, const GNUNET_HashCode * key, + void *value) { struct GSC_Client *client = cls; struct Session *session = value; - GSC_CLIENTS_notify_client_about_neighbour (client, - &session->peer, - NULL, 0, /* FIXME: ATS!? */ - NULL, /* old TMAP: none */ - session->tmap); + GSC_CLIENTS_notify_client_about_neighbour (client, &session->peer, NULL, 0, /* FIXME: ATS!? */ + NULL, /* old TMAP: none */ + session->tmap); return GNUNET_OK; } @@ -316,8 +303,8 @@ void GSC_SESSIONS_notify_client_about_sessions (struct GSC_Client *client) { /* notify new client about existing sessions */ - GNUNET_CONTAINER_multihashmap_iterate (sessions, - ¬ify_client_about_session, client); + GNUNET_CONTAINER_multihashmap_iterate (sessions, ¬ify_client_about_session, + client); } @@ -373,7 +360,7 @@ GSC_SESSIONS_queue_request (struct GSC_ClientActiveRequest *car) "Received client transmission request. queueing\n"); #endif GNUNET_CONTAINER_DLL_insert (session->active_client_request_head, - session->active_client_request_tail, car); + session->active_client_request_tail, car); try_transmission (session); } @@ -389,11 +376,11 @@ GSC_SESSIONS_dequeue_request (struct GSC_ClientActiveRequest *car) { struct Session *s; - if (0 == memcmp (&car->target, - &GSC_my_identity, - sizeof (struct GNUNET_PeerIdentity))) + if (0 == + memcmp (&car->target, &GSC_my_identity, + sizeof (struct GNUNET_PeerIdentity))) return; - s = find_session (&car->target); + s = find_session (&car->target); GNUNET_assert (NULL != s); GNUNET_CONTAINER_DLL_remove (s->active_client_request_head, s->active_client_request_tail, car); @@ -411,7 +398,7 @@ discard_expired_requests (struct Session *session) struct GSC_ClientActiveRequest *pos; struct GSC_ClientActiveRequest *nxt; struct GNUNET_TIME_Absolute now; - + now = GNUNET_TIME_absolute_get (); pos = NULL; nxt = session->active_client_request_head; @@ -419,16 +406,15 @@ discard_expired_requests (struct Session *session) { pos = nxt; nxt = pos->next; - if ( (pos->deadline.abs_value < now.abs_value) && - (GNUNET_YES != pos->was_solicited) ) + if ((pos->deadline.abs_value < now.abs_value) && + (GNUNET_YES != pos->was_solicited)) { GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# messages discarded (expired prior to transmission)"), 1, GNUNET_NO); GNUNET_CONTAINER_DLL_remove (session->active_client_request_head, - session->active_client_request_tail, - pos); + session->active_client_request_tail, pos); GSC_CLIENTS_reject_request (pos); } } @@ -446,7 +432,7 @@ solicit_messages (struct Session *session) struct GSC_ClientActiveRequest *car; size_t so_size; - discard_expired_requests (session); + discard_expired_requests (session); so_size = 0; for (car = session->active_client_request_head; NULL != car; car = car->next) { @@ -462,15 +448,14 @@ solicit_messages (struct Session *session) /** - * Some messages were delayed (corked), but the timeout has now expired. + * Some messages were delayed (corked), but the timeout has now expired. * Send them now. * * @param cls 'struct Session' with the messages to transmit now * @param tc scheduler context (unused) */ static void -pop_cork_task (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +pop_cork_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct Session *session = cls; @@ -499,31 +484,31 @@ try_transmission (struct Session *session) min_deadline = GNUNET_TIME_UNIT_FOREVER_ABS; /* check 'ready' messages */ pos = session->sme_head; - while ( (NULL != pos) && - (msize + pos->size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) ) + while ((NULL != pos) && + (msize + pos->size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE)) { GNUNET_assert (pos->size < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE); msize += pos->size; - min_deadline = GNUNET_TIME_absolute_min (min_deadline, - pos->deadline); + min_deadline = GNUNET_TIME_absolute_min (min_deadline, pos->deadline); pos = pos->next; } now = GNUNET_TIME_absolute_get (); - if ( (msize == 0) || - ( (msize < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE / 2) && - (min_deadline.abs_value > now.abs_value) ) ) + if ((msize == 0) || + ((msize < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE / 2) && + (min_deadline.abs_value > now.abs_value))) { /* not enough ready yet, try to solicit more */ solicit_messages (session); if (msize > 0) { /* if there is data to send, just not yet, make sure we do transmit - it once the deadline is reached */ + * it once the deadline is reached */ if (session->cork_task != GNUNET_SCHEDULER_NO_TASK) - GNUNET_SCHEDULER_cancel (session->cork_task); - session->cork_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (min_deadline), - &pop_cork_task, - session); + GNUNET_SCHEDULER_cancel (session->cork_task); + session->cork_task = + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining + (min_deadline), &pop_cork_task, + session); } return; } @@ -531,18 +516,15 @@ try_transmission (struct Session *session) { static unsigned long long total_bytes; static unsigned int total_msgs; - char pbuf[msize]; /* plaintext */ + char pbuf[msize]; /* plaintext */ size_t used; used = 0; - while ( (NULL != (pos = session->sme_head)) && - (used + pos->size <= msize) ) + while ((NULL != (pos = session->sme_head)) && (used + pos->size <= msize)) { memcpy (&pbuf[used], &pos[1], pos->size); used += pos->size; - GNUNET_CONTAINER_DLL_remove (session->sme_head, - session->sme_tail, - pos); + GNUNET_CONTAINER_DLL_remove (session->sme_head, session->sme_tail, pos); GNUNET_free (pos); } /* compute average payload size */ @@ -554,15 +536,11 @@ try_transmission (struct Session *session) total_msgs = 1; total_bytes = used; } - GNUNET_STATISTICS_set (GSC_stats, - "# avg payload per encrypted message", - total_bytes / total_msgs, - GNUNET_NO); + GNUNET_STATISTICS_set (GSC_stats, "# avg payload per encrypted message", + total_bytes / total_msgs, GNUNET_NO); /* now actually transmit... */ session->ready_to_transmit = GNUNET_NO; - GSC_KX_encrypt_and_transmit (session->kxinfo, - pbuf, - used); + GSC_KX_encrypt_and_transmit (session->kxinfo, pbuf, used); } } @@ -587,9 +565,7 @@ do_send_message (void *cls, const GNUNET_HashCode * key, void *value) m = GNUNET_malloc (sizeof (struct SessionMessageEntry) + size); memcpy (&m[1], hdr, size); m->size = size; - GNUNET_CONTAINER_DLL_insert (session->sme_head, - session->sme_tail, - m); + GNUNET_CONTAINER_DLL_insert (session->sme_head, session->sme_tail, m); try_transmission (session); return GNUNET_OK; } @@ -605,8 +581,8 @@ GSC_SESSIONS_broadcast (const struct GNUNET_MessageHeader *msg) { if (NULL == sessions) return; - GNUNET_CONTAINER_multihashmap_iterate (sessions, - &do_send_message, (void*) msg); + GNUNET_CONTAINER_multihashmap_iterate (sessions, &do_send_message, + (void *) msg); } @@ -640,8 +616,7 @@ GSC_SESSIONS_solicit (const struct GNUNET_PeerIdentity *pid) */ void GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car, - const struct GNUNET_MessageHeader *msg, - int cork) + const struct GNUNET_MessageHeader *msg, int cork) { struct Session *session; struct SessionMessageEntry *sme; @@ -655,10 +630,9 @@ GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car, memcpy (&sme[1], msg, msize); sme->size = msize; if (GNUNET_YES == cork) - sme->deadline = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_MAX_CORK_DELAY); - GNUNET_CONTAINER_DLL_insert_tail (session->sme_head, - session->sme_tail, - sme); + sme->deadline = + GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_MAX_CORK_DELAY); + GNUNET_CONTAINER_DLL_insert_tail (session->sme_head, session->sme_tail, sme); try_transmission (session); } @@ -678,7 +652,7 @@ queue_connect_message (void *cls, const GNUNET_HashCode * key, void *value) struct GNUNET_SERVER_TransmitContext *tc = cls; struct Session *session = value; struct ConnectNotifyMessage cnm; - + /* FIXME: code duplication with clients... */ cnm.header.size = htons (sizeof (struct ConnectNotifyMessage)); cnm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT); @@ -693,23 +667,23 @@ queue_connect_message (void *cls, const GNUNET_HashCode * key, void *value) /** * Handle CORE_ITERATE_PEERS request. For this request type, the client * does not have to have transmitted an INIT request. All current peers - * are returned, regardless of which message types they accept. + * are returned, regardless of which message types they accept. * * @param cls unused * @param client client sending the iteration request * @param message iteration request message */ void -GSC_SESSIONS_handle_client_iterate_peers (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) +GSC_SESSIONS_handle_client_iterate_peers (void *cls, + struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader + *message) { struct GNUNET_MessageHeader done_msg; struct GNUNET_SERVER_TransmitContext *tc; tc = GNUNET_SERVER_transmit_context_create (client); - GNUNET_CONTAINER_multihashmap_iterate (sessions, - &queue_connect_message, - tc); + GNUNET_CONTAINER_multihashmap_iterate (sessions, &queue_connect_message, tc); done_msg.size = htons (sizeof (struct GNUNET_MessageHeader)); done_msg.type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END); GNUNET_SERVER_transmit_context_append_message (tc, &done_msg); @@ -728,14 +702,16 @@ GSC_SESSIONS_handle_client_iterate_peers (void *cls, struct GNUNET_SERVER_Client * @param message iteration request message */ void -GSC_SESSIONS_handle_client_have_peer (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) +GSC_SESSIONS_handle_client_have_peer (void *cls, + struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader + *message) { struct GNUNET_MessageHeader done_msg; struct GNUNET_SERVER_TransmitContext *tc; const struct GNUNET_PeerIdentity *peer; - peer = (const struct GNUNET_PeerIdentity *) &message[1]; // YUCK! + peer = (const struct GNUNET_PeerIdentity *) &message[1]; // YUCK! tc = GNUNET_SERVER_transmit_context_create (client); GNUNET_CONTAINER_multihashmap_get_multiple (sessions, &peer->hashPubKey, &queue_connect_message, tc); @@ -755,24 +731,22 @@ GSC_SESSIONS_handle_client_have_peer (void *cls, struct GNUNET_SERVER_Client *cl */ void GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *msg) + const struct GNUNET_MessageHeader *msg) { struct Session *session; struct GSC_TypeMap *nmap; nmap = GSC_TYPEMAP_get_from_message (msg); if (NULL == nmap) - return; /* malformed */ + return; /* malformed */ session = find_session (peer); if (NULL == session) { GNUNET_break (0); return; } - GSC_CLIENTS_notify_clients_about_neighbour (peer, - NULL, 0, /* FIXME: ATS */ - session->tmap, - nmap); + GSC_CLIENTS_notify_clients_about_neighbour (peer, NULL, 0, /* FIXME: ATS */ + session->tmap, nmap); GSC_TYPEMAP_destroy (session->tmap); session->tmap = nmap; } @@ -788,7 +762,7 @@ GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer, */ void GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer, - uint16_t type) + uint16_t type) { struct Session *session; struct GSC_TypeMap *nmap; @@ -797,16 +771,11 @@ GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer, return; session = find_session (peer); GNUNET_assert (NULL != session); - if (GNUNET_YES == - GSC_TYPEMAP_test_match (session->tmap, - &type, 1)) - return; /* already in it */ - nmap = GSC_TYPEMAP_extend (session->tmap, - &type, 1); - GSC_CLIENTS_notify_clients_about_neighbour (peer, - NULL, 0, /* FIXME: ATS */ - session->tmap, - nmap); + if (GNUNET_YES == GSC_TYPEMAP_test_match (session->tmap, &type, 1)) + return; /* already in it */ + nmap = GSC_TYPEMAP_extend (session->tmap, &type, 1); + GSC_CLIENTS_notify_clients_about_neighbour (peer, NULL, 0, /* FIXME: ATS */ + session->tmap, nmap); GSC_TYPEMAP_destroy (session->tmap); session->tmap = nmap; } @@ -846,12 +815,9 @@ free_session_helper (void *cls, const GNUNET_HashCode * key, void *value) void GSC_SESSIONS_done () { - GNUNET_CONTAINER_multihashmap_iterate (sessions, - &free_session_helper, - NULL); + GNUNET_CONTAINER_multihashmap_iterate (sessions, &free_session_helper, NULL); GNUNET_CONTAINER_multihashmap_destroy (sessions); sessions = NULL; } /* end of gnunet-service-core_sessions.c */ - diff --git a/src/core/gnunet-service-core_sessions.h b/src/core/gnunet-service-core_sessions.h index b70bd59fd..e09cf500e 100644 --- a/src/core/gnunet-service-core_sessions.h +++ b/src/core/gnunet-service-core_sessions.h @@ -20,7 +20,7 @@ /** * @file core/gnunet-service-core_neighbours.h - * @brief code for managing of 'encrypted' sessions (key exchange done) + * @brief code for managing of 'encrypted' sessions (key exchange done) * @author Christian Grothoff */ #ifndef GNUNET_SERVICE_CORE_SESSIONS_H @@ -38,12 +38,12 @@ */ void GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer, - struct GSC_KeyExchangeInfo *kx); + struct GSC_KeyExchangeInfo *kx); /** * End the session with the given peer (we are no longer - * connected). + * connected). * * @param pid identity of peer to kill session with */ @@ -95,8 +95,7 @@ GSC_SESSIONS_dequeue_request (struct GSC_ClientActiveRequest *car); */ void GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car, - const struct GNUNET_MessageHeader *msg, - int cork); + const struct GNUNET_MessageHeader *msg, int cork); /** @@ -125,7 +124,7 @@ GSC_SESSIONS_notify_client_about_sessions (struct GSC_Client *client); */ void GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *msg); + const struct GNUNET_MessageHeader *msg); /** @@ -138,7 +137,7 @@ GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer, */ void GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer, - uint16_t type); + uint16_t type); /** @@ -151,8 +150,10 @@ GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer, * @param message iteration request message */ void -GSC_SESSIONS_handle_client_iterate_peers (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message); +GSC_SESSIONS_handle_client_iterate_peers (void *cls, + struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader + *message); /** @@ -166,8 +167,10 @@ GSC_SESSIONS_handle_client_iterate_peers (void *cls, struct GNUNET_SERVER_Client * @param message iteration request message */ void -GSC_SESSIONS_handle_client_have_peer (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message); +GSC_SESSIONS_handle_client_have_peer (void *cls, + struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader + *message); diff --git a/src/core/gnunet-service-core_typemap.c b/src/core/gnunet-service-core_typemap.c index c54e446c6..d3214ea67 100644 --- a/src/core/gnunet-service-core_typemap.c +++ b/src/core/gnunet-service-core_typemap.c @@ -36,7 +36,7 @@ * A type map describing which messages a given neighbour is able * to process. */ -struct GSC_TypeMap +struct GSC_TypeMap { uint32_t bits[(UINT16_MAX + 1) / 32]; }; @@ -107,10 +107,8 @@ GSC_TYPEMAP_get_from_message (const struct GNUNET_MessageHeader *msg) switch (ntohs (msg->type)) { case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP: - GNUNET_STATISTICS_update (GSC_stats, - gettext_noop ("# type maps received"), - 1, - GNUNET_NO); + GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# type maps received"), + 1, GNUNET_NO); if (size != sizeof (struct GSC_TypeMap)) { GNUNET_break_op (0); @@ -120,16 +118,13 @@ GSC_TYPEMAP_get_from_message (const struct GNUNET_MessageHeader *msg) memcpy (ret, &msg[1], sizeof (struct GSC_TypeMap)); return ret; case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP: - GNUNET_STATISTICS_update (GSC_stats, - gettext_noop ("# type maps received"), - 1, - GNUNET_NO); + GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# type maps received"), + 1, GNUNET_NO); ret = GNUNET_malloc (sizeof (struct GSC_TypeMap)); dlen = sizeof (struct GSC_TypeMap); - if ( (Z_OK != - uncompress ((Bytef*) ret, &dlen, - (const Bytef*) &msg[1], (uLong) size)) || - (dlen != sizeof (struct GSC_TypeMap) ) ) + if ((Z_OK != + uncompress ((Bytef *) ret, &dlen, (const Bytef *) &msg[1], + (uLong) size)) || (dlen != sizeof (struct GSC_TypeMap))) { GNUNET_break_op (0); GNUNET_free (ret); @@ -152,10 +147,9 @@ broadcast_my_type_map () struct GNUNET_MessageHeader *hdr; hdr = GSC_TYPEMAP_compute_type_map_message (); - GNUNET_STATISTICS_update (GSC_stats, - gettext_noop ("# updates to my type map"), - 1, - GNUNET_NO); + GNUNET_STATISTICS_update (GSC_stats, + gettext_noop ("# updates to my type map"), 1, + GNUNET_NO); GSC_SESSIONS_broadcast (hdr); GNUNET_free (hdr); } @@ -165,14 +159,13 @@ broadcast_my_type_map () * Add a set of types to our type map. */ void -GSC_TYPEMAP_add (const uint16_t *types, - unsigned int tlen) +GSC_TYPEMAP_add (const uint16_t * types, unsigned int tlen) { unsigned int i; int changed; changed = GNUNET_NO; - for (i=0;ibits[types[i] / 32] & (1 << (types[i] % 32)))) return GNUNET_YES; return GNUNET_NO; @@ -243,11 +234,10 @@ GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap, * @param types array of types to add * @param tcnt number of entries in types * @return updated type map (fresh copy) - */ + */ struct GSC_TypeMap * -GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap, - const uint16_t *types, - unsigned int tcnt) +GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap, const uint16_t * types, + unsigned int tcnt) { struct GSC_TypeMap *ret; unsigned int i; @@ -255,7 +245,7 @@ GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap, ret = GNUNET_malloc (sizeof (struct GSC_TypeMap)); if (NULL != tmap) memcpy (ret, tmap, sizeof (struct GSC_TypeMap)); - for (i=0;ibits[types[i] / 32] |= (1 << (types[i] % 32)); return ret; } diff --git a/src/core/gnunet-service-core_typemap.h b/src/core/gnunet-service-core_typemap.h index d589c0b1c..ab106a161 100644 --- a/src/core/gnunet-service-core_typemap.h +++ b/src/core/gnunet-service-core_typemap.h @@ -39,16 +39,14 @@ struct GSC_TypeMap; * Add a set of types to our type map. */ void -GSC_TYPEMAP_add (const uint16_t *types, - unsigned int tlen); +GSC_TYPEMAP_add (const uint16_t * types, unsigned int tlen); /** * Remove a set of types from our type map. */ void -GSC_TYPEMAP_remove (const uint16_t *types, - unsigned int tlen); +GSC_TYPEMAP_remove (const uint16_t * types, unsigned int tlen); /** @@ -78,11 +76,10 @@ GSC_TYPEMAP_get_from_message (const struct GNUNET_MessageHeader *msg); * @param types array of types * @param tcnt number of entries in types * @return GNUNET_YES if a type is in the map, GNUNET_NO if not - */ + */ int -GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap, - const uint16_t *types, - unsigned int tcnt); +GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap, const uint16_t * types, + unsigned int tcnt); /** @@ -92,11 +89,10 @@ GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap, * @param types array of types to add * @param tcnt number of entries in types * @return updated type map (fresh copy) - */ + */ struct GSC_TypeMap * -GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap, - const uint16_t *types, - unsigned int tcnt); +GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap, const uint16_t * types, + unsigned int tcnt); /** * Create an empty type map. diff --git a/src/core/test_core_api.c b/src/core/test_core_api.c index be3edf974..e63fc9f9d 100644 --- a/src/core/test_core_api.c +++ b/src/core/test_core_api.c @@ -76,7 +76,7 @@ process_hello (void *cls, const struct GNUNET_MessageHeader *message) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received (my) `%s' from transport service\n", "HELLO"); GNUNET_assert (message != NULL); - if ((p == &p1) && (p2.th != NULL)) + if ((p == &p1) && (p2.th != NULL)) GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL); if ((p == &p2) && (p1.th != NULL)) GNUNET_TRANSPORT_offer_hello (p1.th, message, NULL, NULL); @@ -165,7 +165,8 @@ transmit_ready (void *cls, size_t size, void *buf) static void connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { struct PeerContext *pc = cls; @@ -218,7 +219,8 @@ disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer) static int inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core provides inbound data from `%4s'.\n", GNUNET_i2s (other)); @@ -229,7 +231,8 @@ inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, static int outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core notifies about outbound data for `%4s'.\n", @@ -242,7 +245,8 @@ outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, static int process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving message from `%4s'.\n", GNUNET_i2s (peer)); @@ -296,9 +300,8 @@ init_notify (void *cls, struct GNUNET_CORE_Handle *server, /* connect p2 */ p2.ch = GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify, - &disconnect_notify, &inbound_notify, - GNUNET_YES, &outbound_notify, GNUNET_YES, - handlers); + &disconnect_notify, &inbound_notify, GNUNET_YES, + &outbound_notify, GNUNET_YES, handlers); } else { @@ -344,8 +347,8 @@ run (void *cls, char *const *args, const char *cfgfile, &terminate_task_error, NULL); p1.ch = GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify, - &disconnect_notify, &inbound_notify, - GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); + &disconnect_notify, &inbound_notify, GNUNET_YES, + &outbound_notify, GNUNET_YES, handlers); } diff --git a/src/core/test_core_api_reliability.c b/src/core/test_core_api_reliability.c index 6a764c126..b2079ba35 100644 --- a/src/core/test_core_api_reliability.c +++ b/src/core/test_core_api_reliability.c @@ -156,7 +156,7 @@ terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_CORE_disconnect (p2.ch); p2.ch = NULL; } - if (connect_task != GNUNET_SCHEDULER_NO_TASK) + if (connect_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (connect_task); if (p1.th != NULL) { @@ -177,8 +177,9 @@ terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static void try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - connect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, - &try_connect, NULL); + connect_task = + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect, + NULL); GNUNET_TRANSPORT_try_connect (p1.th, &p2.id); } @@ -239,7 +240,8 @@ transmit_ready (void *cls, size_t size, void *buf) static void connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { struct PeerContext *pc = cls; @@ -284,7 +286,8 @@ disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer) static int inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { #if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -297,7 +300,8 @@ inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, static int outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { #if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -314,7 +318,8 @@ transmit_ready (void *cls, size_t size, void *buf); static int process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { static int n; unsigned int s; diff --git a/src/core/test_core_api_send_to_self.c b/src/core/test_core_api_send_to_self.c index cf9608ede..29b1f75f3 100644 --- a/src/core/test_core_api_send_to_self.c +++ b/src/core/test_core_api_send_to_self.c @@ -182,8 +182,8 @@ run (void *cls, char *const *args, const char *cfgfile, "test_core_api_peer1.conf")); core = - GNUNET_CORE_connect (core_cfg, 42, NULL, &init, &connect_cb, NULL, - NULL, 0, NULL, 0, handlers); + GNUNET_CORE_connect (core_cfg, 42, NULL, &init, &connect_cb, NULL, NULL, + 0, NULL, 0, handlers); die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply diff --git a/src/core/test_core_api_start_only.c b/src/core/test_core_api_start_only.c index f27866c19..b06b97899 100644 --- a/src/core/test_core_api_start_only.c +++ b/src/core/test_core_api_start_only.c @@ -68,7 +68,7 @@ static int ok; static void connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { } @@ -83,7 +83,7 @@ static int inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, const struct GNUNET_MessageHeader *message, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { return GNUNET_OK; } @@ -93,7 +93,7 @@ static int outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, const struct GNUNET_MessageHeader *message, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { return GNUNET_OK; } @@ -130,9 +130,8 @@ init_notify (void *cls, struct GNUNET_CORE_Handle *server, /* connect p2 */ p2.ch = GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify, - &disconnect_notify, &inbound_notify, - GNUNET_YES, &outbound_notify, GNUNET_YES, - handlers); + &disconnect_notify, &inbound_notify, GNUNET_YES, + &outbound_notify, GNUNET_YES, handlers); } else { @@ -193,8 +192,8 @@ run (void *cls, char *const *args, const char *cfgfile, &timeout_task, NULL); p1.ch = GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify, - &disconnect_notify, &inbound_notify, - GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); + &disconnect_notify, &inbound_notify, GNUNET_YES, + &outbound_notify, GNUNET_YES, handlers); } diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c index be875c235..856ed13fd 100644 --- a/src/core/test_core_quota_compliance.c +++ b/src/core/test_core_quota_compliance.c @@ -185,8 +185,9 @@ terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static void try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - connect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, - &try_connect, NULL); + connect_task = + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect, + NULL); GNUNET_TRANSPORT_try_connect (p1.th, &p2.id); GNUNET_TRANSPORT_try_connect (p2.th, &p1.id); } @@ -231,13 +232,11 @@ measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; - throughput_out = total_bytes_sent * 1000 / delta; /* convert to bytes/s */ - throughput_in = total_bytes_recv * 1000 / delta; /* convert to bytes/s */ + throughput_out = total_bytes_sent * 1000 / delta; /* convert to bytes/s */ + throughput_in = total_bytes_recv * 1000 / delta; /* convert to bytes/s */ - max_quota_in = GNUNET_MIN (current_quota_p1_in, - current_quota_p2_in); - max_quota_out = GNUNET_MIN (current_quota_p1_out, - current_quota_p2_out); + max_quota_in = GNUNET_MIN (current_quota_p1_in, current_quota_p2_in); + max_quota_out = GNUNET_MIN (current_quota_p1_out, current_quota_p2_out); if (max_quota_out < max_quota_in) quota_delta = max_quota_in / 5; else @@ -274,7 +273,7 @@ measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2); if (ok != 0) - kind = GNUNET_ERROR_TYPE_ERROR; + kind = GNUNET_ERROR_TYPE_ERROR; switch (test) { case SYMMETRIC: @@ -294,12 +293,10 @@ measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) }; GNUNET_log (kind, "Peer 1 send rate: %llu b/s (%llu bytes in %llu ms)\n", throughput_out, total_bytes_sent, delta); - GNUNET_log (kind, "Peer 1 send quota: %llu b/s\n", - current_quota_p1_out); + GNUNET_log (kind, "Peer 1 send quota: %llu b/s\n", current_quota_p1_out); GNUNET_log (kind, "Peer 2 receive rate: %llu b/s (%llu bytes in %llu ms)\n", throughput_in, total_bytes_recv, delta); - GNUNET_log (kind, "Peer 2 receive quota: %llu b/s\n", - current_quota_p2_in); + GNUNET_log (kind, "Peer 2 receive quota: %llu b/s\n", current_quota_p2_in); /* GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. inbound quota allowed: %llu b/s\n",max_quota_in ); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu b/s\n",max_quota_out); @@ -322,10 +319,11 @@ transmit_ready (void *cls, size_t size, void *buf) { if ((p1.ch != NULL) && (p1.connect_status == 1)) GNUNET_break (NULL != - (p1.nth = GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0, - FAST_TIMEOUT, &p2.id, - MESSAGESIZE, - &transmit_ready, &p1))); + (p1.nth = + GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0, + FAST_TIMEOUT, &p2.id, + MESSAGESIZE, + &transmit_ready, &p1))); return 0; } GNUNET_assert (tr_n < TOTAL_MSGS); @@ -364,12 +362,13 @@ transmit_ready (void *cls, size_t size, void *buf) static void connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { struct PeerContext *pc = cls; if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) - return; /* loopback */ + return; /* loopback */ GNUNET_assert (pc->connect_status == 0); pc->connect_status = 1; if (pc == &p1) @@ -393,10 +392,11 @@ connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, NULL); GNUNET_break (NULL != - (p1.nth = GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0, - TIMEOUT, &p2.id, - MESSAGESIZE, - &transmit_ready, &p1))); + (p1.nth = + GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0, + TIMEOUT, &p2.id, + MESSAGESIZE, + &transmit_ready, &p1))); } } @@ -407,12 +407,12 @@ disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer) struct PeerContext *pc = cls; if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) - return; /* loopback */ + return; /* loopback */ pc->connect_status = 0; if (GNUNET_SCHEDULER_NO_TASK != measure_task) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Measurement aborted due to disconnect!\n"); + "Measurement aborted due to disconnect!\n"); GNUNET_SCHEDULER_cancel (measure_task); measure_task = GNUNET_SCHEDULER_NO_TASK; } @@ -431,7 +431,8 @@ disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer) static int inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { #if DEBUG_TRANSMISSION GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -446,7 +447,8 @@ inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, static int outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { #if DEBUG_TRANSMISSION GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -463,7 +465,8 @@ transmit_ready (void *cls, size_t size, void *buf); static int process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { static int n; const struct TestMessage *hdr; @@ -532,9 +535,10 @@ init_notify (void *cls, struct GNUNET_CORE_Handle *server, GNUNET_assert (ok == 2); OKPP; /* connect p2 */ - p2.ch = GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify, - &disconnect_notify, &inbound_notify, GNUNET_YES, - &outbound_notify, GNUNET_YES, handlers); + p2.ch = + GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify, + &disconnect_notify, &inbound_notify, GNUNET_YES, + &outbound_notify, GNUNET_YES, handlers); } else { @@ -546,8 +550,7 @@ init_notify (void *cls, struct GNUNET_CORE_Handle *server, "Asking core (1) to connect to peer `%4s'\n", GNUNET_i2s (&p2.id)); #endif - connect_task = GNUNET_SCHEDULER_add_now (&try_connect, - NULL); + connect_task = GNUNET_SCHEDULER_add_now (&try_connect, NULL); } } @@ -642,9 +645,10 @@ run (void *cls, char *const *args, const char *cfgfile, "TOTAL_QUOTA_OUT", ¤t_quota_p2_out)); - p1.ch = GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify, - &disconnect_notify, &inbound_notify, GNUNET_YES, - &outbound_notify, GNUNET_YES, handlers); + p1.ch = + GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify, + &disconnect_notify, &inbound_notify, GNUNET_YES, + &outbound_notify, GNUNET_YES, handlers); } diff --git a/src/datacache/datacache.c b/src/datacache/datacache.c index 324ab78ef..d68ba72b5 100644 --- a/src/datacache/datacache.c +++ b/src/datacache/datacache.c @@ -109,8 +109,7 @@ env_delete_notify (void *cls, const GNUNET_HashCode * key, size_t size) struct GNUNET_DATACACHE_Handle *h = cls; #if DEBUG_DATACACHE - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Content under key `%s' discarded\n", + LOG (GNUNET_ERROR_TYPE_DEBUG, "Content under key `%s' discarded\n", GNUNET_h2s (key)); #endif GNUNET_assert (h->utilization >= size); @@ -243,8 +242,7 @@ GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h, return GNUNET_SYSERR; } #if DEBUG_DATACACHE - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Stored data under key `%s' in cache\n", + LOG (GNUNET_ERROR_TYPE_DEBUG, "Stored data under key `%s' in cache\n", GNUNET_h2s (key)); #endif GNUNET_STATISTICS_update (h->stats, gettext_noop ("# bytes stored"), size, @@ -276,8 +274,7 @@ GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h, GNUNET_STATISTICS_update (h->stats, gettext_noop ("# requests received"), 1, GNUNET_NO); #if DEBUG_DATACACHE - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Processing request for key `%s'\n", + LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing request for key `%s'\n", GNUNET_h2s (key)); #endif if (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_test (h->filter, key)) @@ -287,9 +284,8 @@ GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h, ("# requests filtered by bloom filter"), 1, GNUNET_NO); #if DEBUG_DATACACHE - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Bloomfilter filters request for key `%s'\n", - GNUNET_h2s (key)); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Bloomfilter filters request for key `%s'\n", + GNUNET_h2s (key)); #endif return 0; /* can not be present */ } diff --git a/src/datacache/plugin_datacache_sqlite.c b/src/datacache/plugin_datacache_sqlite.c index 44799be63..f852d3b06 100644 --- a/src/datacache/plugin_datacache_sqlite.c +++ b/src/datacache/plugin_datacache_sqlite.c @@ -123,9 +123,8 @@ sqlite_plugin_put (void *cls, const GNUNET_HashCode * key, size_t size, "INSERT INTO ds090 (type, expire, key, value) VALUES (?, ?, ?, ?)", &stmt) != SQLITE_OK) { - LOG_SQLITE (plugin->dbh, - GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "sq_prepare"); + LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "sq_prepare"); return 0; } if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, type)) || @@ -192,9 +191,8 @@ sqlite_plugin_get (void *cls, const GNUNET_HashCode * key, "SELECT count(*) FROM ds090 WHERE key=? AND type=? AND expire >= ?", &stmt) != SQLITE_OK) { - LOG_SQLITE (plugin->dbh, - GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "sq_prepare"); + LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "sq_prepare"); return 0; } ntime = (int64_t) now.abs_value; @@ -218,8 +216,8 @@ sqlite_plugin_get (void *cls, const GNUNET_HashCode * key, sqlite3_finalize (stmt); #if DEBUG_DATACACHE_SQLITE LOG (GNUNET_ERROR_TYPE_DEBUG, - "No content found when processing `%s' for key `%4s'\n", - "GET", GNUNET_h2s (key)); + "No content found when processing `%s' for key `%4s'\n", "GET", + GNUNET_h2s (key)); #endif return 0; } @@ -230,8 +228,8 @@ sqlite_plugin_get (void *cls, const GNUNET_HashCode * key, #if DEBUG_DATACACHE_SQLITE if (0 == total) LOG (GNUNET_ERROR_TYPE_DEBUG, - "No content found when processing `%s' for key `%4s'\n", - "GET", GNUNET_h2s (key)); + "No content found when processing `%s' for key `%4s'\n", "GET", + GNUNET_h2s (key)); #endif return total; } @@ -246,9 +244,8 @@ sqlite_plugin_get (void *cls, const GNUNET_HashCode * key, off); if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK) { - LOG_SQLITE (plugin->dbh, - GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "sq_prepare"); + LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "sq_prepare"); return cnt; } if ((SQLITE_OK != @@ -273,10 +270,8 @@ sqlite_plugin_get (void *cls, const GNUNET_HashCode * key, cnt++; #if DEBUG_DATACACHE_SQLITE LOG (GNUNET_ERROR_TYPE_DEBUG, - "Found %u-byte result when processing `%s' for key `%4s'\n", - (unsigned int) size, - "GET", - GNUNET_h2s (key)); + "Found %u-byte result when processing `%s' for key `%4s'\n", + (unsigned int) size, "GET", GNUNET_h2s (key)); #endif if (GNUNET_OK != iter (iter_cls, exp, key, size, dat, type)) { @@ -316,18 +311,16 @@ sqlite_plugin_del (void *cls) "SELECT _ROWID_,key,value FROM ds090 ORDER BY expire ASC LIMIT 1", &stmt) != SQLITE_OK) { - LOG_SQLITE (plugin->dbh, - GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "sq_prepare"); + LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "sq_prepare"); if (stmt != NULL) (void) sqlite3_finalize (stmt); return GNUNET_SYSERR; } if (SQLITE_ROW != sqlite3_step (stmt)) { - LOG_SQLITE (plugin->dbh, - GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "sqlite3_step"); + LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "sqlite3_step"); (void) sqlite3_finalize (stmt); return GNUNET_SYSERR; } @@ -336,42 +329,35 @@ sqlite_plugin_del (void *cls) memcpy (&hc, sqlite3_column_blob (stmt, 1), sizeof (GNUNET_HashCode)); dsize = sqlite3_column_bytes (stmt, 2); if (SQLITE_OK != sqlite3_finalize (stmt)) - LOG_SQLITE (plugin->dbh, - GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "sqlite3_step"); - if (sq_prepare - (plugin->dbh, "DELETE FROM ds090 WHERE _ROWID_=?", - &dstmt) != SQLITE_OK) + LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "sqlite3_step"); + if (sq_prepare (plugin->dbh, "DELETE FROM ds090 WHERE _ROWID_=?", &dstmt) != + SQLITE_OK) { - LOG_SQLITE (plugin->dbh, - GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "sq_prepare"); + LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "sq_prepare"); if (stmt != NULL) (void) sqlite3_finalize (stmt); return GNUNET_SYSERR; } - if (SQLITE_OK != - sqlite3_bind_int64 (dstmt, 1, rowid)) + if (SQLITE_OK != sqlite3_bind_int64 (dstmt, 1, rowid)) { - LOG_SQLITE (plugin->dbh, - GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "sqlite3_bind"); + LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "sqlite3_bind"); (void) sqlite3_finalize (dstmt); return GNUNET_SYSERR; } if (sqlite3_step (dstmt) != SQLITE_DONE) { - LOG_SQLITE (plugin->dbh, - GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "sqlite3_step"); + LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "sqlite3_step"); (void) sqlite3_finalize (dstmt); return GNUNET_SYSERR; } plugin->env->delete_notify (plugin->env->cls, &hc, dsize + OVERHEAD); if (SQLITE_OK != sqlite3_finalize (dstmt)) - LOG_SQLITE (plugin->dbh, - GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "sqlite3_finalize"); + LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "sqlite3_finalize"); return GNUNET_OK; } @@ -435,8 +421,7 @@ libgnunet_plugin_datacache_sqlite_init (void *cls) api->get = &sqlite_plugin_get; api->put = &sqlite_plugin_put; api->del = &sqlite_plugin_del; - LOG (GNUNET_ERROR_TYPE_INFO, - _("Sqlite datacache running\n")); + LOG (GNUNET_ERROR_TYPE_INFO, _("Sqlite datacache running\n")); return api; } @@ -468,19 +453,19 @@ libgnunet_plugin_datacache_sqlite_done (void *cls) if (result == SQLITE_BUSY) { LOG (GNUNET_ERROR_TYPE_WARNING, - _("Tried to close sqlite without finalizing all prepared statements.\n")); + _ + ("Tried to close sqlite without finalizing all prepared statements.\n")); stmt = sqlite3_next_stmt (plugin->dbh, NULL); while (stmt != NULL) { #if DEBUG_SQLITE - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Closing statement %p\n", stmt); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Closing statement %p\n", stmt); #endif result = sqlite3_finalize (stmt); #if DEBUG_SQLITE if (result != SQLITE_OK) - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Failed to close statement %p: %d\n", stmt, result); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to close statement %p: %d\n", + stmt, result); #endif stmt = sqlite3_next_stmt (plugin->dbh, NULL); } diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c index 318c22cf5..6d3d56c02 100644 --- a/src/datastore/plugin_datastore_sqlite.c +++ b/src/datastore/plugin_datastore_sqlite.c @@ -325,41 +325,35 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg, &plugin->updRepl) != SQLITE_OK) || (sq_prepare (plugin->dbh, - "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " - "FROM gn090 " + "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " "FROM gn090 " #if SQLITE_VERSION_NUMBER >= 3007000 - "INDEXED BY idx_repl_rvalue " + "INDEXED BY idx_repl_rvalue " #endif - "WHERE repl=?2 AND " - " (rvalue>=?1 OR " + "WHERE repl=?2 AND " " (rvalue>=?1 OR " " NOT EXISTS (SELECT 1 FROM gn090 " #if SQLITE_VERSION_NUMBER >= 3007000 - "INDEXED BY idx_repl_rvalue " + "INDEXED BY idx_repl_rvalue " #endif - "WHERE repl=?2 AND rvalue>=?1 LIMIT 1) ) " + "WHERE repl=?2 AND rvalue>=?1 LIMIT 1) ) " "ORDER BY rvalue ASC LIMIT 1", &plugin->selRepl) != SQLITE_OK) || - (sq_prepare - (plugin->dbh, "SELECT MAX(repl) FROM gn090" + (sq_prepare (plugin->dbh, "SELECT MAX(repl) FROM gn090" #if SQLITE_VERSION_NUMBER >= 3007000 - " INDEXED BY idx_repl_rvalue" + " INDEXED BY idx_repl_rvalue" #endif - "", - &plugin->maxRepl) != SQLITE_OK) || + "", &plugin->maxRepl) != SQLITE_OK) || (sq_prepare (plugin->dbh, - "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " - "FROM gn090 " + "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " "FROM gn090 " #if SQLITE_VERSION_NUMBER >= 3007000 - "INDEXED BY idx_expire " + "INDEXED BY idx_expire " #endif "WHERE NOT EXISTS (SELECT 1 FROM gn090 WHERE expire < ?1 LIMIT 1) OR (expire < ?1) " "ORDER BY expire ASC LIMIT 1", &plugin->selExpi) != SQLITE_OK) || (sq_prepare (plugin->dbh, - "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " - "FROM gn090 " + "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " "FROM gn090 " #if SQLITE_VERSION_NUMBER >= 3007000 - "INDEXED BY idx_anon_type_hash " + "INDEXED BY idx_anon_type_hash " #endif "WHERE (anonLevel = 0 AND type=?1) " "ORDER BY hash DESC LIMIT 1 OFFSET ?2", diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c index b1dd0e5de..0309a6592 100644 --- a/src/datastore/test_datastore_api.c +++ b/src/datastore/test_datastore_api.c @@ -185,11 +185,11 @@ check_value (void *cls, const GNUNET_HashCode * key, size_t size, if (NULL == key) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Value check failed (got NULL key) in %d/%d\n", - crc->phase, crc->i); + "Value check failed (got NULL key) in %d/%d\n", crc->phase, + crc->i); crc->phase = RP_ERROR; GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, - GNUNET_SCHEDULER_REASON_PREREQ_DONE); + GNUNET_SCHEDULER_REASON_PREREQ_DONE); return; } #if 0 diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c index 720e82a41..ac69b7a4e 100644 --- a/src/dht/dht_api.c +++ b/src/dht/dht_api.c @@ -249,12 +249,11 @@ add_request_to_pending (void *cls, const GNUNET_HashCode * key, void *value) struct GNUNET_DHT_GetHandle *rh = value; if (GNUNET_NO == rh->message->in_pending_queue) - { + { #if DEBUG_DHT LOG (GNUNET_ERROR_TYPE_DEBUG, - "Retransmitting request related to %s to DHT %p\n", - GNUNET_h2s (key), - handle); + "Retransmitting request related to %s to DHT %p\n", GNUNET_h2s (key), + handle); #endif GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail, rh->message); @@ -284,9 +283,7 @@ try_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) struct GNUNET_DHT_Handle *handle = cls; #if DEBUG_DHT - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Reconnecting with DHT %p\n", - handle); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting with DHT %p\n", handle); #endif handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK; if (handle->retry_time.rel_value < GNUNET_CONSTANTS_SERVICE_RETRY.rel_value) @@ -324,8 +321,8 @@ do_disconnect (struct GNUNET_DHT_Handle *handle) GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th); handle->th = NULL; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Disconnecting from DHT service, will try to reconnect in %llu ms\n", - (unsigned long long) handle->retry_time.rel_value); + "Disconnecting from DHT service, will try to reconnect in %llu ms\n", + (unsigned long long) handle->retry_time.rel_value); GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO); handle->client = NULL; handle->reconnect_task = @@ -351,7 +348,7 @@ process_pending_messages (struct GNUNET_DHT_Handle *handle) if (handle->client == NULL) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "process_pending_messages called, but client is null, reconnecting\n"); + "process_pending_messages called, but client is null, reconnecting\n"); do_disconnect (handle); return; } @@ -368,7 +365,7 @@ process_pending_messages (struct GNUNET_DHT_Handle *handle) if (NULL != handle->th) return; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "notify_transmit_ready returned NULL, reconnecting\n"); + "notify_transmit_ready returned NULL, reconnecting\n"); do_disconnect (handle); } @@ -432,7 +429,7 @@ transmit_pending (void *cls, size_t size, void *buf) #endif handle->in_receive = GNUNET_YES; GNUNET_CLIENT_receive (handle->client, &service_message_handler, handle, - GNUNET_TIME_UNIT_FOREVER_REL); + GNUNET_TIME_UNIT_FOREVER_REL); } return tsize; } @@ -466,9 +463,8 @@ process_reply (void *cls, const GNUNET_HashCode * key, void *value) { /* UID mismatch */ #if DEBUG_DHT - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Ignoring reply for %s: UID mismatch: %llu/%llu\n", - GNUNET_h2s (key), + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Ignoring reply for %s: UID mismatch: %llu/%llu\n", GNUNET_h2s (key), dht_msg->unique_id, get_handle->unique_id); #endif return GNUNET_YES; @@ -490,10 +486,8 @@ process_reply (void *cls, const GNUNET_HashCode * key, void *value) } data_length = msize - meta_length; #if DEBUG_DHT - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Giving %u byte reply for %s to application\n", - (unsigned int) data_length, - GNUNET_h2s (key)); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Giving %u byte reply for %s to application\n", + (unsigned int) data_length, GNUNET_h2s (key)); #endif put_path = (const struct GNUNET_PeerIdentity *) &dht_msg[1]; get_path = &put_path[put_path_length]; @@ -542,10 +536,8 @@ service_message_handler (void *cls, const struct GNUNET_MessageHeader *msg) } dht_msg = (const struct GNUNET_DHT_ClientResultMessage *) msg; #if DEBUG_DHT - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Received reply for `%s' from DHT service %p\n", - GNUNET_h2s (&dht_msg->key), - handle); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Received reply for `%s' from DHT service %p\n", + GNUNET_h2s (&dht_msg->key), handle); #endif GNUNET_CONTAINER_multihashmap_get_multiple (handle->active_requests, &dht_msg->key, &process_reply, @@ -641,7 +633,7 @@ timeout_put_request (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) struct GNUNET_DHT_Handle *handle; handle = pending->handle; - GNUNET_assert (GNUNET_YES == pending->in_pending_queue); + GNUNET_assert (GNUNET_YES == pending->in_pending_queue); GNUNET_CONTAINER_DLL_remove (handle->pending_head, handle->pending_tail, pending); pending->in_pending_queue = GNUNET_NO; @@ -752,10 +744,8 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, return NULL; } #if DEBUG_DHT - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Sending query for %s to DHT %p\n", - GNUNET_h2s (key), - handle); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending query for %s to DHT %p\n", + GNUNET_h2s (key), handle); #endif pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize); get_msg = (struct GNUNET_DHT_ClientGetMessage *) &pending[1]; @@ -803,10 +793,8 @@ GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle) get_msg = (const struct GNUNET_DHT_ClientGetMessage *) get_handle->message->msg; #if DEBUG_DHT - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Sending STOP for %s to DHT via %p\n", - GNUNET_h2s (&get_msg->key), - handle); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending STOP for %s to DHT via %p\n", + GNUNET_h2s (&get_msg->key), handle); #endif /* generate STOP */ pending = diff --git a/src/dht/gnunet-dht-get.c b/src/dht/gnunet-dht-get.c index 8720e76aa..763ff8e6f 100644 --- a/src/dht/gnunet-dht-get.c +++ b/src/dht/gnunet-dht-get.c @@ -124,10 +124,10 @@ static void get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, const GNUNET_HashCode * key, const struct GNUNET_PeerIdentity *get_path, - unsigned int get_path_length, + unsigned int get_path_length, const struct GNUNET_PeerIdentity *put_path, - unsigned int put_path_length, - enum GNUNET_BLOCK_Type type, size_t size, const void *data) + unsigned int put_path_length, enum GNUNET_BLOCK_Type type, + size_t size, const void *data) { fprintf (stdout, "Result %d, type %d:\n%.*s\n", result_count, type, (unsigned int) size, (char *) data); @@ -186,9 +186,9 @@ run (void *cls, char *const *args, const char *cfgfile, GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (absolute_timeout), &cleanup_task, NULL); get_handle = - GNUNET_DHT_get_start (dht_handle, timeout, query_type, &key, - replication, GNUNET_DHT_RO_NONE, NULL, - 0, &get_result_iterator, NULL); + GNUNET_DHT_get_start (dht_handle, timeout, query_type, &key, replication, + GNUNET_DHT_RO_NONE, NULL, 0, &get_result_iterator, + NULL); } diff --git a/src/dht/gnunet-dht-put.c b/src/dht/gnunet-dht-put.c index f165aa4a4..079a8866e 100644 --- a/src/dht/gnunet-dht-put.c +++ b/src/dht/gnunet-dht-put.c @@ -151,9 +151,9 @@ run (void *cls, char *const *args, const char *cfgfile, if (verbose) fprintf (stderr, _("Issuing put request for `%s' with data `%s'!\n"), query_key, data); - GNUNET_DHT_put (dht_handle, &key, replication, GNUNET_DHT_RO_NONE, - query_type, strlen (data), data, expiration, timeout, - &message_sent_cont, NULL); + GNUNET_DHT_put (dht_handle, &key, replication, GNUNET_DHT_RO_NONE, query_type, + strlen (data), data, expiration, timeout, &message_sent_cont, + NULL); } diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index 3e0f3c8d9..72575acae 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/dht/gnunet-service-dht.c @@ -81,8 +81,7 @@ static struct GNUNET_TRANSPORT_GetHelloHandle *ghh; * @param message HELLO message of peer */ static void -process_hello (void *cls, - const struct GNUNET_MessageHeader *message) +process_hello (void *cls, const struct GNUNET_MessageHeader *message) { GNUNET_assert (message != NULL); GNUNET_free_non_null (GDS_my_hello); @@ -149,24 +148,22 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, GDS_DATACACHE_init (); GDS_HELLO_init (); GDS_CLIENTS_init (server); - if (GNUNET_OK != - GDS_NEIGHBOURS_init ()) - { - shutdown_task (NULL, NULL); - return; - } - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, - &shutdown_task, NULL); + if (GNUNET_OK != GDS_NEIGHBOURS_init ()) + { + shutdown_task (NULL, NULL); + return; + } + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, + NULL); GDS_transport_handle = - GNUNET_TRANSPORT_connect (GDS_cfg, NULL, NULL, NULL, NULL, NULL); + GNUNET_TRANSPORT_connect (GDS_cfg, NULL, NULL, NULL, NULL, NULL); if (GDS_transport_handle == NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Failed to connect to transport service!\n")); - return; - } - ghh = GNUNET_TRANSPORT_get_hello (GDS_transport_handle, - &process_hello, NULL); + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + _("Failed to connect to transport service!\n")); + return; + } + ghh = GNUNET_TRANSPORT_get_hello (GDS_transport_handle, &process_hello, NULL); } @@ -181,12 +178,11 @@ int main (int argc, char *const *argv) { int ret; - - ret = (GNUNET_OK == - GNUNET_SERVICE_run (argc, argv, - "dht", - GNUNET_SERVICE_OPTION_NONE, - &run, NULL)) ? 0 : 1; + + ret = + (GNUNET_OK == + GNUNET_SERVICE_run (argc, argv, "dht", GNUNET_SERVICE_OPTION_NONE, &run, + NULL)) ? 0 : 1; GDS_CLIENTS_done (); return ret; } diff --git a/src/dht/gnunet-service-dht_clients.c b/src/dht/gnunet-service-dht_clients.c index 4b9eecc58..dde8c6d7a 100644 --- a/src/dht/gnunet-service-dht_clients.c +++ b/src/dht/gnunet-service-dht_clients.c @@ -53,7 +53,7 @@ struct PendingMessage /** * Actual message to be sent, allocated at the end of the struct: - * // msg = (cast) &pm[1]; + * // msg = (cast) &pm[1]; * // memcpy (&pm[1], data, len); */ const struct GNUNET_MessageHeader *msg; @@ -224,15 +224,13 @@ find_active_client (struct GNUNET_SERVER_Client *client) } ret = GNUNET_malloc (sizeof (struct ClientList)); ret->client_handle = client; - GNUNET_CONTAINER_DLL_insert (client_head, - client_tail, - ret); + GNUNET_CONTAINER_DLL_insert (client_head, client_tail, ret); return ret; } /** - * Iterator over hash map entries that frees all entries + * Iterator over hash map entries that frees all entries * associated with the given client. * * @param cls client to search for in source routes @@ -250,18 +248,15 @@ remove_client_records (void *cls, const GNUNET_HashCode * key, void *value) return GNUNET_YES; #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Removing client %p's record for key %s\n", - client, - GNUNET_h2s (key)); + "Removing client %p's record for key %s\n", client, + GNUNET_h2s (key)); #endif GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (forward_map, - key, record)); + GNUNET_CONTAINER_multihashmap_remove (forward_map, key, + record)); if (NULL != record->hnode) GNUNET_CONTAINER_heap_remove_node (record->hnode); - GNUNET_array_grow (record->seen_replies, - record->seen_replies_count, - 0); + GNUNET_array_grow (record->seen_replies, record->seen_replies_count, 0); GNUNET_free (record); return GNUNET_YES; } @@ -276,37 +271,31 @@ remove_client_records (void *cls, const GNUNET_HashCode * key, void *value) * for the last call when the server is destroyed */ static void -handle_client_disconnect (void *cls, - struct GNUNET_SERVER_Client *client) +handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) { struct ClientList *pos; struct PendingMessage *reply; #if DEBUG_DHT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Local client %p disconnects\n", - client); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Local client %p disconnects\n", client); #endif pos = find_active_client (client); - GNUNET_CONTAINER_DLL_remove (client_head, - client_tail, - pos); + GNUNET_CONTAINER_DLL_remove (client_head, client_tail, pos); if (pos->transmit_handle != NULL) GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->transmit_handle); while (NULL != (reply = pos->pending_head)) - { - GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, - reply); - GNUNET_free (reply); - } - GNUNET_CONTAINER_multihashmap_iterate (forward_map, - &remove_client_records, pos); + { + GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, reply); + GNUNET_free (reply); + } + GNUNET_CONTAINER_multihashmap_iterate (forward_map, &remove_client_records, + pos); GNUNET_free (pos); } /** - * Route the given request via the DHT. This includes updating + * Route the given request via the DHT. This includes updating * the bloom filter and retransmission times, building the P2P * message and initiating the routing operation. */ @@ -318,33 +307,30 @@ transmit_request (struct ClientQueryRecord *cqr) struct GNUNET_CONTAINER_BloomFilter *peer_bf; GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# GET requests from clients injected"), 1, + gettext_noop + ("# GET requests from clients injected"), 1, GNUNET_NO); - reply_bf_mutator = (int32_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, - UINT32_MAX); - reply_bf = GNUNET_BLOCK_construct_bloomfilter (reply_bf_mutator, - cqr->seen_replies, - cqr->seen_replies_count); - peer_bf = GNUNET_CONTAINER_bloomfilter_init (NULL, - DHT_BLOOM_SIZE, - GNUNET_CONSTANTS_BLOOMFILTER_K); - GDS_NEIGHBOURS_handle_get (cqr->type, - cqr->msg_options, - cqr->replication, - 0 /* hop count */, - &cqr->key, - cqr->xquery, - cqr->xquery_size, - reply_bf, - reply_bf_mutator, - peer_bf); + reply_bf_mutator = + (int32_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, + UINT32_MAX); + reply_bf = + GNUNET_BLOCK_construct_bloomfilter (reply_bf_mutator, cqr->seen_replies, + cqr->seen_replies_count); + peer_bf = + GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, + GNUNET_CONSTANTS_BLOOMFILTER_K); + GDS_NEIGHBOURS_handle_get (cqr->type, cqr->msg_options, cqr->replication, + 0 /* hop count */ , + &cqr->key, cqr->xquery, cqr->xquery_size, reply_bf, + reply_bf_mutator, peer_bf); GNUNET_CONTAINER_bloomfilter_free (reply_bf); GNUNET_CONTAINER_bloomfilter_free (peer_bf); /* exponential back-off for retries, max 1h */ - cqr->retry_frequency = - GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_HOURS, - GNUNET_TIME_relative_multiply (cqr->retry_frequency, 2)); + cqr->retry_frequency = + GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_HOURS, + GNUNET_TIME_relative_multiply + (cqr->retry_frequency, 2)); cqr->retry_time = GNUNET_TIME_relative_to_absolute (cqr->retry_frequency); } @@ -359,7 +345,7 @@ transmit_request (struct ClientQueryRecord *cqr) */ static void transmit_next_request_task (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) + const struct GNUNET_SCHEDULER_TaskContext *tc) { struct ClientQueryRecord *cqr; struct GNUNET_TIME_Relative delay; @@ -368,22 +354,24 @@ transmit_next_request_task (void *cls, if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) return; while (NULL != (cqr = GNUNET_CONTAINER_heap_remove_root (retry_heap))) + { + cqr->hnode = NULL; + delay = GNUNET_TIME_absolute_get_remaining (cqr->retry_time); + if (delay.rel_value > 0) { - cqr->hnode = NULL; - delay = GNUNET_TIME_absolute_get_remaining (cqr->retry_time); - if (delay.rel_value > 0) - { - cqr->hnode = GNUNET_CONTAINER_heap_insert (retry_heap, cqr, - cqr->retry_time.abs_value); - retry_task = GNUNET_SCHEDULER_add_delayed (delay, - &transmit_next_request_task, - NULL); - return; - } - transmit_request (cqr); - cqr->hnode = GNUNET_CONTAINER_heap_insert (retry_heap, cqr, - cqr->retry_time.abs_value); + cqr->hnode = + GNUNET_CONTAINER_heap_insert (retry_heap, cqr, + cqr->retry_time.abs_value); + retry_task = + GNUNET_SCHEDULER_add_delayed (delay, &transmit_next_request_task, + NULL); + return; } + transmit_request (cqr); + cqr->hnode = + GNUNET_CONTAINER_heap_insert (retry_heap, cqr, + cqr->retry_time.abs_value); + } } @@ -396,58 +384,52 @@ transmit_next_request_task (void *cls, */ static void handle_dht_local_put (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) + const struct GNUNET_MessageHeader *message) { const struct GNUNET_DHT_ClientPutMessage *dht_msg; struct GNUNET_CONTAINER_BloomFilter *peer_bf; uint16_t size; - + size = ntohs (message->size); if (size < sizeof (struct GNUNET_DHT_ClientPutMessage)) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } + { + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# PUT requests received from clients"), 1, + gettext_noop + ("# PUT requests received from clients"), 1, GNUNET_NO); dht_msg = (const struct GNUNET_DHT_ClientPutMessage *) message; /* give to local clients */ #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Handling local PUT of %u-bytes for query %s\n", - size - sizeof (struct GNUNET_DHT_ClientPutMessage), - GNUNET_h2s (&dht_msg->key)); + "Handling local PUT of %u-bytes for query %s\n", + size - sizeof (struct GNUNET_DHT_ClientPutMessage), + GNUNET_h2s (&dht_msg->key)); #endif GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (dht_msg->expiration), - &dht_msg->key, - 0, NULL, - 0, NULL, - ntohl (dht_msg->type), - size - sizeof (struct GNUNET_DHT_ClientPutMessage), - &dht_msg[1]); + &dht_msg->key, 0, NULL, 0, NULL, + ntohl (dht_msg->type), + size - sizeof (struct GNUNET_DHT_ClientPutMessage), + &dht_msg[1]); /* store locally */ GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (dht_msg->expiration), - &dht_msg->key, - 0, NULL, - ntohl (dht_msg->type), - size - sizeof (struct GNUNET_DHT_ClientPutMessage), - &dht_msg[1]); + &dht_msg->key, 0, NULL, ntohl (dht_msg->type), + size - sizeof (struct GNUNET_DHT_ClientPutMessage), + &dht_msg[1]); /* route to other peers */ - peer_bf = GNUNET_CONTAINER_bloomfilter_init (NULL, - DHT_BLOOM_SIZE, - GNUNET_CONSTANTS_BLOOMFILTER_K); - GDS_NEIGHBOURS_handle_put (ntohl (dht_msg->type), - ntohl (dht_msg->options), - ntohl (dht_msg->desired_replication_level), - GNUNET_TIME_absolute_ntoh (dht_msg->expiration), - 0 /* hop count */, - peer_bf, - &dht_msg->key, - 0, NULL, - &dht_msg[1], - size - sizeof (struct GNUNET_DHT_ClientPutMessage)); + peer_bf = + GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, + GNUNET_CONSTANTS_BLOOMFILTER_K); + GDS_NEIGHBOURS_handle_put (ntohl (dht_msg->type), ntohl (dht_msg->options), + ntohl (dht_msg->desired_replication_level), + GNUNET_TIME_absolute_ntoh (dht_msg->expiration), + 0 /* hop count */ , + peer_bf, &dht_msg->key, 0, NULL, &dht_msg[1], + size - + sizeof (struct GNUNET_DHT_ClientPutMessage)); GNUNET_CONTAINER_bloomfilter_free (peer_bf); GNUNET_SERVER_receive_done (client, GNUNET_OK); } @@ -464,58 +446,55 @@ handle_dht_local_put (void *cls, struct GNUNET_SERVER_Client *client, */ static void handle_dht_local_get (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) + const struct GNUNET_MessageHeader *message) { const struct GNUNET_DHT_ClientGetMessage *get; struct ClientQueryRecord *cqr; size_t xquery_size; - const char* xquery; + const char *xquery; uint16_t size; size = ntohs (message->size); if (size < sizeof (struct GNUNET_DHT_ClientGetMessage)) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } + { + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } xquery_size = size - sizeof (struct GNUNET_DHT_ClientGetMessage); get = (const struct GNUNET_DHT_ClientGetMessage *) message; - xquery = (const char*) &get[1]; + xquery = (const char *) &get[1]; GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# GET requests received from clients"), 1, + gettext_noop + ("# GET requests received from clients"), 1, GNUNET_NO); #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received request for %s from local client %p\n", - GNUNET_h2s (&get->key), - client); + "Received request for %s from local client %p\n", + GNUNET_h2s (&get->key), client); #endif cqr = GNUNET_malloc (sizeof (struct ClientQueryRecord) + xquery_size); cqr->key = get->key; cqr->client = find_active_client (client); - cqr->xquery = (void*) &cqr[1]; + cqr->xquery = (void *) &cqr[1]; memcpy (&cqr[1], xquery, xquery_size); - cqr->hnode = GNUNET_CONTAINER_heap_insert (retry_heap, cqr, 0); + cqr->hnode = GNUNET_CONTAINER_heap_insert (retry_heap, cqr, 0); cqr->retry_frequency = GNUNET_TIME_UNIT_MILLISECONDS; cqr->retry_time = GNUNET_TIME_absolute_get (); cqr->unique_id = get->unique_id; cqr->xquery_size = xquery_size; cqr->replication = ntohl (get->desired_replication_level); cqr->msg_options = ntohl (get->options); - cqr->type = ntohl (get->type); + cqr->type = ntohl (get->type); GNUNET_CONTAINER_multihashmap_put (forward_map, &get->key, cqr, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); /* start remote requests */ if (GNUNET_SCHEDULER_NO_TASK != retry_task) GNUNET_SCHEDULER_cancel (retry_task); retry_task = GNUNET_SCHEDULER_add_now (&transmit_next_request_task, NULL); /* perform local lookup */ - GDS_DATACACHE_handle_get (&get->key, - cqr->type, - cqr->xquery, - xquery_size, - NULL, 0); + GDS_DATACACHE_handle_get (&get->key, cqr->type, cqr->xquery, xquery_size, + NULL, 0); GNUNET_SERVER_receive_done (client, GNUNET_OK); } @@ -538,7 +517,7 @@ struct RemoveByUniqueIdContext /** - * Iterator over hash map entries that frees all entries + * Iterator over hash map entries that frees all entries * that match the given client and unique ID. * * @param cls unique ID and client to search for in source routes @@ -556,9 +535,8 @@ remove_by_unique_id (void *cls, const GNUNET_HashCode * key, void *value) return GNUNET_YES; #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Removing client %p's record for key %s (by unique id)\n", - ctx->client->client_handle, - GNUNET_h2s (key)); + "Removing client %p's record for key %s (by unique id)\n", + ctx->client->client_handle, GNUNET_h2s (key)); #endif return remove_client_records (ctx->client, key, record); } @@ -575,27 +553,24 @@ remove_by_unique_id (void *cls, const GNUNET_HashCode * key, void *value) */ static void handle_dht_local_get_stop (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) + const struct GNUNET_MessageHeader *message) { const struct GNUNET_DHT_ClientGetStopMessage *dht_stop_msg = - (const struct GNUNET_DHT_ClientGetStopMessage *) message; + (const struct GNUNET_DHT_ClientGetStopMessage *) message; struct RemoveByUniqueIdContext ctx; - + GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# GET STOP requests received from clients"), 1, + gettext_noop + ("# GET STOP requests received from clients"), 1, GNUNET_NO); #if DEBUG_DHT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client %p stopped request for key %s\n", - client, - GNUNET_h2s (&dht_stop_msg->key)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p stopped request for key %s\n", + client, GNUNET_h2s (&dht_stop_msg->key)); #endif ctx.client = find_active_client (client); ctx.unique_id = dht_stop_msg->unique_id; - GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, - &dht_stop_msg->key, - &remove_by_unique_id, - &ctx); + GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, &dht_stop_msg->key, + &remove_by_unique_id, &ctx); GNUNET_SERVER_receive_done (client, GNUNET_OK); } @@ -636,8 +611,8 @@ send_reply_to_client (void *cls, size_t size, void *buf) /* client disconnected */ #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client %p disconnected, pending messages will be discarded\n", - client->client_handle); + "Client %p disconnected, pending messages will be discarded\n", + client->client_handle); #endif return 0; } @@ -650,20 +625,15 @@ send_reply_to_client (void *cls, size_t size, void *buf) memcpy (&cbuf[off], reply->msg, msize); GNUNET_free (reply); #if DEBUG_DHT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Transmitting %u bytes to client %p\n", - msize, - client->client_handle); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting %u bytes to client %p\n", + msize, client->client_handle); #endif off += msize; } process_pending_messages (client); #if DEBUG_DHT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Transmitted %u/%u bytes to client %p\n", - (unsigned int) off, - (unsigned int) size, - client->client_handle); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitted %u/%u bytes to client %p\n", + (unsigned int) off, (unsigned int) size, client->client_handle); #endif return off; } @@ -681,20 +651,17 @@ process_pending_messages (struct ClientList *client) { #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Not asking for transmission to %p now: %s\n", - client->client_handle, - client->pending_head == NULL - ? "no more messages" - : "request already pending"); + "Not asking for transmission to %p now: %s\n", + client->client_handle, + client->pending_head == + NULL ? "no more messages" : "request already pending"); #endif return; } #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Asking for transmission of %u bytes to client %p\n", - ntohs (client->pending_head-> - msg->size), - client->client_handle); + "Asking for transmission of %u bytes to client %p\n", + ntohs (client->pending_head->msg->size), client->client_handle); #endif client->transmit_handle = GNUNET_SERVER_notify_transmit_ready (client->client_handle, @@ -716,7 +683,7 @@ add_pending_message (struct ClientList *client, struct PendingMessage *pending_message) { GNUNET_CONTAINER_DLL_insert_tail (client->pending_head, client->pending_tail, - pending_message); + pending_message); process_pending_messages (client); } @@ -728,7 +695,7 @@ struct ForwardReplyContext { /** - * Actual message to send to matching clients. + * Actual message to send to matching clients. */ struct PendingMessage *pm; @@ -777,51 +744,43 @@ forward_reply (void *cls, const GNUNET_HashCode * key, void *value) int do_free; GNUNET_HashCode ch; unsigned int i; - - if ( (record->type != GNUNET_BLOCK_TYPE_ANY) && - (record->type != frc->type) ) + + if ((record->type != GNUNET_BLOCK_TYPE_ANY) && (record->type != frc->type)) + { +#if DEBUG_DHT + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Record type missmatch, not passing request for key %s to local client\n", + GNUNET_h2s (key)); +#endif + GNUNET_STATISTICS_update (GDS_stats, + gettext_noop + ("# Key match, type mismatches in REPLY to CLIENT"), + 1, GNUNET_NO); + return GNUNET_YES; /* type mismatch */ + } + GNUNET_CRYPTO_hash (frc->data, frc->data_size, &ch); + for (i = 0; i < record->seen_replies_count; i++) + if (0 == memcmp (&record->seen_replies[i], &ch, sizeof (GNUNET_HashCode))) { #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Record type missmatch, not passing request for key %s to local client\n", - GNUNET_h2s (key)); + "Duplicate reply, not passing request for key %s to local client\n", + GNUNET_h2s (key)); #endif GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Key match, type mismatches in REPLY to CLIENT"), 1, - GNUNET_NO); - return GNUNET_YES; /* type mismatch */ + gettext_noop + ("# Duplicate REPLIES to CLIENT request dropped"), + 1, GNUNET_NO); + return GNUNET_YES; /* duplicate */ } - GNUNET_CRYPTO_hash (frc->data, - frc->data_size, - &ch); - for (i=0;iseen_replies_count;i++) - if (0 == memcmp (&record->seen_replies[i], - &ch, - sizeof (GNUNET_HashCode))) - { -#if DEBUG_DHT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Duplicate reply, not passing request for key %s to local client\n", - GNUNET_h2s (key)); -#endif - GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Duplicate REPLIES to CLIENT request dropped"), 1, - GNUNET_NO); - return GNUNET_YES; /* duplicate */ - } eval = - GNUNET_BLOCK_evaluate (GDS_block_context, - record->type, key, - NULL, 0, - record->xquery, - record->xquery_size, - frc->data, - frc->data_size); + GNUNET_BLOCK_evaluate (GDS_block_context, record->type, key, NULL, 0, + record->xquery, record->xquery_size, frc->data, + frc->data_size); #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Evaluation result is %d for key %s for local client's query\n", - (int) eval, - GNUNET_h2s (key)); + "Evaluation result is %d for key %s for local client's query\n", + (int) eval, GNUNET_h2s (key)); #endif switch (eval) { @@ -829,9 +788,7 @@ forward_reply (void *cls, const GNUNET_HashCode * key, void *value) do_free = GNUNET_YES; break; case GNUNET_BLOCK_EVALUATION_OK_MORE: - GNUNET_array_append (record->seen_replies, - record->seen_replies_count, - ch); + GNUNET_array_append (record->seen_replies, record->seen_replies_count, ch); do_free = GNUNET_NO; break; case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: @@ -849,38 +806,36 @@ forward_reply (void *cls, const GNUNET_HashCode * key, void *value) return GNUNET_NO; case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Unsupported block type (%u) in request!\n"), - record->type); + _("Unsupported block type (%u) in request!\n"), record->type); return GNUNET_NO; default: GNUNET_break (0); return GNUNET_NO; } if (GNUNET_NO == frc->do_copy) - { - /* first time, we can use the original data */ - pm = frc->pm; - frc->do_copy = GNUNET_YES; - } + { + /* first time, we can use the original data */ + pm = frc->pm; + frc->do_copy = GNUNET_YES; + } else - { - /* two clients waiting for same reply, must copy for queueing */ - pm = GNUNET_malloc (sizeof (struct PendingMessage) + - ntohs (frc->pm->msg->size)); - memcpy (pm, frc->pm, - sizeof (struct PendingMessage) + ntohs (frc->pm->msg->size)); - pm->next = pm->prev = NULL; - } + { + /* two clients waiting for same reply, must copy for queueing */ + pm = GNUNET_malloc (sizeof (struct PendingMessage) + + ntohs (frc->pm->msg->size)); + memcpy (pm, frc->pm, + sizeof (struct PendingMessage) + ntohs (frc->pm->msg->size)); + pm->next = pm->prev = NULL; + } GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# RESULTS queued for clients"), 1, GNUNET_NO); - reply = (struct GNUNET_DHT_ClientResultMessage*) &pm[1]; + reply = (struct GNUNET_DHT_ClientResultMessage *) &pm[1]; reply->unique_id = record->unique_id; #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Queueing reply to query %s for client %p\n", - GNUNET_h2s (key), - record->client->client_handle); + "Queueing reply to query %s for client %p\n", GNUNET_h2s (key), + record->client->client_handle); #endif add_pending_message (record->client, pm); if (GNUNET_YES == do_free) @@ -906,14 +861,13 @@ forward_reply (void *cls, const GNUNET_HashCode * key, void *value) */ void GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, - const GNUNET_HashCode *key, - unsigned int get_path_length, - const struct GNUNET_PeerIdentity *get_path, - unsigned int put_path_length, - const struct GNUNET_PeerIdentity *put_path, - enum GNUNET_BLOCK_Type type, - size_t data_size, - const void *data) + const GNUNET_HashCode * key, + unsigned int get_path_length, + const struct GNUNET_PeerIdentity *get_path, + unsigned int put_path_length, + const struct GNUNET_PeerIdentity *put_path, + enum GNUNET_BLOCK_Type type, size_t data_size, + const void *data) { struct ForwardReplyContext frc; struct PendingMessage *pm; @@ -921,57 +875,57 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, struct GNUNET_PeerIdentity *paths; size_t msize; - if (NULL == - GNUNET_CONTAINER_multihashmap_get (forward_map, key)) + if (NULL == GNUNET_CONTAINER_multihashmap_get (forward_map, key)) { GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# REPLIES ignored for CLIENTS (no match)"), 1, - GNUNET_NO); - return; /* no matching request, fast exit! */ + gettext_noop + ("# REPLIES ignored for CLIENTS (no match)"), 1, + GNUNET_NO); + return; /* no matching request, fast exit! */ } - msize = sizeof(struct GNUNET_DHT_ClientResultMessage) + data_size + - (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity); + msize = + sizeof (struct GNUNET_DHT_ClientResultMessage) + data_size + + (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity); if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Could not pass reply to client, message too big!\n")); - return; - } - pm = (struct PendingMessage *) GNUNET_malloc (msize + sizeof (struct PendingMessage)); - reply = (struct GNUNET_DHT_ClientResultMessage*) &pm[1]; + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + _("Could not pass reply to client, message too big!\n")); + return; + } + pm = (struct PendingMessage *) GNUNET_malloc (msize + + sizeof (struct PendingMessage)); + reply = (struct GNUNET_DHT_ClientResultMessage *) &pm[1]; pm->msg = &reply->header; reply->header.size = htons ((uint16_t) msize); reply->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT); reply->type = htonl (type); reply->get_path_length = htonl (get_path_length); reply->put_path_length = htonl (put_path_length); - reply->unique_id = 0; /* filled in later */ + reply->unique_id = 0; /* filled in later */ reply->expiration = GNUNET_TIME_absolute_hton (expiration); reply->key = *key; - paths = (struct GNUNET_PeerIdentity*) &reply[1]; - memcpy (paths, put_path, - sizeof (struct GNUNET_PeerIdentity) * put_path_length); - memcpy (&paths[put_path_length], - get_path, sizeof (struct GNUNET_PeerIdentity) * get_path_length); - memcpy (&paths[get_path_length + put_path_length], - data, - data_size); + paths = (struct GNUNET_PeerIdentity *) &reply[1]; + memcpy (paths, put_path, + sizeof (struct GNUNET_PeerIdentity) * put_path_length); + memcpy (&paths[put_path_length], get_path, + sizeof (struct GNUNET_PeerIdentity) * get_path_length); + memcpy (&paths[get_path_length + put_path_length], data, data_size); frc.do_copy = GNUNET_NO; frc.pm = pm; frc.data = data; frc.data_size = data_size; frc.type = type; - GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, key, - &forward_reply, - &frc); + GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, key, &forward_reply, + &frc); if (GNUNET_NO == frc.do_copy) - { - /* did not match any of the requests, free! */ - GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# REPLIES ignored for CLIENTS (no match)"), 1, - GNUNET_NO); - GNUNET_free (pm); - } + { + /* did not match any of the requests, free! */ + GNUNET_STATISTICS_update (GDS_stats, + gettext_noop + ("# REPLIES ignored for CLIENTS (no match)"), 1, + GNUNET_NO); + GNUNET_free (pm); + } } @@ -980,17 +934,17 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, * * @param server the initialized server */ -void +void GDS_CLIENTS_init (struct GNUNET_SERVER_Handle *server) { static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = { - {&handle_dht_local_put, NULL, + {&handle_dht_local_put, NULL, GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT, 0}, - {&handle_dht_local_get, NULL, + {&handle_dht_local_get, NULL, GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET, 0}, {&handle_dht_local_get_stop, NULL, - GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP, - sizeof (struct GNUNET_DHT_ClientGetStopMessage) }, + GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP, + sizeof (struct GNUNET_DHT_ClientGetStopMessage)}, {NULL, NULL, 0, 0} }; forward_map = GNUNET_CONTAINER_multihashmap_create (1024); @@ -1009,10 +963,10 @@ GDS_CLIENTS_done () GNUNET_assert (client_head == NULL); GNUNET_assert (client_tail == NULL); if (GNUNET_SCHEDULER_NO_TASK != retry_task) - { - GNUNET_SCHEDULER_cancel (retry_task); - retry_task = GNUNET_SCHEDULER_NO_TASK; - } + { + GNUNET_SCHEDULER_cancel (retry_task); + retry_task = GNUNET_SCHEDULER_NO_TASK; + } GNUNET_assert (0 == GNUNET_CONTAINER_heap_get_size (retry_heap)); GNUNET_CONTAINER_heap_destroy (retry_heap); retry_heap = NULL; @@ -1022,4 +976,3 @@ GDS_CLIENTS_done () } /* end of gnunet-service-dht_clients.c */ - diff --git a/src/dht/gnunet-service-dht_clients.h b/src/dht/gnunet-service-dht_clients.h index 66fa433c0..21b2343e7 100644 --- a/src/dht/gnunet-service-dht_clients.h +++ b/src/dht/gnunet-service-dht_clients.h @@ -47,14 +47,13 @@ */ void GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, - const GNUNET_HashCode *key, - unsigned int get_path_length, - const struct GNUNET_PeerIdentity *get_path, - unsigned int put_path_length, - const struct GNUNET_PeerIdentity *put_path, - enum GNUNET_BLOCK_Type type, - size_t data_size, - const void *data); + const GNUNET_HashCode * key, + unsigned int get_path_length, + const struct GNUNET_PeerIdentity *get_path, + unsigned int put_path_length, + const struct GNUNET_PeerIdentity *put_path, + enum GNUNET_BLOCK_Type type, size_t data_size, + const void *data); /** @@ -62,7 +61,7 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, * * @param server the initialized server */ -void +void GDS_CLIENTS_init (struct GNUNET_SERVER_Handle *server); diff --git a/src/dht/gnunet-service-dht_datacache.c b/src/dht/gnunet-service-dht_datacache.c index f3b2e5b2f..82cd06727 100644 --- a/src/dht/gnunet-service-dht_datacache.c +++ b/src/dht/gnunet-service-dht_datacache.c @@ -74,44 +74,42 @@ struct DHTPutEntry */ void GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration, - const GNUNET_HashCode *key, - unsigned int put_path_length, - const struct GNUNET_PeerIdentity *put_path, - enum GNUNET_BLOCK_Type type, - size_t data_size, - const void *data) + const GNUNET_HashCode * key, + unsigned int put_path_length, + const struct GNUNET_PeerIdentity *put_path, + enum GNUNET_BLOCK_Type type, size_t data_size, + const void *data) { - size_t plen = data_size + put_path_length * sizeof(struct GNUNET_PeerIdentity) + sizeof(struct DHTPutEntry); + size_t plen = + data_size + put_path_length * sizeof (struct GNUNET_PeerIdentity) + + sizeof (struct DHTPutEntry); char buf[plen]; struct DHTPutEntry *pe; struct GNUNET_PeerIdentity *pp; if (datacache == NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("%s request received, but have no datacache!\n"), - "PUT"); - return; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + _("%s request received, but have no datacache!\n"), "PUT"); + return; + } if (data_size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) - { - GNUNET_break (0); - return; - } + { + GNUNET_break (0); + return; + } /* Put size is actual data size plus struct overhead plus path length (if any) */ GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# ITEMS stored in datacache"), 1, - GNUNET_NO); + gettext_noop ("# ITEMS stored in datacache"), 1, + GNUNET_NO); pe = (struct DHTPutEntry *) buf; pe->data_size = htons (data_size); pe->path_length = htons ((uint16_t) put_path_length); pp = (struct GNUNET_PeerIdentity *) &pe[1]; memcpy (pp, put_path, put_path_length * sizeof (struct GNUNET_PeerIdentity)); - memcpy (&pp[put_path_length], - data, data_size); - (void) GNUNET_DATACACHE_put (datacache, key, - plen, (const char *) pe, type, - expiration); + memcpy (&pp[put_path_length], data, data_size); + (void) GNUNET_DATACACHE_put (datacache, key, plen, (const char *) pe, type, + expiration); } @@ -190,20 +188,15 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, return GNUNET_OK; } pp = (const struct GNUNET_PeerIdentity *) &pe[1]; - rdata = (const char*) &pp[put_path_length]; + rdata = (const char *) &pp[put_path_length]; eval = - GNUNET_BLOCK_evaluate (GDS_block_context, type, key, - ctx->reply_bf, - ctx->reply_bf_mutator, - ctx->xquery, - ctx->xquery_size, - rdata, - rdata_size); + GNUNET_BLOCK_evaluate (GDS_block_context, type, key, ctx->reply_bf, + ctx->reply_bf_mutator, ctx->xquery, + ctx->xquery_size, rdata, rdata_size); #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Found reply for query %s in datacache, evaluation result is %d\n", - GNUNET_h2s (key), - (int) eval); + "Found reply for query %s in datacache, evaluation result is %d\n", + GNUNET_h2s (key), (int) eval); #endif ctx->eval = eval; switch (eval) @@ -212,27 +205,26 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, case GNUNET_BLOCK_EVALUATION_OK_MORE: /* forward to local clients */ GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Good RESULTS found in datacache"), 1, - GNUNET_NO); - GDS_CLIENTS_handle_reply (exp, - key, - 0, NULL, - put_path_length, pp, - type, rdata_size, rdata); + gettext_noop + ("# Good RESULTS found in datacache"), 1, + GNUNET_NO); + GDS_CLIENTS_handle_reply (exp, key, 0, NULL, put_path_length, pp, type, + rdata_size, rdata); /* forward to other peers */ - GDS_ROUTING_process (type, exp, - key, put_path_length, pp, - 0, NULL, rdata, rdata_size); + GDS_ROUTING_process (type, exp, key, put_path_length, pp, 0, NULL, rdata, + rdata_size); break; case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Duplicate RESULTS found in datacache"), 1, - GNUNET_NO); + gettext_noop + ("# Duplicate RESULTS found in datacache"), 1, + GNUNET_NO); break; case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Invalid RESULTS found in datacache"), 1, - GNUNET_NO); + gettext_noop + ("# Invalid RESULTS found in datacache"), 1, + GNUNET_NO); break; case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: GNUNET_break (0); @@ -242,11 +234,11 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, return GNUNET_SYSERR; case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Unsupported RESULTS found in datacache"), 1, - GNUNET_NO); + gettext_noop + ("# Unsupported RESULTS found in datacache"), 1, + GNUNET_NO); GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Unsupported block type (%u) in local response!\n"), - type); + _("Unsupported block type (%u) in local response!\n"), type); break; } return (eval == GNUNET_BLOCK_EVALUATION_OK_LAST) ? GNUNET_NO : GNUNET_OK; @@ -256,7 +248,7 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, /** * Handle a GET request we've received from another peer. * - * @param key the query + * @param key the query * @param type requested data type * @param xquery extended query * @param xquery_size number of bytes in xquery @@ -265,28 +257,27 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, * @return evaluation result for the local replies */ enum GNUNET_BLOCK_EvaluationResult -GDS_DATACACHE_handle_get (const GNUNET_HashCode *key, - enum GNUNET_BLOCK_Type type, - const void *xquery, - size_t xquery_size, - struct GNUNET_CONTAINER_BloomFilter **reply_bf, - uint32_t reply_bf_mutator) +GDS_DATACACHE_handle_get (const GNUNET_HashCode * key, + enum GNUNET_BLOCK_Type type, const void *xquery, + size_t xquery_size, + struct GNUNET_CONTAINER_BloomFilter **reply_bf, + uint32_t reply_bf_mutator) { struct GetRequestContext ctx; if (datacache == NULL) return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# GET requests given to datacache"), 1, - GNUNET_NO); + gettext_noop ("# GET requests given to datacache"), + 1, GNUNET_NO); ctx.eval = GNUNET_BLOCK_EVALUATION_REQUEST_VALID; ctx.key = *key; ctx.xquery = xquery; ctx.xquery_size = xquery_size; ctx.reply_bf = reply_bf; ctx.reply_bf_mutator = reply_bf_mutator; - (void) GNUNET_DATACACHE_get (datacache, key, type, - &datacache_get_iterator, &ctx); + (void) GNUNET_DATACACHE_get (datacache, key, type, &datacache_get_iterator, + &ctx); return ctx.eval; } @@ -294,7 +285,7 @@ GDS_DATACACHE_handle_get (const GNUNET_HashCode *key, /** * Initialize datacache subsystem. */ -void +void GDS_DATACACHE_init () { datacache = GNUNET_DATACACHE_create (GDS_cfg, "dhtcache"); diff --git a/src/dht/gnunet-service-dht_datacache.h b/src/dht/gnunet-service-dht_datacache.h index ccd854570..926ad5326 100644 --- a/src/dht/gnunet-service-dht_datacache.h +++ b/src/dht/gnunet-service-dht_datacache.h @@ -44,18 +44,17 @@ */ void GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration, - const GNUNET_HashCode *key, - unsigned int put_path_length, - const struct GNUNET_PeerIdentity *put_path, - enum GNUNET_BLOCK_Type type, - size_t data_size, - const void *data); + const GNUNET_HashCode * key, + unsigned int put_path_length, + const struct GNUNET_PeerIdentity *put_path, + enum GNUNET_BLOCK_Type type, size_t data_size, + const void *data); /** * Handle a GET request we've received from another peer. * - * @param key the query + * @param key the query * @param type requested data type * @param xquery extended query * @param xquery_size number of bytes in xquery @@ -63,19 +62,18 @@ GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration, * @param reply_bf_mutator mutation value for reply_bf * @return evaluation result for the local replies */ -enum GNUNET_BLOCK_EvaluationResult -GDS_DATACACHE_handle_get (const GNUNET_HashCode *key, - enum GNUNET_BLOCK_Type type, - const void *xquery, - size_t xquery_size, - struct GNUNET_CONTAINER_BloomFilter **reply_bf, - uint32_t reply_bf_mutator); +enum GNUNET_BLOCK_EvaluationResult +GDS_DATACACHE_handle_get (const GNUNET_HashCode * key, + enum GNUNET_BLOCK_Type type, const void *xquery, + size_t xquery_size, + struct GNUNET_CONTAINER_BloomFilter **reply_bf, + uint32_t reply_bf_mutator); /** * Initialize datacache subsystem. */ -void +void GDS_DATACACHE_init (void); diff --git a/src/dht/gnunet-service-dht_hello.c b/src/dht/gnunet-service-dht_hello.c index 5be0cbfec..578e651f8 100644 --- a/src/dht/gnunet-service-dht_hello.c +++ b/src/dht/gnunet-service-dht_hello.c @@ -54,8 +54,7 @@ GDS_HELLO_get (const struct GNUNET_PeerIdentity *peer) { if (NULL == peer_to_hello) return NULL; - return GNUNET_CONTAINER_multihashmap_get (peer_to_hello, - &peer->hashPubKey); + return GNUNET_CONTAINER_multihashmap_get (peer_to_hello, &peer->hashPubKey); } @@ -68,11 +67,8 @@ GDS_HELLO_get (const struct GNUNET_PeerIdentity *peer) * @param error message */ static void -process_hello (void *cls, - const struct GNUNET_PeerIdentity * - peer, - const struct GNUNET_HELLO_Message * - hello, const char *err_msg) +process_hello (void *cls, const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_HELLO_Message *hello, const char *err_msg) { struct GNUNET_TIME_Absolute ex; struct GNUNET_HELLO_Message *hm; @@ -83,18 +79,16 @@ process_hello (void *cls, if (GNUNET_TIME_absolute_get_remaining (ex).rel_value == 0) return; GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# HELLOs obtained from peerinfo"), 1, - GNUNET_NO); - hm = GNUNET_CONTAINER_multihashmap_get (peer_to_hello, - &peer->hashPubKey); + gettext_noop ("# HELLOs obtained from peerinfo"), 1, + GNUNET_NO); + hm = GNUNET_CONTAINER_multihashmap_get (peer_to_hello, &peer->hashPubKey); GNUNET_free_non_null (hm); hm = GNUNET_malloc (GNUNET_HELLO_size (hello)); memcpy (hm, hello, GNUNET_HELLO_size (hello)); GNUNET_assert (GNUNET_SYSERR != - GNUNET_CONTAINER_multihashmap_put (peer_to_hello, - &peer->hashPubKey, - hm, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE)); + GNUNET_CONTAINER_multihashmap_put (peer_to_hello, + &peer->hashPubKey, hm, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE)); } @@ -104,9 +98,7 @@ process_hello (void *cls, void GDS_HELLO_init () { - pnc = GNUNET_PEERINFO_notify (GDS_cfg, - &process_hello, - NULL); + pnc = GNUNET_PEERINFO_notify (GDS_cfg, &process_hello, NULL); peer_to_hello = GNUNET_CONTAINER_multihashmap_create (256); } @@ -115,9 +107,7 @@ GDS_HELLO_init () * Free memory occopied by the HELLO. */ static int -free_hello (void *cls, - const GNUNET_HashCode *key, - void *hello) +free_hello (void *cls, const GNUNET_HashCode * key, void *hello) { GNUNET_free (hello); return GNUNET_OK; @@ -137,9 +127,7 @@ GDS_HELLO_done () } if (NULL != peer_to_hello) { - GNUNET_CONTAINER_multihashmap_iterate (peer_to_hello, - &free_hello, - NULL); + GNUNET_CONTAINER_multihashmap_iterate (peer_to_hello, &free_hello, NULL); GNUNET_CONTAINER_multihashmap_destroy (peer_to_hello); } } diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index 02124b488..9ebf16400 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c @@ -275,7 +275,7 @@ struct P2PPendingMessage /** * Actual message to be sent, allocated at the end of the struct: - * // msg = (cast) &pm[1]; + * // msg = (cast) &pm[1]; * // memcpy (&pm[1], data, len); */ const struct GNUNET_MessageHeader *msg; @@ -399,7 +399,7 @@ static GNUNET_SCHEDULER_TaskIdentifier find_peer_task; /** * Identity of this peer. - */ + */ static struct GNUNET_PeerIdentity my_identity; /** @@ -428,11 +428,11 @@ find_bucket (const GNUNET_HashCode * hc) bits = GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey, hc); if (bits == MAX_BUCKETS) - { - /* How can all bits match? Got my own ID? */ - GNUNET_break (0); - return GNUNET_SYSERR; - } + { + /* How can all bits match? Got my own ID? */ + GNUNET_break (0); + return GNUNET_SYSERR; + } return MAX_BUCKETS - bits - 1; } @@ -442,7 +442,7 @@ find_bucket (const GNUNET_HashCode * hc) * * @param cls the 'struct PeerInfo' of the peer * @param tc scheduler context. - */ + */ static void update_core_preference (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) @@ -454,10 +454,10 @@ update_core_preference (void *cls, peer->preference_task = GNUNET_SCHEDULER_NO_TASK; if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) - return; + return; matching = - GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey, - &peer->id.hashPubKey); + GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey, + &peer->id.hashPubKey); if (matching >= 64) matching = 63; bucket = find_bucket (&peer->id.hashPubKey); @@ -469,22 +469,21 @@ update_core_preference (void *cls, preference = (1LL << matching) / k_buckets[bucket].peers_size; } if (preference == 0) - { - peer->preference_task - = GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL, - &update_core_preference, peer); - return; - } + { + peer->preference_task = + GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL, + &update_core_preference, peer); + return; + } GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Preference updates given to core"), 1, - GNUNET_NO); + gettext_noop ("# Preference updates given to core"), + 1, GNUNET_NO); GNUNET_ATS_change_preference (atsAPI, &peer->id, - GNUNET_ATS_PREFERENCE_BANDWIDTH, - (double) preference, - GNUNET_ATS_PREFERENCE_END); - peer->preference_task - = GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL, - &update_core_preference, peer); + GNUNET_ATS_PREFERENCE_BANDWIDTH, + (double) preference, GNUNET_ATS_PREFERENCE_END); + peer->preference_task = + GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL, + &update_core_preference, peer); } @@ -525,9 +524,8 @@ add_known_to_bloom (void *cls, const GNUNET_HashCode * key, void *value) GNUNET_BLOCK_mingle_hash (key, ctx->bf_mutator, &mh); #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Adding known peer (%s) to bloomfilter for FIND PEER with mutation %u\n", - GNUNET_h2s (key), - ctx->bf_mutator); + "Adding known peer (%s) to bloomfilter for FIND PEER with mutation %u\n", + GNUNET_h2s (key), ctx->bf_mutator); #endif GNUNET_CONTAINER_bloomfilter_add (ctx->bloom, &mh); return GNUNET_YES; @@ -553,46 +551,46 @@ send_find_peer_message (void *cls, find_peer_task = GNUNET_SCHEDULER_NO_TASK; if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) return; - if (newly_found_peers > bucket_size) + if (newly_found_peers > bucket_size) { /* If we are finding many peers already, no need to send out our request right now! */ - find_peer_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, - &send_find_peer_message, NULL); + find_peer_task = + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, + &send_find_peer_message, NULL); newly_found_peers = 0; return; } - bcc.bf_mutator = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); + bcc.bf_mutator = + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); bcc.bloom = - GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, GNUNET_CONSTANTS_BLOOMFILTER_K); - GNUNET_CONTAINER_multihashmap_iterate (all_known_peers, - &add_known_to_bloom, + GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, + GNUNET_CONSTANTS_BLOOMFILTER_K); + GNUNET_CONTAINER_multihashmap_iterate (all_known_peers, &add_known_to_bloom, &bcc); GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# FIND PEER messages initiated"), 1, - GNUNET_NO); - peer_bf = GNUNET_CONTAINER_bloomfilter_init (NULL, - DHT_BLOOM_SIZE, - GNUNET_CONSTANTS_BLOOMFILTER_K); + gettext_noop ("# FIND PEER messages initiated"), 1, + GNUNET_NO); + peer_bf = + GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, + GNUNET_CONSTANTS_BLOOMFILTER_K); // FIXME: pass priority!? GDS_NEIGHBOURS_handle_get (GNUNET_BLOCK_TYPE_DHT_HELLO, - GNUNET_DHT_RO_FIND_PEER, - FIND_PEER_REPLICATION_LEVEL, - 0, - &my_identity.hashPubKey, - NULL, 0, - bcc.bloom, bcc.bf_mutator, - peer_bf); + GNUNET_DHT_RO_FIND_PEER, + FIND_PEER_REPLICATION_LEVEL, 0, + &my_identity.hashPubKey, NULL, 0, bcc.bloom, + bcc.bf_mutator, peer_bf); GNUNET_CONTAINER_bloomfilter_free (peer_bf); GNUNET_CONTAINER_bloomfilter_free (bcc.bloom); /* schedule next round */ next_send_time.rel_value = - DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value + - GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, - DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value / (newly_found_peers+1)); + DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value + + GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, + DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value / + (newly_found_peers + 1)); newly_found_peers = 0; - find_peer_task = GNUNET_SCHEDULER_add_delayed (next_send_time, - &send_find_peer_message, - NULL); + find_peer_task = + GNUNET_SCHEDULER_add_delayed (next_send_time, &send_find_peer_message, + NULL); } @@ -607,7 +605,7 @@ send_find_peer_message (void *cls, static void handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { struct PeerInfo *ret; int peer_bucket; @@ -616,10 +614,8 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) return; #if DEBUG_DHT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Connected %s to %s\n", - GNUNET_i2s (&my_identity), - GNUNET_h2s (&peer->hashPubKey)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected %s to %s\n", + GNUNET_i2s (&my_identity), GNUNET_h2s (&peer->hashPubKey)); #endif if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (all_known_peers, @@ -628,11 +624,10 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, GNUNET_break (0); return; } - GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Peers connected"), 1, - GNUNET_NO); + GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# Peers connected"), 1, + GNUNET_NO); peer_bucket = find_bucket (&peer->hashPubKey); - GNUNET_assert ( (peer_bucket >= 0) && (peer_bucket < MAX_BUCKETS) ); + GNUNET_assert ((peer_bucket >= 0) && (peer_bucket < MAX_BUCKETS)); ret = GNUNET_malloc (sizeof (struct PeerInfo)); #if 0 ret->latency = latency; @@ -640,25 +635,23 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, #endif ret->id = *peer; GNUNET_CONTAINER_DLL_insert_tail (k_buckets[peer_bucket].head, - k_buckets[peer_bucket].tail, ret); + k_buckets[peer_bucket].tail, ret); k_buckets[peer_bucket].peers_size++; - closest_bucket = GNUNET_MAX (closest_bucket, - peer_bucket); - if ( (peer_bucket > 0) && - (k_buckets[peer_bucket].peers_size <= bucket_size) ) + closest_bucket = GNUNET_MAX (closest_bucket, peer_bucket); + if ((peer_bucket > 0) && (k_buckets[peer_bucket].peers_size <= bucket_size)) { - ret->preference_task = GNUNET_SCHEDULER_add_now (&update_core_preference, ret); + ret->preference_task = + GNUNET_SCHEDULER_add_now (&update_core_preference, ret); newly_found_peers++; } GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put (all_known_peers, - &peer->hashPubKey, ret, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + GNUNET_CONTAINER_multihashmap_put (all_known_peers, + &peer->hashPubKey, ret, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); if (1 == GNUNET_CONTAINER_multihashmap_size (all_known_peers)) { /* got a first connection, good time to start with FIND PEER requests... */ - find_peer_task = GNUNET_SCHEDULER_add_now (&send_find_peer_message, - NULL); + find_peer_task = GNUNET_SCHEDULER_add_now (&send_find_peer_message, NULL); } } @@ -681,21 +674,18 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) return; #if DEBUG_DHT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Disconnected %s from %s\n", - GNUNET_i2s (&my_identity), - GNUNET_h2s (&peer->hashPubKey)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnected %s from %s\n", + GNUNET_i2s (&my_identity), GNUNET_h2s (&peer->hashPubKey)); #endif to_remove = GNUNET_CONTAINER_multihashmap_get (all_known_peers, &peer->hashPubKey); if (NULL == to_remove) - { - GNUNET_break (0); - return; - } - GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Peers connected"), -1, - GNUNET_NO); + { + GNUNET_break (0); + return; + } + GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# Peers connected"), -1, + GNUNET_NO); GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (all_known_peers, &peer->hashPubKey, @@ -708,15 +698,13 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) current_bucket = find_bucket (&to_remove->id.hashPubKey); GNUNET_assert (current_bucket >= 0); GNUNET_CONTAINER_DLL_remove (k_buckets[current_bucket].head, - k_buckets[current_bucket].tail, - to_remove); + k_buckets[current_bucket].tail, to_remove); GNUNET_assert (k_buckets[current_bucket].peers_size > 0); k_buckets[current_bucket].peers_size--; - while ( (closest_bucket > 0) && - (k_buckets[closest_bucket].peers_size == 0) ) + while ((closest_bucket > 0) && (k_buckets[closest_bucket].peers_size == 0)) closest_bucket--; - if (to_remove->th != NULL) + if (to_remove->th != NULL) { GNUNET_CORE_notify_transmit_ready_cancel (to_remove->th); to_remove->th = NULL; @@ -724,15 +712,14 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) discarded = 0; while (NULL != (pos = to_remove->head)) { - GNUNET_CONTAINER_DLL_remove (to_remove->head, - to_remove->tail, - pos); + GNUNET_CONTAINER_DLL_remove (to_remove->head, to_remove->tail, pos); discarded++; GNUNET_free (pos); } GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Queued messages discarded (peer disconnected)"), discarded, - GNUNET_NO); + gettext_noop + ("# Queued messages discarded (peer disconnected)"), + discarded, GNUNET_NO); GNUNET_free (to_remove); } @@ -756,8 +743,8 @@ core_transmit_notify (void *cls, size_t size, void *buf) size_t msize; peer->th = NULL; - while ( (NULL != (pending = peer->head)) && - (GNUNET_TIME_absolute_get_remaining (pending->timeout).rel_value == 0) ) + while ((NULL != (pending = peer->head)) && + (GNUNET_TIME_absolute_get_remaining (pending->timeout).rel_value == 0)) { peer->pending_count--; GNUNET_CONTAINER_DLL_remove (peer->head, peer->tail, pending); @@ -770,22 +757,24 @@ core_transmit_notify (void *cls, size_t size, void *buf) } if (buf == NULL) { - peer->th - = GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, - pending->importance, - GNUNET_TIME_absolute_get_remaining (pending->timeout), - &peer->id, ntohs (pending->msg->size), - &core_transmit_notify, peer); + peer->th = + GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, + pending->importance, + GNUNET_TIME_absolute_get_remaining + (pending->timeout), &peer->id, + ntohs (pending->msg->size), + &core_transmit_notify, peer); GNUNET_break (NULL != peer->th); return 0; } off = 0; - while ( (NULL != (pending = peer->head)) && - (size - off >= (msize = ntohs (pending->msg->size))) ) + while ((NULL != (pending = peer->head)) && + (size - off >= (msize = ntohs (pending->msg->size)))) { GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Bytes transmitted to other peers"), msize, - GNUNET_NO); + gettext_noop + ("# Bytes transmitted to other peers"), msize, + GNUNET_NO); memcpy (&cbuf[off], pending->msg, msize); off += msize; peer->pending_count--; @@ -794,12 +783,12 @@ core_transmit_notify (void *cls, size_t size, void *buf) } if (peer->head != NULL) { - peer->th - = GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, - pending->importance, - GNUNET_TIME_absolute_get_remaining (pending->timeout), - &peer->id, msize, - &core_transmit_notify, peer); + peer->th = + GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, + pending->importance, + GNUNET_TIME_absolute_get_remaining + (pending->timeout), &peer->id, msize, + &core_transmit_notify, peer); GNUNET_break (NULL != peer->th); } return off; @@ -821,16 +810,16 @@ process_peer_queue (struct PeerInfo *peer) if (NULL != peer->th) return; GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Bytes of bandwdith requested from core"), - ntohs (pending->msg->size), - GNUNET_NO); - peer->th - = GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, - pending->importance, - GNUNET_TIME_absolute_get_remaining (pending->timeout), - &peer->id, - ntohs (pending->msg->size), - &core_transmit_notify, peer); + gettext_noop + ("# Bytes of bandwdith requested from core"), + ntohs (pending->msg->size), GNUNET_NO); + peer->th = + GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, + pending->importance, + GNUNET_TIME_absolute_get_remaining + (pending->timeout), &peer->id, + ntohs (pending->msg->size), + &core_transmit_notify, peer); GNUNET_break (NULL != peer->th); } @@ -844,8 +833,7 @@ process_peer_queue (struct PeerInfo *peer) * @return Some number of peers to forward the message to */ static unsigned int -get_forward_count (uint32_t hop_count, - uint32_t target_replication) +get_forward_count (uint32_t hop_count, uint32_t target_replication) { uint32_t random_value; uint32_t forward_count; @@ -862,18 +850,18 @@ get_forward_count (uint32_t hop_count, return 1; } /* bound by system-wide maximum */ - target_replication = GNUNET_MIN (MAXIMUM_REPLICATION_LEVEL, - target_replication); + target_replication = + GNUNET_MIN (MAXIMUM_REPLICATION_LEVEL, target_replication); target_value = - 1 + (target_replication - 1.0) / (GDS_NSE_get () + - ((float) (target_replication - 1.0) * - hop_count)); + 1 + (target_replication - 1.0) / (GDS_NSE_get () + + ((float) (target_replication - 1.0) * + hop_count)); /* Set forward count to floor of target_value */ forward_count = (uint32_t) target_value; /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */ target_value = target_value - forward_count; random_value = - GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); if (random_value < (target_value * UINT32_MAX)) forward_count++; return forward_count; @@ -950,7 +938,7 @@ get_distance (const GNUNET_HashCode * target, const GNUNET_HashCode * have) * GNUNET_NO otherwise. */ static int -am_closest_peer (const GNUNET_HashCode *key, +am_closest_peer (const GNUNET_HashCode * key, const struct GNUNET_CONTAINER_BloomFilter *bloom) { int bits; @@ -978,7 +966,7 @@ am_closest_peer (const GNUNET_HashCode *key, other_bits = GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey, key); if (other_bits > bits) return GNUNET_NO; - if (other_bits == bits) /* We match the same number of bits */ + if (other_bits == bits) /* We match the same number of bits */ return GNUNET_YES; pos = pos->next; } @@ -997,7 +985,7 @@ am_closest_peer (const GNUNET_HashCode *key, * exponentially declining probability. * * FIXME: double-check that this is fine - * + * * * @param key the key we are selecting a peer to route to * @param bloom a bloomfilter containing entries this request has seen already @@ -1005,9 +993,8 @@ am_closest_peer (const GNUNET_HashCode *key, * @return Peer to route to, or NULL on error */ static struct PeerInfo * -select_peer (const GNUNET_HashCode *key, - const struct GNUNET_CONTAINER_BloomFilter *bloom, - uint32_t hops) +select_peer (const GNUNET_HashCode * key, + const struct GNUNET_CONTAINER_BloomFilter *bloom, uint32_t hops) { unsigned int bc; unsigned int count; @@ -1028,10 +1015,10 @@ select_peer (const GNUNET_HashCode *key, count = 0; while ((pos != NULL) && (count < bucket_size)) { - if ( (bloom == NULL) || - (GNUNET_NO == - GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) ) - { + if ((bloom == NULL) || + (GNUNET_NO == + GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))) + { dist = get_distance (key, &pos->id.hashPubKey); if (dist < smallest_distance) { @@ -1040,25 +1027,25 @@ select_peer (const GNUNET_HashCode *key, } } else - { + { #if DEBUG_DHT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Excluded peer `%s' due to BF match in greedy routing for %s\n", - GNUNET_i2s (&pos->id), - GNUNET_h2s (key)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Excluded peer `%s' due to BF match in greedy routing for %s\n", + GNUNET_i2s (&pos->id), GNUNET_h2s (key)); #endif - GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Peers excluded from routing due to Bloomfilter"), 1, - GNUNET_NO); - } + GNUNET_STATISTICS_update (GDS_stats, + gettext_noop + ("# Peers excluded from routing due to Bloomfilter"), + 1, GNUNET_NO); + } count++; pos = pos->next; } } if (NULL == chosen) GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Peer selection failed"), 1, - GNUNET_NO); + gettext_noop ("# Peer selection failed"), 1, + GNUNET_NO); return chosen; } @@ -1070,18 +1057,18 @@ select_peer (const GNUNET_HashCode *key, pos = k_buckets[bc].head; while ((pos != NULL) && (count < bucket_size)) { - if ( (bloom != NULL) && - (GNUNET_YES == - GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) ) + if ((bloom != NULL) && + (GNUNET_YES == + GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))) { - GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Peers excluded from routing due to Bloomfilter"), 1, - GNUNET_NO); + GNUNET_STATISTICS_update (GDS_stats, + gettext_noop + ("# Peers excluded from routing due to Bloomfilter"), + 1, GNUNET_NO); #if DEBUG_DHT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Excluded peer `%s' due to BF match in random routing for %s\n", - GNUNET_i2s (&pos->id), - GNUNET_h2s (key)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Excluded peer `%s' due to BF match in random routing for %s\n", + GNUNET_i2s (&pos->id), GNUNET_h2s (key)); #endif pos = pos->next; continue; /* Ignore bloomfiltered peers */ @@ -1093,8 +1080,8 @@ select_peer (const GNUNET_HashCode *key, if (count == 0) /* No peers to select from! */ { GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Peer selection failed"), 1, - GNUNET_NO); + gettext_noop ("# Peer selection failed"), 1, + GNUNET_NO); return NULL; } /* Now actually choose a peer */ @@ -1105,9 +1092,9 @@ select_peer (const GNUNET_HashCode *key, pos = k_buckets[bc].head; while ((pos != NULL) && (count < bucket_size)) { - if ( (bloom != NULL) && - (GNUNET_YES == - GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) ) + if ((bloom != NULL) && + (GNUNET_YES == + GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))) { pos = pos->next; continue; /* Ignore bloomfiltered peers */ @@ -1136,11 +1123,10 @@ select_peer (const GNUNET_HashCode *key, * @return number of peers returned in 'targets'. */ static unsigned int -get_target_peers (const GNUNET_HashCode *key, - struct GNUNET_CONTAINER_BloomFilter *bloom, - uint32_t hop_count, - uint32_t target_replication, - struct PeerInfo ***targets) +get_target_peers (const GNUNET_HashCode * key, + struct GNUNET_CONTAINER_BloomFilter *bloom, + uint32_t hop_count, uint32_t target_replication, + struct PeerInfo ***targets) { unsigned int ret; unsigned int off; @@ -1154,25 +1140,23 @@ get_target_peers (const GNUNET_HashCode *key, *targets = NULL; return 0; } - rtargets = GNUNET_malloc (sizeof (struct PeerInfo*) * ret); + rtargets = GNUNET_malloc (sizeof (struct PeerInfo *) * ret); for (off = 0; off < ret; off++) { nxt = select_peer (key, bloom, hop_count); if (nxt == NULL) - break; + break; rtargets[off] = nxt; GNUNET_break (GNUNET_NO == - GNUNET_CONTAINER_bloomfilter_test (bloom, &nxt->id.hashPubKey)); + GNUNET_CONTAINER_bloomfilter_test (bloom, + &nxt->id.hashPubKey)); GNUNET_CONTAINER_bloomfilter_add (bloom, &rtargets[off]->id.hashPubKey); } #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Selected %u/%u peers at hop %u for %s (target was %u)\n", - off, - GNUNET_CONTAINER_multihashmap_size (all_known_peers), - (unsigned int) hop_count, - GNUNET_h2s (key), - ret); + "Selected %u/%u peers at hop %u for %s (target was %u)\n", off, + GNUNET_CONTAINER_multihashmap_size (all_known_peers), + (unsigned int) hop_count, GNUNET_h2s (key), ret); #endif if (0 == off) { @@ -1206,16 +1190,15 @@ get_target_peers (const GNUNET_HashCode *key, */ void GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, - enum GNUNET_DHT_RouteOption options, - uint32_t desired_replication_level, - struct GNUNET_TIME_Absolute expiration_time, - uint32_t hop_count, - struct GNUNET_CONTAINER_BloomFilter *bf, - const GNUNET_HashCode *key, - unsigned int put_path_length, - struct GNUNET_PeerIdentity *put_path, - const void *data, - size_t data_size) + enum GNUNET_DHT_RouteOption options, + uint32_t desired_replication_level, + struct GNUNET_TIME_Absolute expiration_time, + uint32_t hop_count, + struct GNUNET_CONTAINER_BloomFilter *bf, + const GNUNET_HashCode * key, + unsigned int put_path_length, + struct GNUNET_PeerIdentity *put_path, + const void *data, size_t data_size) { unsigned int target_count; unsigned int i; @@ -1225,33 +1208,32 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, size_t msize; struct PeerPutMessage *ppm; struct GNUNET_PeerIdentity *pp; - + GNUNET_assert (NULL != bf); #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Adding myself (%s) to PUT bloomfilter for %s\n", - GNUNET_i2s (&my_identity), - GNUNET_h2s (key)); + "Adding myself (%s) to PUT bloomfilter for %s\n", + GNUNET_i2s (&my_identity), GNUNET_h2s (key)); #endif GNUNET_CONTAINER_bloomfilter_add (bf, &my_identity.hashPubKey); - GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# PUT requests routed"), 1, - GNUNET_NO); - target_count = get_target_peers (key, bf, hop_count, - desired_replication_level, - &targets); + GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# PUT requests routed"), + 1, GNUNET_NO); + target_count = + get_target_peers (key, bf, hop_count, desired_replication_level, + &targets); if (0 == target_count) - { + { #if DEBUG_DHT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Routing PUT for %s terminates after %u hops at %s\n", - GNUNET_h2s (key), - (unsigned int) hop_count, - GNUNET_i2s (&my_identity)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Routing PUT for %s terminates after %u hops at %s\n", + GNUNET_h2s (key), (unsigned int) hop_count, + GNUNET_i2s (&my_identity)); #endif - return; - } - msize = put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size + sizeof (struct PeerPutMessage); + return; + } + msize = + put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size + + sizeof (struct PeerPutMessage); if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) { put_path_length = 0; @@ -1264,22 +1246,21 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, return; } GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# PUT messages queued for transmission"), target_count, - GNUNET_NO); - for (i=0;iid)); + "Routing PUT for %s after %u hops to %s\n", GNUNET_h2s (key), + (unsigned int) hop_count, GNUNET_i2s (&target->id)); #endif pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); - pending->importance = 0; /* FIXME */ - pending->timeout = expiration_time; - ppm = (struct PeerPutMessage*) &pending[1]; + pending->importance = 0; /* FIXME */ + pending->timeout = expiration_time; + ppm = (struct PeerPutMessage *) &pending[1]; pending->msg = &ppm->header; ppm->header.size = htons (msize); ppm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_PUT); @@ -1289,18 +1270,19 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, ppm->desired_replication_level = htonl (desired_replication_level); ppm->put_path_length = htonl (put_path_length); ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); - GNUNET_break (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &target->id.hashPubKey)); + GNUNET_break (GNUNET_YES == + GNUNET_CONTAINER_bloomfilter_test (bf, + &target->id.hashPubKey)); GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_bloomfilter_get_raw_data (bf, - ppm->bloomfilter, - DHT_BLOOM_SIZE)); + GNUNET_CONTAINER_bloomfilter_get_raw_data (bf, + ppm->bloomfilter, + DHT_BLOOM_SIZE)); ppm->key = *key; - pp = (struct GNUNET_PeerIdentity*) &ppm[1]; - memcpy (pp, put_path, sizeof (struct GNUNET_PeerIdentity) * put_path_length); + pp = (struct GNUNET_PeerIdentity *) &ppm[1]; + memcpy (pp, put_path, + sizeof (struct GNUNET_PeerIdentity) * put_path_length); memcpy (&pp[put_path_length], data, data_size); - GNUNET_CONTAINER_DLL_insert_tail (target->head, - target->tail, - pending); + GNUNET_CONTAINER_DLL_insert_tail (target->head, target->tail, pending); target->pending_count++; process_peer_queue (target); } @@ -1327,15 +1309,13 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, */ void GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, - enum GNUNET_DHT_RouteOption options, - uint32_t desired_replication_level, - uint32_t hop_count, - const GNUNET_HashCode *key, - const void *xquery, - size_t xquery_size, - const struct GNUNET_CONTAINER_BloomFilter *reply_bf, - uint32_t reply_bf_mutator, - struct GNUNET_CONTAINER_BloomFilter *peer_bf) + enum GNUNET_DHT_RouteOption options, + uint32_t desired_replication_level, + uint32_t hop_count, const GNUNET_HashCode * key, + const void *xquery, size_t xquery_size, + const struct GNUNET_CONTAINER_BloomFilter *reply_bf, + uint32_t reply_bf_mutator, + struct GNUNET_CONTAINER_BloomFilter *peer_bf) { unsigned int target_count; unsigned int i; @@ -1347,28 +1327,25 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, char *xq; size_t reply_bf_size; - GNUNET_assert (NULL != peer_bf); - GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# GET requests routed"), 1, - GNUNET_NO); - target_count = get_target_peers (key, peer_bf, hop_count, - desired_replication_level, - &targets); + GNUNET_assert (NULL != peer_bf); + GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# GET requests routed"), + 1, GNUNET_NO); + target_count = + get_target_peers (key, peer_bf, hop_count, desired_replication_level, + &targets); #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Adding myself (%s) to GET bloomfilter for %s\n", - GNUNET_i2s (&my_identity), - GNUNET_h2s (key)); + "Adding myself (%s) to GET bloomfilter for %s\n", + GNUNET_i2s (&my_identity), GNUNET_h2s (key)); #endif GNUNET_CONTAINER_bloomfilter_add (peer_bf, &my_identity.hashPubKey); if (0 == target_count) { #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Routing GET for %s terminates after %u hops at %s\n", - GNUNET_h2s (key), - (unsigned int) hop_count, - GNUNET_i2s (&my_identity)); + "Routing GET for %s terminates after %u hops at %s\n", + GNUNET_h2s (key), (unsigned int) hop_count, + GNUNET_i2s (&my_identity)); #endif return; } @@ -1381,23 +1358,22 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, return; } GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# GET messages queued for transmission"), target_count, - GNUNET_NO); + gettext_noop + ("# GET messages queued for transmission"), + target_count, GNUNET_NO); /* forward request */ - for (i=0;iid)); + "Routing GET for %s after %u hops to %s\n", GNUNET_h2s (key), + (unsigned int) hop_count, GNUNET_i2s (&target->id)); #endif - pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); - pending->importance = 0; /* FIXME */ + pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); + pending->importance = 0; /* FIXME */ pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); - pgm = (struct PeerGetMessage*) &pending[1]; + pgm = (struct PeerGetMessage *) &pending[1]; pending->msg = &pgm->header; pgm->header.size = htons (msize); pgm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_GET); @@ -1406,23 +1382,24 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, pgm->hop_count = htonl (hop_count + 1); pgm->desired_replication_level = htonl (desired_replication_level); pgm->xquery_size = htonl (xquery_size); - pgm->bf_mutator = reply_bf_mutator; - GNUNET_break (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (peer_bf, &target->id.hashPubKey)); + pgm->bf_mutator = reply_bf_mutator; + GNUNET_break (GNUNET_YES == + GNUNET_CONTAINER_bloomfilter_test (peer_bf, + &target->id.hashPubKey)); GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_bloomfilter_get_raw_data (peer_bf, - pgm->bloomfilter, - DHT_BLOOM_SIZE)); + GNUNET_CONTAINER_bloomfilter_get_raw_data (peer_bf, + pgm->bloomfilter, + DHT_BLOOM_SIZE)); pgm->key = *key; xq = (char *) &pgm[1]; memcpy (xq, xquery, xquery_size); if (NULL != reply_bf) GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_bloomfilter_get_raw_data (reply_bf, - &xq[xquery_size], - reply_bf_size)); - GNUNET_CONTAINER_DLL_insert_tail (target->head, - target->tail, - pending); + GNUNET_CONTAINER_bloomfilter_get_raw_data (reply_bf, + &xq + [xquery_size], + reply_bf_size)); + GNUNET_CONTAINER_DLL_insert_tail (target->head, target->tail, pending); target->pending_count++; process_peer_queue (target); } @@ -1448,46 +1425,49 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, */ void GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, - enum GNUNET_BLOCK_Type type, - struct GNUNET_TIME_Absolute expiration_time, - const GNUNET_HashCode *key, - unsigned int put_path_length, - const struct GNUNET_PeerIdentity *put_path, - unsigned int get_path_length, - const struct GNUNET_PeerIdentity *get_path, - const void *data, - size_t data_size) + enum GNUNET_BLOCK_Type type, + struct GNUNET_TIME_Absolute expiration_time, + const GNUNET_HashCode * key, + unsigned int put_path_length, + const struct GNUNET_PeerIdentity *put_path, + unsigned int get_path_length, + const struct GNUNET_PeerIdentity *get_path, + const void *data, size_t data_size) { struct PeerInfo *pi; struct P2PPendingMessage *pending; size_t msize; struct PeerResultMessage *prm; struct GNUNET_PeerIdentity *paths; - - msize = data_size + sizeof (struct PeerResultMessage) + - (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity); - if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || - (get_path_length > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) || - (put_path_length > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) || - (data_size > GNUNET_SERVER_MAX_MESSAGE_SIZE) ) + + msize = + data_size + sizeof (struct PeerResultMessage) + (get_path_length + + put_path_length) * + sizeof (struct GNUNET_PeerIdentity); + if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || + (get_path_length > + GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) || + (put_path_length > + GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) || + (data_size > GNUNET_SERVER_MAX_MESSAGE_SIZE)) { GNUNET_break (0); return; } - pi = GNUNET_CONTAINER_multihashmap_get (all_known_peers, - &target->hashPubKey); + pi = GNUNET_CONTAINER_multihashmap_get (all_known_peers, &target->hashPubKey); if (NULL == pi) { /* peer disconnected in the meantime, drop reply */ return; } GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# RESULT messages queued for transmission"), 1, - GNUNET_NO); - pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); - pending->importance = 0; /* FIXME */ + gettext_noop + ("# RESULT messages queued for transmission"), 1, + GNUNET_NO); + pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); + pending->importance = 0; /* FIXME */ pending->timeout = expiration_time; - prm = (struct PeerResultMessage*) &pending[1]; + prm = (struct PeerResultMessage *) &pending[1]; pending->msg = &prm->header; prm->header.size = htons (msize); prm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT); @@ -1496,15 +1476,13 @@ GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, prm->get_path_length = htonl (get_path_length); prm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); prm->key = *key; - paths = (struct GNUNET_PeerIdentity*) &prm[1]; - memcpy (paths, put_path, put_path_length * sizeof (struct GNUNET_PeerIdentity)); - memcpy (&paths[put_path_length], - get_path, get_path_length * sizeof (struct GNUNET_PeerIdentity)); - memcpy (&paths[put_path_length + get_path_length], - data, data_size); - GNUNET_CONTAINER_DLL_insert (pi->head, - pi->tail, - pending); + paths = (struct GNUNET_PeerIdentity *) &prm[1]; + memcpy (paths, put_path, + put_path_length * sizeof (struct GNUNET_PeerIdentity)); + memcpy (&paths[put_path_length], get_path, + get_path_length * sizeof (struct GNUNET_PeerIdentity)); + memcpy (&paths[put_path_length + get_path_length], data, data_size); + GNUNET_CONTAINER_DLL_insert (pi->head, pi->tail, pending); pi->pending_count++; process_peer_queue (pi); } @@ -1539,12 +1517,10 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server, * GNUNET_SYSERR to close it (signal serious error) */ static int -handle_dht_p2p_put (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information - *atsi, - unsigned int atsi_count) +handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_MessageHeader *message, + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { const struct PeerPutMessage *put; const struct GNUNET_PeerIdentity *put_path; @@ -1555,33 +1531,36 @@ handle_dht_p2p_put (void *cls, enum GNUNET_DHT_RouteOption options; struct GNUNET_CONTAINER_BloomFilter *bf; GNUNET_HashCode test_key; - + msize = ntohs (message->size); if (msize < sizeof (struct PeerPutMessage)) { GNUNET_break_op (0); return GNUNET_YES; } - put = (const struct PeerPutMessage*) message; + put = (const struct PeerPutMessage *) message; putlen = ntohl (put->put_path_length); - if ( (msize < sizeof (struct PeerPutMessage) + putlen * sizeof (struct GNUNET_PeerIdentity)) || - (putlen > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) ) - { - GNUNET_break_op (0); - return GNUNET_YES; - } + if ((msize < + sizeof (struct PeerPutMessage) + + putlen * sizeof (struct GNUNET_PeerIdentity)) || + (putlen > + GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) + { + GNUNET_break_op (0); + return GNUNET_YES; + } GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# P2P PUT requests received"), 1, - GNUNET_NO); - put_path = (const struct GNUNET_PeerIdentity*) &put[1]; + gettext_noop ("# P2P PUT requests received"), 1, + GNUNET_NO); + put_path = (const struct GNUNET_PeerIdentity *) &put[1]; payload = &put_path[putlen]; options = ntohl (put->options); - payload_size = msize - (sizeof (struct PeerPutMessage) + - putlen * sizeof (struct GNUNET_PeerIdentity)); - switch (GNUNET_BLOCK_get_key (GDS_block_context, - ntohl (put->type), - payload, payload_size, - &test_key)) + payload_size = + msize - (sizeof (struct PeerPutMessage) + + putlen * sizeof (struct GNUNET_PeerIdentity)); + switch (GNUNET_BLOCK_get_key + (GDS_block_context, ntohl (put->type), payload, payload_size, + &test_key)) { case GNUNET_YES: if (0 != memcmp (&test_key, &put->key, sizeof (GNUNET_HashCode))) @@ -1598,18 +1577,16 @@ handle_dht_p2p_put (void *cls, break; } #if DEBUG_DHT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "PUT for %s at %s\n", - GNUNET_h2s (&put->key), - GNUNET_i2s (&my_identity)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "PUT for %s at %s\n", + GNUNET_h2s (&put->key), GNUNET_i2s (&my_identity)); #endif - bf = GNUNET_CONTAINER_bloomfilter_init (put->bloomfilter, - DHT_BLOOM_SIZE, - GNUNET_CONSTANTS_BLOOMFILTER_K); - GNUNET_break_op (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &peer->hashPubKey)); + bf = GNUNET_CONTAINER_bloomfilter_init (put->bloomfilter, DHT_BLOOM_SIZE, + GNUNET_CONSTANTS_BLOOMFILTER_K); + GNUNET_break_op (GNUNET_YES == + GNUNET_CONTAINER_bloomfilter_test (bf, &peer->hashPubKey)); { - struct GNUNET_PeerIdentity pp[putlen+1]; - + struct GNUNET_PeerIdentity pp[putlen + 1]; + /* extend 'put path' by sender */ if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE)) { @@ -1619,37 +1596,23 @@ handle_dht_p2p_put (void *cls, } else putlen = 0; - + /* give to local clients */ GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (put->expiration_time), - &put->key, - 0, NULL, - putlen, - pp, - ntohl (put->type), - payload_size, - payload); + &put->key, 0, NULL, putlen, pp, ntohl (put->type), + payload_size, payload); /* store locally */ - if ( (0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || - (am_closest_peer (&put->key, - bf) ) ) - GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (put->expiration_time), - &put->key, - putlen, pp, - ntohl (put->type), - payload_size, - payload); + if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || + (am_closest_peer (&put->key, bf))) + GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh + (put->expiration_time), &put->key, putlen, pp, + ntohl (put->type), payload_size, payload); /* route to other peers */ - GDS_NEIGHBOURS_handle_put (ntohl (put->type), - options, - ntohl (put->desired_replication_level), - GNUNET_TIME_absolute_ntoh (put->expiration_time), - ntohl (put->hop_count), - bf, - &put->key, - putlen, pp, - payload, - payload_size); + GDS_NEIGHBOURS_handle_put (ntohl (put->type), options, + ntohl (put->desired_replication_level), + GNUNET_TIME_absolute_ntoh (put->expiration_time), + ntohl (put->hop_count), bf, &put->key, putlen, + pp, payload, payload_size); } GNUNET_CONTAINER_bloomfilter_free (bf); return GNUNET_YES; @@ -1667,9 +1630,8 @@ handle_dht_p2p_put (void *cls, */ static void handle_find_peer (const struct GNUNET_PeerIdentity *sender, - const GNUNET_HashCode *key, - struct GNUNET_CONTAINER_BloomFilter *bf, - uint32_t bf_mutator) + const GNUNET_HashCode * key, + struct GNUNET_CONTAINER_BloomFilter *bf, uint32_t bf_mutator) { int bucket_idx; struct PeerBucket *bucket; @@ -1682,30 +1644,31 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender, if (NULL != GDS_my_hello) { GNUNET_BLOCK_mingle_hash (&my_identity.hashPubKey, bf_mutator, &mhash); - if ( (NULL == bf) || - (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (bf, &mhash)) ) + if ((NULL == bf) || + (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (bf, &mhash))) { - GDS_NEIGHBOURS_handle_reply (sender, - GNUNET_BLOCK_TYPE_DHT_HELLO, - GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION), - key, - 0, NULL, - 0, NULL, - GDS_my_hello, - GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message*) GDS_my_hello)); + GDS_NEIGHBOURS_handle_reply (sender, GNUNET_BLOCK_TYPE_DHT_HELLO, + GNUNET_TIME_relative_to_absolute + (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION), + key, 0, NULL, 0, NULL, GDS_my_hello, + GNUNET_HELLO_size ((const struct + GNUNET_HELLO_Message *) + GDS_my_hello)); } else { GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# FIND PEER requests ignored due to Bloomfilter"), 1, - GNUNET_NO); + gettext_noop + ("# FIND PEER requests ignored due to Bloomfilter"), + 1, GNUNET_NO); } } else { GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# FIND PEER requests ignored due to lack of HELLO"), 1, - GNUNET_NO); + gettext_noop + ("# FIND PEER requests ignored due to lack of HELLO"), + 1, GNUNET_NO); } /* then, also consider sending a random HELLO from the closest bucket */ @@ -1718,8 +1681,8 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender, bucket = &k_buckets[bucket_idx]; if (bucket->peers_size == 0) return; - choice = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, - bucket->peers_size); + choice = + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, bucket->peers_size); peer = bucket->head; while (choice > 0) { @@ -1729,25 +1692,22 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender, } choice = bucket->peers_size; do - { - peer = peer->next; - if (choice-- == 0) - return; /* no non-masked peer available */ - if (peer == NULL) - peer = bucket->head; - GNUNET_BLOCK_mingle_hash (&peer->id.hashPubKey, bf_mutator, &mhash); - hello = GDS_HELLO_get (&peer->id); - } - while ( (hello == NULL) || - (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &mhash)) ); - GDS_NEIGHBOURS_handle_reply (sender, - GNUNET_BLOCK_TYPE_DHT_HELLO, - GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION), - key, - 0, NULL, - 0, NULL, - hello, - GNUNET_HELLO_size (hello)); + { + peer = peer->next; + if (choice-- == 0) + return; /* no non-masked peer available */ + if (peer == NULL) + peer = bucket->head; + GNUNET_BLOCK_mingle_hash (&peer->id.hashPubKey, bf_mutator, &mhash); + hello = GDS_HELLO_get (&peer->id); + } + while ((hello == NULL) || + (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &mhash))); + GDS_NEIGHBOURS_handle_reply (sender, GNUNET_BLOCK_TYPE_DHT_HELLO, + GNUNET_TIME_relative_to_absolute + (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION), key, + 0, NULL, 0, NULL, hello, + GNUNET_HELLO_size (hello)); } @@ -1765,10 +1725,9 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender, */ static int handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information - *atsi, - unsigned int atsi_count) + const struct GNUNET_MessageHeader *message, + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { struct PeerGetMessage *get; uint32_t xquery_size; @@ -1781,7 +1740,9 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_CONTAINER_BloomFilter *peer_bf; const char *xquery; - GNUNET_break (0 != memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity))); + GNUNET_break (0 != + memcmp (peer, &my_identity, + sizeof (struct GNUNET_PeerIdentity))); /* parse and validate message */ msize = ntohs (message->size); if (msize < sizeof (struct PeerGetMessage)) @@ -1797,24 +1758,20 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, return GNUNET_YES; } GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# P2P GET requests received"), 1, - GNUNET_NO); + gettext_noop ("# P2P GET requests received"), 1, + GNUNET_NO); reply_bf_size = msize - (sizeof (struct PeerGetMessage) + xquery_size); type = ntohl (get->type); options = ntohl (get->options); - xquery = (const char*) &get[1]; + xquery = (const char *) &get[1]; reply_bf = NULL; if (reply_bf_size > 0) - reply_bf = GNUNET_CONTAINER_bloomfilter_init (&xquery[xquery_size], - reply_bf_size, - GNUNET_CONSTANTS_BLOOMFILTER_K); - eval = GNUNET_BLOCK_evaluate (GDS_block_context, - type, - &get->key, - &reply_bf, - get->bf_mutator, - xquery, xquery_size, - NULL, 0); + reply_bf = + GNUNET_CONTAINER_bloomfilter_init (&xquery[xquery_size], reply_bf_size, + GNUNET_CONSTANTS_BLOOMFILTER_K); + eval = + GNUNET_BLOCK_evaluate (GDS_block_context, type, &get->key, &reply_bf, + get->bf_mutator, xquery, xquery_size, NULL, 0); if (eval != GNUNET_BLOCK_EVALUATION_REQUEST_VALID) { /* request invalid or block type not supported */ @@ -1824,70 +1781,55 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, return GNUNET_YES; } peer_bf = - GNUNET_CONTAINER_bloomfilter_init (get->bloomfilter, - DHT_BLOOM_SIZE, - GNUNET_CONSTANTS_BLOOMFILTER_K); - GNUNET_break_op (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (peer_bf, &peer->hashPubKey)); + GNUNET_CONTAINER_bloomfilter_init (get->bloomfilter, DHT_BLOOM_SIZE, + GNUNET_CONSTANTS_BLOOMFILTER_K); + GNUNET_break_op (GNUNET_YES == + GNUNET_CONTAINER_bloomfilter_test (peer_bf, + &peer->hashPubKey)); /* remember request for routing replies */ - GDS_ROUTING_add (peer, - type, - options, - &get->key, - xquery, xquery_size, - reply_bf, get->bf_mutator); + GDS_ROUTING_add (peer, type, options, &get->key, xquery, xquery_size, + reply_bf, get->bf_mutator); #if DEBUG_DHT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "GET for %s at %s after %u hops\n", - GNUNET_h2s (&get->key), - GNUNET_i2s (&my_identity), - (unsigned int) ntohl (get->hop_count)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GET for %s at %s after %u hops\n", + GNUNET_h2s (&get->key), GNUNET_i2s (&my_identity), + (unsigned int) ntohl (get->hop_count)); #endif /* local lookup (this may update the reply_bf) */ - if ( (0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || - (am_closest_peer (&get->key, - peer_bf) ) ) - { - if ( (0 != (options & GNUNET_DHT_RO_FIND_PEER))) + if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || + (am_closest_peer (&get->key, peer_bf))) + { + if ((0 != (options & GNUNET_DHT_RO_FIND_PEER))) { GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# P2P FIND PEER requests processed"), 1, - GNUNET_NO); - handle_find_peer (peer, - &get->key, - reply_bf, - get->bf_mutator); + gettext_noop + ("# P2P FIND PEER requests processed"), 1, + GNUNET_NO); + handle_find_peer (peer, &get->key, reply_bf, get->bf_mutator); } else { - eval = GDS_DATACACHE_handle_get (&get->key, - type, - xquery, xquery_size, - &reply_bf, - get->bf_mutator); + eval = + GDS_DATACACHE_handle_get (&get->key, type, xquery, xquery_size, + &reply_bf, get->bf_mutator); } } else { GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# P2P GET requests ONLY routed"), 1, - GNUNET_NO); + gettext_noop ("# P2P GET requests ONLY routed"), + 1, GNUNET_NO); } - + /* P2P forwarding */ if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST) - GDS_NEIGHBOURS_handle_get (type, - options, - ntohl (get->desired_replication_level), - ntohl (get->hop_count), - &get->key, - xquery, xquery_size, - reply_bf, - get->bf_mutator, - peer_bf); + GDS_NEIGHBOURS_handle_get (type, options, + ntohl (get->desired_replication_level), + ntohl (get->hop_count), &get->key, xquery, + xquery_size, reply_bf, get->bf_mutator, peer_bf); /* clean up */ if (NULL != reply_bf) GNUNET_CONTAINER_bloomfilter_free (reply_bf); - GNUNET_CONTAINER_bloomfilter_free (peer_bf); + GNUNET_CONTAINER_bloomfilter_free (peer_bf); return GNUNET_YES; } @@ -1904,10 +1846,9 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, */ static int handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information - *atsi, - unsigned int atsi_count) + const struct GNUNET_MessageHeader *message, + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { const struct PeerResultMessage *prm; const struct GNUNET_PeerIdentity *put_path; @@ -1918,7 +1859,7 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer, uint16_t msize; size_t data_size; enum GNUNET_BLOCK_Type type; - + /* parse and validate message */ msize = ntohs (message->size); if (msize < sizeof (struct PeerResultMessage)) @@ -1929,23 +1870,28 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer, prm = (struct PeerResultMessage *) message; put_path_length = ntohl (prm->put_path_length); get_path_length = ntohl (prm->get_path_length); - if ( (msize < sizeof (struct PeerResultMessage) + - (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity)) || - (get_path_length > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) || - (put_path_length > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) ) + if ((msize < + sizeof (struct PeerResultMessage) + (get_path_length + + put_path_length) * + sizeof (struct GNUNET_PeerIdentity)) || + (get_path_length > + GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) || + (put_path_length > + GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) { GNUNET_break_op (0); return GNUNET_YES; - } - GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# P2P RESULTS received"), 1, - GNUNET_NO); - put_path = (const struct GNUNET_PeerIdentity*) &prm[1]; + } + GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P RESULTS received"), + 1, GNUNET_NO); + put_path = (const struct GNUNET_PeerIdentity *) &prm[1]; get_path = &put_path[put_path_length]; type = ntohl (prm->type); - data = (const void*) &get_path[get_path_length]; - data_size = msize - (sizeof (struct PeerResultMessage) + - (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity)); + data = (const void *) &get_path[get_path_length]; + data_size = + msize - (sizeof (struct PeerResultMessage) + + (get_path_length + + put_path_length) * sizeof (struct GNUNET_PeerIdentity)); /* if we got a HELLO, consider it for our own routing table */ if (type == GNUNET_BLOCK_TYPE_DHT_HELLO) @@ -1967,8 +1913,7 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer, return GNUNET_YES; } if (GNUNET_OK != - GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message*) h, - &pid)) + GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) h, &pid)) { GNUNET_break_op (0); return GNUNET_YES; @@ -1976,49 +1921,35 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer, if (0 != memcmp (&my_identity, &pid, sizeof (struct GNUNET_PeerIdentity))) { bucket = find_bucket (&pid.hashPubKey); - if ( (bucket >= 0) && - (k_buckets[bucket].peers_size < bucket_size) ) - { - if (NULL != GDS_transport_handle) - { - GNUNET_TRANSPORT_offer_hello (GDS_transport_handle, - h, NULL, NULL); - GNUNET_TRANSPORT_try_connect (GDS_transport_handle, - &pid); - } - } + if ((bucket >= 0) && (k_buckets[bucket].peers_size < bucket_size)) + { + if (NULL != GDS_transport_handle) + { + GNUNET_TRANSPORT_offer_hello (GDS_transport_handle, h, NULL, NULL); + GNUNET_TRANSPORT_try_connect (GDS_transport_handle, &pid); + } + } } } /* append 'peer' to 'get_path' */ - { - struct GNUNET_PeerIdentity xget_path[get_path_length+1]; + { + struct GNUNET_PeerIdentity xget_path[get_path_length + 1]; - memcpy (xget_path, get_path, get_path_length * sizeof (struct GNUNET_PeerIdentity)); + memcpy (xget_path, get_path, + get_path_length * sizeof (struct GNUNET_PeerIdentity)); xget_path[get_path_length] = *peer; get_path_length++; - /* forward to local clients */ + /* forward to local clients */ GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (prm->expiration_time), - &prm->key, - get_path_length, - xget_path, - put_path_length, - put_path, - type, - data_size, - data); + &prm->key, get_path_length, xget_path, + put_path_length, put_path, type, data_size, data); /* forward to other peers */ - GDS_ROUTING_process (type, - GNUNET_TIME_absolute_ntoh (prm->expiration_time), - &prm->key, - put_path_length, - put_path, - get_path_length, - xget_path, - data, - data_size); + GDS_ROUTING_process (type, GNUNET_TIME_absolute_ntoh (prm->expiration_time), + &prm->key, put_path_length, put_path, get_path_length, + xget_path, data, data_size); } return GNUNET_YES; } @@ -2039,21 +1970,16 @@ GDS_NEIGHBOURS_init () {NULL, 0, 0} }; unsigned long long temp_config_num; - + if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (GDS_cfg, "DHT", "bucket_size", &temp_config_num)) - bucket_size = (unsigned int) temp_config_num; + bucket_size = (unsigned int) temp_config_num; atsAPI = GNUNET_ATS_performance_init (GDS_cfg, NULL, NULL); - coreAPI = GNUNET_CORE_connect (GDS_cfg, - 1, - NULL, - &core_init, - &handle_core_connect, - &handle_core_disconnect, - NULL, GNUNET_NO, - NULL, GNUNET_NO, - core_handlers); + coreAPI = + GNUNET_CORE_connect (GDS_cfg, 1, NULL, &core_init, &handle_core_connect, + &handle_core_disconnect, NULL, GNUNET_NO, NULL, + GNUNET_NO, core_handlers); if (coreAPI == NULL) return GNUNET_SYSERR; all_known_peers = GNUNET_CONTAINER_multihashmap_create (256); @@ -2070,9 +1996,9 @@ GDS_NEIGHBOURS_done () if (coreAPI == NULL) return; GNUNET_CORE_disconnect (coreAPI); - coreAPI = NULL; + coreAPI = NULL; GNUNET_ATS_performance_done (atsAPI); - atsAPI = NULL; + atsAPI = NULL; GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (all_known_peers)); GNUNET_CONTAINER_multihashmap_destroy (all_known_peers); all_known_peers = NULL; diff --git a/src/dht/gnunet-service-dht_neighbours.h b/src/dht/gnunet-service-dht_neighbours.h index d23ea10ab..b6e0f0ec0 100644 --- a/src/dht/gnunet-service-dht_neighbours.h +++ b/src/dht/gnunet-service-dht_neighbours.h @@ -52,16 +52,15 @@ */ void GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, - enum GNUNET_DHT_RouteOption options, - uint32_t desired_replication_level, - struct GNUNET_TIME_Absolute expiration_time, - uint32_t hop_count, - struct GNUNET_CONTAINER_BloomFilter *bf, - const GNUNET_HashCode *key, - unsigned int put_path_length, - struct GNUNET_PeerIdentity *put_path, - const void *data, - size_t data_size); + enum GNUNET_DHT_RouteOption options, + uint32_t desired_replication_level, + struct GNUNET_TIME_Absolute expiration_time, + uint32_t hop_count, + struct GNUNET_CONTAINER_BloomFilter *bf, + const GNUNET_HashCode * key, + unsigned int put_path_length, + struct GNUNET_PeerIdentity *put_path, + const void *data, size_t data_size); /** @@ -83,15 +82,13 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, */ void GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, - enum GNUNET_DHT_RouteOption options, - uint32_t desired_replication_level, - uint32_t hop_count, - const GNUNET_HashCode *key, - const void *xquery, - size_t xquery_size, - const struct GNUNET_CONTAINER_BloomFilter *reply_bf, - uint32_t reply_bf_mutator, - struct GNUNET_CONTAINER_BloomFilter *peer_bf); + enum GNUNET_DHT_RouteOption options, + uint32_t desired_replication_level, + uint32_t hop_count, const GNUNET_HashCode * key, + const void *xquery, size_t xquery_size, + const struct GNUNET_CONTAINER_BloomFilter *reply_bf, + uint32_t reply_bf_mutator, + struct GNUNET_CONTAINER_BloomFilter *peer_bf); /** @@ -112,15 +109,14 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, */ void GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, - enum GNUNET_BLOCK_Type type, - struct GNUNET_TIME_Absolute expiration_time, - const GNUNET_HashCode *key, - unsigned int put_path_length, - const struct GNUNET_PeerIdentity *put_path, - unsigned int get_path_length, - const struct GNUNET_PeerIdentity *get_path, - const void *data, - size_t data_size); + enum GNUNET_BLOCK_Type type, + struct GNUNET_TIME_Absolute expiration_time, + const GNUNET_HashCode * key, + unsigned int put_path_length, + const struct GNUNET_PeerIdentity *put_path, + unsigned int get_path_length, + const struct GNUNET_PeerIdentity *get_path, + const void *data, size_t data_size); /** diff --git a/src/dht/gnunet-service-dht_nse.c b/src/dht/gnunet-service-dht_nse.c index 0a662ec7b..777998967 100644 --- a/src/dht/gnunet-service-dht_nse.c +++ b/src/dht/gnunet-service-dht_nse.c @@ -56,10 +56,10 @@ update_network_size_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp, double logestimate, double std_dev) { GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Network size estimates received"), 1, - GNUNET_NO); + gettext_noop ("# Network size estimates received"), + 1, GNUNET_NO); /* do not allow estimates < 0.5 */ - log_of_network_size_estimate = GNUNET_MAX (0.5, logestimate); + log_of_network_size_estimate = GNUNET_MAX (0.5, logestimate); } @@ -90,9 +90,9 @@ GDS_NSE_init () */ void GDS_NSE_done () -{ +{ if (NULL != nse) - { + { GNUNET_NSE_disconnect (nse); nse = NULL; } diff --git a/src/dht/gnunet-service-dht_routing.c b/src/dht/gnunet-service-dht_routing.c index 607c756c6..a880bf7cd 100644 --- a/src/dht/gnunet-service-dht_routing.c +++ b/src/dht/gnunet-service-dht_routing.c @@ -66,7 +66,7 @@ struct RecentRequest * Type of the requested block. */ enum GNUNET_BLOCK_Type type; - + /** * extended query (see gnunet_block_lib.h). Allocated at the * end of this struct. @@ -114,7 +114,7 @@ struct ProcessContext /** * Path of the reply. - */ + */ const struct GNUNET_PeerIdentity *get_path; /** @@ -156,13 +156,11 @@ struct ProcessContext * @param cls the 'struct ProcessContext' with the result * @param key the query * @param value the 'struct RecentRequest' with the request - * @return GNUNET_OK (continue to iterate), + * @return GNUNET_OK (continue to iterate), * GNUNET_SYSERR if the result is malformed or type unsupported */ static int -process (void *cls, - const GNUNET_HashCode *key, - void *value) +process (void *cls, const GNUNET_HashCode * key, void *value) { struct ProcessContext *pc = cls; struct RecentRequest *rr = value; @@ -172,9 +170,8 @@ process (void *cls, GNUNET_HashCode hc; const GNUNET_HashCode *eval_key; - if ( (rr->type != GNUNET_BLOCK_TYPE_ANY) && - (rr->type != pc->type) ) - return GNUNET_OK; /* type missmatch */ + if ((rr->type != GNUNET_BLOCK_TYPE_ANY) && (rr->type != pc->type)) + return GNUNET_OK; /* type missmatch */ if (0 != (rr->options & GNUNET_DHT_RO_RECORD_ROUTE)) { @@ -186,59 +183,48 @@ process (void *cls, gpl = 0; ppl = 0; } - if ( (0 != (rr->options & GNUNET_DHT_RO_FIND_PEER)) && - (pc->type == GNUNET_BLOCK_TYPE_DHT_HELLO) ) + if ((0 != (rr->options & GNUNET_DHT_RO_FIND_PEER)) && + (pc->type == GNUNET_BLOCK_TYPE_DHT_HELLO)) { /* key may not match HELLO, which is OK since - the search is approximate. Still, the evaluation - would fail since the match is not exact. So - we fake it by changing the key to the actual PID ... */ - GNUNET_BLOCK_get_key (GDS_block_context, - GNUNET_BLOCK_TYPE_DHT_HELLO, - pc->data, pc->data_size, - &hc); + * the search is approximate. Still, the evaluation + * would fail since the match is not exact. So + * we fake it by changing the key to the actual PID ... */ + GNUNET_BLOCK_get_key (GDS_block_context, GNUNET_BLOCK_TYPE_DHT_HELLO, + pc->data, pc->data_size, &hc); eval_key = &hc; } else { eval_key = key; } - eval = GNUNET_BLOCK_evaluate (GDS_block_context, - pc->type, - eval_key, - &rr->reply_bf, - rr->reply_bf_mutator, - rr->xquery, - rr->xquery_size, - pc->data, - pc->data_size); + eval = + GNUNET_BLOCK_evaluate (GDS_block_context, pc->type, eval_key, + &rr->reply_bf, rr->reply_bf_mutator, rr->xquery, + rr->xquery_size, pc->data, pc->data_size); switch (eval) { case GNUNET_BLOCK_EVALUATION_OK_MORE: case GNUNET_BLOCK_EVALUATION_OK_LAST: GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Good REPLIES matched against routing table"), 1, - GNUNET_NO); - GDS_NEIGHBOURS_handle_reply (&rr->peer, - pc->type, - pc->expiration_time, - key, - ppl, - pc->put_path, - gpl, - pc->get_path, - pc->data, - pc->data_size); + gettext_noop + ("# Good REPLIES matched against routing table"), + 1, GNUNET_NO); + GDS_NEIGHBOURS_handle_reply (&rr->peer, pc->type, pc->expiration_time, key, + ppl, pc->put_path, gpl, pc->get_path, pc->data, + pc->data_size); break; case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Duplicate REPLIES matched against routing table"), 1, - GNUNET_NO); + gettext_noop + ("# Duplicate REPLIES matched against routing table"), + 1, GNUNET_NO); return GNUNET_OK; case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Invalid REPLIES matched against routing table"), 1, - GNUNET_NO); + gettext_noop + ("# Invalid REPLIES matched against routing table"), + 1, GNUNET_NO); return GNUNET_SYSERR; case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID: @@ -246,12 +232,13 @@ process (void *cls, return GNUNET_OK; case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Unsupported REPLIES matched against routing table"), 1, - GNUNET_NO); + gettext_noop + ("# Unsupported REPLIES matched against routing table"), + 1, GNUNET_NO); return GNUNET_SYSERR; default: GNUNET_break (0); - return GNUNET_SYSERR; + return GNUNET_SYSERR; } return GNUNET_OK; } @@ -276,14 +263,12 @@ process (void *cls, */ void GDS_ROUTING_process (enum GNUNET_BLOCK_Type type, - struct GNUNET_TIME_Absolute expiration_time, - const GNUNET_HashCode *key, - unsigned int put_path_length, - const struct GNUNET_PeerIdentity *put_path, - unsigned int get_path_length, - const struct GNUNET_PeerIdentity *get_path, - const void *data, - size_t data_size) + struct GNUNET_TIME_Absolute expiration_time, + const GNUNET_HashCode * key, unsigned int put_path_length, + const struct GNUNET_PeerIdentity *put_path, + unsigned int get_path_length, + const struct GNUNET_PeerIdentity *get_path, + const void *data, size_t data_size) { struct ProcessContext pc; @@ -295,10 +280,7 @@ GDS_ROUTING_process (enum GNUNET_BLOCK_Type type, pc.get_path = get_path; pc.data = data; pc.data_size = data_size; - GNUNET_CONTAINER_multihashmap_get_multiple (recent_map, - key, - &process, - &pc); + GNUNET_CONTAINER_multihashmap_get_multiple (recent_map, key, &process, &pc); } @@ -316,21 +298,21 @@ GDS_ROUTING_process (enum GNUNET_BLOCK_Type type, */ void GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender, - enum GNUNET_BLOCK_Type type, - enum GNUNET_DHT_RouteOption options, - const GNUNET_HashCode *key, - const void *xquery, - size_t xquery_size, - const struct GNUNET_CONTAINER_BloomFilter *reply_bf, - uint32_t reply_bf_mutator) + enum GNUNET_BLOCK_Type type, + enum GNUNET_DHT_RouteOption options, + const GNUNET_HashCode * key, const void *xquery, + size_t xquery_size, + const struct GNUNET_CONTAINER_BloomFilter *reply_bf, + uint32_t reply_bf_mutator) { struct RecentRequest *recent_req; while (GNUNET_CONTAINER_heap_get_size (recent_heap) >= DHT_MAX_RECENT) { GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Entries removed from routing table"), 1, - GNUNET_NO); + gettext_noop + ("# Entries removed from routing table"), 1, + GNUNET_NO); recent_req = GNUNET_CONTAINER_heap_peek (recent_heap); GNUNET_assert (recent_req != NULL); GNUNET_CONTAINER_heap_remove_node (recent_req->heap_node); @@ -339,25 +321,22 @@ GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender, } GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Entries added to routing table"), 1, - GNUNET_NO); + gettext_noop ("# Entries added to routing table"), + 1, GNUNET_NO); recent_req = GNUNET_malloc (sizeof (struct RecentRequest) + xquery_size); recent_req->peer = *sender; recent_req->key = *key; recent_req->heap_node = - GNUNET_CONTAINER_heap_insert (recent_heap, recent_req, - GNUNET_TIME_absolute_get ().abs_value); - recent_req->reply_bf = - GNUNET_CONTAINER_bloomfilter_copy (reply_bf); + GNUNET_CONTAINER_heap_insert (recent_heap, recent_req, + GNUNET_TIME_absolute_get ().abs_value); + recent_req->reply_bf = GNUNET_CONTAINER_bloomfilter_copy (reply_bf); recent_req->type = type; recent_req->options = options; recent_req->xquery = &recent_req[1]; recent_req->xquery_size = xquery_size; recent_req->reply_bf_mutator = reply_bf_mutator; - GNUNET_CONTAINER_multihashmap_put (recent_map, - key, - recent_req, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); + GNUNET_CONTAINER_multihashmap_put (recent_map, key, recent_req, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); } @@ -369,10 +348,8 @@ GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender, void GDS_ROUTING_init () { - recent_heap = - GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); - recent_map = - GNUNET_CONTAINER_multihashmap_create (DHT_MAX_RECENT * 4 / 3); + recent_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); + recent_map = GNUNET_CONTAINER_multihashmap_create (DHT_MAX_RECENT * 4 / 3); } @@ -387,8 +364,9 @@ GDS_ROUTING_done () while (GNUNET_CONTAINER_heap_get_size (recent_heap) > 0) { GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# Entries removed from routing table"), 1, - GNUNET_NO); + gettext_noop + ("# Entries removed from routing table"), 1, + GNUNET_NO); recent_req = GNUNET_CONTAINER_heap_peek (recent_heap); GNUNET_assert (recent_req != NULL); GNUNET_CONTAINER_heap_remove_node (recent_req->heap_node); diff --git a/src/dht/gnunet-service-dht_routing.h b/src/dht/gnunet-service-dht_routing.h index a2576a3bb..9b12c71de 100644 --- a/src/dht/gnunet-service-dht_routing.h +++ b/src/dht/gnunet-service-dht_routing.h @@ -50,14 +50,12 @@ */ void GDS_ROUTING_process (enum GNUNET_BLOCK_Type type, - struct GNUNET_TIME_Absolute expiration_time, - const GNUNET_HashCode *key, - unsigned int put_path_length, - const struct GNUNET_PeerIdentity *put_path, - unsigned int get_path_length, - const struct GNUNET_PeerIdentity *get_path, - const void *data, - size_t data_size); + struct GNUNET_TIME_Absolute expiration_time, + const GNUNET_HashCode * key, unsigned int put_path_length, + const struct GNUNET_PeerIdentity *put_path, + unsigned int get_path_length, + const struct GNUNET_PeerIdentity *get_path, + const void *data, size_t data_size); /** @@ -74,13 +72,12 @@ GDS_ROUTING_process (enum GNUNET_BLOCK_Type type, */ void GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender, - enum GNUNET_BLOCK_Type type, - enum GNUNET_DHT_RouteOption options, - const GNUNET_HashCode *key, - const void *xquery, - size_t xquery_size, - const struct GNUNET_CONTAINER_BloomFilter *reply_bf, - uint32_t reply_bf_mutator); + enum GNUNET_BLOCK_Type type, + enum GNUNET_DHT_RouteOption options, + const GNUNET_HashCode * key, const void *xquery, + size_t xquery_size, + const struct GNUNET_CONTAINER_BloomFilter *reply_bf, + uint32_t reply_bf_mutator); /** diff --git a/src/dht/test_dht_2dtorus.c b/src/dht/test_dht_2dtorus.c index 220554e15..1db351841 100644 --- a/src/dht/test_dht_2dtorus.c +++ b/src/dht/test_dht_2dtorus.c @@ -138,7 +138,8 @@ shutdown_callback (void *cls, const char *emsg) else { #if VERBOSE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: All peers successfully shut down!\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "test: All peers successfully shut down!\n"); #endif } } @@ -169,22 +170,21 @@ disconnect_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { unsigned int i; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: disconnecting peers\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: disconnecting peers\n"); disconnect_task = GNUNET_SCHEDULER_NO_TASK; GNUNET_SCHEDULER_cancel (put_task); if (NULL != get_h) - GNUNET_DHT_get_stop(get_h); + GNUNET_DHT_get_stop (get_h); if (NULL != get_h_2) - GNUNET_DHT_get_stop(get_h_2); + GNUNET_DHT_get_stop (get_h_2); if (NULL != get_h_far) - GNUNET_DHT_get_stop(get_h_far); - for (i = 0; i < num_peers; i++) + GNUNET_DHT_get_stop (get_h_far); + for (i = 0; i < num_peers; i++) { - GNUNET_DHT_disconnect(hs[i]); + GNUNET_DHT_disconnect (hs[i]); } GNUNET_SCHEDULER_cancel (shutdown_handle); - shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL); + shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); } static void @@ -193,44 +193,39 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, const struct GNUNET_PeerIdentity *get_path, unsigned int get_path_length, const struct GNUNET_PeerIdentity *put_path, - unsigned int put_path_length, - enum GNUNET_BLOCK_Type type, size_t size, const void *data) + unsigned int put_path_length, enum GNUNET_BLOCK_Type type, + size_t size, const void *data) { int i; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: ************* FOUND!!! ***********\n"); - if (sizeof(GNUNET_HashCode) == size) + "test: ************* FOUND!!! ***********\n"); + if (sizeof (GNUNET_HashCode) == size) { const GNUNET_HashCode *h = data; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: Contents: %s\n", + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Contents: %s\n", GNUNET_h2s_full (h)); } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: PATH: (get %u, put %u)\n", - get_path_length, - put_path_length); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: LOCAL\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: PATH: (get %u, put %u)\n", + get_path_length, put_path_length); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: LOCAL\n"); for (i = get_path_length - 1; i >= 0; i--) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: %s\n", - GNUNET_i2s (&get_path[i])); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: %s\n", + GNUNET_i2s (&get_path[i])); } for (i = put_path_length - 1; i >= 0; i--) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: %s\n", - GNUNET_i2s (&put_path[i])); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: %s\n", + GNUNET_i2s (&put_path[i])); } found++; if (found < 3) return; ok = 0; - GNUNET_SCHEDULER_cancel(disconnect_task); + GNUNET_SCHEDULER_cancel (disconnect_task); disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_peers, NULL); } @@ -263,7 +258,7 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) if (strcmp (id_aux, id_near2) == 0) d2 = aux; } - if ( (NULL == o) || (NULL == d) || (NULL == d2) || (NULL == d_far)) + if ((NULL == o) || (NULL == d) || (NULL == d2) || (NULL == d_far)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "test: Peers not found (hostkey file changed?)\n"); @@ -272,55 +267,39 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) return; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n"); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: looking for %s\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n", GNUNET_h2s_full (&d->id.hashPubKey)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: looking for %s\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n", GNUNET_h2s_full (&d2->id.hashPubKey)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: looking for %s\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n", GNUNET_h2s_full (&d_far->id.hashPubKey)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: from %s\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: from %s\n", GNUNET_h2s_full (&o->id.hashPubKey)); found = 0; - get_h = GNUNET_DHT_get_start (hs[0], - GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ - GNUNET_BLOCK_TYPE_TEST, /* type */ - &d->id.hashPubKey, /*key to search */ - 4U, /* replication level */ - GNUNET_DHT_RO_RECORD_ROUTE | - GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, - NULL, /* xquery */ - 0, /* xquery bits */ - &dht_get_id_handler, - NULL); - get_h_2 = GNUNET_DHT_get_start (hs[0], - GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ - GNUNET_BLOCK_TYPE_TEST, /* type */ + get_h = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ + GNUNET_BLOCK_TYPE_TEST, /* type */ + &d->id.hashPubKey, /*key to search */ + 4U, /* replication level */ + GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ + 0, /* xquery bits */ + &dht_get_id_handler, NULL); + get_h_2 = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ + GNUNET_BLOCK_TYPE_TEST, /* type */ &d2->id.hashPubKey, /*key to search */ - 4U, /* replication level */ - GNUNET_DHT_RO_RECORD_ROUTE | - GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, - NULL, /* xquery */ - 0, /* xquery bits */ - &dht_get_id_handler, - NULL); - get_h_far = GNUNET_DHT_get_start (hs[0], - GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ - GNUNET_BLOCK_TYPE_TEST, /* type */ - &d_far->id.hashPubKey, /*key to search */ - 4U, /* replication level */ - GNUNET_DHT_RO_RECORD_ROUTE | - GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, - NULL, /* xquery */ - 0, /* xquery bits */ - &dht_get_id_handler, - NULL); + 4U, /* replication level */ + GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ + 0, /* xquery bits */ + &dht_get_id_handler, NULL); + get_h_far = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ + GNUNET_BLOCK_TYPE_TEST, /* type */ + &d_far->id.hashPubKey, /*key to search */ + 4U, /* replication level */ + GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ + 0, /* xquery bits */ + &dht_get_id_handler, NULL); GNUNET_SCHEDULER_cancel (disconnect_task); - disconnect_task = GNUNET_SCHEDULER_add_delayed(GET_TIMEOUT, - &disconnect_peers, NULL); + disconnect_task = + GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &disconnect_peers, NULL); } @@ -331,28 +310,20 @@ put_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) unsigned int i; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: putting id's in DHT\n"); - for (i = 0; i < num_peers; i++) + for (i = 0; i < num_peers; i++) { d = GNUNET_TESTING_daemon_get (pg, i); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: putting into DHT: %s\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: putting into DHT: %s\n", GNUNET_h2s_full (&d->id.hashPubKey)); - GNUNET_DHT_put(hs[i], - &d->id.hashPubKey, - 10U, - GNUNET_DHT_RO_RECORD_ROUTE | - GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, - GNUNET_BLOCK_TYPE_TEST, - sizeof(struct GNUNET_PeerIdentity), - (const char *) &d->id, - GNUNET_TIME_UNIT_FOREVER_ABS, - GNUNET_TIME_UNIT_FOREVER_REL, - NULL, - NULL); + GNUNET_DHT_put (hs[i], &d->id.hashPubKey, 10U, + GNUNET_DHT_RO_RECORD_ROUTE | + GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, + GNUNET_BLOCK_TYPE_TEST, sizeof (struct GNUNET_PeerIdentity), + (const char *) &d->id, GNUNET_TIME_UNIT_FOREVER_ABS, + GNUNET_TIME_UNIT_FOREVER_REL, NULL, NULL); } - put_task = GNUNET_SCHEDULER_add_delayed(PUT_FREQUENCY, - &put_id, NULL); + put_task = GNUNET_SCHEDULER_add_delayed (PUT_FREQUENCY, &put_id, NULL); } @@ -373,8 +344,8 @@ peergroup_ready (void *cls, const char *emsg) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Peergroup callback called with error, aborting test!\n"); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: Error from testing: `%s'\n", emsg); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Error from testing: `%s'\n", + emsg); ok++; GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); return; @@ -384,8 +355,7 @@ peergroup_ready (void *cls, const char *emsg) "************************************************************\n"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Peer Group started successfully!\n"); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: Have %u connections\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Have %u connections\n", total_connections); #endif @@ -398,24 +368,22 @@ peergroup_ready (void *cls, const char *emsg) GNUNET_free (buf); } peers_running = GNUNET_TESTING_daemons_running (pg); - + GNUNET_assert (peers_running == num_peers); - hs = GNUNET_malloc (num_peers * sizeof(struct GNUNET_DHT_Handle *)); - for (i = 0; i < num_peers; i++) + hs = GNUNET_malloc (num_peers * sizeof (struct GNUNET_DHT_Handle *)); + for (i = 0; i < num_peers; i++) { d = GNUNET_TESTING_daemon_get (pg, i); - hs[i] = GNUNET_DHT_connect(d->cfg, 32); + hs[i] = GNUNET_DHT_connect (d->cfg, 32); } - put_task = GNUNET_SCHEDULER_add_now(&put_id, NULL); + put_task = GNUNET_SCHEDULER_add_now (&put_id, NULL); test_task = - GNUNET_SCHEDULER_add_delayed( - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), - &do_test, NULL); - disconnect_task = - GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, - &disconnect_peers, + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, 2), &do_test, NULL); + disconnect_task = + GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &disconnect_peers, NULL); } @@ -446,14 +414,13 @@ connect_cb (void *cls, const struct GNUNET_PeerIdentity *first, if (emsg == NULL) { total_connections++; - GNUNET_PEER_intern(first); - GNUNET_PEER_intern(second); + GNUNET_PEER_intern (first); + GNUNET_PEER_intern (second); } else { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: Problem with new connection (%s)\n", - emsg); + "test: Problem with new connection (%s)\n", emsg); } } @@ -496,7 +463,7 @@ run (void *cls, char *const *args, const char *cfgfile, "num_peers", &num_peers)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Option TESTING:NUM_PEERS is required!\n"); + "Option TESTING:NUM_PEERS is required!\n"); return; } @@ -516,17 +483,17 @@ run (void *cls, char *const *args, const char *cfgfile, &data_filename)) { data_file = - GNUNET_DISK_file_open (data_filename, - GNUNET_DISK_OPEN_READWRITE | - GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE); + GNUNET_DISK_file_open (data_filename, + GNUNET_DISK_OPEN_READWRITE | + GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE); if (data_file == NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n", - data_filename); - GNUNET_free (data_filename); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n", + data_filename); + GNUNET_free (data_filename); + } } if (GNUNET_YES == @@ -552,7 +519,7 @@ run (void *cls, char *const *args, const char *cfgfile, hosts); GNUNET_assert (pg != NULL); shutdown_handle = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, NULL); } @@ -584,7 +551,8 @@ main (int xargc, char *xargv[]) NULL }; - GNUNET_PROGRAM_run (sizeof(argv)/sizeof(char*) - 1, argv, "test_dht_2dtorus", + GNUNET_PROGRAM_run (sizeof (argv) / sizeof (char *) - 1, argv, + "test_dht_2dtorus", gettext_noop ("Test dht in a small 2D torus."), options, &run, NULL); #if REMOVE_DIR diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c index 51f7d947c..e636c08ba 100644 --- a/src/dht/test_dht_api.c +++ b/src/dht/test_dht_api.c @@ -179,10 +179,10 @@ static void test_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, const GNUNET_HashCode * key, const struct GNUNET_PeerIdentity *get_path, - unsigned int get_path_length, + unsigned int get_path_length, const struct GNUNET_PeerIdentity *put_path, - unsigned int put_path_length, - enum GNUNET_BLOCK_Type type, size_t size, const void *data) + unsigned int put_path_length, enum GNUNET_BLOCK_Type type, + size_t size, const void *data) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test_get_iterator called (we got a result), stopping get request!\n"); @@ -213,9 +213,9 @@ test_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) peer->get_handle = GNUNET_DHT_get_start (peer->dht_handle, TOTAL_TIMEOUT, - GNUNET_BLOCK_TYPE_TEST, &hash, - 1, GNUNET_DHT_RO_NONE, NULL, - 0, &test_get_iterator, NULL); + GNUNET_BLOCK_TYPE_TEST, &hash, 1, + GNUNET_DHT_RO_NONE, NULL, 0, &test_get_iterator, + NULL); if (peer->get_handle == NULL) { @@ -250,8 +250,8 @@ test_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_assert (peer->dht_handle != NULL); - GNUNET_DHT_put (peer->dht_handle, &hash, 1, - GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_TEST, data_size, data, + GNUNET_DHT_put (peer->dht_handle, &hash, 1, GNUNET_DHT_RO_NONE, + GNUNET_BLOCK_TYPE_TEST, data_size, data, GNUNET_TIME_relative_to_absolute (TOTAL_TIMEOUT), TOTAL_TIMEOUT, &test_get, &p1); GNUNET_free (data); diff --git a/src/dht/test_dht_multipeer.c b/src/dht/test_dht_multipeer.c index 62833a583..f6519239b 100644 --- a/src/dht/test_dht_multipeer.c +++ b/src/dht/test_dht_multipeer.c @@ -95,12 +95,12 @@ struct TestPutContext struct TestGetContext { /** - * This is a linked list + * This is a linked list */ struct TestGetContext *next; /** - * This is a linked list + * This is a linked list */ struct TestGetContext *prev; @@ -220,9 +220,7 @@ shutdown_callback (void *cls, const char *emsg) { if (emsg != NULL) { - fprintf (stderr, - "Failed to shutdown testing topology: %s\n", - emsg); + fprintf (stderr, "Failed to shutdown testing topology: %s\n", emsg); if (ok == 0) ok = 2; } @@ -370,18 +368,18 @@ stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_free (sm); i = 0; while (stats[i].name != NULL) - { - fprintf (stderr, "Total : %12s/%50s = %12llu\n", stats[i].subsystem, - stats[i].name, (unsigned long long) stats[i].total); - i++; - } + { + fprintf (stderr, "Total : %12s/%50s = %12llu\n", stats[i].subsystem, + stats[i].name, (unsigned long long) stats[i].total); + i++; + } die_task = GNUNET_SCHEDULER_add_now (&do_stop, NULL); return; } sm->stat = GNUNET_STATISTICS_create ("", - GNUNET_TESTING_daemon_get (pg, - sm->daemon)->cfg); + GNUNET_TESTING_daemon_get (pg, + sm->daemon)->cfg); die_task = GNUNET_SCHEDULER_add_now (&stat_run, sm); } @@ -404,9 +402,7 @@ finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_SCHEDULER_cancel (test_put->task); if (test_put->dht_handle != NULL) GNUNET_DHT_disconnect (test_put->dht_handle); - GNUNET_CONTAINER_DLL_remove (all_puts_head, - all_puts_tail, - test_put); + GNUNET_CONTAINER_DLL_remove (all_puts_head, all_puts_tail, test_put); GNUNET_free (test_put); } @@ -418,16 +414,14 @@ finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_DHT_get_stop (test_get->get_handle); if (test_get->dht_handle != NULL) GNUNET_DHT_disconnect (test_get->dht_handle); - GNUNET_CONTAINER_DLL_remove (all_gets_head, - all_gets_tail, - test_get); + GNUNET_CONTAINER_DLL_remove (all_gets_head, all_gets_tail, test_get); GNUNET_free (test_get); } sm = GNUNET_malloc (sizeof (struct StatMaster)); sm->stat = - GNUNET_STATISTICS_create ("", - GNUNET_TESTING_daemon_get (pg, - sm->daemon)->cfg); + GNUNET_STATISTICS_create ("", + GNUNET_TESTING_daemon_get (pg, + sm->daemon)->cfg); die_task = GNUNET_SCHEDULER_add_now (&stat_run, sm); } @@ -445,18 +439,14 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) struct TestGetContext *test_get; die_task = GNUNET_SCHEDULER_NO_TASK; - fprintf (stderr, - "Failing test with error: `%s'!\n", - emsg); + fprintf (stderr, "Failing test with error: `%s'!\n", emsg); while (NULL != (test_put = all_puts_head)) { if (test_put->task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (test_put->task); if (test_put->dht_handle != NULL) GNUNET_DHT_disconnect (test_put->dht_handle); - GNUNET_CONTAINER_DLL_remove (all_puts_head, - all_puts_tail, - test_put); + GNUNET_CONTAINER_DLL_remove (all_puts_head, all_puts_tail, test_put); GNUNET_free (test_put); } @@ -468,9 +458,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_DHT_get_stop (test_get->get_handle); if (test_get->dht_handle != NULL) GNUNET_DHT_disconnect (test_get->dht_handle); - GNUNET_CONTAINER_DLL_remove (all_gets_head, - all_gets_tail, - test_get); + GNUNET_CONTAINER_DLL_remove (all_gets_head, all_gets_tail, test_get); GNUNET_free (test_get); } ok = 1; @@ -495,10 +483,8 @@ get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) if (test_get->succeeded != GNUNET_YES) { gets_failed++; - fprintf (stderr, - "Get from peer %s for key %s failed!\n", - GNUNET_i2s (&test_get->daemon->id), - GNUNET_h2s (&search_key)); + fprintf (stderr, "Get from peer %s for key %s failed!\n", + GNUNET_i2s (&test_get->daemon->id), GNUNET_h2s (&search_key)); } GNUNET_assert (test_get->get_handle != NULL); GNUNET_DHT_get_stop (test_get->get_handle); @@ -508,29 +494,25 @@ get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_DHT_disconnect (test_get->dht_handle); test_get->dht_handle = NULL; - GNUNET_CONTAINER_DLL_remove (all_gets_head, - all_gets_tail, - test_get); + GNUNET_CONTAINER_DLL_remove (all_gets_head, all_gets_tail, test_get); GNUNET_free (test_get); - if ((gets_failed > 10) && (outstanding_gets == 0)) + if ((gets_failed > 10) && (outstanding_gets == 0)) { /* Had more than 10% failures */ - fprintf (stderr, - "%llu gets succeeded, %llu gets failed!\n", - gets_completed, gets_failed); + fprintf (stderr, "%llu gets succeeded, %llu gets failed!\n", gets_completed, + gets_failed); GNUNET_SCHEDULER_cancel (die_task); - ok = 1; - die_task = GNUNET_SCHEDULER_add_now (&finish_testing, "not all gets succeeded"); + ok = 1; + die_task = + GNUNET_SCHEDULER_add_now (&finish_testing, "not all gets succeeded"); return; } - if ( (gets_completed + gets_failed == num_peers * num_peers) && - (outstanding_gets == 0) ) /* All gets successful */ + if ((gets_completed + gets_failed == num_peers * num_peers) && (outstanding_gets == 0)) /* All gets successful */ { - fprintf (stderr, - "%llu gets succeeded, %llu gets failed!\n", - gets_completed, gets_failed); + fprintf (stderr, "%llu gets succeeded, %llu gets failed!\n", gets_completed, + gets_failed); GNUNET_SCHEDULER_cancel (die_task); - ok = 0; + ok = 0; die_task = GNUNET_SCHEDULER_add_now (&finish_testing, NULL); } } @@ -550,10 +532,10 @@ static void get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, const GNUNET_HashCode * key, const struct GNUNET_PeerIdentity *get_path, - unsigned int get_path_length, + unsigned int get_path_length, const struct GNUNET_PeerIdentity *put_path, - unsigned int put_path_length, - enum GNUNET_BLOCK_Type type, size_t size, const void *data) + unsigned int put_path_length, enum GNUNET_BLOCK_Type type, + size_t size, const void *data) { struct TestGetContext *test_get = cls; GNUNET_HashCode search_key; /* Key stored under */ @@ -569,9 +551,8 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, { unsigned int i; - fprintf (stderr, "PUT (%u) Path: ", - test_get->uid); - for (i = 0; iuid); + for (i = 0; i < put_path_length; i++) fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&put_path[i])); fprintf (stderr, "\n"); } @@ -579,25 +560,22 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, { unsigned int i; - fprintf (stderr, "GET (%u) Path: ", - test_get->uid); + fprintf (stderr, "GET (%u) Path: ", test_get->uid); for (i = 0; i < get_path_length; i++) fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&get_path[i])); - fprintf (stderr, "%s%s\n", - get_path_length > 0 ? "->":"", - GNUNET_i2s (&test_get->daemon->id)); + fprintf (stderr, "%s%s\n", get_path_length > 0 ? "->" : "", + GNUNET_i2s (&test_get->daemon->id)); } #endif if ((0 != memcmp (&search_key, key, sizeof (GNUNET_HashCode))) || (0 != memcmp (original_data, data, sizeof (original_data)))) { - fprintf (stderr, - "Key or data is not the same as was inserted!\n"); + fprintf (stderr, "Key or data is not the same as was inserted!\n"); return; } gets_completed++; - test_get->succeeded = GNUNET_YES; + test_get->succeeded = GNUNET_YES; GNUNET_SCHEDULER_cancel (test_get->task); test_get->task = GNUNET_SCHEDULER_add_now (&get_stop_task, test_get); } @@ -615,7 +593,8 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) if (outstanding_gets > MAX_OUTSTANDING_GETS) { - test_get->task = GNUNET_SCHEDULER_add_delayed (GET_DELAY, &do_get, test_get); + test_get->task = + GNUNET_SCHEDULER_add_delayed (GET_DELAY, &do_get, test_get); return; } memset (data, test_get->uid, sizeof (data)); @@ -624,12 +603,11 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_assert (test_get->dht_handle != NULL); outstanding_gets++; test_get->get_handle = - GNUNET_DHT_get_start (test_get->dht_handle, GNUNET_TIME_UNIT_FOREVER_REL, - GNUNET_BLOCK_TYPE_TEST, &key, - 1, route_option, NULL, 0, - &get_result_iterator, test_get); + GNUNET_DHT_get_start (test_get->dht_handle, GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_BLOCK_TYPE_TEST, &key, 1, route_option, NULL, + 0, &get_result_iterator, test_get); test_get->task = - GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &get_stop_task, test_get); + GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &get_stop_task, test_get); } @@ -644,9 +622,7 @@ put_disconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) test_put->task = GNUNET_SCHEDULER_NO_TASK; GNUNET_DHT_disconnect (test_put->dht_handle); test_put->dht_handle = NULL; - GNUNET_CONTAINER_DLL_remove (all_puts_head, - all_puts_tail, - test_put); + GNUNET_CONTAINER_DLL_remove (all_puts_head, all_puts_tail, test_put); GNUNET_free (test_put); } @@ -661,23 +637,19 @@ start_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) unsigned long long j; struct TestGetContext *test_get; -#if VERBOSE - fprintf (stderr, - "Issuing %llu GETs\n", - (unsigned long long) (num_peers * num_peers)); +#if VERBOSE + fprintf (stderr, "Issuing %llu GETs\n", + (unsigned long long) (num_peers * num_peers)); #endif for (i = 0; i < num_peers; i++) for (j = 0; j < num_peers; j++) - { - test_get = GNUNET_malloc (sizeof (struct TestGetContext)); - test_get->uid = i + j*num_peers; - test_get->daemon = GNUNET_TESTING_daemon_get (pg, j); - GNUNET_CONTAINER_DLL_insert (all_gets_head, - all_gets_tail, - test_get); - test_get->task = GNUNET_SCHEDULER_add_now (&do_get, - test_get); - } + { + test_get = GNUNET_malloc (sizeof (struct TestGetContext)); + test_get->uid = i + j * num_peers; + test_get->daemon = GNUNET_TESTING_daemon_get (pg, j); + GNUNET_CONTAINER_DLL_insert (all_gets_head, all_gets_tail, test_get); + test_get->task = GNUNET_SCHEDULER_add_now (&do_get, test_get); + } } @@ -692,15 +664,12 @@ put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) outstanding_puts--; puts_completed++; GNUNET_SCHEDULER_cancel (test_put->task); - test_put->task = - GNUNET_SCHEDULER_add_now (&put_disconnect_task, test_put); + test_put->task = GNUNET_SCHEDULER_add_now (&put_disconnect_task, test_put); if (puts_completed != num_peers * num_peers) return; - + GNUNET_assert (outstanding_puts == 0); - GNUNET_SCHEDULER_add_delayed (START_DELAY, - &start_gets, - NULL); + GNUNET_SCHEDULER_add_delayed (START_DELAY, &start_gets, NULL); } @@ -717,7 +686,8 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) test_put->task = GNUNET_SCHEDULER_NO_TASK; if (outstanding_puts > MAX_OUTSTANDING_PUTS) { - test_put->task = GNUNET_SCHEDULER_add_delayed (PUT_DELAY, &do_put, test_put); + test_put->task = + GNUNET_SCHEDULER_add_delayed (PUT_DELAY, &do_put, test_put); return; } memset (data, test_put->uid, sizeof (data)); @@ -726,46 +696,43 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_assert (test_put->dht_handle != NULL); outstanding_puts++; #if VERBOSE > 2 - fprintf (stderr, "PUT %u at `%s'\n", - test_put->uid, - GNUNET_i2s (&test_put->daemon->id)); + fprintf (stderr, "PUT %u at `%s'\n", test_put->uid, + GNUNET_i2s (&test_put->daemon->id)); #endif - GNUNET_DHT_put (test_put->dht_handle, &key, 1, - route_option, GNUNET_BLOCK_TYPE_TEST, sizeof (data), data, + GNUNET_DHT_put (test_put->dht_handle, &key, 1, route_option, + GNUNET_BLOCK_TYPE_TEST, sizeof (data), data, GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL, &put_finished, test_put); test_put->task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, - &put_disconnect_task, test_put); + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, + &put_disconnect_task, test_put); } static void run_dht_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ +{ unsigned long long i; struct TestPutContext *test_put; #if PATH_TRACKING - route_option = GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE; + route_option = + GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE; #else route_option = GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE; #endif die_task = - GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, - "from setup puts/gets"); - fprintf (stderr, - "Issuing %llu PUTs (one per peer)\n", - (unsigned long long) (num_peers * num_peers)); + GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, + "from setup puts/gets"); + fprintf (stderr, "Issuing %llu PUTs (one per peer)\n", + (unsigned long long) (num_peers * num_peers)); for (i = 0; i < num_peers * num_peers; i++) { test_put = GNUNET_malloc (sizeof (struct TestPutContext)); test_put->uid = i; - test_put->daemon = GNUNET_TESTING_daemon_get (pg, i % num_peers); + test_put->daemon = GNUNET_TESTING_daemon_get (pg, i % num_peers); test_put->task = GNUNET_SCHEDULER_add_now (&do_put, test_put); - GNUNET_CONTAINER_DLL_insert (all_puts_head, - all_puts_tail, - test_put); + GNUNET_CONTAINER_DLL_insert (all_puts_head, all_puts_tail, test_put); } } @@ -782,17 +749,13 @@ startup_done (void *cls, const char *emsg) { if (emsg != NULL) { - fprintf (stderr, - "Failed to setup topology: %s\n", - emsg); - die_task = - GNUNET_SCHEDULER_add_now (&end_badly, - "topology setup failed"); + fprintf (stderr, "Failed to setup topology: %s\n", emsg); + die_task = GNUNET_SCHEDULER_add_now (&end_badly, "topology setup failed"); return; } die_task = - GNUNET_SCHEDULER_add_delayed (START_DELAY, &run_dht_test, - "from setup puts/gets"); + GNUNET_SCHEDULER_add_delayed (START_DELAY, &run_dht_test, + "from setup puts/gets"); } @@ -813,13 +776,8 @@ run (void *cls, char *const *args, const char *cfgfile, GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers", &num_peers)) num_peers = DEFAULT_NUM_PEERS; - pg = GNUNET_TESTING_peergroup_start (cfg, - num_peers, - TIMEOUT, - NULL, - &startup_done, - NULL, - NULL); + pg = GNUNET_TESTING_peergroup_start (cfg, num_peers, TIMEOUT, NULL, + &startup_done, NULL, NULL); GNUNET_assert (NULL != pg); } diff --git a/src/dht/test_dht_twopeer.c b/src/dht/test_dht_twopeer.c index 8947739c4..04198b48b 100644 --- a/src/dht/test_dht_twopeer.c +++ b/src/dht/test_dht_twopeer.c @@ -138,9 +138,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { const char *emsg = cls; - fprintf (stderr, - "Error: %s\n", - emsg); + fprintf (stderr, "Error: %s\n", emsg); if (curr_get_ctx.retry_task != GNUNET_SCHEDULER_NO_TASK) { GNUNET_SCHEDULER_cancel (curr_get_ctx.retry_task); @@ -175,10 +173,10 @@ static void get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, const GNUNET_HashCode * key, const struct GNUNET_PeerIdentity *get_path, - unsigned int get_path_length, + unsigned int get_path_length, const struct GNUNET_PeerIdentity *put_path, - unsigned int put_path_length, - enum GNUNET_BLOCK_Type type, size_t size, const void *data) + unsigned int put_path_length, enum GNUNET_BLOCK_Type type, + size_t size, const void *data) { struct PeerGetContext *get_context = cls; @@ -257,9 +255,9 @@ get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), GNUNET_BLOCK_TYPE_DHT_HELLO, - &get_context->peer->hashPubKey, - 1, GNUNET_DHT_RO_NONE, NULL, - 0, &get_result_iterator, get_context); + &get_context->peer->hashPubKey, 1, + GNUNET_DHT_RO_NONE, NULL, 0, &get_result_iterator, + get_context); } @@ -292,9 +290,9 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), GNUNET_BLOCK_TYPE_DHT_HELLO, - &get_context->peer->hashPubKey, - 1, GNUNET_DHT_RO_FIND_PEER, NULL, - 0, &get_result_iterator, get_context); + &get_context->peer->hashPubKey, 1, + GNUNET_DHT_RO_FIND_PEER, NULL, 0, + &get_result_iterator, get_context); } @@ -335,8 +333,8 @@ topology_callback (void *cls, const struct GNUNET_PeerIdentity *first, #endif GNUNET_SCHEDULER_cancel (die_task); die_task = - GNUNET_SCHEDULER_add_delayed (TIMEOUT, - &end_badly, "Timeout trying to GET"); + GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, + "Timeout trying to GET"); curr_get_ctx.dht_handle = peer1dht; curr_get_ctx.peer = &peer2id; @@ -383,9 +381,7 @@ peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id, { if (emsg != NULL) { - fprintf (stderr, - "Failed to start daemon: `%s'\n", - emsg); + fprintf (stderr, "Failed to start daemon: `%s'\n", emsg); return; } GNUNET_assert (id != NULL); diff --git a/src/dht/test_dht_twopeer_get_put.c b/src/dht/test_dht_twopeer_get_put.c index 2a79c9ffb..d0da778ea 100644 --- a/src/dht/test_dht_twopeer_get_put.c +++ b/src/dht/test_dht_twopeer_get_put.c @@ -215,12 +215,11 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) void get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, const GNUNET_HashCode * key, - const struct GNUNET_PeerIdentity *get_path, - unsigned int get_path_size, - const struct GNUNET_PeerIdentity *put_path, - unsigned int put_path_size, - enum GNUNET_BLOCK_Type type, size_t size, - const void *result_data) + const struct GNUNET_PeerIdentity *get_path, + unsigned int get_path_size, + const struct GNUNET_PeerIdentity *put_path, + unsigned int put_path_size, enum GNUNET_BLOCK_Type type, + size_t size, const void *result_data) { GNUNET_HashCode original_key; /* Key data was stored data under */ char original_data[4]; /* Made up data that was stored */ @@ -279,8 +278,8 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) #else GNUNET_BLOCK_TYPE_TEST, #endif - &key, 1, GNUNET_DHT_RO_NONE, - NULL, 0, &get_result_iterator, NULL); + &key, 1, GNUNET_DHT_RO_NONE, NULL, 0, + &get_result_iterator, NULL); GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), &do_put, NULL); } @@ -313,10 +312,9 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) memset (data, 43, sizeof (data)); /* Insert the data at the first peer */ - GNUNET_DHT_put (peer1dht, &key, 1, GNUNET_DHT_RO_NONE, - GNUNET_BLOCK_TYPE_TEST, sizeof (data), data, - GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL, - &put_finished, NULL); + GNUNET_DHT_put (peer1dht, &key, 1, GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_TEST, + sizeof (data), data, GNUNET_TIME_UNIT_FOREVER_ABS, + GNUNET_TIME_UNIT_FOREVER_REL, &put_finished, NULL); } #else diff --git a/src/dht/test_dht_twopeer_path_tracking.c b/src/dht/test_dht_twopeer_path_tracking.c index f2d86e38e..61a3df0a4 100644 --- a/src/dht/test_dht_twopeer_path_tracking.c +++ b/src/dht/test_dht_twopeer_path_tracking.c @@ -191,10 +191,10 @@ static void get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, const GNUNET_HashCode * key, const struct GNUNET_PeerIdentity *get_path, - unsigned int get_path_length, + unsigned int get_path_length, const struct GNUNET_PeerIdentity *put_path, - unsigned int put_path_length, - enum GNUNET_BLOCK_Type type, size_t size, const void *data) + unsigned int put_path_length, enum GNUNET_BLOCK_Type type, + size_t size, const void *data) { GNUNET_HashCode original_key; /* Key data was stored data under */ char original_data[4]; /* Made up data that was stored */ @@ -220,14 +220,14 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, if (put_path != NULL) { fprintf (stderr, "PUT Path: "); - for (i = 0; i", GNUNET_i2s (&put_path[i])); fprintf (stderr, "\n"); } if (get_path != NULL) { fprintf (stderr, "GET Path: "); - for (i = 0; i", GNUNET_i2s (&get_path[i])); fprintf (stderr, "\n"); } @@ -256,9 +256,9 @@ put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) memset (&key, 42, sizeof (GNUNET_HashCode)); /* Set the key to the same thing as when data was inserted */ global_get_handle = GNUNET_DHT_get_start (peer2dht, GNUNET_TIME_relative_get_forever (), - GNUNET_BLOCK_TYPE_TEST, &key, - 1, GNUNET_DHT_RO_RECORD_ROUTE, - NULL, 0, &get_result_iterator, NULL); + GNUNET_BLOCK_TYPE_TEST, &key, 1, + GNUNET_DHT_RO_RECORD_ROUTE, NULL, 0, + &get_result_iterator, NULL); } /** @@ -274,10 +274,10 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) memset (data, 43, sizeof (data)); /* Insert the data at the first peer */ - GNUNET_DHT_put (peer1dht, &key, 1, - GNUNET_DHT_RO_RECORD_ROUTE, GNUNET_BLOCK_TYPE_TEST, - sizeof (data), data, GNUNET_TIME_UNIT_FOREVER_ABS, - GNUNET_TIME_UNIT_FOREVER_REL, &put_finished, NULL); + GNUNET_DHT_put (peer1dht, &key, 1, GNUNET_DHT_RO_RECORD_ROUTE, + GNUNET_BLOCK_TYPE_TEST, sizeof (data), data, + GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL, + &put_finished, NULL); } /** diff --git a/src/dht/test_dht_twopeer_put_get.c b/src/dht/test_dht_twopeer_put_get.c index 44009c257..275a01a32 100644 --- a/src/dht/test_dht_twopeer_put_get.c +++ b/src/dht/test_dht_twopeer_put_get.c @@ -207,11 +207,10 @@ static void get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, const GNUNET_HashCode * key, const struct GNUNET_PeerIdentity *get_path, - unsigned int get_path_size, + unsigned int get_path_size, const struct GNUNET_PeerIdentity *put_path, - unsigned int put_path_size, - enum GNUNET_BLOCK_Type type, size_t size, - const void *result_data) + unsigned int put_path_size, enum GNUNET_BLOCK_Type type, + size_t size, const void *result_data) { GNUNET_HashCode original_key; /* Key data was stored data under */ char original_data[4]; /* Made up data that was stored */ @@ -254,10 +253,9 @@ put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) memset (&key, 42, sizeof (GNUNET_HashCode)); /* Set the key to the same thing as when data was inserted */ global_get_handle = - GNUNET_DHT_get_start (peer2dht, GNUNET_TIME_UNIT_FOREVER_REL, - GNUNET_BLOCK_TYPE_TEST, - &key, 1, GNUNET_DHT_RO_NONE, - NULL, 0, &get_result_iterator, NULL); + GNUNET_DHT_get_start (peer2dht, GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_BLOCK_TYPE_TEST, &key, 1, GNUNET_DHT_RO_NONE, + NULL, 0, &get_result_iterator, NULL); } @@ -274,10 +272,9 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) memset (data, 43, sizeof (data)); /* Insert the data at the first peer */ - GNUNET_DHT_put (peer1dht, &key, 1, GNUNET_DHT_RO_NONE, - GNUNET_BLOCK_TYPE_TEST, sizeof (data), data, - GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL, - &put_finished, NULL); + GNUNET_DHT_put (peer1dht, &key, 1, GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_TEST, + sizeof (data), data, GNUNET_TIME_UNIT_FOREVER_ABS, + GNUNET_TIME_UNIT_FOREVER_REL, &put_finished, NULL); } diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c index 7d86fc24c..60745070c 100644 --- a/src/dv/gnunet-service-dv.c +++ b/src/dv/gnunet-service-dv.c @@ -1349,13 +1349,13 @@ send_message_delayed (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) */ static uint32_t get_atsi_distance (const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { unsigned int i; - for (i=0;ivalue); + return ntohl (atsi->value); /* FIXME: we do not have distance data? Assume direct neighbor. */ return DIRECT_NEIGHBOR_COST; } @@ -1369,14 +1369,14 @@ get_atsi_distance (const struct GNUNET_ATS_Information *atsi, */ static struct GNUNET_TIME_Relative get_atsi_latency (const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { unsigned int i; - for (i=0;ivalue)); + ntohl (atsi->value)); GNUNET_break (0); /* how can we not have latency data? */ return GNUNET_TIME_UNIT_SECONDS; @@ -1398,7 +1398,7 @@ static int handle_dv_data_message (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { const p2p_dv_MESSAGE_Data *incoming = (const p2p_dv_MESSAGE_Data *) message; const struct GNUNET_MessageHeader *packed_message; @@ -2076,14 +2076,13 @@ static int handle_dv_gossip_message (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count); + unsigned int atsi_count); static int handle_dv_disconnect_message (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information - *atsi, - unsigned int atsi_count); + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count); /** End forward declarations **/ @@ -2658,10 +2657,10 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity *peer, atsi[1].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY); atsi[1].value = htonl ((uint32_t) referrer->pending_messages[i]. - latency.rel_value); + latency.rel_value); handle_dv_data_message (NULL, &referrer->pending_messages[i].sender, - referrer->pending_messages[i].message, - atsi, 2); + referrer->pending_messages[i].message, atsi, + 2); GNUNET_free (referrer->pending_messages[i].message); referrer->pending_messages[i].sender_id = 0; } @@ -2732,9 +2731,8 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity *peer, static int handle_dv_disconnect_message (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information - *atsi, - unsigned int atsi_count) + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { struct DirectNeighbor *referrer; struct DistantNeighbor *distant; @@ -2784,7 +2782,7 @@ static int handle_dv_gossip_message (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { struct DirectNeighbor *referrer; p2p_dv_MESSAGE_NeighborInfo *enc_message = @@ -3087,7 +3085,7 @@ process_peerinfo (void *cls, const struct GNUNET_PeerIdentity *peer, static void handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { struct DirectNeighbor *neighbor; struct DistantNeighbor *about; @@ -3294,8 +3292,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, GNUNET_SERVER_add_handlers (server, plugin_handlers); coreAPI = GNUNET_CORE_connect (cfg, 1, NULL, /* FIXME: anything we want to pass around? */ &core_init, &handle_core_connect, - &handle_core_disconnect, NULL, GNUNET_NO, - NULL, GNUNET_NO, core_handlers); + &handle_core_disconnect, NULL, GNUNET_NO, NULL, + GNUNET_NO, core_handlers); if (coreAPI == NULL) return; diff --git a/src/dv/plugin_transport_dv.c b/src/dv/plugin_transport_dv.c index 5e2a6bd6c..6b585f6cc 100644 --- a/src/dv/plugin_transport_dv.c +++ b/src/dv/plugin_transport_dv.c @@ -171,8 +171,8 @@ handle_dv_message_received (void *cls, struct GNUNET_PeerIdentity *sender, plugin->env->receive (plugin->env->cls, sender, (struct GNUNET_MessageHeader *) msg, - (const struct GNUNET_ATS_Information *) &ats, - 2, NULL, sender_address, sender_address_len); + (const struct GNUNET_ATS_Information *) &ats, 2, NULL, + sender_address, sender_address_len); } diff --git a/src/dv/test_transport_api_dv.c b/src/dv/test_transport_api_dv.c index 82b3cb235..0a3bbaa51 100644 --- a/src/dv/test_transport_api_dv.c +++ b/src/dv/test_transport_api_dv.c @@ -596,8 +596,8 @@ connect_notify_peer1 (void *cls, const struct GNUNET_PeerIdentity *peer, */ pos->peer2handle = GNUNET_CORE_connect (pos->peer2->cfg, 1, pos, &init_notify_peer2, - &connect_notify_peer2, NULL, NULL, - GNUNET_YES, NULL, GNUNET_YES, handlers); + &connect_notify_peer2, NULL, NULL, GNUNET_YES, + NULL, GNUNET_YES, handlers); } } @@ -646,8 +646,8 @@ send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) */ pos->peer1handle = GNUNET_CORE_connect (pos->peer1->cfg, 1, pos, &init_notify_peer1, - &connect_notify_peer1, NULL, NULL, GNUNET_NO, - NULL, GNUNET_NO, no_handlers); + &connect_notify_peer1, NULL, NULL, GNUNET_NO, NULL, + GNUNET_NO, no_handlers); GNUNET_assert (pos->peer1handle != NULL); @@ -936,8 +936,8 @@ peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id, new_peer = GNUNET_malloc (sizeof (struct PeerContext)); new_peer->peer_handle = - GNUNET_CORE_connect (cfg, 1, d, NULL, &all_connect_handler, NULL, - NULL, GNUNET_NO, NULL, GNUNET_NO, no_handlers); + GNUNET_CORE_connect (cfg, 1, d, NULL, &all_connect_handler, NULL, NULL, + GNUNET_NO, NULL, GNUNET_NO, no_handlers); new_peer->daemon = d; new_peer->next = all_peers; all_peers = new_peer; diff --git a/src/fragmentation/fragmentation.c b/src/fragmentation/fragmentation.c index ef3a57a87..47b8a1929 100644 --- a/src/fragmentation/fragmentation.c +++ b/src/fragmentation/fragmentation.c @@ -152,7 +152,7 @@ transmit_next (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) size = ntohs (fc->msg->size); if (bit == size / (fc->mtu - sizeof (struct FragmentHeader))) fsize = - (size % (fc->mtu - sizeof (struct FragmentHeader))) + + (size % (fc->mtu - sizeof (struct FragmentHeader))) + sizeof (struct FragmentHeader); else fsize = fc->mtu; diff --git a/src/fragmentation/test_fragmentation.c b/src/fragmentation/test_fragmentation.c index 8f0be87a5..1f7a1776a 100644 --- a/src/fragmentation/test_fragmentation.c +++ b/src/fragmentation/test_fragmentation.c @@ -65,8 +65,7 @@ static struct GNUNET_FRAGMENT_Context *frags[NUM_MSGS]; static GNUNET_SCHEDULER_TaskIdentifier shutdown_task; static void -do_shutdown (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { unsigned int i; @@ -80,7 +79,7 @@ do_shutdown (void *cls, continue; GNUNET_FRAGMENT_context_destroy (frags[i]); frags[i] = NULL; - } + } } @@ -103,8 +102,7 @@ proc_msgs (void *cls, const struct GNUNET_MessageHeader *hdr) fprintf (stderr, "."); #endif /* tolerate 10% loss, i.e. due to duplicate fragment IDs */ - if ( (total >= NUM_MSGS - (NUM_MSGS / 10)) && - (ret != 0) ) + if ((total >= NUM_MSGS - (NUM_MSGS / 10)) && (ret != 0)) { if (GNUNET_SCHEDULER_NO_TASK == shutdown_task) shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); diff --git a/src/fs/fs_file_information.c b/src/fs/fs_file_information.c index ce4f189a9..bb84b948e 100644 --- a/src/fs/fs_file_information.c +++ b/src/fs/fs_file_information.c @@ -437,7 +437,7 @@ GNUNET_FS_directory_scanner_default (void *cls, struct GNUNET_FS_Handle *h, */ struct MetaValueInformation { - + /** * Mime-type of data. */ @@ -481,21 +481,17 @@ struct MetaValueInformation * used in the main libextractor library and yielding * meta data). * @param type libextractor-type describing the meta data - * @param format basic format information about data + * @param format basic format information about data * @param data_mime_type mime-type of data (not of the original file); * can be NULL (if mime-type is not known) * @param data actual meta-data found * @param data_len number of bytes in data * @return 0 to continue extracting / iterating - */ + */ static int -update_metamap (void *cls, - const char *plugin_name, - enum EXTRACTOR_MetaType type, - enum EXTRACTOR_MetaFormat format, - const char *data_mime_type, - const char *data, - size_t data_len) +update_metamap (void *cls, const char *plugin_name, + enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, + const char *data_mime_type, const char *data, size_t data_len) { struct GNUNET_CONTAINER_MultiHashMap *map = cls; GNUNET_HashCode key; @@ -512,10 +508,10 @@ update_metamap (void *cls, mvi->type = type; mvi->format = format; GNUNET_CONTAINER_multihashmap_put (map, &key, mvi, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); } - mvi->frequency++; - return 0; + mvi->frequency++; + return 0; } @@ -524,7 +520,7 @@ update_metamap (void *cls, */ struct KeywordInformation { - + /** * Mime-type of keyword. */ @@ -581,37 +577,35 @@ struct EntryProcCls * @param fi information for publishing the file */ static void -dirproc_add (void *cls, const char *filename, - struct GNUNET_FS_FileInformation *fi) +dirproc_add (void *cls, const char *filename, + struct GNUNET_FS_FileInformation *fi) { struct EntryProcCls *dc = cls; unsigned int i; const char *kw; struct KeywordInformation *ki; GNUNET_HashCode key; - + GNUNET_assert (fi->next == NULL); GNUNET_assert (fi->dir == NULL); fi->next = dc->entries; dc->entries = fi; dc->count++; if (NULL != fi->meta) - GNUNET_CONTAINER_meta_data_iterate (fi->meta, - &update_metamap, - dc->metamap); - for (i=0;ikeywords->data.ksk.keywordCount;i++) + GNUNET_CONTAINER_meta_data_iterate (fi->meta, &update_metamap, dc->metamap); + for (i = 0; i < fi->keywords->data.ksk.keywordCount; i++) { - kw = fi->keywords->data.ksk.keywords[i]; - GNUNET_CRYPTO_hash (kw, strlen(kw), &key); + kw = fi->keywords->data.ksk.keywords[i]; + GNUNET_CRYPTO_hash (kw, strlen (kw), &key); ki = GNUNET_CONTAINER_multihashmap_get (dc->keywordmap, &key); if (ki == NULL) { ki = GNUNET_malloc (sizeof (struct KeywordInformation)); ki->keyword = &kw[1]; GNUNET_CONTAINER_multihashmap_put (dc->keywordmap, &key, ki, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); } - ki->frequency++; + ki->frequency++; } } @@ -633,7 +627,7 @@ struct ComputeDirectoryMetadataContext /** * Threshold to apply for adding meta data. - */ + */ unsigned int threshold; }; @@ -650,29 +644,22 @@ struct ComputeDirectoryMetadataContext * @return GNUNET_OK */ static int -compute_directory_metadata (void *cls, - const GNUNET_HashCode *key, - void *value) +compute_directory_metadata (void *cls, const GNUNET_HashCode * key, void *value) { struct ComputeDirectoryMetadataContext *cdmc = cls; struct MetaValueInformation *mvi = value; - if (mvi->frequency > cdmc->threshold) + if (mvi->frequency > cdmc->threshold) { if (mvi->type != EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME) - (void) GNUNET_CONTAINER_meta_data_insert (cdmc->meta, - "", - mvi->type, - mvi->format, - mvi->mime_type, - mvi->data, - mvi->data_size); - if ( (mvi->format == EXTRACTOR_METAFORMAT_UTF8) || - (mvi->format == EXTRACTOR_METAFORMAT_C_STRING) ) - GNUNET_FS_uri_ksk_add_keyword (cdmc->ksk, - mvi->data, - GNUNET_NO); - } + (void) GNUNET_CONTAINER_meta_data_insert (cdmc->meta, "", + mvi->type, mvi->format, + mvi->mime_type, mvi->data, + mvi->data_size); + if ((mvi->format == EXTRACTOR_METAFORMAT_UTF8) || + (mvi->format == EXTRACTOR_METAFORMAT_C_STRING)) + GNUNET_FS_uri_ksk_add_keyword (cdmc->ksk, mvi->data, GNUNET_NO); + } GNUNET_free (mvi); return GNUNET_OK; } @@ -680,7 +667,7 @@ compute_directory_metadata (void *cls, /** * Add keywords that occur in more than the threshold entries of the - * directory to the directory itself. + * directory to the directory itself. * * @param cls the 'struct ComputeDirectoryMetadataContext' * @param key unused @@ -688,17 +675,13 @@ compute_directory_metadata (void *cls, * @return GNUNET_OK */ static int -compute_directory_keywords (void *cls, - const GNUNET_HashCode *key, - void *value) +compute_directory_keywords (void *cls, const GNUNET_HashCode * key, void *value) { struct ComputeDirectoryMetadataContext *cdmc = cls; struct KeywordInformation *ki = value; - if (ki->frequency > cdmc->threshold) - (void) GNUNET_FS_uri_ksk_add_keyword (cdmc->ksk, - ki->keyword, - GNUNET_NO); + if (ki->frequency > cdmc->threshold) + (void) GNUNET_FS_uri_ksk_add_keyword (cdmc->ksk, ki->keyword, GNUNET_NO); GNUNET_free (ki); return GNUNET_OK; } @@ -751,36 +734,31 @@ GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h, dc.metamap = GNUNET_CONTAINER_multihashmap_create (64); dc.keywordmap = GNUNET_CONTAINER_multihashmap_create (64); /* update children to point to directory and generate statistics - on all meta data in children */ + * on all meta data in children */ scanner (scanner_cls, h, filename, do_index, bo, &dirproc_add, &dc, emsg); cdmc.meta = GNUNET_CONTAINER_meta_data_create (); cdmc.ksk = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); cdmc.ksk->type = ksk; - cdmc.threshold = 1 + dc.count / 2; /* 50% threshold for now */ + cdmc.threshold = 1 + dc.count / 2; /* 50% threshold for now */ GNUNET_FS_meta_data_make_directory (cdmc.meta); GNUNET_CONTAINER_multihashmap_iterate (dc.metamap, - &compute_directory_metadata, - &cdmc); + &compute_directory_metadata, &cdmc); GNUNET_CONTAINER_multihashmap_iterate (dc.keywordmap, - &compute_directory_keywords, - &cdmc); + &compute_directory_keywords, &cdmc); GNUNET_CONTAINER_multihashmap_destroy (dc.metamap); GNUNET_CONTAINER_multihashmap_destroy (dc.keywordmap); - GNUNET_FS_uri_ksk_add_keyword (cdmc.ksk, - GNUNET_FS_DIRECTORY_MIME, - GNUNET_NO); + GNUNET_FS_uri_ksk_add_keyword (cdmc.ksk, GNUNET_FS_DIRECTORY_MIME, GNUNET_NO); cksk = GNUNET_FS_uri_ksk_canonicalize (cdmc.ksk); /* remove keywords in children that are already in the - parent */ + * parent */ for (epos = dc.entries; NULL != epos; epos = epos->next) { - for (i=0;idata.ksk.keywordCount;i++) - { - kw = cksk->data.ksk.keywords[i]; - GNUNET_FS_uri_ksk_remove_keyword (epos->keywords, - &kw[1]); - } + for (i = 0; i < cksk->data.ksk.keywordCount; i++) + { + kw = cksk->data.ksk.keywords[i]; + GNUNET_FS_uri_ksk_remove_keyword (epos->keywords, &kw[1]); + } } ret = GNUNET_FS_file_information_create_empty_directory (h, client_info, cksk, diff --git a/src/fs/fs_uri.c b/src/fs/fs_uri.c index 2057a18f6..48fabc1fb 100644 --- a/src/fs/fs_uri.c +++ b/src/fs/fs_uri.c @@ -1033,9 +1033,8 @@ canonicalize_keyword (const char *in) wpos++; break; default: - if (isspace ((unsigned char) *rpos) || - isdigit ((unsigned char) *rpos) ) - break; + if (isspace ((unsigned char) *rpos) || isdigit ((unsigned char) *rpos)) + break; /* replace characters listed above with '_' */ *wpos = '_'; wpos++; @@ -1073,24 +1072,19 @@ GNUNET_FS_uri_ksk_canonicalize (const struct GNUNET_FS_Uri *uri) for (i = 0; i < kc; i++) { in = uri->data.ksk.keywords[i]; - GNUNET_FS_uri_ksk_add_keyword (ret, - &in[1], - (in[0] == '+') ? GNUNET_YES : GNUNET_NO); + GNUNET_FS_uri_ksk_add_keyword (ret, &in[1], + (in[0] == '+') ? GNUNET_YES : GNUNET_NO); sb = GNUNET_strdup (&in[1]); #define DELIMS " \\|\"'`/&@-_,.;!?+-*^$#~=[]{}()<>" for (tok = strtok (sb, DELIMS); NULL != tok; tok = strtok (NULL, DELIMS)) #undef DELIMS { - if (strlen(tok) < 3) - continue; - GNUNET_FS_uri_ksk_add_keyword (ret, - tok, - GNUNET_NO); + if (strlen (tok) < 3) + continue; + GNUNET_FS_uri_ksk_add_keyword (ret, tok, GNUNET_NO); cc = canonicalize_keyword (tok); if (strlen (cc) > 2) - GNUNET_FS_uri_ksk_add_keyword (ret, - cc, - GNUNET_NO); + GNUNET_FS_uri_ksk_add_keyword (ret, cc, GNUNET_NO); } GNUNET_free (sb); } diff --git a/src/fs/gnunet-fs.c b/src/fs/gnunet-fs.c index 9b3602d73..310c8a1ae 100644 --- a/src/fs/gnunet-fs.c +++ b/src/fs/gnunet-fs.c @@ -53,8 +53,7 @@ static int verbose; * @param tc unused */ static void -do_shutdown (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { GNUNET_FS_stop (fs); fs = NULL; @@ -70,18 +69,12 @@ do_shutdown (void *cls, * @return GNUNET_OK to continue iteration */ static int -print_indexed (void *cls, const char *filename, - const GNUNET_HashCode * file_id) +print_indexed (void *cls, const char *filename, const GNUNET_HashCode * file_id) { if (verbose) - fprintf (stdout, - "%s: %s\n", - GNUNET_h2s (file_id), - filename); + fprintf (stdout, "%s: %s\n", GNUNET_h2s (file_id), filename); else - fprintf (stdout, - "%s\n", - filename); + fprintf (stdout, "%s\n", filename); return GNUNET_OK; } @@ -100,18 +93,13 @@ run (void *cls, char *const *args, const char *cfgfile, { if (list_indexed_files) { - fs = GNUNET_FS_start (cfg, - "gnunet-fs", - NULL, NULL, - GNUNET_FS_FLAGS_NONE); + fs = GNUNET_FS_start (cfg, "gnunet-fs", NULL, NULL, GNUNET_FS_FLAGS_NONE); if (NULL == fs) { ret = 1; return; } - GNUNET_FS_get_indexed_files (fs, - &print_indexed, NULL, - &do_shutdown, NULL); + GNUNET_FS_get_indexed_files (fs, &print_indexed, NULL, &do_shutdown, NULL); } } @@ -134,8 +122,7 @@ main (int argc, char *const *argv) }; return (GNUNET_OK == GNUNET_PROGRAM_run (argc, argv, "gnunet-fs [OPTIONS]", - gettext_noop - ("Special file-sharing operations"), + gettext_noop ("Special file-sharing operations"), options, &run, NULL)) ? ret : 1; } diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c index 404993130..f588ee9c4 100644 --- a/src/fs/gnunet-service-fs.c +++ b/src/fs/gnunet-service-fs.c @@ -226,19 +226,20 @@ GSF_test_get_load_too_high_ (uint32_t priority) */ static void update_latencies (const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { unsigned int i; - for (i=0;itype) == GNUNET_ATS_QUALITY_NET_DELAY) return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, - ntohl (atsi->value)); + ntohl (atsi->value)); return GNUNET_TIME_UNIT_SECONDS; } @@ -354,8 +353,7 @@ get_latency (const struct GNUNET_ATS_Information *atsi, */ static void update_atsi (struct GSF_ConnectedPeer *cp, - const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) { struct GNUNET_TIME_Relative latency; @@ -402,7 +400,7 @@ peer_transmit_ready_cb (void *cls, size_t size, void *buf); */ static void ats_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer, - int32_t amount, struct GNUNET_TIME_Relative res_delay); + int32_t amount, struct GNUNET_TIME_Relative res_delay); /** @@ -425,11 +423,9 @@ schedule_transmission (struct GSF_PeerTransmitHandle *pth) if (0 != cp->inc_preference) { - GNUNET_ATS_change_preference (ats, - &target, - GNUNET_ATS_PREFERENCE_BANDWIDTH, - (double) cp->inc_preference, - GNUNET_ATS_PREFERENCE_END); + GNUNET_ATS_change_preference (ats, &target, GNUNET_ATS_PREFERENCE_BANDWIDTH, + (double) cp->inc_preference, + GNUNET_ATS_PREFERENCE_END); cp->inc_preference = 0; } @@ -442,9 +438,8 @@ schedule_transmission (struct GSF_PeerTransmitHandle *pth) /* reservation already done! */ pth->was_reserved = GNUNET_YES; cp->rc = - GNUNET_ATS_reserve_bandwidth (ats, &target, - DBLOCK_SIZE, - &ats_reserve_callback, cp); + GNUNET_ATS_reserve_bandwidth (ats, &target, DBLOCK_SIZE, + &ats_reserve_callback, cp); } GNUNET_assert (pth->cth == NULL); pth->cth_in_progress++; @@ -525,9 +520,8 @@ retry_reservation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_PEER_resolve (cp->ppd.pid, &target); cp->rc_delay_task = GNUNET_SCHEDULER_NO_TASK; cp->rc = - GNUNET_ATS_reserve_bandwidth (ats, &target, - DBLOCK_SIZE, - &ats_reserve_callback, cp); + GNUNET_ATS_reserve_bandwidth (ats, &target, DBLOCK_SIZE, + &ats_reserve_callback, cp); } @@ -543,15 +537,14 @@ retry_reservation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) */ static void ats_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer, - int32_t amount, struct GNUNET_TIME_Relative res_delay) + int32_t amount, struct GNUNET_TIME_Relative res_delay) { struct GSF_ConnectedPeer *cp = cls; struct GSF_PeerTransmitHandle *pth; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Reserved %d bytes / need to wait %llu ms for reservation\n", - (int) amount, - (unsigned long long) res_delay.rel_value); + "Reserved %d bytes / need to wait %llu ms for reservation\n", + (int) amount, (unsigned long long) res_delay.rel_value); cp->rc = NULL; if (0 == amount) { @@ -587,22 +580,20 @@ ats_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer, struct GSF_ConnectedPeer * GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { struct GSF_ConnectedPeer *cp; char *fn; uint32_t trust; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Connected to peer %s\n", - GNUNET_i2s (peer)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected to peer %s\n", + GNUNET_i2s (peer)); cp = GNUNET_malloc (sizeof (struct GSF_ConnectedPeer)); cp->ppd.pid = GNUNET_PEER_intern (peer); cp->ppd.transmission_delay = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_ZERO); cp->rc = - GNUNET_ATS_reserve_bandwidth (ats, peer, - DBLOCK_SIZE, - &ats_reserve_callback, cp); + GNUNET_ATS_reserve_bandwidth (ats, peer, DBLOCK_SIZE, + &ats_reserve_callback, cp); fn = get_trust_filename (peer); if ((GNUNET_DISK_file_test (fn) == GNUNET_YES) && (sizeof (trust) == GNUNET_DISK_fn_read (fn, &trust, sizeof (trust)))) @@ -613,11 +604,9 @@ GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer, GNUNET_CONTAINER_multihashmap_put (cp_map, &peer->hashPubKey, cp, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - GNUNET_STATISTICS_set (GSF_stats, - gettext_noop - ("# peers connected"), - GNUNET_CONTAINER_multihashmap_size (cp_map), - GNUNET_NO); + GNUNET_STATISTICS_set (GSF_stats, gettext_noop ("# peers connected"), + GNUNET_CONTAINER_multihashmap_size (cp_map), + GNUNET_NO); update_atsi (cp, atsi, atsi_count); GSF_push_start_ (cp); return cp; @@ -681,9 +670,8 @@ int GSF_handle_p2p_migration_stop_ (void *cls, const struct GNUNET_PeerIdentity *other, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information - *atsi, - unsigned int atsi_count) + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { struct GSF_ConnectedPeer *cp; const struct MigrationStopMessage *msm; @@ -697,9 +685,8 @@ GSF_handle_p2p_migration_stop_ (void *cls, return GNUNET_OK; } GNUNET_STATISTICS_update (GSF_stats, - gettext_noop - ("# migration stop messages received"), - 1, GNUNET_NO); + gettext_noop ("# migration stop messages received"), + 1, GNUNET_NO); bt = GNUNET_TIME_relative_ntoh (msm->duration); GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Migration of content to peer `%s' blocked for %llu ms\n"), @@ -841,8 +828,8 @@ get_randomized_delay () ret = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, GNUNET_CRYPTO_random_u32 - (GNUNET_CRYPTO_QUALITY_WEAK, - 2 * GSF_avg_latency.rel_value + 1)); + (GNUNET_CRYPTO_QUALITY_WEAK, + 2 * GSF_avg_latency.rel_value + 1)); GNUNET_STATISTICS_update (GSF_stats, gettext_noop ("# artificial delays introduced (ms)"), @@ -1179,7 +1166,7 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other, return NULL; } if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO)) - cp = GSF_peer_get_ ((const struct GNUNET_PeerIdentity*) &opt[bits++]); + cp = GSF_peer_get_ ((const struct GNUNET_PeerIdentity *) &opt[bits++]); else cp = cps; if (cp == NULL) @@ -1323,9 +1310,7 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other, 0) ? (const char *) &opt[bits] : NULL, bfsize, ntohl (gm->filter_mutator), 1 /* anonymity */ , - (uint32_t) priority, ttl, spid, - GNUNET_PEER_intern (other), - NULL, 0, /* replies_seen */ + (uint32_t) priority, ttl, spid, GNUNET_PEER_intern (other), NULL, 0, /* replies_seen */ &handle_p2p_reply, peerreq); GNUNET_assert (NULL != pr); peerreq->pr = pr; @@ -1547,11 +1532,9 @@ GSF_peer_disconnect_handler_ (void *cls, const struct GNUNET_PeerIdentity *peer) GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (cp_map, &peer->hashPubKey, cp)); - GNUNET_STATISTICS_set (GSF_stats, - gettext_noop - ("# peers connected"), - GNUNET_CONTAINER_multihashmap_size (cp_map), - GNUNET_NO); + GNUNET_STATISTICS_set (GSF_stats, gettext_noop ("# peers connected"), + GNUNET_CONTAINER_multihashmap_size (cp_map), + GNUNET_NO); if (NULL != cp->migration_pth) { GSF_peer_transmit_cancel_ (cp->migration_pth); diff --git a/src/fs/gnunet-service-fs_cp.h b/src/fs/gnunet-service-fs_cp.h index 8923513c7..a2cc5232c 100644 --- a/src/fs/gnunet-service-fs_cp.h +++ b/src/fs/gnunet-service-fs_cp.h @@ -174,7 +174,7 @@ struct GSF_PeerTransmitHandle; struct GSF_ConnectedPeer * GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count); + unsigned int atsi_count); /** @@ -270,9 +270,8 @@ int GSF_handle_p2p_migration_stop_ (void *cls, const struct GNUNET_PeerIdentity *other, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information - *atsi, - unsigned int atsi_count); + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count); /** diff --git a/src/fs/gnunet-service-fs_indexing.c b/src/fs/gnunet-service-fs_indexing.c index 5978e4d66..41a40e125 100644 --- a/src/fs/gnunet-service-fs_indexing.c +++ b/src/fs/gnunet-service-fs_indexing.c @@ -538,13 +538,12 @@ GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key, uint32_t size, odb = (const struct OnDemandBlock *) data; off = GNUNET_ntohll (odb->offset); fn = (const char *) GNUNET_CONTAINER_multihashmap_get (ifm, &odb->file_id); - if ( (NULL == fn) || - (0 != ACCESS (fn, R_OK)) ) + if ((NULL == fn) || (0 != ACCESS (fn, R_OK))) { GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# index blocks removed: original file inaccessible"), - 1, - GNUNET_YES); + gettext_noop + ("# index blocks removed: original file inaccessible"), + 1, GNUNET_YES); GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL); return GNUNET_SYSERR; diff --git a/src/fs/gnunet-service-fs_lc.c b/src/fs/gnunet-service-fs_lc.c index 9f284ed8f..30a7f57d6 100644 --- a/src/fs/gnunet-service-fs_lc.c +++ b/src/fs/gnunet-service-fs_lc.c @@ -375,7 +375,8 @@ GSF_local_client_start_search_handler_ (struct GNUNET_SERVER_Client *client, ntohl (sm->anonymity_level), 0 /* priority */ , 0 /* ttl */ , - 0 /* sender PID */ , 0 /* origin PID */, + 0 /* sender PID */ , + 0 /* origin PID */ , (const GNUNET_HashCode *) &sm[1], sc, &client_response_handler, cr); return cr->pr; diff --git a/src/fs/gnunet-service-fs_pe.c b/src/fs/gnunet-service-fs_pe.c index 088a3dc11..41dd61a64 100644 --- a/src/fs/gnunet-service-fs_pe.c +++ b/src/fs/gnunet-service-fs_pe.c @@ -263,22 +263,25 @@ plan (struct PeerPlan *pp, struct GSF_RequestPlan *rp) if (rp->transmission_counter < 8) delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, - rp->transmission_counter); + rp->transmission_counter); else if (rp->transmission_counter < 32) delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, - 8 + (1LL << (rp->transmission_counter - 8))); + 8 + + (1LL << (rp->transmission_counter - 8))); else - delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, - 8 + (1LL << 24)); - delay.rel_value = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, - delay.rel_value + 1); + delay = + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, + 8 + (1LL << 24)); + delay.rel_value = + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, + delay.rel_value + 1); if (rp->transmission_counter != 0) delay.rel_value += TTL_DECREMENT; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Considering (re)transmission number %u in %llu ms\n", - (unsigned int) rp->transmission_counter, - (unsigned long long) delay.rel_value); + "Considering (re)transmission number %u in %llu ms\n", + (unsigned int) rp->transmission_counter, + (unsigned long long) delay.rel_value); rp->earliest_transmission = GNUNET_TIME_relative_to_absolute (delay); #if DEBUG_FS GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -295,9 +298,9 @@ plan (struct PeerPlan *pp, struct GSF_RequestPlan *rp) GNUNET_CONTAINER_heap_insert (pp->delay_heap, rp, rp->earliest_transmission.abs_value); GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_contains_value (pp->plan_map, - get_rp_key (rp), - rp)); + GNUNET_CONTAINER_multihashmap_contains_value (pp->plan_map, + get_rp_key (rp), + rp)); if (GNUNET_SCHEDULER_NO_TASK != pp->task) GNUNET_SCHEDULER_cancel (pp->task); pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp); @@ -351,8 +354,9 @@ transmit_message_callback (void *cls, size_t buf_size, void *buf) /* failed, try again... */ pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp); GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# transmission failed (core has no bandwidth)"), 1, - GNUNET_NO); + gettext_noop + ("# transmission failed (core has no bandwidth)"), + 1, GNUNET_NO); return 0; } rp = GNUNET_CONTAINER_heap_peek (pp->priority_heap); @@ -433,22 +437,17 @@ schedule_peer_transmission (void *cls, #if DEBUG_FS GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sleeping for %llu ms before retrying requests on plan %p.\n", - (unsigned long long) - delay.rel_value, pp); + (unsigned long long) delay.rel_value, pp); #endif - GNUNET_STATISTICS_set (GSF_stats, - gettext_noop ("# delay heap timeout"), - delay.rel_value, - GNUNET_NO); - + GNUNET_STATISTICS_set (GSF_stats, gettext_noop ("# delay heap timeout"), + delay.rel_value, GNUNET_NO); + pp->task = - GNUNET_SCHEDULER_add_delayed (delay, - &schedule_peer_transmission, pp); + GNUNET_SCHEDULER_add_delayed (delay, &schedule_peer_transmission, pp); return; } - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# query plans executed"), 1, - GNUNET_NO); + GNUNET_STATISTICS_update (GSF_stats, gettext_noop ("# query plans executed"), + 1, GNUNET_NO); /* process from priority heap */ rp = GNUNET_CONTAINER_heap_peek (pp->priority_heap); #if DEBUG_FS > 1 @@ -488,9 +487,7 @@ struct MergeContext * GNUNET_NO if not (merge success) */ static int -merge_pr (void *cls, - const GNUNET_HashCode *query, - void *element) +merge_pr (void *cls, const GNUNET_HashCode * query, void *element) { struct MergeContext *mpr = cls; struct GSF_RequestPlan *rp = element; @@ -550,8 +547,7 @@ GSF_plan_add_ (struct GSF_ConnectedPeer *cp, struct GSF_PendingRequest *pr) if (NULL == pp) { pp = GNUNET_malloc (sizeof (struct PeerPlan)); - pp->plan_map = - GNUNET_CONTAINER_multihashmap_create (128); + pp->plan_map = GNUNET_CONTAINER_multihashmap_create (128); pp->priority_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX); pp->delay_heap = @@ -563,13 +559,13 @@ GSF_plan_add_ (struct GSF_ConnectedPeer *cp, struct GSF_PendingRequest *pr) mpc.merged = GNUNET_NO; mpc.pr = pr; GNUNET_CONTAINER_multihashmap_get_multiple (pp->plan_map, - &GSF_pending_request_get_data_ (pr)->query, - &merge_pr, &mpc); + &GSF_pending_request_get_data_ + (pr)->query, &merge_pr, &mpc); if (mpc.merged != GNUNET_NO) return; GNUNET_CONTAINER_multihashmap_get_multiple (pp->plan_map, - &GSF_pending_request_get_data_ (pr)->query, - &merge_pr, &mpc); + &GSF_pending_request_get_data_ + (pr)->query, &merge_pr, &mpc); if (mpc.merged != GNUNET_NO) return; plan_count++; @@ -592,10 +588,9 @@ GSF_plan_add_ (struct GSF_ConnectedPeer *cp, struct GSF_PendingRequest *pr) GNUNET_CONTAINER_DLL_insert (rp->prl_head, rp->prl_tail, prl); rp->pp = pp; GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_put (pp->plan_map, - get_rp_key (rp), - rp, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); + GNUNET_CONTAINER_multihashmap_put (pp->plan_map, + get_rp_key (rp), rp, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); plan (pp, rp); } @@ -632,9 +627,8 @@ GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp) while (NULL != (rp = GNUNET_CONTAINER_heap_remove_root (pp->priority_heap))) { GNUNET_break (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (pp->plan_map, - get_rp_key (rp), - rp)); + GNUNET_CONTAINER_multihashmap_remove (pp->plan_map, + get_rp_key (rp), rp)); while (NULL != (prl = rp->prl_head)) { GNUNET_CONTAINER_DLL_remove (rp->prl_head, rp->prl_tail, prl); @@ -649,9 +643,8 @@ GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp) while (NULL != (rp = GNUNET_CONTAINER_heap_remove_root (pp->delay_heap))) { GNUNET_break (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (pp->plan_map, - get_rp_key (rp), - rp)); + GNUNET_CONTAINER_multihashmap_remove (pp->plan_map, + get_rp_key (rp), rp)); while (NULL != (prl = rp->prl_head)) { GNUNET_CONTAINER_DLL_remove (rp->prl_head, rp->prl_tail, prl); @@ -695,9 +688,10 @@ GSF_plan_notify_request_done_ (struct GSF_PendingRequest *pr) GNUNET_CONTAINER_heap_remove_node (rp->hn); plan_count--; GNUNET_break (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (rp->pp->plan_map, - &GSF_pending_request_get_data_ (rpr->prl->pr)->query, - rp)); + GNUNET_CONTAINER_multihashmap_remove (rp->pp->plan_map, + &GSF_pending_request_get_data_ + (rpr->prl->pr)->query, + rp)); GNUNET_free (rp); } GNUNET_free (rpr->prl); diff --git a/src/fs/gnunet-service-fs_pr.c b/src/fs/gnunet-service-fs_pr.c index 63ae3a75f..ac183a980 100644 --- a/src/fs/gnunet-service-fs_pr.c +++ b/src/fs/gnunet-service-fs_pr.c @@ -216,10 +216,10 @@ refresh_bloomfilter (struct GSF_PendingRequest *pr) if (pr->bf != NULL) GNUNET_CONTAINER_bloomfilter_free (pr->bf); pr->mingle = - GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); - pr->bf = GNUNET_BLOCK_construct_bloomfilter (pr->mingle, - pr->replies_seen, - pr->replies_seen_count); + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); + pr->bf = + GNUNET_BLOCK_construct_bloomfilter (pr->mingle, pr->replies_seen, + pr->replies_seen_count); } @@ -319,7 +319,8 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options, if (NULL != bf_data) { pr->bf = - GNUNET_CONTAINER_bloomfilter_init (bf_data, bf_size, GNUNET_CONSTANTS_BLOOMFILTER_K); + GNUNET_CONTAINER_bloomfilter_init (bf_data, bf_size, + GNUNET_CONSTANTS_BLOOMFILTER_K); pr->mingle = mingle; } else if ((replies_seen_count > 0) && @@ -433,17 +434,16 @@ GSF_pending_request_update_ (struct GSF_PendingRequest *pr, pr->mingle = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); pr->bf = - GNUNET_BLOCK_construct_bloomfilter (pr->mingle, - replies_seen, - replies_seen_count); - } + GNUNET_BLOCK_construct_bloomfilter (pr->mingle, replies_seen, + replies_seen_count); + } else { for (i = 0; i < pr->replies_seen_count; i++) - { - GNUNET_BLOCK_mingle_hash (&replies_seen[i], pr->mingle, &mhash); - GNUNET_CONTAINER_bloomfilter_add (pr->bf, &mhash); - } + { + GNUNET_BLOCK_mingle_hash (&replies_seen[i], pr->mingle, &mhash); + GNUNET_CONTAINER_bloomfilter_add (pr->bf, &mhash); + } } } } @@ -970,10 +970,10 @@ static void handle_dht_reply (void *cls, struct GNUNET_TIME_Absolute exp, const GNUNET_HashCode * key, const struct GNUNET_PeerIdentity *get_path, - unsigned int get_path_length, + unsigned int get_path_length, const struct GNUNET_PeerIdentity *put_path, - unsigned int put_path_length, - enum GNUNET_BLOCK_Type type, size_t size, const void *data) + unsigned int put_path_length, enum GNUNET_BLOCK_Type type, + size_t size, const void *data) { struct GSF_PendingRequest *pr = cls; struct ProcessReplyClosure prq; @@ -1051,11 +1051,10 @@ GSF_dht_lookup_ (struct GSF_PendingRequest *pr) pr->gh = GNUNET_DHT_get_start (GSF_dht, GNUNET_TIME_UNIT_FOREVER_REL, pr->public_data.type, &pr->public_data.query, - 5 /* DEFAULT_GET_REPLICATION */, - GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, - /* FIXME: can no longer pass pr->bf/pr->mingle... */ - xquery, xquery_size, &handle_dht_reply, - pr); + 5 /* DEFAULT_GET_REPLICATION */ , + GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, + /* FIXME: can no longer pass pr->bf/pr->mingle... */ + xquery, xquery_size, &handle_dht_reply, pr); } @@ -1231,16 +1230,17 @@ process_local_reply (void *cls, const GNUNET_HashCode * key, size_t size, /* queue priority */ , (0 != (GSF_PRO_PRIORITY_UNLIMITED & - pr->public_data.options)) ? UINT_MAX : datastore_queue_size + pr->public_data.options)) ? UINT_MAX : + datastore_queue_size /* max queue size */ , GNUNET_TIME_UNIT_FOREVER_REL, &process_local_reply, pr); if (NULL != pr->qe) - return; /* we're done */ + return; /* we're done */ GNUNET_STATISTICS_update (GSF_stats, - gettext_noop - ("# Datastore lookups concluded (error queueing)"), - 1, GNUNET_NO); + gettext_noop + ("# Datastore lookups concluded (error queueing)"), + 1, GNUNET_NO); goto check_error_and_continue; } old_rf = pr->public_data.results_found; @@ -1270,7 +1270,8 @@ process_local_reply (void *cls, const GNUNET_HashCode * key, size_t size, /* queue priority */ , (0 != (GSF_PRO_PRIORITY_UNLIMITED & - pr->public_data.options)) ? UINT_MAX : datastore_queue_size + pr->public_data.options)) ? UINT_MAX : + datastore_queue_size /* max queue size */ , GNUNET_TIME_UNIT_FOREVER_REL, &process_local_reply, pr); @@ -1329,7 +1330,8 @@ process_local_reply (void *cls, const GNUNET_HashCode * key, size_t size, /* queue priority */ , (0 != (GSF_PRO_PRIORITY_UNLIMITED & pr-> - public_data.options)) ? UINT_MAX : datastore_queue_size + public_data.options)) ? UINT_MAX : + datastore_queue_size /* max queue size */ , GNUNET_TIME_UNIT_FOREVER_REL, &process_local_reply, pr); @@ -1353,21 +1355,24 @@ check_error_and_continue: /** * Is the given target a legitimate peer for forwarding the given request? - * + * * @param pr request * @param target * @return GNUNET_YES if this request could be forwarded to the given peer */ int GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr, - const struct GNUNET_PeerIdentity *target) + const struct GNUNET_PeerIdentity *target) { struct GNUNET_PeerIdentity pi; - + if (0 == pr->origin_pid) return GNUNET_YES; GNUNET_PEER_resolve (pr->origin_pid, &pi); - return (0 == memcmp (&pi, target, sizeof (struct GNUNET_PeerIdentity))) ? GNUNET_NO :GNUNET_YES; + return (0 == + memcmp (&pi, target, + sizeof (struct GNUNET_PeerIdentity))) ? GNUNET_NO : + GNUNET_YES; } @@ -1405,16 +1410,17 @@ GSF_local_lookup_ (struct GSF_PendingRequest *pr, /* queue priority */ , (0 != (GSF_PRO_PRIORITY_UNLIMITED & pr-> - public_data.options)) ? UINT_MAX : datastore_queue_size + public_data.options)) ? UINT_MAX : + datastore_queue_size /* max queue size */ , GNUNET_TIME_UNIT_FOREVER_REL, &process_local_reply, pr); if (NULL != pr->qe) return; GNUNET_STATISTICS_update (GSF_stats, - gettext_noop - ("# Datastore lookups concluded (error queueing)"), - 1, GNUNET_NO); + gettext_noop + ("# Datastore lookups concluded (error queueing)"), + 1, GNUNET_NO); GNUNET_SCHEDULER_cancel (pr->warn_task); pr->warn_task = GNUNET_SCHEDULER_NO_TASK; pr->llc_cont = NULL; @@ -1566,10 +1572,8 @@ GSF_pending_request_init_ () "MAX_PENDING_REQUESTS"); } if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (GSF_cfg, - "core", - "TOTAL_QUOTA_OUT", - &bps)) + GNUNET_CONFIGURATION_get_value_number (GSF_cfg, "core", "TOTAL_QUOTA_OUT", + &bps)) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ @@ -1578,9 +1582,10 @@ GSF_pending_request_init_ () bps = 65536; } /* queue size should be #queries we can have pending and satisfy within - a carry interval: */ - datastore_queue_size = bps * GNUNET_CONSTANTS_MAX_BANDWIDTH_CARRY_S / DBLOCK_SIZE; - + * a carry interval: */ + datastore_queue_size = + bps * GNUNET_CONSTANTS_MAX_BANDWIDTH_CARRY_S / DBLOCK_SIZE; + active_to_migration = GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg, "FS", "CONTENT_CACHING"); datastore_put_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE); diff --git a/src/fs/gnunet-service-fs_pr.h b/src/fs/gnunet-service-fs_pr.h index 538a38248..00249afcf 100644 --- a/src/fs/gnunet-service-fs_pr.h +++ b/src/fs/gnunet-service-fs_pr.h @@ -359,14 +359,14 @@ GSF_local_lookup_ (struct GSF_PendingRequest *pr, /** * Is the given target a legitimate peer for forwarding the given request? - * + * * @param pr request * @param target * @return GNUNET_YES if this request could be forwarded to the given peer */ int GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr, - const struct GNUNET_PeerIdentity *target); + const struct GNUNET_PeerIdentity *target); diff --git a/src/fs/gnunet-service-fs_put.c b/src/fs/gnunet-service-fs_put.c index c029b4141..07d32ef31 100644 --- a/src/fs/gnunet-service-fs_put.c +++ b/src/fs/gnunet-service-fs_put.c @@ -161,9 +161,9 @@ process_dht_put_content (void *cls, const GNUNET_HashCode * key, size_t size, "Retrieved block `%s' of type %u for DHT PUT\n", GNUNET_h2s (key), type); #endif - GNUNET_DHT_put (GSF_dht, key, 5 /* DEFAULT_PUT_REPLICATION */, - GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, - type, size, data, expiration, GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_DHT_put (GSF_dht, key, 5 /* DEFAULT_PUT_REPLICATION */ , + GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, type, size, data, + expiration, GNUNET_TIME_UNIT_FOREVER_REL, &delay_dht_put_blocks, po); } diff --git a/src/hello/hello.c b/src/hello/hello.c index c7db77a18..a0c26d1ab 100644 --- a/src/hello/hello.c +++ b/src/hello/hello.c @@ -632,8 +632,8 @@ GNUNET_HELLO_equals (const struct GNUNET_HELLO_Message *h1, static int find_min_expire (void *cls, const char *tname, - struct GNUNET_TIME_Absolute expiration, const void *addr, - uint16_t addrlen) + struct GNUNET_TIME_Absolute expiration, const void *addr, + uint16_t addrlen) { struct GNUNET_TIME_Absolute *min = cls; diff --git a/src/hostlist/gnunet-daemon-hostlist.c b/src/hostlist/gnunet-daemon-hostlist.c index 2ef807444..b0fb03e29 100644 --- a/src/hostlist/gnunet-daemon-hostlist.c +++ b/src/hostlist/gnunet-daemon-hostlist.c @@ -143,7 +143,7 @@ static int advertisement_handler (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { GNUNET_assert (NULL != client_adv_handler); return (*client_adv_handler) (cls, peer, message, atsi, atsi_count); @@ -161,7 +161,7 @@ advertisement_handler (void *cls, const struct GNUNET_PeerIdentity *peer, static void connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { if (0 == memcmp (&me, peer, sizeof (struct GNUNET_PeerIdentity))) return; diff --git a/src/hostlist/hostlist-client.c b/src/hostlist/hostlist-client.c index ba5093779..350a0baee 100644 --- a/src/hostlist/hostlist-client.c +++ b/src/hostlist/hostlist-client.c @@ -1112,7 +1112,7 @@ task_hostlist_saving (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static void handler_connect (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { GNUNET_assert (stat_connection_count < UINT_MAX); stat_connection_count++; @@ -1152,7 +1152,7 @@ static int handler_advertisement (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { size_t size; size_t uri_size; diff --git a/src/hostlist/hostlist-server.c b/src/hostlist/hostlist-server.c index a6d9c126c..69d83b4d4 100644 --- a/src/hostlist/hostlist-server.c +++ b/src/hostlist/hostlist-server.c @@ -367,7 +367,7 @@ adv_transmit_ready (void *cls, size_t size, void *buf) static void connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { size_t size; diff --git a/src/hostlist/test_gnunet_daemon_hostlist.c b/src/hostlist/test_gnunet_daemon_hostlist.c index bcb302978..cac2cc67a 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist.c +++ b/src/hostlist/test_gnunet_daemon_hostlist.c @@ -97,8 +97,7 @@ timeout_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) */ static void notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { if (peer == NULL) return; diff --git a/src/hostlist/test_gnunet_daemon_hostlist_learning.c b/src/hostlist/test_gnunet_daemon_hostlist_learning.c index dfeca8d57..670fecc76 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_learning.c +++ b/src/hostlist/test_gnunet_daemon_hostlist_learning.c @@ -299,7 +299,7 @@ static int ad_arrive_handler (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { char *hostname; char *expected_uri; @@ -392,8 +392,8 @@ setup_learn_peer (struct PeerContext *p, const char *cfgname) GNUNET_free (filename); } p->core = - GNUNET_CORE_connect (p->cfg, 1, NULL, NULL, NULL, NULL, NULL, - GNUNET_NO, NULL, GNUNET_NO, learn_handlers); + GNUNET_CORE_connect (p->cfg, 1, NULL, NULL, NULL, NULL, NULL, GNUNET_NO, + NULL, GNUNET_NO, learn_handlers); GNUNET_assert (NULL != p->core); p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg); GNUNET_assert (NULL != p->stats); diff --git a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c index 18757a79e..5dce8df10 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c +++ b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c @@ -108,8 +108,7 @@ timeout_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) */ static void notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { if (peer == NULL) return; diff --git a/src/include/gnunet_ats_service.h b/src/include/gnunet_ats_service.h index ed5631a33..ac963ce1d 100644 --- a/src/include/gnunet_ats_service.h +++ b/src/include/gnunet_ats_service.h @@ -49,14 +49,14 @@ enum GNUNET_ATS_Property /** * Actual traffic on this connection from the other peer to this peer. - * + * * Unit: [bytes/second] */ GNUNET_ATS_UTILIZATION_UP, /** * Actual traffic on this connection from this peer to the other peer. - * + * * Unit: [bytes/second] */ GNUNET_ATS_UTILIZATION_DOWN, @@ -74,14 +74,14 @@ enum GNUNET_ATS_Property * Dialup: 500 */ GNUNET_ATS_QUALITY_NET_DELAY, - + /** * Distance on network layer (required for distance-vector routing). * * Unit: [DV-hops] */ GNUNET_ATS_QUALITY_NET_DISTANCE, - + /** * Network overhead on WAN (Wide-Area Network) * @@ -102,7 +102,7 @@ enum GNUNET_ATS_Property * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb] */ GNUNET_ATS_COST_WAN, - + /** * Network overhead on LAN (Local-Area Network) * @@ -123,7 +123,7 @@ enum GNUNET_ATS_Property * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb] */ GNUNET_ATS_COST_LAN, - + /** * Network overhead on WLAN (Wireless Local Area Network) * @@ -144,12 +144,8 @@ enum GNUNET_ATS_Property * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb] */ GNUNET_ATS_COST_WLAN - - - - /* Cost related values */ - /* =================== */ - + /* Cost related values */ + /* =================== */ /** * Volume based cost in financial units to transmit data * @@ -166,8 +162,7 @@ enum GNUNET_ATS_Property * LAN: 0 [cent/MB] * 2G : 10 [cent/MB] */ - // GNUNET_ATS_COST_FINANCIAL_PER_VOLUME = 1, - + // GNUNET_ATS_COST_FINANCIAL_PER_VOLUME = 1, /** * Time based cost in financial units to transmit data * @@ -184,8 +179,7 @@ enum GNUNET_ATS_Property * LAN : 0 [cent/h] * Dialup: 10 [cent/h] */ - // GNUNET_ATS_COST_FINANCIAL_PER_TIME = 2, - + // GNUNET_ATS_COST_FINANCIAL_PER_TIME = 2, /** * Computational costs * @@ -204,8 +198,7 @@ enum GNUNET_ATS_Property * HTTPS with AES CBC-128: 5,279 * HTTPS with RC4-1024: 2,652 */ - // GNUNET_ATS_COST_COMPUTATIONAL = 3, - + // GNUNET_ATS_COST_COMPUTATIONAL = 3, /** * Energy consumption * @@ -233,8 +226,7 @@ enum GNUNET_ATS_Property * WLAN: 89 (600 mW @ 802.11g /w 54 MBit/s) * Bluetooth: 267 (100 mW @ BT2.0 EDR /w 3 MBit/s) */ - // GNUNET_ATS_COST_ENERGY_CONSUMPTION = 4, - + // GNUNET_ATS_COST_ENERGY_CONSUMPTION = 4, /** * Connect cost * How many bytes are transmitted to initiate a new connection using @@ -256,8 +248,7 @@ enum GNUNET_ATS_Property * 2129 bytes Ethernet, 1975 bytes TCP/IP, 1755 bytes TCP, 1403 bytes HTTPS * * */ - // GNUNET_ATS_COST_CONNECT = 5, - + // GNUNET_ATS_COST_CONNECT = 5, /** * Bandwidth cost * @@ -274,8 +265,7 @@ enum GNUNET_ATS_Property * Dial-up: 8 (64 Kbit/s) * */ - // GNUNET_ATS_COST_BANDWITH_AVAILABLE = 6, - + // GNUNET_ATS_COST_BANDWITH_AVAILABLE = 6, /** * Network overhead * @@ -295,35 +285,28 @@ enum GNUNET_ATS_Property * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8 = 1090 [bytes/kb] * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb] */ - // GNUNET_ATS_COST_NETWORK_OVERHEAD = 7, - - - /* Quality related values */ - /* ====================== */ - - /* Physical layer quality properties */ - + // GNUNET_ATS_COST_NETWORK_OVERHEAD = 7, + /* Quality related values */ + /* ====================== */ + /* Physical layer quality properties */ /** * Signal strength on physical layer * * Unit: [dBm] */ - // GNUNET_ATS_QUALITY_PHY_SIGNAL_STRENGTH = 1025, - + // GNUNET_ATS_QUALITY_PHY_SIGNAL_STRENGTH = 1025, /** * Collision rate on physical layer * * Unit: [B/s] */ - // GNUNET_ATS_QUALITY_PHY_COLLISION_RATE = 1026, - + // GNUNET_ATS_QUALITY_PHY_COLLISION_RATE = 1026, /** * Error rate on physical layer * * Unit: [B/s] */ - // GNUNET_ATS_QUALITY_PHY_ERROR_RATE = 1027, - + // GNUNET_ATS_QUALITY_PHY_ERROR_RATE = 1027, /** * Jitter * Time variations of the delay @@ -331,8 +314,7 @@ enum GNUNET_ATS_Property * * Unit: [ms] */ - // GNUNET_ATS_QUALITY_NET_JITTER = 1029, - + // GNUNET_ATS_QUALITY_NET_JITTER = 1029, /** * Error rate on network layer * @@ -346,8 +328,7 @@ enum GNUNET_ATS_Property * Note: This numbers are just assumptions as an example, not * measured or somehow determined */ - // GNUNET_ATS_QUALITY_NET_ERRORRATE = 1030, - + // GNUNET_ATS_QUALITY_NET_ERRORRATE = 1030, /** * Drop rate on network layer * Bytes actively dismissed by a network component during transmission @@ -363,8 +344,7 @@ enum GNUNET_ATS_Property * Note: This numbers are just assumptions as an example, not * measured or somehow determined */ - // GNUNET_ATS_QUALITY_NET_DROPRATE = 1031, - + // GNUNET_ATS_QUALITY_NET_DROPRATE = 1031, /** * Loss rate on network layer * Bytes lost during transmission @@ -380,8 +360,7 @@ enum GNUNET_ATS_Property * Note: This numbers are just assumptions as an example, not measured * or somehow determined */ - // GNUNET_ATS_QUALITY_NET_LOSSRATE = 1032, - + // GNUNET_ATS_QUALITY_NET_LOSSRATE = 1032, /** * Throughput on network layer * @@ -394,21 +373,17 @@ enum GNUNET_ATS_Property * Dialup: 4 * */ - // GNUNET_ATS_QUALITY_NET_THROUGHPUT = 1033, - - - /* Availability related values */ - /* =========================== */ - + // GNUNET_ATS_QUALITY_NET_THROUGHPUT = 1033, + /* Availability related values */ + /* =========================== */ /** * Is a peer reachable? */ - // GNUNET_ATS_AVAILABILITY_REACHABLE = 2048, - + // GNUNET_ATS_AVAILABILITY_REACHABLE = 2048, /** * Is there a connection established to a peer using this transport */ - // GNUNET_ATS_AVAILABILITY_CONNECTED = 2049 + // GNUNET_ATS_AVAILABILITY_CONNECTED = 2049 }; @@ -461,7 +436,7 @@ struct Session; /** * Signature of a function called by ATS with the current bandwidth - * and address preferences as determined by ATS. + * and address preferences as determined by ATS. * * @param cls closure * @param peer identity of the new peer @@ -488,10 +463,9 @@ typedef void (*GNUNET_ATS_AddressSuggestionCallback) (void *cls, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - const struct - GNUNET_ATS_Information - * ats, - uint32_t ats_count); + const struct + GNUNET_ATS_Information * + ats, uint32_t ats_count); /** @@ -504,8 +478,8 @@ typedef void (*GNUNET_ATS_AddressSuggestionCallback) (void *cls, */ struct GNUNET_ATS_SchedulingHandle * GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg, - GNUNET_ATS_AddressSuggestionCallback suggest_cb, - void *suggest_cb_cls); + GNUNET_ATS_AddressSuggestionCallback suggest_cb, + void *suggest_cb_cls); /** @@ -549,9 +523,8 @@ GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh, void GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh, const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, - const void *plugin_addr, size_t plugin_addr_len, - struct Session *session, + const char *plugin_name, const void *plugin_addr, + size_t plugin_addr_len, struct Session *session, const struct GNUNET_ATS_Information *ats, uint32_t ats_count); @@ -570,12 +543,10 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh, */ void GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh, - const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, - const void *plugin_addr, - size_t plugin_addr_len, - struct Session *session, - int in_use); + const struct GNUNET_PeerIdentity *peer, + const char *plugin_name, const void *plugin_addr, + size_t plugin_addr_len, struct Session *session, + int in_use); /** * A session got destroyed, stop including it as a valid address. @@ -590,10 +561,8 @@ GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh, void GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh, const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, - const void *plugin_addr, - size_t plugin_addr_len, - struct Session *session); + const char *plugin_name, const void *plugin_addr, + size_t plugin_addr_len, struct Session *session); /* ******************************** Performance API ***************************** */ @@ -618,22 +587,20 @@ struct GNUNET_ATS_PerformanceHandle; * @param ats_count number of performance records in 'ats' */ typedef void (*GNUNET_ATS_PeerInformationCallback) (void *cls, - const struct - GNUNET_PeerIdentity * - peer, - const char *plugin_name, - const void *plugin_addr, - size_t plugin_addr_len, - struct - GNUNET_BANDWIDTH_Value32NBO - bandwidth_out, - struct - GNUNET_BANDWIDTH_Value32NBO - bandwidth_in, - const struct - GNUNET_ATS_Information - * ats, - uint32_t ats_count); + const struct + GNUNET_PeerIdentity * peer, + const char *plugin_name, + const void *plugin_addr, + size_t plugin_addr_len, + struct + GNUNET_BANDWIDTH_Value32NBO + bandwidth_out, + struct + GNUNET_BANDWIDTH_Value32NBO + bandwidth_in, + const struct + GNUNET_ATS_Information * + ats, uint32_t ats_count); /** @@ -646,8 +613,8 @@ typedef void (*GNUNET_ATS_PeerInformationCallback) (void *cls, */ struct GNUNET_ATS_PerformanceHandle * GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg, - GNUNET_ATS_PeerInformationCallback infocb, - void *infocb_cls); + GNUNET_ATS_PeerInformationCallback infocb, + void *infocb_cls); /** @@ -670,13 +637,10 @@ GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph); * long should the client wait until re-trying? */ typedef void (*GNUNET_ATS_ReservationCallback) (void *cls, - const struct - GNUNET_PeerIdentity * - peer, - int32_t amount, - struct - GNUNET_TIME_Relative - res_delay); + const struct GNUNET_PeerIdentity + * peer, int32_t amount, + struct GNUNET_TIME_Relative + res_delay); @@ -702,10 +666,10 @@ struct GNUNET_ATS_ReservationContext; */ struct GNUNET_ATS_ReservationContext * GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph, - const struct GNUNET_PeerIdentity *peer, - int32_t amount, - GNUNET_ATS_ReservationCallback rcb, - void *rcb_cls); + const struct GNUNET_PeerIdentity *peer, + int32_t amount, + GNUNET_ATS_ReservationCallback rcb, + void *rcb_cls); /** @@ -714,8 +678,7 @@ GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph, * @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call */ void -GNUNET_ATS_reserve_bandwidth_cancel (struct - GNUNET_ATS_ReservationContext *rc); +GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc); @@ -734,7 +697,7 @@ enum GNUNET_ATS_PreferenceKind * Change the peer's bandwidth value (value per byte of bandwidth in * the goal function) to the given amount. The argument is followed * by a double value giving the desired value (can be negative). - * Preference changes are forgotten if peers disconnect. + * Preference changes are forgotten if peers disconnect. */ GNUNET_ATS_PREFERENCE_BANDWIDTH, @@ -746,22 +709,20 @@ enum GNUNET_ATS_PreferenceKind * the latency preferences. */ GNUNET_ATS_PREFERENCE_LATENCY - }; - + /** * Change preferences for the given peer. Preference changes are forgotten if peers * disconnect. - * + * * @param ph performance handle * @param peer identifies the peer * @param ... 0-terminated specification of the desired changes */ void GNUNET_ATS_change_preference (struct GNUNET_ATS_PerformanceHandle *ph, - const struct GNUNET_PeerIdentity *peer, - ...); + const struct GNUNET_PeerIdentity *peer, ...); diff --git a/src/include/gnunet_block_lib.h b/src/include/gnunet_block_lib.h index 8e7a59c8b..5e6eca76c 100644 --- a/src/include/gnunet_block_lib.h +++ b/src/include/gnunet_block_lib.h @@ -238,8 +238,8 @@ GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx, */ struct GNUNET_CONTAINER_BloomFilter * GNUNET_BLOCK_construct_bloomfilter (int32_t bf_mutator, - const GNUNET_HashCode *seen_results, - unsigned int seen_results_count); + const GNUNET_HashCode * seen_results, + unsigned int seen_results_count); #if 0 /* keep Emacsens' auto-indent happy */ diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h index a46badc74..08c1f96c9 100644 --- a/src/include/gnunet_common.h +++ b/src/include/gnunet_common.h @@ -167,9 +167,11 @@ typedef void (*GNUNET_Logger) (void *cls, enum GNUNET_ErrorType kind, * Number of log calls to ignore. */ extern unsigned int skip_log; + #if !defined(GNUNET_CULL_LOGGING) -int -GNUNET_get_log_call_status (int caller_level, const char *comp, const char *file, const char *function, int line); +int +GNUNET_get_log_call_status (int caller_level, const char *comp, + const char *file, const char *function, int line); #endif /** * Main log function. @@ -214,7 +216,7 @@ GNUNET_log_nocheck (enum GNUNET_ErrorType kind, const char *message, ...); */ void GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, const char *comp, - const char *message, ...); + const char *message, ...); #if !defined(GNUNET_CULL_LOGGING) #define GNUNET_log_from(kind,comp,...) do { int log_line = __LINE__;\ diff --git a/src/include/gnunet_core_service.h b/src/include/gnunet_core_service.h index 24c9aa598..1f6c0f329 100644 --- a/src/include/gnunet_core_service.h +++ b/src/include/gnunet_core_service.h @@ -63,9 +63,8 @@ typedef void (*GNUNET_CORE_ConnectEventHandler) (void *cls, const struct GNUNET_PeerIdentity * peer, const struct - GNUNET_ATS_Information - * atsi, - unsigned int atsi_count); + GNUNET_ATS_Information * atsi, + unsigned int atsi_count); /** @@ -97,10 +96,8 @@ typedef int (*GNUNET_CORE_MessageCallback) (void *cls, other, const struct GNUNET_MessageHeader * message, - const struct - GNUNET_ATS_Information * - atsi, - unsigned int atsi_count); + const struct GNUNET_ATS_Information + * atsi, unsigned int atsi_count); /** @@ -142,7 +139,8 @@ struct GNUNET_CORE_MessageHandler */ typedef void (*GNUNET_CORE_StartupCallback) (void *cls, struct GNUNET_CORE_Handle * server, - const struct GNUNET_PeerIdentity *my_identity); + const struct GNUNET_PeerIdentity * + my_identity); /** diff --git a/src/include/gnunet_dht_service.h b/src/include/gnunet_dht_service.h index fcbc8df47..f047bd8f8 100644 --- a/src/include/gnunet_dht_service.h +++ b/src/include/gnunet_dht_service.h @@ -165,10 +165,10 @@ GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, const GNUNET_HashCode * key, typedef void (*GNUNET_DHT_GetIterator) (void *cls, struct GNUNET_TIME_Absolute exp, const GNUNET_HashCode * key, - const struct GNUNET_PeerIdentity *get_path, - unsigned int get_path_length, - const struct GNUNET_PeerIdentity *put_path, - unsigned int put_path_length, + const struct GNUNET_PeerIdentity * + get_path, unsigned int get_path_length, + const struct GNUNET_PeerIdentity * + put_path, unsigned int put_path_length, enum GNUNET_BLOCK_Type type, size_t size, const void *data); @@ -197,8 +197,7 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, struct GNUNET_TIME_Relative timeout, enum GNUNET_BLOCK_Type type, const GNUNET_HashCode * key, uint32_t desired_replication_level, - enum GNUNET_DHT_RouteOption options, - const void *xquery, + enum GNUNET_DHT_RouteOption options, const void *xquery, size_t xquery_size, GNUNET_DHT_GetIterator iter, void *iter_cls); diff --git a/src/include/gnunet_mesh_service.h b/src/include/gnunet_mesh_service.h index 0497cee2f..b9e95b46d 100644 --- a/src/include/gnunet_mesh_service.h +++ b/src/include/gnunet_mesh_service.h @@ -74,9 +74,8 @@ typedef int (*GNUNET_MESH_MessageCallback) (void *cls, sender, const struct GNUNET_MessageHeader * message, - const struct - GNUNET_ATS_Information * - atsi); + const struct GNUNET_ATS_Information + * atsi); /** @@ -208,8 +207,7 @@ typedef void (*GNUNET_MESH_PeerConnectHandler) (void *cls, const struct GNUNET_PeerIdentity * peer, const struct - GNUNET_ATS_Information - * atsi); + GNUNET_ATS_Information * atsi); diff --git a/src/include/gnunet_plugin_lib.h b/src/include/gnunet_plugin_lib.h index ff795d975..387ca381c 100644 --- a/src/include/gnunet_plugin_lib.h +++ b/src/include/gnunet_plugin_lib.h @@ -89,9 +89,9 @@ GNUNET_PLUGIN_load (const char *library_name, void *arg); * of the library (same as what 'GNUNET_PLUGIN_load' would * have returned for the given library name) */ -typedef void (*GNUNET_PLUGIN_LoaderCallback)(void *cls, - const char *library_name, - void *lib_ret); +typedef void (*GNUNET_PLUGIN_LoaderCallback) (void *cls, + const char *library_name, + void *lib_ret); /** @@ -106,11 +106,9 @@ typedef void (*GNUNET_PLUGIN_LoaderCallback)(void *cls, * @param cb function to call for each plugin found * @param cb_cls closure for 'cb' */ -void -GNUNET_PLUGIN_load_all (const char *basename, - void *arg, - GNUNET_PLUGIN_LoaderCallback cb, - void *cb_cls); +void +GNUNET_PLUGIN_load_all (const char *basename, void *arg, + GNUNET_PLUGIN_LoaderCallback cb, void *cb_cls); /** diff --git a/src/include/gnunet_server_lib.h b/src/include/gnunet_server_lib.h index 5289a6270..c39349c92 100644 --- a/src/include/gnunet_server_lib.h +++ b/src/include/gnunet_server_lib.h @@ -489,8 +489,7 @@ GNUNET_SERVER_transmit_context_run (struct GNUNET_SERVER_TransmitContext *tc, */ void GNUNET_SERVER_transmit_context_destroy (struct GNUNET_SERVER_TransmitContext - *tc, - int success); + *tc, int success); /** diff --git a/src/include/gnunet_strings_lib.h b/src/include/gnunet_strings_lib.h index 5a4996c3b..4efecc863 100644 --- a/src/include/gnunet_strings_lib.h +++ b/src/include/gnunet_strings_lib.h @@ -59,7 +59,7 @@ extern "C" */ int GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size, - unsigned long long *size); + unsigned long long *size); /** @@ -72,7 +72,7 @@ GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size, */ int GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_size, - struct GNUNET_TIME_Relative *rtime); + struct GNUNET_TIME_Relative *rtime); /** diff --git a/src/include/gnunet_transport_service.h b/src/include/gnunet_transport_service.h index 2d6e515fa..de764e7a6 100644 --- a/src/include/gnunet_transport_service.h +++ b/src/include/gnunet_transport_service.h @@ -51,7 +51,7 @@ extern "C" * @param peer (claimed) identity of the other peer * @param message the message * @param ats performance data - * @param ats_count number of entries in ats + * @param ats_count number of entries in ats */ typedef void (*GNUNET_TRANSPORT_ReceiveCallback) (void *cls, const struct @@ -60,8 +60,8 @@ typedef void (*GNUNET_TRANSPORT_ReceiveCallback) (void *cls, GNUNET_MessageHeader * message, const struct - GNUNET_ATS_Information - * ats, uint32_t ats_count); + GNUNET_ATS_Information * ats, + uint32_t ats_count); /** @@ -83,8 +83,8 @@ typedef void (*GNUNET_TRANSPORT_NotifyConnect) (void *cls, const struct GNUNET_PeerIdentity * peer, const struct - GNUNET_ATS_Information - * ats, uint32_t ats_count); + GNUNET_ATS_Information * ats, + uint32_t ats_count); /** * Function called to notify transport users that another diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index c0a7852e0..a5113e52b 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c @@ -342,7 +342,7 @@ struct MeshPathInfo * Path itself */ struct MeshPeerPath *path; - + /** * Position in peer's transmit queue */ @@ -479,7 +479,7 @@ static struct GNUNET_PeerIdentity my_full_id; /** * Own private key */ -static struct GNUNET_CRYPTO_RsaPrivateKey* my_private_key; +static struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key; /** * Own public key. @@ -546,12 +546,9 @@ static int announce_application (void *cls, const GNUNET_HashCode * key, void *value) { /* FIXME are hashes in multihash map equal on all aquitectures? */ - GNUNET_DHT_put (dht_handle, - key, - 10U, + GNUNET_DHT_put (dht_handle, key, 10U, GNUNET_DHT_RO_RECORD_ROUTE | - GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, - GNUNET_BLOCK_TYPE_TEST, + GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, GNUNET_BLOCK_TYPE_TEST, sizeof (struct GNUNET_PeerIdentity), (const char *) &my_full_id, #if MESH_DEBUG @@ -620,11 +617,10 @@ announce_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_DHT_put (dht_handle, /* DHT handle */ &my_full_id.hashPubKey, /* Key to use */ 10U, /* Replication level */ - GNUNET_DHT_RO_RECORD_ROUTE | - GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, /* DHT options */ + GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, /* DHT options */ GNUNET_BLOCK_TYPE_TEST, /* Block type */ - sizeof(my_full_id), /* Size of the data */ - (char *)&my_full_id, /* Data itself */ + sizeof (my_full_id), /* Size of the data */ + (char *) &my_full_id, /* Data itself */ GNUNET_TIME_absolute_get_forever (), /* Data expiration */ GNUNET_TIME_UNIT_FOREVER_REL, /* Retry time */ #if MESH_DEBUG_DHT @@ -656,8 +652,8 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, const struct GNUNET_PeerIdentity *get_path, unsigned int get_path_length, const struct GNUNET_PeerIdentity *put_path, - unsigned int put_path_length, - enum GNUNET_BLOCK_Type type, size_t size, const void *data); + unsigned int put_path_length, enum GNUNET_BLOCK_Type type, + size_t size, const void *data); /******************************************************************************/ @@ -711,12 +707,12 @@ client_is_subscribed (uint16_t message_type, struct MeshClient *c) * Allow a client to send more data after transmitting a multicast message * which some neighbor has not yet accepted altough a reasonable time has * passed. - * + * * @param cls Closure (DataDescriptor containing the task identifier) * @param tc Task Context */ static void -client_allow_send(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +client_allow_send (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct MeshDataDescriptor *info = cls; @@ -728,7 +724,7 @@ client_allow_send(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) *(info->copies)); #endif *(info->timeout_task) = GNUNET_SCHEDULER_NO_TASK; - GNUNET_SERVER_receive_done(info->client, GNUNET_OK); + GNUNET_SERVER_receive_done (info->client, GNUNET_OK); } @@ -756,8 +752,7 @@ tunnel_get (struct GNUNET_PeerIdentity *oid, MESH_TunnelNumber tid); * 0 if the tunnel remained unaffected. */ static GNUNET_PEER_Id -tunnel_notify_connection_broken (struct MeshTunnel *t, - GNUNET_PEER_Id p1, +tunnel_notify_connection_broken (struct MeshTunnel *t, GNUNET_PEER_Id p1, GNUNET_PEER_Id p2); @@ -777,39 +772,39 @@ send_subscribed_clients (const struct GNUNET_MessageHeader *msg, MESH_TunnelNumber *tid; unsigned int count; uint16_t type; - char cbuf[htons(msg->size)]; + char cbuf[htons (msg->size)]; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Sending to clients...\n"); type = ntohs (payload->type); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: message of type %u\n", type); - memcpy (cbuf, msg, sizeof(cbuf)); - switch (htons(msg->type)) + memcpy (cbuf, msg, sizeof (cbuf)); + switch (htons (msg->type)) { struct GNUNET_MESH_Unicast *uc; struct GNUNET_MESH_Multicast *mc; struct GNUNET_MESH_ToOrigin *to; - case GNUNET_MESSAGE_TYPE_MESH_UNICAST: - uc = (struct GNUNET_MESH_Unicast *) cbuf; - tid = &uc->tid; - oid = &uc->oid; - break; - case GNUNET_MESSAGE_TYPE_MESH_MULTICAST: - mc = (struct GNUNET_MESH_Multicast *) cbuf; - tid = &mc->tid; - oid = &mc->oid; - break; - case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: - to = (struct GNUNET_MESH_ToOrigin *) cbuf; - tid = &to->tid; - oid = &to->oid; - break; - default: - GNUNET_break (0); - return 0; + case GNUNET_MESSAGE_TYPE_MESH_UNICAST: + uc = (struct GNUNET_MESH_Unicast *) cbuf; + tid = &uc->tid; + oid = &uc->oid; + break; + case GNUNET_MESSAGE_TYPE_MESH_MULTICAST: + mc = (struct GNUNET_MESH_Multicast *) cbuf; + tid = &mc->tid; + oid = &mc->oid; + break; + case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: + to = (struct GNUNET_MESH_ToOrigin *) cbuf; + tid = &to->tid; + oid = &to->oid; + break; + default: + GNUNET_break (0); + return 0; } - t = tunnel_get (oid, ntohl(*tid)); + t = tunnel_get (oid, ntohl (*tid)); if (NULL == t) { GNUNET_break (0); @@ -823,11 +818,9 @@ send_subscribed_clients (const struct GNUNET_MessageHeader *msg, { count++; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: sending\n"); - GNUNET_SERVER_notification_context_unicast ( - nc, - c->handle, - (struct GNUNET_MessageHeader *) cbuf, - GNUNET_YES); + GNUNET_SERVER_notification_context_unicast (nc, c->handle, + (struct GNUNET_MessageHeader + *) cbuf, GNUNET_YES); } } return count; @@ -837,7 +830,7 @@ send_subscribed_clients (const struct GNUNET_MessageHeader *msg, /** * Notify the client that owns the tunnel that a peer has connected to it * (the requested path to it has been confirmed). - * + * * @param t Tunnel whose owner to notify * @param id Short id of the peer that has connected */ @@ -850,26 +843,26 @@ send_client_peer_connected (const struct MeshTunnel *t, const GNUNET_PEER_Id id) pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); pc.tunnel_id = htonl (t->local_tid); GNUNET_PEER_resolve (id, &pc.peer); - GNUNET_SERVER_notification_context_unicast (nc, t->client->handle, - &pc.header, GNUNET_NO); + GNUNET_SERVER_notification_context_unicast (nc, t->client->handle, &pc.header, + GNUNET_NO); } /** * Notify all clients (not depending on registration status) that the incoming * tunnel is no longer valid. - * + * * @param t Tunnel that was destroyed. */ static void send_clients_tunnel_destroy (struct MeshTunnel *t) { - struct GNUNET_MESH_TunnelMessage msg; + struct GNUNET_MESH_TunnelMessage msg; - msg.header.size = htons (sizeof (msg)); - msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); - msg.tunnel_id = htonl (t->local_tid); - GNUNET_SERVER_notification_context_broadcast(nc, &msg.header, GNUNET_NO); + msg.header.size = htons (sizeof (msg)); + msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); + msg.tunnel_id = htonl (t->local_tid); + GNUNET_SERVER_notification_context_broadcast (nc, &msg.header, GNUNET_NO); } @@ -906,7 +899,7 @@ send_core_data_multicast (void *cls, size_t size, void *buf); /** * Decrements the reference counter and frees all resources if needed - * + * * @param dd Data Descriptor used in a multicast message */ static void @@ -922,7 +915,7 @@ data_descriptor_decrement_multicast (struct MeshDataDescriptor *dd) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: cancelling client timeout (%u)...\n", *(dd->timeout_task)); - GNUNET_SCHEDULER_cancel(*(dd->timeout_task)); + GNUNET_SCHEDULER_cancel (*(dd->timeout_task)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: notifying client...\n"); GNUNET_SERVER_receive_done (dd->client, GNUNET_OK); } @@ -937,12 +930,12 @@ data_descriptor_decrement_multicast (struct MeshDataDescriptor *dd) /** * Cancel a core transmission that was already requested and free all resources * associated to the request. - * + * * @param peer PeeInfo of the peer whose transmission is cancelled. * @param i Position of the transmission to be cancelled. */ static void -peer_info_cancel_transmission(struct MeshPeerInfo *peer, unsigned int i) +peer_info_cancel_transmission (struct MeshPeerInfo *peer, unsigned int i) { if (NULL != peer->core_transmit[i]) { @@ -956,36 +949,34 @@ peer_info_cancel_transmission(struct MeshPeerInfo *peer, unsigned int i) GNUNET_PEER_resolve (peer->id, &id); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Cancelling data transmission at %s [%u]\n", - GNUNET_i2s (&id), - i); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: message type %u\n", + GNUNET_i2s (&id), i); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: message type %u\n", peer->types[i]); } #endif /* TODO: notify that tranmission has failed */ switch (peer->types[i]) { - case GNUNET_MESSAGE_TYPE_MESH_MULTICAST: - case GNUNET_MESSAGE_TYPE_MESH_UNICAST: - case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type payload\n"); - dd = peer->infos[i]; - data_descriptor_decrement_multicast (dd); - break; - case GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type create path\n"); - path_info = peer->infos[i]; - path_destroy(path_info->path); - break; - default: - GNUNET_break (0); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type unknown!\n"); + case GNUNET_MESSAGE_TYPE_MESH_MULTICAST: + case GNUNET_MESSAGE_TYPE_MESH_UNICAST: + case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type payload\n"); + dd = peer->infos[i]; + data_descriptor_decrement_multicast (dd); + break; + case GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE: + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type create path\n"); + path_info = peer->infos[i]; + path_destroy (path_info->path); + break; + default: + GNUNET_break (0); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type unknown!\n"); } GNUNET_CORE_notify_transmit_ready_cancel (peer->core_transmit[i]); peer->core_transmit[i] = NULL; GNUNET_free (peer->infos[i]); - } + } } @@ -1008,7 +999,7 @@ peer_info_transmit_slot (struct MeshPeerInfo *peer) { /* All positions are taken! Overwriting! */ GNUNET_break (0); - peer_info_cancel_transmission(peer, 0); + peer_info_cancel_transmission (peer, 0); return 0; } } @@ -1056,8 +1047,8 @@ peer_info_get_short (const GNUNET_PEER_Id peer) { struct GNUNET_PeerIdentity id; - GNUNET_PEER_resolve(peer, &id); - return peer_info_get(&id); + GNUNET_PEER_resolve (peer, &id); + return peer_info_get (&id); } @@ -1072,7 +1063,7 @@ peer_info_get_short (const GNUNET_PEER_Id peer) * @return always GNUNET_YES, to keep iterating */ static int -peer_info_delete_tunnel (void* cls, const GNUNET_HashCode* key, void* value) +peer_info_delete_tunnel (void *cls, const GNUNET_HashCode * key, void *value) { struct MeshTunnel *t = cls; struct MeshPeerInfo *peer = value; @@ -1080,9 +1071,8 @@ peer_info_delete_tunnel (void* cls, const GNUNET_HashCode* key, void* value) for (i = 0; i < peer->ntunnels; i++) { - if (0 == memcmp(&peer->tunnels[i]->id, - &t->id, - sizeof(struct MESH_TunnelID))) + if (0 == + memcmp (&peer->tunnels[i]->id, &t->id, sizeof (struct MESH_TunnelID))) { peer->ntunnels--; peer->tunnels[i] = peer->tunnels[peer->ntunnels]; @@ -1095,12 +1085,12 @@ peer_info_delete_tunnel (void* cls, const GNUNET_HashCode* key, void* value) /** - * Core callback to write a + * Core callback to write a * * @param cls Closure (MeshDataDescriptor with data in "data" member). * @param size Number of bytes available in buf. * @param buf Where the to write the message. - * + * * @return number of bytes written to buf */ static size_t @@ -1121,15 +1111,10 @@ send_core_data_raw (void *cls, size_t size, void *buf) GNUNET_PEER_resolve (info->peer->id, &id); info->peer->core_transmit[info->handler_n] = - GNUNET_CORE_notify_transmit_ready(core_handle, - 0, - 100, - GNUNET_TIME_UNIT_FOREVER_REL, - &id, - size, - &send_core_data_raw, - info); - return 0; + GNUNET_CORE_notify_transmit_ready (core_handle, 0, 100, + GNUNET_TIME_UNIT_FOREVER_REL, &id, + size, &send_core_data_raw, info); + return 0; } info->peer->core_transmit[info->handler_n] = NULL; memcpy (buf, msg, total_size); @@ -1181,14 +1166,9 @@ send_message (const struct GNUNET_MessageHeader *message, neighbor->types[i] = GNUNET_MESSAGE_TYPE_MESH_UNICAST; neighbor->infos[i] = info; neighbor->core_transmit[i] = - GNUNET_CORE_notify_transmit_ready(core_handle, - 0, - 100, - GNUNET_TIME_UNIT_FOREVER_REL, - peer, - size, - &send_core_data_raw, - info); + GNUNET_CORE_notify_transmit_ready (core_handle, 0, 100, + GNUNET_TIME_UNIT_FOREVER_REL, peer, + size, &send_core_data_raw, info); } @@ -1196,14 +1176,13 @@ send_message (const struct GNUNET_MessageHeader *message, /** * Sends a CREATE PATH message for a path to a peer, properly registrating * all used resources. - * + * * @param peer PeerInfo of the final peer for whom this path is being created. * @param p Path itself. * @param t Tunnel for which the path is created. */ static void -send_create_path (struct MeshPeerInfo *peer, - struct MeshPeerPath *p, +send_create_path (struct MeshPeerInfo *peer, struct MeshPeerPath *p, struct MeshTunnel *t) { struct GNUNET_PeerIdentity id; @@ -1213,7 +1192,7 @@ send_create_path (struct MeshPeerInfo *peer, if (NULL == p) { - p = tree_get_path_to_peer(t->tree, peer->id); + p = tree_get_path_to_peer (t->tree, peer->id); if (NULL == p) { GNUNET_break (0); @@ -1227,37 +1206,34 @@ send_create_path (struct MeshPeerInfo *peer, } if (i >= p->length - 1) { - path_destroy(p); + path_destroy (p); GNUNET_break (0); return; } - GNUNET_PEER_resolve(p->peers[i + 1], &id); + GNUNET_PEER_resolve (p->peers[i + 1], &id); path_info = GNUNET_malloc (sizeof (struct MeshPathInfo)); path_info->path = p; path_info->t = t; - neighbor = peer_info_get(&id); + neighbor = peer_info_get (&id); path_info->peer = neighbor; - path_info->pos = peer_info_transmit_slot(neighbor); + path_info->pos = peer_info_transmit_slot (neighbor); neighbor->types[path_info->pos] = GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE; neighbor->infos[path_info->pos] = path_info; - neighbor->core_transmit[path_info->pos] = - GNUNET_CORE_notify_transmit_ready ( - core_handle, /* handle */ - 0, /* cork */ - 0, /* priority */ - GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ - &id, /* target */ - sizeof (struct GNUNET_MESH_ManipulatePath) - + (p->length * sizeof (struct GNUNET_PeerIdentity)), /*size */ - &send_core_create_path, /* callback */ - path_info); /* cls */ + neighbor->core_transmit[path_info->pos] = GNUNET_CORE_notify_transmit_ready (core_handle, /* handle */ + 0, /* cork */ + 0, /* priority */ + GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ + &id, /* target */ + sizeof (struct GNUNET_MESH_ManipulatePath) + (p->length * sizeof (struct GNUNET_PeerIdentity)), /*size */ + &send_core_create_path, /* callback */ + path_info); /* cls */ } /** * Sends a DESTROY PATH message to free resources for a path in a tunnel - * + * * @param t Tunnel whose path to destroy. * @param destination Short ID of the peer to whom the path to destroy. */ @@ -1267,7 +1243,7 @@ send_destroy_path (struct MeshTunnel *t, GNUNET_PEER_Id destination) struct MeshPeerPath *p; size_t size; - p = tree_get_path_to_peer(t->tree, destination); + p = tree_get_path_to_peer (t->tree, destination); if (NULL == p) { GNUNET_break (0); @@ -1288,9 +1264,9 @@ send_destroy_path (struct MeshTunnel *t, GNUNET_PEER_Id destination) pi = (struct GNUNET_PeerIdentity *) &msg[1]; for (i = 0; i < p->length; i++) { - GNUNET_PEER_resolve(p->peers[i], &pi[i]); + GNUNET_PEER_resolve (p->peers[i], &pi[i]); } - send_message (&msg->header, path_get_first_hop(t->tree, destination)); + send_message (&msg->header, path_get_first_hop (t->tree, destination)); } path_destroy (p); } @@ -1299,7 +1275,7 @@ send_destroy_path (struct MeshTunnel *t, GNUNET_PEER_Id destination) /** * Try to establish a new connection to this peer. * Use the best path for the given tunnel. - * If the peer doesn't have any path to it yet, try to get one. + * If the peer doesn't have any path to it yet, try to get one. * If the peer already has some path, send a CREATE PATH towards it. * * @param peer PeerInfo of the peer. @@ -1313,7 +1289,7 @@ peer_info_connect (struct MeshPeerInfo *peer, struct MeshTunnel *t) if (NULL != peer->path_head) { - p = tree_get_path_to_peer(t->tree, peer->id); + p = tree_get_path_to_peer (t->tree, peer->id); if (NULL == p) { GNUNET_break (0); @@ -1322,38 +1298,33 @@ peer_info_connect (struct MeshPeerInfo *peer, struct MeshTunnel *t) if (p->length > 1) { - send_create_path(peer, p, t); + send_create_path (peer, p, t); } else { - path_destroy(p); - send_client_peer_connected(t, myid); + path_destroy (p); + send_client_peer_connected (t, myid); } } else if (NULL == peer->dhtget) { struct GNUNET_PeerIdentity id; - GNUNET_PEER_resolve(peer->id, &id); - path_info = GNUNET_malloc(sizeof(struct MeshPathInfo)); + GNUNET_PEER_resolve (peer->id, &id); + path_info = GNUNET_malloc (sizeof (struct MeshPathInfo)); path_info->peer = peer; path_info->t = t; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: Starting DHT GET for peer %s\n", - GNUNET_i2s (&id)); + "MESH: Starting DHT GET for peer %s\n", GNUNET_i2s (&id)); peer->dhtgetcls = path_info; - peer->dhtget = - GNUNET_DHT_get_start(dht_handle, /* handle */ - GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ - GNUNET_BLOCK_TYPE_TEST, /* type */ - &id.hashPubKey, /* key to search */ - 4, /* replication level */ - GNUNET_DHT_RO_RECORD_ROUTE | - GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, - NULL, /* xquery */ - 0, /* xquery bits */ - &dht_get_id_handler, - path_info); + peer->dhtget = GNUNET_DHT_get_start (dht_handle, /* handle */ + GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ + GNUNET_BLOCK_TYPE_TEST, /* type */ + &id.hashPubKey, /* key to search */ + 4, /* replication level */ + GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ + 0, /* xquery bits */ + &dht_get_id_handler, path_info); } /* Otherwise, there is no path but the DHT get is already started. */ } @@ -1384,9 +1355,9 @@ peer_info_connect_task (void *cls, /** * Destroy the peer_info and free any allocated resources linked to it - * + * * @param pi The peer_info to destroy. - * + * * @return GNUNET_OK on success */ static int @@ -1401,21 +1372,20 @@ peer_info_destroy (struct MeshPeerInfo *pi) GNUNET_PEER_change_rc (pi->id, -1); if (GNUNET_YES != - GNUNET_CONTAINER_multihashmap_remove (peers,&id.hashPubKey, pi)) + GNUNET_CONTAINER_multihashmap_remove (peers, &id.hashPubKey, pi)) { GNUNET_break (0); GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "MESH: removing peer %s, not in hashmap\n", - GNUNET_i2s (&id)); + "MESH: removing peer %s, not in hashmap\n", GNUNET_i2s (&id)); } if (NULL != pi->dhtget) { - GNUNET_DHT_get_stop(pi->dhtget); + GNUNET_DHT_get_stop (pi->dhtget); GNUNET_free (pi->dhtgetcls); } for (i = 0; i < CORE_QUEUE_SIZE; i++) { - peer_info_cancel_transmission(pi, i); + peer_info_cancel_transmission (pi, i); } p = pi->path_head; while (NULL != p) @@ -1442,8 +1412,7 @@ peer_info_destroy (struct MeshPeerInfo *pi) * TODO: optimize (see below) */ static void -peer_info_remove_path (struct MeshPeerInfo *peer, - GNUNET_PEER_Id p1, +peer_info_remove_path (struct MeshPeerInfo *peer, GNUNET_PEER_Id p1, GNUNET_PEER_Id p2) { struct MeshPeerPath *p; @@ -1486,16 +1455,16 @@ peer_info_remove_path (struct MeshPeerInfo *peer, * Some of them might already have a path to reach them that does not * involve p1 and p2. Adding all anew might render in a better tree than * the trivial immediate fix. - * + * * Trivial immiediate fix: try to reconnect to the disconnected node. All * its children will be reachable trough him. */ - peer_d = peer_info_get_short(d); + peer_d = peer_info_get_short (d); best = UINT_MAX; aux = NULL; for (p = peer_d->path_head; NULL != p; p = p->next) { - if ((cost = path_get_cost(peer->tunnels[i]->tree, p)) < best) + if ((cost = path_get_cost (peer->tunnels[i]->tree, p)) < best) { best = cost; aux = p; @@ -1504,7 +1473,7 @@ peer_info_remove_path (struct MeshPeerInfo *peer, if (NULL != aux) { /* No callback, as peer will be already disconnected */ - tree_add_path(peer->tunnels[i]->tree, aux, NULL, NULL); + tree_add_path (peer->tunnels[i]->tree, aux, NULL, NULL); } else { @@ -1524,8 +1493,7 @@ peer_info_remove_path (struct MeshPeerInfo *peer, * @param trusted Do we trust that this path is real? */ void -peer_info_add_path (struct MeshPeerInfo *peer_info, - struct MeshPeerPath *path, +peer_info_add_path (struct MeshPeerInfo *peer_info, struct MeshPeerPath *path, int trusted) { struct MeshPeerPath *aux; @@ -1549,28 +1517,24 @@ peer_info_add_path (struct MeshPeerInfo *peer_info, { if (path->peers[l] == myid) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: shortening path by %u\n", - l); - for (l2 = 0; l2 < path->length - l - 1 ; l2++) + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: shortening path by %u\n", l); + for (l2 = 0; l2 < path->length - l - 1; l2++) { path->peers[l2] = path->peers[l + l2]; } path->length -= l; l = 1; - path->peers = GNUNET_realloc (path->peers, - path->length * sizeof (GNUNET_PEER_Id)); + path->peers = + GNUNET_realloc (path->peers, path->length * sizeof (GNUNET_PEER_Id)); } } #if MESH_DEBUG - { + { struct GNUNET_PeerIdentity id; GNUNET_PEER_resolve (peer_info->id, &id); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: adding path [%u] to peer %s\n", - path->length, - GNUNET_i2s (&id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: adding path [%u] to peer %s\n", + path->length, GNUNET_i2s (&id)); } #endif l = path_get_length (path); @@ -1587,22 +1551,19 @@ peer_info_add_path (struct MeshPeerInfo *peer_info, if (l2 > l) { GNUNET_CONTAINER_DLL_insert_before (peer_info->path_head, - peer_info->path_tail, - aux, - path); + peer_info->path_tail, aux, path); return; } else { - if (l2 == l && memcmp(path->peers, aux->peers, l) == 0) + if (l2 == l && memcmp (path->peers, aux->peers, l) == 0) { - path_destroy(path); + path_destroy (path); return; } } } - GNUNET_CONTAINER_DLL_insert_tail (peer_info->path_head, - peer_info->path_tail, + GNUNET_CONTAINER_DLL_insert_tail (peer_info->path_head, peer_info->path_tail, path); return; } @@ -1620,10 +1581,9 @@ peer_info_add_path (struct MeshPeerInfo *peer_info, */ static void peer_info_add_path_to_origin (struct MeshPeerInfo *peer_info, - struct MeshPeerPath *path, - int trusted) + struct MeshPeerPath *path, int trusted) { - path_invert(path); + path_invert (path); peer_info_add_path (peer_info, path, trusted); } @@ -1646,29 +1606,28 @@ path_build_from_dht (const struct GNUNET_PeerIdentity *get_path, p = path_new (1); p->peers[0] = myid; - GNUNET_PEER_change_rc(myid, 1); + GNUNET_PEER_change_rc (myid, 1); i = get_path_length; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: GET has %d hops.\n", i); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: GET has %d hops.\n", i); for (i--; i >= 0; i--) { id = GNUNET_PEER_intern (&get_path[i]); if (p->length > 0 && id == p->peers[p->length - 1]) { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: Optimizing 1 hop out.\n"); - GNUNET_PEER_change_rc(id, -1); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Optimizing 1 hop out.\n"); + GNUNET_PEER_change_rc (id, -1); } else { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "MESH: Adding from GET: %s.\n", - GNUNET_i2s(&get_path[i])); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Adding from GET: %s.\n", + GNUNET_i2s (&get_path[i])); p->length++; p->peers = GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * p->length); p->peers[p->length - 1] = id; } } i = put_path_length; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: PUT has %d hops.\n", i); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: PUT has %d hops.\n", i); for (i--; i >= 0; i--) { id = GNUNET_PEER_intern (&put_path[i]); @@ -1682,14 +1641,13 @@ path_build_from_dht (const struct GNUNET_PeerIdentity *get_path, } if (p->length > 0 && id == p->peers[p->length - 1]) { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: Optimizing 1 hop out.\n"); - GNUNET_PEER_change_rc(id, -1); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Optimizing 1 hop out.\n"); + GNUNET_PEER_change_rc (id, -1); } else { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "MESH: Adding from PUT: %s.\n", - GNUNET_i2s(&put_path[i])); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Adding from PUT: %s.\n", + GNUNET_i2s (&put_path[i])); p->length++; p->peers = GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * p->length); p->peers[p->length - 1] = id; @@ -1697,25 +1655,20 @@ path_build_from_dht (const struct GNUNET_PeerIdentity *get_path, } #if MESH_DEBUG if (get_path_length > 0) - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: (first of GET: %s)\n", - GNUNET_i2s(&get_path[0])); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: (first of GET: %s)\n", + GNUNET_i2s (&get_path[0])); if (put_path_length > 0) - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: (first of PUT: %s)\n", - GNUNET_i2s(&put_path[0])); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: In total: %d hops\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: (first of PUT: %s)\n", + GNUNET_i2s (&put_path[0])); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: In total: %d hops\n", p->length); for (i = 0; i < p->length; i++) { struct GNUNET_PeerIdentity peer_id; - GNUNET_PEER_resolve(p->peers[i], &peer_id); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: %u: %s\n", - p->peers[i], - GNUNET_i2s(&peer_id)); + GNUNET_PEER_resolve (p->peers[i], &peer_id); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %u: %s\n", p->peers[i], + GNUNET_i2s (&peer_id)); } #endif return p; @@ -1831,6 +1784,7 @@ notify_peer_disconnected (void *cls, GNUNET_PEER_Id peer_id) if (NULL != t->client && NULL != nc) { struct GNUNET_MESH_PeerControl msg; + msg.header.size = htons (sizeof (msg)); msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL); msg.tunnel_id = htonl (t->local_tid); @@ -1838,11 +1792,11 @@ notify_peer_disconnected (void *cls, GNUNET_PEER_Id peer_id) GNUNET_SERVER_notification_context_unicast (nc, t->client->handle, &msg.header, GNUNET_NO); } - peer = peer_info_get_short(peer_id); + peer = peer_info_get_short (peer_id); path_info = GNUNET_malloc (sizeof (struct MeshPathInfo)); path_info->peer = peer; path_info->t = t; - GNUNET_SCHEDULER_add_now(&peer_info_connect_task, path_info); + GNUNET_SCHEDULER_add_now (&peer_info_connect_task, path_info); } @@ -1864,23 +1818,22 @@ tunnel_add_peer (struct MeshTunnel *t, struct MeshPeerInfo *peer) unsigned int best_cost; unsigned int cost; - GNUNET_PEER_resolve(peer->id, &id); + GNUNET_PEER_resolve (peer->id, &id); if (GNUNET_NO == - GNUNET_CONTAINER_multihashmap_contains(t->peers, &id.hashPubKey)) + GNUNET_CONTAINER_multihashmap_contains (t->peers, &id.hashPubKey)) { t->peers_total++; GNUNET_array_append (peer->tunnels, peer->ntunnels, t); - GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put( - t->peers, - &id.hashPubKey, - peer, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); + GNUNET_assert (GNUNET_OK == + GNUNET_CONTAINER_multihashmap_put (t->peers, &id.hashPubKey, + peer, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); } if (NULL != (p = peer->path_head)) { best_p = p; - best_cost = path_get_cost(t->tree, p); + best_cost = path_get_cost (t->tree, p); while (NULL != p) { if ((cost = path_get_cost (t->tree, p)) < best_cost) @@ -1898,7 +1851,7 @@ tunnel_add_peer (struct MeshTunnel *t, struct MeshPeerInfo *peer) else { /* Start a DHT get if necessary */ - peer_info_connect(peer, t); + peer_info_connect (peer, t); } } @@ -1913,22 +1866,19 @@ tunnel_add_peer (struct MeshTunnel *t, struct MeshPeerInfo *peer) * */ static void -tunnel_add_path (struct MeshTunnel *t, - struct MeshPeerPath *p, +tunnel_add_path (struct MeshTunnel *t, struct MeshPeerPath *p, unsigned int own_pos) { struct GNUNET_PeerIdentity id; GNUNET_assert (0 != own_pos); - tree_add_path(t->tree, p, NULL, NULL); + tree_add_path (t->tree, p, NULL, NULL); if (tree_get_me (t->tree) == 0) tree_set_me (t->tree, p->peers[own_pos]); if (own_pos < p->length - 1) { GNUNET_PEER_resolve (p->peers[own_pos + 1], &id); - tree_update_first_hops(t->tree, - tree_get_me (t->tree), - &id); + tree_update_first_hops (t->tree, tree_get_me (t->tree), &id); } } @@ -1947,24 +1897,21 @@ tunnel_add_path (struct MeshTunnel *t, * 0 if the tunnel remained unaffected. */ static GNUNET_PEER_Id -tunnel_notify_connection_broken (struct MeshTunnel *t, - GNUNET_PEER_Id p1, +tunnel_notify_connection_broken (struct MeshTunnel *t, GNUNET_PEER_Id p1, GNUNET_PEER_Id p2) { GNUNET_PEER_Id pid; - pid = tree_notify_connection_broken (t->tree, - p1, - p2, - ¬ify_peer_disconnected, - t); + pid = + tree_notify_connection_broken (t->tree, p1, p2, ¬ify_peer_disconnected, + t); if (myid != p1 && myid != p2) { return pid; } if (pid != myid) { - if (tree_get_predecessor(t->tree) != 0) + if (tree_get_predecessor (t->tree) != 0) { /* We are the peer still connected, notify owner of the disconnection. */ struct GNUNET_MESH_PathBroken msg; @@ -2002,8 +1949,7 @@ struct MeshMulticastData * Send a multicast packet to a neighbor. */ static void -tunnel_send_multicast_iterator (void *cls, - GNUNET_PEER_Id neighbor_id) +tunnel_send_multicast_iterator (void *cls, GNUNET_PEER_Id neighbor_id) { struct MeshMulticastData *mdata = cls; struct MeshDataDescriptor *info; @@ -2025,24 +1971,20 @@ tunnel_send_multicast_iterator (void *cls, info->destination = neighbor_id; GNUNET_PEER_resolve (neighbor_id, &neighbor); #if MESH_DEBUG - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: sending to %s...\n", - GNUNET_i2s (&neighbor)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: sending to %s...\n", + GNUNET_i2s (&neighbor)); #endif - info->peer = peer_info_get(&neighbor); + info->peer = peer_info_get (&neighbor); GNUNET_assert (NULL != info->peer); - i = peer_info_transmit_slot(info->peer); + i = peer_info_transmit_slot (info->peer); info->handler_n = i; info->peer->infos[i] = info; info->peer->types[i] = GNUNET_MESSAGE_TYPE_MESH_MULTICAST; info->peer->core_transmit[i] = - GNUNET_CORE_notify_transmit_ready (core_handle, - 0, - 0, - GNUNET_TIME_UNIT_FOREVER_REL, - &neighbor, - info->size, - &send_core_data_multicast, info); + GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0, + GNUNET_TIME_UNIT_FOREVER_REL, + &neighbor, info->size, + &send_core_data_multicast, info); } /** @@ -2072,9 +2014,9 @@ tunnel_send_multicast (struct MeshTunnel *t, if (NULL != t->client) { mdata->task = GNUNET_malloc (sizeof (GNUNET_SCHEDULER_TaskIdentifier)); - *(mdata->task) = GNUNET_SCHEDULER_add_delayed (UNACKNOWLEDGED_WAIT, - &client_allow_send, - t->client->handle); + *(mdata->task) = + GNUNET_SCHEDULER_add_delayed (UNACKNOWLEDGED_WAIT, &client_allow_send, + t->client->handle); } tree_iterate_children (t->tree, &tunnel_send_multicast_iterator, mdata); @@ -2140,11 +2082,9 @@ tunnel_destroy (struct MeshTunnel *t) { struct GNUNET_PeerIdentity id; - GNUNET_PEER_resolve(t->id.oid, &id); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: destroying tunnel %s [%x]\n", - GNUNET_i2s (&id), - t->id.tid); + GNUNET_PEER_resolve (t->id.oid, &id); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: destroying tunnel %s [%x]\n", + GNUNET_i2s (&id), t->id.tid); if (NULL != c) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: by client %u\n", c->id); } @@ -2166,12 +2106,13 @@ tunnel_destroy (struct MeshTunnel *t) { GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash); GNUNET_break (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (incoming_tunnels, &hash, t)); + GNUNET_CONTAINER_multihashmap_remove (incoming_tunnels, &hash, + t)); } if (NULL != t->peers) { - GNUNET_CONTAINER_multihashmap_iterate(t->peers, - &peer_info_delete_tunnel, t); + GNUNET_CONTAINER_multihashmap_iterate (t->peers, &peer_info_delete_tunnel, + t); GNUNET_CONTAINER_multihashmap_destroy (t->peers); } q = t->queue_head; @@ -2184,13 +2125,13 @@ tunnel_destroy (struct MeshTunnel *t) q = qn; /* TODO cancel core transmit ready in case it was active */ } - tree_destroy(t->tree); + tree_destroy (t->tree); if (NULL != t->dht_get_type) - GNUNET_DHT_get_stop(t->dht_get_type); + GNUNET_DHT_get_stop (t->dht_get_type); if (GNUNET_SCHEDULER_NO_TASK != t->timeout_task) - GNUNET_SCHEDULER_cancel(t->timeout_task); + GNUNET_SCHEDULER_cancel (t->timeout_task); if (GNUNET_SCHEDULER_NO_TASK != t->path_refresh_task) - GNUNET_SCHEDULER_cancel(t->path_refresh_task); + GNUNET_SCHEDULER_cancel (t->path_refresh_task); GNUNET_free (t); return r; } @@ -2205,8 +2146,7 @@ tunnel_destroy (struct MeshTunnel *t) * @param p Peer which should be removed. */ static void -tunnel_delete_peer (struct MeshTunnel *t, - GNUNET_PEER_Id peer) +tunnel_delete_peer (struct MeshTunnel *t, GNUNET_PEER_Id peer) { if (GNUNET_NO == tree_del_peer (t->tree, peer, NULL, NULL)) tunnel_destroy (t); @@ -2216,11 +2156,11 @@ tunnel_delete_peer (struct MeshTunnel *t, /** * tunnel_destroy_iterator: iterator for deleting each tunnel that belongs to a * client when the client disconnects. - * + * * @param cls closure (client that is disconnecting) * @param key the hash of the local tunnel id (used to access the hashmap) * @param value the value stored at the key (tunnel to destroy) - * + * * @return GNUNET_OK on success */ static int @@ -2261,10 +2201,9 @@ tunnel_reset_timeout (struct MeshTunnel *t) { if (GNUNET_SCHEDULER_NO_TASK != t->timeout_task) GNUNET_SCHEDULER_cancel (t->timeout_task); - t->timeout_task = GNUNET_SCHEDULER_add_delayed ( - GNUNET_TIME_relative_multiply(REFRESH_PATH_TIME, 4), - &tunnel_timeout, - t); + t->timeout_task = + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply + (REFRESH_PATH_TIME, 4), &tunnel_timeout, t); } @@ -2295,8 +2234,7 @@ send_core_create_path (void *cls, size_t size, void *buf) size_t size_needed; int i; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: CREATE PATH sending...\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: CREATE PATH sending...\n"); size_needed = sizeof (struct GNUNET_MESH_ManipulatePath) + p->length * sizeof (struct GNUNET_PeerIdentity); @@ -2305,15 +2243,15 @@ send_core_create_path (void *cls, size_t size, void *buf) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: create path retransmit!\n"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: buf: %p\n", buf); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: size: (%u/%u)\n", - size, size_needed); - info->peer->core_transmit[info->pos] = - GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0, - GNUNET_TIME_UNIT_FOREVER_REL, - path_get_first_hop (t->tree, peer->id), - size_needed, - &send_core_create_path, - info); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: size: (%u/%u)\n", size, + size_needed); + info->peer->core_transmit[info->pos] = + GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0, + GNUNET_TIME_UNIT_FOREVER_REL, + path_get_first_hop (t->tree, + peer->id), + size_needed, &send_core_create_path, + info); return 0; } info->peer->core_transmit[info->pos] = NULL; @@ -2324,8 +2262,7 @@ send_core_create_path (void *cls, size_t size, void *buf) GNUNET_PEER_resolve (peer->id, &id); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: setting core_transmit %s [%u] to NULL\n", - GNUNET_i2s (&id), - info->pos); + GNUNET_i2s (&id), info->pos); } #endif msg = (struct GNUNET_MESH_ManipulatePath *) buf; @@ -2343,8 +2280,7 @@ send_core_create_path (void *cls, size_t size, void *buf) GNUNET_free (info); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: CREATE PATH (%u bytes long) sent!\n", - size_needed); + "MESH: CREATE PATH (%u bytes long) sent!\n", size_needed); return size_needed; } @@ -2358,7 +2294,7 @@ send_core_create_path (void *cls, size_t size, void *buf) * @param cls closure (data itself) * @param size number of bytes available in buf * @param buf where the callee should write the message - * + * * @return number of bytes written to buf */ static size_t @@ -2379,18 +2315,14 @@ send_core_data_multicast (void *cls, size_t size, void *buf) struct GNUNET_PeerIdentity id; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: Multicast: retransmitting... (%u/%u)\n", - size, total_size); - GNUNET_PEER_resolve(info->peer->id, &id); + "MESH: Multicast: retransmitting... (%u/%u)\n", size, + total_size); + GNUNET_PEER_resolve (info->peer->id, &id); info->peer->core_transmit[info->handler_n] = - GNUNET_CORE_notify_transmit_ready (core_handle, - 0, - 0, - GNUNET_TIME_UNIT_FOREVER_REL, - &id, - total_size, - &send_core_data_multicast, - info); + GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0, + GNUNET_TIME_UNIT_FOREVER_REL, &id, + total_size, + &send_core_data_multicast, info); return 0; } info->peer->core_transmit[info->handler_n] = NULL; @@ -2408,16 +2340,13 @@ send_core_data_multicast (void *cls, size_t size, void *buf) mc = (struct GNUNET_MESH_Multicast *) mh; mh = (struct GNUNET_MessageHeader *) &mc[1]; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: multicast, payload type %u\n", - ntohs (mh->type)); + "MESH: multicast, payload type %u\n", ntohs (mh->type)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: multicast, payload size %u\n", - ntohs (mh->size)); + "MESH: multicast, payload size %u\n", ntohs (mh->size)); } else { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: type %u\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type %u\n", ntohs (mh->type)); } } @@ -2483,7 +2412,7 @@ send_core_path_ack (void *cls, size_t size, void *buf) * @param peer peer identity this notification is about * @param atsi performance data * @param atsi_count number of records in 'atsi' - * + * * @return GNUNET_OK to keep the connection open, * GNUNET_SYSERR to close it (signal serious error) */ @@ -2491,7 +2420,7 @@ static int handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { unsigned int own_pos; uint16_t size; @@ -2507,7 +2436,7 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Received a path create msg [%s]\n", - GNUNET_i2s(&my_full_id)); + GNUNET_i2s (&my_full_id)); size = ntohs (message->size); if (size < sizeof (struct GNUNET_MESH_ManipulatePath)) { @@ -2527,18 +2456,14 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, GNUNET_break_op (0); return GNUNET_OK; } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: path has %u hops.\n", - size); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: path has %u hops.\n", size); msg = (struct GNUNET_MESH_ManipulatePath *) message; tid = ntohl (msg->tid); pi = (struct GNUNET_PeerIdentity *) &msg[1]; t = tunnel_get (pi, tid); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: path is for tunnel %s [%X].\n", - GNUNET_i2s(pi), - tid); + "MESH: path is for tunnel %s [%X].\n", GNUNET_i2s (pi), tid); if (NULL == t) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Creating tunnel\n"); @@ -2549,15 +2474,12 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, next_local_tid = (next_local_tid + 1) | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV; t->local_tid = next_local_tid++; next_local_tid = next_local_tid | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV; - t->tree = tree_new(t->id.oid); + t->tree = tree_new (t->id.oid); GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash); if (GNUNET_OK != - GNUNET_CONTAINER_multihashmap_put ( - tunnels, - &hash, - t, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) + GNUNET_CONTAINER_multihashmap_put (tunnels, &hash, t, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) { tunnel_destroy (t); GNUNET_break (0); @@ -2566,11 +2488,8 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, tunnel_reset_timeout (t); GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash); if (GNUNET_OK != - GNUNET_CONTAINER_multihashmap_put ( - incoming_tunnels, - &hash, - t, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) + GNUNET_CONTAINER_multihashmap_put (incoming_tunnels, &hash, t, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) { tunnel_destroy (t); GNUNET_break (0); @@ -2604,15 +2523,13 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, own_pos = 0; for (i = 0; i < size; i++) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: ... adding %s\n", - GNUNET_i2s(&pi[i])); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: ... adding %s\n", + GNUNET_i2s (&pi[i])); path->peers[i] = GNUNET_PEER_intern (&pi[i]); if (path->peers[i] == myid) own_pos = i; } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: Own position: %u\n", own_pos); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Own position: %u\n", own_pos); if (own_pos == 0) { /* cannot be self, must be 'not found' */ @@ -2630,22 +2547,22 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, struct MeshDataDescriptor *info; unsigned int j; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: It's for us!\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: It's for us!\n"); peer_info_add_path_to_origin (orig_peer_info, path, GNUNET_NO); if (NULL == t->peers) - t->peers = GNUNET_CONTAINER_multihashmap_create(4); - GNUNET_break (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put ( - t->peers, - &my_full_id.hashPubKey, - peer_info_get(&my_full_id), - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); + t->peers = GNUNET_CONTAINER_multihashmap_create (4); + GNUNET_break (GNUNET_OK == + GNUNET_CONTAINER_multihashmap_put (t->peers, + &my_full_id.hashPubKey, + peer_info_get + (&my_full_id), + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); /* FIXME use send_message */ info = GNUNET_malloc (sizeof (struct MeshDataDescriptor)); info->origin = &t->id; info->peer = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); GNUNET_assert (NULL != info->peer); - j = peer_info_transmit_slot(info->peer); + j = peer_info_transmit_slot (info->peer); info->handler_n = j; info->peer->types[j] = GNUNET_MESSAGE_TYPE_MESH_PATH_ACK; info->peer->infos[j] = info; @@ -2654,24 +2571,23 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, GNUNET_TIME_UNIT_FOREVER_REL, peer, sizeof (struct GNUNET_MESH_PathACK), &send_core_path_ack, info); - cmsg.header.size = htons(sizeof(cmsg)); - cmsg.header.type = htons(GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE); - GNUNET_PEER_resolve(t->id.oid, &cmsg.peer); - cmsg.tunnel_id = htonl(t->local_tid); - GNUNET_SERVER_notification_context_broadcast(nc, &cmsg.header, GNUNET_NO); + cmsg.header.size = htons (sizeof (cmsg)); + cmsg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE); + GNUNET_PEER_resolve (t->id.oid, &cmsg.peer); + cmsg.tunnel_id = htonl (t->local_tid); + GNUNET_SERVER_notification_context_broadcast (nc, &cmsg.header, GNUNET_NO); } else { struct MeshPeerPath *path2; /* It's for somebody else! Retransmit. */ - path2 = path_duplicate(path); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: Retransmitting.\n"); - peer_info_add_path(dest_peer_info, path2, GNUNET_NO); - path2 = path_duplicate(path); - peer_info_add_path_to_origin(orig_peer_info, path2, GNUNET_NO); - send_create_path(dest_peer_info, path, t); + path2 = path_duplicate (path); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Retransmitting.\n"); + peer_info_add_path (dest_peer_info, path2, GNUNET_NO); + path2 = path_duplicate (path); + peer_info_add_path_to_origin (orig_peer_info, path2, GNUNET_NO); + send_create_path (dest_peer_info, path, t); } return GNUNET_OK; } @@ -2693,7 +2609,7 @@ static int handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { struct GNUNET_MESH_ManipulatePath *msg; struct GNUNET_PeerIdentity *pi; @@ -2704,8 +2620,7 @@ handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer, size_t size; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: Received a PATH DESTROY msg from %s\n", - GNUNET_i2s(peer)); + "MESH: Received a PATH DESTROY msg from %s\n", GNUNET_i2s (peer)); size = ntohs (message->size); if (size < sizeof (struct GNUNET_MESH_ManipulatePath)) { @@ -2725,15 +2640,12 @@ handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer, GNUNET_break_op (0); return GNUNET_OK; } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: path has %u hops.\n", - size); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: path has %u hops.\n", size); msg = (struct GNUNET_MESH_ManipulatePath *) message; pi = (struct GNUNET_PeerIdentity *) &msg[1]; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: path is for tunnel %s [%X].\n", - GNUNET_i2s(pi), + "MESH: path is for tunnel %s [%X].\n", GNUNET_i2s (pi), msg->tid); t = tunnel_get (pi, ntohl (msg->tid)); if (NULL == t) @@ -2747,15 +2659,13 @@ handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer, own_pos = 0; for (i = 0; i < size; i++) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: ... adding %s\n", - GNUNET_i2s(&pi[i])); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: ... adding %s\n", + GNUNET_i2s (&pi[i])); path->peers[i] = GNUNET_PEER_intern (&pi[i]); if (path->peers[i] == myid) own_pos = i; } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: Own position: %u\n", own_pos); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Own position: %u\n", own_pos); if (own_pos < path->length - 1) send_message (message, &pi[own_pos + 1]); tunnel_delete_peer (t, path->peers[path->length - 1]); @@ -2778,32 +2688,28 @@ handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer, */ static int handle_mesh_path_broken (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + const struct GNUNET_MessageHeader *message, + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { struct GNUNET_MESH_PathBroken *msg; struct MeshTunnel *t; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: Received a PATH BROKEN msg from %s\n", - GNUNET_i2s(peer)); + "MESH: Received a PATH BROKEN msg from %s\n", GNUNET_i2s (peer)); msg = (struct GNUNET_MESH_PathBroken *) message; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: regarding %s\n", - GNUNET_i2s(&msg->peer1)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: regarding %s\n", - GNUNET_i2s(&msg->peer2)); - t = tunnel_get(&msg->oid, ntohl (msg->tid)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: regarding %s\n", + GNUNET_i2s (&msg->peer1)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: regarding %s\n", + GNUNET_i2s (&msg->peer2)); + t = tunnel_get (&msg->oid, ntohl (msg->tid)); if (NULL == t) { GNUNET_break_op (0); return GNUNET_OK; } - tunnel_notify_connection_broken(t, - GNUNET_PEER_search(&msg->peer1), - GNUNET_PEER_search(&msg->peer2)); + tunnel_notify_connection_broken (t, GNUNET_PEER_search (&msg->peer1), + GNUNET_PEER_search (&msg->peer2)); return GNUNET_OK; } @@ -2825,19 +2731,16 @@ static int handle_mesh_tunnel_destroy (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { struct GNUNET_MESH_TunnelDestroy *msg; struct MeshTunnel *t; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: Got a TUNNEL DESTROY packet from %s\n", - GNUNET_i2s (peer)); + "MESH: Got a TUNNEL DESTROY packet from %s\n", GNUNET_i2s (peer)); msg = (struct GNUNET_MESH_TunnelDestroy *) message; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: for tunnel %s [%u]\n", - GNUNET_i2s (&msg->oid), - ntohl (msg->tid)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: for tunnel %s [%u]\n", + GNUNET_i2s (&msg->oid), ntohl (msg->tid)); t = tunnel_get (&msg->oid, ntohl (msg->tid)); if (NULL == t) { @@ -2878,15 +2781,14 @@ static int handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { struct GNUNET_MESH_Unicast *msg; struct MeshTunnel *t; GNUNET_PEER_Id pid; size_t size; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: got a unicast packet from %s\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: got a unicast packet from %s\n", GNUNET_i2s (peer)); size = ntohs (message->size); if (size < @@ -2897,8 +2799,7 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer, return GNUNET_OK; } msg = (struct GNUNET_MESH_Unicast *) message; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: of type %u\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: of type %u\n", ntohs (msg[1].header.type)); t = tunnel_get (&msg->oid, ntohl (msg->tid)); if (NULL == t) @@ -2908,7 +2809,7 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer, return GNUNET_OK; } tunnel_reset_timeout (t); - pid = GNUNET_PEER_search(&msg->destination); + pid = GNUNET_PEER_search (&msg->destination); if (pid == myid) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -2918,7 +2819,7 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer, } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: not for us, retransmitting...\n"); - send_message (message, path_get_first_hop(t->tree, pid)); + send_message (message, path_get_first_hop (t->tree, pid)); return GNUNET_OK; } @@ -2940,14 +2841,13 @@ static int handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { struct GNUNET_MESH_Multicast *msg; struct MeshTunnel *t; size_t size; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: got a multicast packet from %s\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: got a multicast packet from %s\n", GNUNET_i2s (peer)); size = ntohs (message->size); if (sizeof (struct GNUNET_MESH_Multicast) + @@ -2973,7 +2873,7 @@ handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer, { send_subscribed_clients (message, &msg[1].header); } - tunnel_send_multicast(t, message); + tunnel_send_multicast (t, message); return GNUNET_OK; } @@ -2994,7 +2894,7 @@ static int handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { struct GNUNET_MESH_ToOrigin *msg; struct GNUNET_PeerIdentity id; @@ -3002,8 +2902,7 @@ handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer, struct MeshTunnel *t; size_t size; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: got a ToOrigin packet from %s\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: got a ToOrigin packet from %s\n", GNUNET_i2s (peer)); size = ntohs (message->size); if (size < sizeof (struct GNUNET_MESH_ToOrigin) + /* Payload must be */ @@ -3013,8 +2912,7 @@ handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer, return GNUNET_OK; } msg = (struct GNUNET_MESH_ToOrigin *) message; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: of type %u\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: of type %u\n", ntohs (msg[1].header.type)); t = tunnel_get (&msg->oid, ntohl (msg->tid)); @@ -3035,8 +2933,7 @@ handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer, if (NULL == t->client) { /* got data packet for ownerless tunnel */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: no clients!\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: no clients!\n"); GNUNET_break_op (0); return GNUNET_OK; } @@ -3044,10 +2941,8 @@ handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer, memcpy (cbuf, message, size); copy = (struct GNUNET_MESH_ToOrigin *) cbuf; copy->tid = htonl (t->local_tid); - GNUNET_SERVER_notification_context_unicast (nc, - t->client->handle, - ©->header, - GNUNET_YES); + GNUNET_SERVER_notification_context_unicast (nc, t->client->handle, + ©->header, GNUNET_YES); return GNUNET_OK; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -3060,7 +2955,7 @@ handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer, GNUNET_break (0); return GNUNET_OK; } - GNUNET_PEER_resolve (tree_get_predecessor(t->tree), &id); + GNUNET_PEER_resolve (tree_get_predecessor (t->tree), &id); send_message (message, &id); return GNUNET_OK; @@ -3083,16 +2978,15 @@ static int handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { struct GNUNET_MESH_PathACK *msg; struct GNUNET_PeerIdentity id; struct MeshPeerInfo *peer_info; struct MeshTunnel *t; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: Received a path ACK msg [%s]\n", - GNUNET_i2s(&my_full_id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Received a path ACK msg [%s]\n", + GNUNET_i2s (&my_full_id)); msg = (struct GNUNET_MESH_PathACK *) message; t = tunnel_get (&msg->oid, msg->tid); if (NULL == t) @@ -3116,14 +3010,14 @@ handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer, t->dht_get_type = NULL; } peer_info = peer_info_get (&msg->peer_id); - tree_set_status(t->tree, peer_info->id, MESH_PEER_READY); - send_client_peer_connected(t, peer_info->id); + tree_set_status (t->tree, peer_info->id, MESH_PEER_READY); + send_client_peer_connected (t, peer_info->id); return GNUNET_OK; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: not for us, retransmitting...\n"); - GNUNET_PEER_resolve(tree_get_predecessor(t->tree), &id); + GNUNET_PEER_resolve (tree_get_predecessor (t->tree), &id); peer_info = peer_info_get (&msg->oid); if (NULL == peer_info) { @@ -3143,13 +3037,13 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = { {&handle_mesh_path_create, GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE, 0}, {&handle_mesh_path_destroy, GNUNET_MESSAGE_TYPE_MESH_PATH_DESTROY, 0}, {&handle_mesh_path_broken, GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN, - sizeof (struct GNUNET_MESH_PathBroken)}, + sizeof (struct GNUNET_MESH_PathBroken)}, {&handle_mesh_tunnel_destroy, GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY, 0}, {&handle_mesh_data_unicast, GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0}, {&handle_mesh_data_multicast, GNUNET_MESSAGE_TYPE_MESH_MULTICAST, 0}, {&handle_mesh_data_to_orig, GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN, 0}, {&handle_mesh_path_ack, GNUNET_MESSAGE_TYPE_MESH_PATH_ACK, - sizeof (struct GNUNET_MESH_PathACK)}, + sizeof (struct GNUNET_MESH_PathACK)}, {NULL, 0, 0} }; @@ -3161,18 +3055,19 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = { /** * deregister_app: iterator for removing each application registered by a client - * + * * @param cls closure * @param key the hash of the application id (used to access the hashmap) * @param value the value stored at the key (client) - * + * * @return GNUNET_OK on success */ static int deregister_app (void *cls, const GNUNET_HashCode * key, void *value) { - GNUNET_break (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (applications, key, value)); + GNUNET_break (GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove (applications, key, + value)); return GNUNET_OK; } @@ -3230,8 +3125,9 @@ path_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) struct MeshTunnel *t = cls; struct GNUNET_MessageHeader *payload; struct GNUNET_MESH_Multicast *msg; - size_t size = sizeof(struct GNUNET_MESH_Multicast) + - sizeof(struct GNUNET_MessageHeader); + size_t size = + sizeof (struct GNUNET_MESH_Multicast) + + sizeof (struct GNUNET_MessageHeader); char cbuf[size]; if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) @@ -3241,16 +3137,15 @@ path_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) t->path_refresh_task = GNUNET_SCHEDULER_NO_TASK; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: sending keepalive for tunnel %d\n", - t->id.tid); + "MESH: sending keepalive for tunnel %d\n", t->id.tid); msg = (struct GNUNET_MESH_Multicast *) cbuf; msg->header.size = htons (size); msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_MULTICAST); msg->oid = my_full_id; - msg->tid = htonl(t->id.tid); + msg->tid = htonl (t->id.tid); payload = (struct GNUNET_MessageHeader *) &msg[1]; - payload->size = htons (sizeof(struct GNUNET_MessageHeader)); + payload->size = htons (sizeof (struct GNUNET_MessageHeader)); payload->type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_KEEPALIVE); tunnel_send_multicast (t, &msg->header); @@ -3280,30 +3175,27 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, const struct GNUNET_PeerIdentity *get_path, unsigned int get_path_length, const struct GNUNET_PeerIdentity *put_path, - unsigned int put_path_length, - enum GNUNET_BLOCK_Type type, size_t size, const void *data) + unsigned int put_path_length, enum GNUNET_BLOCK_Type type, + size_t size, const void *data) { struct MeshPathInfo *path_info = cls; struct MeshPeerPath *p; struct GNUNET_PeerIdentity pi; int i; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "MESH: Got results from DHT!\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Got results from DHT!\n"); GNUNET_PEER_resolve (path_info->peer->id, &pi); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "MESH: for %s\n", - GNUNET_i2s(&pi)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: for %s\n", GNUNET_i2s (&pi)); // GNUNET_DHT_get_stop(path_info->peer->dhtget); // path_info->peer->dhtget = NULL; - p = path_build_from_dht (get_path, get_path_length, - put_path, put_path_length); + p = path_build_from_dht (get_path, get_path_length, put_path, + put_path_length); peer_info_add_path (path_info->peer, p, GNUNET_NO); for (i = 0; i < path_info->peer->ntunnels; i++) { tunnel_add_peer (path_info->peer->tunnels[i], path_info->peer); - peer_info_connect(path_info->peer, path_info->t); + peer_info_connect (path_info->peer, path_info->t); } // GNUNET_free (path_info); @@ -3327,11 +3219,10 @@ static void dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp, const GNUNET_HashCode * key, const struct GNUNET_PeerIdentity *get_path, - unsigned int get_path_length, + unsigned int get_path_length, const struct GNUNET_PeerIdentity *put_path, - unsigned int put_path_length, - enum GNUNET_BLOCK_Type type, size_t size, - const void *data) + unsigned int put_path_length, enum GNUNET_BLOCK_Type type, + size_t size, const void *data) { const struct GNUNET_PeerIdentity *pi = data; struct MeshTunnel *t = cls; @@ -3345,16 +3236,14 @@ dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp, } GNUNET_assert (NULL != t->client); peer_info = peer_info_get (pi); - (void) GNUNET_CONTAINER_multihashmap_put ( - t->peers, - &pi->hashPubKey, - peer_info, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); - - p = path_build_from_dht (get_path, get_path_length, - put_path, put_path_length); + (void) GNUNET_CONTAINER_multihashmap_put (t->peers, &pi->hashPubKey, + peer_info, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); + + p = path_build_from_dht (get_path, get_path_length, put_path, + put_path_length); peer_info_add_path (peer_info, p, GNUNET_NO); - tunnel_add_peer(t, peer_info); + tunnel_add_peer (t, peer_info); peer_info_connect (peer_info, t); } @@ -3397,8 +3286,7 @@ handle_local_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) if (NULL != c->tunnels) { GNUNET_CONTAINER_multihashmap_iterate (c->tunnels, - &tunnel_destroy_iterator, - c); + &tunnel_destroy_iterator, c); GNUNET_CONTAINER_multihashmap_destroy (c->tunnels); } @@ -3467,7 +3355,8 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client, #if MESH_DEBUG c->id = next_client_id++; #endif - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: CLIENT NEW %u at %p\n", c->id, c); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: CLIENT NEW %u at %p\n", c->id, + c); c->handle = client; GNUNET_SERVER_client_keep (client); a = (GNUNET_MESH_ApplicationType *) &cc_msg[1]; @@ -3589,20 +3478,16 @@ handle_local_tunnel_create (void *cls, struct GNUNET_SERVER_Client *client, t->id.oid = myid; t->local_tid = ntohl (t_msg->tunnel_id); #if MESH_DEBUG - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: CREATED TUNNEL %s [%x] (%x)\n", - GNUNET_i2s (&my_full_id), - t->id.tid, - t->local_tid); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: CREATED TUNNEL %s [%x] (%x)\n", + GNUNET_i2s (&my_full_id), t->id.tid, t->local_tid); #endif t->client = c; t->peers = GNUNET_CONTAINER_multihashmap_create (32); GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash); if (GNUNET_OK != - GNUNET_CONTAINER_multihashmap_put ( - c->tunnels, &hash, t, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) + GNUNET_CONTAINER_multihashmap_put (c->tunnels, &hash, t, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) { GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); @@ -3611,16 +3496,15 @@ handle_local_tunnel_create (void *cls, struct GNUNET_SERVER_Client *client, GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash); if (GNUNET_OK != - GNUNET_CONTAINER_multihashmap_put ( - tunnels, &hash, t, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) + GNUNET_CONTAINER_multihashmap_put (tunnels, &hash, t, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) { GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } t->tree = tree_new (myid); - tree_set_me(t->tree, myid); + tree_set_me (t->tree, myid); GNUNET_SERVER_receive_done (client, GNUNET_OK); return; @@ -3673,11 +3557,11 @@ handle_local_tunnel_destroy (void *cls, struct GNUNET_SERVER_Client *client, GNUNET_CRYPTO_hash (&tid, sizeof (MESH_TunnelNumber), &hash); t = GNUNET_CONTAINER_multihashmap_get (c->tunnels, &hash); GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (c->tunnels, &hash, t)); + GNUNET_CONTAINER_multihashmap_remove (c->tunnels, &hash, t)); t->client = NULL; tunnel_send_destroy (t); - tunnel_destroy(t); + tunnel_destroy (t); GNUNET_SERVER_receive_done (client, GNUNET_OK); return; } @@ -3700,7 +3584,7 @@ handle_local_connect_add (void *cls, struct GNUNET_SERVER_Client *client, struct MeshTunnel *t; MESH_TunnelNumber tid; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: Got connection request\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Got connection request\n"); /* Sanity check for client registration */ if (NULL == (c = client_get (client))) { @@ -3735,12 +3619,12 @@ handle_local_connect_add (void *cls, struct GNUNET_SERVER_Client *client, GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: for %s\n", - GNUNET_i2s(&peer_msg->peer)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: for %s\n", + GNUNET_i2s (&peer_msg->peer)); peer_info = peer_info_get (&peer_msg->peer); - tunnel_add_peer(t, peer_info); - peer_info_connect(peer_info, t); + tunnel_add_peer (t, peer_info); + peer_info_connect (peer_info, t); GNUNET_SERVER_receive_done (client, GNUNET_OK); return; @@ -3800,12 +3684,11 @@ handle_local_connect_del (void *cls, struct GNUNET_SERVER_Client *client, return; } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: for peer %s\n", - GNUNET_i2s(&peer_msg->peer)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: for peer %s\n", + GNUNET_i2s (&peer_msg->peer)); /* Is the peer in the tunnel? */ - peer_info = GNUNET_CONTAINER_multihashmap_get(t->peers, - &peer_msg->peer.hashPubKey); + peer_info = + GNUNET_CONTAINER_multihashmap_get (t->peers, &peer_msg->peer.hashPubKey); if (NULL == peer_info) { GNUNET_break (0); @@ -3818,7 +3701,7 @@ handle_local_connect_del (void *cls, struct GNUNET_SERVER_Client *client, &peer_msg->peer.hashPubKey); send_destroy_path (t, peer_info->id); - tunnel_delete_peer(t, peer_info->id); + tunnel_delete_peer (t, peer_info->id); GNUNET_SERVER_receive_done (client, GNUNET_OK); return; } @@ -3894,7 +3777,7 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: notifying client\n"); - send_client_peer_connected(t, myid); + send_client_peer_connected (t, myid); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Done\n"); GNUNET_SERVER_receive_done (client, GNUNET_OK); return; @@ -3907,14 +3790,10 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: looking in DHT for %s\n", GNUNET_h2s (&hash)); t->dht_get_type = - GNUNET_DHT_get_start (dht_handle, - GNUNET_TIME_UNIT_FOREVER_REL, - GNUNET_BLOCK_TYPE_TEST, - &hash, - 10U, + GNUNET_DHT_get_start (dht_handle, GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_BLOCK_TYPE_TEST, &hash, 10U, GNUNET_DHT_RO_RECORD_ROUTE | - GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, - NULL, 0, + GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, 0, &dht_get_type_handler, t); GNUNET_SERVER_receive_done (client, GNUNET_OK); @@ -3972,8 +3851,7 @@ handle_local_unicast (void *cls, struct GNUNET_SERVER_Client *client, } /* Is it a local tunnel? Then, does client own the tunnel? */ - if (NULL != t->client && - NULL != t->client->handle && + if (NULL != t->client && NULL != t->client->handle && t->client->handle != client) { GNUNET_break (0); @@ -4074,7 +3952,7 @@ handle_local_to_origin (void *cls, struct GNUNET_SERVER_Client *client, GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } - GNUNET_PEER_resolve(t->id.oid, &id); + GNUNET_PEER_resolve (t->id.oid, &id); /* Ok, everything is correct, send the message * (pretend we got it from a mesh peer) @@ -4153,16 +4031,16 @@ handle_local_multicast (void *cls, struct GNUNET_SERVER_Client *client, } { - char buf[ntohs(message->size)]; + char buf[ntohs (message->size)]; struct GNUNET_MESH_Multicast *copy; - copy = (struct GNUNET_MESH_Multicast *)buf; - memcpy(buf, message, ntohs(message->size)); + copy = (struct GNUNET_MESH_Multicast *) buf; + memcpy (buf, message, ntohs (message->size)); copy->oid = my_full_id; - copy->tid = htonl(t->id.tid); + copy->tid = htonl (t->id.tid); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: calling generic handler...\n"); - handle_mesh_data_multicast(client, &my_full_id, ©->header, NULL, 0); + handle_mesh_data_multicast (client, &my_full_id, ©->header, NULL, 0); } /* receive done gets called when last copy is sent to a neighbor */ @@ -4213,10 +4091,11 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server, { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Core init\n"); core_handle = server; - if (0 != memcmp(identity, &my_full_id, sizeof(my_full_id)) || NULL == server) + if (0 != memcmp (identity, &my_full_id, sizeof (my_full_id)) || + NULL == server) { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("MESH: Wrong CORE service\n")); - GNUNET_SCHEDULER_shutdown(); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("MESH: Wrong CORE service\n")); + GNUNET_SCHEDULER_shutdown (); } return; } @@ -4240,7 +4119,7 @@ core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, #if MESH_DEBUG_CONNECTION GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Peer connected\n"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s\n", - GNUNET_i2s(&my_full_id)); + GNUNET_i2s (&my_full_id)); #endif peer_info = peer_info_get (peer); if (myid == peer_info->id) @@ -4253,15 +4132,14 @@ core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, #if MESH_DEBUG_CONNECTION else { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s\n", - GNUNET_i2s(peer)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s\n", GNUNET_i2s (peer)); } #endif path = path_new (2); path->peers[0] = myid; path->peers[1] = peer_info->id; - GNUNET_PEER_change_rc(myid, 1); - GNUNET_PEER_change_rc(peer_info->id, 1); + GNUNET_PEER_change_rc (myid, 1); + GNUNET_PEER_change_rc (peer_info->id, 1); peer_info_add_path (peer_info, path, GNUNET_YES); return; } @@ -4290,7 +4168,7 @@ core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) for (i = 0; i < CORE_QUEUE_SIZE; i++) { /* TODO: notify that the transmission failed */ - peer_info_cancel_transmission(pi, i); + peer_info_cancel_transmission (pi, i); } peer_info_remove_path (pi, pi->id, myid); #if MESH_DEBUG_CONNECTION @@ -4320,7 +4198,8 @@ static int shutdown_tunnel (void *cls, const GNUNET_HashCode * key, void *value) { struct MeshTunnel *t = value; - tunnel_destroy(t); + + tunnel_destroy (t); return GNUNET_YES; } @@ -4337,6 +4216,7 @@ static int shutdown_peer (void *cls, const GNUNET_HashCode * key, void *value) { struct MeshPeerInfo *p = value; + peer_info_destroy (p); return GNUNET_YES; } @@ -4357,8 +4237,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_CORE_disconnect (core_handle); core_handle = NULL; } - GNUNET_CONTAINER_multihashmap_iterate(tunnels, &shutdown_tunnel, NULL); - GNUNET_CONTAINER_multihashmap_iterate(peers, &shutdown_peer, NULL); + GNUNET_CONTAINER_multihashmap_iterate (tunnels, &shutdown_tunnel, NULL); + GNUNET_CONTAINER_multihashmap_iterate (peers, &shutdown_peer, NULL); if (dht_handle != NULL) { GNUNET_DHT_disconnect (dht_handle); @@ -4414,8 +4294,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, } if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY", - &keyfile)) + GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY", + &keyfile)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ @@ -4463,8 +4343,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, nc = GNUNET_SERVER_notification_context_create (server_handle, LOCAL_QUEUE_SIZE); GNUNET_SERVER_disconnect_notify (server_handle, - &handle_local_client_disconnect, - NULL); + &handle_local_client_disconnect, NULL); clients = NULL; @@ -4477,11 +4356,11 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, announce_id_task = GNUNET_SCHEDULER_add_now (&announce_id, cls); /* Create a peer_info for the local peer */ - peer = peer_info_get(&my_full_id); + peer = peer_info_get (&my_full_id); p = path_new (1); p->peers[0] = myid; GNUNET_PEER_change_rc (myid, 1); - peer_info_add_path(peer, p, GNUNET_YES); + peer_info_add_path (peer, p, GNUNET_YES); /* Scheduled the task to clean up when shutdown is called */ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c index 33cb41179..35bbab3a1 100644 --- a/src/mesh/mesh_api.c +++ b/src/mesh/mesh_api.c @@ -903,10 +903,8 @@ process_incoming_data (struct GNUNET_MESH_Handle *h, t = retrieve_tunnel (h, ntohl (ucast->tid)); payload = (struct GNUNET_MessageHeader *) &ucast[1]; peer = &ucast->oid; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "mesh: on tunnel %s [%x]\n", - GNUNET_i2s (peer), - ntohl (ucast->tid)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: on tunnel %s [%x]\n", + GNUNET_i2s (peer), ntohl (ucast->tid)); break; case GNUNET_MESSAGE_TYPE_MESH_MULTICAST: mcast = (struct GNUNET_MESH_Multicast *) message; @@ -1053,11 +1051,9 @@ send_callback (void *cls, size_t size, void *buf) GNUNET_assert (size >= th->size); mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (to)]; - psize = - th->notify (th->notify_cls, size - sizeof (to), mh); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "mesh: to origin, type %u\n", - ntohs (mh->type)); + psize = th->notify (th->notify_cls, size - sizeof (to), mh); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: to origin, type %u\n", + ntohs (mh->type)); if (psize > 0) { psize += sizeof (to); @@ -1078,10 +1074,8 @@ send_callback (void *cls, size_t size, void *buf) GNUNET_assert (size >= th->size); mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (mc)]; - psize = - th->notify (th->notify_cls, size - sizeof (mc), mh); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "mesh: multicast, type %u\n", + psize = th->notify (th->notify_cls, size - sizeof (mc), mh); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: multicast, type %u\n", ntohs (mh->type)); if (psize > 0) { @@ -1102,11 +1096,9 @@ send_callback (void *cls, size_t size, void *buf) GNUNET_assert (size >= th->size); mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (uc)]; - psize = - th->notify (th->notify_cls, size - sizeof (uc), mh); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "mesh: unicast, type %u\n", - ntohs (mh->type)); + psize = th->notify (th->notify_cls, size - sizeof (uc), mh); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: unicast, type %u\n", + ntohs (mh->type)); if (psize > 0) { psize += sizeof (uc); @@ -1482,12 +1474,10 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: mesh notify transmit ready called\n"); if (NULL != target) - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "mesh: target %s\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: target %s\n", GNUNET_i2s (target)); else - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "mesh: target multicast\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: target multicast\n"); #endif GNUNET_assert (NULL != notify); if (tunnel->mesh->npackets >= tunnel->mesh->max_queue_size && @@ -1541,11 +1531,9 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork, if (NULL != tunnel->mesh->th) return th; tunnel->mesh->th = - GNUNET_CLIENT_notify_transmit_ready (tunnel->mesh->client, - th->size, + GNUNET_CLIENT_notify_transmit_ready (tunnel->mesh->client, th->size, GNUNET_TIME_UNIT_FOREVER_REL, - GNUNET_YES, - &send_callback, + GNUNET_YES, &send_callback, tunnel->mesh); return th; } diff --git a/src/mesh/mesh_protocol.h b/src/mesh/mesh_protocol.h index e16f32093..180ba453f 100644 --- a/src/mesh/mesh_protocol.h +++ b/src/mesh/mesh_protocol.h @@ -206,7 +206,7 @@ struct GNUNET_MESH_PathBroken * ID of the endpoint */ struct GNUNET_PeerIdentity peer1; - + /** * ID of the endpoint */ diff --git a/src/mesh/mesh_tunnel_tree.c b/src/mesh/mesh_tunnel_tree.c index 332a022c1..cfe6a46a8 100644 --- a/src/mesh/mesh_tunnel_tree.c +++ b/src/mesh/mesh_tunnel_tree.c @@ -119,11 +119,11 @@ path_new (unsigned int length) { struct MeshPeerPath *p; - p = GNUNET_malloc (sizeof(struct MeshPeerPath)); + p = GNUNET_malloc (sizeof (struct MeshPeerPath)); if (length > 0) { p->length = length; - p->peers = GNUNET_malloc (length * sizeof(GNUNET_PEER_Id)); + p->peers = GNUNET_malloc (length * sizeof (GNUNET_PEER_Id)); } return p; } @@ -160,10 +160,10 @@ path_duplicate (struct MeshPeerPath *path) struct MeshPeerPath *aux; unsigned int i; - aux = path_new(path->length); - memcpy (aux->peers, path->peers, path->length * sizeof(GNUNET_PEER_Id)); + aux = path_new (path->length); + memcpy (aux->peers, path->peers, path->length * sizeof (GNUNET_PEER_Id)); for (i = 0; i < path->length; i++) - GNUNET_PEER_change_rc(path->peers[i], 1); + GNUNET_PEER_change_rc (path->peers[i], 1); return aux; } @@ -202,18 +202,17 @@ path_get_first_hop (struct MeshTunnelTree *t, GNUNET_PEER_Id peer) { struct MeshTunnelTreeNode *n; - n = tree_find_peer(t, peer); + n = tree_find_peer (t, peer); if (NULL != t->me && NULL != n) { - tree_node_update_first_hops(t, n, NULL); + tree_node_update_first_hops (t, n, NULL); r = GNUNET_CONTAINER_multihashmap_get (t->first_hops, &id.hashPubKey); GNUNET_assert (NULL != r); } else { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Tree structure inconsistent! me: %p, n: %p", - t->me, n); + "Tree structure inconsistent! me: %p, n: %p", t->me, n); GNUNET_break (0); } } @@ -287,18 +286,17 @@ path_destroy (struct MeshPeerPath *p) * @return Newly allocated node */ static struct MeshTunnelTreeNode * -tree_node_new(struct MeshTunnelTreeNode *parent, GNUNET_PEER_Id peer) +tree_node_new (struct MeshTunnelTreeNode *parent, GNUNET_PEER_Id peer) { struct MeshTunnelTreeNode *node; - node = GNUNET_malloc(sizeof(struct MeshTunnelTreeNode)); + node = GNUNET_malloc (sizeof (struct MeshTunnelTreeNode)); node->peer = peer; - GNUNET_PEER_change_rc(peer, 1); + GNUNET_PEER_change_rc (peer, 1); node->parent = parent; if (NULL != parent) - GNUNET_CONTAINER_DLL_insert(parent->children_head, - parent->children_tail, - node); + GNUNET_CONTAINER_DLL_insert (parent->children_head, parent->children_tail, + node); return node; } @@ -313,8 +311,7 @@ tree_node_new(struct MeshTunnelTreeNode *parent, GNUNET_PEER_Id peer) * @return Pointer to the node of the peer. NULL if not found. */ static struct MeshTunnelTreeNode * -tree_node_find_peer (struct MeshTunnelTreeNode *parent, - GNUNET_PEER_Id peer_id) +tree_node_find_peer (struct MeshTunnelTreeNode *parent, GNUNET_PEER_Id peer_id) { struct MeshTunnelTreeNode *n; struct MeshTunnelTreeNode *r; @@ -350,10 +347,9 @@ tree_node_update_first_hops (struct MeshTunnelTree *tree, struct MeshTunnelTreeNode *n; #if MESH_TREE_DEBUG - GNUNET_PEER_resolve(parent->peer, &id); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "tree: Finding first hop for %s.\n", - GNUNET_i2s (&id)); + GNUNET_PEER_resolve (parent->peer, &id); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Finding first hop for %s.\n", + GNUNET_i2s (&id)); #endif if (NULL == hop) { @@ -364,35 +360,31 @@ tree_node_update_first_hops (struct MeshTunnelTree *tree, while (aux != tree->me) { #if MESH_TREE_DEBUG - GNUNET_PEER_resolve(old->peer, &id); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "tree: ... its not %s.\n", - GNUNET_i2s (&id)); + GNUNET_PEER_resolve (old->peer, &id); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: ... its not %s.\n", + GNUNET_i2s (&id)); #endif old = aux; aux = aux->parent; - GNUNET_assert(NULL != aux); + GNUNET_assert (NULL != aux); } #if MESH_TREE_DEBUG - GNUNET_PEER_resolve(old->peer, &id); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "tree: It's %s!\n", - GNUNET_i2s (&id)); + GNUNET_PEER_resolve (old->peer, &id); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: It's %s!\n", + GNUNET_i2s (&id)); #endif hop = π - GNUNET_PEER_resolve(old->peer, hop); + GNUNET_PEER_resolve (old->peer, hop); } - GNUNET_PEER_resolve(parent->peer, &id); + GNUNET_PEER_resolve (parent->peer, &id); copy = GNUNET_CONTAINER_multihashmap_get (tree->first_hops, &id.hashPubKey); if (NULL == copy) - copy = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); + copy = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); *copy = *hop; - (void) GNUNET_CONTAINER_multihashmap_put( - tree->first_hops, - &id.hashPubKey, - copy, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); + (void) GNUNET_CONTAINER_multihashmap_put (tree->first_hops, &id.hashPubKey, + copy, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); for (n = parent->children_head; NULL != n; n = n->next) { @@ -402,34 +394,34 @@ tree_node_update_first_hops (struct MeshTunnelTree *tree, static void -tree_node_debug(struct MeshTunnelTreeNode *n, uint16_t level) +tree_node_debug (struct MeshTunnelTreeNode *n, uint16_t level) { struct MeshTunnelTreeNode *c; struct GNUNET_PeerIdentity id;; uint16_t i; for (i = 0; i < level; i++) - fprintf(stderr, " "); + fprintf (stderr, " "); if (n->status == MESH_PEER_READY) - fprintf(stderr, "#"); + fprintf (stderr, "#"); if (n->status == MESH_PEER_SEARCHING) - fprintf(stderr, "+"); + fprintf (stderr, "+"); if (n->status == MESH_PEER_RELAY) - fprintf(stderr, "-"); + fprintf (stderr, "-"); if (n->status == MESH_PEER_RECONNECTING) - fprintf(stderr, "*"); + fprintf (stderr, "*"); - GNUNET_PEER_resolve(n->peer, &id); - fprintf(stderr, "%s, [%u, %p] ", GNUNET_i2s (&id), n->peer, n); + GNUNET_PEER_resolve (n->peer, &id); + fprintf (stderr, "%s, [%u, %p] ", GNUNET_i2s (&id), n->peer, n); if (NULL != n->parent) { - GNUNET_PEER_resolve(n->parent->peer, &id); - fprintf(stderr, "(-> %s [%u])\n", GNUNET_i2s(&id), n->parent->peer); + GNUNET_PEER_resolve (n->parent->peer, &id); + fprintf (stderr, "(-> %s [%u])\n", GNUNET_i2s (&id), n->parent->peer); } else - fprintf(stderr, "(root)\n"); + fprintf (stderr, "(root)\n"); for (c = n->children_head; NULL != c; c = c->next) - tree_node_debug(c, level + 1); + tree_node_debug (c, level + 1); } @@ -443,30 +435,27 @@ tree_node_destroy (struct MeshTunnelTreeNode *parent) { struct MeshTunnelTreeNode *n; struct MeshTunnelTreeNode *next; + #if MESH_TREE_DEBUG struct GNUNET_PeerIdentity id; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "tree: Destroying node %u\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Destroying node %u\n", parent->peer); GNUNET_PEER_resolve (parent->peer, &id); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "tree: (%s)\n", - GNUNET_i2s (&id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: (%s)\n", GNUNET_i2s (&id)); #endif n = parent->children_head; while (NULL != n) { next = n->next; - tree_node_destroy(n); + tree_node_destroy (n); n = next; } - GNUNET_PEER_change_rc(parent->peer, -1); + GNUNET_PEER_change_rc (parent->peer, -1); if (NULL != parent->parent) - GNUNET_CONTAINER_DLL_remove(parent->parent->children_head, - parent->parent->children_tail, - parent); - GNUNET_free(parent); + GNUNET_CONTAINER_DLL_remove (parent->parent->children_head, + parent->parent->children_tail, parent); + GNUNET_free (parent); } @@ -484,9 +473,9 @@ tree_new (GNUNET_PEER_Id peer) { struct MeshTunnelTree *tree; - tree = GNUNET_malloc(sizeof (struct MeshTunnelTree)); - tree->first_hops = GNUNET_CONTAINER_multihashmap_create(32); - tree->root = tree_node_new(NULL, peer); + tree = GNUNET_malloc (sizeof (struct MeshTunnelTree)); + tree->first_hops = GNUNET_CONTAINER_multihashmap_create (32); + tree->root = tree_node_new (NULL, peer); tree->root->status = MESH_PEER_ROOT; return tree; @@ -502,7 +491,7 @@ tree_new (GNUNET_PEER_Id peer) void tree_set_me (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer) { - tree->me = tree_find_peer(tree, peer); + tree->me = tree_find_peer (tree, peer); } @@ -529,13 +518,12 @@ tree_get_me (struct MeshTunnelTree *tree) * @param peer A short peer id of local peer. */ void -tree_set_status (struct MeshTunnelTree *tree, - GNUNET_PEER_Id peer, +tree_set_status (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer, enum MeshPeerState status) { struct MeshTunnelTreeNode *n; - n = tree_find_peer(tree, peer); + n = tree_find_peer (tree, peer); if (NULL == n) return; n->status = status; @@ -554,7 +542,7 @@ tree_get_status (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer) { struct MeshTunnelTreeNode *n; - n = tree_find_peer(tree, peer); + n = tree_find_peer (tree, peer); if (NULL == n) return MESH_PEER_INVALID; return n->status; @@ -589,7 +577,7 @@ tree_get_predecessor (struct MeshTunnelTree *tree) struct MeshTunnelTreeNode * tree_find_peer (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer_id) { - return tree_node_find_peer(tree->root, peer_id); + return tree_node_find_peer (tree->root, peer_id); } @@ -603,8 +591,7 @@ tree_find_peer (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer_id) static void tree_mark_peers_disconnected (struct MeshTunnelTree *tree, struct MeshTunnelTreeNode *parent, - MeshTreeCallback cb, - void *cbcls) + MeshTreeCallback cb, void *cbcls) { struct GNUNET_PeerIdentity *pi; struct GNUNET_PeerIdentity id; @@ -622,24 +609,23 @@ tree_mark_peers_disconnected (struct MeshTunnelTree *tree, } /* Remove and free info about first hop */ - GNUNET_PEER_resolve(parent->peer, &id); - pi = GNUNET_CONTAINER_multihashmap_get(tree->first_hops, &id.hashPubKey); - GNUNET_CONTAINER_multihashmap_remove_all(tree->first_hops, &id.hashPubKey); + GNUNET_PEER_resolve (parent->peer, &id); + pi = GNUNET_CONTAINER_multihashmap_get (tree->first_hops, &id.hashPubKey); + GNUNET_CONTAINER_multihashmap_remove_all (tree->first_hops, &id.hashPubKey); if (NULL != pi) - GNUNET_free(pi); + GNUNET_free (pi); } /** * Iterate over all children of the local node. - * + * * @param tree Tree to use. Must have "me" set. * @param cb Callback to call over each child. * @param cls Closure. */ void -tree_iterate_children (struct MeshTunnelTree *tree, - MeshTreeCallback cb, +tree_iterate_children (struct MeshTunnelTree *tree, MeshTreeCallback cb, void *cls) { struct MeshTunnelTreeNode *n; @@ -665,13 +651,10 @@ tree_iterate_children (struct MeshTunnelTree *tree, * If not known, NULL to find out and pass on children. */ void -tree_update_first_hops (struct MeshTunnelTree *tree, - GNUNET_PEER_Id parent_id, +tree_update_first_hops (struct MeshTunnelTree *tree, GNUNET_PEER_Id parent_id, struct GNUNET_PeerIdentity *hop) { - tree_node_update_first_hops(tree, - tree_find_peer(tree, parent_id), - hop); + tree_node_update_first_hops (tree, tree_find_peer (tree, parent_id), hop); } @@ -689,10 +672,8 @@ tree_update_first_hops (struct MeshTunnelTree *tree, * NULL when not found */ struct MeshTunnelTreeNode * -tree_del_path (struct MeshTunnelTree *t, - GNUNET_PEER_Id peer_id, - MeshTreeCallback cb, - void *cbcls) +tree_del_path (struct MeshTunnelTree *t, GNUNET_PEER_Id peer_id, + MeshTreeCallback cb, void *cbcls) { struct MeshTunnelTreeNode *parent; struct MeshTunnelTreeNode *node; @@ -700,10 +681,10 @@ tree_del_path (struct MeshTunnelTree *t, #if MESH_TREE_DEBUG struct GNUNET_PeerIdentity id; - GNUNET_PEER_resolve(peer_id, &id); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "tree: Deleting path to %s.\n", - GNUNET_i2s (&id)); + + GNUNET_PEER_resolve (peer_id, &id); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Deleting path to %s.\n", + GNUNET_i2s (&id)); #endif if (peer_id == t->root->peer) return NULL; @@ -713,8 +694,7 @@ tree_del_path (struct MeshTunnelTree *t, if (n->peer == peer_id) { /* Was already pathless, waiting for reconnection */ - GNUNET_CONTAINER_DLL_remove (t->disconnected_head, - t->disconnected_tail, + GNUNET_CONTAINER_DLL_remove (t->disconnected_head, t->disconnected_tail, n); return n; } @@ -725,26 +705,24 @@ tree_del_path (struct MeshTunnelTree *t, node = n; parent = n->parent; - GNUNET_CONTAINER_DLL_remove(parent->children_head, parent->children_tail, n); + GNUNET_CONTAINER_DLL_remove (parent->children_head, parent->children_tail, n); n->parent = NULL; while (MESH_PEER_RELAY == parent->status && NULL == parent->children_head) { #if MESH_TREE_DEBUG - GNUNET_PEER_resolve(parent->peer, &id); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "tree: Deleting node %s.\n", - GNUNET_i2s (&id)); + GNUNET_PEER_resolve (parent->peer, &id); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Deleting node %s.\n", + GNUNET_i2s (&id)); #endif n = parent->parent; - tree_node_destroy(parent); + tree_node_destroy (parent); parent = n; } #if MESH_TREE_DEBUG - GNUNET_PEER_resolve(parent->peer, &id); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "tree: Not deleted peer %s.\n", - GNUNET_i2s (&id)); + GNUNET_PEER_resolve (parent->peer, &id); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Not deleted peer %s.\n", + GNUNET_i2s (&id)); #endif tree_mark_peers_disconnected (t, node, cb, cbcls); @@ -764,30 +742,30 @@ tree_del_path (struct MeshTunnelTree *t, * Path must be destroyed afterwards. */ struct MeshPeerPath * -tree_get_path_to_peer(struct MeshTunnelTree *t, GNUNET_PEER_Id peer) +tree_get_path_to_peer (struct MeshTunnelTree *t, GNUNET_PEER_Id peer) { struct MeshTunnelTreeNode *n; struct MeshPeerPath *p; GNUNET_PEER_Id myid = t->me->peer; - n = tree_find_peer(t, peer); + n = tree_find_peer (t, peer); if (NULL == n) return NULL; - p = path_new(0); + p = path_new (0); /* Building the path (inverted!) */ while (n->peer != myid) { - GNUNET_array_append(p->peers, p->length, n->peer); - GNUNET_PEER_change_rc(n->peer, 1); + GNUNET_array_append (p->peers, p->length, n->peer); + GNUNET_PEER_change_rc (n->peer, 1); n = n->parent; if (NULL == n) return NULL; } - GNUNET_array_append(p->peers, p->length, myid); - GNUNET_PEER_change_rc(myid, 1); + GNUNET_array_append (p->peers, p->length, myid); + GNUNET_PEER_change_rc (myid, 1); - path_invert(p); + path_invert (p); return p; } @@ -816,10 +794,8 @@ tree_get_path_to_peer(struct MeshTunnelTree *t, GNUNET_PEER_Id peer) * - do not disconnect peers until new path is created & connected */ int -tree_add_path (struct MeshTunnelTree *t, - const struct MeshPeerPath *p, - MeshTreeCallback cb, - void *cbcls) +tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p, + MeshTreeCallback cb, void *cbcls) { struct MeshTunnelTreeNode *parent; struct MeshTunnelTreeNode *oldnode; @@ -831,18 +807,17 @@ tree_add_path (struct MeshTunnelTree *t, unsigned int i; #if MESH_TREE_DEBUG - GNUNET_PEER_resolve(p->peers[p->length - 1], &id); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "tree: Adding path [%u] towards peer %s.\n", - p->length, - GNUNET_i2s (&id)); + GNUNET_PEER_resolve (p->peers[p->length - 1], &id); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "tree: Adding path [%u] towards peer %s.\n", p->length, + GNUNET_i2s (&id)); #endif if (NULL != t->me) myid = t->me->peer; else myid = 0; - GNUNET_assert(0 != p->length); + GNUNET_assert (0 != p->length); parent = n = t->root; if (n->peer != p->peers[0]) { @@ -862,10 +837,9 @@ tree_add_path (struct MeshTunnelTree *t, for (i = 1; i < p->length; i++) { #if MESH_TREE_DEBUG - GNUNET_PEER_resolve(p->peers[i], &id); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "tree: Looking for peer %s.\n", - GNUNET_i2s (&id)); + GNUNET_PEER_resolve (p->peers[i], &id); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Looking for peer %s.\n", + GNUNET_i2s (&id)); #endif parent = n; if (p->peers[i] == myid) @@ -875,10 +849,9 @@ tree_add_path (struct MeshTunnelTree *t, if (c->peer == p->peers[i]) { #if MESH_TREE_DEBUG - GNUNET_PEER_resolve(parent->peer, &id); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "tree: Found in children of %s.\n", - GNUNET_i2s (&id)); + GNUNET_PEER_resolve (parent->peer, &id); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "tree: Found in children of %s.\n", GNUNET_i2s (&id)); #endif n = c; break; @@ -890,45 +863,40 @@ tree_add_path (struct MeshTunnelTree *t, break; } #if MESH_TREE_DEBUG - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "tree: All childen visited.\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: All childen visited.\n"); #endif /* Add the rest of the path as a branch from parent. */ while (i < p->length) { #if MESH_TREE_DEBUG - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "tree: Adding peer %u to %u.\n", - p->peers[i], parent->peer); - GNUNET_PEER_resolve(p->peers[i], &id); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "tree: Adding peer %s.\n", - GNUNET_i2s (&id)); - GNUNET_PEER_resolve(parent->peer, &id); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "tree: to %s.\n", - GNUNET_i2s (&id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Adding peer %u to %u.\n", + p->peers[i], parent->peer); + GNUNET_PEER_resolve (p->peers[i], &id); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Adding peer %s.\n", + GNUNET_i2s (&id)); + GNUNET_PEER_resolve (parent->peer, &id); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: to %s.\n", + GNUNET_i2s (&id)); #endif if (i == p->length - 1 && NULL != oldnode) { #if MESH_TREE_DEBUG - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "tree: Putting old node into place.\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "tree: Putting old node into place.\n"); #endif oldnode->parent = parent; - GNUNET_CONTAINER_DLL_insert(parent->children_head, - parent->children_tail, - oldnode); + GNUNET_CONTAINER_DLL_insert (parent->children_head, parent->children_tail, + oldnode); tree_node_update_first_hops (t, oldnode, NULL); n = oldnode; } else { #if MESH_TREE_DEBUG - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: Creating new node.\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Creating new node.\n"); #endif - n = tree_node_new(parent, p->peers[i]); + n = tree_node_new (parent, p->peers[i]); n->status = MESH_PEER_RELAY; if (n->peer == myid) t->me = n; @@ -943,16 +911,14 @@ tree_add_path (struct MeshTunnelTree *t, { #if MESH_TREE_DEBUG GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "MESH: finding first hop (own pos %d/%u)\n", - me, p->length - 1); + "MESH: finding first hop (own pos %d/%u)\n", me, + p->length - 1); #endif GNUNET_PEER_resolve (p->peers[me + 1], &id); - tree_update_first_hops(t, - p->peers[p->length - 1], - &id); + tree_update_first_hops (t, p->peers[p->length - 1], &id); } #if MESH_TREE_DEBUG - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: New node added.\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: New node added.\n"); #endif return GNUNET_OK; } @@ -971,40 +937,32 @@ tree_add_path (struct MeshTunnelTree *t, * @return Short ID of the first disconnected peer in the tree. */ GNUNET_PEER_Id -tree_notify_connection_broken (struct MeshTunnelTree *t, - GNUNET_PEER_Id p1, - GNUNET_PEER_Id p2, - MeshTreeCallback cb, +tree_notify_connection_broken (struct MeshTunnelTree *t, GNUNET_PEER_Id p1, + GNUNET_PEER_Id p2, MeshTreeCallback cb, void *cbcls) { struct MeshTunnelTreeNode *n; struct MeshTunnelTreeNode *c; - n = tree_find_peer(t, p1); + n = tree_find_peer (t, p1); if (NULL == n) return 0; if (NULL != n->parent && n->parent->peer == p2) { - tree_mark_peers_disconnected(t, n, cb, cbcls); - GNUNET_CONTAINER_DLL_remove(n->parent->children_head, - n->parent->children_tail, - n); - GNUNET_CONTAINER_DLL_insert(t->disconnected_head, - t->disconnected_tail, - n); + tree_mark_peers_disconnected (t, n, cb, cbcls); + GNUNET_CONTAINER_DLL_remove (n->parent->children_head, + n->parent->children_tail, n); + GNUNET_CONTAINER_DLL_insert (t->disconnected_head, t->disconnected_tail, n); return p1; } for (c = n->children_head; NULL != c; c = c->next) { if (c->peer == p2) { - tree_mark_peers_disconnected(t, c, cb, cbcls); - GNUNET_CONTAINER_DLL_remove(n->children_head, - n->children_tail, - c); - GNUNET_CONTAINER_DLL_insert(t->disconnected_head, - t->disconnected_tail, - c); + tree_mark_peers_disconnected (t, c, cb, cbcls); + GNUNET_CONTAINER_DLL_remove (n->children_head, n->children_tail, c); + GNUNET_CONTAINER_DLL_insert (t->disconnected_head, t->disconnected_tail, + c); return p2; } } @@ -1026,21 +984,19 @@ tree_notify_connection_broken (struct MeshTunnelTree *t, * @return GNUNET_OK or GNUNET_SYSERR */ int -tree_del_peer (struct MeshTunnelTree *t, - GNUNET_PEER_Id peer, - MeshTreeCallback cb, - void *cbcls) +tree_del_peer (struct MeshTunnelTree *t, GNUNET_PEER_Id peer, + MeshTreeCallback cb, void *cbcls) { struct MeshTunnelTreeNode *n; - n = tree_del_path(t, peer, cb, cbcls); + n = tree_del_path (t, peer, cb, cbcls); if (NULL == n) { GNUNET_break (0); return GNUNET_YES; } GNUNET_break_op (NULL == n->children_head); - tree_node_destroy(n); + tree_node_destroy (n); if (NULL == t->root->children_head && t->me != t->root) { tree_node_destroy (t->root); @@ -1057,9 +1013,9 @@ tree_del_peer (struct MeshTunnelTree *t, * @param t The tree */ void -tree_debug(struct MeshTunnelTree *t) +tree_debug (struct MeshTunnelTree *t) { - tree_node_debug(t->root, 0); + tree_node_debug (t->root, 0); } @@ -1075,14 +1031,14 @@ tree_debug(struct MeshTunnelTree *t) static int iterate_free (void *cls, const GNUNET_HashCode * key, void *value) { - GNUNET_free(value); + GNUNET_free (value); return GNUNET_YES; } /** * Destroy the whole tree and free all used memory and Peer_Ids - * + * * @param t Tree to be destroyed */ void @@ -1091,8 +1047,8 @@ tree_destroy (struct MeshTunnelTree *t) #if MESH_TREE_DEBUG GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Destroying tree\n"); #endif - tree_node_destroy(t->root); - GNUNET_CONTAINER_multihashmap_iterate(t->first_hops, &iterate_free, NULL); - GNUNET_CONTAINER_multihashmap_destroy(t->first_hops); - GNUNET_free(t); + tree_node_destroy (t->root); + GNUNET_CONTAINER_multihashmap_iterate (t->first_hops, &iterate_free, NULL); + GNUNET_CONTAINER_multihashmap_destroy (t->first_hops); + GNUNET_free (t); } diff --git a/src/mesh/mesh_tunnel_tree.h b/src/mesh/mesh_tunnel_tree.h index e946259da..094a617cb 100644 --- a/src/mesh/mesh_tunnel_tree.h +++ b/src/mesh/mesh_tunnel_tree.h @@ -110,8 +110,7 @@ path_duplicate (struct MeshPeerPath *path); * NULL on error */ struct GNUNET_PeerIdentity * -path_get_first_hop (struct MeshTunnelTree *t, - GNUNET_PEER_Id peer); +path_get_first_hop (struct MeshTunnelTree *t, GNUNET_PEER_Id peer); /** @@ -136,8 +135,7 @@ path_get_length (struct MeshPeerPath *p); * in the path */ unsigned int -path_get_cost (struct MeshTunnelTree *t, - struct MeshPeerPath *path); +path_get_cost (struct MeshTunnelTree *t, struct MeshPeerPath *path); /** @@ -159,8 +157,7 @@ path_destroy (struct MeshPeerPath *p); * @param cls Closure. * @param peer_id short ID of peer that is no longer reachable. */ -typedef void (*MeshTreeCallback) (void *cls, - GNUNET_PEER_Id peer_id); +typedef void (*MeshTreeCallback) (void *cls, GNUNET_PEER_Id peer_id); /** @@ -202,8 +199,7 @@ tree_get_me (struct MeshTunnelTree *tree); * @param peer A short peer id of local peer. */ void -tree_set_status (struct MeshTunnelTree *tree, - GNUNET_PEER_Id peer, +tree_set_status (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer, enum MeshPeerState status); @@ -243,14 +239,13 @@ tree_find_peer (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer_id); /** * Iterate over all children of the local node. - * + * * @param tree Tree to use. Must have "me" set. * @param cb Callback to call over each child. * @param cls Closure. */ void -tree_iterate_children (struct MeshTunnelTree *tree, - MeshTreeCallback cb, +tree_iterate_children (struct MeshTunnelTree *tree, MeshTreeCallback cb, void *cls); @@ -263,8 +258,7 @@ tree_iterate_children (struct MeshTunnelTree *tree, * If not known, NULL to find out and pass on children. */ void -tree_update_first_hops (struct MeshTunnelTree *tree, - GNUNET_PEER_Id parent_id, +tree_update_first_hops (struct MeshTunnelTree *tree, GNUNET_PEER_Id parent_id, struct GNUNET_PeerIdentity *hop); /** @@ -282,10 +276,8 @@ tree_update_first_hops (struct MeshTunnelTree *tree, * NULL when not found */ struct MeshTunnelTreeNode * -tree_del_path (struct MeshTunnelTree *t, - GNUNET_PEER_Id peer, - MeshTreeCallback cb, - void *cbcls); +tree_del_path (struct MeshTunnelTree *t, GNUNET_PEER_Id peer, + MeshTreeCallback cb, void *cbcls); /** @@ -299,8 +291,7 @@ tree_del_path (struct MeshTunnelTree *t, * Path must be destroyed afterwards. */ struct MeshPeerPath * -tree_get_path_to_peer(struct MeshTunnelTree *t, - GNUNET_PEER_Id peer); +tree_get_path_to_peer (struct MeshTunnelTree *t, GNUNET_PEER_Id peer); /** @@ -315,10 +306,8 @@ tree_get_path_to_peer(struct MeshTunnelTree *t, * GNUNET_SYSERR in case of error. */ int -tree_add_path (struct MeshTunnelTree *t, - const struct MeshPeerPath *p, - MeshTreeCallback cb, - void *cbcls); +tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p, + MeshTreeCallback cb, void *cbcls); /** @@ -334,10 +323,8 @@ tree_add_path (struct MeshTunnelTree *t, * @return Short ID of the first disconnected peer in the tree. */ GNUNET_PEER_Id -tree_notify_connection_broken (struct MeshTunnelTree *t, - GNUNET_PEER_Id p1, - GNUNET_PEER_Id p2, - MeshTreeCallback cb, +tree_notify_connection_broken (struct MeshTunnelTree *t, GNUNET_PEER_Id p1, + GNUNET_PEER_Id p2, MeshTreeCallback cb, void *cbcls); @@ -355,10 +342,8 @@ tree_notify_connection_broken (struct MeshTunnelTree *t, * @return GNUNET_YES if the tunnel still has nodes */ int -tree_del_peer (struct MeshTunnelTree *t, - GNUNET_PEER_Id peer, - MeshTreeCallback cb, - void *cbcls); +tree_del_peer (struct MeshTunnelTree *t, GNUNET_PEER_Id peer, + MeshTreeCallback cb, void *cbcls); /** * Print the tree on stderr @@ -366,7 +351,7 @@ tree_del_peer (struct MeshTunnelTree *t, * @param t The tree */ void -tree_debug(struct MeshTunnelTree *t); +tree_debug (struct MeshTunnelTree *t); /** diff --git a/src/mesh/test_mesh_api.c b/src/mesh/test_mesh_api.c index 10e16bd42..6fcc8c7ff 100644 --- a/src/mesh/test_mesh_api.c +++ b/src/mesh/test_mesh_api.c @@ -122,7 +122,8 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_SECONDS, 5), &do_shutdown, NULL); + (GNUNET_TIME_UNIT_SECONDS, 5), &do_shutdown, + NULL); } diff --git a/src/mesh/test_mesh_local_2.c b/src/mesh/test_mesh_local_2.c index a2f5dd759..c91548052 100644 --- a/src/mesh/test_mesh_local_2.c +++ b/src/mesh/test_mesh_local_2.c @@ -268,10 +268,9 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) &peer_disconnected, (void *) &two); GNUNET_MESH_peer_request_connect_by_type (t, 1); test_task = - GNUNET_SCHEDULER_add_delayed ( - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), - &do_connect_peer_1, - cfg); + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, 5), + &do_connect_peer_1, cfg); } diff --git a/src/mesh/test_mesh_small.c b/src/mesh/test_mesh_small.c index 68fc9cc24..42390e1a6 100644 --- a/src/mesh/test_mesh_small.c +++ b/src/mesh/test_mesh_small.c @@ -171,14 +171,16 @@ shutdown_callback (void *cls, const char *emsg) if (emsg != NULL) { #if VERBOSE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: Shutdown of peers failed!\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "***************** test: Shutdown of peers failed!\n"); #endif ok--; } else { #if VERBOSE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: All peers successfully shut down!\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "***************** test: All peers successfully shut down!\n"); #endif } } @@ -188,7 +190,8 @@ static void shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { #if VERBOSE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: Ending test.\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "***************** test: Ending test.\n"); #endif if (disconnect_task != GNUNET_SCHEDULER_NO_TASK) @@ -210,14 +213,14 @@ disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: disconnecting mesh service of peers\n"); disconnect_task = GNUNET_SCHEDULER_NO_TASK; - GNUNET_MESH_disconnect(h1); - GNUNET_MESH_disconnect(h2); + GNUNET_MESH_disconnect (h1); + GNUNET_MESH_disconnect (h2); if (test == MULTICAST) - GNUNET_MESH_disconnect(h3); + GNUNET_MESH_disconnect (h3); if (GNUNET_SCHEDULER_NO_TASK != shutdown_handle) { GNUNET_SCHEDULER_cancel (shutdown_handle); - shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL); + shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); } } @@ -230,12 +233,13 @@ tmt_rdy (void *cls, size_t size, void *buf) { struct GNUNET_MessageHeader *msg = buf; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: tmt_rdy called\n"); - if (size < sizeof(struct GNUNET_MessageHeader) || NULL == buf) + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "***************** test: tmt_rdy called\n"); + if (size < sizeof (struct GNUNET_MessageHeader) || NULL == buf) return 0; - msg->size = htons (sizeof(struct GNUNET_MessageHeader)); + msg->size = htons (sizeof (struct GNUNET_MessageHeader)); msg->type = htons ((long) cls); - return sizeof(struct GNUNET_MessageHeader); + return sizeof (struct GNUNET_MessageHeader); } @@ -252,57 +256,51 @@ tmt_rdy (void *cls, size_t size, void *buf) * GNUNET_SYSERR to close it (signal serious error) */ int -data_callback (void *cls, - struct GNUNET_MESH_Tunnel * tunnel, - void **tunnel_ctx, - const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *atsi) +data_callback (void *cls, struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx, + const struct GNUNET_PeerIdentity *sender, + const struct GNUNET_MessageHeader *message, + const struct GNUNET_ATS_Information *atsi) { long client = (long) cls; switch (client) { - case 1L: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "***************** test: Origin client got a response!\n"); - ok++; - peers_responded++; - if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) - { - GNUNET_SCHEDULER_cancel (disconnect_task); - disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME, - &disconnect_mesh_peers, - NULL); - } - if (test == MULTICAST && peers_responded < 2) - return GNUNET_OK; - GNUNET_MESH_tunnel_destroy (tunnel); - break; - case 2L: - case 3L: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "***************** test: Destination client %u got a message.\n", - client); - ok++; - GNUNET_MESH_notify_transmit_ready(tunnel, - GNUNET_NO, - 0, - GNUNET_TIME_UNIT_FOREVER_REL, - sender, - sizeof(struct GNUNET_MessageHeader), - &tmt_rdy, - (void *) 1L); - if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) - { - GNUNET_SCHEDULER_cancel (disconnect_task); - disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME, - &disconnect_mesh_peers, - NULL); - } - break; - default: - break; + case 1L: + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "***************** test: Origin client got a response!\n"); + ok++; + peers_responded++; + if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) + { + GNUNET_SCHEDULER_cancel (disconnect_task); + disconnect_task = + GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers, + NULL); + } + if (test == MULTICAST && peers_responded < 2) + return GNUNET_OK; + GNUNET_MESH_tunnel_destroy (tunnel); + break; + case 2L: + case 3L: + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "***************** test: Destination client %u got a message.\n", + client); + ok++; + GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO, 0, + GNUNET_TIME_UNIT_FOREVER_REL, sender, + sizeof (struct GNUNET_MessageHeader), + &tmt_rdy, (void *) 1L); + if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) + { + GNUNET_SCHEDULER_cancel (disconnect_task); + disconnect_task = + GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers, + NULL); + } + break; + default: + break; } return GNUNET_OK; } @@ -312,7 +310,7 @@ data_callback (void *cls, * Handlers, for diverse services */ static struct GNUNET_MESH_MessageHandler handlers[] = { - {&data_callback, 1, sizeof(struct GNUNET_MessageHeader)}, + {&data_callback, 1, sizeof (struct GNUNET_MessageHeader)}, {NULL, 0, 0} }; @@ -329,15 +327,13 @@ static struct GNUNET_MESH_MessageHandler handlers[] = { * (can be NULL -- that's not an error) */ static void * -incoming_tunnel (void *cls, - struct GNUNET_MESH_Tunnel * tunnel, - const struct GNUNET_PeerIdentity * initiator, - const struct GNUNET_ATS_Information * atsi) +incoming_tunnel (void *cls, struct GNUNET_MESH_Tunnel *tunnel, + const struct GNUNET_PeerIdentity *initiator, + const struct GNUNET_ATS_Information *atsi) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: Incoming tunnel from %s to peer %d\n", - GNUNET_i2s(initiator), - (long) cls); + GNUNET_i2s (initiator), (long) cls); ok++; if ((long) cls == 1L) incoming_t = tunnel; @@ -346,9 +342,8 @@ incoming_tunnel (void *cls, if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) { GNUNET_SCHEDULER_cancel (disconnect_task); - disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME, - &disconnect_mesh_peers, - NULL); + disconnect_task = + GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers, NULL); } return NULL; } @@ -377,8 +372,7 @@ tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel, ok++; else GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "***************** test: Unknown peer! %d\n", - i); + "***************** test: Unknown peer! %d\n", i); peers_in_tunnel--; if (peers_in_tunnel > 0) return; @@ -404,7 +398,7 @@ dh (void *cls, const struct GNUNET_PeerIdentity *peer) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: peer %s disconnected\n", - GNUNET_i2s(peer)); + GNUNET_i2s (peer)); return; } @@ -423,51 +417,46 @@ ch (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_PeerIdentity *dest; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "***************** test: peer %s connected\n", - GNUNET_i2s(peer)); + "***************** test: peer %s connected\n", GNUNET_i2s (peer)); - if (0 == memcmp(&d2->id, peer, sizeof(d2->id)) && (long) cls == 1L) + if (0 == memcmp (&d2->id, peer, sizeof (d2->id)) && (long) cls == 1L) ok++; - if (test == MULTICAST && - 0 == memcmp(&d3->id, peer, sizeof(d3->id)) && + if (test == MULTICAST && 0 == memcmp (&d3->id, peer, sizeof (d3->id)) && (long) cls == 1L) ok++; switch (test) { - case UNICAST: - dest = &d2->id; - break; - case MULTICAST: - peers_in_tunnel++; - if (peers_in_tunnel < 2) - return; - dest = NULL; - break; - default: + case UNICAST: + dest = &d2->id; + break; + case MULTICAST: + peers_in_tunnel++; + if (peers_in_tunnel < 2) return; + dest = NULL; + break; + default: + return; } if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) { GNUNET_SCHEDULER_cancel (disconnect_task); - disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME, - &disconnect_mesh_peers, - NULL); + disconnect_task = + GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers, NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: Sending data...\n"); peers_responded = 0; - GNUNET_MESH_notify_transmit_ready(t, - GNUNET_NO, - 0, - GNUNET_TIME_UNIT_FOREVER_REL, - dest, - sizeof(struct GNUNET_MessageHeader), - &tmt_rdy, - (void *) 1L); + GNUNET_MESH_notify_transmit_ready (t, GNUNET_NO, 0, + GNUNET_TIME_UNIT_FOREVER_REL, dest, + sizeof (struct GNUNET_MessageHeader), + &tmt_rdy, (void *) 1L); } else { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: Disconnect already run?\n"); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: Aborting...\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "***************** test: Disconnect already run?\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "***************** test: Aborting...\n"); } return; } @@ -481,20 +470,19 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: add peer 3\n"); - GNUNET_MESH_peer_request_connect_add(t, &d3->id); + GNUNET_MESH_peer_request_connect_add (t, &d3->id); } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "***************** test: add peer 2\n"); - GNUNET_MESH_peer_request_connect_add(t, &d2->id); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: add peer 2\n"); + GNUNET_MESH_peer_request_connect_add (t, &d2->id); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: schedule timeout in 30s\n"); if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) { GNUNET_SCHEDULER_cancel (disconnect_task); - disconnect_task = GNUNET_SCHEDULER_add_delayed( - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30), - &disconnect_mesh_peers, - NULL); + disconnect_task = + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, 30), + &disconnect_mesh_peers, NULL); } } @@ -510,50 +498,46 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) * @param emsg error message (NULL on success) */ void -topo_cb (void *cls, - const struct GNUNET_PeerIdentity* first, - const struct GNUNET_PeerIdentity* second, - const char *emsg) +topo_cb (void *cls, const struct GNUNET_PeerIdentity *first, + const struct GNUNET_PeerIdentity *second, const char *emsg) { GNUNET_PEER_Id p1; GNUNET_PEER_Id p2; struct GNUNET_PeerIdentity id; - GNUNET_PEER_resolve(1, &id); - p1 = GNUNET_PEER_search(first); + GNUNET_PEER_resolve (1, &id); + p1 = GNUNET_PEER_search (first); if (p1 == pid1) { - p2 = GNUNET_PEER_search(second); + p2 = GNUNET_PEER_search (second); if (p2 == 0 || p2 > num_peers) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "***************** test: %s is UNKNOWN!? (%u)\n", - GNUNET_i2s(second), - p2); + GNUNET_i2s (second), p2); return; } mesh_peers[p2]++; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: %s IS a neighbor\n", - GNUNET_i2s(second)); + GNUNET_i2s (second)); return; } - p1 = GNUNET_PEER_search(second); + p1 = GNUNET_PEER_search (second); if (p1 == pid1) { - p2 = GNUNET_PEER_search(first); + p2 = GNUNET_PEER_search (first); if (p2 == 0 || p2 > num_peers) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "***************** test: %s is UNKNOWN!? (%u)\n", - GNUNET_i2s(first), - p2); + GNUNET_i2s (first), p2); return; } mesh_peers[p2]++; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: %s IS a neighbor\n", - GNUNET_i2s(first)); + GNUNET_i2s (first)); return; } } @@ -569,15 +553,15 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) unsigned int i; struct GNUNET_PeerIdentity id; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: connect_mesh_service\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "***************** test: connect_mesh_service\n"); for (i = 1; i <= num_peers; i++) { - GNUNET_PEER_resolve(i, &id); + GNUNET_PEER_resolve (i, &id); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "***************** test: peer %s has %u conns to d1\n", - GNUNET_i2s (&id), - mesh_peers[i]); + "***************** test: peer %s has %u conns to d1\n", + GNUNET_i2s (&id), mesh_peers[i]); if (mesh_peers[i] == 0) break; } @@ -587,11 +571,10 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { for (i++; i <= num_peers; i++) { - GNUNET_PEER_resolve(i, &id); + GNUNET_PEER_resolve (i, &id); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "***************** test: peer %s has %u conns to d1\n", - GNUNET_i2s (&id), - mesh_peers[i]); + "***************** test: peer %s has %u conns to d1\n", + GNUNET_i2s (&id), mesh_peers[i]); if (mesh_peers[i] == 0) break; } @@ -603,50 +586,32 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) #if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: connecting to mesh service of peer %s (%u)\n", - GNUNET_i2s (&d1->id), - mesh_peers[0]); + GNUNET_i2s (&d1->id), mesh_peers[0]); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: connecting to mesh service of peer %s (%u)\n", - GNUNET_i2s (&d2->id), - i); + GNUNET_i2s (&d2->id), i); if (test == MULTICAST) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: connecting to mesh service of peer %s (%u)\n", - GNUNET_i2s (&d3->id), - i); + GNUNET_i2s (&d3->id), i); } #endif - h1 = GNUNET_MESH_connect (d1->cfg, - 10, - (void *) 1L, - NULL, - &tunnel_cleaner, - handlers, - &app); - h2 = GNUNET_MESH_connect (d2->cfg, - 10, - (void *) 2L, - &incoming_tunnel, - &tunnel_cleaner, - handlers, - &app); + h1 = GNUNET_MESH_connect (d1->cfg, 10, (void *) 1L, NULL, &tunnel_cleaner, + handlers, &app); + h2 = GNUNET_MESH_connect (d2->cfg, 10, (void *) 2L, &incoming_tunnel, + &tunnel_cleaner, handlers, &app); if (test == MULTICAST) { - h3 = GNUNET_MESH_connect (d3->cfg, - 10, - (void *) 3L, - &incoming_tunnel, - &tunnel_cleaner, - handlers, - &app); + h3 = GNUNET_MESH_connect (d3->cfg, 10, (void *) 3L, &incoming_tunnel, + &tunnel_cleaner, handlers, &app); } t = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, (void *) 1L); peers_in_tunnel = 0; test_task = - GNUNET_SCHEDULER_add_delayed( - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 6), - &do_test, NULL); + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, 6), &do_test, + NULL); } @@ -697,25 +662,21 @@ peergroup_ready (void *cls, const char *emsg) GNUNET_PEER_Id peer_id; d1 = GNUNET_TESTING_daemon_get (pg, i); - peer_id = GNUNET_PEER_intern(&d1->id); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "***************** test: %u: %s\n", - peer_id, - GNUNET_i2s (&d1->id)); + peer_id = GNUNET_PEER_intern (&d1->id); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: %u: %s\n", + peer_id, GNUNET_i2s (&d1->id)); } d1 = GNUNET_TESTING_daemon_get (pg, 0); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: Peer looking: %s\n", GNUNET_i2s (&d1->id)); - pid1 = GNUNET_PEER_intern(&d1->id); + pid1 = GNUNET_PEER_intern (&d1->id); mesh_peers[pid1] = 100; - GNUNET_TESTING_get_topology(pg, &topo_cb, NULL); + GNUNET_TESTING_get_topology (pg, &topo_cb, NULL); - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply( - GNUNET_TIME_UNIT_SECONDS, - 4), - &connect_mesh_service, - NULL); + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, 4), + &connect_mesh_service, NULL); disconnect_task = GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL); @@ -753,11 +714,9 @@ connect_cb (void *cls, const struct GNUNET_PeerIdentity *first, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: Problem with new connection (%s)\n", emsg); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "***************** test: (%s)\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: (%s)\n", GNUNET_i2s (first)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "***************** test: (%s)\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: (%s)\n", GNUNET_i2s (second)); } @@ -792,7 +751,8 @@ run (void *cls, char *const *args, const char *cfgfile, NULL); #if VERBOSE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: Starting daemons.\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "***************** test: Starting daemons.\n"); GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing", "use_progressbars", "YES"); #endif @@ -806,7 +766,7 @@ run (void *cls, char *const *args, const char *cfgfile, return; } - mesh_peers = GNUNET_malloc (sizeof(uint16_t) * (num_peers + 1)); + mesh_peers = GNUNET_malloc (sizeof (uint16_t) * (num_peers + 1)); if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small", @@ -833,15 +793,15 @@ run (void *cls, char *const *args, const char *cfgfile, &data_filename)) { data_file = - GNUNET_DISK_file_open (data_filename, - GNUNET_DISK_OPEN_READWRITE | - GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE); + GNUNET_DISK_file_open (data_filename, + GNUNET_DISK_OPEN_READWRITE | + GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE); if (data_file == NULL) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n", - data_filename); + data_filename); GNUNET_free (data_filename); } } @@ -939,8 +899,8 @@ main (int argc, char *argv[]) GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, "test_mesh_small", - gettext_noop ("Test mesh in a small network."), - options, &run, NULL); + gettext_noop ("Test mesh in a small network."), options, + &run, NULL); #if REMOVE_DIR GNUNET_DISK_directory_remove ("/tmp/test_mesh_small"); #endif @@ -950,8 +910,7 @@ main (int argc, char *argv[]) "***************** test: FAILED! (%d/%d)\n", ok, ok_goal); return 1; } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "***************** test: success\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: success\n"); return 0; } diff --git a/src/mesh/test_mesh_small_unicast_far.c b/src/mesh/test_mesh_small_unicast_far.c index e35922929..cc9995b48 100644 --- a/src/mesh/test_mesh_small_unicast_far.c +++ b/src/mesh/test_mesh_small_unicast_far.c @@ -148,7 +148,8 @@ shutdown_callback (void *cls, const char *emsg) else { #if VERBOSE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: All peers successfully shut down!\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "test: All peers successfully shut down!\n"); #endif } } @@ -189,10 +190,10 @@ disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: disconnecting mesh service of peers\n"); disconnect_task = GNUNET_SCHEDULER_NO_TASK; - GNUNET_MESH_disconnect(h1); - GNUNET_MESH_disconnect(h2); + GNUNET_MESH_disconnect (h1); + GNUNET_MESH_disconnect (h2); GNUNET_SCHEDULER_cancel (shutdown_handle); - shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL); + shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); } @@ -208,16 +209,14 @@ disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) * (can be NULL -- that's not an error) */ static void * -incoming_tunnel (void *cls, - struct GNUNET_MESH_Tunnel * tunnel, - const struct GNUNET_PeerIdentity * initiator, - const struct GNUNET_ATS_Information * atsi) +incoming_tunnel (void *cls, struct GNUNET_MESH_Tunnel *tunnel, + const struct GNUNET_PeerIdentity *initiator, + const struct GNUNET_ATS_Information *atsi) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: Incoming tunnel from %s\n", - GNUNET_i2s(initiator)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Incoming tunnel from %s\n", + GNUNET_i2s (initiator)); GNUNET_SCHEDULER_cancel (disconnect_task); - disconnect_task = GNUNET_SCHEDULER_add_now(&disconnect_mesh_peers, NULL); + disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_mesh_peers, NULL); ok = 0; return NULL; } @@ -238,7 +237,7 @@ tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel, #if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: tunnel disconnected\n"); #endif - + return; } @@ -251,9 +250,8 @@ tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel, static void dh (void *cls, const struct GNUNET_PeerIdentity *peer) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: peer %s disconnected\n", - GNUNET_i2s(peer)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: peer %s disconnected\n", + GNUNET_i2s (peer)); return; } @@ -269,9 +267,8 @@ static void ch (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Information *atsi) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: peer %s connected\n", - GNUNET_i2s(peer)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: peer %s connected\n", + GNUNET_i2s (peer)); return; } @@ -280,11 +277,12 @@ static void do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n"); - GNUNET_MESH_peer_request_connect_add(t, &d2->id); + GNUNET_MESH_peer_request_connect_add (t, &d2->id); GNUNET_SCHEDULER_cancel (disconnect_task); - disconnect_task = GNUNET_SCHEDULER_add_delayed( - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30), - &disconnect_mesh_peers, NULL); + disconnect_task = + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, 30), + &disconnect_mesh_peers, NULL); } @@ -300,10 +298,9 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: connect_mesh_service\n"); - GNUNET_PEER_resolve(11, &id); + GNUNET_PEER_resolve (11, &id); d2 = GNUNET_TESTING_daemon_get_by_id (pg, &id); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: Peer searched: %s\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Peer searched: %s\n", GNUNET_i2s (&d2->id)); app = (GNUNET_MESH_ApplicationType) 0; @@ -315,20 +312,10 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) "test: connecting to mesh service of peer %s\n", GNUNET_i2s (&d2->id)); #endif - h1 = GNUNET_MESH_connect (d1->cfg, - 10, - NULL, - NULL, - &tunnel_cleaner, - handlers, - &app); - h2 = GNUNET_MESH_connect (d2->cfg, - 10, - NULL, - &incoming_tunnel, - &tunnel_cleaner, - handlers, + h1 = GNUNET_MESH_connect (d1->cfg, 10, NULL, NULL, &tunnel_cleaner, handlers, &app); + h2 = GNUNET_MESH_connect (d2->cfg, 10, NULL, &incoming_tunnel, + &tunnel_cleaner, handlers, &app); #if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: connected to mesh service of peer %s\n", @@ -339,9 +326,9 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) #endif t = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, NULL); test_task = - GNUNET_SCHEDULER_add_delayed( - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 6), - &do_test, NULL); + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, 6), &do_test, + NULL); } @@ -362,8 +349,8 @@ peergroup_ready (void *cls, const char *emsg) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Peergroup callback called with error, aborting test!\n"); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: Error from testing: `%s'\n", emsg); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Error from testing: `%s'\n", + emsg); ok++; GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); return; @@ -373,8 +360,7 @@ peergroup_ready (void *cls, const char *emsg) "************************************************************\n"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Peer Group started successfully!\n"); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: Have %u connections\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Have %u connections\n", total_connections); #endif @@ -390,18 +376,14 @@ peergroup_ready (void *cls, const char *emsg) for (i = 0; i < num_peers; i++) { d1 = GNUNET_TESTING_daemon_get (pg, i); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: %u: %s\n", - GNUNET_PEER_intern(&d1->id), - GNUNET_i2s (&d1->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: %u: %s\n", + GNUNET_PEER_intern (&d1->id), GNUNET_i2s (&d1->id)); } d1 = GNUNET_TESTING_daemon_get (pg, 0); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: Peer looking: %s\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Peer looking: %s\n", GNUNET_i2s (&d1->id)); - GNUNET_SCHEDULER_add_now (&connect_mesh_service, - NULL); + GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL); disconnect_task = GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL); @@ -437,8 +419,7 @@ connect_cb (void *cls, const struct GNUNET_PeerIdentity *first, else { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: Problem with new connection (%s)\n", - emsg); + "test: Problem with new connection (%s)\n", emsg); } } @@ -495,7 +476,7 @@ run (void *cls, char *const *args, const char *cfgfile, } } - mesh_peers = GNUNET_malloc (sizeof(GNUNET_PEER_Id) * (num_peers + 1)); + mesh_peers = GNUNET_malloc (sizeof (GNUNET_PEER_Id) * (num_peers + 1)); if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small", @@ -522,15 +503,15 @@ run (void *cls, char *const *args, const char *cfgfile, &data_filename)) { data_file = - GNUNET_DISK_file_open (data_filename, - GNUNET_DISK_OPEN_READWRITE | - GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE); + GNUNET_DISK_file_open (data_filename, + GNUNET_DISK_OPEN_READWRITE | + GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE); if (data_file == NULL) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n", - data_filename); + data_filename); GNUNET_free (data_filename); } } @@ -585,8 +566,8 @@ int main (int argc, char *argv[]) { GNUNET_PROGRAM_run (argc, argv, "test_mesh_small_unicast", - gettext_noop ("Test mesh unicast in a small network."), options, - &run, NULL); + gettext_noop ("Test mesh unicast in a small network."), + options, &run, NULL); #if REMOVE_DIR GNUNET_DISK_directory_remove ("/tmp/test_mesh_small_unicast"); #endif diff --git a/src/mesh/test_mesh_tree_api.c b/src/mesh/test_mesh_tree_api.c index 8df8fe19b..b1bdcd693 100644 --- a/src/mesh/test_mesh_tree_api.c +++ b/src/mesh/test_mesh_tree_api.c @@ -39,16 +39,16 @@ int failed; int cb_call; -struct GNUNET_PeerIdentity* pi[10]; +struct GNUNET_PeerIdentity *pi[10]; struct MeshTunnelTree *tree; static void cb (void *cls, GNUNET_PEER_Id peer_id) { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: CB: Disconnected %u\n", peer_id); - if(0 == cb_call) + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: CB: Disconnected %u\n", peer_id); + if (0 == cb_call) { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: and it shouldn't!\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: and it shouldn't!\n"); failed++; } cb_call--; @@ -64,10 +64,8 @@ cb (void *cls, GNUNET_PEER_Id peer_id) * @param first_hop Short ID of the expected first hop towards the peer. */ static void -test_assert (GNUNET_PEER_Id peer_id, - enum MeshPeerState status, - unsigned int children, - GNUNET_PEER_Id first_hop) +test_assert (GNUNET_PEER_Id peer_id, enum MeshPeerState status, + unsigned int children, GNUNET_PEER_Id first_hop) { struct MeshTunnelTreeNode *n; struct MeshTunnelTreeNode *c; @@ -75,58 +73,57 @@ test_assert (GNUNET_PEER_Id peer_id, int pre_failed; pre_failed = failed; - n = tree_find_peer(tree, peer_id); + n = tree_find_peer (tree, peer_id); if (n->peer != peer_id) { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Retrieved peer has wrong ID! (%u, %u)\n", - n->peer, peer_id); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Retrieved peer has wrong ID! (%u, %u)\n", n->peer, peer_id); failed++; } if (n->status != status) { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Retrieved peer has wrong status! (%u, %u)\n", - n->status, status); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Retrieved peer has wrong status! (%u, %u)\n", n->status, + status); failed++; } - for (c = n->children_head, i = 0; NULL != c; c = c->next, i++); + for (c = n->children_head, i = 0; NULL != c; c = c->next, i++) ; if (i != children) { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Retrieved peer wrong has number of children! (%u, %u)\n", - i, children); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Retrieved peer wrong has number of children! (%u, %u)\n", i, + children); failed++; } if (0 != first_hop && - GNUNET_PEER_search(path_get_first_hop(tree, peer_id)) != first_hop) + GNUNET_PEER_search (path_get_first_hop (tree, peer_id)) != first_hop) { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Wrong first hop! (%u, %u)\n", - GNUNET_PEER_search(path_get_first_hop(tree, peer_id)), - first_hop); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Wrong first hop! (%u, %u)\n", + GNUNET_PEER_search (path_get_first_hop (tree, peer_id)), + first_hop); failed++; } if (pre_failed != failed) { struct GNUNET_PeerIdentity id; + GNUNET_PEER_resolve (peer_id, &id); - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "*** Peer %s (%u) has failed %d checks! (real, expected)\n", - GNUNET_i2s (&id), peer_id, failed - pre_failed); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "*** Peer %s (%u) has failed %d checks! (real, expected)\n", + GNUNET_i2s (&id), peer_id, failed - pre_failed); } } static void -finish(void) +finish (void) { unsigned int i; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Finishing...\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Finishing...\n"); for (i = 0; i < 10; i++) { - GNUNET_free(pi[i]); + GNUNET_free (pi[i]); } } @@ -138,7 +135,7 @@ get_pi (uint32_t id) { struct GNUNET_PeerIdentity *pi; - pi = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); + pi = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); pi->hashPubKey.bits[0] = id + 1; return pi; } @@ -164,11 +161,10 @@ main (int argc, char *argv[]) NULL); for (i = 0; i < 10; i++) { - pi[i] = get_pi(i); - GNUNET_break (i + 1 == GNUNET_PEER_intern(pi[i])); - GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Peer %u: %s\n", - i + 1, - GNUNET_h2s(&pi[i]->hashPubKey)); + pi[i] = get_pi (i); + GNUNET_break (i + 1 == GNUNET_PEER_intern (pi[i])); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer %u: %s\n", i + 1, + GNUNET_h2s (&pi[i]->hashPubKey)); } tree = tree_new (1); tree->me = tree->root; @@ -179,37 +175,37 @@ main (int argc, char *argv[]) path->peers[3] = 4; path->length = 4; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3 4\n"); - tree_add_path(tree, path, &cb, NULL); - tree_debug(tree); - path1 = tree_get_path_to_peer(tree, 4); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3 4\n"); + tree_add_path (tree, path, &cb, NULL); + tree_debug (tree); + path1 = tree_get_path_to_peer (tree, 4); if (path->length != path1->length || - memcmp(path->peers, path1->peers, path->length) != 0) + memcmp (path->peers, path1->peers, path->length) != 0) { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved path != original\n"); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Retrieved path != original\n"); failed++; } - path_destroy(path1); + path_destroy (path1); test_assert (4, MESH_PEER_SEARCHING, 0, 2); test_assert (3, MESH_PEER_RELAY, 1, 0); test_assert (2, MESH_PEER_RELAY, 1, 0); test_assert (1, MESH_PEER_ROOT, 1, 0); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding second path: 1 2 3\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding second path: 1 2 3\n"); path->length--; - tree_add_path(tree, path, &cb, NULL); - tree_debug(tree); + tree_add_path (tree, path, &cb, NULL); + tree_debug (tree); test_assert (4, MESH_PEER_SEARCHING, 0, 2); test_assert (3, MESH_PEER_SEARCHING, 1, 2); test_assert (2, MESH_PEER_RELAY, 1, 0); test_assert (1, MESH_PEER_ROOT, 1, 0); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding third path...\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding third path...\n"); path->length++; path->peers[3] = 5; - tree_add_path(tree, path, &cb, NULL); - tree_debug(tree); + tree_add_path (tree, path, &cb, NULL); + tree_debug (tree); test_assert (5, MESH_PEER_SEARCHING, 0, 2); test_assert (4, MESH_PEER_SEARCHING, 0, 2); @@ -217,20 +213,20 @@ main (int argc, char *argv[]) test_assert (2, MESH_PEER_RELAY, 1, 0); test_assert (1, MESH_PEER_ROOT, 1, 0); - node = tree_find_peer(tree, 5); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Deleting third path...\n"); + node = tree_find_peer (tree, 5); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Deleting third path...\n"); node->status = MESH_PEER_READY; cb_call = 1; - node2 = tree_del_path(tree, 5, &cb, NULL); - tree_debug(tree); + node2 = tree_del_path (tree, 5, &cb, NULL); + tree_debug (tree); if (cb_call != 0) { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call); failed++; } if (node2->peer != 5) { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); failed++; } @@ -239,20 +235,20 @@ main (int argc, char *argv[]) test_assert (2, MESH_PEER_RELAY, 1, 0); test_assert (1, MESH_PEER_ROOT, 1, 0); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Destroying node copy...\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Destroying node copy...\n"); GNUNET_free (node2); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "test: Adding new shorter first path...\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "test: Adding new shorter first path...\n"); path->length = 2; path->peers[1] = 4; cb_call = 1; - tree_find_peer(tree, 4)->status = MESH_PEER_READY; - tree_add_path(tree, path, &cb, NULL); - tree_debug(tree); + tree_find_peer (tree, 4)->status = MESH_PEER_READY; + tree_add_path (tree, path, &cb, NULL); + tree_debug (tree); if (cb_call != 0) { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call); failed++; } @@ -265,35 +261,35 @@ main (int argc, char *argv[]) GNUNET_free (path); tree_destroy (tree); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test:\n"); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Testing relay trees\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test:\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Testing relay trees\n"); for (i = 0; i < 10; i++) { - GNUNET_break (i + 1 == GNUNET_PEER_intern(pi[i])); + GNUNET_break (i + 1 == GNUNET_PEER_intern (pi[i])); } - tree = tree_new(1); + tree = tree_new (1); path = path_new (3); path->peers[0] = 1; path->peers[1] = 2; path->peers[2] = 3; path->length = 3; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3\n"); - tree_add_path(tree, path, &cb, NULL); - tree_debug(tree); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3\n"); + tree_add_path (tree, path, &cb, NULL); + tree_debug (tree); tree_set_me (tree, 2); test_assert (3, MESH_PEER_SEARCHING, 0, 3); test_assert (2, MESH_PEER_RELAY, 1, 0); test_assert (1, MESH_PEER_ROOT, 1, 0); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding same path: 1 2 3\n"); - tree_add_path(tree, path, &cb, NULL); - + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding same path: 1 2 3\n"); + tree_add_path (tree, path, &cb, NULL); + GNUNET_free (path->peers); GNUNET_free (path); tree_destroy (tree); - finish(); + finish (); if (failed > 0) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u tests failed\n", failed); diff --git a/src/nat/nat.c b/src/nat/nat.c index 2040451d5..802b241e4 100644 --- a/src/nat/nat.c +++ b/src/nat/nat.c @@ -649,8 +649,9 @@ process_interfaces (void *cls, const char *name, int isDefault, ip = &s4->sin_addr; /* Check if address is in 127.0.0.0/8 */ - uint32_t address = ntohl((in_addr_t)(s4->sin_addr.s_addr)); + uint32_t address = ntohl ((in_addr_t) (s4->sin_addr.s_addr)); uint32_t value = (address & 0xFF000000) ^ 0x7F000000; + if ((h->return_localaddress == GNUNET_NO) && (value == 0)) { return GNUNET_OK; @@ -1139,7 +1140,8 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, int is_tcp, h->use_localaddresses = GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat", "USE_LOCALADDR"); h->return_localaddress = - GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat", "RETURN_LOCAL_ADDRESSES"); + GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat", + "RETURN_LOCAL_ADDRESSES"); h->use_hostname = GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat", "USE_HOSTNAME"); diff --git a/src/nat/test_nat_test.c b/src/nat/test_nat_test.c index 0786bb04b..c080e8ff3 100644 --- a/src/nat/test_nat_test.c +++ b/src/nat/test_nat_test.c @@ -111,7 +111,8 @@ main (int argc, char *const argv[]) nat_res = GNUNET_OS_check_helper_binary ("gnunet-nat-server"); if (GNUNET_SYSERR == nat_res) { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Cannot run NAT test: `%s' file not found\n", + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Cannot run NAT test: `%s' file not found\n", "gnunet-nat-server"); return 0; } diff --git a/src/nse/gnunet-nse-profiler.c b/src/nse/gnunet-nse-profiler.c index ecd594e86..4ad689be9 100644 --- a/src/nse/gnunet-nse-profiler.c +++ b/src/nse/gnunet-nse-profiler.c @@ -589,14 +589,14 @@ run (void *cls, char *const *args, const char *cfgfile, &data_filename)) { data_file = - GNUNET_DISK_file_open (data_filename, - GNUNET_DISK_OPEN_READWRITE | - GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE); + GNUNET_DISK_file_open (data_filename, + GNUNET_DISK_OPEN_READWRITE | + GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE); if (data_file == NULL) GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n", - data_filename); + data_filename); GNUNET_free (data_filename); } diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c index d9687acd2..a0e7923ac 100644 --- a/src/nse/gnunet-service-nse.c +++ b/src/nse/gnunet-service-nse.c @@ -339,7 +339,7 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em) std_dev = sqrt (variance); current_std_dev = std_dev; current_size_estimate = mean; - + em->header.size = htons (sizeof (struct GNUNET_NSE_ClientMessage)); em->header.type = htons (GNUNET_MESSAGE_TYPE_NSE_ESTIMATE); em->reserved = htonl (0); @@ -637,7 +637,8 @@ setup_flood_message (unsigned int slot, struct GNUNET_TIME_Absolute ts) fm->pkey = my_public_key; fm->proof_of_work = my_proof; GNUNET_assert (GNUNET_OK == - GNUNET_CRYPTO_rsa_sign (my_private_key, &fm->purpose, &fm->signature)); + GNUNET_CRYPTO_rsa_sign (my_private_key, &fm->purpose, + &fm->signature)); } @@ -826,9 +827,11 @@ find_proof (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { size_estimate_messages[i].proof_of_work = my_proof; GNUNET_assert (GNUNET_OK == - GNUNET_CRYPTO_rsa_sign (my_private_key, - &size_estimate_messages[i].purpose, - &size_estimate_messages[i].signature)); + GNUNET_CRYPTO_rsa_sign (my_private_key, + &size_estimate_messages + [i].purpose, + &size_estimate_messages + [i].signature)); } write_proof (); return; @@ -944,7 +947,7 @@ static int handle_p2p_size_estimate (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { const struct GNUNET_NSE_FloodMessage *incoming_flood; struct GNUNET_TIME_Absolute ts; @@ -1100,7 +1103,7 @@ handle_p2p_size_estimate (void *cls, const struct GNUNET_PeerIdentity *peer, static void handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { struct NSEPeerEntry *peer_entry; diff --git a/src/statistics/statistics_api.c b/src/statistics/statistics_api.c index 5d419f637..8e80a4d75 100644 --- a/src/statistics/statistics_api.c +++ b/src/statistics/statistics_api.c @@ -243,22 +243,24 @@ struct GNUNET_STATISTICS_Handle /** * Schedule the next action to be performed. */ -static void schedule_action (struct GNUNET_STATISTICS_Handle *h); +static void +schedule_action (struct GNUNET_STATISTICS_Handle *h); /** * Try to (re)connect to the statistics service. * * @return GNUNET_YES on success, GNUNET_NO on failure. */ -static int try_connect (struct GNUNET_STATISTICS_Handle *ret); +static int +try_connect (struct GNUNET_STATISTICS_Handle *ret); static void insert_ai (struct GNUNET_STATISTICS_Handle *h, - struct GNUNET_STATISTICS_GetHandle *ai) + struct GNUNET_STATISTICS_GetHandle *ai) { GNUNET_CONTAINER_DLL_insert_after (h->action_head, h->action_tail, - h->action_tail, ai); + h->action_tail, ai); if (h->action_head == ai) schedule_action (h); } @@ -266,7 +268,7 @@ insert_ai (struct GNUNET_STATISTICS_Handle *h, static void schedule_watch_request (struct GNUNET_STATISTICS_Handle *h, - struct GNUNET_STATISTICS_WatchEntry *watch) + struct GNUNET_STATISTICS_WatchEntry *watch) { struct GNUNET_STATISTICS_GetHandle *ai; @@ -276,18 +278,18 @@ schedule_watch_request (struct GNUNET_STATISTICS_Handle *h, GNUNET_assert (h != NULL); if (GNUNET_YES != try_connect (h)) - { - schedule_action (h); - return; - } + { + schedule_action (h); + return; + } slen = strlen (watch->subsystem) + 1; nlen = strlen (watch->name) + 1; nsize = sizeof (struct GNUNET_MessageHeader) + slen + nlen; if (nsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) - { - GNUNET_break (0); - return; - } + { + GNUNET_break (0); + return; + } ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle)); ai->sh = h; ai->subsystem = GNUNET_strdup (watch->subsystem); @@ -315,11 +317,11 @@ try_connect (struct GNUNET_STATISTICS_Handle *ret) return GNUNET_YES; ret->client = GNUNET_CLIENT_connect ("statistics", ret->cfg); if (ret->client != NULL) - { - for (i = 0; i < ret->watches_size; i++) - schedule_watch_request (ret, ret->watches[i]); - return GNUNET_YES; - } + { + for (i = 0; i < ret->watches_size; i++) + schedule_watch_request (ret, ret->watches[i]); + return GNUNET_YES; + } #if DEBUG_STATISTICS LOG (GNUNET_ERROR_TYPE_DEBUG, _("Failed to connect to statistics service!\n")); @@ -351,11 +353,11 @@ finish (struct GNUNET_STATISTICS_Handle *h, int code) h->current = NULL; schedule_action (h); if (pos != NULL) - { - if (pos->cont != NULL) - pos->cont (pos->cls, code); - free_action_item (pos); - } + { + if (pos->cont != NULL) + pos->cont (pos->cls, code); + free_action_item (pos); + } } @@ -366,7 +368,7 @@ finish (struct GNUNET_STATISTICS_Handle *h, int code) */ static int process_message (struct GNUNET_STATISTICS_Handle *h, - const struct GNUNET_MessageHeader *msg) + const struct GNUNET_MessageHeader *msg) { char *service; char *name; @@ -374,45 +376,43 @@ process_message (struct GNUNET_STATISTICS_Handle *h, uint16_t size; if (h->current->aborted) - { + { #if DEBUG_STATISTICS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Iteration was aborted, ignoring VALUE\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Iteration was aborted, ignoring VALUE\n"); #endif - return GNUNET_OK; /* don't bother */ - } + return GNUNET_OK; /* don't bother */ + } size = ntohs (msg->size); if (size < sizeof (struct GNUNET_STATISTICS_ReplyMessage)) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } smsg = (const struct GNUNET_STATISTICS_ReplyMessage *) msg; size -= sizeof (struct GNUNET_STATISTICS_ReplyMessage); if (size != GNUNET_STRINGS_buffer_tokenize ((const char *) &smsg[1], size, 2, - &service, &name)) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + &service, &name)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } #if DEBUG_STATISTICS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Received valid statistic on `%s:%s': %llu\n", service, name, - GNUNET_ntohll (smsg->value)); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Received valid statistic on `%s:%s': %llu\n", + service, name, GNUNET_ntohll (smsg->value)); #endif if (GNUNET_OK != h->current->proc (h->current->cls, service, name, - GNUNET_ntohll (smsg->value), - 0 != - (ntohl (smsg->uid) & GNUNET_STATISTICS_PERSIST_BIT))) - { + GNUNET_ntohll (smsg->value), + 0 != + (ntohl (smsg->uid) & GNUNET_STATISTICS_PERSIST_BIT))) + { #if DEBUG_STATISTICS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Processing of remaining statistics aborted by client.\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Processing of remaining statistics aborted by client.\n"); #endif - h->current->aborted = GNUNET_YES; - } + h->current->aborted = GNUNET_YES; + } #if DEBUG_STATISTICS LOG (GNUNET_ERROR_TYPE_DEBUG, "VALUE processed successfully\n"); #endif @@ -422,30 +422,29 @@ process_message (struct GNUNET_STATISTICS_Handle *h, static int process_watch_value (struct GNUNET_STATISTICS_Handle *h, - const struct GNUNET_MessageHeader *msg) + const struct GNUNET_MessageHeader *msg) { const struct GNUNET_STATISTICS_WatchValueMessage *wvm; struct GNUNET_STATISTICS_WatchEntry *w; uint32_t wid; - if (sizeof (struct GNUNET_STATISTICS_WatchValueMessage) != - ntohs (msg->size)) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + if (sizeof (struct GNUNET_STATISTICS_WatchValueMessage) != ntohs (msg->size)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } wvm = (const struct GNUNET_STATISTICS_WatchValueMessage *) msg; GNUNET_break (0 == ntohl (wvm->reserved)); wid = ntohl (wvm->wid); if (wid >= h->watches_size) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } w = h->watches[wid]; (void) w->proc (w->proc_cls, w->subsystem, w->name, - GNUNET_ntohll (wvm->value), - 0 != (ntohl (wvm->flags) & GNUNET_STATISTICS_PERSIST_BIT)); + GNUNET_ntohll (wvm->value), + 0 != (ntohl (wvm->flags) & GNUNET_STATISTICS_PERSIST_BIT)); return GNUNET_OK; } @@ -462,73 +461,73 @@ receive_stats (void *cls, const struct GNUNET_MessageHeader *msg) struct GNUNET_STATISTICS_Handle *h = cls; if (msg == NULL) + { + if (NULL != h->client) { - if (NULL != h->client) - { - GNUNET_CLIENT_disconnect (h->client, GNUNET_NO); - h->client = NULL; - } + GNUNET_CLIENT_disconnect (h->client, GNUNET_NO); + h->client = NULL; + } #if DEBUG_STATISTICS - LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, - "Error receiving statistics from service, is the service running?\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, + "Error receiving statistics from service, is the service running?\n"); #endif - finish (h, GNUNET_SYSERR); - return; - } + finish (h, GNUNET_SYSERR); + return; + } switch (ntohs (msg->type)) + { + case GNUNET_MESSAGE_TYPE_STATISTICS_END: +#if DEBUG_STATISTICS + LOG (GNUNET_ERROR_TYPE_DEBUG, "Received end of statistics marker\n"); +#endif + h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; + if (h->watches_size > 0) { - case GNUNET_MESSAGE_TYPE_STATISTICS_END: + GNUNET_CLIENT_receive (h->client, &receive_stats, h, + GNUNET_TIME_UNIT_FOREVER_REL); + } + else + { + h->receiving = GNUNET_NO; + } + finish (h, GNUNET_OK); + return; + case GNUNET_MESSAGE_TYPE_STATISTICS_VALUE: + if (GNUNET_OK == process_message (h, msg)) + { + /* finally, look for more! */ #if DEBUG_STATISTICS - LOG (GNUNET_ERROR_TYPE_DEBUG, "Received end of statistics marker\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Processing VALUE done, now reading more\n"); #endif + GNUNET_CLIENT_receive (h->client, &receive_stats, h, + GNUNET_TIME_absolute_get_remaining (h-> + current->timeout)); h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; - if (h->watches_size > 0) - { - GNUNET_CLIENT_receive (h->client, &receive_stats, h, - GNUNET_TIME_UNIT_FOREVER_REL); - } - else - { - h->receiving = GNUNET_NO; - } - finish (h, GNUNET_OK); return; - case GNUNET_MESSAGE_TYPE_STATISTICS_VALUE: - if (GNUNET_OK == process_message (h, msg)) - { - /* finally, look for more! */ -#if DEBUG_STATISTICS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Processing VALUE done, now reading more\n"); -#endif - GNUNET_CLIENT_receive (h->client, &receive_stats, h, - GNUNET_TIME_absolute_get_remaining - (h->current->timeout)); - h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; - return; - } - GNUNET_break (0); - break; - case GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE: - if (GNUNET_OK == process_watch_value (h, msg)) - { - h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; - GNUNET_assert (h->watches_size > 0); - GNUNET_CLIENT_receive (h->client, &receive_stats, h, - GNUNET_TIME_UNIT_FOREVER_REL); - return; - } - GNUNET_break (0); - break; - default: - GNUNET_break (0); - break; } - if (NULL != h->client) + GNUNET_break (0); + break; + case GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE: + if (GNUNET_OK == process_watch_value (h, msg)) { - GNUNET_CLIENT_disconnect (h->client, GNUNET_NO); - h->client = NULL; + h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; + GNUNET_assert (h->watches_size > 0); + GNUNET_CLIENT_receive (h->client, &receive_stats, h, + GNUNET_TIME_UNIT_FOREVER_REL); + return; } + GNUNET_break (0); + break; + default: + GNUNET_break (0); + break; + } + if (NULL != h->client) + { + GNUNET_CLIENT_disconnect (h->client, GNUNET_NO); + h->client = NULL; + } finish (h, GNUNET_SYSERR); } @@ -546,15 +545,15 @@ transmit_get (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf) uint16_t msize; if (buf == NULL) - { - /* timeout / error */ + { + /* timeout / error */ #if DEBUG_STATISTICS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Transmission of request for statistics failed!\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Transmission of request for statistics failed!\n"); #endif - finish (handle, GNUNET_SYSERR); - return 0; - } + finish (handle, GNUNET_SYSERR); + return 0; + } slen1 = strlen (handle->current->subsystem) + 1; slen2 = strlen (handle->current->name) + 1; msize = slen1 + slen2 + sizeof (struct GNUNET_MessageHeader); @@ -563,20 +562,20 @@ transmit_get (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf) hdr->size = htons (msize); hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_GET); GNUNET_assert (slen1 + slen2 == - GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], slen1 + slen2, - 2, handle->current->subsystem, - handle->current->name)); + GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], slen1 + slen2, 2, + handle->current->subsystem, + handle->current->name)); if (!handle->receiving) - { + { #if DEBUG_STATISTICS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Transmission of GET done, now reading response\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Transmission of GET done, now reading response\n"); #endif - handle->receiving = GNUNET_YES; - GNUNET_CLIENT_receive (handle->client, &receive_stats, handle, - GNUNET_TIME_absolute_get_remaining - (handle->current->timeout)); - } + handle->receiving = GNUNET_YES; + GNUNET_CLIENT_receive (handle->client, &receive_stats, handle, + GNUNET_TIME_absolute_get_remaining (handle-> + current->timeout)); + } return msize; } @@ -586,8 +585,7 @@ transmit_get (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf) * the response). */ static size_t -transmit_watch (struct GNUNET_STATISTICS_Handle *handle, size_t size, - void *buf) +transmit_watch (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf) { struct GNUNET_MessageHeader *hdr; size_t slen1; @@ -595,15 +593,15 @@ transmit_watch (struct GNUNET_STATISTICS_Handle *handle, size_t size, uint16_t msize; if (buf == NULL) - { - /* timeout / error */ + { + /* timeout / error */ #if DEBUG_STATISTICS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Transmission of request for statistics failed!\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Transmission of request for statistics failed!\n"); #endif - finish (handle, GNUNET_SYSERR); - return 0; - } + finish (handle, GNUNET_SYSERR); + return 0; + } #if DEBUG_STATISTICS LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting watch request for `%s'\n", handle->current->name); @@ -616,15 +614,15 @@ transmit_watch (struct GNUNET_STATISTICS_Handle *handle, size_t size, hdr->size = htons (msize); hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_WATCH); GNUNET_assert (slen1 + slen2 == - GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], slen1 + slen2, - 2, handle->current->subsystem, - handle->current->name)); + GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], slen1 + slen2, 2, + handle->current->subsystem, + handle->current->name)); if (GNUNET_YES != handle->receiving) - { - handle->receiving = GNUNET_YES; - GNUNET_CLIENT_receive (handle->client, &receive_stats, handle, - GNUNET_TIME_UNIT_FOREVER_REL); - } + { + handle->receiving = GNUNET_YES; + GNUNET_CLIENT_receive (handle->client, &receive_stats, handle, + GNUNET_TIME_UNIT_FOREVER_REL); + } finish (handle, GNUNET_OK); return msize; } @@ -642,20 +640,20 @@ transmit_set (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf) size_t nsize; if (NULL == buf) - { - finish (handle, GNUNET_SYSERR); - return 0; - } + { + finish (handle, GNUNET_SYSERR); + return 0; + } slen = strlen (handle->current->subsystem) + 1; nlen = strlen (handle->current->name) + 1; nsize = sizeof (struct GNUNET_STATISTICS_SetMessage) + slen + nlen; if (size < nsize) - { - GNUNET_break (0); - finish (handle, GNUNET_SYSERR); - return 0; - } + { + GNUNET_break (0); + finish (handle, GNUNET_SYSERR); + return 0; + } r = buf; r->header.size = htons (nsize); r->header.type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_SET); @@ -666,9 +664,9 @@ transmit_set (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf) if (handle->current->type == ACTION_UPDATE) r->flags |= htonl (GNUNET_STATISTICS_SETFLAG_RELATIVE); GNUNET_assert (slen + nlen == - GNUNET_STRINGS_buffer_fill ((char *) &r[1], slen + nlen, 2, - handle->current->subsystem, - handle->current->name)); + GNUNET_STRINGS_buffer_fill ((char *) &r[1], slen + nlen, 2, + handle->current->subsystem, + handle->current->name)); finish (handle, GNUNET_OK); return nsize; } @@ -682,22 +680,22 @@ transmit_action (void *cls, size_t size, void *buf) handle->th = NULL; switch (handle->current->type) - { - case ACTION_GET: - ret = transmit_get (handle, size, buf); - break; - case ACTION_SET: - case ACTION_UPDATE: - ret = transmit_set (handle, size, buf); - break; - case ACTION_WATCH: - ret = transmit_watch (handle, size, buf); - break; - default: - ret = 0; - GNUNET_break (0); - break; - } + { + case ACTION_GET: + ret = transmit_get (handle, size, buf); + break; + case ACTION_SET: + case ACTION_UPDATE: + ret = transmit_set (handle, size, buf); + break; + case ACTION_WATCH: + ret = transmit_watch (handle, size, buf); + break; + default: + ret = 0; + GNUNET_break (0); + break; + } return ret; } @@ -711,7 +709,7 @@ transmit_action (void *cls, size_t size, void *buf) */ struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create (const char *subsystem, - const struct GNUNET_CONFIGURATION_Handle *cfg) + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_STATISTICS_Handle *ret; @@ -722,11 +720,11 @@ GNUNET_STATISTICS_create (const char *subsystem, ret->subsystem = GNUNET_strdup (subsystem); ret->backoff = GNUNET_TIME_UNIT_MILLISECONDS; if (GNUNET_YES != try_connect (ret)) - { - GNUNET_free (ret->subsystem); - GNUNET_free (ret); - return NULL; - } + { + GNUNET_free (ret->subsystem); + GNUNET_free (ret); + return NULL; + } return ret; } @@ -753,83 +751,83 @@ GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, int sync_first) if (GNUNET_SCHEDULER_NO_TASK != h->backoff_task) GNUNET_SCHEDULER_cancel (h->backoff_task); if (sync_first) + { + if (h->current != NULL) { - if (h->current != NULL) - { - if (h->current->type == ACTION_GET) - { - GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); - h->th = NULL; - free_action_item (h->current); - h->current = NULL; - } - } - pos = h->action_head; - prev = NULL; - while (pos != NULL) - { - next = pos->next; - if (pos->type == ACTION_GET) - { - if (prev == NULL) - h->action_head = next; - else - prev->next = next; - free_action_item (pos); - } - else - { - prev = pos; - } - pos = next; - } - h->action_tail = prev; - if (h->current == NULL) - { - h->current = h->action_head; - if (h->action_head != NULL) - { - h->action_head = h->action_head->next; - if (h->action_head == NULL) - h->action_tail = NULL; - } - } - h->do_destroy = GNUNET_YES; - if ((h->current != NULL) && (h->th == NULL)) - { - timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout); - h->th = - GNUNET_CLIENT_notify_transmit_ready (h->client, h->current->msize, - timeout, GNUNET_YES, - &transmit_action, h); - GNUNET_assert (NULL != h->th); - } - if (h->th != NULL) - return; + if (h->current->type == ACTION_GET) + { + GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); + h->th = NULL; + free_action_item (h->current); + h->current = NULL; + } } - if (NULL != h->th) + pos = h->action_head; + prev = NULL; + while (pos != NULL) { - GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); - h->th = NULL; + next = pos->next; + if (pos->type == ACTION_GET) + { + if (prev == NULL) + h->action_head = next; + else + prev->next = next; + free_action_item (pos); + } + else + { + prev = pos; + } + pos = next; } - if (h->current != NULL) - free_action_item (h->current); - while (NULL != (pos = h->action_head)) + h->action_tail = prev; + if (h->current == NULL) { - h->action_head = pos->next; - free_action_item (pos); + h->current = h->action_head; + if (h->action_head != NULL) + { + h->action_head = h->action_head->next; + if (h->action_head == NULL) + h->action_tail = NULL; + } } - if (h->client != NULL) + h->do_destroy = GNUNET_YES; + if ((h->current != NULL) && (h->th == NULL)) { - GNUNET_CLIENT_disconnect (h->client, GNUNET_YES); - h->client = NULL; + timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout); + h->th = + GNUNET_CLIENT_notify_transmit_ready (h->client, h->current->msize, + timeout, GNUNET_YES, + &transmit_action, h); + GNUNET_assert (NULL != h->th); } + if (h->th != NULL) + return; + } + if (NULL != h->th) + { + GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); + h->th = NULL; + } + if (h->current != NULL) + free_action_item (h->current); + while (NULL != (pos = h->action_head)) + { + h->action_head = pos->next; + free_action_item (pos); + } + if (h->client != NULL) + { + GNUNET_CLIENT_disconnect (h->client, GNUNET_YES); + h->client = NULL; + } for (i = 0; i < h->watches_size; i++) - { - GNUNET_free (h->watches[i]->subsystem); - GNUNET_free (h->watches[i]->name); - GNUNET_free (h->watches[i]); - } + { + GNUNET_free (h->watches[i]->subsystem); + GNUNET_free (h->watches[i]->name); + GNUNET_free (h->watches[i]); + } GNUNET_array_grow (h->watches, h->watches_size, 0); GNUNET_free (h->subsystem); GNUNET_free (h); @@ -855,43 +853,42 @@ schedule_action (struct GNUNET_STATISTICS_Handle *h) struct GNUNET_TIME_Relative timeout; if (h->current != NULL) - return; /* action already pending */ + return; /* action already pending */ if (GNUNET_YES != try_connect (h)) - { - h->backoff_task = - GNUNET_SCHEDULER_add_delayed (h->backoff, &finish_task, h); - h->backoff = GNUNET_TIME_relative_multiply (h->backoff, 2); - h->backoff = - GNUNET_TIME_relative_min (h->backoff, - GNUNET_CONSTANTS_SERVICE_TIMEOUT); - return; - } + { + h->backoff_task = + GNUNET_SCHEDULER_add_delayed (h->backoff, &finish_task, h); + h->backoff = GNUNET_TIME_relative_multiply (h->backoff, 2); + h->backoff = + GNUNET_TIME_relative_min (h->backoff, GNUNET_CONSTANTS_SERVICE_TIMEOUT); + return; + } /* schedule next action */ h->current = h->action_head; if (NULL == h->current) + { + if (h->do_destroy) { - if (h->do_destroy) - { - h->do_destroy = GNUNET_NO; - GNUNET_STATISTICS_destroy (h, GNUNET_YES); - } - return; + h->do_destroy = GNUNET_NO; + GNUNET_STATISTICS_destroy (h, GNUNET_YES); } + return; + } GNUNET_CONTAINER_DLL_remove (h->action_head, h->action_tail, h->current); timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout); if (NULL == (h->th = GNUNET_CLIENT_notify_transmit_ready (h->client, h->current->msize, - timeout, GNUNET_YES, - &transmit_action, h))) - { + timeout, GNUNET_YES, + &transmit_action, h))) + { #if DEBUG_STATISTICS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Failed to transmit request to statistics service.\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Failed to transmit request to statistics service.\n"); #endif - finish (h, GNUNET_SYSERR); - } + finish (h, GNUNET_SYSERR); + } } @@ -910,10 +907,10 @@ schedule_action (struct GNUNET_STATISTICS_Handle *h) */ struct GNUNET_STATISTICS_GetHandle * GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, - const char *subsystem, const char *name, - struct GNUNET_TIME_Relative timeout, - GNUNET_STATISTICS_Callback cont, - GNUNET_STATISTICS_Iterator proc, void *cls) + const char *subsystem, const char *name, + struct GNUNET_TIME_Relative timeout, + GNUNET_STATISTICS_Callback cont, + GNUNET_STATISTICS_Iterator proc, void *cls) { size_t slen1; size_t slen2; @@ -923,14 +920,14 @@ GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, GNUNET_assert (proc != NULL); GNUNET_assert (GNUNET_NO == handle->do_destroy); if (GNUNET_YES != try_connect (handle)) - { + { #if DEBUG_STATISTICS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Failed to connect to statistics service, can not get value `%s:%s'.\n", - strlen (subsystem) ? subsystem : "*", strlen (name) ? name : "*"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Failed to connect to statistics service, can not get value `%s:%s'.\n", + strlen (subsystem) ? subsystem : "*", strlen (name) ? name : "*"); #endif - return NULL; - } + return NULL; + } if (subsystem == NULL) subsystem = ""; if (name == NULL) @@ -938,7 +935,7 @@ GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, slen1 = strlen (subsystem) + 1; slen2 = strlen (name) + 1; GNUNET_assert (slen1 + slen2 + sizeof (struct GNUNET_MessageHeader) < - GNUNET_SERVER_MAX_MESSAGE_SIZE); + GNUNET_SERVER_MAX_MESSAGE_SIZE); ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle)); ai->sh = handle; ai->subsystem = GNUNET_strdup (subsystem); @@ -964,17 +961,16 @@ void GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh) { if (gh->sh->current == gh) - { - gh->aborted = GNUNET_YES; - } + { + gh->aborted = GNUNET_YES; + } else - { - GNUNET_CONTAINER_DLL_remove (gh->sh->action_head, gh->sh->action_tail, - gh); - GNUNET_free (gh->name); - GNUNET_free (gh->subsystem); - GNUNET_free (gh); - } + { + GNUNET_CONTAINER_DLL_remove (gh->sh->action_head, gh->sh->action_tail, gh); + GNUNET_free (gh->name); + GNUNET_free (gh->subsystem); + GNUNET_free (gh); + } } @@ -992,8 +988,8 @@ GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh) */ int GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle, - const char *subsystem, const char *name, - GNUNET_STATISTICS_Iterator proc, void *proc_cls) + const char *subsystem, const char *name, + GNUNET_STATISTICS_Iterator proc, void *proc_cls) { struct GNUNET_STATISTICS_WatchEntry *w; @@ -1012,7 +1008,7 @@ GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle, static void add_setter_action (struct GNUNET_STATISTICS_Handle *h, const char *name, - int make_persistent, uint64_t value, enum ActionType type) + int make_persistent, uint64_t value, enum ActionType type) { struct GNUNET_STATISTICS_GetHandle *ai; size_t slen; @@ -1028,59 +1024,58 @@ add_setter_action (struct GNUNET_STATISTICS_Handle *h, const char *name, nlen = strlen (name) + 1; nsize = sizeof (struct GNUNET_STATISTICS_SetMessage) + slen + nlen; if (nsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) - { - GNUNET_break (0); - return; - } + { + GNUNET_break (0); + return; + } ai = h->action_head; while (ai != NULL) + { + if ((0 == strcmp (ai->subsystem, h->subsystem)) && + (0 == strcmp (ai->name, name)) && ((ai->type == ACTION_UPDATE) || + (ai->type == ACTION_SET))) { - if ((0 == strcmp (ai->subsystem, h->subsystem)) && - (0 == strcmp (ai->name, name)) && ((ai->type == ACTION_UPDATE) || - (ai->type == ACTION_SET))) - { - if (ai->type == ACTION_SET) - { - if (type == ACTION_UPDATE) - { - delta = (int64_t) value; - if (delta > 0) - { - ai->value += delta; - } - else - { - if (ai->value < -delta) - ai->value = 0; - else - ai->value += delta; - } - } - else - { - ai->value = value; - } - } - else - { - if (type == ACTION_UPDATE) - { - delta = (int64_t) value; - ai->value += delta; - } - else - { - ai->value = value; - ai->type = type; - } - } - ai->timeout = - GNUNET_TIME_relative_to_absolute (SET_TRANSMIT_TIMEOUT); - ai->make_persistent = make_persistent; - return; - } - ai = ai->next; + if (ai->type == ACTION_SET) + { + if (type == ACTION_UPDATE) + { + delta = (int64_t) value; + if (delta > 0) + { + ai->value += delta; + } + else + { + if (ai->value < -delta) + ai->value = 0; + else + ai->value += delta; + } + } + else + { + ai->value = value; + } + } + else + { + if (type == ACTION_UPDATE) + { + delta = (int64_t) value; + ai->value += delta; + } + else + { + ai->value = value; + ai->type = type; + } + } + ai->timeout = GNUNET_TIME_relative_to_absolute (SET_TRANSMIT_TIMEOUT); + ai->make_persistent = make_persistent; + return; } + ai = ai->next; + } ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle)); ai->sh = h; ai->subsystem = GNUNET_strdup (h->subsystem); @@ -1105,7 +1100,7 @@ add_setter_action (struct GNUNET_STATISTICS_Handle *h, const char *name, */ void GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle, - const char *name, uint64_t value, int make_persistent) + const char *name, uint64_t value, int make_persistent) { if (handle == NULL) return; @@ -1125,8 +1120,7 @@ GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle, */ void GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle, - const char *name, int64_t delta, - int make_persistent) + const char *name, int64_t delta, int make_persistent) { if (handle == NULL) return; @@ -1134,7 +1128,7 @@ GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle, return; GNUNET_assert (GNUNET_NO == handle->do_destroy); add_setter_action (handle, name, make_persistent, (uint64_t) delta, - ACTION_UPDATE); + ACTION_UPDATE); } diff --git a/src/testing/test_testing_connect.c b/src/testing/test_testing_connect.c index f32e2e40f..87501469d 100644 --- a/src/testing/test_testing_connect.c +++ b/src/testing/test_testing_connect.c @@ -148,10 +148,12 @@ run (void *cls, char *const *args, const char *cfgfile, #endif c1 = GNUNET_CONFIGURATION_create (); GNUNET_assert (GNUNET_OK == - GNUNET_CONFIGURATION_load (c1, "test_testing_connect_peer1.conf")); + GNUNET_CONFIGURATION_load (c1, + "test_testing_connect_peer1.conf")); c2 = GNUNET_CONFIGURATION_create (); GNUNET_assert (GNUNET_OK == - GNUNET_CONFIGURATION_load (c2, "test_testing_connect_peer2.conf")); + GNUNET_CONFIGURATION_load (c2, + "test_testing_connect_peer2.conf")); d1 = GNUNET_TESTING_daemon_start (c1, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL, NULL, NULL, &my_cb1, NULL); GNUNET_assert (d1 != NULL); diff --git a/src/testing/test_testing_reconnect.c b/src/testing/test_testing_reconnect.c index f317040fb..20c628c6a 100644 --- a/src/testing/test_testing_reconnect.c +++ b/src/testing/test_testing_reconnect.c @@ -101,8 +101,8 @@ end1_cb (void *cls, const char *emsg) if (d2 != NULL) { GNUNET_TESTING_daemon_stop (d2, TIMEOUT, &end2_cb, NULL, - (phase == NUM_PHASES) ? GNUNET_YES : GNUNET_NO, - GNUNET_NO); + (phase == NUM_PHASES) ? GNUNET_YES : GNUNET_NO, + GNUNET_NO); d2 = NULL; } } @@ -192,9 +192,13 @@ run (void *cls, char *const *args, const char *cfgfile, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemon.\n"); #endif c1 = GNUNET_CONFIGURATION_create (); - GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (c1, "test_testing_connect_peer1.conf")); + GNUNET_assert (GNUNET_OK == + GNUNET_CONFIGURATION_load (c1, + "test_testing_connect_peer1.conf")); c2 = GNUNET_CONFIGURATION_create (); - GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (c2, "test_testing_connect_peer2.conf")); + GNUNET_assert (GNUNET_OK == + GNUNET_CONFIGURATION_load (c2, + "test_testing_connect_peer2.conf")); run_phase (); } diff --git a/src/testing/test_testing_topology.c b/src/testing/test_testing_topology.c index e563f4d64..deaeae457 100644 --- a/src/testing/test_testing_topology.c +++ b/src/testing/test_testing_topology.c @@ -349,7 +349,7 @@ static int process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { char *dotOutFileNameFinished; FILE *dotOutFileFinished; @@ -543,7 +543,7 @@ init_notify_peer2 (void *cls, struct GNUNET_CORE_Handle *server, static void connect_notify_peers (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { struct TestMessageContext *pos = cls; @@ -604,8 +604,7 @@ init_notify_peer1 (void *cls, struct GNUNET_CORE_Handle *server, */ pos->peer2handle = GNUNET_CORE_connect (pos->peer2->cfg, 1, pos, &init_notify_peer2, NULL, - NULL, NULL, GNUNET_YES, NULL, GNUNET_YES, - handlers); + NULL, NULL, GNUNET_YES, NULL, GNUNET_YES, handlers); } @@ -643,8 +642,8 @@ send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) */ pos->peer1handle = GNUNET_CORE_connect (pos->peer1->cfg, 1, pos, &init_notify_peer1, - &connect_notify_peers, NULL, NULL, GNUNET_NO, - NULL, GNUNET_NO, no_handlers); + &connect_notify_peers, NULL, NULL, GNUNET_NO, NULL, + GNUNET_NO, no_handlers); GNUNET_assert (pos->peer1handle != NULL); diff --git a/src/testing/testing.c b/src/testing/testing.c index e81a92fb5..6edc1fc8c 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c @@ -1888,7 +1888,7 @@ notify_connect_result (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static void connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { struct GNUNET_TESTING_ConnectContext *ctx = cls; @@ -1965,8 +1965,7 @@ core_init_notify (void *cls, struct GNUNET_CORE_Handle *server, if (connect_ctx->send_hello == GNUNET_NO) { - GNUNET_TRANSPORT_try_connect (connect_ctx->d1th, - &connect_ctx->d2->id); + GNUNET_TRANSPORT_try_connect (connect_ctx->d1th, &connect_ctx->d2->id); #if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending connect request to TRANSPORT of %s for peer %s\n", @@ -2088,7 +2087,7 @@ reattempt_daemons_connect (void *cls, static void core_initial_iteration (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { struct GNUNET_TESTING_ConnectContext *ctx = cls; diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c index 04c2cfd00..171cf1c48 100644 --- a/src/testing/testing_group.c +++ b/src/testing/testing_group.c @@ -2669,8 +2669,8 @@ create_from_file (struct GNUNET_TESTING_PeerGroup *pg, char *filename, return connect_attempts; } #if DEBUG_TESTING - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Found %u total peers in topology\n", total_peers); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u total peers in topology\n", + total_peers); #endif GNUNET_assert (total_peers == pg->total); curr_state = PEER_INDEX; @@ -3348,7 +3348,9 @@ send_core_connect_requests (void *cls, while (conn != NULL) { GNUNET_TRANSPORT_try_connect (send_hello_context->peer->daemon->th, - &send_hello_context->pg->peers[conn->index].daemon->id); + &send_hello_context->pg->peers[conn-> + index].daemon-> + id); conn = conn->next; } send_hello_context->core_connect_task = @@ -3486,7 +3488,7 @@ core_connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, */ void core_init (void *cls, struct GNUNET_CORE_Handle *server, - struct GNUNET_PeerIdentity *my_identity) + struct GNUNET_PeerIdentity *my_identity) { struct SendHelloContext *send_hello_context = cls; @@ -4878,7 +4880,7 @@ perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) static void internal_topology_callback (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { struct CoreContext *core_ctx = cls; struct TopologyIterateContext *iter_ctx = core_ctx->iter_context; @@ -5835,9 +5837,8 @@ start_peer_helper (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) "peerStartHelper.pl", tempdir, NULL); GNUNET_assert (helper->proc != NULL); #if DEBUG_TESTING - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "starting peers with cmd ssh %s %s %s\n", arg, - "peerStartHelper.pl", tempdir); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "starting peers with cmd ssh %s %s %s\n", + arg, "peerStartHelper.pl", tempdir); #endif GNUNET_SCHEDULER_add_now (&check_peers_started, helper); GNUNET_free (tempdir); @@ -6109,8 +6110,7 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, fs = 0; #if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Found file size %llu for hostkeys\n", - fs); + "Found file size %llu for hostkeys\n", fs); #endif if (0 != (fs % HOSTKEYFILESIZE)) { @@ -6784,9 +6784,8 @@ GNUNET_TESTING_daemons_start_service (struct GNUNET_TESTING_PeerGroup *pg, for (i = 0; i < pg->total; i++) { #if DEBUG_START - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Starting up service %s on peer %d!\n", service, - stopped_arr[stopped_permute[i]]); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting up service %s on peer %d!\n", + service, stopped_arr[stopped_permute[i]]); #endif peer_start_ctx = GNUNET_malloc (sizeof (struct PeerServiceStartContext)); peer_start_ctx->start_ctx = start_ctx; diff --git a/src/testing/testing_peergroup.c b/src/testing/testing_peergroup.c index 470fdf8fa..a46e1bfb2 100644 --- a/src/testing/testing_peergroup.c +++ b/src/testing/testing_peergroup.c @@ -591,8 +591,8 @@ internal_hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id, GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task); GNUNET_free_non_null (pg_start_ctx->fail_reason); - pg_start_ctx->fail_reason = - GNUNET_strdup ("from continue startup (timeout)"); + pg_start_ctx->fail_reason = + GNUNET_strdup ("from continue startup (timeout)"); pg_start_ctx->die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (pg_start_ctx->timeout), &end_badly, @@ -928,7 +928,8 @@ GNUNET_TESTING_peergroup_start (const struct GNUNET_CONFIGURATION_Handle *cfg, /* Make compilers happy */ reset_meter (pg_start_ctx->peer_start_meter); pg_start_ctx->fail_reason = - GNUNET_strdup ("didn't generate all hostkeys within allowed startup time!"); + GNUNET_strdup + ("didn't generate all hostkeys within allowed startup time!"); pg_start_ctx->die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (pg_start_ctx->timeout), &end_badly, diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c index 625923cdf..3e4fd2685 100644 --- a/src/topology/gnunet-daemon-topology.c +++ b/src/topology/gnunet-daemon-topology.c @@ -376,8 +376,9 @@ attempt_connect (struct Peer *pos) GNUNET_i2s (&pos->pid)); #endif GNUNET_STATISTICS_update (stats, - gettext_noop ("# connect requests issued to transport"), - 1, GNUNET_NO); + gettext_noop + ("# connect requests issued to transport"), 1, + GNUNET_NO); GNUNET_TRANSPORT_try_connect (transport, &pos->pid); } @@ -637,7 +638,7 @@ reschedule_hellos (void *cls, const GNUNET_HashCode * pid, void *value) static void connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { struct Peer *pos; @@ -1110,7 +1111,7 @@ static int handle_encrypted_hello (void *cls, const struct GNUNET_PeerIdentity *other, const struct GNUNET_MessageHeader *message, const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) + unsigned int atsi_count) { struct Peer *peer; struct GNUNET_PeerIdentity pid; @@ -1282,8 +1283,8 @@ run (void *cls, char *const *args, const char *cfgfile, transport = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL, NULL, NULL); handle = GNUNET_CORE_connect (cfg, 1, NULL, &core_init, &connect_notify, - &disconnect_notify, NULL, GNUNET_NO, NULL, - GNUNET_NO, handlers); + &disconnect_notify, NULL, GNUNET_NO, NULL, GNUNET_NO, + handlers); GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task, NULL); if (NULL == transport) diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 10c1c68a8..878ab2618 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -90,9 +90,7 @@ struct GNUNET_ATS_SchedulingHandle *GST_ats; static void transmit_our_hello (void *cls, const struct GNUNET_PeerIdentity *target, const struct GNUNET_ATS_Information *ats, - uint32_t ats_count, - const char * transport, - const void * addr, + uint32_t ats_count, const char *transport, const void *addr, size_t addrlen) { const struct GNUNET_MessageHeader *hello = cls; @@ -118,7 +116,7 @@ process_hello_update (void *cls, const struct GNUNET_MessageHeader *hello) /** - * We received some payload. Prepare to pass it on to our clients. + * We received some payload. Prepare to pass it on to our clients. * * @param peer (claimed) identity of the other peer * @param message the message, never NULL @@ -128,48 +126,45 @@ process_hello_update (void *cls, const struct GNUNET_MessageHeader *hello) */ static struct GNUNET_TIME_Relative process_payload (const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_MessageHeader *message, + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { struct GNUNET_TIME_Relative ret; int do_forward; struct InboundMessage *im; size_t msg_size = ntohs (message->size); - size_t size = sizeof (struct InboundMessage) + msg_size + sizeof (struct GNUNET_ATS_Information) * ats_count; + size_t size = + sizeof (struct InboundMessage) + msg_size + + sizeof (struct GNUNET_ATS_Information) * ats_count; char buf[size]; struct GNUNET_ATS_Information *ap; - + ret = GNUNET_TIME_UNIT_ZERO; do_forward = GNUNET_SYSERR; - ret = - GST_neighbours_calculate_receive_delay (peer, - msg_size, - &do_forward); + ret = GST_neighbours_calculate_receive_delay (peer, msg_size, &do_forward); if (!GST_neighbours_test_connected (peer)) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Discarded %u bytes type %u payload from peer `%s'\n", - msg_size, - ntohs (message->type), - GNUNET_i2s (peer)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Discarded %u bytes type %u payload from peer `%s'\n", msg_size, + ntohs (message->type), GNUNET_i2s (peer)); GNUNET_STATISTICS_update (GST_stats, - gettext_noop ("# bytes payload discarded due to not connected peer "), - msg_size, - GNUNET_NO); + gettext_noop + ("# bytes payload discarded due to not connected peer "), + msg_size, GNUNET_NO); return ret; } if (do_forward != GNUNET_YES) return ret; - im = (struct InboundMessage*) buf; + im = (struct InboundMessage *) buf; im->header.size = htons (size); im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); im->ats_count = htonl (ats_count); im->peer = *peer; - ap = (struct GNUNET_ATS_Information*) &im[1]; + ap = (struct GNUNET_ATS_Information *) &im[1]; memcpy (ap, ats, ats_count * sizeof (struct GNUNET_ATS_Information)); memcpy (&ap[ats_count], message, ntohs (message->size)); @@ -213,7 +208,7 @@ plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer, const char *plugin_name = cls; struct GNUNET_TIME_Relative ret; uint16_t type; - + ret = GNUNET_TIME_UNIT_ZERO; if (NULL == message) goto end; @@ -231,43 +226,38 @@ plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer, case GNUNET_MESSAGE_TYPE_TRANSPORT_PING: #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, - "Processing `%s' from `%s'\n", "PING", - (sender_address != NULL) ? GST_plugins_a2s (plugin_name, - sender_address, - sender_address_len) - : ""); + "Processing `%s' from `%s'\n", "PING", + (sender_address != NULL) ? GST_plugins_a2s (plugin_name, + sender_address, + sender_address_len) + : ""); #endif GST_validation_handle_ping (peer, message, plugin_name, session, - sender_address, sender_address_len); + sender_address, sender_address_len); break; case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG: #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, - "Processing `%s' from `%s'\n", "PONG", - (sender_address != NULL) ? GST_plugins_a2s (plugin_name, - sender_address, - sender_address_len) - : ""); + "Processing `%s' from `%s'\n", "PONG", + (sender_address != NULL) ? GST_plugins_a2s (plugin_name, + sender_address, + sender_address_len) + : ""); #endif GST_validation_handle_pong (peer, message); break; case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT: - GST_neighbours_handle_connect (message, - peer, - plugin_name, sender_address, sender_address_len, - session, ats, ats_count); + GST_neighbours_handle_connect (message, peer, plugin_name, sender_address, + sender_address_len, session, ats, ats_count); break; case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK: - GST_neighbours_handle_connect_ack (message, - peer, - plugin_name, sender_address, sender_address_len, - session, ats, ats_count); + GST_neighbours_handle_connect_ack (message, peer, plugin_name, + sender_address, sender_address_len, + session, ats, ats_count); break; case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK: - GST_neighbours_handle_ack (message, - peer, - plugin_name, sender_address, sender_address_len, - session, ats, ats_count); + GST_neighbours_handle_ack (message, peer, plugin_name, sender_address, + sender_address_len, session, ats, ats_count); break; case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: GST_neighbours_handle_disconnect_message (peer, message); @@ -277,25 +267,20 @@ plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer, break; default: /* should be payload */ - ret = process_payload (peer, - message, - ats, ats_count); + ret = process_payload (peer, message, ats, ats_count); break; } - end: +end: #if 1 /* FIXME: this should not be needed, and not sure it's good to have it, but without - this connections seem to go extra-slow */ - GNUNET_ATS_address_update (GST_ats, peer, - plugin_name, sender_address, sender_address_len, - session, - ats, ats_count); + * this connections seem to go extra-slow */ + GNUNET_ATS_address_update (GST_ats, peer, plugin_name, sender_address, + sender_address_len, session, ats, ats_count); #endif #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Allowing receive from peer %s to continue in %llu ms\n", - GNUNET_i2s (peer), - (unsigned long long) ret.rel_value); + "Allowing receive from peer %s to continue in %llu ms\n", + GNUNET_i2s (peer), (unsigned long long) ret.rel_value); #endif return ret; } @@ -340,16 +325,14 @@ plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, struct Session *session) { #if DEBUG_TRANSPORT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Session %X to peer `%s' ended \n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Session %X to peer `%s' ended \n", session, GNUNET_i2s (peer)); #endif if (NULL != session) - GNUNET_log_from (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, - "transport-ats", - "Telling ATS to destroy session %p from peer %s\n", - session, - GNUNET_i2s (peer)); + GNUNET_log_from (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, + "transport-ats", + "Telling ATS to destroy session %p from peer %s\n", + session, GNUNET_i2s (peer)); GNUNET_ATS_address_destroyed (GST_ats, peer, NULL, NULL, 0, session); GST_neighbours_session_terminated (peer, session); } @@ -373,32 +356,32 @@ plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, */ static void ats_request_address_change (void *cls, const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, - const void *plugin_addr, size_t plugin_addr_len, - struct Session *session, + const char *plugin_name, const void *plugin_addr, + size_t plugin_addr_len, struct Session *session, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - const struct GNUNET_ATS_Information * ats, + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { uint32_t bw_in = ntohl (bandwidth_in.value__); uint32_t bw_out = ntohl (bandwidth_out.value__); - /* ATS tells me to disconnect from peer*/ + /* ATS tells me to disconnect from peer */ if ((bw_in == 0) && (bw_out == 0)) { #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "ATS tells me to disconnect from peer `%s'\n", - GNUNET_i2s (peer)); + "ATS tells me to disconnect from peer `%s'\n", + GNUNET_i2s (peer)); #endif - GST_neighbours_force_disconnect(peer); + GST_neighbours_force_disconnect (peer); return; } /* will never return GNUNET_YES since connection is to be established */ GST_neighbours_switch_to_address_3way (peer, plugin_name, plugin_addr, - plugin_addr_len, session, ats, ats_count, - bandwidth_in, bandwidth_out); + plugin_addr_len, session, ats, + ats_count, bandwidth_in, + bandwidth_out); } @@ -414,10 +397,11 @@ ats_request_address_change (void *cls, const struct GNUNET_PeerIdentity *peer, static void neighbours_connect_notification (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Information - *ats, uint32_t ats_count) + const struct GNUNET_ATS_Information *ats, + uint32_t ats_count) { - size_t len = sizeof (struct ConnectInfoMessage) + + size_t len = + sizeof (struct ConnectInfoMessage) + ats_count * sizeof (struct GNUNET_ATS_Information); char buf[len]; struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *) buf; @@ -428,8 +412,7 @@ neighbours_connect_notification (void *cls, connect_msg->ats_count = htonl (ats_count); connect_msg->id = *peer; ap = (struct GNUNET_ATS_Information *) &connect_msg[1]; - memcpy (ap, ats, - ats_count * sizeof (struct GNUNET_ATS_Information)); + memcpy (ap, ats, ats_count * sizeof (struct GNUNET_ATS_Information)); GST_clients_broadcast (&connect_msg->header, GNUNET_NO); } @@ -548,7 +531,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, GST_plugins_load (&plugin_env_receive_callback, &plugin_env_address_change_notification, &plugin_env_session_end); - GST_ats = GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL); + GST_ats = + GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL); GST_neighbours_start (NULL, &neighbours_connect_notification, &neighbours_disconnect_notification); GST_clients_start (server); diff --git a/src/transport/gnunet-service-transport_blacklist.c b/src/transport/gnunet-service-transport_blacklist.c index 45d01e1e2..78eea2ff9 100644 --- a/src/transport/gnunet-service-transport_blacklist.c +++ b/src/transport/gnunet-service-transport_blacklist.c @@ -557,9 +557,7 @@ struct TestConnectionContext static void test_connection_ok (void *cls, const struct GNUNET_PeerIdentity *neighbour, const struct GNUNET_ATS_Information *ats, - uint32_t ats_count, - const char * transport, - const void * addr, + uint32_t ats_count, const char *transport, const void *addr, size_t addrlen) { struct TestConnectionContext *tcc = cls; diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c index 8b022ef7e..ebab72db6 100644 --- a/src/transport/gnunet-service-transport_clients.c +++ b/src/transport/gnunet-service-transport_clients.c @@ -165,8 +165,7 @@ setup_client (struct GNUNET_SERVER_Client *client) GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, tc); #if DEBUG_TRANSPORT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client %X connected\n", tc); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %X connected\n", tc); #endif return tc; } @@ -333,29 +332,26 @@ client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client) static void notify_client_about_neighbour (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Information - *ats, uint32_t ats_count, - const char * transport, - const void * addr, - size_t addrlen) + const struct GNUNET_ATS_Information *ats, + uint32_t ats_count, const char *transport, + const void *addr, size_t addrlen) { struct TransportClient *tc = cls; struct ConnectInfoMessage *cim; struct GNUNET_ATS_Information *ap; size_t size = - sizeof (struct ConnectInfoMessage) + - ats_count * sizeof (struct GNUNET_ATS_Information); + sizeof (struct ConnectInfoMessage) + + ats_count * sizeof (struct GNUNET_ATS_Information); char buf[size]; GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE); - cim = (struct ConnectInfoMessage*) buf; + cim = (struct ConnectInfoMessage *) buf; cim->header.size = htons (size); cim->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); cim->ats_count = htonl (ats_count); cim->id = *peer; ap = (struct GNUNET_ATS_Information *) &cim[1]; - memcpy (ap, ats, - ats_count * sizeof (struct GNUNET_ATS_Information)); + memcpy (ap, ats, ats_count * sizeof (struct GNUNET_ATS_Information)); unicast (tc, &cim->header, GNUNET_NO); } @@ -401,10 +397,10 @@ clients_handle_start (void *cls, struct GNUNET_SERVER_Client *client, } start = (const struct StartMessage *) message; options = ntohl (start->options); - if ((0 != (1 & options) ) && + if ((0 != (1 & options)) && (0 != memcmp (&start->self, &GST_my_identity, - sizeof (struct GNUNET_PeerIdentity)))) + sizeof (struct GNUNET_PeerIdentity)))) { /* client thinks this is a different peer, reject */ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -799,26 +795,23 @@ clients_handle_peer_address_lookup (void *cls, */ static void output_addresses (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count, - const char * transport, - const void * addr, - size_t addrlen) + const struct GNUNET_ATS_Information *ats, uint32_t ats_count, + const char *transport, const void *addr, size_t addrlen) { struct GNUNET_SERVER_TransmitContext *tc = cls; - struct AddressIterateResponseMessage * msg; + struct AddressIterateResponseMessage *msg; size_t size; size = - (sizeof (struct AddressIterateResponseMessage) + strlen(transport) + 1); + (sizeof (struct AddressIterateResponseMessage) + strlen (transport) + 1); msg = GNUNET_malloc (size); memcpy (&msg->peer, peer, sizeof (struct GNUNET_PeerIdentity)); - memcpy (&msg[0], transport, strlen(transport)+1); + memcpy (&msg[0], transport, strlen (transport) + 1); msg->addrlen = ntohs (addrlen); - msg->pluginlen = ntohs (strlen(transport)+1); + msg->pluginlen = ntohs (strlen (transport) + 1); transmit_binary_to_client (tc, msg, size); - GNUNET_free(msg); + GNUNET_free (msg); } @@ -908,9 +901,8 @@ GST_clients_broadcast (const struct GNUNET_MessageHeader *msg, int may_drop) for (tc = clients_head; tc != NULL; tc = tc->next) { - if ( (GNUNET_YES == may_drop) && - (GNUNET_YES != tc->send_payload) ) - continue; /* skip, this client does not care about payload */ + if ((GNUNET_YES == may_drop) && (GNUNET_YES != tc->send_payload)) + continue; /* skip, this client does not care about payload */ unicast (tc, msg, may_drop); } } diff --git a/src/transport/gnunet-service-transport_hello.c b/src/transport/gnunet-service-transport_hello.c index a1c721857..45fdf0a26 100644 --- a/src/transport/gnunet-service-transport_hello.c +++ b/src/transport/gnunet-service-transport_hello.c @@ -166,7 +166,8 @@ refresh_hello_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) hello_task = GNUNET_SCHEDULER_NO_TASK; gc.addr_pos = oal_head; gc.expiration = - GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION); + GNUNET_TIME_relative_to_absolute + (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION); GNUNET_free (our_hello); our_hello = GNUNET_HELLO_create (&GST_my_public_key, &address_generator, &gc); #if DEBUG_TRANSPORT diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index d0d5b099c..0ceba53bc 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c @@ -122,7 +122,7 @@ struct SessionDisconnectMessage * Public key of the sender. */ struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key; - + /** * Signature of the peer that sends us the disconnect. Only * valid if the timestamp is AFTER the timestamp from the @@ -186,18 +186,18 @@ struct MessageQueue enum State { - /* fresh peer or completely disconnected */ - S_NOT_CONNECTED = 0, - /* sent CONNECT message to other peer, waiting for CONNECT_ACK */ - S_CONNECT_SENT = 1, - /* received CONNECT message to other peer, sending CONNECT_ACK */ - S_CONNECT_RECV = 4, - /* sent CONNECT_ACK message to other peer, wait for ACK or payload */ - S_CONNECT_RECV_ACK_SENT = 8, - /* received ACK or payload */ - S_CONNECTED = 16, - /* Disconnect in progress */ - S_DISCONNECT = 32 + /* fresh peer or completely disconnected */ + S_NOT_CONNECTED = 0, + /* sent CONNECT message to other peer, waiting for CONNECT_ACK */ + S_CONNECT_SENT = 1, + /* received CONNECT message to other peer, sending CONNECT_ACK */ + S_CONNECT_RECV = 4, + /* sent CONNECT_ACK message to other peer, wait for ACK or payload */ + S_CONNECT_RECV_ACK_SENT = 8, + /* received ACK or payload */ + S_CONNECTED = 16, + /* Disconnect in progress */ + S_DISCONNECT = 32 }; /** @@ -359,7 +359,7 @@ lookup_neighbour (const struct GNUNET_PeerIdentity *pid) #define change_state(n, state, ...) change (n, state, __LINE__) static int -is_connecting (struct NeighbourMapEntry * n) +is_connecting (struct NeighbourMapEntry *n) { if ((n->state > S_NOT_CONNECTED) && (n->state < S_CONNECTED)) return GNUNET_YES; @@ -367,7 +367,7 @@ is_connecting (struct NeighbourMapEntry * n) } static int -is_connected (struct NeighbourMapEntry * n) +is_connected (struct NeighbourMapEntry *n) { if (n->state == S_CONNECTED) return GNUNET_YES; @@ -375,7 +375,7 @@ is_connected (struct NeighbourMapEntry * n) } static int -is_disconnecting (struct NeighbourMapEntry * n) +is_disconnecting (struct NeighbourMapEntry *n) { if (n->state == S_DISCONNECT) return GNUNET_YES; @@ -385,84 +385,85 @@ is_disconnecting (struct NeighbourMapEntry * n) static const char * print_state (int state) { - switch (state) { - case S_CONNECTED: - return "S_CONNECTED"; - break; - case S_CONNECT_RECV: - return "S_CONNECT_RECV"; - break; - case S_CONNECT_RECV_ACK_SENT: - return"S_CONNECT_RECV_ACK_SENT"; - break; - case S_CONNECT_SENT: - return "S_CONNECT_SENT"; - break; - case S_DISCONNECT: - return "S_DISCONNECT"; - break; - case S_NOT_CONNECTED: - return "S_NOT_CONNECTED"; - break; - default: - GNUNET_break (0); - break; + switch (state) + { + case S_CONNECTED: + return "S_CONNECTED"; + break; + case S_CONNECT_RECV: + return "S_CONNECT_RECV"; + break; + case S_CONNECT_RECV_ACK_SENT: + return "S_CONNECT_RECV_ACK_SENT"; + break; + case S_CONNECT_SENT: + return "S_CONNECT_SENT"; + break; + case S_DISCONNECT: + return "S_DISCONNECT"; + break; + case S_NOT_CONNECTED: + return "S_NOT_CONNECTED"; + break; + default: + GNUNET_break (0); + break; } return NULL; } static int -change (struct NeighbourMapEntry * n, int state, int line); +change (struct NeighbourMapEntry *n, int state, int line); static void -ats_suggest_cancel (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc); +ats_suggest_cancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); static void -reset_task (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +reset_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - struct NeighbourMapEntry * n = cls; + struct NeighbourMapEntry *n = cls; n->state_reset = GNUNET_SCHEDULER_NO_TASK; #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Connection to peer `%s' %s failed in state `%s', resetting connection attempt \n", - GNUNET_i2s (&n->id), GST_plugins_a2s(n->plugin_name, n->addr, n->addrlen), print_state(n->state)); + "Connection to peer `%s' %s failed in state `%s', resetting connection attempt \n", + GNUNET_i2s (&n->id), GST_plugins_a2s (n->plugin_name, n->addr, + n->addrlen), + print_state (n->state)); #endif GNUNET_STATISTICS_update (GST_stats, - gettext_noop ("# failed connection attempts due to timeout"), - 1, + gettext_noop + ("# failed connection attempts due to timeout"), 1, GNUNET_NO); /* resetting state */ n->state = S_NOT_CONNECTED; /* destroying address */ - GNUNET_ATS_address_destroyed (GST_ats, - &n->id, - n->plugin_name, - n->addr, - n->addrlen, - NULL); + GNUNET_ATS_address_destroyed (GST_ats, &n->id, n->plugin_name, n->addr, + n->addrlen, NULL); /* request new address */ if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) - GNUNET_SCHEDULER_cancel(n->ats_suggest); - n->ats_suggest = GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, n); - GNUNET_ATS_suggest_address(GST_ats, &n->id); + GNUNET_SCHEDULER_cancel (n->ats_suggest); + n->ats_suggest = + GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, + n); + GNUNET_ATS_suggest_address (GST_ats, &n->id); } static int -change (struct NeighbourMapEntry * n, int state, int line) +change (struct NeighbourMapEntry *n, int state, int line) { - char * old = strdup(print_state(n->state)); - char * new = strdup(print_state(state)); + char *old = strdup (print_state (n->state)); + char *new = strdup (print_state (state)); /* allowed transitions */ int allowed = GNUNET_NO; - switch (n->state) { + + switch (n->state) + { case S_NOT_CONNECTED: if ((state == S_CONNECT_RECV) || (state == S_CONNECT_SENT) || (state == S_DISCONNECT)) @@ -470,10 +471,12 @@ change (struct NeighbourMapEntry * n, int state, int line) allowed = GNUNET_YES; /* Schedule reset task */ - if ((state == S_CONNECT_RECV) || (state == S_CONNECT_SENT) ) + if ((state == S_CONNECT_RECV) || (state == S_CONNECT_SENT)) { GNUNET_assert (n->state_reset == GNUNET_SCHEDULER_NO_TASK); - n->state_reset = GNUNET_SCHEDULER_add_delayed (SETUP_CONNECTION_TIMEOUT, &reset_task, n); + n->state_reset = + GNUNET_SCHEDULER_add_delayed (SETUP_CONNECTION_TIMEOUT, &reset_task, + n); } break; @@ -481,14 +484,18 @@ change (struct NeighbourMapEntry * n, int state, int line) break; case S_CONNECT_RECV: if ((state == S_NOT_CONNECTED) || (state == S_DISCONNECT) || - (state == S_CONNECTED) || /* FIXME SENT -> RECV ISSUE!*/ (state == S_CONNECT_SENT)) + (state == S_CONNECTED) || + /* FIXME SENT -> RECV ISSUE! */ (state == S_CONNECT_SENT)) { - if ((state == S_CONNECTED) || (state == S_DISCONNECT) || (state == S_NOT_CONNECTED)) + if ((state == S_CONNECTED) || (state == S_DISCONNECT) || + (state == S_NOT_CONNECTED)) { #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Removed reset task for peer `%s' %s failed in state transition `%s' -> `%s' \n", - GNUNET_i2s (&n->id), GST_plugins_a2s(n->plugin_name, n->addr, n->addrlen), print_state(n->state), print_state(state)); + "Removed reset task for peer `%s' %s failed in state transition `%s' -> `%s' \n", + GNUNET_i2s (&n->id), GST_plugins_a2s (n->plugin_name, + n->addr, n->addrlen), + print_state (n->state), print_state (state)); #endif GNUNET_assert (n->state_reset != GNUNET_SCHEDULER_NO_TASK); GNUNET_SCHEDULER_cancel (n->state_reset); @@ -501,14 +508,18 @@ change (struct NeighbourMapEntry * n, int state, int line) break; case S_CONNECT_SENT: if ((state == S_NOT_CONNECTED) || (state == S_CONNECTED) || - (state == S_DISCONNECT) || /* FIXME SENT -> RECV ISSUE!*/ (state == S_CONNECT_RECV)) + (state == S_DISCONNECT) || + /* FIXME SENT -> RECV ISSUE! */ (state == S_CONNECT_RECV)) { - if ((state == S_CONNECTED) || (state == S_DISCONNECT) || (state == S_NOT_CONNECTED)) + if ((state == S_CONNECTED) || (state == S_DISCONNECT) || + (state == S_NOT_CONNECTED)) { #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Removed reset task for peer `%s' %s failed in state transition `%s' -> `%s' \n", - GNUNET_i2s (&n->id), GST_plugins_a2s(n->plugin_name, n->addr, n->addrlen), print_state(n->state), print_state(state)); + "Removed reset task for peer `%s' %s failed in state transition `%s' -> `%s' \n", + GNUNET_i2s (&n->id), GST_plugins_a2s (n->plugin_name, + n->addr, n->addrlen), + print_state (n->state), print_state (state)); #endif GNUNET_assert (n->state_reset != GNUNET_SCHEDULER_NO_TASK); GNUNET_SCHEDULER_cancel (n->state_reset); @@ -528,11 +539,11 @@ change (struct NeighbourMapEntry * n, int state, int line) break; case S_DISCONNECT: /* - if (state == S_NOT_CONNECTED) - { - allowed = GNUNET_YES; - break; - }*/ + * if (state == S_NOT_CONNECTED) + * { + * allowed = GNUNET_YES; + * break; + * } */ break; default: GNUNET_break (0); @@ -543,8 +554,8 @@ change (struct NeighbourMapEntry * n, int state, int line) if (allowed == GNUNET_NO) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Illegal state transition from `%s' to `%s' in line %u \n", - old, new, line); + "Illegal state transition from `%s' to `%s' in line %u \n", old, + new, line); GNUNET_break (0); GNUNET_free (old); GNUNET_free (new); @@ -553,8 +564,9 @@ change (struct NeighbourMapEntry * n, int state, int line) n->state = state; #if DEBUG_TRANSPORT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "State for neighbour `%s' %X changed from `%s' to `%s' in line %u\n", - GNUNET_i2s (&n->id), n, old, new, line); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "State for neighbour `%s' %X changed from `%s' to `%s' in line %u\n", + GNUNET_i2s (&n->id), n, old, new, line); #endif GNUNET_free (old); GNUNET_free (new); @@ -562,19 +574,12 @@ change (struct NeighbourMapEntry * n, int state, int line) } static ssize_t -send_with_plugin ( const struct GNUNET_PeerIdentity * target, - const char *msgbuf, - size_t msgbuf_size, - uint32_t priority, - struct GNUNET_TIME_Relative timeout, - struct Session * session, - const char * plugin_name, - const void *addr, - size_t addrlen, - int force_address, - GNUNET_TRANSPORT_TransmitContinuation cont, - void *cont_cls) - +send_with_plugin (const struct GNUNET_PeerIdentity *target, const char *msgbuf, + size_t msgbuf_size, uint32_t priority, + struct GNUNET_TIME_Relative timeout, struct Session *session, + const char *plugin_name, const void *addr, size_t addrlen, + int force_address, GNUNET_TRANSPORT_TransmitContinuation cont, + void *cont_cls) { struct GNUNET_TRANSPORT_PluginFunctions *papi; size_t ret = GNUNET_SYSERR; @@ -602,15 +607,9 @@ send_with_plugin ( const struct GNUNET_PeerIdentity * target, return GNUNET_SYSERR; } - ret = papi->send (papi->cls, - target, - msgbuf, msgbuf_size, - 0, - timeout, - session, - addr, addrlen, - GNUNET_YES, - cont, cont_cls); + ret = + papi->send (papi->cls, target, msgbuf, msgbuf_size, 0, timeout, session, + addr, addrlen, GNUNET_YES, cont, cont_cls); if (ret == -1) { @@ -713,7 +712,7 @@ try_transmission_to_peer (struct NeighbourMapEntry *n) n->is_active = mq; mq->n = n; - if ((n->session == NULL) && (n->addr == NULL) && (n->addrlen == 0)) + if ((n->session == NULL) && (n->addr == NULL) && (n->addrlen == 0)) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No address for peer `%s'\n", GNUNET_i2s (&n->id)); @@ -723,12 +722,11 @@ try_transmission_to_peer (struct NeighbourMapEntry *n) return; } - ret = send_with_plugin (&n->id, - mq->message_buf, mq->message_buf_size, 0, - timeout, - n->session, n->plugin_name, n->addr, n->addrlen, - GNUNET_YES, - &transmit_send_continuation, mq); + ret = + send_with_plugin (&n->id, mq->message_buf, mq->message_buf_size, 0, + timeout, n->session, n->plugin_name, n->addr, + n->addrlen, GNUNET_YES, &transmit_send_continuation, + mq); if (ret == -1) { /* failure, but 'send' would not call continuation in this case, @@ -749,7 +747,8 @@ static void transmission_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct NeighbourMapEntry *n = cls; - GNUNET_assert (NULL != lookup_neighbour(&n->id)); + + GNUNET_assert (NULL != lookup_neighbour (&n->id)); n->transmission_task = GNUNET_SCHEDULER_NO_TASK; try_transmission_to_peer (n); } @@ -774,56 +773,61 @@ GST_neighbours_start (void *cls, GNUNET_TRANSPORT_NotifyConnect connect_cb, static void -send_disconnect_cont (void *cls, - const struct GNUNET_PeerIdentity * target, - int result) +send_disconnect_cont (void *cls, const struct GNUNET_PeerIdentity *target, + int result) { #if DEBUG_TRANSPORT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending DISCONNECT message to peer `%4s': %i\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Sending DISCONNECT message to peer `%4s': %i\n", GNUNET_i2s (target), result); #endif } static int -send_disconnect (const struct GNUNET_PeerIdentity * target, - const char *plugin_name, - const char *sender_address, uint16_t sender_address_len, - struct Session *session) +send_disconnect (const struct GNUNET_PeerIdentity *target, + const char *plugin_name, const char *sender_address, + uint16_t sender_address_len, struct Session *session) { size_t ret; struct SessionDisconnectMessage disconnect_msg; #if DEBUG_TRANSPORT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending DISCONNECT message to peer `%4s'\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Sending DISCONNECT message to peer `%4s'\n", GNUNET_i2s (target)); #endif disconnect_msg.header.size = htons (sizeof (struct SessionDisconnectMessage)); disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); disconnect_msg.reserved = htonl (0); - disconnect_msg.purpose.size = htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + - sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + - sizeof (struct GNUNET_TIME_AbsoluteNBO) ); - disconnect_msg.purpose.purpose = htonl (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT); - disconnect_msg.timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); + disconnect_msg.purpose.size = + htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + + sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + + sizeof (struct GNUNET_TIME_AbsoluteNBO)); + disconnect_msg.purpose.purpose = + htonl (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT); + disconnect_msg.timestamp = + GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); disconnect_msg.public_key = GST_my_public_key; GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_rsa_sign (GST_my_private_key, &disconnect_msg.purpose, &disconnect_msg.signature)); - ret = send_with_plugin(target, - (const char *) &disconnect_msg, sizeof (disconnect_msg), - UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, - session, plugin_name, sender_address, sender_address_len, - GNUNET_YES, &send_disconnect_cont, NULL); + ret = + send_with_plugin (target, (const char *) &disconnect_msg, + sizeof (disconnect_msg), UINT32_MAX, + GNUNET_TIME_UNIT_FOREVER_REL, session, plugin_name, + sender_address, sender_address_len, GNUNET_YES, + &send_disconnect_cont, NULL); if (ret == GNUNET_SYSERR) return GNUNET_SYSERR; GNUNET_STATISTICS_update (GST_stats, - gettext_noop ("# peers disconnected due to external request"), 1, + gettext_noop + ("# peers disconnected due to external request"), 1, GNUNET_NO); return GNUNET_OK; } @@ -837,21 +841,24 @@ static void disconnect_neighbour (struct NeighbourMapEntry *n) { struct MessageQueue *mq; - int was_connected = is_connected(n); + int was_connected = is_connected (n); /* send DISCONNECT MESSAGE */ - if (is_connected(n) || is_connecting(n)) + if (is_connected (n) || is_connecting (n)) { - if (GNUNET_OK == send_disconnect(&n->id, n->plugin_name, n->addr, n->addrlen, n->session)) + if (GNUNET_OK == + send_disconnect (&n->id, n->plugin_name, n->addr, n->addrlen, + n->session)) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent DISCONNECT_MSG to `%s'\n", GNUNET_i2s (&n->id)); else - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Could not send DISCONNECT_MSG to `%s'\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Could not send DISCONNECT_MSG to `%s'\n", GNUNET_i2s (&n->id)); } - if (is_disconnecting(n)) + if (is_disconnecting (n)) return; change_state (n, S_DISCONNECT); @@ -871,7 +878,7 @@ disconnect_neighbour (struct NeighbourMapEntry *n) { GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != n->keepalive_task); GNUNET_SCHEDULER_cancel (n->keepalive_task); - n->keepalive_task = GNUNET_SCHEDULER_NO_TASK; + n->keepalive_task = GNUNET_SCHEDULER_NO_TASK; GNUNET_assert (neighbours_connected > 0); neighbours_connected--; GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), -1, @@ -929,7 +936,8 @@ neighbour_timeout_task (void *cls, n->timeout_task = GNUNET_SCHEDULER_NO_TASK; GNUNET_STATISTICS_update (GST_stats, - gettext_noop ("# peers disconnected due to timeout"), 1, + gettext_noop + ("# peers disconnected due to timeout"), 1, GNUNET_NO); disconnect_neighbour (n); } @@ -943,27 +951,24 @@ neighbour_timeout_task (void *cls, */ static void neighbour_keepalive_task (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) + const struct GNUNET_SCHEDULER_TaskContext *tc) { struct NeighbourMapEntry *n = cls; struct GNUNET_MessageHeader m; - n->keepalive_task = GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY, - &neighbour_keepalive_task, - n); - GNUNET_assert (is_connected(n)); - GNUNET_STATISTICS_update (GST_stats, - gettext_noop ("# keepalives sent"), 1, - GNUNET_NO); + n->keepalive_task = + GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY, + &neighbour_keepalive_task, n); + GNUNET_assert (is_connected (n)); + GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# keepalives sent"), 1, + GNUNET_NO); m.size = htons (sizeof (struct GNUNET_MessageHeader)); m.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE); - send_with_plugin(&n->id, (const void *) &m, - sizeof (m), - UINT32_MAX /* priority */ , - GNUNET_TIME_UNIT_FOREVER_REL, - n->session, n->plugin_name, n->addr, n->addrlen, - GNUNET_YES, NULL, NULL); + send_with_plugin (&n->id, (const void *) &m, sizeof (m), + UINT32_MAX /* priority */ , + GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->plugin_name, + n->addr, n->addrlen, GNUNET_YES, NULL, NULL); } @@ -983,18 +988,18 @@ disconnect_all_neighbours (void *cls, const GNUNET_HashCode * key, void *value) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s', %s\n", GNUNET_i2s (&n->id), "SHUTDOWN_TASK"); #endif - if (is_connected(n)) + if (is_connected (n)) GNUNET_STATISTICS_update (GST_stats, - gettext_noop ("# peers disconnected due to global disconnect"), 1, - GNUNET_NO); + gettext_noop + ("# peers disconnected due to global disconnect"), + 1, GNUNET_NO); disconnect_neighbour (n); return GNUNET_OK; } static void -ats_suggest_cancel (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +ats_suggest_cancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct NeighbourMapEntry *n = cls; @@ -1004,7 +1009,7 @@ ats_suggest_cancel (void *cls, " ATS did not suggested address to connect to peer `%s'\n", GNUNET_i2s (&n->id)); - disconnect_neighbour(n); + disconnect_neighbour (n); } /** @@ -1039,44 +1044,39 @@ GST_neighbours_stop () * @param success GNUNET_OK on success */ static void -send_connect_continuation (void *cls, - const struct GNUNET_PeerIdentity * target, - int success) - +send_connect_continuation (void *cls, const struct GNUNET_PeerIdentity *target, + int success) { struct NeighbourMapEntry *n = cls; GNUNET_assert (n != NULL); - GNUNET_assert (!is_connected(n)); + GNUNET_assert (!is_connected (n)); - if (is_disconnecting(n)) - return; /* neighbour is going away */ + if (is_disconnecting (n)) + return; /* neighbour is going away */ if (GNUNET_YES != success) { #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Failed to send CONNECT_MSG to peer `%4s' with plugin `%s' address '%s' session %X, asking ATS for new address \n", - GNUNET_i2s (&n->id), n->plugin_name, - (n->addrlen == 0) ? "" : GST_plugins_a2s (n->plugin_name, - n->addr, - n->addrlen), - n->session); + "Failed to send CONNECT_MSG to peer `%4s' with plugin `%s' address '%s' session %X, asking ATS for new address \n", + GNUNET_i2s (&n->id), n->plugin_name, + (n->addrlen == + 0) ? "" : GST_plugins_a2s (n->plugin_name, n->addr, + n->addrlen), n->session); #endif - GNUNET_ATS_address_destroyed (GST_ats, - &n->id, - n->plugin_name, - n->addr, - n->addrlen, - NULL); + GNUNET_ATS_address_destroyed (GST_ats, &n->id, n->plugin_name, n->addr, + n->addrlen, NULL); - change_state(n, S_NOT_CONNECTED); + change_state (n, S_NOT_CONNECTED); - if (n->ats_suggest!= GNUNET_SCHEDULER_NO_TASK) - GNUNET_SCHEDULER_cancel(n->ats_suggest); - n->ats_suggest = GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, n); - GNUNET_ATS_suggest_address(GST_ats, &n->id); + if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) + GNUNET_SCHEDULER_cancel (n->ats_suggest); + n->ats_suggest = + GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, + n); + GNUNET_ATS_suggest_address (GST_ats, &n->id); return; } @@ -1093,40 +1093,36 @@ send_connect_continuation (void *cls, */ static void send_switch_address_continuation (void *cls, - const struct GNUNET_PeerIdentity * target, - int success) - + const struct GNUNET_PeerIdentity *target, + int success) { struct NeighbourMapEntry *n = cls; GNUNET_assert (n != NULL); - if (is_disconnecting(n)) - return; /* neighbour is going away */ + if (is_disconnecting (n)) + return; /* neighbour is going away */ GNUNET_assert (n->state == S_CONNECTED); if (GNUNET_YES != success) { #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Failed to switch connected peer `%s' to plugin `%s' address '%s' session %X, asking ATS for new address \n", - GNUNET_i2s (&n->id), n->plugin_name, - (n->addrlen == 0) ? "" : GST_plugins_a2s (n->plugin_name, - n->addr, - n->addrlen), - n->session); + "Failed to switch connected peer `%s' to plugin `%s' address '%s' session %X, asking ATS for new address \n", + GNUNET_i2s (&n->id), n->plugin_name, + (n->addrlen == + 0) ? "" : GST_plugins_a2s (n->plugin_name, n->addr, + n->addrlen), n->session); #endif - GNUNET_ATS_address_destroyed (GST_ats, - &n->id, - n->plugin_name, - n->addr, - n->addrlen, - NULL); + GNUNET_ATS_address_destroyed (GST_ats, &n->id, n->plugin_name, n->addr, + n->addrlen, NULL); if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) - GNUNET_SCHEDULER_cancel(n->ats_suggest); - n->ats_suggest = GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, n); - GNUNET_ATS_suggest_address(GST_ats, &n->id); + GNUNET_SCHEDULER_cancel (n->ats_suggest); + n->ats_suggest = + GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, + n); + GNUNET_ATS_suggest_address (GST_ats, &n->id); return; } } @@ -1141,40 +1137,37 @@ send_switch_address_continuation (void *cls, */ static void send_connect_ack_continuation (void *cls, - const struct GNUNET_PeerIdentity * target, - int success) - + const struct GNUNET_PeerIdentity *target, + int success) { struct NeighbourMapEntry *n = cls; GNUNET_assert (n != NULL); if (GNUNET_YES == success) - return; /* sending successful */ + return; /* sending successful */ /* sending failed, ask for next address */ #if DEBUG_TRANSPORT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to send CONNECT_MSG to peer `%4s' with plugin `%s' address '%s' session %X, asking ATS for new address \n", GNUNET_i2s (&n->id), n->plugin_name, (n->addrlen == 0) ? "" : GST_plugins_a2s (n->plugin_name, - n->addr, - n->addrlen), + n->addr, + n->addrlen), n->session); #endif - change_state(n, S_NOT_CONNECTED); + change_state (n, S_NOT_CONNECTED); - GNUNET_ATS_address_destroyed (GST_ats, - &n->id, - n->plugin_name, - n->addr, - n->addrlen, - NULL); + GNUNET_ATS_address_destroyed (GST_ats, &n->id, n->plugin_name, n->addr, + n->addrlen, NULL); - if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) - GNUNET_SCHEDULER_cancel(n->ats_suggest); - n->ats_suggest = GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, n); - GNUNET_ATS_suggest_address(GST_ats, &n->id); + if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) + GNUNET_SCHEDULER_cancel (n->ats_suggest); + n->ats_suggest = + GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, + n); + GNUNET_ATS_suggest_address (GST_ats, &n->id); } /** @@ -1194,12 +1187,15 @@ send_connect_ack_continuation (void *cls, */ int GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, const void *address, - size_t address_len, struct Session *session, - const struct GNUNET_ATS_Information - *ats, uint32_t ats_count, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) + const char *plugin_name, + const void *address, size_t address_len, + struct Session *session, + const struct GNUNET_ATS_Information *ats, + uint32_t ats_count, + struct GNUNET_BANDWIDTH_Value32NBO + bandwidth_in, + struct GNUNET_BANDWIDTH_Value32NBO + bandwidth_out) { struct NeighbourMapEntry *n; struct SessionConnectMessage connect_msg; @@ -1219,14 +1215,14 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "ATS offered suggested us empty address: plugin NULL"); - GNUNET_break_op(0); + GNUNET_break_op (0); checks_failed = GNUNET_YES; } - if ((address == NULL) && (address_len == 0 ) && (session == NULL)) + if ((address == NULL) && (address_len == 0) && (session == NULL)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "ATS offered suggested us empty address: address NULL & session NULL"); - GNUNET_break_op(0); + GNUNET_break_op (0); checks_failed = GNUNET_YES; } @@ -1236,12 +1232,10 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, if (checks_failed == GNUNET_YES) { - GNUNET_ATS_address_destroyed (GST_ats, - peer, - plugin_name, address, - address_len, session); + GNUNET_ATS_address_destroyed (GST_ats, peer, plugin_name, address, + address_len, session); if (n != NULL) - GNUNET_ATS_suggest_address(GST_ats, peer); + GNUNET_ATS_suggest_address (GST_ats, peer); return GNUNET_NO; } @@ -1253,18 +1247,18 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, (address_len == 0) ? "" : GST_plugins_a2s (plugin_name, address, address_len), - session, (is_connected(n) ? "CONNECTED" : "NOT CONNECTED"), + session, (is_connected (n) ? "CONNECTED" : "NOT CONNECTED"), GNUNET_i2s (peer)); #endif if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) { - GNUNET_SCHEDULER_cancel(n->ats_suggest); + GNUNET_SCHEDULER_cancel (n->ats_suggest); n->ats_suggest = GNUNET_SCHEDULER_NO_TASK; } // do not switch addresses just update quotas - if ((is_connected(n)) && (address_len == n->addrlen)) + if ((is_connected (n)) && (address_len == n->addrlen)) { if ((0 == memcmp (address, n->addr, address_len)) && (n->session == session)) @@ -1272,16 +1266,15 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, struct QuotaSetMessage q_msg; #if DEBUG_TRANSPORT -GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending outbound quota of %u Bps and inbound quota of %u Bps for peer `%s' to all clients\n", - ntohl (n->bandwidth_out.value__), - ntohl (n->bandwidth_in.value__), - GNUNET_i2s (peer)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Sending outbound quota of %u Bps and inbound quota of %u Bps for peer `%s' to all clients\n", + ntohl (n->bandwidth_out.value__), + ntohl (n->bandwidth_in.value__), GNUNET_i2s (peer)); #endif n->bandwidth_in = bandwidth_in; n->bandwidth_out = bandwidth_out; - GST_neighbours_set_incoming_quota(&n->id, n->bandwidth_in); + GST_neighbours_set_incoming_quota (&n->id, n->bandwidth_in); q_msg.header.size = htons (sizeof (struct QuotaSetMessage)); q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA); @@ -1324,9 +1317,11 @@ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, change_state (n, S_CONNECT_SENT); - ret = send_with_plugin (peer, (const char *) &connect_msg, msg_len, UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, - session, plugin_name, address, address_len, - GNUNET_YES, &send_connect_continuation, n); + ret = + send_with_plugin (peer, (const char *) &connect_msg, msg_len, + UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session, + plugin_name, address, address_len, GNUNET_YES, + &send_connect_continuation, n); return GNUNET_NO; } @@ -1336,13 +1331,16 @@ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, msg_len = sizeof (struct SessionConnectMessage); connect_msg.header.size = htons (msg_len); connect_msg.header.type = - htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK); + htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK); connect_msg.reserved = htonl (0); - connect_msg.timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); + connect_msg.timestamp = + GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); - ret = send_with_plugin(&n->id, (const void *) &connect_msg, msg_len, UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, - session, plugin_name, address, address_len, - GNUNET_YES, &send_connect_ack_continuation, n); + ret = + send_with_plugin (&n->id, (const void *) &connect_msg, msg_len, + UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session, + plugin_name, address, address_len, GNUNET_YES, + &send_connect_ack_continuation, n); return GNUNET_NO; } /* connected peer is switching addresses */ @@ -1356,26 +1354,28 @@ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, connect_msg.timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); - ret = send_with_plugin (peer, (const char *) &connect_msg, msg_len, UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, - session, plugin_name, address, address_len, - GNUNET_YES, &send_switch_address_continuation, n); + ret = + send_with_plugin (peer, (const char *) &connect_msg, msg_len, + UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session, + plugin_name, address, address_len, GNUNET_YES, + &send_switch_address_continuation, n); if (ret == GNUNET_SYSERR) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Failed to send CONNECT_MESSAGE to `%4s' using plugin `%s' address '%s' session %X\n", - GNUNET_i2s (peer), plugin_name, - (address_len == 0) ? "" : GST_plugins_a2s (plugin_name, - address, - address_len), - session); + "Failed to send CONNECT_MESSAGE to `%4s' using plugin `%s' address '%s' session %X\n", + GNUNET_i2s (peer), plugin_name, + (address_len == + 0) ? "" : GST_plugins_a2s (plugin_name, address, + address_len), session); } return GNUNET_NO; } else if (n->state == S_CONNECT_SENT) { - return GNUNET_NO; + return GNUNET_NO; } - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid connection state to switch addresses %u \n", n->state); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Invalid connection state to switch addresses %u \n", n->state); GNUNET_break_op (0); return GNUNET_NO; } @@ -1383,7 +1383,7 @@ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, /** * Create an entry in the neighbour map for the given peer - * + * * @param peer peer to create an entry for * @return new neighbour map entry */ @@ -1394,22 +1394,21 @@ setup_neighbour (const struct GNUNET_PeerIdentity *peer) #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Unknown peer `%s', creating new neighbour\n", - GNUNET_i2s (peer)); + "Unknown peer `%s', creating new neighbour\n", GNUNET_i2s (peer)); #endif n = GNUNET_malloc (sizeof (struct NeighbourMapEntry)); n->id = *peer; n->state = S_NOT_CONNECTED; GNUNET_BANDWIDTH_tracker_init (&n->in_tracker, - GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, - MAX_BANDWIDTH_CARRY_S); + GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, + MAX_BANDWIDTH_CARRY_S); n->timeout_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, - &neighbour_timeout_task, n); + GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, + &neighbour_timeout_task, n); GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put (neighbours, - &n->id.hashPubKey, n, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + GNUNET_CONTAINER_multihashmap_put (neighbours, + &n->id.hashPubKey, n, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); return n; } @@ -1433,8 +1432,8 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to connect to peer `%s'\n", GNUNET_i2s (target)); #endif - if (0 == memcmp (target, &GST_my_identity, - sizeof (struct GNUNET_PeerIdentity))) + if (0 == + memcmp (target, &GST_my_identity, sizeof (struct GNUNET_PeerIdentity))) { /* my own hello */ return; @@ -1443,9 +1442,9 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target) if (NULL != n) { - if ((is_connected(n)) || (is_connecting(n))) - return; /* already connecting or connected */ - if (is_disconnecting(n)) + if ((is_connected (n)) || (is_connecting (n))) + return; /* already connecting or connected */ + if (is_disconnecting (n)) change_state (n, S_NOT_CONNECTED); } @@ -1458,7 +1457,7 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target) GNUNET_i2s (&n->id)); #endif - GNUNET_ATS_suggest_address (GST_ats, &n->id); + GNUNET_ATS_suggest_address (GST_ats, &n->id); } /** @@ -1480,7 +1479,7 @@ GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target) n = lookup_neighbour (target); - if ((NULL == n) || (!is_connected(n))) + if ((NULL == n) || (!is_connected (n))) return GNUNET_NO; /* not connected */ return GNUNET_YES; } @@ -1505,8 +1504,7 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer, } #if DEBUG_TRANSPORT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Session %X to peer `%s' ended \n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Session %X to peer `%s' ended \n", session, GNUNET_i2s (peer)); #endif @@ -1522,7 +1520,7 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer, n->addrlen = 0; /* not connected anymore anyway, shouldn't matter */ - if ((!is_connected(n)) && (!is_connecting(n))) + if ((!is_connected (n)) && (!is_connecting (n))) return; /* We are connected, so ask ATS to switch addresses */ @@ -1532,8 +1530,10 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer, &neighbour_timeout_task, n); /* try QUICKLY to re-establish a connection, reduce timeout! */ if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) - GNUNET_SCHEDULER_cancel(n->ats_suggest); - n->ats_suggest = GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, n); + GNUNET_SCHEDULER_cancel (n->ats_suggest); + n->ats_suggest = + GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, + n); GNUNET_ATS_suggest_address (GST_ats, peer); } @@ -1563,7 +1563,7 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg, } n = lookup_neighbour (target); - if ((n == NULL) || (!is_connected(n))) + if ((n == NULL) || (!is_connected (n))) { GNUNET_STATISTICS_update (GST_stats, gettext_noop @@ -1574,7 +1574,7 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Could not send message to peer `%s': unknown neighbour", GNUNET_i2s (target)); - else if (!is_connected(n)) + else if (!is_connected (n)) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Could not send message to peer `%s': not connected\n", GNUNET_i2s (target)); @@ -1584,16 +1584,16 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg, return; } - if ((n->session == NULL) && (n->addr == NULL) && (n->addrlen ==0)) + if ((n->session == NULL) && (n->addr == NULL) && (n->addrlen == 0)) { GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# messages not sent (no such peer or not connected)"), 1, GNUNET_NO); #if DEBUG_TRANSPORT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Could not send message to peer `%s': no address available\n", - GNUNET_i2s (target)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Could not send message to peer `%s': no address available\n", + GNUNET_i2s (target)); #endif if (NULL != cont) @@ -1655,14 +1655,14 @@ GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity if (NULL == n) { GNUNET_STATISTICS_update (GST_stats, - gettext_noop - ("# messages discarded due to lack of neighbour record"), - 1, GNUNET_NO); + gettext_noop + ("# messages discarded due to lack of neighbour record"), + 1, GNUNET_NO); *do_forward = GNUNET_NO; return GNUNET_TIME_UNIT_ZERO; } } - if (!is_connected(n)) + if (!is_connected (n)) { *do_forward = GNUNET_SYSERR; return GNUNET_TIME_UNIT_ZERO; @@ -1784,10 +1784,10 @@ GST_neighbours_set_incoming_quota (const struct GNUNET_PeerIdentity *neighbour, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s' due to `%s'\n", GNUNET_i2s (&n->id), "SET_QUOTA"); #endif - if (is_connected(n)) + if (is_connected (n)) GNUNET_STATISTICS_update (GST_stats, - gettext_noop ("# disconnects due to quota of 0"), 1, - GNUNET_NO); + gettext_noop ("# disconnects due to quota of 0"), + 1, GNUNET_NO); disconnect_neighbour (n); } @@ -1823,7 +1823,7 @@ neighbours_iterate (void *cls, const GNUNET_HashCode * key, void *value) struct IteratorContext *ic = cls; struct NeighbourMapEntry *n = value; - if (!is_connected(n)) + if (!is_connected (n)) return GNUNET_OK; ic->cb (ic->cb_cls, &n->id, NULL, 0, n->plugin_name, n->addr, n->addrlen); @@ -1872,13 +1872,13 @@ GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target) n = lookup_neighbour (target); if (NULL == n) return; /* not active */ - if (is_connected(n)) + if (is_connected (n)) { - send_disconnect(&n->id, n->plugin_name, n->addr, n->addrlen, n->session); + send_disconnect (&n->id, n->plugin_name, n->addr, n->addrlen, n->session); n = lookup_neighbour (target); if (NULL == n) - return; /* gone already */ + return; /* gone already */ } disconnect_neighbour (n); } @@ -1887,13 +1887,15 @@ GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target) /** * We received a disconnect message from the given peer, * validate and process. - * + * * @param peer sender of the message * @param msg the disconnect message */ void -GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *msg) +GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity + *peer, + const struct GNUNET_MessageHeader + *msg) { struct NeighbourMapEntry *n; const struct SessionDisconnectMessage *sdm; @@ -1901,18 +1903,20 @@ GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received DISCONNECT message from peer `%s'\n", GNUNET_i2s (peer)); + "Received DISCONNECT message from peer `%s'\n", + GNUNET_i2s (peer)); #endif if (ntohs (msg->size) != sizeof (struct SessionDisconnectMessage)) { // GNUNET_break_op (0); GNUNET_STATISTICS_update (GST_stats, - gettext_noop ("# disconnect messages ignored (old format)"), 1, - GNUNET_NO); + gettext_noop + ("# disconnect messages ignored (old format)"), 1, + GNUNET_NO); return; } - sdm = (const struct SessionDisconnectMessage* ) msg; + sdm = (const struct SessionDisconnectMessage *) msg; n = lookup_neighbour (peer); if (NULL == n) return; /* gone already */ @@ -1920,21 +1924,20 @@ GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer n->connect_ts.abs_value) { GNUNET_STATISTICS_update (GST_stats, - gettext_noop ("# disconnect messages ignored (timestamp)"), 1, - GNUNET_NO); + gettext_noop + ("# disconnect messages ignored (timestamp)"), 1, + GNUNET_NO); return; } GNUNET_CRYPTO_hash (&sdm->public_key, - sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), - &hc); - if (0 != memcmp (peer, - &hc, - sizeof (struct GNUNET_PeerIdentity))) + sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), + &hc); + if (0 != memcmp (peer, &hc, sizeof (struct GNUNET_PeerIdentity))) { GNUNET_break_op (0); return; } - if (ntohl (sdm->purpose.size) != + if (ntohl (sdm->purpose.size) != sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + sizeof (struct GNUNET_TIME_AbsoluteNBO)) @@ -1943,10 +1946,9 @@ GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer return; } if (GNUNET_OK != - GNUNET_CRYPTO_rsa_verify (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT, - &sdm->purpose, - &sdm->signature, - &sdm->public_key)) + GNUNET_CRYPTO_rsa_verify + (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT, &sdm->purpose, + &sdm->signature, &sdm->public_key)) { GNUNET_break_op (0); return; @@ -1970,12 +1972,13 @@ GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer */ void GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message, - const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, - const char *sender_address, uint16_t sender_address_len, - struct Session *session, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_PeerIdentity *peer, + const char *plugin_name, + const char *sender_address, + uint16_t sender_address_len, + struct Session *session, + const struct GNUNET_ATS_Information *ats, + uint32_t ats_count) { const struct SessionConnectMessage *scm; struct QuotaSetMessage q_msg; @@ -1987,7 +1990,8 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message, #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received CONNECT_ACK message from peer `%s'\n", GNUNET_i2s (peer)); + "Received CONNECT_ACK message from peer `%s'\n", + GNUNET_i2s (peer)); #endif if (ntohs (message->size) != sizeof (struct SessionConnectMessage)) @@ -2013,104 +2017,94 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message, GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, "transport-ats", "Giving ATS session %p of plugin %s for peer %s\n", - session, - plugin_name, - GNUNET_i2s (peer)); - GNUNET_ATS_address_update (GST_ats, - peer, - plugin_name, sender_address, sender_address_len, - session, ats, ats_count); - - was_connected = is_connected(n); - if (!is_connected(n)) + session, plugin_name, GNUNET_i2s (peer)); + GNUNET_ATS_address_update (GST_ats, peer, plugin_name, sender_address, + sender_address_len, session, ats, ats_count); + + was_connected = is_connected (n); + if (!is_connected (n)) change_state (n, S_CONNECTED); - GNUNET_ATS_address_in_use (GST_ats, - peer, - plugin_name, - sender_address, - sender_address_len, - session, - GNUNET_YES); + GNUNET_ATS_address_in_use (GST_ats, peer, plugin_name, sender_address, + sender_address_len, session, GNUNET_YES); #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Setting inbound quota of %u for peer `%s' to \n", ntohl (n->bandwidth_in.value__), GNUNET_i2s (&n->id)); #endif - GST_neighbours_set_incoming_quota(&n->id, n->bandwidth_in); + GST_neighbours_set_incoming_quota (&n->id, n->bandwidth_in); - /* send ACK (ACK)*/ - msg_len = sizeof (msg); + /* send ACK (ACK) */ + msg_len = sizeof (msg); msg.size = htons (msg_len); msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK); - ret = send_with_plugin (&n->id, (const char *) &msg, msg_len, UINT32_MAX, - GNUNET_TIME_UNIT_FOREVER_REL, - n->session, n->plugin_name, n->addr, n->addrlen, - GNUNET_YES, NULL, NULL); + ret = + send_with_plugin (&n->id, (const char *) &msg, msg_len, UINT32_MAX, + GNUNET_TIME_UNIT_FOREVER_REL, n->session, + n->plugin_name, n->addr, n->addrlen, GNUNET_YES, NULL, + NULL); if (ret == GNUNET_SYSERR) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Failed to send SESSION_ACK to `%4s' using plugin `%s' address '%s' session %X\n", - GNUNET_i2s (&n->id), n->plugin_name, - (n->addrlen == 0) ? "" : GST_plugins_a2s (n->plugin_name, - n->addr, - n->addrlen), - n->session); + "Failed to send SESSION_ACK to `%4s' using plugin `%s' address '%s' session %X\n", + GNUNET_i2s (&n->id), n->plugin_name, + (n->addrlen == + 0) ? "" : GST_plugins_a2s (n->plugin_name, n->addr, + n->addrlen), n->session); if (!was_connected) { if (n->keepalive_task == GNUNET_SCHEDULER_NO_TASK) - n->keepalive_task = GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY, - &neighbour_keepalive_task, - n); + n->keepalive_task = + GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY, + &neighbour_keepalive_task, n); neighbours_connected++; GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1, GNUNET_NO); #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Notify about connect of `%4s' using plugin `%s' address '%s' session %X LINE %u\n", - GNUNET_i2s (&n->id), n->plugin_name, - (n->addrlen == 0) ? "" : GST_plugins_a2s (n->plugin_name, - n->addr, - n->addrlen), - n->session, __LINE__); + "Notify about connect of `%4s' using plugin `%s' address '%s' session %X LINE %u\n", + GNUNET_i2s (&n->id), n->plugin_name, + (n->addrlen == + 0) ? "" : GST_plugins_a2s (n->plugin_name, n->addr, + n->addrlen), n->session, + __LINE__); #endif connect_notify_cb (callback_cls, &n->id, ats, ats_count); } #if DEBUG_TRANSPORT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending outbound quota of %u Bps for peer `%s' to all clients\n", - ntohl (n->bandwidth_out.value__), GNUNET_i2s (peer)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Sending outbound quota of %u Bps for peer `%s' to all clients\n", + ntohl (n->bandwidth_out.value__), GNUNET_i2s (peer)); #endif - q_msg.header.size = htons (sizeof (struct QuotaSetMessage)); - q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA); - q_msg.quota = n->bandwidth_out; - q_msg.peer = (*peer); - GST_clients_broadcast (&q_msg.header, GNUNET_NO); + q_msg.header.size = htons (sizeof (struct QuotaSetMessage)); + q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA); + q_msg.quota = n->bandwidth_out; + q_msg.peer = (*peer); + GST_clients_broadcast (&q_msg.header, GNUNET_NO); } void GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message, - const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, - const char *sender_address, uint16_t sender_address_len, - struct Session *session, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_PeerIdentity *peer, + const char *plugin_name, const char *sender_address, + uint16_t sender_address_len, struct Session *session, + const struct GNUNET_ATS_Information *ats, + uint32_t ats_count) { struct NeighbourMapEntry *n; struct QuotaSetMessage q_msg; int was_connected; #if DEBUG_TRANSPORT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received ACK message from peer `%s'\n", GNUNET_i2s (peer)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ACK message from peer `%s'\n", + GNUNET_i2s (peer)); #endif if (ntohs (message->size) != sizeof (struct GNUNET_MessageHeader)) @@ -2122,60 +2116,52 @@ GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message, n = lookup_neighbour (peer); if (NULL == n) { - send_disconnect(peer, plugin_name, sender_address, sender_address_len, session); + send_disconnect (peer, plugin_name, sender_address, sender_address_len, + session); GNUNET_break (0); return; } - if (is_connected(n)) + if (is_connected (n)) return; if (NULL != session) GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, "transport-ats", "Giving ATS session %p of plugin %s for peer %s\n", - session, - plugin_name, - GNUNET_i2s (peer)); - GNUNET_ATS_address_update (GST_ats, - peer, - plugin_name, sender_address, sender_address_len, - session, ats, ats_count); - - was_connected = is_connected(n); + session, plugin_name, GNUNET_i2s (peer)); + GNUNET_ATS_address_update (GST_ats, peer, plugin_name, sender_address, + sender_address_len, session, ats, ats_count); + + was_connected = is_connected (n); change_state (n, S_CONNECTED); - GNUNET_ATS_address_in_use (GST_ats, - peer, - plugin_name, - sender_address, - sender_address_len, - session, - GNUNET_YES); + GNUNET_ATS_address_in_use (GST_ats, peer, plugin_name, sender_address, + sender_address_len, session, GNUNET_YES); - GST_neighbours_set_incoming_quota(&n->id, n->bandwidth_in); + GST_neighbours_set_incoming_quota (&n->id, n->bandwidth_in); if (n->keepalive_task == GNUNET_SCHEDULER_NO_TASK) - n->keepalive_task = GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY, - &neighbour_keepalive_task, - n); + n->keepalive_task = + GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY, + &neighbour_keepalive_task, n); if (!was_connected) { - neighbours_connected++; - GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1, - GNUNET_NO); + neighbours_connected++; + GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1, + GNUNET_NO); #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Notify about connect of `%4s' using plugin `%s' address '%s' session %X LINE %u\n", - GNUNET_i2s (&n->id), n->plugin_name, - (n->addrlen == 0) ? "" : GST_plugins_a2s (n->plugin_name, - n->addr, - n->addrlen), - n->session, __LINE__); + "Notify about connect of `%4s' using plugin `%s' address '%s' session %X LINE %u\n", + GNUNET_i2s (&n->id), n->plugin_name, + (n->addrlen == + 0) ? "" : GST_plugins_a2s (n->plugin_name, n->addr, + n->addrlen), n->session, + __LINE__); #endif - connect_notify_cb (callback_cls, &n->id, ats, ats_count); + connect_notify_cb (callback_cls, &n->id, ats, ats_count); } #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -2209,15 +2195,17 @@ struct BlackListCheckContext static void handle_connect_blacklist_cont (void *cls, - const struct GNUNET_PeerIdentity - * peer, int result) + const struct GNUNET_PeerIdentity *peer, + int result) { struct NeighbourMapEntry *n; - struct BlackListCheckContext * bcc = cls; + struct BlackListCheckContext *bcc = cls; #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Blacklist check due to CONNECT message: `%s'\n", GNUNET_i2s (peer), (result == GNUNET_OK) ? "ALLOWED" : "FORBIDDEN"); + "Blacklist check due to CONNECT message: `%s'\n", + GNUNET_i2s (peer), + (result == GNUNET_OK) ? "ALLOWED" : "FORBIDDEN"); #endif /* not allowed */ @@ -2237,13 +2225,12 @@ handle_connect_blacklist_cont (void *cls, GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, "transport-ats", "Giving ATS session %p of plugin %s address `%s' for peer %s\n", - bcc->session, - bcc->plugin_name, - GST_plugins_a2s (bcc->plugin_name, bcc->sender_address, bcc->sender_address_len), + bcc->session, bcc->plugin_name, + GST_plugins_a2s (bcc->plugin_name, bcc->sender_address, + bcc->sender_address_len), GNUNET_i2s (peer)); - GNUNET_ATS_address_update (GST_ats, - peer, - bcc->plugin_name, bcc->sender_address, bcc->sender_address_len, + GNUNET_ATS_address_update (GST_ats, peer, bcc->plugin_name, + bcc->sender_address, bcc->sender_address_len, bcc->session, bcc->ats, bcc->ats_count); n->connect_ts = bcc->ts; } @@ -2251,13 +2238,15 @@ handle_connect_blacklist_cont (void *cls, GNUNET_free (bcc); if (n->state != S_CONNECT_RECV) - change_state (n, S_CONNECT_RECV); + change_state (n, S_CONNECT_RECV); /* Ask ATS for an address to connect via that address */ if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) - GNUNET_SCHEDULER_cancel(n->ats_suggest); - n->ats_suggest = GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, n); - GNUNET_ATS_suggest_address(GST_ats, peer); + GNUNET_SCHEDULER_cancel (n->ats_suggest); + n->ats_suggest = + GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, + n); + GNUNET_ATS_suggest_address (GST_ats, peer); } /** @@ -2276,20 +2265,21 @@ handle_connect_blacklist_cont (void *cls, */ void GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message, - const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, - const char *sender_address, uint16_t sender_address_len, - struct Session *session, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_PeerIdentity *peer, + const char *plugin_name, + const char *sender_address, + uint16_t sender_address_len, + struct Session *session, + const struct GNUNET_ATS_Information *ats, + uint32_t ats_count) { const struct SessionConnectMessage *scm; - struct NeighbourMapEntry * n; - struct BlackListCheckContext * bcc = NULL; + struct NeighbourMapEntry *n; + struct BlackListCheckContext *bcc = NULL; #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received CONNECT message from peer `%s'\n", GNUNET_i2s (peer)); + "Received CONNECT message from peer `%s'\n", GNUNET_i2s (peer)); #endif if (ntohs (message->size) != sizeof (struct SessionConnectMessage)) @@ -2301,23 +2291,24 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message, scm = (const struct SessionConnectMessage *) message; GNUNET_break_op (ntohl (scm->reserved) == 0); - n = lookup_neighbour(peer); + n = lookup_neighbour (peer); if (n != NULL) { /* connected peer switches addresses */ - if (is_connected(n)) + if (is_connected (n)) { - GNUNET_ATS_address_update(GST_ats, peer, plugin_name, sender_address, sender_address_len, session, ats, ats_count); + GNUNET_ATS_address_update (GST_ats, peer, plugin_name, sender_address, + sender_address_len, session, ats, ats_count); return; } } /* we are not connected to this peer */ - /* do blacklist check*/ - bcc = GNUNET_malloc (sizeof (struct BlackListCheckContext) + - sizeof (struct GNUNET_ATS_Information) * ats_count + - sender_address_len + - strlen (plugin_name)+1); + /* do blacklist check */ + bcc = + GNUNET_malloc (sizeof (struct BlackListCheckContext) + + sizeof (struct GNUNET_ATS_Information) * ats_count + + sender_address_len + strlen (plugin_name) + 1); bcc->ts = GNUNET_TIME_absolute_ntoh (scm->timestamp); @@ -2326,15 +2317,16 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message, bcc->session = session; bcc->ats = (struct GNUNET_ATS_Information *) &bcc[1]; - memcpy (bcc->ats, ats,sizeof (struct GNUNET_ATS_Information) * ats_count ); + memcpy (bcc->ats, ats, sizeof (struct GNUNET_ATS_Information) * ats_count); bcc->sender_address = (char *) &bcc->ats[ats_count]; - memcpy (bcc->sender_address, sender_address , sender_address_len); + memcpy (bcc->sender_address, sender_address, sender_address_len); bcc->plugin_name = &bcc->sender_address[sender_address_len]; strcpy (bcc->plugin_name, plugin_name); - GST_blacklist_test_allowed (peer, plugin_name, handle_connect_blacklist_cont, bcc); + GST_blacklist_test_allowed (peer, plugin_name, handle_connect_blacklist_cont, + bcc); } diff --git a/src/transport/gnunet-service-transport_neighbours.h b/src/transport/gnunet-service-transport_neighbours.h index 3868ef2cf..3aafc3d55 100644 --- a/src/transport/gnunet-service-transport_neighbours.h +++ b/src/transport/gnunet-service-transport_neighbours.h @@ -159,11 +159,9 @@ GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target); typedef void (*GST_NeighbourIterator) (void *cls, const struct GNUNET_PeerIdentity * neighbour, - const struct - GNUNET_ATS_Information * ats, - uint32_t ats_count, - const char * transport, - const void * addr, + const struct GNUNET_ATS_Information * + ats, uint32_t ats_count, + const char *transport, const void *addr, size_t addrlen); @@ -209,17 +207,20 @@ int GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, const char *plugin_name, const void *address, size_t address_len, struct Session *session, - const struct GNUNET_ATS_Information - *ats, uint32_t ats_count); + const struct GNUNET_ATS_Information *ats, + uint32_t ats_count); int GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, const void *address, - size_t address_len, struct Session *session, - const struct GNUNET_ATS_Information - *ats, uint32_t ats_count, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out); + const char *plugin_name, + const void *address, size_t address_len, + struct Session *session, + const struct GNUNET_ATS_Information *ats, + uint32_t ats_count, + struct GNUNET_BANDWIDTH_Value32NBO + bandwidth_in, + struct GNUNET_BANDWIDTH_Value32NBO + bandwidth_out); /** @@ -238,41 +239,44 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, */ void GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message, - const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, - const char *sender_address, uint16_t sender_address_len, - struct Session *session, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count); - -void -GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message, const struct GNUNET_PeerIdentity *peer, const char *plugin_name, - const char *sender_address, uint16_t sender_address_len, + const char *sender_address, + uint16_t sender_address_len, struct Session *session, const struct GNUNET_ATS_Information *ats, uint32_t ats_count); +void +GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message, + const struct GNUNET_PeerIdentity *peer, + const char *plugin_name, + const char *sender_address, + uint16_t sender_address_len, + struct Session *session, + const struct GNUNET_ATS_Information *ats, + uint32_t ats_count); + void GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message, - const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, - const char *sender_address, uint16_t sender_address_len, - struct Session *session, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count); + const struct GNUNET_PeerIdentity *peer, + const char *plugin_name, const char *sender_address, + uint16_t sender_address_len, struct Session *session, + const struct GNUNET_ATS_Information *ats, + uint32_t ats_count); /** * We received a disconnect message from the given peer, * validate and process. - * + * * @param peer sender of the message * @param msg the disconnect message */ void -GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *msg); +GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity + *peer, + const struct GNUNET_MessageHeader + *msg); #endif diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c index 5758ebfbb..d7b4929b2 100644 --- a/src/transport/gnunet-service-transport_validation.c +++ b/src/transport/gnunet-service-transport_validation.c @@ -405,8 +405,8 @@ add_valid_address (void *cls, const char *tname, } ve = find_validation_entry (&public_key, &pid, tname, addr, addrlen); ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, expiration); - GNUNET_ATS_address_update (GST_ats, &pid, tname, addr, - addrlen, NULL, NULL, 0); + GNUNET_ATS_address_update (GST_ats, &pid, tname, addr, addrlen, NULL, NULL, + 0); return GNUNET_OK; } @@ -595,7 +595,8 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, sizeof (struct GNUNET_PeerIdentity))) { GNUNET_STATISTICS_update (GST_stats, - gettext_noop ("# PING message for different peer received"), 1, + gettext_noop + ("# PING message for different peer received"), 1, GNUNET_NO); return; } @@ -614,27 +615,28 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, { addrend = memchr (addr, '\0', alen); if (NULL == addrend) - { - GNUNET_break_op (0); - return; - } + { + GNUNET_break_op (0); + return; + } addrend++; slen = strlen (addr) + 1; alen -= slen; - + if (GNUNET_YES != - GST_hello_test_address (addr, addrend, alen, &sig_cache, &sig_cache_exp)) + GST_hello_test_address (addr, addrend, alen, &sig_cache, + &sig_cache_exp)) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _ - ("Not confirming PING with address `%s' since I cannot confirm having this address.\n"), - GST_plugins_a2s (addr, addrend, alen)); + _ + ("Not confirming PING with address `%s' since I cannot confirm having this address.\n"), + GST_plugins_a2s (addr, addrend, alen)); return; } - } + } else { - addrend = NULL; /* make gcc happy */ + addrend = NULL; /* make gcc happy */ slen = 0; static struct GNUNET_CRYPTO_RsaSignature no_address_signature; static struct GNUNET_TIME_Absolute no_address_signature_expiration; @@ -751,7 +753,8 @@ transmit_ping_if_allowed (void *cls, const struct GNUNET_PeerIdentity *pid, ve->bc = NULL; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting plain PING to `%s' %s\n", - GNUNET_i2s (pid), GST_plugins_a2s (ve->transport_name, ve->addr, ve->addrlen)); + GNUNET_i2s (pid), GST_plugins_a2s (ve->transport_name, ve->addr, + ve->addrlen)); slen = strlen (ve->transport_name) + 1; hello = GST_hello_get (); @@ -996,12 +999,13 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, struct GNUNET_ATS_Information ats; ats.type = htonl (GNUNET_ATS_QUALITY_NET_DELAY); - ats.value = htonl ((uint32_t) GNUNET_TIME_absolute_get_duration (ve->send_time).rel_value); - GNUNET_ATS_address_update (GST_ats, &ve->pid, - ve->transport_name,ve->addr, ve->addrlen, NULL, - &ats, 1); + ats.value = + htonl ((uint32_t) + GNUNET_TIME_absolute_get_duration (ve->send_time).rel_value); + GNUNET_ATS_address_update (GST_ats, &ve->pid, ve->transport_name, ve->addr, + ve->addrlen, NULL, &ats, 1); } - + /* build HELLO to store in PEERINFO */ ve->copied = GNUNET_NO; hello = GNUNET_HELLO_create (&ve->public_key, &add_valid_peer_address, ve); @@ -1043,17 +1047,16 @@ GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello) GNUNET_break (0); return; } - if (0 == memcmp (&GST_my_identity, &vac.pid, sizeof (struct GNUNET_PeerIdentity))) + if (0 == + memcmp (&GST_my_identity, &vac.pid, sizeof (struct GNUNET_PeerIdentity))) return; /* Add peer identity without addresses to peerinfo service */ h = GNUNET_HELLO_create (&vac.public_key, NULL, NULL); GNUNET_PEERINFO_add_peer (GST_peerinfo, h); #if VERBOSE_VALIDATION GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - _ - ("Adding `%s' without addresses for peer `%s'\n"), - "HELLO", - GNUNET_i2s(&vac.pid)); + _("Adding `%s' without addresses for peer `%s'\n"), "HELLO", + GNUNET_i2s (&vac.pid)); #endif GNUNET_free (h); diff --git a/src/transport/gnunet-transport-connect-running-peers.c b/src/transport/gnunet-transport-connect-running-peers.c index a0e3b93a2..172f34b27 100644 --- a/src/transport/gnunet-transport-connect-running-peers.c +++ b/src/transport/gnunet-transport-connect-running-peers.c @@ -174,24 +174,23 @@ sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) "Press to quit or <1> to send from p1 to p2, <2> to send from p2 to p1, repeat\n"); read: - t = getchar(); + t = getchar (); if (t == '1') { - th = GNUNET_TRANSPORT_notify_transmit_ready (p1->th, &p2->id, 256, 0, TIMEOUT, - ¬ify_ready, p1); + th = GNUNET_TRANSPORT_notify_transmit_ready (p1->th, &p2->id, 256, 0, + TIMEOUT, ¬ify_ready, p1); return; } if (t == '2') { - th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, 256, 0, TIMEOUT, - ¬ify_ready, p2); + th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, 256, 0, + TIMEOUT, ¬ify_ready, p2); return; } if (t == 'q') { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Exiting %c!\n", t); - GNUNET_SCHEDULER_add_now(&end, NULL); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Exiting %c!\n", t); + GNUNET_SCHEDULER_add_now (&end, NULL); return; } goto read; @@ -200,8 +199,7 @@ read: static void notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message of type %d from peer %s!\n", @@ -210,8 +208,7 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, if ((MTYPE == ntohs (message->type)) && (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Successfully received message\n"); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Successfully received message\n"); send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL); } @@ -219,8 +216,7 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, static void notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls); diff --git a/src/transport/gnunet-transport-wlan-helper.c b/src/transport/gnunet-transport-wlan-helper.c index 016aa29dd..25e55e510 100644 --- a/src/transport/gnunet-transport-wlan-helper.c +++ b/src/transport/gnunet-transport-wlan-helper.c @@ -1016,7 +1016,9 @@ getFrequencyFromChannel (int channel) 6050, 6055, 6060, 6065, 6070, 6075, 6080, 6085, 6090, 6095, 6100 }; - return ( (channel > 0) && (channel < sizeof(frequencies) / sizeof(int)) ) ? frequencies[channel] : -1; + return ((channel > 0) && + (channel < + sizeof (frequencies) / sizeof (int))) ? frequencies[channel] : -1; } /** diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c index 686423a3d..4d2912c34 100644 --- a/src/transport/gnunet-transport.c +++ b/src/transport/gnunet-transport.c @@ -162,15 +162,11 @@ display_test_result (struct TestContext *tc, int result) { if (GNUNET_YES != result) { - fprintf (stderr, - "Configuration for plugin `%s' did not work!\n", - tc->name); + fprintf (stderr, "Configuration for plugin `%s' did not work!\n", tc->name); } else { - fprintf (stderr, - "Configuration for plugin `%s' is working!\n", - tc->name); + fprintf (stderr, "Configuration for plugin `%s' is working!\n", tc->name); } if (GNUNET_SCHEDULER_NO_TASK != tc->tsk) { @@ -184,8 +180,7 @@ display_test_result (struct TestContext *tc, int result) } GNUNET_free (tc); resolver_users--; - if ( (0 == resolver_users) && - (NULL != resolver) ) + if ((0 == resolver_users) && (NULL != resolver)) { GNUNET_break (0 == GNUNET_OS_process_kill (resolver, SIGTERM)); GNUNET_OS_process_close (resolver); @@ -242,52 +237,46 @@ do_test_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg) struct TestContext *tc; if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string (cfg, - "transport", - "plugins", - &plugins)) + GNUNET_CONFIGURATION_get_value_string (cfg, "transport", "plugins", + &plugins)) { fprintf (stderr, - _("No transport plugins configured, peer will never communicate\n")); + _ + ("No transport plugins configured, peer will never communicate\n")); ret = 4; return; } for (tok = strtok (plugins, " "); tok != NULL; tok = strtok (NULL, " ")) - { - char section[12+strlen(tok)]; - - GNUNET_snprintf (section, - sizeof (section), - "transport-%s", - tok); + { + char section[12 + strlen (tok)]; + + GNUNET_snprintf (section, sizeof (section), "transport-%s", tok); if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (cfg, section, "PORT", - &bnd_port)) - { - fprintf (stderr, - _("No port configured for plugin `%s', cannot test it\n"), - tok); - continue; - } + GNUNET_CONFIGURATION_get_value_number (cfg, section, "PORT", &bnd_port)) + { + fprintf (stderr, + _("No port configured for plugin `%s', cannot test it\n"), tok); + continue; + } if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (cfg, section, - "ADVERTISED_PORT", &adv_port)) + GNUNET_CONFIGURATION_get_value_number (cfg, section, "ADVERTISED_PORT", + &adv_port)) adv_port = bnd_port; if (NULL == resolver) resolver = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-resolver", - "gnunet-service-resolver", NULL); + GNUNET_OS_start_process (NULL, NULL, "gnunet-service-resolver", + "gnunet-service-resolver", NULL); resolver_users++; GNUNET_RESOLVER_connect (cfg); tc = GNUNET_malloc (sizeof (struct TestContext)); tc->name = GNUNET_strdup (tok); tc->tst = - GNUNET_NAT_test_start (cfg, - (0 == strcasecmp (tok, "udp")) - ? GNUNET_NO - : GNUNET_YES, - (uint16_t) bnd_port, - (uint16_t) adv_port, &result_callback, tc); + GNUNET_NAT_test_start (cfg, + (0 == + strcasecmp (tok, + "udp")) ? GNUNET_NO : GNUNET_YES, + (uint16_t) bnd_port, (uint16_t) adv_port, + &result_callback, tc); if (NULL == tc->tst) { display_test_result (tc, GNUNET_SYSERR); @@ -303,8 +292,7 @@ do_test_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg) * Shutdown, print statistics. */ static void -do_disconnect (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +do_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_TIME_Relative duration; @@ -317,20 +305,16 @@ do_disconnect (void *cls, if (benchmark_receive) { duration = GNUNET_TIME_absolute_get_duration (start_time); - fprintf (stdout, - _("Received %llu bytes/s (%llu bytes in %llu ms)\n"), - 1000 * traffic_received / (1+duration.rel_value), - traffic_received, - (unsigned long long) duration.rel_value); + fprintf (stdout, _("Received %llu bytes/s (%llu bytes in %llu ms)\n"), + 1000 * traffic_received / (1 + duration.rel_value), + traffic_received, (unsigned long long) duration.rel_value); } if (benchmark_send) { duration = GNUNET_TIME_absolute_get_duration (start_time); - fprintf (stdout, - _("Transmitted %llu bytes/s (%llu bytes in %llu ms)\n"), - 1000 * traffic_sent / (1+duration.rel_value), - traffic_sent, - (unsigned long long) duration.rel_value); + fprintf (stdout, _("Transmitted %llu bytes/s (%llu bytes in %llu ms)\n"), + 1000 * traffic_sent / (1 + duration.rel_value), traffic_sent, + (unsigned long long) duration.rel_value); } } @@ -347,8 +331,7 @@ do_disconnect (void *cls, * @return number of bytes written to buf */ static size_t -transmit_data (void *cls, size_t size, - void *buf) +transmit_data (void *cls, size_t size, void *buf) { struct GNUNET_MessageHeader *m = buf; @@ -358,17 +341,12 @@ transmit_data (void *cls, size_t size, m->type = ntohs (GNUNET_MESSAGE_TYPE_DUMMY); memset (&m[1], 52, size - sizeof (struct GNUNET_MessageHeader)); traffic_sent += size; - th = GNUNET_TRANSPORT_notify_transmit_ready (handle, - &pid, - 32 * 1024, - 0, - GNUNET_TIME_UNIT_FOREVER_REL, - &transmit_data, NULL); + th = GNUNET_TRANSPORT_notify_transmit_ready (handle, &pid, 32 * 1024, 0, + GNUNET_TIME_UNIT_FOREVER_REL, + &transmit_data, NULL); if (verbosity > 0) - fprintf (stdout, - _("Transmitting %u bytes to %s\n"), - (unsigned int) size, - GNUNET_i2s (&pid)); + fprintf (stdout, _("Transmitting %u bytes to %s\n"), (unsigned int) size, + GNUNET_i2s (&pid)); return size; } @@ -383,39 +361,27 @@ transmit_data (void *cls, size_t size, * @param ats_count number of entries in ats (excluding 0-termination) */ static void -notify_connect (void *cls, - const struct GNUNET_PeerIdentity - * peer, - const struct - GNUNET_ATS_Information - * ats, uint32_t ats_count) +notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { if (verbosity > 0) - fprintf (stdout, - _("Connected to %s\n"), - GNUNET_i2s (peer)); - if (0 != memcmp (&pid, - peer, - sizeof (struct GNUNET_PeerIdentity))) + fprintf (stdout, _("Connected to %s\n"), GNUNET_i2s (peer)); + if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity))) return; ret = 0; - if (benchmark_send) + if (benchmark_send) { start_time = GNUNET_TIME_absolute_get (); - th = GNUNET_TRANSPORT_notify_transmit_ready (handle, - peer, - 32 * 1024, - 0, - GNUNET_TIME_UNIT_FOREVER_REL, - &transmit_data, NULL); + th = GNUNET_TRANSPORT_notify_transmit_ready (handle, peer, 32 * 1024, 0, + GNUNET_TIME_UNIT_FOREVER_REL, + &transmit_data, NULL); } else { /* all done, terminate instantly */ GNUNET_SCHEDULER_cancel (end); - end = GNUNET_SCHEDULER_add_now (&do_disconnect, - NULL); - } + end = GNUNET_SCHEDULER_add_now (&do_disconnect, NULL); + } } @@ -427,24 +393,17 @@ notify_connect (void *cls, * @param peer the peer that disconnected */ static void -notify_disconnect (void *cls, - const struct - GNUNET_PeerIdentity * peer) +notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) { if (verbosity > 0) - fprintf (stdout, - _("Disconnected from %s\n"), - GNUNET_i2s (peer)); - if ( (0 == memcmp (&pid, - peer, - sizeof (struct GNUNET_PeerIdentity))) && - (NULL != th) ) + fprintf (stdout, _("Disconnected from %s\n"), GNUNET_i2s (peer)); + if ((0 == memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity))) && + (NULL != th)) { GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); th = NULL; GNUNET_SCHEDULER_cancel (end); - end = GNUNET_SCHEDULER_add_now (&do_disconnect, - NULL); + end = GNUNET_SCHEDULER_add_now (&do_disconnect, NULL); } } @@ -456,26 +415,18 @@ notify_disconnect (void *cls, * @param peer (claimed) identity of the other peer * @param message the message * @param ats performance data - * @param ats_count number of entries in ats + * @param ats_count number of entries in ats */ static void -notify_receive (void *cls, - const struct - GNUNET_PeerIdentity * peer, - const struct - GNUNET_MessageHeader * - message, - const struct - GNUNET_ATS_Information - * ats, uint32_t ats_count) +notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_MessageHeader *message, + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { - if (! benchmark_receive) + if (!benchmark_receive) return; if (verbosity > 0) - fprintf (stdout, - _("Received %u bytes from %s\n"), - (unsigned int) ntohs (message->size), - GNUNET_i2s (peer)); + fprintf (stdout, _("Received %u bytes from %s\n"), + (unsigned int) ntohs (message->size), GNUNET_i2s (peer)); if (traffic_received == 0) start_time = GNUNET_TIME_absolute_get (); traffic_received += ntohs (message->size); @@ -494,11 +445,12 @@ process_address (void *cls, const struct GNUNET_PeerIdentity *peer, { if ((peer != NULL) || (transport != NULL) || ((addr != NULL) && (addrlen > 0))) - fprintf (stdout, - _("Peer `%s' plugin: `%s' address `%s'\n"), + fprintf (stdout, _("Peer `%s' plugin: `%s' address `%s'\n"), (peer != NULL) ? GNUNET_i2s (peer) : "", - (transport != NULL) ? transport : "", - ((addr != NULL) && (addrlen > 0) && (transport != NULL)) ? + (transport != NULL) ? transport : "", ((addr != NULL) && + (addrlen > 0) && + (transport != + NULL)) ? "how do i resolve the name without transport service?" : ""); } @@ -523,45 +475,41 @@ run (void *cls, char *const *args, const char *cfgfile, if (benchmark_send && (NULL == cpid)) { fprintf (stderr, _("Option `%s' makes no sense without option `%s'.\n"), - "-s", "-C"); + "-s", "-C"); return; } if (NULL != cpid) { ret = 1; - if (GNUNET_OK != - GNUNET_CRYPTO_hash_from_string (cpid, &pid.hashPubKey)) + if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (cpid, &pid.hashPubKey)) { - fprintf (stderr, - _("Failed to parse peer identity `%s'\n"), - cpid); + fprintf (stderr, _("Failed to parse peer identity `%s'\n"), cpid); return; } - handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, - ¬ify_receive, - ¬ify_connect, - ¬ify_disconnect); + handle = + GNUNET_TRANSPORT_connect (cfg, NULL, NULL, ¬ify_receive, + ¬ify_connect, ¬ify_disconnect); GNUNET_TRANSPORT_try_connect (handle, &pid); - end = GNUNET_SCHEDULER_add_delayed (benchmark_send - ? GNUNET_TIME_UNIT_FOREVER_REL - : GNUNET_TIME_UNIT_SECONDS, - &do_disconnect, - NULL); - } else if (benchmark_receive) + end = + GNUNET_SCHEDULER_add_delayed (benchmark_send ? + GNUNET_TIME_UNIT_FOREVER_REL : + GNUNET_TIME_UNIT_SECONDS, &do_disconnect, + NULL); + } + else if (benchmark_receive) { - handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, - ¬ify_receive, - ¬ify_connect, - ¬ify_disconnect); + handle = + GNUNET_TRANSPORT_connect (cfg, NULL, NULL, ¬ify_receive, + ¬ify_connect, ¬ify_disconnect); GNUNET_TRANSPORT_try_connect (handle, &pid); - end = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, - &do_disconnect, - NULL); + end = + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, + &do_disconnect, NULL); } if (iterate_connections) { GNUNET_TRANSPORT_address_iterate (cfg, GNUNET_TIME_UNIT_MINUTES, - &process_address, NULL); + &process_address, NULL); } } @@ -578,20 +526,22 @@ main (int argc, char *const *argv) 1, &GNUNET_GETOPT_set_string, &cpid}, {'i', "information", NULL, gettext_noop ("provide information about all current connections (once)"), - 0, &GNUNET_GETOPT_set_one, &iterate_connections}, + 0, &GNUNET_GETOPT_set_one, &iterate_connections}, {'s', "send", NULL, - gettext_noop ("send data for benchmarking to the other peer (until CTRL-C)"), - 0, &GNUNET_GETOPT_set_one, &benchmark_send}, + gettext_noop + ("send data for benchmarking to the other peer (until CTRL-C)"), + 0, &GNUNET_GETOPT_set_one, &benchmark_send}, {'t', "test", NULL, gettext_noop ("test transport configuration (involves external server)"), - 0, &GNUNET_GETOPT_set_one, &test_configuration}, - GNUNET_GETOPT_OPTION_VERBOSE(&verbosity), + 0, &GNUNET_GETOPT_set_one, &test_configuration}, + GNUNET_GETOPT_OPTION_VERBOSE (&verbosity), GNUNET_GETOPT_OPTION_END }; return (GNUNET_OK == GNUNET_PROGRAM_run (argc, argv, "gnunet-transport", - gettext_noop ("Direct access to transport service."), - options, &run, NULL)) ? ret : 1; + gettext_noop + ("Direct access to transport service."), options, + &run, NULL)) ? ret : 1; } diff --git a/src/transport/gnunet_wlan_sender.c b/src/transport/gnunet_wlan_sender.c index 3aa32fb1c..f1a90178b 100644 --- a/src/transport/gnunet_wlan_sender.c +++ b/src/transport/gnunet_wlan_sender.c @@ -78,13 +78,13 @@ struct ieee80211_frame * @return GNUNET_YES at success */ static int -getRadiotapHeader ( struct Radiotap_Send *header) +getRadiotapHeader (struct Radiotap_Send *header) { - header->rate = 255; - header->tx_power = 0; - header->antenna = 0; + header->rate = 255; + header->tx_power = 0; + header->antenna = 0; return GNUNET_YES; } @@ -98,9 +98,8 @@ getRadiotapHeader ( struct Radiotap_Send *header) * @return GNUNET_YES if there was no error */ static int -getWlanHeader (struct ieee80211_frame *Header, - const char *to_mac_addr, const char *mac, - unsigned int size) +getWlanHeader (struct ieee80211_frame *Header, const char *to_mac_addr, + const char *mac, unsigned int size) { uint16_t *tmp16; const int rate = 11000000; @@ -108,8 +107,7 @@ getWlanHeader (struct ieee80211_frame *Header, Header->i_fc[0] = IEEE80211_FC0_TYPE_DATA; Header->i_fc[1] = 0x00; memcpy (&Header->i_addr3, &mac_bssid, sizeof (mac_bssid)); - memcpy (&Header->i_addr2, mac, - sizeof (mac_bssid)); + memcpy (&Header->i_addr2, mac, sizeof (mac_bssid)); memcpy (&Header->i_addr1, to_mac_addr, sizeof (mac_bssid)); tmp16 = (uint16_t *) Header->i_dur; @@ -120,115 +118,133 @@ getWlanHeader (struct ieee80211_frame *Header, return GNUNET_YES; } -int main(int argc, char *argv[]){ +int +main (int argc, char *argv[]) +{ char msg_buf[WLAN_MTU]; - struct GNUNET_MessageHeader *msg; - struct ieee80211_frame *wlan_header; - struct Radiotap_Send *radiotap; - - unsigned int temp[6]; - char inmac[6]; - char outmac[6]; - int pos; - long long count; - double bytes_per_s; - time_t start; - time_t akt; - int i; - - if (4 != argc) { - fprintf( - stderr, - "This program must be started with the interface and the targets and source mac as argument.\nThis program was compiled at ----- %s ----\n", - __TIMESTAMP__); - fprintf(stderr, "Usage: interface-name mac-target mac-source\n" "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); - return 1; - } - if (6 != - sscanf(argv[3], "%x-%x-%x-%x-%x-%x", &temp[0],&temp[1],&temp[2],&temp[3],&temp[4],&temp[5])) - { - fprintf(stderr, "Usage: interface-name mac-target mac-source\n" "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); - return 1; - } - if (6 != - sscanf(argv[2], "%x-%x-%x-%x-%x-%x", &temp[0],&temp[1],&temp[2],&temp[3],&temp[4],&temp[5])) - { - fprintf(stderr, "Usage: interface-name mac-target mac-source\n" "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); - return 1; - } - for (i = 0; i < 6; i++) - { - inmac[i] = temp[i]; - } - for (i = 0; i < 6; i++) - { - outmac[i] = temp[i]; - } - - - pid_t pid; - int commpipe[2]; /* This holds the fd for the input & output of the pipe */ - - /* Setup communication pipeline first */ - if(pipe(commpipe)){ - fprintf(stderr,"Pipe error!\n"); - exit(1); - } - - /* Attempt to fork and check for errors */ - if( (pid=fork()) == -1){ - fprintf(stderr,"Fork error. Exiting.\n"); /* something went wrong */ - exit(1); - } - - if(pid){ - /* A positive (non-negative) PID indicates the parent process */ - close(commpipe[0]); /* Close unused side of pipe (in side) */ - setvbuf(stdout,(char*)NULL,_IONBF,0); /* Set non-buffered output on stdout */ - - - msg = (struct GNUNET_MessageHeader*) msg_buf; - msg->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); - msg->size = htons (WLAN_MTU); - radiotap = (struct Radiotap_Send *) &msg[1]; - wlan_header = (struct ieee80211_frame *) &radiotap[1]; - pos = 0; - - getRadiotapHeader(radiotap); - getWlanHeader(wlan_header, outmac, inmac, WLAN_MTU - sizeof(struct GNUNET_MessageHeader)); - - start = time(NULL); - count = 0; - while (1){ - pos += write(commpipe[1], msg, WLAN_MTU - pos); - if (pos % WLAN_MTU == 0){ - pos = 0; - count ++; - - if (count % 1000 == 0){ - akt = time(NULL); - bytes_per_s = count * WLAN_MTU / (akt - start); - bytes_per_s /= 1024; - printf("send %f kbytes/s\n", bytes_per_s); - } - } - - } - } - else{ - /* A zero PID indicates that this is the child process */ - (void) close(0); - if (-1 == dup2(commpipe[0],0)) /* Replace stdin with the in side of the pipe */ - fprintf (stderr, - "dup2 failed: %s\n", - strerror (errno)); - (void) close(commpipe[1]); /* Close unused side of pipe (out side) */ - /* Replace the child fork with a new process */ - if (execl("gnunet-transport-wlan-helper","gnunet-transport-wlan-helper", argv[1], NULL) == -1) - { - fprintf(stderr,"Could not start gnunet-transport-wlan-helper!"); - _exit(1); - } - } - return 0; + struct GNUNET_MessageHeader *msg; + struct ieee80211_frame *wlan_header; + struct Radiotap_Send *radiotap; + + unsigned int temp[6]; + char inmac[6]; + char outmac[6]; + int pos; + long long count; + double bytes_per_s; + time_t start; + time_t akt; + int i; + + if (4 != argc) + { + fprintf (stderr, + "This program must be started with the interface and the targets and source mac as argument.\nThis program was compiled at ----- %s ----\n", + __TIMESTAMP__); + fprintf (stderr, + "Usage: interface-name mac-target mac-source\n" + "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); + return 1; + } + if (6 != + sscanf (argv[3], "%x-%x-%x-%x-%x-%x", &temp[0], &temp[1], &temp[2], + &temp[3], &temp[4], &temp[5])) + { + fprintf (stderr, + "Usage: interface-name mac-target mac-source\n" + "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); + return 1; + } + if (6 != + sscanf (argv[2], "%x-%x-%x-%x-%x-%x", &temp[0], &temp[1], &temp[2], + &temp[3], &temp[4], &temp[5])) + { + fprintf (stderr, + "Usage: interface-name mac-target mac-source\n" + "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); + return 1; + } + for (i = 0; i < 6; i++) + { + inmac[i] = temp[i]; + } + for (i = 0; i < 6; i++) + { + outmac[i] = temp[i]; + } + + + pid_t pid; + int commpipe[2]; /* This holds the fd for the input & output of the pipe */ + + /* Setup communication pipeline first */ + if (pipe (commpipe)) + { + fprintf (stderr, "Pipe error!\n"); + exit (1); + } + + /* Attempt to fork and check for errors */ + if ((pid = fork ()) == -1) + { + fprintf (stderr, "Fork error. Exiting.\n"); /* something went wrong */ + exit (1); + } + + if (pid) + { + /* A positive (non-negative) PID indicates the parent process */ + close (commpipe[0]); /* Close unused side of pipe (in side) */ + setvbuf (stdout, (char *) NULL, _IONBF, 0); /* Set non-buffered output on stdout */ + + + msg = (struct GNUNET_MessageHeader *) msg_buf; + msg->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); + msg->size = htons (WLAN_MTU); + radiotap = (struct Radiotap_Send *) &msg[1]; + wlan_header = (struct ieee80211_frame *) &radiotap[1]; + pos = 0; + + getRadiotapHeader (radiotap); + getWlanHeader (wlan_header, outmac, inmac, + WLAN_MTU - sizeof (struct GNUNET_MessageHeader)); + + start = time (NULL); + count = 0; + while (1) + { + pos += write (commpipe[1], msg, WLAN_MTU - pos); + if (pos % WLAN_MTU == 0) + { + pos = 0; + count++; + + if (count % 1000 == 0) + { + akt = time (NULL); + bytes_per_s = count * WLAN_MTU / (akt - start); + bytes_per_s /= 1024; + printf ("send %f kbytes/s\n", bytes_per_s); + } + } + + } + } + else + { + /* A zero PID indicates that this is the child process */ + (void) close (0); + if (-1 == dup2 (commpipe[0], 0)) /* Replace stdin with the in side of the pipe */ + fprintf (stderr, "dup2 failed: %s\n", strerror (errno)); + (void) close (commpipe[1]); /* Close unused side of pipe (out side) */ + /* Replace the child fork with a new process */ + if (execl + ("gnunet-transport-wlan-helper", "gnunet-transport-wlan-helper", + argv[1], NULL) == -1) + { + fprintf (stderr, "Could not start gnunet-transport-wlan-helper!"); + _exit (1); + } + } + return 0; } diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index 784dd3002..9008b958d 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c @@ -155,18 +155,20 @@ http_plugin_address_pretty_printer (void *cls, const char *type, struct PrettyPrinterContext *ppc; const void *sb; size_t sbs; - uint16_t port = 0 ; + uint16_t port = 0; if (addrlen == sizeof (struct IPv6HttpAddress)) { - struct IPv6HttpAddress * a6 = (struct IPv6HttpAddress *) addr; + struct IPv6HttpAddress *a6 = (struct IPv6HttpAddress *) addr; + sb = &a6->ipv6_addr; sbs = sizeof (struct in6_addr); port = ntohs (a6->u6_port); } else if (addrlen == sizeof (struct IPv4HttpAddress)) { - struct IPv4HttpAddress * a4 = (struct IPv4HttpAddress *) addr; + struct IPv4HttpAddress *a4 = (struct IPv4HttpAddress *) addr; + sb = &a4->ipv4_addr; sbs = sizeof (struct in_addr); port = ntohs (a4->u4_port); @@ -218,9 +220,12 @@ http_plugin_address_suggested (void *cls, const void *addr, size_t addrlen) if (addrlen == sizeof (struct IPv4HttpAddress)) { struct IPv4HttpAddress *a4 = (struct IPv4HttpAddress *) addr; + while (w_tv4 != NULL) { - if ((0 == memcmp (&w_tv4->addr.ipv4_addr, &a4->ipv4_addr, sizeof (struct in_addr))) && + if ((0 == + memcmp (&w_tv4->addr.ipv4_addr, &a4->ipv4_addr, + sizeof (struct in_addr))) && (w_tv4->addr.u4_port == a4->u4_port)) break; w_tv4 = w_tv4->next; @@ -233,9 +238,12 @@ http_plugin_address_suggested (void *cls, const void *addr, size_t addrlen) if (addrlen == sizeof (struct sockaddr_in6)) { struct IPv6HttpAddress *a6 = (struct IPv6HttpAddress *) addr; + while (w_tv6 != NULL) { - if ((0 == memcmp (&w_tv6->addr6.ipv6_addr, &a6->ipv6_addr, sizeof (struct in6_addr))) && + if ((0 == + memcmp (&w_tv6->addr6.ipv6_addr, &a6->ipv6_addr, + sizeof (struct in6_addr))) && (w_tv6->addr6.u6_port == a6->u6_port)) break; w_tv6 = w_tv6->next; @@ -249,11 +257,10 @@ http_plugin_address_suggested (void *cls, const void *addr, size_t addrlen) } struct GNUNET_TIME_Relative -http_plugin_receive (void *cls, const struct GNUNET_PeerIdentity * peer, - const struct GNUNET_MessageHeader * message, - struct Session * session, - const char *sender_address, - uint16_t sender_address_len) +http_plugin_receive (void *cls, const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_MessageHeader *message, + struct Session *session, const char *sender_address, + uint16_t sender_address_len) { struct Session *s = cls; struct Plugin *plugin = s->plugin; @@ -263,7 +270,10 @@ http_plugin_receive (void *cls, const struct GNUNET_PeerIdentity * peer, distance.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); distance.value = htonl (1); - delay = plugin->env->receive (plugin->env->cls, &s->target, message, (const struct GNUNET_ATS_Information*) &distance, 1, s, s->addr, s->addrlen); + delay = + plugin->env->receive (plugin->env->cls, &s->target, message, + (const struct GNUNET_ATS_Information *) &distance, + 1, s, s->addr, s->addrlen); return delay; } @@ -293,14 +303,18 @@ http_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) { a6 = (struct IPv6HttpAddress *) addr; address = GNUNET_malloc (INET6_ADDRSTRLEN); - GNUNET_assert(NULL != inet_ntop (AF_INET6, &a6->ipv6_addr, address, INET6_ADDRSTRLEN)); + GNUNET_assert (NULL != + inet_ntop (AF_INET6, &a6->ipv6_addr, address, + INET6_ADDRSTRLEN)); port = ntohs (a6->u6_port); } else if (addrlen == sizeof (struct IPv4HttpAddress)) { a4 = (struct IPv4HttpAddress *) addr; address = GNUNET_malloc (INET_ADDRSTRLEN); - GNUNET_assert(NULL != inet_ntop (AF_INET, &(a4->ipv4_addr), address, INET_ADDRSTRLEN)); + GNUNET_assert (NULL != + inet_ntop (AF_INET, &(a4->ipv4_addr), address, + INET_ADDRSTRLEN)); port = ntohs (a4->u4_port); } else @@ -309,17 +323,21 @@ http_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) GNUNET_break (0); return NULL; } -#if !BUILD_HTTPS - char * protocol = "http"; +#if !BUILD_HTTPS + char *protocol = "http"; #else - char * protocol = "https"; + char *protocol = "https"; #endif GNUNET_assert (strlen (address) + 7 < (INET6_ADDRSTRLEN + 13)); if (addrlen == sizeof (struct IPv6HttpAddress)) - res = GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://[%s]:%u/", protocol, address, port); + res = + GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://[%s]:%u/", protocol, + address, port); else if (addrlen == sizeof (struct IPv4HttpAddress)) - res = GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://%s:%u/", protocol, address, port); + res = + GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://%s:%u/", protocol, address, + port); GNUNET_free (address); GNUNET_assert (res != 0); @@ -328,8 +346,8 @@ http_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) struct Session * lookup_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, - struct Session * session, - const void *addr, size_t addrlen, int force_address) + struct Session *session, const void *addr, size_t addrlen, + int force_address) { struct Session *s = NULL; struct Session *t = NULL; @@ -343,9 +361,15 @@ lookup_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, { #if 0 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, - "Comparing peer `%s' address `%s' len %i session %X to \n", GNUNET_i2s(target), GNUNET_a2s(addr,addrlen), addrlen, session); - GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,"peer `%s' address `%s' len %i session %X \n\n", GNUNET_i2s(&t->target), GNUNET_a2s(t->addr,t->addrlen), t->addrlen, t); - GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,"memcmp %i \n", memcmp (addr, t->addr, addrlen)); + "Comparing peer `%s' address `%s' len %i session %X to \n", + GNUNET_i2s (target), GNUNET_a2s (addr, addrlen), addrlen, + session); + GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, + "peer `%s' address `%s' len %i session %X \n\n", + GNUNET_i2s (&t->target), GNUNET_a2s (t->addr, t->addrlen), + t->addrlen, t); + GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, "memcmp %i \n", + memcmp (addr, t->addr, addrlen)); #endif e_peer = GNUNET_NO; e_addr = GNUNET_NO; @@ -362,13 +386,13 @@ lookup_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, } if ((t == session)) { - if(t->addrlen == session->addrlen) - { - if (0 == memcmp (session->addr, t->addr, t->addrlen)) + if (t->addrlen == session->addrlen) { - e_addr = GNUNET_YES; + if (0 == memcmp (session->addr, t->addr, t->addrlen)) + { + e_addr = GNUNET_YES; + } } - } } } @@ -377,7 +401,8 @@ lookup_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, s = t; break; } - if ((e_peer == GNUNET_YES) && (force_address == GNUNET_YES) && (e_addr == GNUNET_YES)) + if ((e_peer == GNUNET_YES) && (force_address == GNUNET_YES) && + (e_addr == GNUNET_YES)) { s = t; break; @@ -405,8 +430,8 @@ delete_session (struct Session *s) s->msg_tk = NULL; } GNUNET_free (s->addr); - GNUNET_free_non_null(s->server_recv); - GNUNET_free_non_null(s->server_send); + GNUNET_free_non_null (s->server_recv); + GNUNET_free_non_null (s->server_send); GNUNET_free (s); } @@ -416,7 +441,9 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) { struct Session *s = NULL; - GNUNET_assert ((addrlen == sizeof (struct IPv6HttpAddress)) || (addrlen == sizeof (struct IPv4HttpAddress))); + + GNUNET_assert ((addrlen == sizeof (struct IPv6HttpAddress)) || + (addrlen == sizeof (struct IPv4HttpAddress))); s = GNUNET_malloc (sizeof (struct Session)); memcpy (&s->target, target, sizeof (struct GNUNET_PeerIdentity)); s->plugin = plugin; @@ -424,14 +451,13 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, memcpy (s->addr, addr, addrlen); s->addrlen = addrlen; s->next = NULL; - s->next_receive = GNUNET_TIME_absolute_get_zero(); + s->next_receive = GNUNET_TIME_absolute_get_zero (); return s; } void -notify_session_end (void *cls, - const struct GNUNET_PeerIdentity * - peer, struct Session * s) +notify_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, + struct Session *s) { struct Plugin *plugin = cls; @@ -486,28 +512,38 @@ http_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, { struct Plugin *plugin = cls; struct HTTP_Message *msg; + GNUNET_assert (plugin != NULL); int res = GNUNET_SYSERR; #if DEBUG_HTTP GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Sending %u bytes to peer `%s' on address `%s' %X %i\n", msgbuf_size, - GNUNET_i2s (target), ((addr != NULL) && (addrlen != 0)) ? http_plugin_address_to_string(plugin, addr, addrlen) : "", session, force_address); + "Sending %u bytes to peer `%s' on address `%s' %X %i\n", + msgbuf_size, GNUNET_i2s (target), ((addr != NULL) && + (addrlen != + 0)) ? + http_plugin_address_to_string (plugin, addr, + addrlen) : "", + session, force_address); #endif struct Session *s = NULL; if (addrlen != 0) - GNUNET_assert ((addrlen == sizeof (struct IPv4HttpAddress)) || - (addrlen == sizeof (struct IPv6HttpAddress))); + GNUNET_assert ((addrlen == sizeof (struct IPv4HttpAddress)) || + (addrlen == sizeof (struct IPv6HttpAddress))); /* look for existing connection */ s = lookup_session (plugin, target, session, addr, addrlen, 1); #if DEBUG_HTTP GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "%s existing session: %s\n", (s!=NULL) ? "Found" : "NOT Found", ((s != NULL) && (s->inbound == GNUNET_YES)) ? "inbound" : "outbound"); + "%s existing session: %s\n", + (s != NULL) ? "Found" : "NOT Found", ((s != NULL) && + (s->inbound == + GNUNET_YES)) ? + "inbound" : "outbound"); #endif /* create new outbound connection */ @@ -517,8 +553,7 @@ http_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, { GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name, "Maximum number of connections reached, " - "cannot connect to peer `%s'\n", - GNUNET_i2s (target)); + "cannot connect to peer `%s'\n", GNUNET_i2s (target)); return res; } @@ -554,8 +589,8 @@ http_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, "Using outbound client session to send to `%s'\n", GNUNET_i2s (target)); #endif - client_send (s, msg); - res = msgbuf_size; + client_send (s, msg); + res = msgbuf_size; } if (s->inbound == GNUNET_YES) { @@ -621,14 +656,16 @@ nat_add_address (void *cls, int add_remove, const struct sockaddr *addr, case AF_INET: w_t4 = plugin->ipv4_addr_head; struct sockaddr_in *a4 = (struct sockaddr_in *) addr; + while (w_t4 != NULL) { int res = memcmp (&w_t4->addr.ipv4_addr, &a4->sin_addr, sizeof (struct in_addr)); + if (res == 0) { - if (a4->sin_port!= w_t4->addr.u4_port) + if (a4->sin_port != w_t4->addr.u4_port) res = -1; } @@ -639,8 +676,7 @@ nat_add_address (void *cls, int add_remove, const struct sockaddr *addr, if (w_t4 == NULL) { w_t4 = GNUNET_malloc (sizeof (struct IPv4HttpAddressWrapper)); - memcpy (&w_t4->addr.ipv4_addr, &a4->sin_addr, - sizeof (struct in_addr)); + memcpy (&w_t4->addr.ipv4_addr, &a4->sin_addr, sizeof (struct in_addr)); w_t4->addr.u4_port = a4->sin_port; GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head, @@ -649,18 +685,23 @@ nat_add_address (void *cls, int add_remove, const struct sockaddr *addr, #if DEBUG_HTTP GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Notifying transport to add IPv4 address `%s'\n", - http_plugin_address_to_string(NULL, &w_t4->addr, sizeof (struct IPv4HttpAddress))); + http_plugin_address_to_string (NULL, &w_t4->addr, + sizeof (struct + IPv4HttpAddress))); #endif - plugin->env->notify_address (plugin->env->cls, add_remove, &w_t4->addr, sizeof (struct IPv4HttpAddress)); + plugin->env->notify_address (plugin->env->cls, add_remove, &w_t4->addr, + sizeof (struct IPv4HttpAddress)); break; case AF_INET6: w_t6 = plugin->ipv6_addr_head; struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) addr; + while (w_t6) { int res = memcmp (&w_t6->addr6.ipv6_addr, &a6->sin6_addr, sizeof (struct in6_addr)); + if (res == 0) { if (a6->sin6_port != w_t6->addr6.u6_port) @@ -674,8 +715,7 @@ nat_add_address (void *cls, int add_remove, const struct sockaddr *addr, { w_t6 = GNUNET_malloc (sizeof (struct IPv6HttpAddressWrapper)); - memcpy (&w_t6->addr6.ipv6_addr, &a6->sin6_addr, - sizeof (struct in6_addr)); + memcpy (&w_t6->addr6.ipv6_addr, &a6->sin6_addr, sizeof (struct in6_addr)); w_t6->addr6.u6_port = a6->sin6_port; GNUNET_CONTAINER_DLL_insert (plugin->ipv6_addr_head, @@ -684,9 +724,12 @@ nat_add_address (void *cls, int add_remove, const struct sockaddr *addr, #if DEBUG_HTTP GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Notifying transport to add IPv6 address `%s'\n", - http_plugin_address_to_string(NULL, &w_t6->addr6, sizeof (struct IPv6HttpAddress))); + http_plugin_address_to_string (NULL, &w_t6->addr6, + sizeof (struct + IPv6HttpAddress))); #endif - plugin->env->notify_address (plugin->env->cls, add_remove, &w_t6->addr6, sizeof (struct IPv6HttpAddress)); + plugin->env->notify_address (plugin->env->cls, add_remove, &w_t6->addr6, + sizeof (struct IPv6HttpAddress)); break; default: return; @@ -709,14 +752,16 @@ nat_remove_address (void *cls, int add_remove, const struct sockaddr *addr, case AF_INET: w_t4 = plugin->ipv4_addr_head; struct sockaddr_in *a4 = (struct sockaddr_in *) addr; + while (w_t4 != NULL) { int res = memcmp (&w_t4->addr.ipv4_addr, &a4->sin_addr, sizeof (struct in_addr)); + if (res == 0) { - if (a4->sin_port!= w_t4->addr.u4_port) + if (a4->sin_port != w_t4->addr.u4_port) res = -1; } @@ -730,7 +775,9 @@ nat_remove_address (void *cls, int add_remove, const struct sockaddr *addr, #if DEBUG_HTTP GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Notifying transport to remove IPv4 address `%s'\n", - http_plugin_address_to_string(NULL, &w_t4->addr, sizeof (struct IPv4HttpAddress))); + http_plugin_address_to_string (NULL, &w_t4->addr, + sizeof (struct + IPv4HttpAddress))); #endif plugin->env->notify_address (plugin->env->cls, add_remove, &w_t4->addr, sizeof (struct IPv4HttpAddress)); @@ -742,10 +789,12 @@ nat_remove_address (void *cls, int add_remove, const struct sockaddr *addr, case AF_INET6: w_t6 = plugin->ipv6_addr_head; struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) addr; + while (w_t6) { int res = memcmp (&w_t6->addr6.ipv6_addr, &a6->sin6_addr, sizeof (struct in6_addr)); + if (res == 0) { if (a6->sin6_port != w_t6->addr6.u6_port) @@ -760,7 +809,9 @@ nat_remove_address (void *cls, int add_remove, const struct sockaddr *addr, #if DEBUG_HTTP GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Notifying transport to remove IPv6 address `%s'\n", - http_plugin_address_to_string(NULL, &w_t6->addr6, sizeof (struct IPv6HttpAddress))); + http_plugin_address_to_string (NULL, &w_t6->addr6, + sizeof (struct + IPv6HttpAddress))); #endif plugin->env->notify_address (plugin->env->cls, add_remove, &w_t6->addr6, sizeof (struct IPv6HttpAddress)); @@ -801,7 +852,7 @@ nat_port_map_callback (void *cls, int add_remove, const struct sockaddr *addr, switch (add_remove) { case GNUNET_YES: - nat_add_address (cls, add_remove, addr, addrlen); + nat_add_address (cls, add_remove, addr, addrlen); break; case GNUNET_NO: nat_remove_address (cls, add_remove, addr, addrlen); @@ -813,6 +864,7 @@ void http_check_ipv6 (struct Plugin *plugin) { struct GNUNET_NETWORK_Handle *desc = NULL; + if (plugin->ipv6 == GNUNET_YES) { /* probe IPv6 support */ @@ -825,8 +877,8 @@ http_check_ipv6 (struct Plugin *plugin) GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); } GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name, - _ - ("Disabling IPv6 since it is not supported on this system!\n")); + _ + ("Disabling IPv6 since it is not supported on this system!\n")); plugin->ipv6 = GNUNET_NO; } else @@ -835,17 +887,16 @@ http_check_ipv6 (struct Plugin *plugin) desc = NULL; } - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Testing IPv6 on this system: %s\n", (plugin->ipv6 == GNUNET_YES) ? "successful" : "failed"); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, + "Testing IPv6 on this system: %s\n", + (plugin->ipv6 == GNUNET_YES) ? "successful" : "failed"); } } int -http_get_addresses (struct Plugin *plugin, - const char *serviceName, - const struct GNUNET_CONFIGURATION_Handle - *cfg, struct sockaddr ***addrs, - socklen_t ** addr_lens) +http_get_addresses (struct Plugin *plugin, const char *serviceName, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct sockaddr ***addrs, socklen_t ** addr_lens) { int disablev6; unsigned long long port; @@ -892,8 +943,8 @@ http_get_addresses (struct Plugin *plugin, if (hostname != NULL) { GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Resolving `%s' since that is where `%s' will bind to.\n", - hostname, serviceName); + "Resolving `%s' since that is where `%s' will bind to.\n", + hostname, serviceName); memset (&hints, 0, sizeof (struct addrinfo)); if (disablev6) hints.ai_family = AF_INET; @@ -938,8 +989,8 @@ http_get_addresses (struct Plugin *plugin, if ((pos->ai_socktype != SOCK_STREAM) && (pos->ai_socktype != 0)) continue; /* huh? */ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Service will bind to `%s'\n", - GNUNET_a2s (pos->ai_addr, pos->ai_addrlen)); + "Service will bind to `%s'\n", GNUNET_a2s (pos->ai_addr, + pos->ai_addrlen)); if (pos->ai_family == AF_INET) { GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in)); @@ -1019,10 +1070,10 @@ start_report_addresses (struct Plugin *plugin) socklen_t *addrlens; res = - http_get_addresses (plugin, plugin->name, plugin->env->cfg, - &addrs, &addrlens); + http_get_addresses (plugin, plugin->name, plugin->env->cfg, &addrs, + &addrlens); GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - _("Found %u addresses to report to NAT service\n"),res); + _("Found %u addresses to report to NAT service\n"), res); if (res != GNUNET_SYSERR) { @@ -1030,14 +1081,12 @@ start_report_addresses (struct Plugin *plugin) GNUNET_NAT_register (plugin->env->cfg, GNUNET_YES, plugin->port, (unsigned int) res, (const struct sockaddr **) addrs, addrlens, - &nat_port_map_callback, NULL, - plugin); + &nat_port_map_callback, NULL, plugin); while (res > 0) { res--; #if 0 - GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, - _("FREEING %s\n"), + GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, _("FREEING %s\n"), GNUNET_a2s (addrs[res], addrlens[res])); #endif GNUNET_assert (addrs[res] != NULL); @@ -1136,24 +1185,28 @@ configure_plugin (struct Plugin *plugin) if (plugin->port == 0) { GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - _("Port 0, client only mode\n")); + _("Port 0, client only mode\n")); plugin->client_only = GNUNET_YES; } - char * bind4_address = NULL; - if ((plugin->ipv4 == GNUNET_YES) && (GNUNET_YES == - GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name, - "BINDTO", &bind4_address))) + char *bind4_address = NULL; + + if ((plugin->ipv4 == GNUNET_YES) && + (GNUNET_YES == + GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name, + "BINDTO", &bind4_address))) { GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Binding %s plugin to specific IPv4 address: `%s'\n", - plugin->protocol, bind4_address); + "Binding %s plugin to specific IPv4 address: `%s'\n", + plugin->protocol, bind4_address); plugin->server_addr_v4 = GNUNET_malloc (sizeof (struct sockaddr_in)); - if (1 != inet_pton (AF_INET, bind4_address, &plugin->server_addr_v4->sin_addr)) + if (1 != + inet_pton (AF_INET, bind4_address, &plugin->server_addr_v4->sin_addr)) { GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, - _("Specific IPv4 address `%s' for plugin %s in configuration file is invalid! Binding to all addresses!\n"), - bind4_address, plugin->protocol); + _ + ("Specific IPv4 address `%s' for plugin %s in configuration file is invalid! Binding to all addresses!\n"), + bind4_address, plugin->protocol); GNUNET_free (plugin->server_addr_v4); plugin->server_addr_v4 = NULL; } @@ -1166,20 +1219,24 @@ configure_plugin (struct Plugin *plugin) } - char * bind6_address = NULL; - if ((plugin->ipv6 == GNUNET_YES) && (GNUNET_YES == - GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name, - "BINDTO6", &bind6_address))) + char *bind6_address = NULL; + + if ((plugin->ipv6 == GNUNET_YES) && + (GNUNET_YES == + GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name, + "BINDTO6", &bind6_address))) { GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Binding %s plugin to specific IPv6 address: `%s'\n", - plugin->protocol, bind6_address); + "Binding %s plugin to specific IPv6 address: `%s'\n", + plugin->protocol, bind6_address); plugin->server_addr_v6 = GNUNET_malloc (sizeof (struct sockaddr_in6)); - if (1 != inet_pton (AF_INET6, bind6_address, &plugin->server_addr_v6->sin6_addr)) + if (1 != + inet_pton (AF_INET6, bind6_address, &plugin->server_addr_v6->sin6_addr)) { GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, - _("Specific IPv6 address `%s' for plugin %s in configuration file is invalid! Binding to all addresses!\n"), - bind6_address, plugin->protocol); + _ + ("Specific IPv6 address `%s' for plugin %s in configuration file is invalid! Binding to all addresses!\n"), + bind6_address, plugin->protocol); GNUNET_free (plugin->server_addr_v6); plugin->server_addr_v6 = NULL; } @@ -1194,6 +1251,7 @@ configure_plugin (struct Plugin *plugin) /* Optional parameters */ unsigned long long maxneigh; + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, plugin->name, "MAX_CONNECTIONS", &maxneigh)) @@ -1303,8 +1361,8 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) while (s != NULL) { #if DEBUG_HTTP - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Disconnecting `%s' \n", GNUNET_i2s (&s->target)); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, + "Disconnecting `%s' \n", GNUNET_i2s (&s->target)); #endif if (s->inbound == GNUNET_NO) GNUNET_assert (GNUNET_OK == client_disconnect (s)); @@ -1314,15 +1372,13 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) } #if DEBUG_HTTP - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Stopping server\n"); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Stopping server\n"); #endif /* Stop server */ server_stop (plugin); #if DEBUG_HTTP - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Stopping client\n"); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Stopping client\n"); #endif /* Stop client */ client_stop (plugin); @@ -1332,6 +1388,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) while (s != NULL) { struct Session *t = s->next; + GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s); delete_session (s); s = t; diff --git a/src/transport/plugin_transport_http.h b/src/transport/plugin_transport_http.h index dd0bc4b9d..7ace96cb6 100644 --- a/src/transport/plugin_transport_http.h +++ b/src/transport/plugin_transport_http.h @@ -228,12 +228,12 @@ struct Plugin /** * IPv4 server socket to bind to */ - struct sockaddr_in * server_addr_v4; + struct sockaddr_in *server_addr_v4; /** * IPv6 server socket to bind to */ - struct sockaddr_in6 * server_addr_v6; + struct sockaddr_in6 *server_addr_v6; /** * Server semi connections @@ -455,11 +455,10 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls); struct GNUNET_TIME_Relative -http_plugin_receive (void *cls, const struct GNUNET_PeerIdentity * peer, - const struct GNUNET_MessageHeader * message, - struct Session * session, - const char *sender_address, - uint16_t sender_address_len); +http_plugin_receive (void *cls, const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_MessageHeader *message, + struct Session *session, const char *sender_address, + uint16_t sender_address_len); const char * http_plugin_address_to_string (void *cls, const void *addr, size_t addrlen); @@ -483,7 +482,7 @@ int server_disconnect (struct Session *s); int -server_send (struct Session *s, struct HTTP_Message * msg); +server_send (struct Session *s, struct HTTP_Message *msg); int server_start (struct Plugin *plugin); @@ -492,8 +491,7 @@ void server_stop (struct Plugin *plugin); void -notify_session_end (void *cls, - const struct GNUNET_PeerIdentity * - peer, struct Session * s); +notify_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, + struct Session *s); /* end of plugin_transport_http.h */ diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index a2024953c..62be281ab 100644 --- a/src/transport/plugin_transport_http_client.c +++ b/src/transport/plugin_transport_http_client.c @@ -52,11 +52,11 @@ client_log (CURL * curl, curl_infotype type, char *data, size_t size, void *cls) text[size + 1] = '\0'; } #if BUILD_HTTPS - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, - "transport-https", "Client: %X - %s", cls, text); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-https", + "Client: %X - %s", cls, text); #else - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, - "transport-http", "Client: %X - %s", cls, text); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-http", + "Client: %X - %s", cls, text); #endif } return 0; @@ -91,7 +91,7 @@ client_schedule (struct Plugin *plugin, int now) struct GNUNET_TIME_Relative timeout; /* Cancel previous scheduled task */ - if (plugin->client_perform_task!= GNUNET_SCHEDULER_NO_TASK) + if (plugin->client_perform_task != GNUNET_SCHEDULER_NO_TASK) { GNUNET_SCHEDULER_cancel (plugin->client_perform_task); plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK; @@ -132,12 +132,8 @@ client_schedule (struct Plugin *plugin, int now) plugin->client_perform_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, - GNUNET_SCHEDULER_NO_TASK, - timeout, - grs, - gws, - &client_run, - plugin); + GNUNET_SCHEDULER_NO_TASK, timeout, grs, gws, + &client_run, plugin); GNUNET_NETWORK_fdset_destroy (gws); GNUNET_NETWORK_fdset_destroy (grs); return GNUNET_OK; @@ -153,10 +149,10 @@ client_send (struct Session *s, struct HTTP_Message *msg) { #if VERBOSE_CLIENT GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, - "Client: %X was suspended, unpausing\n", s->client_put); + "Client: %X was suspended, unpausing\n", s->client_put); #endif s->client_put_paused = GNUNET_NO; - curl_easy_pause(s->client_put, CURLPAUSE_CONT); + curl_easy_pause (s->client_put, CURLPAUSE_CONT); } client_schedule (s->plugin, GNUNET_YES); @@ -189,43 +185,45 @@ client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) running = 0; mret = curl_multi_perform (plugin->client_mh, &running); - CURLMsg * msg; + CURLMsg *msg; int msgs_left; - while ((msg = curl_multi_info_read(plugin->client_mh, &msgs_left))) + + while ((msg = curl_multi_info_read (plugin->client_mh, &msgs_left))) { - CURL *easy_h = msg->easy_handle; - struct Session *s = NULL; - char * d = (char *) s; - - - //GNUNET_assert (easy_h != NULL); - if (easy_h == NULL) - { - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Client: connection to ended with reason %i: `%s', %i handles running\n", - msg->data.result, - curl_easy_strerror(msg->data.result), - running); - continue; - } - - GNUNET_assert (CURLE_OK == curl_easy_getinfo(easy_h, CURLINFO_PRIVATE, &d)); - s = (struct Session *) d; - GNUNET_assert (s != NULL); - - if (msg->msg == CURLMSG_DONE) - { - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Client: %X connection to '%s' %s ended with reason %i: `%s'\n", - msg->easy_handle, GNUNET_i2s(&s->target), - http_plugin_address_to_string (NULL, s->addr, s->addrlen), - msg->data.result, - curl_easy_strerror(msg->data.result)); - - client_disconnect(s); - //GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,"Notifying about ended session to peer `%s' `%s'\n", GNUNET_i2s (&s->target), http_plugin_address_to_string (plugin, s->addr, s->addrlen)); - notify_session_end (plugin, &s->target, s); - } + CURL *easy_h = msg->easy_handle; + struct Session *s = NULL; + char *d = (char *) s; + + + //GNUNET_assert (easy_h != NULL); + if (easy_h == NULL) + { + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, + "Client: connection to ended with reason %i: `%s', %i handles running\n", + msg->data.result, + curl_easy_strerror (msg->data.result), running); + continue; + } + + GNUNET_assert (CURLE_OK == + curl_easy_getinfo (easy_h, CURLINFO_PRIVATE, &d)); + s = (struct Session *) d; + GNUNET_assert (s != NULL); + + if (msg->msg == CURLMSG_DONE) + { + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, + "Client: %X connection to '%s' %s ended with reason %i: `%s'\n", + msg->easy_handle, GNUNET_i2s (&s->target), + http_plugin_address_to_string (NULL, s->addr, + s->addrlen), + msg->data.result, + curl_easy_strerror (msg->data.result)); + + client_disconnect (s); + //GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,"Notifying about ended session to peer `%s' `%s'\n", GNUNET_i2s (&s->target), http_plugin_address_to_string (plugin, s->addr, s->addrlen)); + notify_session_end (plugin, &s->target, s); + } } } while (mret == CURLM_CALL_MULTI_PERFORM); @@ -238,18 +236,17 @@ client_disconnect (struct Session *s) int res = GNUNET_OK; CURLMcode mret; struct Plugin *plugin = s->plugin; - struct HTTP_Message * msg; - struct HTTP_Message * t; + struct HTTP_Message *msg; + struct HTTP_Message *t; if (s->client_put != NULL) { #if DEBUG_HTTP - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Client: %X Deleting outbound PUT session to peer `%s'\n", - s->client_put, - GNUNET_i2s (&s->target)); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, + "Client: %X Deleting outbound PUT session to peer `%s'\n", + s->client_put, GNUNET_i2s (&s->target)); #endif mret = curl_multi_remove_handle (plugin->client_mh, s->client_put); @@ -266,17 +263,16 @@ client_disconnect (struct Session *s) if (s->recv_wakeup_task != GNUNET_SCHEDULER_NO_TASK) { - GNUNET_SCHEDULER_cancel (s->recv_wakeup_task); - s->recv_wakeup_task = GNUNET_SCHEDULER_NO_TASK; + GNUNET_SCHEDULER_cancel (s->recv_wakeup_task); + s->recv_wakeup_task = GNUNET_SCHEDULER_NO_TASK; } if (s->client_get != NULL) { #if DEBUG_HTTP - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Client: %X Deleting outbound GET session to peer `%s'\n", - s->client_get, - GNUNET_i2s (&s->target)); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, + "Client: %X Deleting outbound GET session to peer `%s'\n", + s->client_get, GNUNET_i2s (&s->target)); #endif mret = curl_multi_remove_handle (plugin->client_mh, s->client_get); @@ -296,7 +292,7 @@ client_disconnect (struct Session *s) t = msg->next; if (NULL != msg->transmit_cont) msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_SYSERR); - GNUNET_CONTAINER_DLL_remove(s->msg_head, s->msg_tail, msg); + GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg); GNUNET_free (msg); msg = t; } @@ -316,24 +312,28 @@ client_disconnect (struct Session *s) static void client_receive_mst_cb (void *cls, void *client, - const struct GNUNET_MessageHeader *message) + const struct GNUNET_MessageHeader *message) { struct Session *s = cls; struct GNUNET_TIME_Relative delay; delay = http_plugin_receive (s, &s->target, message, s, s->addr, s->addrlen); - s->next_receive = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), delay); + s->next_receive = + GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), delay); - if (GNUNET_TIME_absolute_get().abs_value < s->next_receive.abs_value) + if (GNUNET_TIME_absolute_get ().abs_value < s->next_receive.abs_value) { #if VERBOSE_CLIENT struct Plugin *plugin = s->plugin; + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Client: peer `%s' address `%s' next read delayed for %llu ms\n", - GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen), delay); + "Client: peer `%s' address `%s' next read delayed for %llu ms\n", + GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen), + delay); #endif } } + static void client_wake_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { @@ -345,11 +345,10 @@ client_wake_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) return; GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, - "Client: %X Waking up receive handle\n", - s->client_get); + "Client: %X Waking up receive handle\n", s->client_get); if (s->client_get != NULL) - curl_easy_pause(s->client_get, CURLPAUSE_CONT); + curl_easy_pause (s->client_get, CURLPAUSE_CONT); } @@ -372,37 +371,38 @@ client_receive (void *stream, size_t size, size_t nmemb, void *cls) #if VERBOSE_CLIENT struct Plugin *plugin = s->plugin; + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Client: Received %Zu bytes from peer `%s'\n", - len, + "Client: Received %Zu bytes from peer `%s'\n", len, GNUNET_i2s (&s->target)); #endif - now = GNUNET_TIME_absolute_get(); + now = GNUNET_TIME_absolute_get (); if (now.abs_value < s->next_receive.abs_value) { - struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); - struct GNUNET_TIME_Relative delta = GNUNET_TIME_absolute_get_difference(now, s->next_receive); + struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); + struct GNUNET_TIME_Relative delta = + GNUNET_TIME_absolute_get_difference (now, s->next_receive); #if DEBUG_CLIENT GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Client: %X No inbound bandwidth available! Next read was delayed for %llu ms\n", - s->client_get, delta.rel_value); + "Client: %X No inbound bandwidth available! Next read was delayed for %llu ms\n", + s->client_get, delta.rel_value); #endif if (s->recv_wakeup_task != GNUNET_SCHEDULER_NO_TASK) { GNUNET_SCHEDULER_cancel (s->recv_wakeup_task); s->recv_wakeup_task = GNUNET_SCHEDULER_NO_TASK; } - s->recv_wakeup_task = GNUNET_SCHEDULER_add_delayed (delta, &client_wake_up, s); + s->recv_wakeup_task = + GNUNET_SCHEDULER_add_delayed (delta, &client_wake_up, s); return CURLPAUSE_ALL; } if (s->msg_tk == NULL) - s->msg_tk = GNUNET_SERVER_mst_create (&client_receive_mst_cb, s); + s->msg_tk = GNUNET_SERVER_mst_create (&client_receive_mst_cb, s); - GNUNET_SERVER_mst_receive (s->msg_tk, s, stream, len, GNUNET_NO, - GNUNET_NO); + GNUNET_SERVER_mst_receive (s->msg_tk, s, stream, len, GNUNET_NO, GNUNET_NO); return len; } @@ -420,6 +420,7 @@ static size_t client_send_cb (void *stream, size_t size, size_t nmemb, void *cls) { struct Session *s = cls; + #if VERBOSE_CLIENT struct Plugin *plugin = s->plugin; #endif @@ -432,7 +433,8 @@ client_send_cb (void *stream, size_t size, size_t nmemb, void *cls) { #if VERBOSE_CLIENT GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Client: %X Nothing to send! Suspending PUT handle!\n", s->client_put); + "Client: %X Nothing to send! Suspending PUT handle!\n", + s->client_put); #endif s->client_put_paused = GNUNET_YES; return CURL_READFUNC_PAUSE; @@ -469,13 +471,13 @@ client_send_cb (void *stream, size_t size, size_t nmemb, void *cls) { #if VERBOSE_CLIENT GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Client: %X Message with %u bytes sent, removing message from queue\n", - s->client_put, msg->size, msg->pos); + "Client: %X Message with %u bytes sent, removing message from queue\n", + s->client_put, msg->size, msg->pos); #endif /* Calling transmit continuation */ if (NULL != msg->transmit_cont) msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK); - GNUNET_CONTAINER_DLL_remove(s->msg_head, s->msg_tail, msg); + GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg); GNUNET_free (msg); } return bytes_sent; @@ -500,12 +502,11 @@ client_connect (struct Session *s) plugin->last_tag++; /* create url */ GNUNET_asprintf (&url, "%s%s;%u", - http_plugin_address_to_string (plugin, s->addr, s->addrlen), - GNUNET_h2s_full (&plugin->env->my_identity->hashPubKey),plugin->last_tag); + http_plugin_address_to_string (plugin, s->addr, s->addrlen), + GNUNET_h2s_full (&plugin->env->my_identity->hashPubKey), + plugin->last_tag); #if 0 - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "URL `%s'\n", - url); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "URL `%s'\n", url); #endif /* create get connection */ s->client_get = curl_easy_init (); @@ -592,7 +593,7 @@ client_connect (struct Session *s) plugin->cur_connections += 2; /* Re-schedule since handles have changed */ - if (plugin->client_perform_task!= GNUNET_SCHEDULER_NO_TASK) + if (plugin->client_perform_task != GNUNET_SCHEDULER_NO_TASK) { GNUNET_SCHEDULER_cancel (plugin->client_perform_task); plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK; diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c index e5b20cfb4..48c8739d5 100644 --- a/src/transport/plugin_transport_http_server.c +++ b/src/transport/plugin_transport_http_server.c @@ -39,7 +39,7 @@ struct ServerConnection int disconnect; struct Session *session; - struct MHD_Connection * mhd_conn; + struct MHD_Connection *mhd_conn; }; /** @@ -50,7 +50,8 @@ struct ServerConnection * @return gnunet task identifier */ static GNUNET_SCHEDULER_TaskIdentifier -server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle, int now); +server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle, + int now); static void server_log (void *arg, const char *fmt, va_list ap) @@ -74,13 +75,14 @@ server_log (void *arg, const char *fmt, va_list ap) static int server_accept_cb (void *cls, const struct sockaddr *addr, socklen_t addr_len) { - struct Plugin * plugin = cls; + struct Plugin *plugin = cls; if (plugin->cur_connections <= plugin->max_connections) return MHD_YES; else { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Server: Cannot accept new connections\n"); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Server: Cannot accept new connections\n"); return MHD_NO; } } @@ -131,8 +133,11 @@ server_load_certificate (struct Plugin *plugin) /* Get crypto init string from config * If not present just use default values */ - GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name, - "CRYPTO_INIT", &plugin->crypto_init)); + GNUNET_assert (GNUNET_OK == + GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, + plugin->name, + "CRYPTO_INIT", + &plugin->crypto_init)); if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (plugin->env->cfg, plugin->name, @@ -145,7 +150,7 @@ server_load_certificate (struct Plugin *plugin) GNUNET_CONFIGURATION_get_value_filename (plugin->env->cfg, plugin->name, "CERT_FILE", &cert_file)) { - GNUNET_asprintf(&cert_file, "%s", "https_cert.crt"); + GNUNET_asprintf (&cert_file, "%s", "https_cert.crt"); } /* read key & certificates from file */ @@ -244,7 +249,7 @@ server_reschedule (struct Plugin *plugin, int now) { if (plugin->server_v4_task != GNUNET_SCHEDULER_NO_TASK) { - GNUNET_SCHEDULER_cancel(plugin->server_v4_task); + GNUNET_SCHEDULER_cancel (plugin->server_v4_task); plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK; } plugin->server_v4_task = server_schedule (plugin, plugin->server_v4, now); @@ -252,12 +257,12 @@ server_reschedule (struct Plugin *plugin, int now) if (plugin->server_v6 != NULL) { - if (plugin->server_v6_task != GNUNET_SCHEDULER_NO_TASK) - { - GNUNET_SCHEDULER_cancel(plugin->server_v6_task); - plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK; - } - plugin->server_v6_task = server_schedule (plugin, plugin->server_v6, now); + if (plugin->server_v6_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel (plugin->server_v6_task); + plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK; + } + plugin->server_v6_task = server_schedule (plugin, plugin->server_v6, now); } } @@ -269,9 +274,10 @@ server_reschedule (struct Plugin *plugin, int now) */ static void server_receive_mst_cb (void *cls, void *client, - const struct GNUNET_MessageHeader *message) + const struct GNUNET_MessageHeader *message) { struct Session *s = cls; + #if VERBOSE_SERVER struct Plugin *plugin = s->plugin; #endif @@ -279,13 +285,16 @@ server_receive_mst_cb (void *cls, void *client, delay = http_plugin_receive (s, &s->target, message, s, s->addr, s->addrlen); - s->next_receive = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), delay); + s->next_receive = + GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), delay); if (delay.rel_value > 0) { #if VERBOSE_CLIENT - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Server: peer `%s' address `%s' next read delayed for %llu ms\n", - GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen), delay); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, + "Server: peer `%s' address `%s' next read delayed for %llu ms\n", + GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen), + delay); #endif } } @@ -305,6 +314,7 @@ server_send_callback (void *cls, uint64_t pos, char *buf, size_t max) struct HTTP_Message *msg; int bytes_read = 0; + //static int c = 0; msg = s->msg_head; if (msg != NULL) @@ -328,54 +338,58 @@ server_send_callback (void *cls, uint64_t pos, char *buf, size_t max) { if (NULL != msg->transmit_cont) msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK); - GNUNET_CONTAINER_DLL_remove(s->msg_head, s->msg_tail, msg); + GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg); GNUNET_free (msg); } } #if VERBOSE_CLIENT struct Plugin *plugin = s->plugin; + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Server: %X: sent %u bytes\n", - s, bytes_read); + "Server: %X: sent %u bytes\n", s, bytes_read); #endif return bytes_read; } static struct ServerConnection * server_lookup_session (struct Plugin *plugin, - struct MHD_Connection *mhd_connection, - const char * url, - const char *method) + struct MHD_Connection *mhd_connection, const char *url, + const char *method) { struct Session *s = NULL; - struct Session * t; + struct Session *t; struct ServerConnection *sc = NULL; const union MHD_ConnectionInfo *conn_info; struct IPv4HttpAddress a4; struct IPv6HttpAddress a6; - struct sockaddr_in * s4; - struct sockaddr_in6 * s6; - void * a; + struct sockaddr_in *s4; + struct sockaddr_in6 *s6; + void *a; size_t a_len; struct GNUNET_PeerIdentity target; int check = GNUNET_NO; uint32_t tag = 0; int direction; - conn_info = MHD_get_connection_info (mhd_connection, MHD_CONNECTION_INFO_CLIENT_ADDRESS); - if ((conn_info->client_addr->sa_family != AF_INET) && (conn_info->client_addr->sa_family != AF_INET6)) + conn_info = + MHD_get_connection_info (mhd_connection, + MHD_CONNECTION_INFO_CLIENT_ADDRESS); + if ((conn_info->client_addr->sa_family != AF_INET) && + (conn_info->client_addr->sa_family != AF_INET6)) return MHD_NO; - if ((strlen(&url[1]) >= 105) && (url[104] == ';')) + if ((strlen (&url[1]) >= 105) && (url[104] == ';')) { char hash[104]; - char * tagc = (char *) &url[105]; - memcpy(&hash, &url[1], 103); - hash [103] = '\0'; - if (GNUNET_OK == GNUNET_CRYPTO_hash_from_string ((const char *) &hash, - &(target.hashPubKey))) + char *tagc = (char *) &url[105]; + + memcpy (&hash, &url[1], 103); + hash[103] = '\0'; + if (GNUNET_OK == + GNUNET_CRYPTO_hash_from_string ((const char *) &hash, + &(target.hashPubKey))) { tag = strtoul (tagc, NULL, 10); if (tagc > 0) @@ -395,7 +409,8 @@ server_lookup_session (struct Plugin *plugin, #if VERBOSE_SERVER GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Server: New inbound connection from %s with tag %u\n", GNUNET_i2s(&target), tag); + "Server: New inbound connection from %s with tag %u\n", + GNUNET_i2s (&target), tag); #endif /* find duplicate session */ @@ -403,17 +418,20 @@ server_lookup_session (struct Plugin *plugin, while (t != NULL) { - if ((t->inbound) && (0 == memcmp (&t->target, &target, sizeof (struct GNUNET_PeerIdentity))) && + if ((t->inbound) && + (0 == memcmp (&t->target, &target, sizeof (struct GNUNET_PeerIdentity))) + && /* FIXME add source address comparison */ (t->tag == tag)) - break; + break; t = t->next; } if (t != NULL) { #if VERBOSE_SERVER GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Server: Duplicate session, dismissing new connection from peer `%s'\n", GNUNET_i2s (&target)); + "Server: Duplicate session, dismissing new connection from peer `%s'\n", + GNUNET_i2s (&target)); #endif goto error; } @@ -424,8 +442,8 @@ server_lookup_session (struct Plugin *plugin, while (t != NULL) { /* FIXME add source address comparison */ - if ((0 == memcmp (&t->target, &target, sizeof (struct GNUNET_PeerIdentity))) && - (t->tag == tag)) + if ((0 == memcmp (&t->target, &target, sizeof (struct GNUNET_PeerIdentity))) + && (t->tag == tag)) { break; } @@ -437,25 +455,29 @@ server_lookup_session (struct Plugin *plugin, #if VERBOSE_SERVER GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Server: Found existing semi-session for `%s'\n", GNUNET_i2s (&target)); + "Server: Found existing semi-session for `%s'\n", + GNUNET_i2s (&target)); #endif if ((direction == _SEND) && (t->server_send != NULL)) { #if VERBOSE_SERVER GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Server: Duplicate GET session, dismissing new connection from peer `%s'\n", GNUNET_i2s (&target)); + "Server: Duplicate GET session, dismissing new connection from peer `%s'\n", + GNUNET_i2s (&target)); #endif goto error; } else { s = t; - GNUNET_CONTAINER_DLL_remove(plugin->server_semi_head, plugin->server_semi_tail, s); - GNUNET_CONTAINER_DLL_insert(plugin->head, plugin->tail, s); + GNUNET_CONTAINER_DLL_remove (plugin->server_semi_head, + plugin->server_semi_tail, s); + GNUNET_CONTAINER_DLL_insert (plugin->head, plugin->tail, s); #if VERBOSE_SERVER GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Server: Found matching semi-session, merging session for peer `%s'\n", GNUNET_i2s (&target)); + "Server: Found matching semi-session, merging session for peer `%s'\n", + GNUNET_i2s (&target)); #endif goto found; @@ -464,18 +486,21 @@ server_lookup_session (struct Plugin *plugin, { #if VERBOSE_SERVER GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Server: Duplicate PUT session, dismissing new connection from peer `%s'\n", GNUNET_i2s (&target)); + "Server: Duplicate PUT session, dismissing new connection from peer `%s'\n", + GNUNET_i2s (&target)); #endif goto error; } else { s = t; - GNUNET_CONTAINER_DLL_remove(plugin->server_semi_head, plugin->server_semi_tail, s); - GNUNET_CONTAINER_DLL_insert(plugin->head, plugin->tail, s); + GNUNET_CONTAINER_DLL_remove (plugin->server_semi_head, + plugin->server_semi_tail, s); + GNUNET_CONTAINER_DLL_insert (plugin->head, plugin->tail, s); #if VERBOSE_SERVER GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Server: Found matching semi-session, merging session for peer `%s'\n", GNUNET_i2s (&target)); + "Server: Found matching semi-session, merging session for peer `%s'\n", + GNUNET_i2s (&target)); #endif goto found; } @@ -484,53 +509,48 @@ create: /* create new session */ #if VERBOSE_SERVER GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Server: Creating new session for peer `%s' \n", GNUNET_i2s (&target)); + "Server: Creating new session for peer `%s' \n", + GNUNET_i2s (&target)); #endif switch (conn_info->client_addr->sa_family) { case (AF_INET): - s4 = ((struct sockaddr_in * ) conn_info->client_addr); - a4.u4_port = s4->sin_port; - memcpy (&a4.ipv4_addr, &s4->sin_addr, - sizeof (struct in_addr)); - a = &a4; - a_len = sizeof (struct IPv4HttpAddress); - break; + s4 = ((struct sockaddr_in *) conn_info->client_addr); + a4.u4_port = s4->sin_port; + memcpy (&a4.ipv4_addr, &s4->sin_addr, sizeof (struct in_addr)); + a = &a4; + a_len = sizeof (struct IPv4HttpAddress); + break; case (AF_INET6): - s6 = ((struct sockaddr_in6 * ) conn_info->client_addr); - a6.u6_port = s6->sin6_port; - memcpy (&a6.ipv6_addr, &s6->sin6_addr, - sizeof (struct in6_addr)); - a = &a6; - a_len = sizeof (struct IPv6HttpAddress); - break; + s6 = ((struct sockaddr_in6 *) conn_info->client_addr); + a6.u6_port = s6->sin6_port; + memcpy (&a6.ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr)); + a = &a6; + a_len = sizeof (struct IPv6HttpAddress); + break; default: GNUNET_break (0); goto error; } - s = create_session (plugin, - &target, - a, - a_len, - NULL, - NULL); + s = create_session (plugin, &target, a, a_len, NULL, NULL); s->inbound = GNUNET_YES; - s->next_receive = GNUNET_TIME_absolute_get_zero(); - s->tag= tag; + s->next_receive = GNUNET_TIME_absolute_get_zero (); + s->tag = tag; if (0 == strcmp (MHD_HTTP_METHOD_PUT, method)) s->server_recv = s; if (0 == strcmp (MHD_HTTP_METHOD_GET, method)) s->server_send = s; - GNUNET_CONTAINER_DLL_insert (plugin->server_semi_head, plugin->server_semi_tail, s); + GNUNET_CONTAINER_DLL_insert (plugin->server_semi_head, + plugin->server_semi_tail, s); goto found; error: #if VERBOSE_SERVER GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Server: Invalid connection request\n"); + "Server: Invalid connection request\n"); #endif return NULL; @@ -546,6 +566,7 @@ found: #if MHD_VERSION >= 0x00090E00 int to = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value / 1000); + #if VERBOSE_SERVER GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Server: Setting timeout for %X to %u sec.\n", sc, to); @@ -581,12 +602,14 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, /* new connection */ if (sc == NULL) { - sc = server_lookup_session(plugin, mhd_connection, url, method); + sc = server_lookup_session (plugin, mhd_connection, url, method); if (sc != NULL) (*httpSessionCache) = sc; else { - response = MHD_create_response_from_data (strlen (HTTP_ERROR_RESPONSE),HTTP_ERROR_RESPONSE, MHD_NO, MHD_NO); + response = + MHD_create_response_from_data (strlen (HTTP_ERROR_RESPONSE), + HTTP_ERROR_RESPONSE, MHD_NO, MHD_NO); res = MHD_queue_response (mhd_connection, MHD_HTTP_NOT_FOUND, response); MHD_destroy_response (response); return res; @@ -597,10 +620,12 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, sc = (*httpSessionCache); s = sc->session; - /* connection is to be disconnected*/ + /* connection is to be disconnected */ if (sc->disconnect == GNUNET_YES) { - response = MHD_create_response_from_data (strlen ("Thank you!"), "Thank you!", MHD_NO, MHD_NO); + response = + MHD_create_response_from_data (strlen ("Thank you!"), "Thank you!", + MHD_NO, MHD_NO); res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response); #if VERBOSE_SERVER GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -613,7 +638,8 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, GNUNET_assert (s != NULL); if (sc->direction == _SEND) { - response = MHD_create_response_from_callback (-1, 32 * 1024, &server_send_callback, + response = + MHD_create_response_from_callback (-1, 32 * 1024, &server_send_callback, s, NULL); res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response); MHD_destroy_response (response); @@ -624,9 +650,10 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, if (*upload_data_size == 0) { #if VERBOSE_SERVER - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Server: Peer `%s' PUT on address `%s' connected\n", - GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen)); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, + "Server: Peer `%s' PUT on address `%s' connected\n", + GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, + s->addrlen)); #endif return MHD_YES; } @@ -635,23 +662,28 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, if ((*upload_data_size > 0)) { #if VERBOSE_SERVER - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Server: peer `%s' PUT on address `%s' received %Zu bytes\n", - GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen), *upload_data_size); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, + "Server: peer `%s' PUT on address `%s' received %Zu bytes\n", + GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, + s->addrlen), + *upload_data_size); #endif - struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); - if (( s->next_receive.abs_value <= now.abs_value)) + struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); + + if ((s->next_receive.abs_value <= now.abs_value)) { #if VERBOSE_SERVER GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Server: %X: PUT with %u bytes forwarded to MST\n", s, - *upload_data_size); + "Server: %X: PUT with %u bytes forwarded to MST\n", s, + *upload_data_size); #endif if (s->msg_tk == NULL) { s->msg_tk = GNUNET_SERVER_mst_create (&server_receive_mst_cb, s); } - res = GNUNET_SERVER_mst_receive (s->msg_tk, s, upload_data, *upload_data_size, GNUNET_NO, GNUNET_NO); + res = + GNUNET_SERVER_mst_receive (s->msg_tk, s, upload_data, + *upload_data_size, GNUNET_NO, GNUNET_NO); #if MHD_VERSION >= 0x00090E00 int to = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value / 1000); @@ -668,18 +700,22 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, t = s->server_recv; #if VERBOSE_SERVER GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Server: Setting timeout for %X to %u sec.\n", t, to); + "Server: Setting timeout for %X to %u sec.\n", t, + to); #endif - MHD_set_connection_option (t->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, to); + MHD_set_connection_option (t->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, + to); } if (s->server_send != NULL) { t = s->server_send; #if VERBOSE_SERVER GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Server: Setting timeout for %X to %u sec.\n", t, to); + "Server: Setting timeout for %X to %u sec.\n", t, + to); #endif - MHD_set_connection_option (t->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, to); + MHD_set_connection_option (t->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, + to); } server_reschedule (plugin, GNUNET_NO); #endif @@ -688,8 +724,9 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, else { #if DEBUG_HTTP - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Server: %X no inbound bandwidth available! Next read was delayed by %llu ms\n", s, now.abs_value - s->next_receive.abs_value); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Server: %X no inbound bandwidth available! Next read was delayed by %llu ms\n", + s, now.abs_value - s->next_receive.abs_value); #endif } return MHD_YES; @@ -706,22 +743,22 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, { struct ServerConnection *sc = *httpSessionCache; struct ServerConnection *tc = *httpSessionCache; - struct Session * s = NULL; - struct Session * t = NULL; - struct Plugin * plugin = NULL; + struct Session *s = NULL; + struct Session *t = NULL; + struct Plugin *plugin = NULL; if (sc == NULL) return; s = sc->session; - plugin = s-> plugin; + plugin = s->plugin; if (sc->direction == _SEND) { #if VERBOSE_SERVER - GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, - "Server: %X peer `%s' GET on address `%s' disconnected\n", - s->server_send, - GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen)); + GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, + "Server: %X peer `%s' GET on address `%s' disconnected\n", + s->server_send, GNUNET_i2s (&s->target), + GNUNET_a2s (s->addr, s->addrlen)); #endif s->server_send = NULL; @@ -730,17 +767,18 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, tc = s->server_recv; tc->disconnect = GNUNET_YES; #if MHD_VERSION >= 0x00090E00 - MHD_set_connection_option (sc->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, 1); + MHD_set_connection_option (sc->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, + 1); #endif } } if (sc->direction == _RECEIVE) { #if VERBOSE_SERVER - GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, - "Server: %X peer `%s' PUT on address `%s' disconnected\n", - s->server_recv, - GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen)); + GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, + "Server: %X peer `%s' PUT on address `%s' disconnected\n", + s->server_recv, GNUNET_i2s (&s->target), + GNUNET_a2s (s->addr, s->addrlen)); #endif s->server_recv = NULL; if (s->server_send != NULL) @@ -748,13 +786,14 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, tc = s->server_send; tc->disconnect = GNUNET_YES; #if MHD_VERSION >= 0x00090E00 - MHD_set_connection_option (sc->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, 1); + MHD_set_connection_option (sc->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, + 1); #endif } if (s->msg_tk != NULL) { - GNUNET_SERVER_mst_destroy(s->msg_tk); - s->msg_tk = NULL; + GNUNET_SERVER_mst_destroy (s->msg_tk); + s->msg_tk = NULL; } } GNUNET_free (sc); @@ -764,8 +803,9 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, { if (t == s) { - GNUNET_CONTAINER_DLL_remove(plugin->server_semi_head, plugin->server_semi_tail, s); - GNUNET_CONTAINER_DLL_insert(plugin->head, plugin->tail, s); + GNUNET_CONTAINER_DLL_remove (plugin->server_semi_head, + plugin->server_semi_tail, s); + GNUNET_CONTAINER_DLL_insert (plugin->head, plugin->tail, s); break; } t = t->next; @@ -777,17 +817,17 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, if ((s->server_send == NULL) && (s->server_recv == NULL)) { #if VERBOSE_SERVER - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Server: peer `%s' on address `%s' disconnected\n", - GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen)); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, + "Server: peer `%s' on address `%s' disconnected\n", + GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen)); #endif if (s->msg_tk != NULL) { - GNUNET_SERVER_mst_destroy(s->msg_tk); - s->msg_tk = NULL; + GNUNET_SERVER_mst_destroy (s->msg_tk); + s->msg_tk = NULL; } - notify_session_end(s->plugin, &s->target, s); + notify_session_end (s->plugin, &s->target, s); } } @@ -818,7 +858,7 @@ server_disconnect (struct Session *s) } int -server_send (struct Session *s, struct HTTP_Message * msg) +server_send (struct Session *s, struct HTTP_Message *msg) { GNUNET_CONTAINER_DLL_insert (s->msg_head, s->msg_tail, msg); server_reschedule (s->plugin, GNUNET_YES); @@ -834,10 +874,10 @@ server_send (struct Session *s, struct HTTP_Message * msg) * @param tc task context */ static void -server_v4_run (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +server_v4_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct Plugin *plugin = cls; + GNUNET_assert (cls != NULL); plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK; @@ -847,7 +887,8 @@ server_v4_run (void *cls, GNUNET_assert (MHD_YES == MHD_run (plugin->server_v4)); if (plugin->server_v4 != NULL) - plugin->server_v4_task = server_schedule (plugin, plugin->server_v4, GNUNET_NO); + plugin->server_v4_task = + server_schedule (plugin, plugin->server_v4, GNUNET_NO); } @@ -858,10 +899,10 @@ server_v4_run (void *cls, * @param tc task context */ static void -server_v6_run (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +server_v6_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct Plugin *plugin = cls; + GNUNET_assert (cls != NULL); plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK; @@ -871,7 +912,8 @@ server_v6_run (void *cls, GNUNET_assert (MHD_YES == MHD_run (plugin->server_v6)); if (plugin->server_v6 != NULL) - plugin->server_v6_task = server_schedule (plugin, plugin->server_v6, GNUNET_NO); + plugin->server_v6_task = + server_schedule (plugin, plugin->server_v6, GNUNET_NO); } /** @@ -882,7 +924,8 @@ server_v6_run (void *cls, * @return gnunet task identifier */ static GNUNET_SCHEDULER_TaskIdentifier -server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle, int now) +server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle, + int now) { GNUNET_SCHEDULER_TaskIdentifier ret; fd_set rs; @@ -909,7 +952,7 @@ server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle, int no GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max)); haveto = MHD_get_timeout (daemon_handle, &timeout); if (haveto == MHD_YES) - { + { if (timeout != last_timeout) { #if VERBOSE_SERVER @@ -920,7 +963,7 @@ server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle, int no last_timeout = timeout; } tv.rel_value = (uint64_t) timeout; - } + } else tv = GNUNET_TIME_UNIT_SECONDS; /* Force immediate run, since we have outbound data to send */ @@ -972,7 +1015,7 @@ server_start (struct Plugin *plugin) if (res == GNUNET_SYSERR) { GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, - "Could not load or create server certificate! Loading plugin failed!\n"); + "Could not load or create server certificate! Loading plugin failed!\n"); return res; } #endif @@ -981,11 +1024,13 @@ server_start (struct Plugin *plugin) #if MHD_VERSION >= 0x00090E00 timeout = GNUNET_CONSTANTS_DISCONNECT_SESSION_TIMEOUT.rel_value / 1000; GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "MHD can set timeout per connection! Default time out %u sec.\n", timeout); + "MHD can set timeout per connection! Default time out %u sec.\n", + timeout); #else timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value / 1000; GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name, - "MHD cannot set timeout per connection! Default time out %u sec.\n", timeout); + "MHD cannot set timeout per connection! Default time out %u sec.\n", + timeout); #endif plugin->server_v4 = NULL; if (plugin->ipv4 == GNUNET_YES) @@ -1015,7 +1060,7 @@ server_start (struct Plugin *plugin) plugin->cert, #endif MHD_OPTION_CONNECTION_TIMEOUT, - timeout , + timeout, MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (2 * GNUNET_SERVER_MAX_MESSAGE_SIZE), @@ -1066,15 +1111,15 @@ server_start (struct Plugin *plugin) if ((plugin->ipv4 == GNUNET_YES) && (plugin->server_v4 == NULL)) { GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, - "Failed to start %s IPv4 server component on port %u\n", plugin->name, - plugin->port); + "Failed to start %s IPv4 server component on port %u\n", + plugin->name, plugin->port); return GNUNET_SYSERR; } if ((plugin->ipv6 == GNUNET_YES) && (plugin->server_v6 == NULL)) { GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, - "Failed to start %s IPv6 server component on port %u\n", plugin->name, - plugin->port); + "Failed to start %s IPv6 server component on port %u\n", + plugin->name, plugin->port); return GNUNET_SYSERR; } @@ -1095,8 +1140,10 @@ server_stop (struct Plugin *plugin) struct Session *t = NULL; struct MHD_Daemon *server_v4_tmp = plugin->server_v4; + plugin->server_v4 = NULL; struct MHD_Daemon *server_v6_tmp = plugin->server_v6; + plugin->server_v6 = NULL; if (plugin->server_v4_task != GNUNET_SCHEDULER_NO_TASK) diff --git a/src/transport/plugin_transport_sat_constants.h b/src/transport/plugin_transport_sat_constants.h index a9ee9227c..bd64c5d2b 100644 --- a/src/transport/plugin_transport_sat_constants.h +++ b/src/transport/plugin_transport_sat_constants.h @@ -32,22 +32,26 @@ typedef struct MacAdress { - uint8_t mac[6]; -}MacAdress; + uint8_t mac[6]; +} MacAdress; //praeamble -static const struct char praeambel[56] = -{{1,0,1,0,10,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0}}; +static const struct char praeambel[56] = + { {1, 0, 1, 0, 10, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, + 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, + 0, 1, 0, 1, 0, 1, 0} +}; //start of frame -static const struct char sof[8]= -{{1,0,1,0,1,0,1,1}} +static const struct char sof[8] = { {1, 0, 1, 0, 1, 0, 1, 1} } // broadcast mac static const struct MacAddress bc_all_mac = - { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }; + { {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} }; //crc polynom static const struct char ploynom[32] = - {{1,1,1,0,1,1,0,1,1,0,1,1,1,0,0,0,1,0,0,0,0,0,1,1,0,0,1,0,0,0,0,1}}; + { {1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, + 0, 0, 1, 0, 0, 0, 0, 1} +}; #endif diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 04ba348b3..9c6535988 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c @@ -696,10 +696,9 @@ do_transmit (void *cls, size_t size, void *buf) GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, session->pending_messages_tail, pos); GNUNET_assert (size >= pos->message_size); - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, - "tcp", - "Transmitting message of type %u\n", - ntohs (((struct GNUNET_MessageHeader*)pos->msg)->type)); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", + "Transmitting message of type %u\n", + ntohs (((struct GNUNET_MessageHeader *) pos->msg)->type)); /* FIXME: this memcpy can be up to 7% of our total runtime */ memcpy (cbuf, pos->msg, pos->message_size); cbuf += pos->message_size; @@ -1002,7 +1001,7 @@ tcp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, { if (addrlen == sizeof (struct IPv6TcpAddress)) { - GNUNET_assert (NULL != addr); /* make static analysis happy */ + GNUNET_assert (NULL != addr); /* make static analysis happy */ t6 = addr; af = AF_INET6; memset (&a6, 0, sizeof (a6)); @@ -1019,7 +1018,7 @@ tcp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, } else if (addrlen == sizeof (struct IPv4TcpAddress)) { - GNUNET_assert (NULL != addr); /* make static analysis happy */ + GNUNET_assert (NULL != addr); /* make static analysis happy */ t4 = addr; af = AF_INET; memset (&a4, 0, sizeof (a4)); @@ -1073,7 +1072,7 @@ tcp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, /* append pm to pending_messages list */ GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head, - session->pending_messages_tail, pm); + session->pending_messages_tail, pm); GNUNET_assert (GNUNET_CONTAINER_multihashmap_put (plugin->nat_wait_conns, &target->hashPubKey, session, @@ -1129,16 +1128,14 @@ tcp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, /* check if session is valid */ struct Session *ses = plugin->sessions; - if (0 != memcmp (target, - &session->target, - sizeof (struct GNUNET_PeerIdentity))) + if (0 != + memcmp (target, &session->target, sizeof (struct GNUNET_PeerIdentity))) { GNUNET_break (0); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Got session %p for `%s', but should be for peer `%s'!\n", - session, - GNUNET_i2s (&session->target), - GNUNET_h2s (&target->hashPubKey)); + "Got session %p for `%s', but should be for peer `%s'!\n", + session, GNUNET_i2s (&session->target), + GNUNET_h2s (&target->hashPubKey)); return -1; } @@ -1170,7 +1167,7 @@ tcp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, /* append pm to pending_messages list */ GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head, - session->pending_messages_tail, pm); + session->pending_messages_tail, pm); #if DEBUG_TCP GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", "Asked to transmit %u bytes to `%s', added message to list.\n", @@ -1741,8 +1738,8 @@ handle_tcp_data (void *cls, struct GNUNET_SERVER_Client *client, distance.value = htonl (1); delay = plugin->env->receive (plugin->env->cls, &session->target, message, - (const struct GNUNET_ATS_Information *) - &distance, 1, session, + (const struct GNUNET_ATS_Information *) &distance, + 1, session, (GNUNET_YES == session->inbound) ? NULL : session->connect_addr, (GNUNET_YES == diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index cf6e01306..667af25be 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c @@ -120,12 +120,12 @@ struct UDP_Beacon_Message /** * Message header. */ - struct GNUNET_MessageHeader header; + struct GNUNET_MessageHeader header; /** * What is the identity of the sender */ - struct GNUNET_PeerIdentity sender; + struct GNUNET_PeerIdentity sender; }; @@ -396,8 +396,8 @@ struct Plugin struct PeerSessionIteratorContext { - struct Session * result; - const void * addr; + struct Session *result; + const void *addr; size_t addrlen; }; @@ -417,13 +417,12 @@ find_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *peer) } -static int -inbound_session_iterator (void *cls, - const GNUNET_HashCode * key, - void *value) +static int +inbound_session_iterator (void *cls, const GNUNET_HashCode * key, void *value) { struct PeerSessionIteratorContext *psc = cls; struct Session *s = value; + if (s->addrlen == psc->addrlen) { if (0 == memcmp (&s[1], psc->addr, s->addrlen)) @@ -444,26 +443,29 @@ inbound_session_iterator (void *cls, */ static struct Session * find_inbound_session (struct Plugin *plugin, - const struct GNUNET_PeerIdentity *peer, - const void * addr, size_t addrlen) + const struct GNUNET_PeerIdentity *peer, const void *addr, + size_t addrlen) { struct PeerSessionIteratorContext psc; + psc.result = NULL; psc.addrlen = addrlen; psc.addr = addr; - GNUNET_CONTAINER_multihashmap_get_multiple(plugin->inbound_sessions, &peer->hashPubKey, &inbound_session_iterator, &psc); + GNUNET_CONTAINER_multihashmap_get_multiple (plugin->inbound_sessions, + &peer->hashPubKey, + &inbound_session_iterator, &psc); return psc.result; } -static int -inbound_session_by_addr_iterator (void *cls, - const GNUNET_HashCode * key, - void *value) +static int +inbound_session_by_addr_iterator (void *cls, const GNUNET_HashCode * key, + void *value) { struct PeerSessionIteratorContext *psc = cls; struct Session *s = value; + if (s->addrlen == psc->addrlen) { if (0 == memcmp (&s[1], psc->addr, s->addrlen)) @@ -484,14 +486,18 @@ inbound_session_by_addr_iterator (void *cls, * @return NULL if we have no session */ static struct Session * -find_inbound_session_by_addr (struct Plugin *plugin, const void * addr, size_t addrlen) +find_inbound_session_by_addr (struct Plugin *plugin, const void *addr, + size_t addrlen) { struct PeerSessionIteratorContext psc; + psc.result = NULL; psc.addrlen = addrlen; psc.addr = addr; - GNUNET_CONTAINER_multihashmap_iterate (plugin->inbound_sessions, &inbound_session_by_addr_iterator, &psc); + GNUNET_CONTAINER_multihashmap_iterate (plugin->inbound_sessions, + &inbound_session_by_addr_iterator, + &psc); return psc.result; } @@ -531,7 +537,7 @@ destroy_inbound_session (void *cls, const GNUNET_HashCode * key, void *value) struct Session *s = value; if (s->invalidation_task != GNUNET_SCHEDULER_NO_TASK) - GNUNET_SCHEDULER_cancel(s->invalidation_task); + GNUNET_SCHEDULER_cancel (s->invalidation_task); if (GNUNET_SCHEDULER_NO_TASK != s->delayed_cont_task) GNUNET_SCHEDULER_cancel (s->delayed_cont_task); GNUNET_free (s); @@ -560,11 +566,10 @@ udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) session)); GNUNET_CONTAINER_multihashmap_get_multiple (plugin->inbound_sessions, - &target->hashPubKey, - &destroy_inbound_session, NULL); + &target->hashPubKey, + &destroy_inbound_session, NULL); GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sendto"); - LOG (GNUNET_ERROR_TYPE_ERROR, - "UDP DISCONNECT\n"); + LOG (GNUNET_ERROR_TYPE_ERROR, "UDP DISCONNECT\n"); plugin->last_expected_delay = GNUNET_FRAGMENT_context_destroy (session->frag); if (GNUNET_SCHEDULER_NO_TASK != session->delayed_cont_task) @@ -614,15 +619,15 @@ udp_send (struct Plugin *plugin, const struct sockaddr *sa, { GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sendto"); LOG (GNUNET_ERROR_TYPE_ERROR, - "UDP transmited %u-byte message to %s (%d: %s)\n", - (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen), - (int) sent, (sent < 0) ? STRERROR (errno) : "ok"); + "UDP transmited %u-byte message to %s (%d: %s)\n", + (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen), (int) sent, + (sent < 0) ? STRERROR (errno) : "ok"); } LOG (GNUNET_ERROR_TYPE_DEBUG, - "UDP transmited %u-byte message to %s (%d: %s)\n", - (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen), - (int) sent, (sent < 0) ? STRERROR (errno) : "ok"); + "UDP transmited %u-byte message to %s (%d: %s)\n", + (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen), (int) sent, + (sent < 0) ? STRERROR (errno) : "ok"); return sent; } @@ -648,10 +653,10 @@ send_fragment (void *cls, const struct GNUNET_MessageHeader *msg) static struct Session * create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, - const void *addr, size_t addrlen, - GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) + const void *addr, size_t addrlen, + GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) { - struct Session * peer_session; + struct Session *peer_session; const struct IPv4UdpAddress *t4; const struct IPv6UdpAddress *t6; struct sockaddr_in *v4; @@ -667,8 +672,7 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, } t4 = addr; peer_session = - GNUNET_malloc (sizeof (struct Session) + - sizeof (struct sockaddr_in)); + GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in)); len = sizeof (struct sockaddr_in); v4 = (struct sockaddr_in *) &peer_session[1]; v4->sin_family = AF_INET; @@ -685,8 +689,7 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, } t6 = addr; peer_session = - GNUNET_malloc (sizeof (struct Session) + - sizeof (struct sockaddr_in6)); + GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in6)); len = sizeof (struct sockaddr_in6); v6 = (struct sockaddr_in6 *) &peer_session[1]; v6->sin6_family = AF_INET6; @@ -719,8 +722,7 @@ udp_address_to_string (void *cls, const void *addr, size_t addrlen); static void -udp_call_continuation (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +udp_call_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct Session *s = cls; GNUNET_TRANSPORT_TransmitContinuation cont = s->cont; @@ -779,10 +781,10 @@ udp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, } LOG (GNUNET_ERROR_TYPE_DEBUG, - "UDP transmits %u-byte message to `%s' using address `%s' session 0x%X mode %i\n", - msgbuf_size, GNUNET_i2s (target), - udp_address_to_string (NULL, addr, addrlen), - session, force_address); + "UDP transmits %u-byte message to `%s' using address `%s' session 0x%X mode %i\n", + msgbuf_size, GNUNET_i2s (target), udp_address_to_string (NULL, addr, + addrlen), + session, force_address); if ((force_address == GNUNET_SYSERR) && (session == NULL)) return GNUNET_SYSERR; @@ -792,10 +794,11 @@ udp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, if ((session != NULL) && (addr != NULL) && (addrlen != 0)) { s = session; - GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains_value ( - plugin->inbound_sessions, &target->hashPubKey, s)); + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multihashmap_contains_value + (plugin->inbound_sessions, &target->hashPubKey, s)); - if (0 != memcmp (&s->target, target, sizeof (struct GNUNET_PeerIdentity))) + if (0 != memcmp (&s->target, target, sizeof (struct GNUNET_PeerIdentity))) return GNUNET_SYSERR; switch (addrlen) { @@ -810,10 +813,13 @@ udp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, if (s->addrlen != (sizeof (struct sockaddr_in))) return GNUNET_SYSERR; struct sockaddr_in *a4 = (struct sockaddr_in *) s->sock_addr; + GNUNET_assert (a4->sin_port == t4->u4_port); - GNUNET_assert (0 == memcmp(&a4->sin_addr, &t4->ipv4_addr, sizeof (struct in_addr))); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Session 0x%X successfully checked!\n", session); + GNUNET_assert (0 == + memcmp (&a4->sin_addr, &t4->ipv4_addr, + sizeof (struct in_addr))); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Session 0x%X successfully checked!\n", + session); break; case sizeof (struct IPv6UdpAddress): if (NULL == plugin->sockv6) @@ -825,10 +831,13 @@ udp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, t6 = addr; GNUNET_assert (s->addrlen == sizeof (struct sockaddr_in6)); struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) s->sock_addr; + GNUNET_assert (a6->sin6_port == t6->u6_port); - GNUNET_assert (0 == memcmp(&a6->sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr))); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Session 0x%X successfully checked!\n", session); + GNUNET_assert (0 == + memcmp (&a6->sin6_addr, &t6->ipv6_addr, + sizeof (struct in6_addr))); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Session 0x%X successfully checked!\n", + session); break; default: /* Must have a valid address to send to */ @@ -854,7 +863,7 @@ udp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, udp->sender = *plugin->env->my_identity; memcpy (&udp[1], msgbuf, msgbuf_size); - if (s != NULL) + if (s != NULL) delta = GNUNET_TIME_absolute_get_remaining (s->flow_delay_from_other_peer); else delta = GNUNET_TIME_UNIT_ZERO; @@ -863,17 +872,15 @@ udp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, mlen = udp_send (plugin, peer_session->sock_addr, &udp->header); if (cont != NULL) { - if ( (delta.rel_value > 0) && - (mlen > 0) ) + if ((delta.rel_value > 0) && (mlen > 0)) { - s->cont = cont; - s->cont_cls = cont_cls; - s->delayed_cont_task = GNUNET_SCHEDULER_add_delayed (delta, - &udp_call_continuation, - s); + s->cont = cont; + s->cont_cls = cont_cls; + s->delayed_cont_task = + GNUNET_SCHEDULER_add_delayed (delta, &udp_call_continuation, s); } else - cont (cont_cls, target, (mlen > 0) ? GNUNET_OK : GNUNET_SYSERR); + cont (cont_cls, target, (mlen > 0) ? GNUNET_OK : GNUNET_SYSERR); } GNUNET_free_non_null (peer_session); } @@ -915,7 +922,7 @@ struct SourceInformation */ size_t args; - struct Session * session; + struct Session *session; }; @@ -940,23 +947,29 @@ process_inbound_tokenized_messages (void *cls, void *client, distance.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); distance.value = htonl (1); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Giving Session %X %s to transport\n", si->session, GNUNET_i2s(&si->session->target)); - delay = plugin->env->receive (plugin->env->cls, &si->sender, hdr, &distance, 1, si->session, - si->arg, si->args); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Giving Session %X %s to transport\n", + si->session, GNUNET_i2s (&si->session->target)); + delay = + plugin->env->receive (plugin->env->cls, &si->sender, hdr, &distance, 1, + si->session, si->arg, si->args); si->session->flow_delay_for_other_peer = delay; } static void invalidation_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - struct Session * s = cls; - s->invalidation_task = GNUNET_SCHEDULER_NO_TASK; - LOG (GNUNET_ERROR_TYPE_ERROR, - "Session %X (`%s') is now invalid\n", s, GNUNET_a2s (s->sock_addr,s->addrlen)); + struct Session *s = cls; - s->plugin->env->session_end(s->plugin->env->cls, &s->target, s); - GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(s->plugin->inbound_sessions, &s->target.hashPubKey, s)); + s->invalidation_task = GNUNET_SCHEDULER_NO_TASK; + LOG (GNUNET_ERROR_TYPE_ERROR, "Session %X (`%s') is now invalid\n", s, + GNUNET_a2s (s->sock_addr, s->addrlen)); + + s->plugin->env->session_end (s->plugin->env->cls, &s->target, s); + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove (s-> + plugin->inbound_sessions, + &s->target.hashPubKey, + s)); GNUNET_free (s); } @@ -1015,54 +1028,54 @@ process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg, } #if DEBUG_UDP LOG (GNUNET_ERROR_TYPE_DEBUG, - "Received message with %u bytes from peer `%s' at `%s'\n", - (unsigned int) ntohs (msg->header.size), - GNUNET_i2s (&msg->sender), GNUNET_a2s (sender_addr, - sender_addr_len)); + "Received message with %u bytes from peer `%s' at `%s'\n", + (unsigned int) ntohs (msg->header.size), GNUNET_i2s (&msg->sender), + GNUNET_a2s (sender_addr, sender_addr_len)); #endif /* create a session for inbound connections */ - const struct UDPMessage * udp_msg = (const struct UDPMessage *) msg; + const struct UDPMessage *udp_msg = (const struct UDPMessage *) msg; + LOG (GNUNET_ERROR_TYPE_DEBUG, - "Lookup inbound UDP sessions for peer `%s' address `%s'\n", - GNUNET_i2s (&udp_msg->sender), - udp_address_to_string(NULL, arg, args)); + "Lookup inbound UDP sessions for peer `%s' address `%s'\n", + GNUNET_i2s (&udp_msg->sender), udp_address_to_string (NULL, arg, args)); - struct Session * s = NULL; - s = find_inbound_session (plugin, &udp_msg->sender, sender_addr, sender_addr_len); + struct Session *s = NULL; + + s = find_inbound_session (plugin, &udp_msg->sender, sender_addr, + sender_addr_len); if (s != NULL) { LOG (GNUNET_ERROR_TYPE_DEBUG, - "Found existing inbound UDP sessions 0x%X for peer `%s' address `%s'\n", - s, - GNUNET_i2s (&s->target), - udp_address_to_string(NULL, arg, args)); + "Found existing inbound UDP sessions 0x%X for peer `%s' address `%s'\n", + s, GNUNET_i2s (&s->target), udp_address_to_string (NULL, arg, args)); } else { s = create_session (plugin, &udp_msg->sender, arg, args, NULL, NULL); LOG (GNUNET_ERROR_TYPE_DEBUG, - "Creating inbound UDP sessions 0x%X for peer `%s' address `%s'\n", - s, - GNUNET_i2s (&s->target), - udp_address_to_string(NULL, arg, args)); - - GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (plugin->inbound_sessions, - &s->target.hashPubKey, - s, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); + "Creating inbound UDP sessions 0x%X for peer `%s' address `%s'\n", s, + GNUNET_i2s (&s->target), udp_address_to_string (NULL, arg, args)); + + GNUNET_assert (GNUNET_OK == + GNUNET_CONTAINER_multihashmap_put (plugin->inbound_sessions, + &s->target.hashPubKey, s, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); } - s->valid_until = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); + s->valid_until = + GNUNET_TIME_relative_to_absolute + (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); if (s->invalidation_task != GNUNET_SCHEDULER_NO_TASK) { - GNUNET_SCHEDULER_cancel(s->invalidation_task); + GNUNET_SCHEDULER_cancel (s->invalidation_task); s->invalidation_task = GNUNET_SCHEDULER_NO_TASK; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Rescheduling %X' `%s'\n", - s, udp_address_to_string(NULL, arg, args)); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Rescheduling %X' `%s'\n", s, + udp_address_to_string (NULL, arg, args)); } - s->invalidation_task = GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &invalidation_task, s); + s->invalidation_task = + GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, + &invalidation_task, s); /* iterate over all embedded messages */ si.sender = msg->sender; si.arg = arg; @@ -1118,6 +1131,7 @@ ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg) uint32_t delay = 0; struct Session *s; + s = find_inbound_session_by_addr (rc->plugin, rc->src_addr, rc->addr_len); if (s != NULL) { @@ -1129,12 +1143,13 @@ ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg) #if DEBUG_UDP - LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ACK to `%s' including delay of %u ms\n", - GNUNET_a2s (rc->src_addr, - (rc->src_addr->sa_family == - AF_INET) ? sizeof (struct sockaddr_in) : - sizeof (struct sockaddr_in6)), - delay); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Sending ACK to `%s' including delay of %u ms\n", + GNUNET_a2s (rc->src_addr, + (rc->src_addr->sa_family == + AF_INET) ? sizeof (struct sockaddr_in) : sizeof (struct + sockaddr_in6)), + delay); #endif udp_ack = (struct UDP_ACK_Message *) buf; udp_ack->header.size = htons ((uint16_t) msize); @@ -1166,7 +1181,7 @@ struct FindReceiveContext */ socklen_t addr_len; - struct Session * session; + struct Session *session; }; @@ -1217,7 +1232,7 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) struct ReceiveContext *rc; struct GNUNET_TIME_Absolute now; struct FindReceiveContext frc; - struct Session * s = NULL; + struct Session *s = NULL; struct GNUNET_TIME_Relative flow_delay; fromlen = sizeof (addr); @@ -1233,8 +1248,8 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) msg = (const struct GNUNET_MessageHeader *) buf; LOG (GNUNET_ERROR_TYPE_DEBUG, - "UDP received %u-byte message from `%s' type %i\n", (unsigned int) ret, - GNUNET_a2s ((const struct sockaddr *) addr, fromlen), ntohs(msg->type)); + "UDP received %u-byte message from `%s' type %i\n", (unsigned int) ret, + GNUNET_a2s ((const struct sockaddr *) addr, fromlen), ntohs (msg->type)); if (ret != ntohs (msg->size)) { @@ -1261,27 +1276,29 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) return; } udp_ack = (const struct UDP_ACK_Message *) msg; - s = find_inbound_session(plugin, &udp_ack->sender, addr, fromlen); + s = find_inbound_session (plugin, &udp_ack->sender, addr, fromlen); if (s != NULL) { - flow_delay.rel_value = (uint64_t) ntohl(udp_ack->delay); + flow_delay.rel_value = (uint64_t) ntohl (udp_ack->delay); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "We received a sending delay of %llu\n", flow_delay.rel_value); + LOG (GNUNET_ERROR_TYPE_DEBUG, "We received a sending delay of %llu\n", + flow_delay.rel_value); - s->flow_delay_from_other_peer = GNUNET_TIME_relative_to_absolute (flow_delay); + s->flow_delay_from_other_peer = + GNUNET_TIME_relative_to_absolute (flow_delay); } ack = (const struct GNUNET_MessageHeader *) &udp_ack[1]; - if (ntohs (ack->size) != ntohs (msg->size) - sizeof (struct UDP_ACK_Message)) + if (ntohs (ack->size) != + ntohs (msg->size) - sizeof (struct UDP_ACK_Message)) { GNUNET_break_op (0); return; } #if DEBUG_UDP LOG (GNUNET_ERROR_TYPE_DEBUG, - "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", - (unsigned int) ntohs (msg->size), GNUNET_i2s (&udp_ack->sender), - GNUNET_a2s ((const struct sockaddr *) addr, fromlen)); + "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", + (unsigned int) ntohs (msg->size), GNUNET_i2s (&udp_ack->sender), + GNUNET_a2s ((const struct sockaddr *) addr, fromlen)); #endif peer_session = find_session (plugin, &udp_ack->sender); @@ -1289,7 +1306,7 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) { #if DEBUG_UDP LOG (GNUNET_ERROR_TYPE_DEBUG, - "Session for ACK not found, dropping ACK!\n"); + "Session for ACK not found, dropping ACK!\n"); #endif return; } @@ -1332,10 +1349,9 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) now.abs_value); } #if DEBUG_UDP - LOG (GNUNET_ERROR_TYPE_DEBUG, - "UDP processes %u-byte fragment from `%s'\n", - (unsigned int) ntohs (msg->size), - GNUNET_a2s ((const struct sockaddr *) addr, fromlen)); + LOG (GNUNET_ERROR_TYPE_DEBUG, "UDP processes %u-byte fragment from `%s'\n", + (unsigned int) ntohs (msg->size), + GNUNET_a2s ((const struct sockaddr *) addr, fromlen)); #endif if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (rc->defrag, msg)) @@ -1395,40 +1411,43 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) struct MstContext { - struct Plugin * plugin; + struct Plugin *plugin; struct IPv4UdpAddress addr; }; -void udp_broadcast_mst_cb (void *cls, void *client, - const struct - GNUNET_MessageHeader * - message) +void +udp_broadcast_mst_cb (void *cls, void *client, + const struct GNUNET_MessageHeader *message) { - struct Plugin * plugin = cls; - struct MstContext * mc = client; - const struct GNUNET_MessageHeader* hello; - struct UDP_Beacon_Message * msg; + struct Plugin *plugin = cls; + struct MstContext *mc = client; + const struct GNUNET_MessageHeader *hello; + struct UDP_Beacon_Message *msg; + msg = (struct UDP_Beacon_Message *) message; - if (GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON != ntohs(msg->header.type)) + if (GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON != + ntohs (msg->header.type)) return; LOG (GNUNET_ERROR_TYPE_ERROR, - "Received beacon with %u bytes from peer `%s' via address `%s'\n", - ntohs(msg->header.size), - GNUNET_i2s (&msg->sender), - udp_address_to_string(NULL, &mc->addr, sizeof (mc->addr))); + "Received beacon with %u bytes from peer `%s' via address `%s'\n", + ntohs (msg->header.size), GNUNET_i2s (&msg->sender), + udp_address_to_string (NULL, &mc->addr, sizeof (mc->addr))); struct GNUNET_ATS_Information ats; + ats.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); ats.value = htonl (1); hello = (struct GNUNET_MessageHeader *) &msg[1]; - plugin->env->receive (plugin->env->cls, &msg->sender, hello, &ats, 1, NULL, (const char *) &mc->addr, sizeof (mc->addr)); + plugin->env->receive (plugin->env->cls, &msg->sender, hello, &ats, 1, NULL, + (const char *) &mc->addr, sizeof (mc->addr)); - GNUNET_STATISTICS_update(plugin->env->stats, - _("# HELLO beacons received via udp"), 1, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + _("# HELLO beacons received via udp"), 1, + GNUNET_NO); GNUNET_free (mc); } @@ -1445,54 +1464,61 @@ udp_broadcast_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) char addr[32]; char buf[65536]; ssize_t ret; - struct MstContext * mc; + struct MstContext *mc; fromlen = sizeof (addr); memset (&addr, 0, sizeof (addr)); - ret = GNUNET_NETWORK_socket_recvfrom (rsock, buf, sizeof (buf), (struct sockaddr *) &addr, &fromlen); + ret = + GNUNET_NETWORK_socket_recvfrom (rsock, buf, sizeof (buf), + (struct sockaddr *) &addr, &fromlen); if (ret < sizeof (struct GNUNET_MessageHeader)) { /* malformed beacon, just throw it away */ return; } - mc = GNUNET_malloc(sizeof (struct MstContext)); + mc = GNUNET_malloc (sizeof (struct MstContext)); + + struct sockaddr_in *av4 = (struct sockaddr_in *) &addr; - struct sockaddr_in * av4 = (struct sockaddr_in *) &addr; mc->addr.ipv4_addr = av4->sin_addr.s_addr; mc->addr.u4_port = av4->sin_port; - if (GNUNET_OK != GNUNET_SERVER_mst_receive(plugin->broadcast_mst, mc, buf, ret, GNUNET_NO, GNUNET_NO)) + if (GNUNET_OK != + GNUNET_SERVER_mst_receive (plugin->broadcast_mst, mc, buf, ret, GNUNET_NO, + GNUNET_NO)) GNUNET_free (mc); } static void -udp_broadcast_send (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +udp_broadcast_send (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - struct Plugin * plugin = cls; + struct Plugin *plugin = cls; int sent; uint16_t msg_size; uint16_t hello_size; char buf[65536]; + // /ssize_t ret; const struct GNUNET_MessageHeader *hello; - struct UDP_Beacon_Message * msg; + struct UDP_Beacon_Message *msg; plugin->send_broadcast_task = GNUNET_SCHEDULER_NO_TASK; struct sockaddr_in baddr; + baddr.sin_family = AF_INET; baddr.sin_port = htons (plugin->broadcast_port); - baddr.sin_addr.s_addr=htonl(-1); /* send message to 255.255.255.255 */ + baddr.sin_addr.s_addr = htonl (-1); /* send message to 255.255.255.255 */ hello = plugin->env->get_our_hello (); hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello); msg_size = hello_size + sizeof (struct UDP_Beacon_Message); - if (hello_size < (sizeof (struct GNUNET_MessageHeader)) ||(msg_size > (UDP_MTU))) + if (hello_size < (sizeof (struct GNUNET_MessageHeader)) || + (msg_size > (UDP_MTU))) return; msg = (struct UDP_Beacon_Message *) buf; @@ -1501,13 +1527,17 @@ udp_broadcast_send (void *cls, msg->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON); memcpy (&msg[1], hello, hello_size); - sent = GNUNET_NETWORK_socket_sendto (plugin->sockv4_broadcast, msg, msg_size, - (const struct sockaddr *) &baddr, sizeof (struct sockaddr_in)); + sent = + GNUNET_NETWORK_socket_sendto (plugin->sockv4_broadcast, msg, msg_size, + (const struct sockaddr *) &baddr, + sizeof (struct sockaddr_in)); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Sent HELLO beacon broadcast with %i bytes\n", sent); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Sent HELLO beacon broadcast with %i bytes\n", + sent); - plugin->send_broadcast_task = GNUNET_SCHEDULER_add_delayed(plugin->broadcast_interval, &udp_broadcast_send, plugin); + plugin->send_broadcast_task = + GNUNET_SCHEDULER_add_delayed (plugin->broadcast_interval, + &udp_broadcast_send, plugin); } @@ -1520,7 +1550,8 @@ udp_broadcast_send (void *cls, * @param tc the scheduling context (for rescheduling this function again) */ static void -udp_plugin_broadcast_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +udp_plugin_broadcast_select (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) { struct Plugin *plugin = cls; @@ -1535,8 +1566,9 @@ udp_plugin_broadcast_select (void *cls, const struct GNUNET_SCHEDULER_TaskContex plugin->select_broadcast_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_UNIT_FOREVER_REL, plugin->broadcast_rs, - NULL, &udp_plugin_broadcast_select, plugin); + GNUNET_TIME_UNIT_FOREVER_REL, + plugin->broadcast_rs, NULL, + &udp_plugin_broadcast_select, plugin); } @@ -1664,7 +1696,7 @@ udp_address_to_string (void *cls, const void *addr, size_t addrlen) } inet_ntop (af, sb, buf, INET6_ADDRSTRLEN); GNUNET_snprintf (rbuf, sizeof (rbuf), (af == AF_INET6) ? "[%s]:%u" : "%s:%u", - buf, port); + buf, port); return rbuf; } @@ -1868,16 +1900,20 @@ libgnunet_plugin_transport_udp_init (void *cls) &port)) port = 2086; - broadcast = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "transport-udp", "BROADCAST"); - if (broadcast == GNUNET_SYSERR) - broadcast = GNUNET_NO; + broadcast = + GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "transport-udp", + "BROADCAST"); + if (broadcast == GNUNET_SYSERR) + broadcast = GNUNET_NO; - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (env->cfg, "transport-udp", "BROADCAST_INTERVAL", &interval)) - interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10); + if (GNUNET_SYSERR == + GNUNET_CONFIGURATION_get_value_time (env->cfg, "transport-udp", + "BROADCAST_INTERVAL", &interval)) + interval = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", "BROADCAST_PORT", - &bport)) + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", + "BROADCAST_PORT", &bport)) bport = 20086; if (GNUNET_OK != @@ -1891,8 +1927,8 @@ libgnunet_plugin_transport_udp_init (void *cls) if (port > 65535) { LOG (GNUNET_ERROR_TYPE_WARNING, - _("Given `%s' option is out of range: %llu > %u\n"), "PORT", - port, 65535); + _("Given `%s' option is out of range: %llu > %u\n"), "PORT", port, + 65535); return NULL; } memset (&serverAddrv6, 0, sizeof (serverAddrv6)); @@ -1923,8 +1959,8 @@ libgnunet_plugin_transport_udp_init (void *cls) "BINDTO", &plugin->bind4_address)) { LOG (GNUNET_ERROR_TYPE_DEBUG, - "Binding udp plugin to specific address: `%s'\n", - plugin->bind4_address); + "Binding udp plugin to specific address: `%s'\n", + plugin->bind4_address); if (1 != inet_pton (AF_INET, plugin->bind4_address, &serverAddrv4.sin_addr)) { GNUNET_free (plugin->bind4_address); @@ -1939,13 +1975,13 @@ libgnunet_plugin_transport_udp_init (void *cls) "BINDTO6", &plugin->bind6_address)) { LOG (GNUNET_ERROR_TYPE_DEBUG, - "Binding udp plugin to specific address: `%s'\n", - plugin->bind6_address); + "Binding udp plugin to specific address: `%s'\n", + plugin->bind6_address); if (1 != inet_pton (AF_INET6, plugin->bind6_address, &serverAddrv6.sin6_addr)) { LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid IPv6 address: `%s'\n"), - plugin->bind6_address); + plugin->bind6_address); GNUNET_free_non_null (plugin->bind4_address); GNUNET_free (plugin->bind6_address); GNUNET_free (plugin); @@ -1984,7 +2020,7 @@ libgnunet_plugin_transport_udp_init (void *cls) serverAddr = (struct sockaddr *) &serverAddrv6; #if DEBUG_UDP LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv6 port %d\n", - ntohs (serverAddrv6.sin6_port)); + ntohs (serverAddrv6.sin6_port)); #endif tries = 0; while (GNUNET_NETWORK_socket_bind (plugin->sockv6, serverAddr, addrlen) != @@ -1993,8 +2029,8 @@ libgnunet_plugin_transport_udp_init (void *cls) serverAddrv6.sin6_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */ #if DEBUG_UDP LOG (GNUNET_ERROR_TYPE_DEBUG, - "IPv6 Binding failed, trying new port %d\n", - ntohs (serverAddrv6.sin6_port)); + "IPv6 Binding failed, trying new port %d\n", + ntohs (serverAddrv6.sin6_port)); #endif tries++; if (tries > 10) @@ -2032,7 +2068,7 @@ libgnunet_plugin_transport_udp_init (void *cls) serverAddr = (struct sockaddr *) &serverAddrv4; #if DEBUG_UDP LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv4 port %d\n", - ntohs (serverAddrv4.sin_port)); + ntohs (serverAddrv4.sin_port)); #endif tries = 0; while (GNUNET_NETWORK_socket_bind (plugin->sockv4, serverAddr, addrlen) != @@ -2040,9 +2076,8 @@ libgnunet_plugin_transport_udp_init (void *cls) { serverAddrv4.sin_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */ #if DEBUG_UDP - LOG (GNUNET_ERROR_TYPE_DEBUG, - "IPv4 Binding failed, trying new port %d\n", - ntohs (serverAddrv4.sin_port)); + LOG (GNUNET_ERROR_TYPE_DEBUG, "IPv4 Binding failed, trying new port %d\n", + ntohs (serverAddrv4.sin_port)); #endif tries++; if (tries > 10) @@ -2077,47 +2112,56 @@ libgnunet_plugin_transport_udp_init (void *cls) /* create broadcast socket */ if (broadcast) { - plugin->sockv4_broadcast = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0); + plugin->sockv4_broadcast = + GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0); if (NULL == plugin->sockv4_broadcast) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket"); } else { - #if HAVE_SOCKADDR_IN_SIN_LEN +#if HAVE_SOCKADDR_IN_SIN_LEN serverAddrv4.sin_len = sizeof (serverAddrv4); - #endif +#endif serverAddrv4.sin_family = AF_INET; serverAddrv4.sin_addr.s_addr = INADDR_ANY; serverAddrv4.sin_port = htons (plugin->broadcast_port); addrlen = sizeof (serverAddrv4); serverAddr = (struct sockaddr *) &serverAddrv4; - #if DEBUG_UDP - #endif +#if DEBUG_UDP +#endif LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding Broadcast to IPv4 port %d\n", - ntohs (serverAddrv4.sin_port)); + ntohs (serverAddrv4.sin_port)); - if (GNUNET_NETWORK_socket_bind (plugin->sockv4_broadcast, serverAddr, addrlen) != GNUNET_OK) + if (GNUNET_NETWORK_socket_bind + (plugin->sockv4_broadcast, serverAddr, addrlen) != GNUNET_OK) { - LOG (GNUNET_ERROR_TYPE_WARNING, _("Failed to create IPv4 broadcast socket on port %d\n"), - ntohs (serverAddrv4.sin_port)); - GNUNET_NETWORK_socket_close (plugin->sockv4_broadcast); - plugin->sockv4_broadcast = NULL; + LOG (GNUNET_ERROR_TYPE_WARNING, + _("Failed to create IPv4 broadcast socket on port %d\n"), + ntohs (serverAddrv4.sin_port)); + GNUNET_NETWORK_socket_close (plugin->sockv4_broadcast); + plugin->sockv4_broadcast = NULL; } if (plugin->sockv4_broadcast != NULL) { int yes = 1; - if (GNUNET_NETWORK_socket_setsockopt (plugin->sockv4_broadcast, SOL_SOCKET, SO_BROADCAST, &yes, sizeof(int)) != GNUNET_OK) + + if (GNUNET_NETWORK_socket_setsockopt + (plugin->sockv4_broadcast, SOL_SOCKET, SO_BROADCAST, &yes, + sizeof (int)) != GNUNET_OK) { - LOG (GNUNET_ERROR_TYPE_WARNING, _("Failed to set IPv4 broadcast option for broadcast socket on port %d\n"), - ntohs (serverAddrv4.sin_port)); - GNUNET_NETWORK_socket_close(plugin->sockv4_broadcast); + LOG (GNUNET_ERROR_TYPE_WARNING, + _ + ("Failed to set IPv4 broadcast option for broadcast socket on port %d\n"), + ntohs (serverAddrv4.sin_port)); + GNUNET_NETWORK_socket_close (plugin->sockv4_broadcast); plugin->sockv4_broadcast = NULL; } else { plugin->broadcast_rs = GNUNET_NETWORK_fdset_create (); - GNUNET_NETWORK_fdset_set (plugin->broadcast_rs, plugin->sockv4_broadcast); + GNUNET_NETWORK_fdset_set (plugin->broadcast_rs, + plugin->sockv4_broadcast); } } } @@ -2125,16 +2169,20 @@ libgnunet_plugin_transport_udp_init (void *cls) if (plugin->sockv4_broadcast != NULL) { plugin->broadcast = GNUNET_YES; - plugin->broadcast_mst = GNUNET_SERVER_mst_create (udp_broadcast_mst_cb, plugin); - GNUNET_STATISTICS_update(plugin->env->stats, - _("# HELLO beacons received via udp"), 1, GNUNET_NO); + plugin->broadcast_mst = + GNUNET_SERVER_mst_create (udp_broadcast_mst_cb, plugin); + GNUNET_STATISTICS_update (plugin->env->stats, + _("# HELLO beacons received via udp"), 1, + GNUNET_NO); plugin->select_broadcast_task = - GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_UNIT_FOREVER_REL, plugin->broadcast_rs, - NULL, &udp_plugin_broadcast_select, plugin); - - plugin->send_broadcast_task = GNUNET_SCHEDULER_add_now (&udp_broadcast_send, plugin); + GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, + GNUNET_SCHEDULER_NO_TASK, + GNUNET_TIME_UNIT_FOREVER_REL, + plugin->broadcast_rs, NULL, + &udp_plugin_broadcast_select, plugin); + + plugin->send_broadcast_task = + GNUNET_SCHEDULER_add_now (&udp_broadcast_send, plugin); } else plugin->broadcast = GNUNET_NO; @@ -2167,8 +2215,8 @@ libgnunet_plugin_transport_udp_done (void *cls) NULL); GNUNET_CONTAINER_multihashmap_destroy (plugin->sessions); plugin->sessions = NULL; - GNUNET_CONTAINER_multihashmap_iterate (plugin->inbound_sessions, &destroy_inbound_session, - NULL); + GNUNET_CONTAINER_multihashmap_iterate (plugin->inbound_sessions, + &destroy_inbound_session, NULL); GNUNET_CONTAINER_multihashmap_destroy (plugin->inbound_sessions); plugin->inbound_sessions = NULL; while (NULL != (rc = GNUNET_CONTAINER_heap_remove_root (plugin->defrags))) @@ -2201,16 +2249,17 @@ libgnunet_plugin_transport_udp_done (void *cls) GNUNET_SCHEDULER_cancel (plugin->select_broadcast_task); plugin->select_broadcast_task = GNUNET_SCHEDULER_NO_TASK; } - if (plugin->send_broadcast_task != GNUNET_SCHEDULER_NO_TASK) + if (plugin->send_broadcast_task != GNUNET_SCHEDULER_NO_TASK) { - GNUNET_SCHEDULER_cancel (plugin->send_broadcast_task ); - plugin->send_broadcast_task = GNUNET_SCHEDULER_NO_TASK; + GNUNET_SCHEDULER_cancel (plugin->send_broadcast_task); + plugin->send_broadcast_task = GNUNET_SCHEDULER_NO_TASK; } if (plugin->broadcast_mst != NULL) - GNUNET_SERVER_mst_destroy(plugin->broadcast_mst); + GNUNET_SERVER_mst_destroy (plugin->broadcast_mst); if (plugin->sockv4_broadcast != NULL) { - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4_broadcast)); + GNUNET_break (GNUNET_OK == + GNUNET_NETWORK_socket_close (plugin->sockv4_broadcast)); plugin->sockv4_broadcast = NULL; } GNUNET_NETWORK_fdset_destroy (plugin->broadcast_rs); diff --git a/src/transport/plugin_transport_udp_new.c b/src/transport/plugin_transport_udp_new.c index 325c5d893..7eb4cbe87 100644 --- a/src/transport/plugin_transport_udp_new.c +++ b/src/transport/plugin_transport_udp_new.c @@ -299,21 +299,22 @@ struct Plugin }; -int delete_session_iterator (void *cls, - const GNUNET_HashCode * key, - void *value) +int +delete_session_iterator (void *cls, const GNUNET_HashCode * key, void *value) { struct Session *s = (struct Session *) value; + if (s->invalidation_task != GNUNET_SCHEDULER_NO_TASK) { - GNUNET_SCHEDULER_cancel(s->invalidation_task); + GNUNET_SCHEDULER_cancel (s->invalidation_task); s->invalidation_task = GNUNET_SCHEDULER_NO_TASK; } - GNUNET_CONTAINER_multihashmap_remove(s->plugin->sessions, key, s); + GNUNET_CONTAINER_multihashmap_remove (s->plugin->sessions, key, s); GNUNET_free (s); return GNUNET_YES; } + /** * Disconnect from a remote node. Clean up session if we have one for this peer * @@ -326,7 +327,8 @@ udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) { struct Plugin *plugin = cls; - GNUNET_CONTAINER_multihashmap_get_multiple(plugin, &target->hashPubKey, &delete_session_iterator, NULL); + GNUNET_CONTAINER_multihashmap_get_multiple (plugin, &target->hashPubKey, + &delete_session_iterator, NULL); } @@ -370,25 +372,25 @@ udp_send (struct Plugin *plugin, const struct sockaddr *sa, { GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sendto"); LOG (GNUNET_ERROR_TYPE_ERROR, - "UDP transmited %u-byte message to %s (%d: %s)\n", - (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen), - (int) sent, (sent < 0) ? STRERROR (errno) : "ok"); + "UDP transmited %u-byte message to %s (%d: %s)\n", + (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen), (int) sent, + (sent < 0) ? STRERROR (errno) : "ok"); } LOG (GNUNET_ERROR_TYPE_DEBUG, - "UDP transmited %u-byte message to %s (%d: %s)\n", - (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen), - (int) sent, (sent < 0) ? STRERROR (errno) : "ok"); + "UDP transmited %u-byte message to %s (%d: %s)\n", + (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen), (int) sent, + (sent < 0) ? STRERROR (errno) : "ok"); return sent; } static struct Session * create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, - const void *addr, size_t addrlen, - GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) + const void *addr, size_t addrlen, + GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) { - struct Session * s; + struct Session *s; const struct IPv4UdpAddress *t4; const struct IPv6UdpAddress *t6; struct sockaddr_in *v4; @@ -403,9 +405,7 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, return NULL; } t4 = addr; - s = - GNUNET_malloc (sizeof (struct Session) + - sizeof (struct sockaddr_in)); + s = GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in)); len = sizeof (struct sockaddr_in); v4 = (struct sockaddr_in *) &s[1]; v4->sin_family = AF_INET; @@ -421,9 +421,7 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, return NULL; } t6 = addr; - s = - GNUNET_malloc (sizeof (struct Session) + - sizeof (struct sockaddr_in6)); + s = GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in6)); len = sizeof (struct sockaddr_in6); v6 = (struct sockaddr_in6 *) &s[1]; v6->sin6_family = AF_INET6; @@ -457,13 +455,17 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, static void invalidation_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - struct Session * s = cls; - s->invalidation_task = GNUNET_SCHEDULER_NO_TASK; - LOG (GNUNET_ERROR_TYPE_ERROR, - "Session %X (`%s') is now invalid\n", s, GNUNET_a2s (s->sock_addr,s->addrlen)); + struct Session *s = cls; - s->plugin->env->session_end(s->plugin->env->cls, &s->target, s); - GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(s->plugin->sessions, &s->target.hashPubKey, s)); + s->invalidation_task = GNUNET_SCHEDULER_NO_TASK; + LOG (GNUNET_ERROR_TYPE_ERROR, "Session %X (`%s') is now invalid\n", s, + GNUNET_a2s (s->sock_addr, s->addrlen)); + + s->plugin->env->session_end (s->plugin->env->cls, &s->target, s); + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove (s->plugin->sessions, + &s->target.hashPubKey, + s)); GNUNET_free (s); } @@ -534,10 +536,10 @@ udp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, } LOG (GNUNET_ERROR_TYPE_DEBUG, - "UDP transmits %u-byte message to `%s' using address `%s' session 0x%X mode %i\n", - msgbuf_size, GNUNET_i2s (target), - udp_address_to_string (NULL, addr, addrlen), - session, force_address); + "UDP transmits %u-byte message to `%s' using address `%s' session 0x%X mode %i\n", + msgbuf_size, GNUNET_i2s (target), udp_address_to_string (NULL, addr, + addrlen), + session, force_address); /* no valid address given */ if ((addr = NULL) || (addrlen == 0)) @@ -562,10 +564,13 @@ udp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, if (force_address == GNUNET_SYSERR) return GNUNET_SYSERR; /* create new session */ - s = create_session(plugin, target, addr, addrlen, cont, cont_cls); - GNUNET_CONTAINER_multihashmap_put(plugin->sessions, &target->hashPubKey, s, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); + s = create_session (plugin, target, addr, addrlen, cont, cont_cls); + GNUNET_CONTAINER_multihashmap_put (plugin->sessions, &target->hashPubKey, s, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); /* schedule invalidation task */ - s->invalidation_task = GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &invalidation_task, NULL); + s->invalidation_task = + GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, + &invalidation_task, NULL); } /* Message */ @@ -576,12 +581,16 @@ udp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, udp->sender = *plugin->env->my_identity; memcpy (&udp[1], msgbuf, msgbuf_size); - struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); + struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); + if (s->flow_delay_from_other_peer.abs_value > now.abs_value) { - struct GNUNET_TIME_Relative delta = GNUNET_TIME_absolute_get_difference(now, s->flow_delay_from_other_peer); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "We try to send to early! Should in %llu!\n", delta.rel_value); + struct GNUNET_TIME_Relative delta = + GNUNET_TIME_absolute_get_difference (now, + s->flow_delay_from_other_peer); + + LOG (GNUNET_ERROR_TYPE_DEBUG, "We try to send to early! Should in %llu!\n", + delta.rel_value); } else LOG (GNUNET_ERROR_TYPE_DEBUG, "We can send!\n"); @@ -598,11 +607,11 @@ udp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, /* send with fragmentation */ else { - s->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats, UDP_MTU, + s->frag = + GNUNET_FRAGMENT_context_create (plugin->env->stats, UDP_MTU, &plugin->tracker, plugin->last_expected_delay, - &udp->header, &send_fragment, - s); + &udp->header, &send_fragment, s); } return mlen; } @@ -621,7 +630,7 @@ process_inbound_tokenized_messages (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) { struct Plugin *plugin = cls; - struct Session * s = client; + struct Session *s = client; struct GNUNET_ATS_Information distance; struct GNUNET_TIME_Relative delay; @@ -629,11 +638,12 @@ process_inbound_tokenized_messages (void *cls, void *client, distance.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); distance.value = htonl (1); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Giving Session %X %s to transport\n", s->session, GNUNET_i2s(&s->target)); - delay = plugin->env->receive (plugin->env->cls, &s->target, hdr, &distance, 1, s, - // FIXME: USE UDP ADDRESSES!!!! - s->sock_addr, s->addrlen); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Giving Session %X %s to transport\n", + s->session, GNUNET_i2s (&s->target)); + delay = + plugin->env->receive (plugin->env->cls, &s->target, hdr, &distance, 1, s, + // FIXME: USE UDP ADDRESSES!!!! + s->sock_addr, s->addrlen); s->flow_delay_for_other_peer = delay; } @@ -691,54 +701,54 @@ process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg, } #if DEBUG_UDP LOG (GNUNET_ERROR_TYPE_DEBUG, - "Received message with %u bytes from peer `%s' at `%s'\n", - (unsigned int) ntohs (msg->header.size), - GNUNET_i2s (&msg->sender), GNUNET_a2s (sender_addr, - sender_addr_len)); + "Received message with %u bytes from peer `%s' at `%s'\n", + (unsigned int) ntohs (msg->header.size), GNUNET_i2s (&msg->sender), + GNUNET_a2s (sender_addr, sender_addr_len)); #endif - const struct UDPMessage * udp_msg = (const struct UDPMessage *) msg; + const struct UDPMessage *udp_msg = (const struct UDPMessage *) msg; + LOG (GNUNET_ERROR_TYPE_DEBUG, - "Lookup inbound UDP sessions for peer `%s' address `%s'\n", - GNUNET_i2s (&udp_msg->sender), - udp_address_to_string(NULL, arg, args)); + "Lookup inbound UDP sessions for peer `%s' address `%s'\n", + GNUNET_i2s (&udp_msg->sender), udp_address_to_string (NULL, arg, args)); /* create a session for inbound connections */ - struct Session * s = NULL; - s = find_inbound_session (plugin, &udp_msg->sender, sender_addr, sender_addr_len); + struct Session *s = NULL; + + s = find_inbound_session (plugin, &udp_msg->sender, sender_addr, + sender_addr_len); if (s != NULL) { LOG (GNUNET_ERROR_TYPE_DEBUG, - "Found existing inbound UDP sessions 0x%X for peer `%s' address `%s'\n", - s, - GNUNET_i2s (&s->target), - udp_address_to_string(NULL, arg, args)); + "Found existing inbound UDP sessions 0x%X for peer `%s' address `%s'\n", + s, GNUNET_i2s (&s->target), udp_address_to_string (NULL, arg, args)); } else { s = create_session (plugin, &udp_msg->sender, arg, args, NULL, NULL); LOG (GNUNET_ERROR_TYPE_DEBUG, - "Creating inbound UDP sessions 0x%X for peer `%s' address `%s'\n", - s, - GNUNET_i2s (&s->target), - udp_address_to_string(NULL, arg, args)); - - GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (plugin->sessions, - &s->target.hashPubKey, - s, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); + "Creating inbound UDP sessions 0x%X for peer `%s' address `%s'\n", s, + GNUNET_i2s (&s->target), udp_address_to_string (NULL, arg, args)); + + GNUNET_assert (GNUNET_OK == + GNUNET_CONTAINER_multihashmap_put (plugin->sessions, + &s->target.hashPubKey, s, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); } - s->valid_until = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); + s->valid_until = + GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), + GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); if (s->invalidation_task != GNUNET_SCHEDULER_NO_TASK) { - GNUNET_SCHEDULER_cancel(s->invalidation_task); + GNUNET_SCHEDULER_cancel (s->invalidation_task); s->invalidation_task = GNUNET_SCHEDULER_NO_TASK; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Rescheduling %X' `%s'\n", - s, udp_address_to_string(NULL, arg, args)); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Rescheduling %X' `%s'\n", s, + udp_address_to_string (NULL, arg, args)); } - s->invalidation_task = GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &invalidation_task, s); + s->invalidation_task = + GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, + &invalidation_task, s); /* we received from peer, so session is bidirectional and reliable */ s->bidirectional = GNUNET_YES; @@ -768,7 +778,7 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) struct ReceiveContext *rc; struct GNUNET_TIME_Absolute now; struct FindReceiveContext frc; - struct Session * s = NULL; + struct Session *s = NULL; struct GNUNET_TIME_Relative flow_delay; fromlen = sizeof (addr); @@ -784,8 +794,8 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) msg = (const struct GNUNET_MessageHeader *) buf; LOG (GNUNET_ERROR_TYPE_DEBUG, - "UDP received %u-byte message from `%s' type %i\n", (unsigned int) ret, - GNUNET_a2s ((const struct sockaddr *) addr, fromlen), ntohs(msg->type)); + "UDP received %u-byte message from `%s' type %i\n", (unsigned int) ret, + GNUNET_a2s ((const struct sockaddr *) addr, fromlen), ntohs (msg->type)); if (ret != ntohs (msg->size)) { @@ -814,26 +824,25 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) } udp_ack = (const struct UDP_ACK_Message *) msg; LOG (GNUNET_ERROR_TYPE_DEBUG, - "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", - (unsigned int) ntohs (msg->size), GNUNET_i2s (&udp->sender), - GNUNET_a2s ((const struct sockaddr *) addr, fromlen)); + "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", + (unsigned int) ntohs (msg->size), GNUNET_i2s (&udp->sender), + GNUNET_a2s ((const struct sockaddr *) addr, fromlen)); // TODO Guess a session from address, give it defragmenter and check in process_udp if guess was right s = guess_session (plugin->sessions, addr, addrlen); if (GNUNET_OK != GNUNET_FRAGMENT_process_ack (peer_session->frag, ack)) - // ... other stuff - return; + // ... other stuff + return; case GNUNET_MESSAGE_TYPE_FRAGMENT: - LOG (GNUNET_ERROR_TYPE_DEBUG, - "UDP processes %u-byte fragment from `%s'\n", - (unsigned int) ntohs (msg->size), - GNUNET_a2s ((const struct sockaddr *) addr, fromlen)); + LOG (GNUNET_ERROR_TYPE_DEBUG, "UDP processes %u-byte fragment from `%s'\n", + (unsigned int) ntohs (msg->size), + GNUNET_a2s ((const struct sockaddr *) addr, fromlen)); // TODO Guess a session from address, give it defragmenter and check in process_udp if guess was right s = guess_session (plugin->sessions, addr, addrlen); if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (rc->defrag, msg)) - // other stuff - return; + // other stuff + return; default: GNUNET_break_op (0); return; @@ -995,7 +1004,7 @@ udp_address_to_string (void *cls, const void *addr, size_t addrlen) } inet_ntop (af, sb, buf, INET6_ADDRSTRLEN); GNUNET_snprintf (rbuf, sizeof (rbuf), (af == AF_INET6) ? "[%s]:%u" : "%s:%u", - buf, port); + buf, port); return rbuf; } @@ -1206,8 +1215,8 @@ libgnunet_plugin_transport_udp_init (void *cls) if (port > 65535) { LOG (GNUNET_ERROR_TYPE_WARNING, - _("Given `%s' option is out of range: %llu > %u\n"), "PORT", - port, 65535); + _("Given `%s' option is out of range: %llu > %u\n"), "PORT", port, + 65535); return NULL; } memset (&serverAddrv6, 0, sizeof (serverAddrv6)); @@ -1235,8 +1244,8 @@ libgnunet_plugin_transport_udp_init (void *cls) "BINDTO", &plugin->bind4_address)) { LOG (GNUNET_ERROR_TYPE_DEBUG, - "Binding udp plugin to specific address: `%s'\n", - plugin->bind4_address); + "Binding udp plugin to specific address: `%s'\n", + plugin->bind4_address); if (1 != inet_pton (AF_INET, plugin->bind4_address, &serverAddrv4.sin_addr)) { GNUNET_free (plugin->bind4_address); @@ -1251,13 +1260,13 @@ libgnunet_plugin_transport_udp_init (void *cls) "BINDTO6", &plugin->bind6_address)) { LOG (GNUNET_ERROR_TYPE_DEBUG, - "Binding udp plugin to specific address: `%s'\n", - plugin->bind6_address); + "Binding udp plugin to specific address: `%s'\n", + plugin->bind6_address); if (1 != inet_pton (AF_INET6, plugin->bind6_address, &serverAddrv6.sin6_addr)) { LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid IPv6 address: `%s'\n"), - plugin->bind6_address); + plugin->bind6_address); GNUNET_free_non_null (plugin->bind4_address); GNUNET_free (plugin->bind6_address); GNUNET_free (plugin); @@ -1296,7 +1305,7 @@ libgnunet_plugin_transport_udp_init (void *cls) serverAddr = (struct sockaddr *) &serverAddrv6; #if DEBUG_UDP LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv6 port %d\n", - ntohs (serverAddrv6.sin6_port)); + ntohs (serverAddrv6.sin6_port)); #endif tries = 0; while (GNUNET_NETWORK_socket_bind (plugin->sockv6, serverAddr, addrlen) != @@ -1305,8 +1314,8 @@ libgnunet_plugin_transport_udp_init (void *cls) serverAddrv6.sin6_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */ #if DEBUG_UDP LOG (GNUNET_ERROR_TYPE_DEBUG, - "IPv6 Binding failed, trying new port %d\n", - ntohs (serverAddrv6.sin6_port)); + "IPv6 Binding failed, trying new port %d\n", + ntohs (serverAddrv6.sin6_port)); #endif tries++; if (tries > 10) @@ -1344,7 +1353,7 @@ libgnunet_plugin_transport_udp_init (void *cls) serverAddr = (struct sockaddr *) &serverAddrv4; #if DEBUG_UDP LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv4 port %d\n", - ntohs (serverAddrv4.sin_port)); + ntohs (serverAddrv4.sin_port)); #endif tries = 0; while (GNUNET_NETWORK_socket_bind (plugin->sockv4, serverAddr, addrlen) != @@ -1352,9 +1361,8 @@ libgnunet_plugin_transport_udp_init (void *cls) { serverAddrv4.sin_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */ #if DEBUG_UDP - LOG (GNUNET_ERROR_TYPE_DEBUG, - "IPv4 Binding failed, trying new port %d\n", - ntohs (serverAddrv4.sin_port)); + LOG (GNUNET_ERROR_TYPE_DEBUG, "IPv4 Binding failed, trying new port %d\n", + ntohs (serverAddrv4.sin_port)); #endif tries++; if (tries > 10) @@ -1411,8 +1419,8 @@ libgnunet_plugin_transport_udp_done (void *cls) NULL); GNUNET_CONTAINER_multihashmap_destroy (plugin->sessions); plugin->sessions = NULL; - GNUNET_CONTAINER_multihashmap_iterate (plugin->inbound_sessions, &destroy_inbound_session, - NULL); + GNUNET_CONTAINER_multihashmap_iterate (plugin->inbound_sessions, + &destroy_inbound_session, NULL); GNUNET_CONTAINER_multihashmap_destroy (plugin->inbound_sessions); plugin->inbound_sessions = NULL; while (NULL != (rc = GNUNET_CONTAINER_heap_remove_root (plugin->defrags))) diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c index 32f047d65..270829e68 100644 --- a/src/transport/plugin_transport_unix.c +++ b/src/transport/plugin_transport_unix.c @@ -731,9 +731,8 @@ unix_demultiplexer (struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, un->sun_path); #endif plugin->env->receive (plugin->env->cls, sender, currhdr, - (const struct GNUNET_ATS_Information *) - &distance, 1, NULL, un->sun_path, - strlen (un->sun_path) + 1); + (const struct GNUNET_ATS_Information *) &distance, 1, + NULL, un->sun_path, strlen (un->sun_path) + 1); } diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index 041e80f86..cbab8cb0f 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c @@ -862,7 +862,7 @@ session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) struct Sessionqueue *queue = cls; GNUNET_assert (queue != NULL); - GNUNET_assert(queue->content != NULL); + GNUNET_assert (queue->content != NULL); queue->content->timeout_task = GNUNET_SCHEDULER_NO_TASK; if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) { @@ -873,9 +873,10 @@ session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) (queue->content->last_activity, SESSION_TIMEOUT)).rel_value == 0) { - GNUNET_assert(queue->content->mac != NULL); - GNUNET_assert(queue->content->mac->plugin != NULL); - GNUNET_STATISTICS_update (queue->content->mac->plugin->env->stats, _("# wlan session timeouts"), 1, GNUNET_NO); + GNUNET_assert (queue->content->mac != NULL); + GNUNET_assert (queue->content->mac->plugin != NULL); + GNUNET_STATISTICS_update (queue->content->mac->plugin->env->stats, + _("# wlan session timeouts"), 1, GNUNET_NO); free_session (queue->content->mac->plugin, queue, GNUNET_YES); } else @@ -900,7 +901,8 @@ create_session (struct Plugin *plugin, struct MacEndpoint *endpoint, { GNUNET_assert (endpoint != NULL); GNUNET_assert (plugin != NULL); - GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan session created"), 1, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan session created"), 1, + GNUNET_NO); struct Sessionqueue *queue = GNUNET_malloc (sizeof (struct Sessionqueue) + sizeof (struct Session)); @@ -983,7 +985,8 @@ queue_session (struct Plugin *plugin, struct Session *session) GNUNET_CONTAINER_DLL_insert_tail (plugin->pending_Sessions_head, plugin->pending_Sessions_tail, queue); plugin->pendingsessions++; - GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending sessions"), plugin->pendingsessions, GNUNET_NO); + GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"), + plugin->pendingsessions, GNUNET_NO); } } @@ -1132,24 +1135,25 @@ get_next_queue_session (struct Plugin *plugin) pm = session->pending_message_head; if (pm == NULL) - { + { #if DEBUG_wlan - GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME, - "pending message is empty, should not happen. session %p\n", - session); + GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME, + "pending message is empty, should not happen. session %p\n", + session); #endif - sessionqueue_alt = sessionqueue; - sessionqueue = sessionqueue->next; - plugin->pendingsessions--; - GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending sessions"), plugin->pendingsessions, GNUNET_NO); - GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head, - plugin->pending_Sessions_tail, - sessionqueue_alt); + sessionqueue_alt = sessionqueue; + sessionqueue = sessionqueue->next; + plugin->pendingsessions--; + GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"), + plugin->pendingsessions, GNUNET_NO); + GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head, + plugin->pending_Sessions_tail, + sessionqueue_alt); - GNUNET_free (sessionqueue_alt); - continue; + GNUNET_free (sessionqueue_alt); + continue; - } + } //check for message timeout if (GNUNET_TIME_absolute_get_remaining (pm->timeout).rel_value > 0) @@ -1161,7 +1165,8 @@ get_next_queue_session (struct Plugin *plugin) FRAGMENT_QUEUE_MESSAGES_OUT_PER_SESSION)) { plugin->pendingsessions--; - GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending sessions"), plugin->pendingsessions, GNUNET_NO); + GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"), + plugin->pendingsessions, GNUNET_NO); GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head, plugin->pending_Sessions_tail, sessionqueue); @@ -1191,7 +1196,8 @@ get_next_queue_session (struct Plugin *plugin) sessionqueue_alt = sessionqueue; sessionqueue = sessionqueue->next; plugin->pendingsessions--; - GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending sessions"), plugin->pendingsessions, GNUNET_NO); + GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"), + plugin->pendingsessions, GNUNET_NO); GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head, plugin->pending_Sessions_tail, sessionqueue_alt); @@ -1217,38 +1223,40 @@ free_fragment_message (struct Plugin *plugin, struct FragmentMessage *fm) struct FragmentMessage_queue *fmq; struct FragmentMessage_queue *fmq_next; - fmq = plugin->sending_messages_head; - while (fmq != NULL) + fmq = plugin->sending_messages_head; + while (fmq != NULL) + { + fmq_next = fmq->next; + if (fmq->content == fm) { - fmq_next = fmq->next; - if (fmq->content == fm) - { - GNUNET_CONTAINER_DLL_remove (plugin->sending_messages_head, - plugin->sending_messages_tail, fmq); - GNUNET_free (fmq); - } - fmq = fmq_next; + GNUNET_CONTAINER_DLL_remove (plugin->sending_messages_head, + plugin->sending_messages_tail, fmq); + GNUNET_free (fmq); } + fmq = fmq_next; + } - (session->mac->fragment_messages_out_count)--; - session->fragment_messages_out_count--; - plugin->pending_Fragment_Messages--; - GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending fragments"), plugin->pending_Fragment_Messages, GNUNET_NO); - GNUNET_CONTAINER_DLL_remove (endpoint->sending_messages_head, - endpoint->sending_messages_tail, fm); - GNUNET_FRAGMENT_context_destroy (fm->fragcontext); - if (fm->timeout_task != GNUNET_SCHEDULER_NO_TASK){ - GNUNET_SCHEDULER_cancel (fm->timeout_task); - fm->timeout_task = GNUNET_SCHEDULER_NO_TASK; - } + (session->mac->fragment_messages_out_count)--; + session->fragment_messages_out_count--; + plugin->pending_Fragment_Messages--; + GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending fragments"), + plugin->pending_Fragment_Messages, GNUNET_NO); + GNUNET_CONTAINER_DLL_remove (endpoint->sending_messages_head, + endpoint->sending_messages_tail, fm); + GNUNET_FRAGMENT_context_destroy (fm->fragcontext); + if (fm->timeout_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel (fm->timeout_task); + fm->timeout_task = GNUNET_SCHEDULER_NO_TASK; + } - GNUNET_free (fm); + GNUNET_free (fm); - queue_session (plugin, session); + queue_session (plugin, session); #if DEBUG_wlan - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, - "Free pending fragment messages %p, session %p\n", fm, - session); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, + "Free pending fragment messages %p, session %p\n", fm, + session); #endif } @@ -1499,15 +1507,17 @@ wlan_transport_start_wlan_helper (struct Plugin *plugin) else { char cwd[FILENAME_MAX]; - GNUNET_assert (getcwd(cwd, sizeof(cwd)) != NULL); - GNUNET_asprintf (&absolute_filename, "%s%s%s", cwd, DIR_SEPARATOR_STR, filenameloopback); + GNUNET_assert (getcwd (cwd, sizeof (cwd)) != NULL); + + GNUNET_asprintf (&absolute_filename, "%s%s%s", cwd, DIR_SEPARATOR_STR, + filenameloopback); if (GNUNET_DISK_file_test (filenameloopback) != GNUNET_YES) { GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME, "Helper `%s' not found! %i\n", absolute_filename); - GNUNET_break(0); + GNUNET_break (0); } } } @@ -1552,14 +1562,16 @@ wlan_transport_start_wlan_helper (struct Plugin *plugin) "Starting gnunet-wlan-helper loopback 1 process cmd: %s %s %i\n", absolute_filename, plugin->interface, plugin->testmode); #endif - plugin->server_proc = GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout, - absolute_filename, absolute_filename, "1", - NULL); + plugin->server_proc = + GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout, + absolute_filename, absolute_filename, "1", + NULL); if (plugin->server_proc == NULL) { - GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME, - "`%s' not found, please look if it exists and is in the $PATH variable!\n", absolute_filename); - GNUNET_break (0); + GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME, + "`%s' not found, please look if it exists and is in the $PATH variable!\n", + absolute_filename); + GNUNET_break (0); } } else if (plugin->testmode == 2) @@ -1570,18 +1582,20 @@ wlan_transport_start_wlan_helper (struct Plugin *plugin) absolute_filename, plugin->interface, plugin->testmode); #endif - plugin->server_proc = GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout, - absolute_filename, absolute_filename, "2", - NULL); - if (plugin->server_proc == NULL) - { - GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME, - "`%s' not found, please look if it exists and is in the $PATH variable!\n", absolute_filename); + plugin->server_proc = + GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout, + absolute_filename, absolute_filename, "2", + NULL); + if (plugin->server_proc == NULL) + { + GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME, + "`%s' not found, please look if it exists and is in the $PATH variable!\n", + absolute_filename); GNUNET_break (0); - } + } } if (absolute_filename != NULL) - GNUNET_free(absolute_filename); + GNUNET_free (absolute_filename); if (plugin->server_proc == NULL) { #if DEBUG_wlan @@ -1632,8 +1646,8 @@ static int wlan_transport_stop_wlan_helper (struct Plugin *plugin) { #if DEBUG_wlan - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, - "Stoping WLAN helper process\n"); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, + "Stoping WLAN helper process\n"); #endif if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK) @@ -1657,7 +1671,7 @@ wlan_transport_stop_wlan_helper (struct Plugin *plugin) GNUNET_DISK_pipe_close (plugin->server_stdout); GNUNET_DISK_pipe_close (plugin->server_stdin); GNUNET_OS_process_kill (plugin->server_proc, SIGKILL); - GNUNET_OS_process_wait(plugin->server_proc); + GNUNET_OS_process_wait (plugin->server_proc); GNUNET_OS_process_close (plugin->server_proc); return GNUNET_YES; @@ -1673,31 +1687,32 @@ delay_restart_helper (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct Finish_send *finish = cls; struct Plugin *plugin; + plugin = finish->plugin; plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK; if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) { - GNUNET_free_non_null(finish->msgstart); + GNUNET_free_non_null (finish->msgstart); GNUNET_free (finish); return; } - wlan_transport_start_wlan_helper(plugin); + wlan_transport_start_wlan_helper (plugin); if (finish->size != 0) - { - plugin->server_write_task = - GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, - plugin->server_stdin_handle, - &finish_sending, finish); - } + { + plugin->server_write_task = + GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, + plugin->server_stdin_handle, + &finish_sending, finish); + } else - { - set_next_send (plugin); - GNUNET_free_non_null(finish->msgstart); - GNUNET_free (finish); - } + { + set_next_send (plugin); + GNUNET_free_non_null (finish->msgstart); + GNUNET_free (finish); + } } @@ -1707,14 +1722,15 @@ delay_restart_helper (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) * @param finish pointer to the Finish_send struct to finish */ static void -restart_helper(struct Plugin *plugin, struct Finish_send *finish) +restart_helper (struct Plugin *plugin, struct Finish_send *finish) { - static struct GNUNET_TIME_Relative next_try = {1000}; - GNUNET_assert(finish != NULL); + static struct GNUNET_TIME_Relative next_try = { 1000 }; + GNUNET_assert (finish != NULL); - wlan_transport_stop_wlan_helper(plugin); - plugin->server_write_task = GNUNET_SCHEDULER_add_delayed (next_try, &delay_restart_helper, finish); - GNUNET_TIME_relative_multiply(next_try, HELPER_RESTART_SCALING_FACTOR); + wlan_transport_stop_wlan_helper (plugin); + plugin->server_write_task = + GNUNET_SCHEDULER_add_delayed (next_try, &delay_restart_helper, finish); + GNUNET_TIME_relative_multiply (next_try, HELPER_RESTART_SCALING_FACTOR); } @@ -1740,24 +1756,24 @@ finish_sending (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) return; } bytes = - GNUNET_DISK_file_write (plugin->server_stdin_handle, finish->head_of_next_write, - finish->size); + GNUNET_DISK_file_write (plugin->server_stdin_handle, + finish->head_of_next_write, finish->size); if (bytes != finish->size) { if (bytes != GNUNET_SYSERR) - { + { finish->head_of_next_write += bytes; finish->size -= bytes; plugin->server_write_task = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdin_handle, &finish_sending, finish); - } + } else - { - restart_helper(plugin, finish); - } + { + restart_helper (plugin, finish); + } } else { @@ -1788,11 +1804,12 @@ send_hello_beacon (struct Plugin *plugin) struct Radiotap_Send *radioHeader; struct GNUNET_MessageHeader *msgheader2; const struct GNUNET_MessageHeader *hello; - struct Finish_send * finish; + struct Finish_send *finish; GNUNET_assert (plugin != NULL); - GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan hello beacons send"), 1, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan hello beacons send"), + 1, GNUNET_NO); hello = plugin->env->get_our_hello (); hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello); @@ -1812,10 +1829,10 @@ send_hello_beacon (struct Plugin *plugin) msgheader2 = (struct GNUNET_MessageHeader *) &ieeewlanheader[1]; /*msgheader2->size = - htons (GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello) + - sizeof (struct GNUNET_MessageHeader)); - - msgheader2->type = htons (GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT);*/ + * htons (GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello) + + * sizeof (struct GNUNET_MessageHeader)); + * + * msgheader2->type = htons (GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT); */ memcpy (msgheader2, hello, hello_size); bytes = GNUNET_DISK_file_write (plugin->server_stdin_handle, msgheader, size); @@ -1831,17 +1848,17 @@ send_hello_beacon (struct Plugin *plugin) finish->head_of_next_write = NULL; finish->size = 0; finish->msgstart = NULL; - restart_helper(plugin, finish); + restart_helper (plugin, finish); set_next_beacon_time (plugin); } else - { + { GNUNET_assert (bytes == size); set_next_beacon_time (plugin); set_next_send (plugin); - } + } GNUNET_free (msgheader); @@ -1951,7 +1968,8 @@ check_fragment_queue (struct Plugin *plugin) session->mac->fragment_messages_out_count++; session->fragment_messages_out_count++; plugin->pending_Fragment_Messages++; - GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending fragments"), plugin->pending_Fragment_Messages, GNUNET_NO); + GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending fragments"), + plugin->pending_Fragment_Messages, GNUNET_NO); fm = GNUNET_malloc (sizeof (struct FragmentMessage)); fm->session = session; @@ -2012,7 +2030,7 @@ send_ack (struct Plugin *plugin) ssize_t bytes; struct AckSendQueue *ack; - struct Finish_send * finish; + struct Finish_send *finish; ack = plugin->ack_send_queue_head; @@ -2025,7 +2043,8 @@ send_ack (struct Plugin *plugin) #endif GNUNET_assert (plugin != NULL); - GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan acks send"), 1, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan acks send"), 1, + GNUNET_NO); getRadiotapHeader (plugin, ack->endpoint, ack->radioHeader); getWlanHeader (ack->ieeewlanheader, &ack->endpoint->addr, plugin, @@ -2045,7 +2064,7 @@ send_ack (struct Plugin *plugin) finish->head_of_next_write = NULL; finish->size = 0; finish->msgstart = NULL; - restart_helper(plugin, finish); + restart_helper (plugin, finish); } else { @@ -2067,6 +2086,7 @@ static void do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct Plugin *plugin = cls; + GNUNET_assert (plugin != NULL); plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK; @@ -2094,7 +2114,8 @@ do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) if (plugin->sending_messages_head != NULL) { - GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan fragments send"), 1, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan fragments send"), 1, + GNUNET_NO); fmq = plugin->sending_messages_head; fm = fmq->content; @@ -2136,16 +2157,16 @@ do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) finish->head_of_next_write = fm->frag; finish->size = fm->size; - restart_helper(plugin, finish); + restart_helper (plugin, finish); } else { finish->head_of_next_write = fm->frag + bytes; finish->size = fm->size - bytes; plugin->server_write_task = - GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, - plugin->server_stdin_handle, - &finish_sending, finish); + GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, + plugin->server_stdin_handle, + &finish_sending, finish); } fm->frag = NULL; @@ -2192,13 +2213,15 @@ wlan_plugin_address_suggested (void *cls, const void *addr, size_t addrlen) /* TODO check for bad addresses like multicast, broadcast, etc */ #if DEBUG_wlan GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, - "wlan_plugin_address_suggested got good address, size %u!\n", addrlen); + "wlan_plugin_address_suggested got good address, size %u!\n", + addrlen); #endif return GNUNET_OK; } #if DEBUG_wlan - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, - "wlan_plugin_address_suggested got bad address, size %u!\n", addrlen); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, + "wlan_plugin_address_suggested got bad address, size %u!\n", + addrlen); #endif return GNUNET_SYSERR; } @@ -2239,6 +2262,7 @@ wlan_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, struct Plugin *plugin = cls; struct PendingMessage *newmsg; struct WlanHeader *wlanheader; + GNUNET_assert (plugin != NULL); //check if msglen > 0 GNUNET_assert (msgbuf_size > 0); @@ -2258,7 +2282,8 @@ wlan_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, } } - GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan messages queued"), 1, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan messages queued"), 1, + GNUNET_NO); //queue message: @@ -2348,7 +2373,8 @@ free_macendpoint (struct Plugin *plugin, struct MacEndpoint *endpoint) endpoint->timeout_task = GNUNET_SCHEDULER_NO_TASK; } plugin->mac_count--; - GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan mac endpoints"), plugin->mac_count, GNUNET_NO); + GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan mac endpoints"), + plugin->mac_count, GNUNET_NO); GNUNET_free (endpoint); } @@ -2386,7 +2412,8 @@ free_session (struct Plugin *plugin, struct Sessionqueue *queue, if (pendingsession_tmp->content == queue->content) { plugin->pendingsessions--; - GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending sessions"), plugin->pendingsessions, GNUNET_NO); + GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"), + plugin->pendingsessions, GNUNET_NO); GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head, plugin->pending_Sessions_tail, pendingsession_tmp); @@ -2423,12 +2450,14 @@ free_session (struct Plugin *plugin, struct Sessionqueue *queue, GNUNET_CONTAINER_DLL_remove (endpoint->sessions_head, endpoint->sessions_tail, queue); //Check that no ohter session on this endpoint for this session exits - GNUNET_assert(search_session(plugin, endpoint, &queue->content->target) == NULL); + GNUNET_assert (search_session (plugin, endpoint, &queue->content->target) == + NULL); if (endpoint->sessions_head == NULL && do_free_macendpoint == GNUNET_YES) { free_macendpoint (plugin, endpoint); //check if no endpoint with the same address exists - GNUNET_assert(get_macendpoint(plugin, &endpoint->addr, GNUNET_NO) == NULL); + GNUNET_assert (get_macendpoint (plugin, &endpoint->addr, GNUNET_NO) == + NULL); } if (queue->content->timeout_task != GNUNET_SCHEDULER_NO_TASK) @@ -2507,31 +2536,31 @@ wlan_plugin_address_pretty_printer (void *cls, const char *type, const unsigned char *input; //GNUNET_assert(cls !=NULL); - if (addrlen != sizeof(struct MacAddress)) + if (addrlen != sizeof (struct MacAddress)) { /* invalid address (MAC addresses have 6 bytes) */ //GNUNET_break (0); #if DEBUG_wlan - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, - "Func wlan_plugin_address_pretty_printer got size: %u, worng size!\n", - addrlen); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, + "Func wlan_plugin_address_pretty_printer got size: %u, worng size!\n", + addrlen); #endif - asc(asc_cls, NULL); + asc (asc_cls, NULL); return; } input = (const unsigned char *) addr; GNUNET_asprintf (&ret, - "Transport %s: %s Mac-Address %.2X:%.2X:%.2X:%.2X:%.2X:%.2X",type, - PROTOCOL_PREFIX, input[0], input[1], input[2], input[3], - input[4], input[5]); + "Transport %s: %s Mac-Address %.2X:%.2X:%.2X:%.2X:%.2X:%.2X", + type, PROTOCOL_PREFIX, input[0], input[1], input[2], + input[3], input[4], input[5]); #if DEBUG_wlan GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, "Func wlan_plugin_address_pretty_printer got size: %u, nummeric %u, type %s; made string: %s\n", addrlen, numeric, type, ret); #endif - asc ( asc_cls, ret); + asc (asc_cls, ret); //only one mac address per plugin - asc ( asc_cls, NULL); + asc (asc_cls, NULL); } @@ -2571,7 +2600,9 @@ wlan_data_message_handler (void *cls, const struct GNUNET_MessageHeader *hdr) return; } - GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan whole messages received"), 1, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + _("# wlan whole messages received"), 1, + GNUNET_NO); wlanheader = (struct WlanHeader *) hdr; session = search_session (plugin, endpoint, &wlanheader->source); @@ -2711,9 +2742,8 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) #endif plugin->env->receive (plugin->env->cls, &(session->target), hdr, - (const struct GNUNET_ATS_Information *) - &distance, 1, session, - (const char *) &session->mac->addr, + (const struct GNUNET_ATS_Information *) &distance, 1, + session, (const char *) &session->mac->addr, sizeof (session->mac->addr)); } @@ -2735,7 +2765,7 @@ wlan_data_helper (void *cls, struct Session_light *session_light, struct FragmentMessage *fm2; struct GNUNET_PeerIdentity tmpsource; - GNUNET_assert(plugin != NULL); + GNUNET_assert (plugin != NULL); //ADVERTISEMENT if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_HELLO) @@ -2761,18 +2791,22 @@ wlan_data_helper (void *cls, struct Session_light *session_light, if (GNUNET_HELLO_get_id - ((const struct GNUNET_HELLO_Message *) hdr, - &tmpsource) == GNUNET_OK) + ((const struct GNUNET_HELLO_Message *) hdr, &tmpsource) == GNUNET_OK) { - session_light->session = search_session (plugin, session_light->macendpoint, &tmpsource); + session_light->session = + search_session (plugin, session_light->macendpoint, &tmpsource); if (session_light->session == NULL) - { - session_light->session = create_session (plugin, session_light->macendpoint, &tmpsource); - } - GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan hello messages received"), 1, GNUNET_NO); - plugin->env->receive(plugin->env->cls,&session_light->session->target,hdr, NULL, 0, session_light->session, - (const char *) &session_light->session->mac->addr, - sizeof (session_light->session->mac->addr)); + { + session_light->session = + create_session (plugin, session_light->macendpoint, &tmpsource); + } + GNUNET_STATISTICS_update (plugin->env->stats, + _("# wlan hello messages received"), 1, + GNUNET_NO); + plugin->env->receive (plugin->env->cls, &session_light->session->target, + hdr, NULL, 0, session_light->session, + (const char *) &session_light->session->mac->addr, + sizeof (session_light->session->mac->addr)); } else { @@ -2803,7 +2837,8 @@ wlan_data_helper (void *cls, struct Session_light *session_light, 6)); #endif - GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan fragments received"), 1, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + _("# wlan fragments received"), 1, GNUNET_NO); int ret = GNUNET_DEFRAGMENT_process_fragment (session_light->macendpoint->defrag, hdr); @@ -2855,7 +2890,8 @@ wlan_data_helper (void *cls, struct Session_light *session_light, while (fm != NULL) { fm2 = fm->next; - GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan acks received"), 1, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan acks received"), + 1, GNUNET_NO); int ret = GNUNET_FRAGMENT_process_ack (fm->fragcontext, hdr); if (ret == GNUNET_OK) @@ -2947,8 +2983,9 @@ macendpoint_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) (GNUNET_TIME_absolute_add (endpoint->last_activity, MACENDPOINT_TIMEOUT)).rel_value == 0) { - GNUNET_assert(endpoint->plugin != NULL); - GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# wlan mac endpoints timeouts"), 1, GNUNET_NO); + GNUNET_assert (endpoint->plugin != NULL); + GNUNET_STATISTICS_update (endpoint->plugin->env->stats, + _("# wlan mac endpoints timeouts"), 1, GNUNET_NO); free_macendpoint (endpoint->plugin, endpoint); } else @@ -2970,8 +3007,9 @@ create_macendpoint (struct Plugin *plugin, const struct MacAddress *addr) { struct MacEndpoint *newend = GNUNET_malloc (sizeof (struct MacEndpoint)); - GNUNET_assert(plugin != NULL); - GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan mac endpoints created"), 1, GNUNET_NO); + GNUNET_assert (plugin != NULL); + GNUNET_STATISTICS_update (plugin->env->stats, + _("# wlan mac endpoints created"), 1, GNUNET_NO); newend->addr = *addr; newend->plugin = plugin; newend->addr = *addr; @@ -2987,7 +3025,8 @@ create_macendpoint (struct Plugin *plugin, const struct MacAddress *addr) newend); plugin->mac_count++; - GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan mac endpoints"), plugin->mac_count, GNUNET_NO); + GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan mac endpoints"), + plugin->mac_count, GNUNET_NO); GNUNET_CONTAINER_DLL_insert_tail (plugin->mac_head, plugin->mac_tail, newend); #if DEBUG_wlan GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, @@ -3017,7 +3056,7 @@ wlan_process_helper (void *cls, void *client, int datasize = 0; int pos; - GNUNET_assert(plugin != NULL); + GNUNET_assert (plugin != NULL); switch (ntohs (hdr->type)) { case GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA: @@ -3027,11 +3066,13 @@ wlan_process_helper (void *cls, void *client, ntohs (hdr->size)); #endif - GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan WLAN_HELPER_DATA received"), 1, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + _("# wlan WLAN_HELPER_DATA received"), 1, + GNUNET_NO); //call wlan_process_helper with the message inside, later with wlan: analyze signal if (ntohs (hdr->size) < - sizeof (struct ieee80211_frame) + 2*sizeof (struct GNUNET_MessageHeader) + - sizeof (struct Radiotap_rx)) + sizeof (struct ieee80211_frame) + + 2 * sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_rx)) { #if DEBUG_wlan GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, @@ -3057,16 +3098,19 @@ wlan_process_helper (void *cls, void *client, { //check for broadcast or mac if ((memcmp - (&(wlanIeeeHeader->i_addr1), &bc_all_mac, - sizeof (struct MacAddress)) == 0) || - (memcmp (&(wlanIeeeHeader->i_addr1), &(plugin->mac_address), - sizeof (struct MacAddress)) == 0)) + (&(wlanIeeeHeader->i_addr1), &bc_all_mac, + sizeof (struct MacAddress)) == 0) || + (memcmp + (&(wlanIeeeHeader->i_addr1), &(plugin->mac_address), + sizeof (struct MacAddress)) == 0)) { - //if packet is from us return - if ((memcmp (&(wlanIeeeHeader->i_addr2), &(plugin->mac_address), - sizeof (struct MacAddress)) == 0)){ - return; - } + //if packet is from us return + if ((memcmp + (&(wlanIeeeHeader->i_addr2), &(plugin->mac_address), + sizeof (struct MacAddress)) == 0)) + { + return; + } // process the inner data @@ -3078,25 +3122,30 @@ wlan_process_helper (void *cls, void *client, memcpy (&session_light->addr, &(wlanIeeeHeader->i_addr2), sizeof (struct MacAddress)); //session_light->session = search_session(plugin,session_light->addr); - GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan messages for this client received"), 1, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + _("# wlan messages for this client received"), + 1, GNUNET_NO); pos = 0; while (pos < datasize) { temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1] + pos; - if (ntohs(temp_hdr->size) <= datasize + pos) - { - GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan messages inside WLAN_HELPER_DATA received"), 1, GNUNET_NO); - wlan_data_helper (plugin, session_light, temp_hdr, rxinfo); - } + if (ntohs (temp_hdr->size) <= datasize + pos) + { + GNUNET_STATISTICS_update (plugin->env->stats, + _ + ("# wlan messages inside WLAN_HELPER_DATA received"), + 1, GNUNET_NO); + wlan_data_helper (plugin, session_light, temp_hdr, rxinfo); + } else - { + { #if DEBUG_wlan GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, - "Size of packet is too small; size: %u > size of packet: %u\n", - ntohs(temp_hdr->size),datasize + pos); + "Size of packet is too small; size: %u > size of packet: %u\n", + ntohs (temp_hdr->size), datasize + pos); #endif - } + } pos += ntohs (temp_hdr->size); } @@ -3176,7 +3225,7 @@ libgnunet_plugin_transport_wlan_done (void *cls) "libgnunet_plugin_transport_wlan_done started\n"); #endif - wlan_transport_stop_wlan_helper(plugin); + wlan_transport_stop_wlan_helper (plugin); GNUNET_assert (cls != NULL); //free sessions @@ -3220,9 +3269,11 @@ libgnunet_plugin_transport_wlan_init (void *cls) plugin = GNUNET_malloc (sizeof (struct Plugin)); plugin->env = env; plugin->pendingsessions = 0; - GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending sessions"), plugin->pendingsessions, GNUNET_NO); + GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"), + plugin->pendingsessions, GNUNET_NO); plugin->mac_count = 0; - GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan mac endpoints"), plugin->mac_count, GNUNET_NO); + GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan mac endpoints"), + plugin->mac_count, GNUNET_NO); plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK; plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK; plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK; @@ -3253,7 +3304,7 @@ libgnunet_plugin_transport_wlan_init (void *cls) if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-wlan", "TESTMODE", &(plugin->testmode))) - plugin->testmode = 0; //default value + plugin->testmode = 0; //default value } if (GNUNET_CONFIGURATION_have_value (env->cfg, "transport-wlan", "INTERFACE")) @@ -3270,7 +3321,7 @@ libgnunet_plugin_transport_wlan_init (void *cls) //start the plugin wlan_transport_start_wlan_helper (plugin); set_next_beacon_time (plugin); - set_next_send(plugin); + set_next_send (plugin); #if DEBUG_wlan GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, "wlan init finished\n"); diff --git a/src/transport/test_quota_compliance.c b/src/transport/test_quota_compliance.c index 1c6bba0d5..7d28820cb 100644 --- a/src/transport/test_quota_compliance.c +++ b/src/transport/test_quota_compliance.c @@ -70,9 +70,9 @@ struct PeerContext *p1; struct PeerContext *p2; -struct PeerContext * sender; +struct PeerContext *sender; -struct PeerContext * receiver; +struct PeerContext *receiver; struct GNUNET_TRANSPORT_TransmitHandle *th; @@ -86,7 +86,7 @@ char *gen_cfg_p1; unsigned long long quota_in_p2; unsigned long long quota_out_p2; -struct GNUNET_TRANSPORT_TESTING_handle * tth; +struct GNUNET_TRANSPORT_TESTING_handle *tth; static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; @@ -144,26 +144,28 @@ end () delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; datarate = (total_bytes_sent * 1000) / delta; - fprintf (stderr, "Throughput was %llu b/s\n", - datarate); + fprintf (stderr, "Throughput was %llu b/s\n", datarate); test_failed = GNUNET_NO; if (datarate > quota_in_p2) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Datarate of %llu b/s higher than allowed inbound quota of %llu b/s\n", datarate, quota_in_p2); + "Datarate of %llu b/s higher than allowed inbound quota of %llu b/s\n", + datarate, quota_in_p2); test_failed = GNUNET_YES; } if (datarate > quota_out_p1) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Datarate of %llu b/s higher than allowed outbound quota of %llu b/s\n", datarate, quota_out_p1); + "Datarate of %llu b/s higher than allowed outbound quota of %llu b/s\n", + datarate, quota_out_p1); test_failed = GNUNET_YES; } if (test_failed == GNUNET_NO) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Datarate of %llu b/s complied to allowed outbound quota of %llu b/s and inbound quota of %llu b/s\n", datarate, quota_out_p1, quota_in_p2); + "Datarate of %llu b/s complied to allowed outbound quota of %llu b/s and inbound quota of %llu b/s\n", + datarate, quota_out_p1, quota_in_p2); } if (die_task != GNUNET_SCHEDULER_NO_TASK) @@ -174,7 +176,7 @@ end () th = NULL; if (cc != NULL) - GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc); + GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); @@ -200,7 +202,7 @@ end_badly () th = NULL; if (cc != NULL) - GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc); + GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); if (p1 != NULL) GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); @@ -224,8 +226,7 @@ get_size (unsigned int iter) static void notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { static int n; unsigned int s; @@ -269,17 +270,19 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, if (die_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (die_task); test_failed = GNUNET_YES; - die_task = GNUNET_SCHEDULER_add_now (&end_badly, - NULL); + die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); return; } #if VERBOSE if (ntohl (hdr->num) % 5000 == 0) { struct PeerContext *p = cls; - char * ps = strdup(GNUNET_i2s(&p->id)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", - p->no, ps, ntohl (hdr->num), ntohs (message->size), GNUNET_i2s(peer)); + char *ps = strdup (GNUNET_i2s (&p->id)); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", + p->no, ps, ntohl (hdr->num), ntohs (message->size), + GNUNET_i2s (peer)); GNUNET_free (ps); } #endif @@ -300,7 +303,8 @@ notify_ready (void *cls, size_t size, void *buf) if (buf == NULL) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Timeout occurred while waiting for transmit_ready for message %u of %u\n", msg_scheduled, TOTAL_MSGS); + "Timeout occurred while waiting for transmit_ready for message %u of %u\n", + msg_scheduled, TOTAL_MSGS); if (GNUNET_SCHEDULER_NO_TASK != die_task) GNUNET_SCHEDULER_cancel (die_task); die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); @@ -327,12 +331,12 @@ notify_ready (void *cls, size_t size, void *buf) if (n % 5000 == 0) { - char * receiver_s = strdup(GNUNET_i2s (&receiver->id)); + char *receiver_s = strdup (GNUNET_i2s (&receiver->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message of size %u from peer %u (`%4s') -> peer %u (`%s') !\n", - n, - sender->no, - GNUNET_i2s (&sender->id), receiver->no, receiver_s); + n, sender->no, GNUNET_i2s (&sender->id), receiver->no, + receiver_s); GNUNET_free (receiver_s); } #endif @@ -367,11 +371,11 @@ notify_ready (void *cls, size_t size, void *buf) static void notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { struct PeerContext *p = cls; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') connected to us!\n", p->no, GNUNET_i2s (peer)); } @@ -381,8 +385,9 @@ static void notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) { struct PeerContext *p = cls; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') disconnected!\n", - p->no, GNUNET_i2s (peer)); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') disconnected!\n", p->no, + GNUNET_i2s (peer)); if (th != NULL) GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); th = NULL; @@ -403,10 +408,11 @@ static void measure (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { static int counter; + measure_task = GNUNET_SCHEDULER_NO_TASK; counter++; - if ((DURATION.rel_value / 1000) < counter ) + if ((DURATION.rel_value / 1000) < counter) { fprintf (stderr, ".\n"); GNUNET_SCHEDULER_add_now (&end, NULL); @@ -414,7 +420,8 @@ measure (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) else { fprintf (stderr, "."); - measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &measure, NULL); + measure_task = + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &measure, NULL); } } @@ -423,28 +430,29 @@ static void testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) { char *p1_c = strdup (GNUNET_i2s (&p1->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n", - p1->no, p1_c, - p2->no, GNUNET_i2s (&p2->id)); + p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id)); GNUNET_free (p1_c); cc = NULL; test_connected = GNUNET_YES; - measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &measure, NULL); + measure_task = + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &measure, NULL); GNUNET_SCHEDULER_add_now (&sendtask, NULL); } -void start_cb (struct PeerContext * p, - void *cls) +void +start_cb (struct PeerContext *p, void *cls) { static int started; + started++; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", - p->no, - GNUNET_i2s (&p->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, + GNUNET_i2s (&p->id)); if (started != 2) return; @@ -455,61 +463,66 @@ void start_cb (struct PeerContext * p, receiver = p1; char *sender_c = strdup (GNUNET_i2s (&sender->id)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test tries to send from %u (%s) -> peer %u (%s)\n", - sender->no, sender_c, - receiver->no, GNUNET_i2s (&receiver->id)); - cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, NULL); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Test tries to send from %u (%s) -> peer %u (%s)\n", sender->no, + sender_c, receiver->no, GNUNET_i2s (&receiver->id)); + + cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, + NULL); } static char * -generate_config (char * cfg_file, unsigned long long quota_in, unsigned long long quota_out) +generate_config (char *cfg_file, unsigned long long quota_in, + unsigned long long quota_out) { - char * fname = NULL; - struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create(); + char *fname = NULL; + struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); + GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, cfg_file)); - GNUNET_asprintf (&fname, "q_in_%llu_q_out_%llu_%s", quota_in, quota_out, cfg_file); - GNUNET_CONFIGURATION_set_value_string(cfg, "PATHS", "DEFAULTCONFIG", fname); - GNUNET_CONFIGURATION_set_value_number(cfg, "core", "TOTAL_QUOTA_OUT", quota_out); - GNUNET_CONFIGURATION_set_value_number(cfg, "core", "TOTAL_QUOTA_IN", quota_in); - GNUNET_CONFIGURATION_set_value_number(cfg, "ats", "TOTAL_QUOTA_IN", quota_in); - GNUNET_CONFIGURATION_set_value_number(cfg, "ats", "TOTAL_QUOTA_OUT", quota_out); - GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write(cfg, fname)); - GNUNET_CONFIGURATION_destroy(cfg); + GNUNET_asprintf (&fname, "q_in_%llu_q_out_%llu_%s", quota_in, quota_out, + cfg_file); + GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG", fname); + GNUNET_CONFIGURATION_set_value_number (cfg, "core", "TOTAL_QUOTA_OUT", + quota_out); + GNUNET_CONFIGURATION_set_value_number (cfg, "core", "TOTAL_QUOTA_IN", + quota_in); + GNUNET_CONFIGURATION_set_value_number (cfg, "ats", "TOTAL_QUOTA_IN", + quota_in); + GNUNET_CONFIGURATION_set_value_number (cfg, "ats", "TOTAL_QUOTA_OUT", + quota_out); + GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write (cfg, fname)); + GNUNET_CONFIGURATION_destroy (cfg); return fname; } static void -run_measurement (unsigned long long p1_quota_in, unsigned long long p1_quota_out, - unsigned long long p2_quota_in, unsigned long long p2_quota_out) +run_measurement (unsigned long long p1_quota_in, + unsigned long long p1_quota_out, + unsigned long long p2_quota_in, + unsigned long long p2_quota_out) { die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); /* setting ATS quota */ quota_out_p1 = p1_quota_out; - gen_cfg_p1 = generate_config(cfg_file_p1, p1_quota_in, p1_quota_out); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Generated config file `%s'\n", - gen_cfg_p1); + gen_cfg_p1 = generate_config (cfg_file_p1, p1_quota_in, p1_quota_out); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Generated config file `%s'\n", + gen_cfg_p1); quota_in_p2 = p2_quota_in; - gen_cfg_p2 = generate_config(cfg_file_p2, p2_quota_in, p2_quota_out); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Generated config file `%s'\n", - gen_cfg_p2); + gen_cfg_p2 = generate_config (cfg_file_p2, p2_quota_in, p2_quota_out); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Generated config file `%s'\n", + gen_cfg_p2); - p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, gen_cfg_p1, 1, - ¬ify_receive, + p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, gen_cfg_p1, 1, ¬ify_receive, ¬ify_connect, ¬ify_disconnect, - &start_cb, - NULL); + &start_cb, NULL); - p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, gen_cfg_p2, 2, - ¬ify_receive, + p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, gen_cfg_p2, 2, ¬ify_receive, ¬ify_connect, ¬ify_disconnect, - &start_cb, - NULL); + &start_cb, NULL); if ((p1 == NULL) || (p2 == NULL)) { @@ -530,19 +543,19 @@ run (void *cls, char *const *args, const char *cfgfile, unsigned long long p2_quota_in = 10000; unsigned long long p2_quota_out = 10000; - if (NULL != strstr (test_name,"asymmetric")) + if (NULL != strstr (test_name, "asymmetric")) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Running asymmetric test with sending peer unlimited, receiving peer (in/out): %llu/%llu b/s \n", - p2_quota_in, p2_quota_out); + "Running asymmetric test with sending peer unlimited, receiving peer (in/out): %llu/%llu b/s \n", + p2_quota_in, p2_quota_out); p1_quota_out = 1024 * 1024 * 1024; p1_quota_in = 1024 * 1024 * 1024; } else { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Running symmetric test with (in/out) %llu/%llu b/s \n", - p2_quota_in, p2_quota_out); + "Running symmetric test with (in/out) %llu/%llu b/s \n", + p2_quota_in, p2_quota_out); } run_measurement (p1_quota_in, p1_quota_out, p2_quota_in, p2_quota_out); } diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c index 6b6cc0c0e..47686f8d9 100644 --- a/src/transport/test_transport_api.c +++ b/src/transport/test_transport_api.c @@ -74,7 +74,7 @@ static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; struct GNUNET_TRANSPORT_TransmitHandle *th; -struct GNUNET_TRANSPORT_TESTING_handle * tth; +struct GNUNET_TRANSPORT_TESTING_handle *tth; char *cfg_file_p1; @@ -140,10 +140,9 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static void notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { - struct PeerContext * p = cls; + struct PeerContext *p = cls; struct PeerContext *t = NULL; if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) @@ -152,11 +151,12 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, t = p2; GNUNET_assert (t != NULL); - char * ps = strdup (GNUNET_i2s(&p->id)); + char *ps = strdup (GNUNET_i2s (&p->id)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n", - p->no, ps, ntohs (message->type), ntohs (message->size), t->no, GNUNET_i2s (&t->id)); + p->no, ps, ntohs (message->type), ntohs (message->size), t->no, + GNUNET_i2s (&t->id)); if ((MTYPE == ntohs (message->type)) && (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) @@ -200,13 +200,12 @@ notify_ready (void *cls, size_t size, void *buf) hdr->size = htons (sizeof (struct GNUNET_MessageHeader)); hdr->type = htons (MTYPE); } - char * ps = strdup (GNUNET_i2s(&p2->id)); + char *ps = strdup (GNUNET_i2s (&p2->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n", - p2->no, - ps, - ntohs (hdr->type), - ntohs (hdr->size), p->no, GNUNET_i2s (&p->id)); + p2->no, ps, ntohs (hdr->type), ntohs (hdr->size), p->no, + GNUNET_i2s (&p->id)); GNUNET_free (ps); return sizeof (struct GNUNET_MessageHeader); } @@ -219,11 +218,11 @@ sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) return; - char * receiver_s = strdup(GNUNET_i2s (&p1->id)); + char *receiver_s = strdup (GNUNET_i2s (&p1->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", - p2->no, - GNUNET_i2s (&p2->id), p1->no, receiver_s); + p2->no, GNUNET_i2s (&p2->id), p1->no, receiver_s); GNUNET_free (receiver_s); th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, 256, 0, @@ -234,10 +233,10 @@ sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static void notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { static int c; + c++; struct PeerContext *p = cls; struct PeerContext *t = NULL; @@ -246,11 +245,12 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, t = p1; if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))) t = p2; - GNUNET_assert (t!=NULL); + GNUNET_assert (t != NULL); + + char *ps = strdup (GNUNET_i2s (&p->id)); - char * ps = strdup (GNUNET_i2s(&p->id)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", - p->no, ps, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", p->no, ps, t->no, GNUNET_i2s (peer)); GNUNET_free (ps); } @@ -260,9 +260,11 @@ static void notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) { struct PeerContext *p = cls; - char * ps = strdup (GNUNET_i2s(&p->id)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", - p->no, ps, GNUNET_i2s (peer)); + char *ps = strdup (GNUNET_i2s (&p->id)); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", p->no, ps, + GNUNET_i2s (peer)); if (th != NULL) GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); @@ -276,8 +278,7 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) char *p1_c = strdup (GNUNET_i2s (&p1->id)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n", - p1->no, p1_c, - p2->no, GNUNET_i2s (&p2->id)); + p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id)); GNUNET_free (p1_c); send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL); @@ -285,23 +286,24 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) -void start_cb (struct PeerContext * p, - void *cls) +void +start_cb (struct PeerContext *p, void *cls) { static int started; + started++; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", - p->no, - GNUNET_i2s (&p->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, + GNUNET_i2s (&p->id)); if (started != 2) return; char *sender_c = strdup (GNUNET_i2s (&p1->id)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", - p1->no, sender_c, - p2->no, GNUNET_i2s (&p2->id)); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", + p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id)); cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, NULL); @@ -315,17 +317,13 @@ run (void *cls, char *const *args, const char *cfgfile, die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, - ¬ify_receive, - ¬ify_connect, - ¬ify_disconnect, - &start_cb, - NULL); + ¬ify_receive, ¬ify_connect, + ¬ify_disconnect, &start_cb, + NULL); p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, - ¬ify_receive, - ¬ify_connect, - ¬ify_disconnect, - &start_cb, + ¬ify_receive, ¬ify_connect, + ¬ify_disconnect, &start_cb, NULL); if ((p1 == NULL) || (p2 == NULL)) diff --git a/src/transport/test_transport_api_disconnect.c b/src/transport/test_transport_api_disconnect.c index 0be922e93..f97c449fc 100644 --- a/src/transport/test_transport_api_disconnect.c +++ b/src/transport/test_transport_api_disconnect.c @@ -71,7 +71,7 @@ static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; struct GNUNET_TRANSPORT_TransmitHandle *th; -struct GNUNET_TRANSPORT_TESTING_handle * tth; +struct GNUNET_TRANSPORT_TESTING_handle *tth; int shutdown_; @@ -148,9 +148,11 @@ static void notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) { struct PeerContext *p = cls; - char * ps = strdup (GNUNET_i2s(&p->id)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", - p->no, ps, GNUNET_i2s (peer)); + char *ps = strdup (GNUNET_i2s (&p->id)); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", p->no, ps, + GNUNET_i2s (peer)); if (th != NULL) GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); @@ -158,8 +160,8 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) if (shutdown_ == GNUNET_YES) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Complete, shutting down...\n"); - GNUNET_SCHEDULER_add_now (&end, NULL); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Complete, shutting down...\n"); + GNUNET_SCHEDULER_add_now (&end, NULL); } } @@ -170,12 +172,12 @@ stop_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) return; - struct PeerContext * p = cls; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down peer %u (`%s')\n", - p->no, - GNUNET_i2s (&p->id)); + struct PeerContext *p = cls; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down peer %u (`%s')\n", p->no, + GNUNET_i2s (&p->id)); shutdown_ = GNUNET_YES; - GNUNET_TRANSPORT_TESTING_stop_peer(tth, p2); + GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); p2 = NULL; GNUNET_assert (p2 == NULL); } @@ -183,10 +185,9 @@ stop_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static void notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { - struct PeerContext * p = cls; + struct PeerContext *p = cls; struct PeerContext *t = NULL; if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) @@ -195,17 +196,18 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, t = p2; GNUNET_assert (t != NULL); - char * ps = strdup (GNUNET_i2s(&p->id)); + char *ps = strdup (GNUNET_i2s (&p->id)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n", - p->no, ps, ntohs (message->type), ntohs (message->size), t->no, GNUNET_i2s (&t->id)); + p->no, ps, ntohs (message->type), ntohs (message->size), t->no, + GNUNET_i2s (&t->id)); if ((MTYPE == ntohs (message->type)) && (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) { ok = 1; - GNUNET_SCHEDULER_add_now(stop_peer, p2); + GNUNET_SCHEDULER_add_now (stop_peer, p2); return; } } @@ -238,13 +240,12 @@ notify_ready (void *cls, size_t size, void *buf) hdr->size = htons (sizeof (struct GNUNET_MessageHeader)); hdr->type = htons (MTYPE); } - char * ps = strdup (GNUNET_i2s(&p2->id)); + char *ps = strdup (GNUNET_i2s (&p2->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n", - p2->no, - ps, - ntohs (hdr->type), - ntohs (hdr->size), p->no, GNUNET_i2s (&p->id)); + p2->no, ps, ntohs (hdr->type), ntohs (hdr->size), p->no, + GNUNET_i2s (&p->id)); GNUNET_free (ps); return sizeof (struct GNUNET_MessageHeader); } @@ -257,11 +258,11 @@ sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) return; - char * receiver_s = strdup(GNUNET_i2s (&p1->id)); + char *receiver_s = strdup (GNUNET_i2s (&p1->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", - p2->no, - GNUNET_i2s (&p2->id), p1->no, receiver_s); + p2->no, GNUNET_i2s (&p2->id), p1->no, receiver_s); GNUNET_free (receiver_s); th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, 256, 0, @@ -272,10 +273,10 @@ sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static void notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { static int c; + c++; struct PeerContext *p = cls; struct PeerContext *t = NULL; @@ -284,11 +285,12 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, t = p1; if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))) t = p2; - GNUNET_assert (t!=NULL); + GNUNET_assert (t != NULL); + + char *ps = strdup (GNUNET_i2s (&p->id)); - char * ps = strdup (GNUNET_i2s(&p->id)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", - p->no, ps, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", p->no, ps, t->no, GNUNET_i2s (peer)); GNUNET_free (ps); } @@ -301,8 +303,7 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) char *p1_c = strdup (GNUNET_i2s (&p1->id)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n", - p1->no, p1_c, - p2->no, GNUNET_i2s (&p2->id)); + p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id)); GNUNET_free (p1_c); send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL); @@ -310,23 +311,24 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) -void start_cb (struct PeerContext * p, - void *cls) +void +start_cb (struct PeerContext *p, void *cls) { static int started; + started++; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", - p->no, - GNUNET_i2s (&p->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, + GNUNET_i2s (&p->id)); if (started != 2) return; char *sender_c = strdup (GNUNET_i2s (&p1->id)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", - p1->no, sender_c, - p2->no, GNUNET_i2s (&p2->id)); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", + p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id)); cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, NULL); @@ -340,17 +342,13 @@ run (void *cls, char *const *args, const char *cfgfile, die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, - ¬ify_receive, - ¬ify_connect, - ¬ify_disconnect, - &start_cb, - NULL); + ¬ify_receive, ¬ify_connect, + ¬ify_disconnect, &start_cb, + NULL); p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, - ¬ify_receive, - ¬ify_connect, - ¬ify_disconnect, - &start_cb, + ¬ify_receive, ¬ify_connect, + ¬ify_disconnect, &start_cb, NULL); if ((p1 == NULL) || (p2 == NULL)) diff --git a/src/transport/test_transport_api_limited_sockets.c b/src/transport/test_transport_api_limited_sockets.c index 20dc3ed2e..f165a5771 100644 --- a/src/transport/test_transport_api_limited_sockets.c +++ b/src/transport/test_transport_api_limited_sockets.c @@ -77,7 +77,7 @@ static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; struct GNUNET_TRANSPORT_TransmitHandle *th; -struct GNUNET_TRANSPORT_TESTING_handle * tth; +struct GNUNET_TRANSPORT_TESTING_handle *tth; char *cfg_file_p1; @@ -138,8 +138,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static void notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message of type %d from peer %s!\n", @@ -185,8 +184,7 @@ notify_ready (void *cls, size_t size, void *buf) static void notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls); @@ -230,15 +228,15 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL); } -void start_cb (struct PeerContext * p, - void *cls) +void +start_cb (struct PeerContext *p, void *cls) { static int started; + started++; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", - p->no, - GNUNET_i2s (&p->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, + GNUNET_i2s (&p->id)); if (started != 2) return; @@ -257,14 +255,12 @@ run (void *cls, char *const *args, const char *cfgfile, tth = GNUNET_TRANSPORT_TESTING_init (); p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, - ¬ify_receive, - ¬ify_connect, ¬ify_disconnect, - &start_cb, + ¬ify_receive, ¬ify_connect, + ¬ify_disconnect, &start_cb, NULL); p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, - ¬ify_receive, - ¬ify_connect, ¬ify_disconnect, - &start_cb, + ¬ify_receive, ¬ify_connect, + ¬ify_disconnect, &start_cb, NULL); if ((p1 == NULL) || (p2 == NULL)) { diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c index e4b635905..5bbff2550 100644 --- a/src/transport/test_transport_api_reliability.c +++ b/src/transport/test_transport_api_reliability.c @@ -69,9 +69,9 @@ struct PeerContext *p1; struct PeerContext *p2; -struct PeerContext * sender; +struct PeerContext *sender; -struct PeerContext * receiver; +struct PeerContext *receiver; struct GNUNET_TRANSPORT_TransmitHandle *th; @@ -79,7 +79,7 @@ char *cfg_file_p1; char *cfg_file_p2; -struct GNUNET_TRANSPORT_TESTING_handle * tth; +struct GNUNET_TRANSPORT_TESTING_handle *tth; static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; @@ -151,7 +151,7 @@ end () th = NULL; if (cc != NULL) - GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc); + GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); @@ -175,7 +175,7 @@ end_badly () th = NULL; if (cc != NULL) - GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc); + GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); if (p1 != NULL) GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); @@ -201,8 +201,7 @@ get_size (unsigned int iter) static void notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { static int n; unsigned int s; @@ -253,9 +252,12 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, if (ntohl (hdr->num) % 5000 == 0) { struct PeerContext *p = cls; - char * ps = strdup(GNUNET_i2s(&p->id)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", - p->no, ps, ntohl (hdr->num), ntohs (message->size), GNUNET_i2s(peer)); + char *ps = strdup (GNUNET_i2s (&p->id)); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", + p->no, ps, ntohl (hdr->num), ntohs (message->size), + GNUNET_i2s (peer)); GNUNET_free (ps); } #endif @@ -289,7 +291,8 @@ notify_ready (void *cls, size_t size, void *buf) if (buf == NULL) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Timeout occurred while waiting for transmit_ready for message %u of %u\n", msg_scheduled, TOTAL_MSGS); + "Timeout occurred while waiting for transmit_ready for message %u of %u\n", + msg_scheduled, TOTAL_MSGS); if (GNUNET_SCHEDULER_NO_TASK != die_task) GNUNET_SCHEDULER_cancel (die_task); die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); @@ -316,12 +319,12 @@ notify_ready (void *cls, size_t size, void *buf) if (n % 5000 == 0) { - char * receiver_s = strdup(GNUNET_i2s (&receiver->id)); + char *receiver_s = strdup (GNUNET_i2s (&receiver->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message of size %u from peer %u (`%4s') -> peer %u (`%s') !\n", - n, - sender->no, - GNUNET_i2s (&sender->id), receiver->no, receiver_s); + n, sender->no, GNUNET_i2s (&sender->id), receiver->no, + receiver_s); GNUNET_free (receiver_s); } #endif @@ -356,11 +359,11 @@ notify_ready (void *cls, size_t size, void *buf) static void notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { struct PeerContext *p = cls; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') connected to us!\n", p->no, GNUNET_i2s (peer)); } @@ -370,8 +373,9 @@ static void notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) { struct PeerContext *p = cls; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') disconnected!\n", - p->no, GNUNET_i2s (peer)); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') disconnected!\n", p->no, + GNUNET_i2s (peer)); if (th != NULL) GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); th = NULL; @@ -391,9 +395,9 @@ static void testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) { char *p1_c = strdup (GNUNET_i2s (&p1->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n", - p1->no, p1_c, - p2->no, GNUNET_i2s (&p2->id)); + p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id)); GNUNET_free (p1_c); cc = NULL; @@ -402,37 +406,39 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) } -void start_cb (struct PeerContext * p, - void *cls) +void +start_cb (struct PeerContext *p, void *cls) { static int started; + started++; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", - p->no, - GNUNET_i2s (&p->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, + GNUNET_i2s (&p->id)); if (started != 2) return; test_connected = GNUNET_NO; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u: `%s' using configuration file `%s'\n", - p1->no, - GNUNET_i2s (&p1->id), cfg_file_p1); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u: `%s' using configuration file `%s'\n", - p2->no, - GNUNET_i2s (&p2->id), cfg_file_p2); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peer %u: `%s' using configuration file `%s'\n", p1->no, + GNUNET_i2s (&p1->id), cfg_file_p1); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peer %u: `%s' using configuration file `%s'\n", p2->no, + GNUNET_i2s (&p2->id), cfg_file_p2); sender = p2; receiver = p1; char *sender_c = strdup (GNUNET_i2s (&sender->id)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test triest to send from %u (%s) -> peer %u (%s)\n", - sender->no, sender_c, - receiver->no, GNUNET_i2s (&receiver->id)); - cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, NULL); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Test triest to send from %u (%s) -> peer %u (%s)\n", sender->no, + sender_c, receiver->no, GNUNET_i2s (&receiver->id)); + + cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, + NULL); } @@ -444,14 +450,12 @@ run (void *cls, char *const *args, const char *cfgfile, die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, - ¬ify_receive, - ¬ify_connect, ¬ify_disconnect, - &start_cb, + ¬ify_receive, ¬ify_connect, + ¬ify_disconnect, &start_cb, NULL); p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, - ¬ify_receive, - ¬ify_connect, ¬ify_disconnect, - &start_cb, + ¬ify_receive, ¬ify_connect, + ¬ify_disconnect, &start_cb, NULL); if ((p1 == NULL) || (p2 == NULL)) diff --git a/src/transport/test_transport_api_timeout.c b/src/transport/test_transport_api_timeout.c index aff36853a..79a90ba0e 100644 --- a/src/transport/test_transport_api_timeout.c +++ b/src/transport/test_transport_api_timeout.c @@ -65,7 +65,7 @@ static GNUNET_SCHEDULER_TaskIdentifier die_task; static GNUNET_SCHEDULER_TaskIdentifier timer_task; -struct GNUNET_TRANSPORT_TESTING_handle * tth; +struct GNUNET_TRANSPORT_TESTING_handle *tth; struct PeerContext *p1; @@ -161,8 +161,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static void notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message of type %d from peer %s!\n", @@ -171,8 +170,7 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, static void notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls); @@ -240,23 +238,24 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) timer_task = GNUNET_SCHEDULER_add_now (&timer, NULL); } -void start_cb (struct PeerContext * p, - void *cls) +void +start_cb (struct PeerContext *p, void *cls) { static int started; + started++; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", - p->no, - GNUNET_i2s (&p->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, + GNUNET_i2s (&p->id)); if (started != 2) return; char *sender_c = strdup (GNUNET_i2s (&p1->id)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", - p1->no, sender_c, - p2->no, GNUNET_i2s (&p2->id)); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", + p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id)); cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, NULL); @@ -269,17 +268,13 @@ run (void *cls, char *const *args, const char *cfgfile, { die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); - p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, - ¬ify_receive, - ¬ify_connect, - ¬ify_disconnect, - &start_cb, + p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, + ¬ify_receive, ¬ify_connect, + ¬ify_disconnect, &start_cb, NULL); p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, - ¬ify_receive, - ¬ify_connect, - ¬ify_disconnect, - &start_cb, + ¬ify_receive, ¬ify_connect, + ¬ify_disconnect, &start_cb, NULL); if ((p1 == NULL) || (p2 == NULL)) @@ -314,8 +309,8 @@ check () ok = 1; GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, - "test-transport-api-timeout", "nohelp", options, - &run, &ok); + "test-transport-api-timeout", "nohelp", options, &run, + &ok); return ok; } diff --git a/src/transport/test_transport_api_unreliability.c b/src/transport/test_transport_api_unreliability.c index 90b5280ce..3077eaae6 100644 --- a/src/transport/test_transport_api_unreliability.c +++ b/src/transport/test_transport_api_unreliability.c @@ -78,7 +78,7 @@ char *cfg_file_p2; uint32_t max_bps_p1; uint32_t max_bps_p2; -struct GNUNET_TRANSPORT_TESTING_handle * tth; +struct GNUNET_TRANSPORT_TESTING_handle *tth; /* * Testcase specific declarations @@ -156,7 +156,7 @@ end () th = NULL; if (cc != NULL) - GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc); + GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); cc = NULL; GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); @@ -190,13 +190,15 @@ end_badly () GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers got NOT connected\n"); if (test_sending == GNUNET_NO) - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testcase did not send any messages timeout\n"); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Testcase did not send any messages timeout\n"); else GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Reliability failed: Last message sent %u, Next message scheduled %u, Last message received %u, Message expected %u\n", msg_sent, msg_scheduled, msg_recv, msg_recv_expected); if (test_send_timeout == GNUNET_YES) - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test had timeout while waiting to send data\n"); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Test had timeout while waiting to send data\n"); if (th != NULL) @@ -204,7 +206,7 @@ end_badly () th = NULL; if (cc != NULL) - GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc); + GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); cc = NULL; if (p1 != NULL) @@ -273,8 +275,7 @@ get_bit (const char *map, unsigned int bit) static void notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { static int n; @@ -400,8 +401,7 @@ notify_ready (void *cls, size_t size, void *buf) else { fprintf (stderr, "\n"); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "All messages scheduled to be sent\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All messages scheduled to be sent\n"); if (GNUNET_SCHEDULER_NO_TASK != die_task) GNUNET_SCHEDULER_cancel (die_task); die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); @@ -418,8 +418,7 @@ notify_ready (void *cls, size_t size, void *buf) static void notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n", @@ -450,6 +449,7 @@ static void testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) { char *p1_c = strdup (GNUNET_i2s (&p1->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %s <-> %s\n", p1_c, GNUNET_i2s (&p2->id)); GNUNET_free (p1_c); @@ -460,21 +460,22 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) GNUNET_SCHEDULER_add_now (&sendtask, NULL); } -void start_cb (struct PeerContext * p, - void *cls) +void +start_cb (struct PeerContext *p, void *cls) { static int started; + started++; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", - p->no, - GNUNET_i2s (&p->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, + GNUNET_i2s (&p->id)); if (started != 2) return; test_connected = GNUNET_NO; - cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, NULL); + cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, + NULL); } @@ -487,14 +488,12 @@ run (void *cls, char *const *args, const char *cfgfile, p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, - ¬ify_receive, - ¬ify_connect, ¬ify_disconnect, - &start_cb, + ¬ify_receive, ¬ify_connect, + ¬ify_disconnect, &start_cb, NULL); p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, - ¬ify_receive, - ¬ify_connect, ¬ify_disconnect, - &start_cb, + ¬ify_receive, ¬ify_connect, + ¬ify_disconnect, &start_cb, NULL); diff --git a/src/transport/test_transport_api_unreliability_constant.c b/src/transport/test_transport_api_unreliability_constant.c index c8638cd23..3ce256017 100644 --- a/src/transport/test_transport_api_unreliability_constant.c +++ b/src/transport/test_transport_api_unreliability_constant.c @@ -71,7 +71,7 @@ struct PeerContext *p2; struct GNUNET_TRANSPORT_TransmitHandle *th; -struct GNUNET_TRANSPORT_TESTING_handle * tth; +struct GNUNET_TRANSPORT_TESTING_handle *tth; char *cfg_file_p1; @@ -154,7 +154,7 @@ end () th = NULL; if (cc != NULL) - GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc); + GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); cc = NULL; GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); @@ -165,7 +165,8 @@ end () ok = 0; if (test_failed == GNUNET_NO) ok = GNUNET_SYSERR; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GOT %u of %u messages\n", msg_recv, TOTAL_MSGS); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GOT %u of %u messages\n", msg_recv, + TOTAL_MSGS); } static void @@ -186,7 +187,7 @@ end_badly () th = NULL; if (cc != NULL) - GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc); + GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); cc = NULL; if (p1 != NULL) @@ -217,8 +218,7 @@ get_size (unsigned int iter) static void notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { static int n; @@ -234,8 +234,7 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, msg_recv = ntohl (hdr->num); if (msg_recv_expected != msg_recv) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Expected message no %u, got %u\n", + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expected message no %u, got %u\n", msg_recv_expected, msg_recv); if (GNUNET_SCHEDULER_NO_TASK != die_task) GNUNET_SCHEDULER_cancel (die_task); @@ -373,8 +372,7 @@ notify_ready (void *cls, size_t size, void *buf) static void notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n", @@ -415,20 +413,21 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) GNUNET_SCHEDULER_add_now (&sendtask, NULL); } -void start_cb (struct PeerContext * p, - void *cls) +void +start_cb (struct PeerContext *p, void *cls) { static int started; + started++; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", - p->no, - GNUNET_i2s (&p->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, + GNUNET_i2s (&p->id)); if (started != 2) return; - cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, NULL); + cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, + NULL); } static void @@ -438,14 +437,12 @@ run (void *cls, char *const *args, const char *cfgfile, die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, - ¬ify_receive, - ¬ify_connect, ¬ify_disconnect, - &start_cb, + ¬ify_receive, ¬ify_connect, + ¬ify_disconnect, &start_cb, NULL); p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, - ¬ify_receive, - ¬ify_connect, ¬ify_disconnect, - &start_cb, + ¬ify_receive, ¬ify_connect, + ¬ify_disconnect, &start_cb, NULL); if ((p1 == NULL) || (p2 == NULL)) diff --git a/src/transport/test_transport_startonly.c b/src/transport/test_transport_startonly.c index 1349a0c4d..c6215c9bc 100644 --- a/src/transport/test_transport_startonly.c +++ b/src/transport/test_transport_startonly.c @@ -54,7 +54,7 @@ GNUNET_SCHEDULER_TaskIdentifier timeout_task; static struct PeerContext *p1; -struct GNUNET_TRANSPORT_TESTING_handle * tth; +struct GNUNET_TRANSPORT_TESTING_handle *tth; static int connected = GNUNET_NO; @@ -92,8 +92,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static void notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' connected \n", GNUNET_i2s (peer)); @@ -110,8 +109,7 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) static void notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving\n"); } @@ -130,8 +128,10 @@ run (void *cls, char *const *args, const char *cfgfile, while (i <= ITERATIONS) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting peer\n"); - p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_startonly.conf", 1, - ¬ify_receive, ¬ify_connect, + p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, + "test_transport_startonly.conf", + 1, ¬ify_receive, + ¬ify_connect, ¬ify_disconnect, NULL, p1); diff --git a/src/transport/test_transport_testing.c b/src/transport/test_transport_testing.c index 266933580..996ea0543 100644 --- a/src/transport/test_transport_testing.c +++ b/src/transport/test_transport_testing.c @@ -55,7 +55,7 @@ static struct PeerContext *p2; static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; -struct GNUNET_TRANSPORT_TESTING_handle * tth; +struct GNUNET_TRANSPORT_TESTING_handle *tth; static int connected = GNUNET_NO; @@ -94,9 +94,10 @@ end_badly () static void testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) { - char * ps = strdup (GNUNET_i2s(&p1->id)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') connected to peer %u (`%s')!\n", - p1->no, ps, + char *ps = strdup (GNUNET_i2s (&p1->id)); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peer %u (`%4s') connected to peer %u (`%s')!\n", p1->no, ps, p2->no, GNUNET_i2s (&p2->id)); GNUNET_free (ps); GNUNET_SCHEDULER_add_now (&end, NULL); @@ -104,8 +105,7 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) static void notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' connected \n", GNUNET_i2s (peer)); @@ -122,29 +122,29 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) static void notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving\n"); } -void start_cb (struct PeerContext * p, - void *cls) +void +start_cb (struct PeerContext *p, void *cls) { static int started; + started++; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", - p->no, - GNUNET_i2s (&p->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, + GNUNET_i2s (&p->id)); if (started != 2) return; char *sender_c = strdup (GNUNET_i2s (&p1->id)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", - p1->no, sender_c, - p2->no, GNUNET_i2s (&p2->id)); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", + p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id)); cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, NULL); @@ -161,34 +161,30 @@ run (void *cls, char *const *args, const char *cfgfile, GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &end_badly, NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting peer\n"); - p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_api_tcp_peer1.conf", - 1, - ¬ify_receive, ¬ify_connect, - ¬ify_disconnect, - &start_cb, - p1); - p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_api_tcp_peer2.conf", - 2, - ¬ify_receive, ¬ify_connect, - ¬ify_disconnect, - &start_cb, - p2); + p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, + "test_transport_api_tcp_peer1.conf", + 1, ¬ify_receive, ¬ify_connect, + ¬ify_disconnect, &start_cb, p1); + p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, + "test_transport_api_tcp_peer2.conf", + 2, ¬ify_receive, ¬ify_connect, + ¬ify_disconnect, &start_cb, p2); if (p1 == NULL) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer1 was not started successfully\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peer1 was not started successfully\n"); if (timeout_task != GNUNET_SCHEDULER_NO_TASK) - GNUNET_SCHEDULER_cancel(timeout_task); - timeout_task = - GNUNET_SCHEDULER_add_now (&end_badly, NULL); + GNUNET_SCHEDULER_cancel (timeout_task); + timeout_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); } if (p2 == NULL) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer2 was not started successfully\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peer2 was not started successfully\n"); if (timeout_task != GNUNET_SCHEDULER_NO_TASK) - GNUNET_SCHEDULER_cancel(timeout_task); - timeout_task = - GNUNET_SCHEDULER_add_now (&end_badly, NULL); + GNUNET_SCHEDULER_cancel (timeout_task); + timeout_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); } } diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c index a4eba609d..b23879032 100644 --- a/src/transport/transport-testing.c +++ b/src/transport/transport-testing.c @@ -31,11 +31,11 @@ static struct PeerContext * -find_peer_context ( struct GNUNET_TRANSPORT_TESTING_handle *tth, - const struct GNUNET_PeerIdentity *peer) +find_peer_context (struct GNUNET_TRANSPORT_TESTING_handle *tth, + const struct GNUNET_PeerIdentity *peer) { GNUNET_assert (tth != NULL); - struct PeerContext * t = tth->p_head; + struct PeerContext *t = tth->p_head; while (t != NULL) { @@ -48,17 +48,16 @@ find_peer_context ( struct GNUNET_TRANSPORT_TESTING_handle *tth, } struct ConnectingContext * -find_connecting_context ( struct GNUNET_TRANSPORT_TESTING_handle *tth, - struct PeerContext *p1, - struct PeerContext * p2) +find_connecting_context (struct GNUNET_TRANSPORT_TESTING_handle *tth, + struct PeerContext *p1, struct PeerContext *p2) { GNUNET_assert (tth != NULL); - struct ConnectingContext * cc = tth->cc_head; + struct ConnectingContext *cc = tth->cc_head; while (cc != NULL) { if ((cc->p1 == p1) && (cc->p2 == p2)) - break; + break; if ((cc->p1 == p2) && (cc->p2 == p1)) break; cc = cc->next; @@ -69,14 +68,14 @@ find_connecting_context ( struct GNUNET_TRANSPORT_TESTING_handle *tth, static void notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { struct PeerContext *p = cls; + /* Find PeerContext */ GNUNET_assert (p != 0); GNUNET_assert (p->tth != NULL); - struct PeerContext * p2 = find_peer_context (p->tth, peer); + struct PeerContext *p2 = find_peer_context (p->tth, peer); if (p == NULL) return; @@ -84,21 +83,22 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, p->nc (p->cb_cls, peer, ats, ats_count); #if VERBOSE - char * p2_s; + char *p2_s; + if (p2 != NULL) - GNUNET_asprintf(&p2_s, "%u (`%s')", p2->no, GNUNET_i2s (&p2->id)); + GNUNET_asprintf (&p2_s, "%u (`%s')", p2->no, GNUNET_i2s (&p2->id)); else - GNUNET_asprintf(&p2_s, "`%s'", GNUNET_i2s (peer)); + GNUNET_asprintf (&p2_s, "`%s'", GNUNET_i2s (peer)); GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", - "Peers %s connected to peer %u (`%s')\n", - p2_s, - p->no, GNUNET_i2s (&p->id)); + "Peers %s connected to peer %u (`%s')\n", p2_s, p->no, + GNUNET_i2s (&p->id)); GNUNET_free (p2_s); #endif /* Find ConnectingContext */ - struct ConnectingContext * cc = find_connecting_context(p->tth, p, p2); + struct ConnectingContext *cc = find_connecting_context (p->tth, p, p2); + if (cc == NULL) return; @@ -106,12 +106,12 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, cc->p1_c = GNUNET_YES; if (p == cc->p2) - cc->p2_c = GNUNET_YES; + cc->p2_c = GNUNET_YES; if ((cc->p1_c == GNUNET_YES) && (cc->p2_c == GNUNET_YES)) { cc->cb (cc->p1, cc->p2, cc->cb_cls); - GNUNET_TRANSPORT_TESTING_connect_peers_cancel(p->tth, cc); + GNUNET_TRANSPORT_TESTING_connect_peers_cancel (p->tth, cc); } } @@ -119,9 +119,10 @@ static void notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) { struct PeerContext *p = cls; + /* Find PeerContext */ int no = 0; - struct PeerContext * p2 = NULL; + struct PeerContext *p2 = NULL; if (p != NULL) { @@ -130,15 +131,15 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) no = p->no; } - char * p2_s; + char *p2_s; + if (p2 != NULL) - GNUNET_asprintf(&p2_s, "%u (`%s')", p2->no, GNUNET_i2s (&p2->id)); + GNUNET_asprintf (&p2_s, "%u (`%s')", p2->no, GNUNET_i2s (&p2->id)); else - GNUNET_asprintf(&p2_s, "`%s'", GNUNET_i2s (peer)); + GNUNET_asprintf (&p2_s, "`%s'", GNUNET_i2s (peer)); GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", - "Peers %s disconnected from peer %u (`%s')\n", - p2_s, - no , GNUNET_i2s (&p->id)); + "Peers %s disconnected from peer %u (`%s')\n", p2_s, no, + GNUNET_i2s (&p->id)); GNUNET_free (p2_s); if (p == NULL) @@ -150,8 +151,7 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) static void notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { struct PeerContext *p = cls; @@ -170,25 +170,25 @@ get_hello (void *cb_cls, const struct GNUNET_MessageHeader *message) GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) message, &p->id)); - size_t size = GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *) message); + size_t size = + GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *) message); GNUNET_free_non_null (p->hello); - p->hello = (struct GNUNET_HELLO_Message*) GNUNET_copy_message (message); + p->hello = (struct GNUNET_HELLO_Message *) GNUNET_copy_message (message); #if VERBOSE - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, - "transport-testing", - "New HELLO for peer %u (`%s') with size %u\n", - p->no, GNUNET_i2s (&p->id), size); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", + "New HELLO for peer %u (`%s') with size %u\n", p->no, + GNUNET_i2s (&p->id), size); #endif if (p->start_cb != NULL) { #if VERBOSE GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", - "Peer %u (`%s') successfully started\n", - p->no, GNUNET_i2s (&p->id)); + "Peer %u (`%s') successfully started\n", p->no, + GNUNET_i2s (&p->id)); #endif - p->start_cb(p, p->cb_cls); + p->start_cb (p, p->cb_cls); p->start_cb = NULL; } } @@ -205,15 +205,17 @@ try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) return; - char * p2_s = GNUNET_strdup(GNUNET_i2s (&p2->id)); + char *p2_s = GNUNET_strdup (GNUNET_i2s (&p2->id)); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", - "Asking peer %u (`%s') to connect peer %u (`%s'), providing HELLO with %u bytes\n", - p1->no, GNUNET_i2s (&p1->id), p2->no, p2_s, - GNUNET_HELLO_size (cc->p2->hello)); + "Asking peer %u (`%s') to connect peer %u (`%s'), providing HELLO with %u bytes\n", + p1->no, GNUNET_i2s (&p1->id), p2->no, p2_s, + GNUNET_HELLO_size (cc->p2->hello)); GNUNET_free (p2_s); GNUNET_TRANSPORT_offer_hello (cc->th_p1, - (const struct GNUNET_MessageHeader *) cc->p2->hello, NULL, NULL); + (const struct GNUNET_MessageHeader *) cc-> + p2->hello, NULL, NULL); GNUNET_TRANSPORT_try_connect (cc->th_p1, &p2->id); cc->tct = @@ -230,9 +232,8 @@ try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) * @return the peer context */ struct PeerContext * -GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle * tth, - const char *cfgname, - int peer_id, +GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle + *tth, const char *cfgname, int peer_id, GNUNET_TRANSPORT_ReceiveCallback rec, GNUNET_TRANSPORT_NotifyConnect nc, GNUNET_TRANSPORT_NotifyDisconnect nd, @@ -243,7 +244,7 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle * tt if (GNUNET_DISK_file_test (cfgname) == GNUNET_NO) { GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", - "File not found: `%s' \n", cfgname); + "File not found: `%s' \n", cfgname); return NULL; } @@ -253,8 +254,10 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle * tt GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); if (GNUNET_CONFIGURATION_have_value (p->cfg, "PATHS", "SERVICEHOME")) - GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME", - &p->servicehome)); + GNUNET_assert (GNUNET_OK == + GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", + "SERVICEHOME", + &p->servicehome)); if (NULL != p->servicehome) GNUNET_DISK_directory_remove (p->servicehome); p->arm_proc = @@ -286,7 +289,7 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle * tt p->ghh = GNUNET_TRANSPORT_get_hello (p->th, &get_hello, p); GNUNET_assert (p->ghh != NULL); - GNUNET_CONTAINER_DLL_insert(tth->p_head, tth->p_tail, p); + GNUNET_CONTAINER_DLL_insert (tth->p_head, tth->p_tail, p); return p; } @@ -296,7 +299,7 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle * tt * @param p the peer */ void -GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle * tth, +GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth, struct PeerContext *p) { GNUNET_assert (p != NULL); @@ -346,12 +349,11 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle * tth * @return connect context */ GNUNET_TRANSPORT_TESTING_ConnectRequest -GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle * tth, - struct PeerContext *p1, +GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle + *tth, struct PeerContext *p1, struct PeerContext *p2, GNUNET_TRANSPORT_TESTING_connect_cb cb, void *cb_cls) - { GNUNET_assert (tth != NULL); @@ -377,7 +379,7 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle * cc->tct = GNUNET_SCHEDULER_add_now (&try_connect, cc); GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", - "New connect request %X\n", cc); + "New connect request %X\n", cc); return cc; } @@ -387,16 +389,19 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle * * Tou MUST cancel the request if you stop the peers before the peers connected succesfully * @param cc a connect request handle */ -void GNUNET_TRANSPORT_TESTING_connect_peers_cancel - (struct GNUNET_TRANSPORT_TESTING_handle * tth, - GNUNET_TRANSPORT_TESTING_ConnectRequest ccr) +void +GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct + GNUNET_TRANSPORT_TESTING_handle + *tth, + GNUNET_TRANSPORT_TESTING_ConnectRequest + ccr) { struct ConnectingContext *cc = ccr; GNUNET_assert (tth != NULL); GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", - "Canceling connect request %X!\n", cc); + "Canceling connect request %X!\n", cc); if (cc->tct != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (cc->tct); @@ -412,7 +417,7 @@ void GNUNET_TRANSPORT_TESTING_connect_peers_cancel * @param tth transport testing handle */ void -GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle * tth) +GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle *tth) { struct ConnectingContext *cc = tth->cc_head; struct ConnectingContext *ct = NULL; @@ -425,8 +430,8 @@ GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle * tth) { ct = cc->next; GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", - "Developer forgot to cancel connect request %X!\n", cc); - GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc); + "Developer forgot to cancel connect request %X!\n", cc); + GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); cc = ct; } @@ -434,7 +439,7 @@ GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle * tth) { t = p->next; GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", - "Developer forgot to stop peer!\n"); + "Developer forgot to stop peer!\n"); GNUNET_TRANSPORT_TESTING_stop_peer (tth, p); p = t; } @@ -450,7 +455,8 @@ GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle * tth) struct GNUNET_TRANSPORT_TESTING_handle * GNUNET_TRANSPORT_TESTING_init () { - struct GNUNET_TRANSPORT_TESTING_handle * tth = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_TESTING_handle)); + struct GNUNET_TRANSPORT_TESTING_handle *tth = + GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_TESTING_handle)); return tth; } diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h index ed9238ecb..8e5d55dcd 100644 --- a/src/transport/transport-testing.h +++ b/src/transport/transport-testing.h @@ -65,10 +65,10 @@ struct GNUNET_TRANSPORT_TESTING_handle; */ struct PeerContext { - struct PeerContext * next; - struct PeerContext * prev; + struct PeerContext *next; + struct PeerContext *prev; - struct GNUNET_TRANSPORT_TESTING_handle * tth; + struct GNUNET_TRANSPORT_TESTING_handle *tth; struct GNUNET_CONFIGURATION_Handle *cfg; @@ -100,8 +100,8 @@ struct PeerContext struct ConnectingContext { - struct ConnectingContext * next; - struct ConnectingContext * prev; + struct ConnectingContext *next; + struct ConnectingContext *prev; struct PeerContext *p1; struct PeerContext *p2; GNUNET_SCHEDULER_TaskIdentifier tct; @@ -115,11 +115,11 @@ struct ConnectingContext struct GNUNET_TRANSPORT_TESTING_handle { - struct ConnectingContext * cc_head; - struct ConnectingContext * cc_tail; + struct ConnectingContext *cc_head; + struct ConnectingContext *cc_tail; - struct PeerContext * p_head; - struct PeerContext * p_tail; + struct PeerContext *p_head; + struct PeerContext *p_tail; }; @@ -134,9 +134,8 @@ struct GNUNET_TRANSPORT_TESTING_handle * @return the peer context */ struct PeerContext * -GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle * tth, - const char *cfgname, - int peer_id, +GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle + *tth, const char *cfgname, int peer_id, GNUNET_TRANSPORT_ReceiveCallback rec, GNUNET_TRANSPORT_NotifyConnect nc, GNUNET_TRANSPORT_NotifyDisconnect nd, @@ -150,7 +149,7 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle * tt */ void -GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle * tth, +GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth, struct PeerContext *pc); @@ -165,8 +164,8 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle * tth * @return a connect request handle */ GNUNET_TRANSPORT_TESTING_ConnectRequest -GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle * tth, - struct PeerContext *p1, +GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle + *tth, struct PeerContext *p1, struct PeerContext *p2, GNUNET_TRANSPORT_TESTING_connect_cb cb, void *cls); @@ -177,15 +176,16 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle * * @param cc a connect request handle */ void -GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct GNUNET_TRANSPORT_TESTING_handle *, - void *cc); +GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct + GNUNET_TRANSPORT_TESTING_handle + *, void *cc); /** * Clean up the transport testing * @param tth transport testing handle */ void -GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle * tth); +GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle *tth); /** * Initialize the transport testing diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c index cff967b19..b7704e512 100644 --- a/src/transport/transport_api.c +++ b/src/transport/transport_api.c @@ -473,7 +473,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg) GNUNET_break (0); break; } - ats = (const struct GNUNET_ATS_Information*) &cim[1]; + ats = (const struct GNUNET_ATS_Information *) &cim[1]; #if DEBUG_TRANSPORT_API LOG (GNUNET_ERROR_TYPE_DEBUG, "Receiving `%s' message for `%4s'.\n", "CONNECT", GNUNET_i2s (&cim->id)); @@ -547,7 +547,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg) } im = (const struct InboundMessage *) msg; ats_count = ntohl (im->ats_count); - ats = (const struct GNUNET_ATS_Information*) &im[1]; + ats = (const struct GNUNET_ATS_Information *) &im[1]; imm = (const struct GNUNET_MessageHeader *) &ats[ats_count]; if (ntohs (imm->size) + sizeof (struct InboundMessage) + ats_count * sizeof (struct GNUNET_ATS_Information) != size) diff --git a/src/transport/transport_api_address_iterate.c b/src/transport/transport_api_address_iterate.c index 2ffe1ada8..3c3f97c28 100644 --- a/src/transport/transport_api_address_iterate.c +++ b/src/transport/transport_api_address_iterate.c @@ -80,7 +80,8 @@ peer_address_response_processor (void *cls, struct AddressLookupCtx *alucb = cls; struct AddressIterateResponseMessage *address; uint16_t size; - char * transport; + char *transport; + //size_t transport_len; //void * addr; size_t addrlen; @@ -120,7 +121,7 @@ peer_address_response_processor (void *cls, transport = (char *) &address[0]; //transport_len = ntohs(address->pluginlen); - addrlen = ntohs(address->addrlen); + addrlen = ntohs (address->addrlen); /* expect more replies */ GNUNET_CLIENT_receive (alucb->client, &peer_address_response_processor, alucb, diff --git a/src/util/bandwidth.c b/src/util/bandwidth.c index a736b7607..0920362f5 100644 --- a/src/util/bandwidth.c +++ b/src/util/bandwidth.c @@ -60,11 +60,11 @@ GNUNET_BANDWIDTH_value_init (uint32_t bytes_per_second) */ struct GNUNET_BANDWIDTH_Value32NBO GNUNET_BANDWIDTH_value_min (struct GNUNET_BANDWIDTH_Value32NBO b1, - struct GNUNET_BANDWIDTH_Value32NBO b2) + struct GNUNET_BANDWIDTH_Value32NBO b2) { return - GNUNET_BANDWIDTH_value_init (GNUNET_MIN - (ntohl (b1.value__), ntohl (b2.value__))); + GNUNET_BANDWIDTH_value_init (GNUNET_MIN + (ntohl (b1.value__), ntohl (b2.value__))); } @@ -78,9 +78,9 @@ GNUNET_BANDWIDTH_value_min (struct GNUNET_BANDWIDTH_Value32NBO b1, */ uint64_t GNUNET_BANDWIDTH_value_get_available_until (struct GNUNET_BANDWIDTH_Value32NBO - bps, - struct GNUNET_TIME_Relative - deadline) + bps, + struct GNUNET_TIME_Relative + deadline) { uint64_t b; @@ -105,20 +105,20 @@ GNUNET_BANDWIDTH_value_get_available_until (struct GNUNET_BANDWIDTH_Value32NBO */ struct GNUNET_TIME_Relative GNUNET_BANDWIDTH_value_get_delay_for (struct GNUNET_BANDWIDTH_Value32NBO bps, - uint64_t size) + uint64_t size) { uint64_t b; struct GNUNET_TIME_Relative ret; b = ntohl (bps.value__); if (b == 0) - { + { #if DEBUG_BANDWIDTH - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Bandwidth suggests delay of infinity (zero bandwidth)\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Bandwidth suggests delay of infinity (zero bandwidth)\n"); #endif - return GNUNET_TIME_UNIT_FOREVER_REL; - } + return GNUNET_TIME_UNIT_FOREVER_REL; + } ret.rel_value = size * 1000LL / b; #if DEBUG_BANDWIDTH LOG (GNUNET_ERROR_TYPE_DEBUG, @@ -145,8 +145,8 @@ GNUNET_BANDWIDTH_value_get_delay_for (struct GNUNET_BANDWIDTH_Value32NBO bps, */ void GNUNET_BANDWIDTH_tracker_init (struct GNUNET_BANDWIDTH_Tracker *av, - struct GNUNET_BANDWIDTH_Value32NBO - bytes_per_second_limit, uint32_t max_carry_s) + struct GNUNET_BANDWIDTH_Value32NBO + bytes_per_second_limit, uint32_t max_carry_s) { av->consumption_since_last_update__ = 0; av->last_update__ = GNUNET_TIME_absolute_get (); @@ -155,8 +155,7 @@ GNUNET_BANDWIDTH_tracker_init (struct GNUNET_BANDWIDTH_Tracker *av, #if DEBUG_BANDWIDTH LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p initialized with %u Bps and max carry %u\n", av, - (unsigned int) av->available_bytes_per_s__, - (unsigned int) max_carry_s); + (unsigned int) av->available_bytes_per_s__, (unsigned int) max_carry_s); #endif } @@ -179,25 +178,25 @@ update_tracker (struct GNUNET_BANDWIDTH_Tracker *av) now = GNUNET_TIME_absolute_get (); delta_time = now.abs_value - av->last_update__.abs_value; delta_avail = - (delta_time * ((unsigned long long) av->available_bytes_per_s__) + - 500LL) / 1000LL; + (delta_time * ((unsigned long long) av->available_bytes_per_s__) + + 500LL) / 1000LL; av->consumption_since_last_update__ -= delta_avail; av->last_update__ = now; if (av->consumption_since_last_update__ < 0) - { - left_bytes = -av->consumption_since_last_update__; - max_carry = av->available_bytes_per_s__ * av->max_carry_s__; - if (max_carry < GNUNET_SERVER_MAX_MESSAGE_SIZE) - max_carry = GNUNET_SERVER_MAX_MESSAGE_SIZE; - if (max_carry > left_bytes) - av->consumption_since_last_update__ = -left_bytes; - else - av->consumption_since_last_update__ = -max_carry; - } + { + left_bytes = -av->consumption_since_last_update__; + max_carry = av->available_bytes_per_s__ * av->max_carry_s__; + if (max_carry < GNUNET_SERVER_MAX_MESSAGE_SIZE) + max_carry = GNUNET_SERVER_MAX_MESSAGE_SIZE; + if (max_carry > left_bytes) + av->consumption_since_last_update__ = -left_bytes; + else + av->consumption_since_last_update__ = -max_carry; + } #if DEBUG_BANDWIDTH LOG (GNUNET_ERROR_TYPE_DEBUG, - "Tracker %p updated, have %u Bps, last update was %llu ms ago\n", - av, (unsigned int) av->available_bytes_per_s__, + "Tracker %p updated, have %u Bps, last update was %llu ms ago\n", av, + (unsigned int) av->available_bytes_per_s__, (unsigned long long) delta_time); #endif @@ -217,7 +216,7 @@ update_tracker (struct GNUNET_BANDWIDTH_Tracker *av) */ int GNUNET_BANDWIDTH_tracker_consume (struct GNUNET_BANDWIDTH_Tracker *av, - ssize_t size) + ssize_t size) { int64_t nc; @@ -226,29 +225,29 @@ GNUNET_BANDWIDTH_tracker_consume (struct GNUNET_BANDWIDTH_Tracker *av, (int) size); #endif if (size > 0) + { + nc = av->consumption_since_last_update__ + size; + if (nc < av->consumption_since_last_update__) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + av->consumption_since_last_update__ = nc; + update_tracker (av); + if (av->consumption_since_last_update__ > 0) { - nc = av->consumption_since_last_update__ + size; - if (nc < av->consumption_since_last_update__) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - av->consumption_since_last_update__ = nc; - update_tracker (av); - if (av->consumption_since_last_update__ > 0) - { #if DEBUG_BANDWIDTH - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Tracker %p consumption %llu bytes above limit\n", av, - (unsigned long long) av->consumption_since_last_update__); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Tracker %p consumption %llu bytes above limit\n", av, + (unsigned long long) av->consumption_since_last_update__); #endif - return GNUNET_YES; - } + return GNUNET_YES; } + } else - { - av->consumption_since_last_update__ += size; - } + { + av->consumption_since_last_update__ += size; + } return GNUNET_NO; } @@ -264,35 +263,34 @@ GNUNET_BANDWIDTH_tracker_consume (struct GNUNET_BANDWIDTH_Tracker *av, */ struct GNUNET_TIME_Relative GNUNET_BANDWIDTH_tracker_get_delay (struct GNUNET_BANDWIDTH_Tracker *av, - size_t size) + size_t size) { struct GNUNET_TIME_Relative ret; int64_t bytes_needed; if (av->available_bytes_per_s__ == 0) - { + { #if DEBUG_BANDWIDTH - LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p delay is infinity\n", av); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p delay is infinity\n", av); #endif - return GNUNET_TIME_UNIT_FOREVER_REL; - } + return GNUNET_TIME_UNIT_FOREVER_REL; + } update_tracker (av); bytes_needed = size + av->consumption_since_last_update__; if (bytes_needed <= 0) - { + { #if DEBUG_BANDWIDTH - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Tracker %p delay for %u bytes is zero\n", av, - (unsigned int) size); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p delay for %u bytes is zero\n", av, + (unsigned int) size); #endif - return GNUNET_TIME_UNIT_ZERO; - } + return GNUNET_TIME_UNIT_ZERO; + } ret.rel_value = - (1000LL * bytes_needed) / (unsigned long long) av->available_bytes_per_s__; + (1000LL * bytes_needed) / + (unsigned long long) av->available_bytes_per_s__; #if DEBUG_BANDWIDTH - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Tracker %p delay for %u bytes is %llu ms\n", av, - (unsigned int) size, (unsigned long long) ret.rel_value); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p delay for %u bytes is %llu ms\n", + av, (unsigned int) size, (unsigned long long) ret.rel_value); #endif return ret; } @@ -315,9 +313,9 @@ GNUNET_BANDWIDTH_tracker_get_available (struct GNUNET_BANDWIDTH_Tracker * av) update_tracker (av); bps = GNUNET_BANDWIDTH_value_init (av->available_bytes_per_s__); avail = - GNUNET_BANDWIDTH_value_get_available_until (bps, - GNUNET_TIME_absolute_get_duration - (av->last_update__)); + GNUNET_BANDWIDTH_value_get_available_until (bps, + GNUNET_TIME_absolute_get_duration + (av->last_update__)); used = av->consumption_since_last_update__; #if DEBUG_BANDWIDTH LOG (GNUNET_ERROR_TYPE_DEBUG, @@ -336,23 +334,22 @@ GNUNET_BANDWIDTH_tracker_get_available (struct GNUNET_BANDWIDTH_Tracker * av) */ void GNUNET_BANDWIDTH_tracker_update_quota (struct GNUNET_BANDWIDTH_Tracker *av, - struct GNUNET_BANDWIDTH_Value32NBO - bytes_per_second_limit) + struct GNUNET_BANDWIDTH_Value32NBO + bytes_per_second_limit) { uint32_t old_limit; uint32_t new_limit; new_limit = ntohl (bytes_per_second_limit.value__); #if DEBUG_BANDWIDTH - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Tracker %p bandwidth changed to %u Bps\n", av, + LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p bandwidth changed to %u Bps\n", av, (unsigned int) new_limit); #endif update_tracker (av); old_limit = av->available_bytes_per_s__; av->available_bytes_per_s__ = new_limit; if (old_limit > new_limit) - update_tracker (av); /* maximum excess might be less now */ + update_tracker (av); /* maximum excess might be less now */ } diff --git a/src/util/bio.c b/src/util/bio.c index 9c2b9d0dd..41ad5fd5d 100644 --- a/src/util/bio.c +++ b/src/util/bio.c @@ -58,8 +58,7 @@ GNUNET_BIO_read_open (const char *fn) struct GNUNET_DISK_FileHandle *fd; struct GNUNET_BIO_ReadHandle *h; - fd = - GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE); + fd = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE); if (NULL == fd) return NULL; h = GNUNET_malloc (sizeof (struct GNUNET_BIO_ReadHandle) + BIO_BUFFER_SIZE); @@ -105,7 +104,7 @@ GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg) */ int GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, const char *what, - void *result, size_t len) + void *result, size_t len) { char *dst = result; size_t min; @@ -116,38 +115,38 @@ GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, const char *what, return GNUNET_SYSERR; pos = 0; do + { + /* first, use buffer */ + min = h->have - h->pos; + if (min > 0) { - /* first, use buffer */ - min = h->have - h->pos; - if (min > 0) - { - if (min > len - pos) - min = len - pos; - memcpy (&dst[pos], &h->buffer[h->pos], min); - h->pos += min; - pos += min; - } - if (pos == len) - return GNUNET_OK; /* done! */ - GNUNET_assert (h->have == h->pos); - /* fill buffer */ - ret = GNUNET_DISK_file_read (h->fd, h->buffer, h->size); - if (ret == -1) - { - GNUNET_asprintf (&h->emsg, _("Error reading `%s': %s"), what, - STRERROR (errno)); - return GNUNET_SYSERR; - } - if (ret == 0) - { - GNUNET_asprintf (&h->emsg, _("Error reading `%s': %s"), what, - _("End of file")); - return GNUNET_SYSERR; - } - h->pos = 0; - h->have = ret; + if (min > len - pos) + min = len - pos; + memcpy (&dst[pos], &h->buffer[h->pos], min); + h->pos += min; + pos += min; + } + if (pos == len) + return GNUNET_OK; /* done! */ + GNUNET_assert (h->have == h->pos); + /* fill buffer */ + ret = GNUNET_DISK_file_read (h->fd, h->buffer, h->size); + if (ret == -1) + { + GNUNET_asprintf (&h->emsg, _("Error reading `%s': %s"), what, + STRERROR (errno)); + return GNUNET_SYSERR; + } + if (ret == 0) + { + GNUNET_asprintf (&h->emsg, _("Error reading `%s': %s"), what, + _("End of file")); + return GNUNET_SYSERR; } - while (pos < len); /* should always be true */ + h->pos = 0; + h->have = ret; + } + while (pos < len); /* should always be true */ return GNUNET_OK; } @@ -163,8 +162,8 @@ GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, const char *what, * @return GNUNET_OK on success, GNUNET_SYSERR on failure */ int -GNUNET_BIO_read_fn (struct GNUNET_BIO_ReadHandle *h, const char *file, - int line, void *result, size_t len) +GNUNET_BIO_read_fn (struct GNUNET_BIO_ReadHandle *h, const char *file, int line, + void *result, size_t len) { char what[1024]; @@ -185,41 +184,39 @@ GNUNET_BIO_read_fn (struct GNUNET_BIO_ReadHandle *h, const char *file, */ int GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, const char *what, - char **result, size_t maxLen) + char **result, size_t maxLen) { char *buf; uint32_t big; if (GNUNET_OK != GNUNET_BIO_read_int32 (h, &big)) - { - GNUNET_free_non_null (h->emsg); - GNUNET_asprintf (&h->emsg, _("Error reading length of string `%s'"), - what); - return GNUNET_SYSERR; - } + { + GNUNET_free_non_null (h->emsg); + GNUNET_asprintf (&h->emsg, _("Error reading length of string `%s'"), what); + return GNUNET_SYSERR; + } if (big == 0) - { - *result = NULL; - return GNUNET_OK; - } + { + *result = NULL; + return GNUNET_OK; + } if (big > maxLen) - { - GNUNET_asprintf (&h->emsg, - _("String `%s' longer than allowed (%u > %u)"), what, - big, maxLen); - return GNUNET_SYSERR; - } + { + GNUNET_asprintf (&h->emsg, _("String `%s' longer than allowed (%u > %u)"), + what, big, maxLen); + return GNUNET_SYSERR; + } buf = GNUNET_malloc (big); *result = buf; buf[--big] = '\0'; if (big == 0) return GNUNET_OK; if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, big)) - { - GNUNET_free (buf); - *result = NULL; - return GNUNET_SYSERR; - } + { + GNUNET_free (buf); + *result = NULL; + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -234,7 +231,7 @@ GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, const char *what, */ int GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, const char *what, - struct GNUNET_CONTAINER_MetaData **result) + struct GNUNET_CONTAINER_MetaData **result) { uint32_t size; char *buf; @@ -243,32 +240,30 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, const char *what, if (GNUNET_BIO_read_int32 (h, (int32_t *) & size) != GNUNET_OK) return GNUNET_SYSERR; if (size == 0) - { - *result = NULL; - return GNUNET_OK; - } + { + *result = NULL; + return GNUNET_OK; + } if (size > MAX_META_DATA) - { - GNUNET_asprintf (&h->emsg, - _ - ("Serialized metadata `%s' larger than allowed (%u>%u)"), - what, size, MAX_META_DATA); - return GNUNET_SYSERR; - } + { + GNUNET_asprintf (&h->emsg, + _("Serialized metadata `%s' larger than allowed (%u>%u)"), + what, size, MAX_META_DATA); + return GNUNET_SYSERR; + } buf = GNUNET_malloc (size); if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, size)) - { - GNUNET_free (buf); - return GNUNET_SYSERR; - } + { + GNUNET_free (buf); + return GNUNET_SYSERR; + } meta = GNUNET_CONTAINER_meta_data_deserialize (buf, size); if (meta == NULL) - { - GNUNET_free (buf); - GNUNET_asprintf (&h->emsg, _("Metadata `%s' failed to deserialize"), - what); - return GNUNET_SYSERR; - } + { + GNUNET_free (buf); + GNUNET_asprintf (&h->emsg, _("Metadata `%s' failed to deserialize"), what); + return GNUNET_SYSERR; + } GNUNET_free (buf); *result = meta; return GNUNET_OK; @@ -286,7 +281,7 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, const char *what, */ int GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, const char *file, - int line, int32_t * i) + int line, int32_t * i) { int32_t big; @@ -308,7 +303,7 @@ GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, const char *file, */ int GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h, const char *file, - int line, int64_t * i) + int line, int64_t * i) { int64_t big; @@ -344,15 +339,13 @@ GNUNET_BIO_write_open (const char *fn) struct GNUNET_BIO_WriteHandle *h; fd = GNUNET_DISK_file_open (fn, - GNUNET_DISK_OPEN_WRITE | - GNUNET_DISK_OPEN_TRUNCATE | - GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE); + GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE + | GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE); if (NULL == fd) return NULL; - h = - GNUNET_malloc (sizeof (struct GNUNET_BIO_WriteHandle) + BIO_BUFFER_SIZE); + h = GNUNET_malloc (sizeof (struct GNUNET_BIO_WriteHandle) + BIO_BUFFER_SIZE); h->buffer = (char *) &h[1]; h->size = BIO_BUFFER_SIZE; h->fd = fd; @@ -374,18 +367,18 @@ GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h) int ret; if (NULL == h->fd) - { - ret = GNUNET_SYSERR; - } + { + ret = GNUNET_SYSERR; + } else - { - wrt = GNUNET_DISK_file_write (h->fd, h->buffer, h->have); - if (wrt == h->have) - ret = GNUNET_OK; - else - ret = GNUNET_SYSERR; - GNUNET_DISK_file_close (h->fd); - } + { + wrt = GNUNET_DISK_file_write (h->fd, h->buffer, h->have); + if (wrt == h->have) + ret = GNUNET_OK; + else + ret = GNUNET_SYSERR; + GNUNET_DISK_file_close (h->fd); + } GNUNET_free (h); return ret; } @@ -401,7 +394,7 @@ GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h) */ int GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, const void *buffer, - size_t n) + size_t n) { const char *src = buffer; size_t min; @@ -412,27 +405,27 @@ GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, const void *buffer, return GNUNET_SYSERR; pos = 0; do + { + /* first, just use buffer */ + min = h->size - h->have; + if (min > n - pos) + min = n - pos; + memcpy (&h->buffer[h->have], &src[pos], min); + pos += min; + h->have += min; + if (pos == n) + return GNUNET_OK; /* done */ + GNUNET_assert (h->have == h->size); + ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->size); + if (ret != h->size) { - /* first, just use buffer */ - min = h->size - h->have; - if (min > n - pos) - min = n - pos; - memcpy (&h->buffer[h->have], &src[pos], min); - pos += min; - h->have += min; - if (pos == n) - return GNUNET_OK; /* done */ - GNUNET_assert (h->have == h->size); - ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->size); - if (ret != h->size) - { - GNUNET_DISK_file_close (h->fd); - h->fd = NULL; - return GNUNET_SYSERR; /* error */ - } - h->have = 0; + GNUNET_DISK_file_close (h->fd); + h->fd = NULL; + return GNUNET_SYSERR; /* error */ } - while (pos < n); /* should always be true */ + h->have = 0; + } + while (pos < n); /* should always be true */ GNUNET_break (0); return GNUNET_OK; } @@ -468,7 +461,7 @@ GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, const char *s) */ int GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h, - const struct GNUNET_CONTAINER_MetaData *m) + const struct GNUNET_CONTAINER_MetaData *m) { ssize_t size; char *buf; @@ -477,19 +470,19 @@ GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h, return GNUNET_BIO_write_int32 (h, 0); buf = NULL; size = - GNUNET_CONTAINER_meta_data_serialize (m, &buf, MAX_META_DATA, - GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); + GNUNET_CONTAINER_meta_data_serialize (m, &buf, MAX_META_DATA, + GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); if (size == -1) - { - GNUNET_free (buf); - return GNUNET_SYSERR; - } + { + GNUNET_free (buf); + return GNUNET_SYSERR; + } if ((GNUNET_OK != GNUNET_BIO_write_int32 (h, (uint32_t) size)) || (GNUNET_OK != GNUNET_BIO_write (h, buf, size))) - { - GNUNET_free (buf); - return GNUNET_SYSERR; - } + { + GNUNET_free (buf); + return GNUNET_SYSERR; + } GNUNET_free (buf); return GNUNET_OK; } diff --git a/src/util/client.c b/src/util/client.c index d2f347947..e71ccdf39 100644 --- a/src/util/client.c +++ b/src/util/client.c @@ -259,8 +259,7 @@ struct GNUNET_CLIENT_Connection */ static struct GNUNET_CONNECTION_Handle * do_connect (const char *service_name, - const struct GNUNET_CONFIGURATION_Handle *cfg, - unsigned int attempt) + const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned int attempt) { struct GNUNET_CONNECTION_Handle *sock; char *hostname; @@ -270,80 +269,78 @@ do_connect (const char *service_name, sock = NULL; #if AF_UNIX if (0 == (attempt % 2)) + { + /* on even rounds, try UNIX */ + unixpath = NULL; + if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "UNIXPATH", &unixpath)) && (0 < strlen (unixpath))) /* We have a non-NULL unixpath, does that mean it's valid? */ { - /* on even rounds, try UNIX */ - unixpath = NULL; - if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "UNIXPATH", &unixpath)) && (0 < strlen (unixpath))) /* We have a non-NULL unixpath, does that mean it's valid? */ - { - sock = - GNUNET_CONNECTION_create_from_connect_to_unixpath (cfg, unixpath); - if (sock != NULL) - { + sock = GNUNET_CONNECTION_create_from_connect_to_unixpath (cfg, unixpath); + if (sock != NULL) + { #if DEBUG_CLIENT - LOG (GNUNET_ERROR_TYPE_DEBUG, "Connected to unixpath `%s'!\n", - unixpath); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Connected to unixpath `%s'!\n", + unixpath); #endif - GNUNET_free (unixpath); - return sock; - } - } - GNUNET_free_non_null (unixpath); + GNUNET_free (unixpath); + return sock; + } } + GNUNET_free_non_null (unixpath); + } #endif if ((GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (cfg, service_name, "PORT", - &port)) || (port > 65535) - || (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string (cfg, service_name, - "HOSTNAME", &hostname))) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - _ - ("Could not determine valid hostname and port for service `%s' from configuration.\n"), - service_name); - return NULL; - } + GNUNET_CONFIGURATION_get_value_number (cfg, service_name, "PORT", &port)) + || (port > 65535) || + (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "HOSTNAME", + &hostname))) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + _ + ("Could not determine valid hostname and port for service `%s' from configuration.\n"), + service_name); + return NULL; + } if (0 == strlen (hostname)) - { - GNUNET_free (hostname); - LOG (GNUNET_ERROR_TYPE_WARNING, - _("Need a non-empty hostname for service `%s'.\n"), service_name); - return NULL; - } + { + GNUNET_free (hostname); + LOG (GNUNET_ERROR_TYPE_WARNING, + _("Need a non-empty hostname for service `%s'.\n"), service_name); + return NULL; + } if (port == 0) - { + { #if AF_UNIX - if (0 != (attempt % 2)) - { - /* try UNIX */ - unixpath = NULL; - if ((GNUNET_OK == - GNUNET_CONFIGURATION_get_value_string (cfg, service_name, - "UNIXPATH", &unixpath)) - && (0 < strlen (unixpath))) - { - sock = - GNUNET_CONNECTION_create_from_connect_to_unixpath (cfg, - unixpath); - if (sock != NULL) - { - GNUNET_free (unixpath); - GNUNET_free (hostname); - return sock; - } - } - GNUNET_free_non_null (unixpath); - } + if (0 != (attempt % 2)) + { + /* try UNIX */ + unixpath = NULL; + if ((GNUNET_OK == + GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "UNIXPATH", + &unixpath)) && + (0 < strlen (unixpath))) + { + sock = + GNUNET_CONNECTION_create_from_connect_to_unixpath (cfg, unixpath); + if (sock != NULL) + { + GNUNET_free (unixpath); + GNUNET_free (hostname); + return sock; + } + } + GNUNET_free_non_null (unixpath); + } #endif #if DEBUG_CLIENT - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Port is 0 for service `%s', UNIXPATH did not work, returning NULL!\n", - service_name); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Port is 0 for service `%s', UNIXPATH did not work, returning NULL!\n", + service_name); #endif - GNUNET_free (hostname); - return NULL; - } + GNUNET_free (hostname); + return NULL; + } sock = GNUNET_CONNECTION_create_from_connect (cfg, hostname, port); GNUNET_free (hostname); @@ -360,7 +357,7 @@ do_connect (const char *service_name, */ struct GNUNET_CLIENT_Connection * GNUNET_CLIENT_connect (const char *service_name, - const struct GNUNET_CONFIGURATION_Handle *cfg) + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_CLIENT_Connection *ret; struct GNUNET_CONNECTION_Handle *sock; @@ -393,33 +390,33 @@ GNUNET_CLIENT_connect (const char *service_name, */ void GNUNET_CLIENT_disconnect (struct GNUNET_CLIENT_Connection *sock, - int finish_pending_write) + int finish_pending_write) { if (sock->in_receive == GNUNET_YES) - { - GNUNET_CONNECTION_receive_cancel (sock->sock); - sock->in_receive = GNUNET_NO; - } + { + GNUNET_CONNECTION_receive_cancel (sock->sock); + sock->in_receive = GNUNET_NO; + } if (sock->th != NULL) - { - GNUNET_CLIENT_notify_transmit_ready_cancel (sock->th); - sock->th = NULL; - } + { + GNUNET_CLIENT_notify_transmit_ready_cancel (sock->th); + sock->th = NULL; + } if (NULL != sock->sock) - { - GNUNET_CONNECTION_destroy (sock->sock, finish_pending_write); - sock->sock = NULL; - } + { + GNUNET_CONNECTION_destroy (sock->sock, finish_pending_write); + sock->sock = NULL; + } if (sock->receive_task != GNUNET_SCHEDULER_NO_TASK) - { - GNUNET_SCHEDULER_cancel (sock->receive_task); - sock->receive_task = GNUNET_SCHEDULER_NO_TASK; - } + { + GNUNET_SCHEDULER_cancel (sock->receive_task); + sock->receive_task = GNUNET_SCHEDULER_NO_TASK; + } if (sock->tag != NULL) - { - GNUNET_free (sock->tag); - sock->tag = NULL; - } + { + GNUNET_free (sock->tag); + sock->tag = NULL; + } sock->receiver_handler = NULL; GNUNET_array_grow (sock->received_buf, sock->received_size, 0); GNUNET_free (sock->service_name); @@ -436,7 +433,7 @@ check_complete (struct GNUNET_CLIENT_Connection *conn) if ((conn->received_pos >= sizeof (struct GNUNET_MessageHeader)) && (conn->received_pos >= ntohs (((const struct GNUNET_MessageHeader *) conn->received_buf)-> - size))) + size))) conn->msg_complete = GNUNET_YES; } @@ -455,7 +452,7 @@ check_complete (struct GNUNET_CLIENT_Connection *conn) */ static void receive_helper (void *cls, const void *buf, size_t available, - const struct sockaddr *addr, socklen_t addrlen, int errCode) + const struct sockaddr *addr, socklen_t addrlen, int errCode) { struct GNUNET_CLIENT_Connection *conn = cls; struct GNUNET_TIME_Relative remaining; @@ -465,22 +462,22 @@ receive_helper (void *cls, const void *buf, size_t available, GNUNET_assert (conn->msg_complete == GNUNET_NO); conn->in_receive = GNUNET_NO; if ((available == 0) || (conn->sock == NULL) || (errCode != 0)) - { - /* signal timeout! */ + { + /* signal timeout! */ #if DEBUG_CLIENT - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Timeout in receive_helper, available %u, conn->sock %s, errCode `%s'\n", - (unsigned int) available, - conn->sock == NULL ? "NULL" : "non-NULL", STRERROR (errCode)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Timeout in receive_helper, available %u, conn->sock %s, errCode `%s'\n", + (unsigned int) available, conn->sock == NULL ? "NULL" : "non-NULL", + STRERROR (errCode)); #endif - if (NULL != (receive_handler = conn->receiver_handler)) - { - receive_handler_cls = conn->receiver_handler_cls; - conn->receiver_handler = NULL; - receive_handler (receive_handler_cls, NULL); - } - return; + if (NULL != (receive_handler = conn->receiver_handler)) + { + receive_handler_cls = conn->receiver_handler_cls; + conn->receiver_handler = NULL; + receive_handler (receive_handler_cls, NULL); } + return; + } /* FIXME: optimize for common fast case where buf contains the * entire message and we need no copying... */ @@ -489,22 +486,22 @@ receive_helper (void *cls, const void *buf, size_t available, /* slow path: append to array */ if (conn->received_size < conn->received_pos + available) GNUNET_array_grow (conn->received_buf, conn->received_size, - conn->received_pos + available); + conn->received_pos + available); memcpy (&conn->received_buf[conn->received_pos], buf, available); conn->received_pos += available; check_complete (conn); /* check for timeout */ remaining = GNUNET_TIME_absolute_get_remaining (conn->receive_timeout); if (remaining.rel_value == 0) - { - /* signal timeout! */ - if (NULL != conn->receiver_handler) - conn->receiver_handler (conn->receiver_handler_cls, NULL); - return; - } + { + /* signal timeout! */ + if (NULL != conn->receiver_handler) + conn->receiver_handler (conn->receiver_handler_cls, NULL); + return; + } /* back to receive -- either for more data or to call callback! */ GNUNET_CLIENT_receive (conn, conn->receiver_handler, - conn->receiver_handler_cls, remaining); + conn->receiver_handler_cls, remaining); } @@ -520,23 +517,22 @@ receive_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) struct GNUNET_CLIENT_Connection *sock = cls; GNUNET_CLIENT_MessageHandler handler = sock->receiver_handler; const struct GNUNET_MessageHeader *cmsg = - (const struct GNUNET_MessageHeader *) sock->received_buf; + (const struct GNUNET_MessageHeader *) sock->received_buf; void *handler_cls = sock->receiver_handler_cls; uint16_t msize = ntohs (cmsg->size); char mbuf[msize]; struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) mbuf; #if DEBUG_CLIENT - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Received message of type %u and size %u\n", ntohs (cmsg->type), - msize); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Received message of type %u and size %u\n", + ntohs (cmsg->type), msize); #endif sock->receive_task = GNUNET_SCHEDULER_NO_TASK; GNUNET_assert (GNUNET_YES == sock->msg_complete); GNUNET_assert (sock->received_pos >= msize); memcpy (msg, cmsg, msize); memmove (sock->received_buf, &sock->received_buf[msize], - sock->received_pos - msize); + sock->received_pos - msize); sock->received_pos -= msize; sock->msg_complete = GNUNET_NO; sock->receiver_handler = NULL; @@ -556,36 +552,35 @@ receive_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) */ void GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *sock, - GNUNET_CLIENT_MessageHandler handler, - void *handler_cls, struct GNUNET_TIME_Relative timeout) + GNUNET_CLIENT_MessageHandler handler, void *handler_cls, + struct GNUNET_TIME_Relative timeout) { if (sock->sock == NULL) - { - /* already disconnected, fail instantly! */ - GNUNET_break (0); /* this should not happen in well-written code! */ - if (NULL != handler) - handler (handler_cls, NULL); - return; - } + { + /* already disconnected, fail instantly! */ + GNUNET_break (0); /* this should not happen in well-written code! */ + if (NULL != handler) + handler (handler_cls, NULL); + return; + } sock->receiver_handler = handler; sock->receiver_handler_cls = handler_cls; sock->receive_timeout = GNUNET_TIME_relative_to_absolute (timeout); if (GNUNET_YES == sock->msg_complete) - { - GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->receive_task); - sock->receive_task = GNUNET_SCHEDULER_add_now (&receive_task, sock); - } + { + GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->receive_task); + sock->receive_task = GNUNET_SCHEDULER_add_now (&receive_task, sock); + } else - { - GNUNET_assert (sock->in_receive == GNUNET_NO); - sock->in_receive = GNUNET_YES; + { + GNUNET_assert (sock->in_receive == GNUNET_NO); + sock->in_receive = GNUNET_YES; #if DEBUG_CLIENT - LOG (GNUNET_ERROR_TYPE_DEBUG, "calling GNUNET_CONNECTION_receive\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "calling GNUNET_CONNECTION_receive\n"); #endif - GNUNET_CONNECTION_receive (sock->sock, - GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, timeout, - &receive_helper, sock); - } + GNUNET_CONNECTION_receive (sock->sock, GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, + timeout, &receive_helper, sock); + } } @@ -596,7 +591,7 @@ static void service_test_error (GNUNET_SCHEDULER_Task task, void *task_cls) { GNUNET_SCHEDULER_add_continuation (task, task_cls, - GNUNET_SCHEDULER_REASON_TIMEOUT); + GNUNET_SCHEDULER_REASON_TIMEOUT); } @@ -615,18 +610,18 @@ confirm_handler (void *cls, const struct GNUNET_MessageHeader *msg) * detail in the future, for example, is this the * correct service? FIXME! */ if (msg != NULL) - { + { #if DEBUG_CLIENT - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Received confirmation that service is running.\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Received confirmation that service is running.\n"); #endif - GNUNET_SCHEDULER_add_continuation (conn->test_cb, conn->test_cb_cls, - GNUNET_SCHEDULER_REASON_PREREQ_DONE); - } + GNUNET_SCHEDULER_add_continuation (conn->test_cb, conn->test_cb_cls, + GNUNET_SCHEDULER_REASON_PREREQ_DONE); + } else - { - service_test_error (conn->test_cb, conn->test_cb_cls); - } + { + service_test_error (conn->test_cb, conn->test_cb_cls); + } GNUNET_CLIENT_disconnect (conn, GNUNET_NO); } @@ -647,14 +642,14 @@ write_test (void *cls, size_t size, void *buf) struct GNUNET_MessageHeader *msg; if (size < sizeof (struct GNUNET_MessageHeader)) - { + { #if DEBUG_CLIENT - LOG (GNUNET_ERROR_TYPE_DEBUG, _("Failure to transmit TEST request.\n")); + LOG (GNUNET_ERROR_TYPE_DEBUG, _("Failure to transmit TEST request.\n")); #endif - service_test_error (conn->test_cb, conn->test_cb_cls); - GNUNET_CLIENT_disconnect (conn, GNUNET_NO); - return 0; /* client disconnected */ - } + service_test_error (conn->test_cb, conn->test_cb_cls); + GNUNET_CLIENT_disconnect (conn, GNUNET_NO); + return 0; /* client disconnected */ + } #if DEBUG_CLIENT LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting `%s' request.\n", "TEST"); #endif @@ -662,8 +657,8 @@ write_test (void *cls, size_t size, void *buf) msg->type = htons (GNUNET_MESSAGE_TYPE_TEST); msg->size = htons (sizeof (struct GNUNET_MessageHeader)); GNUNET_CLIENT_receive (conn, &confirm_handler, conn, - GNUNET_TIME_absolute_get_remaining - (conn->test_deadline)); + GNUNET_TIME_absolute_get_remaining + (conn->test_deadline)); return sizeof (struct GNUNET_MessageHeader); } @@ -683,9 +678,9 @@ write_test (void *cls, size_t size, void *buf) */ void GNUNET_CLIENT_service_test (const char *service, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TIME_Relative timeout, - GNUNET_SCHEDULER_Task task, void *task_cls) + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TIME_Relative timeout, + GNUNET_SCHEDULER_Task task, void *task_cls) { char *hostname; unsigned long long port; @@ -704,50 +699,49 @@ GNUNET_CLIENT_service_test (const char *service, char *unixpath; unixpath = NULL; - if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, service, "UNIXPATH", &unixpath)) && (0 < strlen (unixpath))) /* We have a non-NULL unixpath, does that mean it's valid? */ + if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, service, "UNIXPATH", &unixpath)) && (0 < strlen (unixpath))) /* We have a non-NULL unixpath, does that mean it's valid? */ + { + if (strlen (unixpath) >= sizeof (s_un.sun_path)) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + _("UNIXPATH `%s' too long, maximum length is %llu\n"), unixpath, + sizeof (s_un.sun_path)); + } + else { - if (strlen (unixpath) >= sizeof (s_un.sun_path)) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - _("UNIXPATH `%s' too long, maximum length is %llu\n"), - unixpath, sizeof (s_un.sun_path)); - } - else - { - sock = GNUNET_NETWORK_socket_create (PF_UNIX, SOCK_STREAM, 0); - if (sock != NULL) - { - memset (&s_un, 0, sizeof (s_un)); - s_un.sun_family = AF_UNIX; - slen = strlen (unixpath) + 1; - if (slen >= sizeof (s_un.sun_path)) - slen = sizeof (s_un.sun_path) - 1; - memcpy (s_un.sun_path, unixpath, slen); - s_un.sun_path[slen] = '\0'; - slen = sizeof (struct sockaddr_un); + sock = GNUNET_NETWORK_socket_create (PF_UNIX, SOCK_STREAM, 0); + if (sock != NULL) + { + memset (&s_un, 0, sizeof (s_un)); + s_un.sun_family = AF_UNIX; + slen = strlen (unixpath) + 1; + if (slen >= sizeof (s_un.sun_path)) + slen = sizeof (s_un.sun_path) - 1; + memcpy (s_un.sun_path, unixpath, slen); + s_un.sun_path[slen] = '\0'; + slen = sizeof (struct sockaddr_un); #if LINUX - s_un.sun_path[0] = '\0'; + s_un.sun_path[0] = '\0'; #endif #if HAVE_SOCKADDR_IN_SIN_LEN - s_un.sun_len = (u_char) slen; + s_un.sun_len = (u_char) slen; #endif - if (GNUNET_OK != - GNUNET_NETWORK_socket_bind (sock, - (const struct sockaddr *) - &s_un, slen)) - { - /* failed to bind => service must be running */ - GNUNET_free (unixpath); - (void) GNUNET_NETWORK_socket_close (sock); - GNUNET_SCHEDULER_add_continuation (task, task_cls, - GNUNET_SCHEDULER_REASON_PREREQ_DONE); - return; - } - (void) GNUNET_NETWORK_socket_close (sock); - } - /* let's try IP */ - } + if (GNUNET_OK != + GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_un, + slen)) + { + /* failed to bind => service must be running */ + GNUNET_free (unixpath); + (void) GNUNET_NETWORK_socket_close (sock); + GNUNET_SCHEDULER_add_continuation (task, task_cls, + GNUNET_SCHEDULER_REASON_PREREQ_DONE); + return; + } + (void) GNUNET_NETWORK_socket_close (sock); + } + /* let's try IP */ } + } GNUNET_free_non_null (unixpath); } #endif @@ -758,124 +752,121 @@ GNUNET_CLIENT_service_test (const char *service, (port > 65535) || (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, service, "HOSTNAME", - &hostname))) - { - /* UNIXPATH failed (if possible) AND IP failed => error */ - service_test_error (task, task_cls); - return; - } + &hostname))) + { + /* UNIXPATH failed (if possible) AND IP failed => error */ + service_test_error (task, task_cls); + return; + } if (0 == strcmp ("localhost", hostname) #if !LINUX && 0 #endif - ) - { - /* can test using 'bind' */ - struct sockaddr_in s_in; + ) + { + /* can test using 'bind' */ + struct sockaddr_in s_in; - memset (&s_in, 0, sizeof (s_in)); + memset (&s_in, 0, sizeof (s_in)); #if HAVE_SOCKADDR_IN_SIN_LEN - s_in.sin_len = sizeof (struct sockaddr_in); + s_in.sin_len = sizeof (struct sockaddr_in); #endif - s_in.sin_family = AF_INET; - s_in.sin_port = htons (port); + s_in.sin_family = AF_INET; + s_in.sin_port = htons (port); - sock = GNUNET_NETWORK_socket_create (AF_INET, SOCK_STREAM, 0); - if (sock != NULL) - { - if (GNUNET_OK != - GNUNET_NETWORK_socket_bind (sock, - (const struct sockaddr *) &s_in, - sizeof (s_in))) - { - /* failed to bind => service must be running */ - GNUNET_free (hostname); - (void) GNUNET_NETWORK_socket_close (sock); - GNUNET_SCHEDULER_add_continuation (task, task_cls, - GNUNET_SCHEDULER_REASON_PREREQ_DONE); - return; - } - (void) GNUNET_NETWORK_socket_close (sock); - } + sock = GNUNET_NETWORK_socket_create (AF_INET, SOCK_STREAM, 0); + if (sock != NULL) + { + if (GNUNET_OK != + GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_in, + sizeof (s_in))) + { + /* failed to bind => service must be running */ + GNUNET_free (hostname); + (void) GNUNET_NETWORK_socket_close (sock); + GNUNET_SCHEDULER_add_continuation (task, task_cls, + GNUNET_SCHEDULER_REASON_PREREQ_DONE); + return; + } + (void) GNUNET_NETWORK_socket_close (sock); } + } if (0 == strcmp ("ip6-localhost", hostname) #if !LINUX && 0 #endif - ) - { - /* can test using 'bind' */ - struct sockaddr_in6 s_in6; + ) + { + /* can test using 'bind' */ + struct sockaddr_in6 s_in6; - memset (&s_in6, 0, sizeof (s_in6)); + memset (&s_in6, 0, sizeof (s_in6)); #if HAVE_SOCKADDR_IN_SIN_LEN - s_in6.sin6_len = sizeof (struct sockaddr_in6); + s_in6.sin6_len = sizeof (struct sockaddr_in6); #endif - s_in6.sin6_family = AF_INET6; - s_in6.sin6_port = htons (port); + s_in6.sin6_family = AF_INET6; + s_in6.sin6_port = htons (port); - sock = GNUNET_NETWORK_socket_create (AF_INET6, SOCK_STREAM, 0); - if (sock != NULL) - { - if (GNUNET_OK != - GNUNET_NETWORK_socket_bind (sock, - (const struct sockaddr *) &s_in6, - sizeof (s_in6))) - { - /* failed to bind => service must be running */ - GNUNET_free (hostname); - (void) GNUNET_NETWORK_socket_close (sock); - GNUNET_SCHEDULER_add_continuation (task, task_cls, - GNUNET_SCHEDULER_REASON_PREREQ_DONE); - return; - } - (void) GNUNET_NETWORK_socket_close (sock); - } + sock = GNUNET_NETWORK_socket_create (AF_INET6, SOCK_STREAM, 0); + if (sock != NULL) + { + if (GNUNET_OK != + GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_in6, + sizeof (s_in6))) + { + /* failed to bind => service must be running */ + GNUNET_free (hostname); + (void) GNUNET_NETWORK_socket_close (sock); + GNUNET_SCHEDULER_add_continuation (task, task_cls, + GNUNET_SCHEDULER_REASON_PREREQ_DONE); + return; + } + (void) GNUNET_NETWORK_socket_close (sock); } + } if (((0 == strcmp ("localhost", hostname)) || (0 == strcmp ("ip6-localhost", hostname))) #if !LINUX && 0 #endif - ) - { - /* all binds succeeded => claim service not running right now */ - GNUNET_free_non_null (hostname); - service_test_error (task, task_cls); - return; - } + ) + { + /* all binds succeeded => claim service not running right now */ + GNUNET_free_non_null (hostname); + service_test_error (task, task_cls); + return; + } GNUNET_free_non_null (hostname); /* non-localhost, try 'connect' method */ conn = GNUNET_CLIENT_connect (service, cfg); if (conn == NULL) - { - LOG (GNUNET_ERROR_TYPE_INFO, - _("Could not connect to service `%s', must not be running.\n"), - service); - service_test_error (task, task_cls); - return; - } + { + LOG (GNUNET_ERROR_TYPE_INFO, + _("Could not connect to service `%s', must not be running.\n"), + service); + service_test_error (task, task_cls); + return; + } conn->test_cb = task; conn->test_cb_cls = task_cls; conn->test_deadline = GNUNET_TIME_relative_to_absolute (timeout); if (NULL == GNUNET_CLIENT_notify_transmit_ready (conn, - sizeof (struct - GNUNET_MessageHeader), - timeout, GNUNET_YES, &write_test, - conn)) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - _("Failure to transmit request to service `%s'\n"), service); - service_test_error (task, task_cls); - GNUNET_CLIENT_disconnect (conn, GNUNET_NO); - return; - } + sizeof (struct GNUNET_MessageHeader), + timeout, GNUNET_YES, &write_test, + conn)) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + _("Failure to transmit request to service `%s'\n"), service); + service_test_error (task, task_cls); + GNUNET_CLIENT_disconnect (conn, GNUNET_NO); + return; + } } @@ -889,7 +880,8 @@ GNUNET_CLIENT_service_test (const char *service, * @param buf where to write them * @return number of bytes written to buf */ -static size_t client_notify (void *cls, size_t size, void *buf); +static size_t +client_notify (void *cls, size_t size, void *buf); /** @@ -900,58 +892,57 @@ static size_t client_notify (void *cls, size_t size, void *buf); * @param tc unused */ static void -client_delayed_retry (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +client_delayed_retry (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_CLIENT_TransmitHandle *th = cls; struct GNUNET_TIME_Relative delay; th->reconnect_task = GNUNET_SCHEDULER_NO_TASK; if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) - { + { #if DEBUG_CLIENT - LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmission failed due to shutdown.\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmission failed due to shutdown.\n"); #endif - th->sock->th = NULL; - th->notify (th->notify_cls, 0, NULL); - GNUNET_free (th); - return; - } + th->sock->th = NULL; + th->notify (th->notify_cls, 0, NULL); + GNUNET_free (th); + return; + } th->sock->sock = - do_connect (th->sock->service_name, th->sock->cfg, th->sock->attempts++); + do_connect (th->sock->service_name, th->sock->cfg, th->sock->attempts++); if (NULL == th->sock->sock) - { - /* could happen if we're out of sockets */ - delay = - GNUNET_TIME_relative_min (GNUNET_TIME_absolute_get_remaining - (th->timeout), th->sock->back_off); - th->sock->back_off = - GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply - (th->sock->back_off, 2), - GNUNET_TIME_UNIT_SECONDS); + { + /* could happen if we're out of sockets */ + delay = + GNUNET_TIME_relative_min (GNUNET_TIME_absolute_get_remaining + (th->timeout), th->sock->back_off); + th->sock->back_off = + GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply + (th->sock->back_off, 2), + GNUNET_TIME_UNIT_SECONDS); #if DEBUG_CLIENT - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Transmission failed %u times, trying again in %llums.\n", - MAX_ATTEMPTS - th->attempts_left, - (unsigned long long) delay.rel_value); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Transmission failed %u times, trying again in %llums.\n", + MAX_ATTEMPTS - th->attempts_left, + (unsigned long long) delay.rel_value); #endif - th->reconnect_task = - GNUNET_SCHEDULER_add_delayed (delay, &client_delayed_retry, th); - return; - } + th->reconnect_task = + GNUNET_SCHEDULER_add_delayed (delay, &client_delayed_retry, th); + return; + } th->th = - GNUNET_CONNECTION_notify_transmit_ready (th->sock->sock, th->size, - GNUNET_TIME_absolute_get_remaining - (th->timeout), &client_notify, - th); + GNUNET_CONNECTION_notify_transmit_ready (th->sock->sock, th->size, + GNUNET_TIME_absolute_get_remaining + (th->timeout), &client_notify, + th); if (th->th == NULL) - { - GNUNET_break (0); - th->sock->th = NULL; - th->notify (th->notify_cls, 0, NULL); - GNUNET_free (th); - return; - } + { + GNUNET_break (0); + th->sock->th = NULL; + th->notify (th->notify_cls, 0, NULL); + GNUNET_free (th); + return; + } } @@ -974,47 +965,47 @@ client_notify (void *cls, size_t size, void *buf) th->th = NULL; th->sock->th = NULL; if (buf == NULL) + { + delay = GNUNET_TIME_absolute_get_remaining (th->timeout); + delay.rel_value /= 2; + if ((0 != + (GNUNET_SCHEDULER_REASON_SHUTDOWN & GNUNET_SCHEDULER_get_reason ())) || + (GNUNET_YES != th->auto_retry) || (0 == --th->attempts_left) || + (delay.rel_value < 1)) { - delay = GNUNET_TIME_absolute_get_remaining (th->timeout); - delay.rel_value /= 2; - if ((0 != - (GNUNET_SCHEDULER_REASON_SHUTDOWN & - GNUNET_SCHEDULER_get_reason ())) || (GNUNET_YES != th->auto_retry) - || (0 == --th->attempts_left) || (delay.rel_value < 1)) - { #if DEBUG_CLIENT - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Transmission failed %u times, giving up.\n", - MAX_ATTEMPTS - th->attempts_left); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Transmission failed %u times, giving up.\n", + MAX_ATTEMPTS - th->attempts_left); #endif - GNUNET_break (0 == th->notify (th->notify_cls, 0, NULL)); - GNUNET_free (th); - return 0; - } - /* auto-retry */ + GNUNET_break (0 == th->notify (th->notify_cls, 0, NULL)); + GNUNET_free (th); + return 0; + } + /* auto-retry */ #if DEBUG_CLIENT - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Failed to connect to `%s', automatically trying again.\n", - th->sock->service_name); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Failed to connect to `%s', automatically trying again.\n", + th->sock->service_name); #endif - GNUNET_CONNECTION_destroy (th->sock->sock, GNUNET_NO); - th->sock->sock = NULL; - delay = GNUNET_TIME_relative_min (delay, th->sock->back_off); - th->sock->back_off = - GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply - (th->sock->back_off, 2), - GNUNET_TIME_UNIT_SECONDS); + GNUNET_CONNECTION_destroy (th->sock->sock, GNUNET_NO); + th->sock->sock = NULL; + delay = GNUNET_TIME_relative_min (delay, th->sock->back_off); + th->sock->back_off = + GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply + (th->sock->back_off, 2), + GNUNET_TIME_UNIT_SECONDS); #if DEBUG_CLIENT - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Transmission failed %u times, trying again in %llums.\n", - MAX_ATTEMPTS - th->attempts_left, - (unsigned long long) delay.rel_value); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Transmission failed %u times, trying again in %llums.\n", + MAX_ATTEMPTS - th->attempts_left, + (unsigned long long) delay.rel_value); #endif - th->sock->th = th; - th->reconnect_task = - GNUNET_SCHEDULER_add_delayed (delay, &client_delayed_retry, th); - return 0; - } + th->sock->th = th; + th->reconnect_task = + GNUNET_SCHEDULER_add_delayed (delay, &client_delayed_retry, th); + return 0; + } GNUNET_assert (size >= th->size); ret = th->notify (th->notify_cls, size, buf); GNUNET_free (th); @@ -1043,21 +1034,21 @@ client_notify (void *cls, size_t size, void *buf) */ struct GNUNET_CLIENT_TransmitHandle * GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *sock, - size_t size, - struct GNUNET_TIME_Relative timeout, - int auto_retry, - GNUNET_CONNECTION_TransmitReadyNotify - notify, void *notify_cls) + size_t size, + struct GNUNET_TIME_Relative timeout, + int auto_retry, + GNUNET_CONNECTION_TransmitReadyNotify + notify, void *notify_cls) { struct GNUNET_CLIENT_TransmitHandle *th; if (NULL != sock->th) - { - /* If this breaks, you most likley called this function twice without waiting - * for completion or canceling the request */ - GNUNET_break (0); - return NULL; - } + { + /* If this breaks, you most likley called this function twice without waiting + * for completion or canceling the request */ + GNUNET_break (0); + return NULL; + } th = GNUNET_malloc (sizeof (struct GNUNET_CLIENT_TransmitHandle)); th->sock = sock; th->size = size; @@ -1068,25 +1059,25 @@ GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *sock, th->attempts_left = MAX_ATTEMPTS; sock->th = th; if (sock->sock == NULL) - { - th->reconnect_task = - GNUNET_SCHEDULER_add_delayed (sock->back_off, &client_delayed_retry, - th); + { + th->reconnect_task = + GNUNET_SCHEDULER_add_delayed (sock->back_off, &client_delayed_retry, + th); - } + } else + { + th->th = + GNUNET_CONNECTION_notify_transmit_ready (sock->sock, size, timeout, + &client_notify, th); + if (NULL == th->th) { - th->th = - GNUNET_CONNECTION_notify_transmit_ready (sock->sock, size, timeout, - &client_notify, th); - if (NULL == th->th) - { - GNUNET_break (0); - GNUNET_free (th); - sock->th = NULL; - return NULL; - } + GNUNET_break (0); + GNUNET_free (th); + sock->th = NULL; + return NULL; } + } return th; } @@ -1097,20 +1088,20 @@ GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *sock, * @param th handle from the original request. */ void -GNUNET_CLIENT_notify_transmit_ready_cancel (struct - GNUNET_CLIENT_TransmitHandle *th) +GNUNET_CLIENT_notify_transmit_ready_cancel (struct GNUNET_CLIENT_TransmitHandle + *th) { if (th->reconnect_task != GNUNET_SCHEDULER_NO_TASK) - { - GNUNET_assert (NULL == th->th); - GNUNET_SCHEDULER_cancel (th->reconnect_task); - th->reconnect_task = GNUNET_SCHEDULER_NO_TASK; - } + { + GNUNET_assert (NULL == th->th); + GNUNET_SCHEDULER_cancel (th->reconnect_task); + th->reconnect_task = GNUNET_SCHEDULER_NO_TASK; + } else - { - GNUNET_assert (NULL != th->th); - GNUNET_CONNECTION_notify_transmit_ready_cancel (th->th); - } + { + GNUNET_assert (NULL != th->th); + GNUNET_CONNECTION_notify_transmit_ready_cancel (th->th); + } th->sock->th = NULL; GNUNET_free (th); } @@ -1136,21 +1127,20 @@ transmit_for_response (void *cls, size_t size, void *buf) tc->sock->tag = NULL; msize = ntohs (tc->hdr->size); if (NULL == buf) - { + { #if DEBUG_CLIENT - LOG (GNUNET_ERROR_TYPE_DEBUG, - _ - ("Could not submit request, not expecting to receive a response.\n")); + LOG (GNUNET_ERROR_TYPE_DEBUG, + _("Could not submit request, not expecting to receive a response.\n")); #endif - if (NULL != tc->rn) - tc->rn (tc->rn_cls, NULL); - GNUNET_free (tc); - return 0; - } + if (NULL != tc->rn) + tc->rn (tc->rn_cls, NULL); + GNUNET_free (tc); + return 0; + } GNUNET_assert (size >= msize); memcpy (buf, tc->hdr, msize); GNUNET_CLIENT_receive (tc->sock, tc->rn, tc->rn_cls, - GNUNET_TIME_absolute_get_remaining (tc->timeout)); + GNUNET_TIME_absolute_get_remaining (tc->timeout)); GNUNET_free (tc); return msize; } @@ -1178,14 +1168,12 @@ transmit_for_response (void *cls, size_t size, void *buf) * is already pending */ int -GNUNET_CLIENT_transmit_and_get_response (struct GNUNET_CLIENT_Connection - *sock, - const struct GNUNET_MessageHeader - *hdr, - struct GNUNET_TIME_Relative timeout, - int auto_retry, - GNUNET_CLIENT_MessageHandler rn, - void *rn_cls) +GNUNET_CLIENT_transmit_and_get_response (struct GNUNET_CLIENT_Connection *sock, + const struct GNUNET_MessageHeader *hdr, + struct GNUNET_TIME_Relative timeout, + int auto_retry, + GNUNET_CLIENT_MessageHandler rn, + void *rn_cls) { struct TransmitGetResponseContext *tc; uint16_t msize; @@ -1203,12 +1191,12 @@ GNUNET_CLIENT_transmit_and_get_response (struct GNUNET_CLIENT_Connection tc->rn_cls = rn_cls; if (NULL == GNUNET_CLIENT_notify_transmit_ready (sock, msize, timeout, auto_retry, - &transmit_for_response, tc)) - { - GNUNET_break (0); - GNUNET_free (tc); - return GNUNET_SYSERR; - } + &transmit_for_response, tc)) + { + GNUNET_break (0); + GNUNET_free (tc); + return GNUNET_SYSERR; + } sock->tag = tc; return GNUNET_OK; } diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c index 31da5829b..340ad5334 100644 --- a/src/util/common_allocation.c +++ b/src/util/common_allocation.c @@ -65,10 +65,10 @@ GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber) GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, filename, linenumber); ret = GNUNET_xmalloc_unchecked_ (size, filename, linenumber); if (ret == NULL) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "malloc"); - abort (); - } + { + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "malloc"); + abort (); + } return ret; } @@ -86,7 +86,7 @@ GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber) */ void * GNUNET_xmemdup_ (const void *buf, size_t size, const char *filename, - int linenumber) + int linenumber) { void *ret; @@ -101,10 +101,10 @@ GNUNET_xmemdup_ (const void *buf, size_t size, const char *filename, GNUNET_assert_at (size < INT_MAX, filename, linenumber); ret = malloc (size); if (ret == NULL) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "malloc"); - abort (); - } + { + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "malloc"); + abort (); + } #ifdef W32_MEM_LIMIT *((size_t *) ret) = size; ret = &((size_t *) ret)[1]; @@ -172,10 +172,10 @@ GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber) #endif ptr = realloc (ptr, n); if ((NULL == ptr) && (n > 0)) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "realloc"); - abort (); - } + { + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "realloc"); + abort (); + } #ifdef W32_MEM_LIMIT ptr = &((size_t *) ptr)[1]; #endif @@ -233,7 +233,7 @@ GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber) */ char * GNUNET_xstrndup_ (const char *str, size_t len, const char *filename, - int linenumber) + int linenumber) { char *res; @@ -260,7 +260,7 @@ GNUNET_xstrndup_ (const char *str, size_t len, const char *filename, */ void GNUNET_xgrow_ (void **old, size_t elementSize, unsigned int *oldCount, - unsigned int newCount, const char *filename, int linenumber) + unsigned int newCount, const char *filename, int linenumber) { void *tmp; size_t size; @@ -268,22 +268,22 @@ GNUNET_xgrow_ (void **old, size_t elementSize, unsigned int *oldCount, GNUNET_assert_at (INT_MAX / elementSize > newCount, filename, linenumber); size = newCount * elementSize; if (size == 0) - { - tmp = NULL; - } + { + tmp = NULL; + } else - { - tmp = GNUNET_xmalloc_ (size, filename, linenumber); - memset (tmp, 0, size); /* client code should not rely on this, though... */ - if (*oldCount > newCount) - *oldCount = newCount; /* shrink is also allowed! */ - memcpy (tmp, *old, elementSize * (*oldCount)); - } + { + tmp = GNUNET_xmalloc_ (size, filename, linenumber); + memset (tmp, 0, size); /* client code should not rely on this, though... */ + if (*oldCount > newCount) + *oldCount = newCount; /* shrink is also allowed! */ + memcpy (tmp, *old, elementSize * (*oldCount)); + } if (*old != NULL) - { - GNUNET_xfree_ (*old, filename, linenumber); - } + { + GNUNET_xfree_ (*old, filename, linenumber); + } *old = tmp; *oldCount = newCount; } diff --git a/src/util/common_logging.c b/src/util/common_logging.c index 1d3843cfd..0b7d06bab 100644 --- a/src/util/common_logging.c +++ b/src/util/common_logging.c @@ -276,22 +276,21 @@ resize_logdefs () */ static void add_definition (char *component, char *file, char *function, int from_line, - int to_line, int level, int force) + int to_line, int level, int force) { if (logdefs_size == logdefs_len) resize_logdefs (); struct LogDef n; + memset (&n, 0, sizeof (n)); if (strlen (component) > 0 && component[0] != '*') n.component = GNUNET_strdup (component); if (strlen (file) > 0 && file[0] != '*') - { - n.file = GNUNET_strdup (file); - n.strlen_file = strlen (file); - } - if ( (NULL != function) && - (strlen (function) > 0) && - (function[0] != '*') ) + { + n.file = GNUNET_strdup (file); + n.strlen_file = strlen (file); + } + if ((NULL != function) && (strlen (function) > 0) && (function[0] != '*')) n.function = GNUNET_strdup (function); n.from_line = from_line; n.to_line = to_line; @@ -316,7 +315,7 @@ add_definition (char *component, char *file, char *function, int from_line, */ int GNUNET_get_log_call_status (int caller_level, const char *comp, - const char *file, const char *function, int line) + const char *file, const char *function, int line) { struct LogDef *ld; int i; @@ -337,20 +336,22 @@ GNUNET_get_log_call_status (int caller_level, const char *comp, force_only = min_level >= 0; strlen_file = strlen (file); for (i = 0; i < logdefs_len; i++) + { + ld = &logdefs[i]; + if ((!force_only || ld->force) && + (line >= ld->from_line && line <= ld->to_line) && (ld->component == NULL + || strcmp (comp, + ld->component) + == 0) && + (ld->file == NULL || + (ld->strlen_file <= strlen_file && + strcmp (&file[strlen_file - ld->strlen_file], ld->file) == 0)) && + (ld->function == NULL || strcmp (function, ld->function) == 0)) { - ld = &logdefs[i]; - if ((!force_only || ld->force) && - (line >= ld->from_line && line <= ld->to_line) && - (ld->component == NULL || strcmp (comp, ld->component) == 0) && - (ld->file == NULL || - (ld->strlen_file <= strlen_file && - strcmp (&file[strlen_file - ld->strlen_file], ld->file) == 0)) && - (ld->function == NULL || strcmp (function, ld->function) == 0)) - { - /* We're finished */ - return caller_level <= ld->level; - } + /* We're finished */ + return caller_level <= ld->level; } + } /* No matches - use global level, if defined */ if (min_level >= 0) return caller_level <= min_level; @@ -400,6 +401,7 @@ parse_definitions (const char *constname, int force) int from_line, to_line; int counter = 0; int keep_looking = 1; + tmp = getenv (constname); if (tmp == NULL) return 0; @@ -408,85 +410,84 @@ parse_definitions (const char *constname, int force) from_line = 0; to_line = INT_MAX; for (p = def, state = 0, start = def; keep_looking; p++) + { + switch (p[0]) { - switch (p[0]) - { - case ';': /* found a field separator */ - p[0] = '\0'; - switch (state) - { - case 0: /* within a component name */ - comp = start; - break; - case 1: /* within a file name */ - file = start; - break; - case 2: /* within a function name */ - /* after a file name there must be a function name */ - function = start; - break; - case 3: /* within a from-to line range */ - if (strlen (start) > 0) - { - errno = 0; - from_line = strtol (start, &t, 10); - if (errno != 0 || from_line < 0) - { - free (def); - return counter; - } - if (t < p && t[0] == '-') - { - errno = 0; - start = t + 1; - to_line = strtol (start, &t, 10); - if (errno != 0 || to_line < 0 || t != p) - { - free (def); - return counter; - } - } - else /* one number means "match this line only" */ - to_line = from_line; - } - else /* default to 0-max */ - { - from_line = 0; - to_line = INT_MAX; - } - break; - } - start = p + 1; - state += 1; - break; - case '\0': /* found EOL */ - keep_looking = 0; - /* fall through to '/' */ - case '/': /* found a definition separator */ - switch (state) - { - case 4: /* within a log level */ - p[0] = '\0'; - state = 0; - level = get_type ((const char *) start); - if (level == GNUNET_ERROR_TYPE_INVALID - || level == GNUNET_ERROR_TYPE_UNSPECIFIED) - { - free (def); - return counter; - } - add_definition (comp, file, function, from_line, to_line, level, - force); - counter += 1; - start = p + 1; - break; - default: - break; - } - default: - break; - } + case ';': /* found a field separator */ + p[0] = '\0'; + switch (state) + { + case 0: /* within a component name */ + comp = start; + break; + case 1: /* within a file name */ + file = start; + break; + case 2: /* within a function name */ + /* after a file name there must be a function name */ + function = start; + break; + case 3: /* within a from-to line range */ + if (strlen (start) > 0) + { + errno = 0; + from_line = strtol (start, &t, 10); + if (errno != 0 || from_line < 0) + { + free (def); + return counter; + } + if (t < p && t[0] == '-') + { + errno = 0; + start = t + 1; + to_line = strtol (start, &t, 10); + if (errno != 0 || to_line < 0 || t != p) + { + free (def); + return counter; + } + } + else /* one number means "match this line only" */ + to_line = from_line; + } + else /* default to 0-max */ + { + from_line = 0; + to_line = INT_MAX; + } + break; + } + start = p + 1; + state += 1; + break; + case '\0': /* found EOL */ + keep_looking = 0; + /* fall through to '/' */ + case '/': /* found a definition separator */ + switch (state) + { + case 4: /* within a log level */ + p[0] = '\0'; + state = 0; + level = get_type ((const char *) start); + if (level == GNUNET_ERROR_TYPE_INVALID || + level == GNUNET_ERROR_TYPE_UNSPECIFIED) + { + free (def); + return counter; + } + add_definition (comp, file, function, from_line, to_line, level, force); + counter += 1; + start = p + 1; + break; + default: + break; + } + default: + break; } + } free (def); return counter; } @@ -502,7 +503,7 @@ parse_all_definitions () gnunet_log_parsed = GNUNET_YES; if (gnunet_force_log_parsed == GNUNET_NO) gnunet_force_log_present = - parse_definitions ("GNUNET_FORCE_LOG", 1) > 0 ? GNUNET_YES : GNUNET_NO; + parse_definitions ("GNUNET_FORCE_LOG", 1) > 0 ? GNUNET_YES : GNUNET_NO; gnunet_force_log_parsed = GNUNET_YES; } #endif @@ -546,16 +547,15 @@ GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile) dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)); altlog = FOPEN (fn, "a"); if (altlog == NULL) - { - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", fn); - if (dirwarn) - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _ - ("Failed to create or access directory for log file `%s'\n"), - fn); - GNUNET_free (fn); - return GNUNET_SYSERR; - } + { + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", fn); + if (dirwarn) + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + _("Failed to create or access directory for log file `%s'\n"), + fn); + GNUNET_free (fn); + return GNUNET_SYSERR; + } GNUNET_free (fn); if (GNUNET_stderr != NULL) fclose (GNUNET_stderr); @@ -596,11 +596,11 @@ GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls) prev = NULL; pos = loggers; while ((pos != NULL) && - ((pos->logger != logger) || (pos->logger_cls != logger_cls))) - { - prev = pos; - pos = pos->next; - } + ((pos->logger != logger) || (pos->logger_cls != logger_cls))) + { + prev = pos; + pos = pos->next; + } GNUNET_assert (pos != NULL); if (prev == NULL) loggers = pos->next; @@ -620,22 +620,22 @@ GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls) */ static void output_message (enum GNUNET_ErrorType kind, const char *comp, - const char *datestr, const char *msg) + const char *datestr, const char *msg) { struct CustomLogger *pos; if (GNUNET_stderr != NULL) - { - fprintf (GNUNET_stderr, "%s %s %s %s", datestr, comp, - GNUNET_error_type_to_string (kind), msg); - fflush (GNUNET_stderr); - } + { + fprintf (GNUNET_stderr, "%s %s %s %s", datestr, comp, + GNUNET_error_type_to_string (kind), msg); + fflush (GNUNET_stderr); + } pos = loggers; while (pos != NULL) - { - pos->logger (pos->logger_cls, kind, comp, datestr, msg); - pos = pos->next; - } + { + pos->logger (pos->logger_cls, kind, comp, datestr, msg); + pos = pos->next; + } } @@ -661,16 +661,15 @@ flush_bulk (const char *datestr) else if (last != last_bulk) last--; if (last[0] == '\n') - { - rev = 1; - last[0] = '\0'; - } - ft = - GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration - (last_bulk_time)); + { + rev = 1; + last[0] = '\0'; + } + ft = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration + (last_bulk_time)); snprintf (msg, sizeof (msg), - _("Message `%.*s' repeated %u times in the last %s\n"), - BULK_TRACK_SIZE, last_bulk, last_bulk_repeat, ft); + _("Message `%.*s' repeated %u times in the last %s\n"), + BULK_TRACK_SIZE, last_bulk, last_bulk_repeat, ft); GNUNET_free (ft); if (rev == 1) last[0] = '\n'; @@ -690,14 +689,14 @@ void GNUNET_log_skip (unsigned int n, int check_reset) { if (n == 0) - { - int ok; + { + int ok; - ok = (0 == skip_log); - skip_log = 0; - if (check_reset) - GNUNET_assert (ok); - } + ok = (0 == skip_log); + skip_log = 0; + if (check_reset) + GNUNET_assert (ok); + } else skip_log += n; } @@ -736,34 +735,33 @@ mylog (enum GNUNET_ErrorType kind, const char *comp, const char *message, tmptr = localtime (&timetmp); gettimeofday (&timeofday, NULL); if (NULL != tmptr) - { + { #ifdef WINDOWS - LARGE_INTEGER pc; - - pc.QuadPart = 0; - QueryPerformanceCounter (&pc); - strftime (date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%020llu", tmptr); - snprintf (date, sizeof (date), date2, - (long long) (pc.QuadPart / - (performance_frequency.QuadPart / 1000))); + LARGE_INTEGER pc; + + pc.QuadPart = 0; + QueryPerformanceCounter (&pc); + strftime (date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%020llu", tmptr); + snprintf (date, sizeof (date), date2, + (long long) (pc.QuadPart / + (performance_frequency.QuadPart / 1000))); #else - strftime (date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%06u", tmptr); - snprintf (date, sizeof (date), date2, timeofday.tv_usec); + strftime (date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%06u", tmptr); + snprintf (date, sizeof (date), date2, timeofday.tv_usec); #endif - } + } else strcpy (date, "localtime error"); - if ((0 != (kind & GNUNET_ERROR_TYPE_BULK)) - && (last_bulk_time.abs_value != 0) - && (0 == strncmp (buf, last_bulk, sizeof (last_bulk)))) - { - last_bulk_repeat++; - if ((GNUNET_TIME_absolute_get_duration (last_bulk_time).rel_value > - BULK_DELAY_THRESHOLD) - || (last_bulk_repeat > BULK_REPEAT_THRESHOLD)) - flush_bulk (date); - return; - } + if ((0 != (kind & GNUNET_ERROR_TYPE_BULK)) && + (last_bulk_time.abs_value != 0) && + (0 == strncmp (buf, last_bulk, sizeof (last_bulk)))) + { + last_bulk_repeat++; + if ((GNUNET_TIME_absolute_get_duration (last_bulk_time).rel_value > + BULK_DELAY_THRESHOLD) || (last_bulk_repeat > BULK_REPEAT_THRESHOLD)) + flush_bulk (date); + return; + } flush_bulk (date); strncpy (last_bulk, buf, sizeof (last_bulk)); last_bulk_repeat = 0; @@ -804,7 +802,7 @@ GNUNET_log_nocheck (enum GNUNET_ErrorType kind, const char *message, ...) */ void GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, const char *comp, - const char *message, ...) + const char *message, ...) { va_list va; char comp_w_pid[128]; @@ -922,44 +920,44 @@ GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen) if (addr == NULL) return _("unknown address"); switch (addr->sa_family) - { - case AF_INET: - if (addrlen != sizeof (struct sockaddr_in)) - return ""; - v4 = (const struct sockaddr_in *) addr; - inet_ntop (AF_INET, &v4->sin_addr, buf, INET_ADDRSTRLEN); - if (0 == ntohs (v4->sin_port)) - return buf; - strcat (buf, ":"); - GNUNET_snprintf (b2, sizeof (b2), "%u", ntohs (v4->sin_port)); - strcat (buf, b2); - return buf; - case AF_INET6: - if (addrlen != sizeof (struct sockaddr_in6)) - return ""; - v6 = (const struct sockaddr_in6 *) addr; - buf[0] = '['; - inet_ntop (AF_INET6, &v6->sin6_addr, &buf[1], INET6_ADDRSTRLEN); - if (0 == ntohs (v6->sin6_port)) - return &buf[1]; - strcat (buf, "]:"); - GNUNET_snprintf (b2, sizeof (b2), "%u", ntohs (v6->sin6_port)); - strcat (buf, b2); - return buf; - case AF_UNIX: - if (addrlen <= sizeof (sa_family_t)) - return ""; - un = (const struct sockaddr_un *) addr; - off = 0; - if (un->sun_path[0] == '\0') - off++; - snprintf (buf, sizeof (buf), "%s%.*s", (off == 1) ? "@" : "", - (int) (addrlen - sizeof (sa_family_t) - 1 - off), - &un->sun_path[off]); + { + case AF_INET: + if (addrlen != sizeof (struct sockaddr_in)) + return ""; + v4 = (const struct sockaddr_in *) addr; + inet_ntop (AF_INET, &v4->sin_addr, buf, INET_ADDRSTRLEN); + if (0 == ntohs (v4->sin_port)) return buf; - default: - return _("invalid address"); - } + strcat (buf, ":"); + GNUNET_snprintf (b2, sizeof (b2), "%u", ntohs (v4->sin_port)); + strcat (buf, b2); + return buf; + case AF_INET6: + if (addrlen != sizeof (struct sockaddr_in6)) + return ""; + v6 = (const struct sockaddr_in6 *) addr; + buf[0] = '['; + inet_ntop (AF_INET6, &v6->sin6_addr, &buf[1], INET6_ADDRSTRLEN); + if (0 == ntohs (v6->sin6_port)) + return &buf[1]; + strcat (buf, "]:"); + GNUNET_snprintf (b2, sizeof (b2), "%u", ntohs (v6->sin6_port)); + strcat (buf, b2); + return buf; + case AF_UNIX: + if (addrlen <= sizeof (sa_family_t)) + return ""; + un = (const struct sockaddr_un *) addr; + off = 0; + if (un->sun_path[0] == '\0') + off++; + snprintf (buf, sizeof (buf), "%s%.*s", (off == 1) ? "@" : "", + (int) (addrlen - sizeof (sa_family_t) - 1 - off), + &un->sun_path[off]); + return buf; + default: + return _("invalid address"); + } } diff --git a/src/util/configuration.c b/src/util/configuration.c index 9a131fb50..41a4e1975 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c @@ -150,7 +150,7 @@ GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg) */ int GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, - const char *filename) + const char *filename) { int dirty; char line[256]; @@ -167,89 +167,87 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, fn = GNUNET_STRINGS_filename_expand (filename); if (fn == NULL) return GNUNET_SYSERR; - dirty = cfg->dirty; /* back up value! */ + dirty = cfg->dirty; /* back up value! */ if (NULL == (fp = FOPEN (fn, "r"))) - { - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fopen", fn); - GNUNET_free (fn); - return GNUNET_SYSERR; - } + { + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fopen", fn); + GNUNET_free (fn); + return GNUNET_SYSERR; + } GNUNET_free (fn); ret = GNUNET_OK; section = GNUNET_strdup (""); memset (line, 0, 256); nr = 0; while (NULL != fgets (line, 255, fp)) + { + nr++; + for (i = 0; i < 255; i++) + if (line[i] == '\t') + line[i] = ' '; + if (line[0] == '\n' || line[0] == '#' || line[0] == '%' || line[0] == '\r') + continue; + emptyline = 1; + for (i = 0; (i < 255 && line[i] != 0); i++) + if (line[i] != ' ' && line[i] != '\n' && line[i] != '\r') + emptyline = 0; + if (emptyline == 1) + continue; + /* remove tailing whitespace */ + for (i = strlen (line) - 1; (i >= 0) && (isspace ((unsigned char) line[i])); + i--) + line[i] = '\0'; + if (1 == sscanf (line, "@INLINE@ %191[^\n]", value)) { - nr++; - for (i = 0; i < 255; i++) - if (line[i] == '\t') - line[i] = ' '; - if (line[0] == '\n' || line[0] == '#' || line[0] == '%' - || line[0] == '\r') - continue; - emptyline = 1; - for (i = 0; (i < 255 && line[i] != 0); i++) - if (line[i] != ' ' && line[i] != '\n' && line[i] != '\r') - emptyline = 0; - if (emptyline == 1) - continue; - /* remove tailing whitespace */ - for (i = strlen (line) - 1; - (i >= 0) && (isspace ((unsigned char) line[i])); i--) - line[i] = '\0'; - if (1 == sscanf (line, "@INLINE@ %191[^\n]", value)) - { - /* @INLINE@ value */ - if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, value)) - ret = GNUNET_SYSERR; /* failed to parse included config */ - } - else if (1 == sscanf (line, "[%99[^]]]", value)) - { - /* [value] */ - GNUNET_free (section); - section = GNUNET_strdup (value); - } - else if (2 == sscanf (line, " %63[^= ] = %191[^\n]", tag, value)) - { - /* tag = value */ - /* Strip LF */ - i = strlen (value) - 1; - while ((i >= 0) && (isspace ((unsigned char) value[i]))) - value[i--] = '\0'; - /* remove quotes */ - i = 0; - if (value[0] == '"') - { - i = 1; - while ((value[i] != '\0') && (value[i] != '"')) - i++; - if (value[i] == '"') - { - value[i] = '\0'; - i = 1; - } - else - i = 0; - } - GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, - &value[i]); - } - else if (1 == sscanf (line, " %63[^= ] =[^\n]", tag)) - { - /* tag = */ - GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, ""); - } - else - { - /* parse error */ - LOG (GNUNET_ERROR_TYPE_WARNING, - _("Syntax error in configuration file `%s' at line %u.\n"), - filename, nr); - ret = GNUNET_SYSERR; - break; - } + /* @INLINE@ value */ + if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, value)) + ret = GNUNET_SYSERR; /* failed to parse included config */ + } + else if (1 == sscanf (line, "[%99[^]]]", value)) + { + /* [value] */ + GNUNET_free (section); + section = GNUNET_strdup (value); + } + else if (2 == sscanf (line, " %63[^= ] = %191[^\n]", tag, value)) + { + /* tag = value */ + /* Strip LF */ + i = strlen (value) - 1; + while ((i >= 0) && (isspace ((unsigned char) value[i]))) + value[i--] = '\0'; + /* remove quotes */ + i = 0; + if (value[0] == '"') + { + i = 1; + while ((value[i] != '\0') && (value[i] != '"')) + i++; + if (value[i] == '"') + { + value[i] = '\0'; + i = 1; + } + else + i = 0; + } + GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, &value[i]); + } + else if (1 == sscanf (line, " %63[^= ] =[^\n]", tag)) + { + /* tag = */ + GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, ""); + } + else + { + /* parse error */ + LOG (GNUNET_ERROR_TYPE_WARNING, + _("Syntax error in configuration file `%s' at line %u.\n"), filename, + nr); + ret = GNUNET_SYSERR; + break; } + } GNUNET_assert (0 == fclose (fp)); /* restore dirty flag - anything we set in the meantime * came from disk */ @@ -282,7 +280,7 @@ GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg) */ int GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, - const char *filename) + const char *filename) { struct ConfigSection *sec; struct ConfigEntry *ent; @@ -296,67 +294,67 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, if (fn == NULL) return GNUNET_SYSERR; if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)) - { - GNUNET_free (fn); - return GNUNET_SYSERR; - } + { + GNUNET_free (fn); + return GNUNET_SYSERR; + } if (NULL == (fp = FOPEN (fn, "w"))) - { - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fopen", fn); - GNUNET_free (fn); - return GNUNET_SYSERR; - } + { + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fopen", fn); + GNUNET_free (fn); + return GNUNET_SYSERR; + } GNUNET_free (fn); error = 0; sec = cfg->sections; while (sec != NULL) + { + if (0 > fprintf (fp, "[%s]\n", sec->name)) { - if (0 > fprintf (fp, "[%s]\n", sec->name)) - { - error = 1; - break; - } - ent = sec->entries; - while (ent != NULL) - { - if (ent->val != NULL) - { - val = GNUNET_malloc (strlen (ent->val) * 2 + 1); - strcpy (val, ent->val); - while (NULL != (pos = strstr (val, "\n"))) - { - memmove (&pos[2], &pos[1], strlen (&pos[1])); - pos[0] = '\\'; - pos[1] = 'n'; - } - if (0 > fprintf (fp, "%s = %s\n", ent->key, val)) - { - error = 1; - GNUNET_free (val); - break; - } - GNUNET_free (val); - } - ent = ent->next; - } - if (error != 0) - break; - if (0 > fprintf (fp, "\n")) - { - error = 1; - break; - } - sec = sec->next; + error = 1; + break; } + ent = sec->entries; + while (ent != NULL) + { + if (ent->val != NULL) + { + val = GNUNET_malloc (strlen (ent->val) * 2 + 1); + strcpy (val, ent->val); + while (NULL != (pos = strstr (val, "\n"))) + { + memmove (&pos[2], &pos[1], strlen (&pos[1])); + pos[0] = '\\'; + pos[1] = 'n'; + } + if (0 > fprintf (fp, "%s = %s\n", ent->key, val)) + { + error = 1; + GNUNET_free (val); + break; + } + GNUNET_free (val); + } + ent = ent->next; + } + if (error != 0) + break; + if (0 > fprintf (fp, "\n")) + { + error = 1; + break; + } + sec = sec->next; + } if (error != 0) LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fprintf", filename); GNUNET_assert (0 == fclose (fp)); if (error != 0) - { - cfg->dirty = GNUNET_SYSERR; /* last write failed */ - return GNUNET_SYSERR; - } - cfg->dirty = GNUNET_NO; /* last write succeeded */ + { + cfg->dirty = GNUNET_SYSERR; /* last write failed */ + return GNUNET_SYSERR; + } + cfg->dirty = GNUNET_NO; /* last write succeeded */ return GNUNET_OK; } @@ -370,23 +368,23 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, */ void GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, - GNUNET_CONFIGURATION_Iterator iter, - void *iter_cls) + GNUNET_CONFIGURATION_Iterator iter, + void *iter_cls) { struct ConfigSection *spos; struct ConfigEntry *epos; spos = cfg->sections; while (spos != NULL) + { + epos = spos->entries; + while (epos != NULL) { - epos = spos->entries; - while (epos != NULL) - { - iter (iter_cls, spos->name, epos->key, epos->val); - epos = epos->next; - } - spos = spos->next; + iter (iter_cls, spos->name, epos->key, epos->val); + epos = epos->next; } + spos = spos->next; + } } @@ -400,10 +398,10 @@ GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, */ void GNUNET_CONFIGURATION_iterate_section_values (const struct - GNUNET_CONFIGURATION_Handle *cfg, - const char *section, - GNUNET_CONFIGURATION_Iterator - iter, void *iter_cls) + GNUNET_CONFIGURATION_Handle *cfg, + const char *section, + GNUNET_CONFIGURATION_Iterator iter, + void *iter_cls) { struct ConfigSection *spos; struct ConfigEntry *epos; @@ -417,10 +415,10 @@ GNUNET_CONFIGURATION_iterate_section_values (const struct epos = spos->entries; while (epos != NULL) - { - iter (iter_cls, spos->name, epos->key, epos->val); - epos = epos->next; - } + { + iter (iter_cls, spos->name, epos->key, epos->val); + epos = epos->next; + } } @@ -432,21 +430,21 @@ GNUNET_CONFIGURATION_iterate_section_values (const struct * @param iter_cls closure for iter */ void -GNUNET_CONFIGURATION_iterate_sections (const struct - GNUNET_CONFIGURATION_Handle *cfg, - GNUNET_CONFIGURATION_Section_Iterator - iter, void *iter_cls) +GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle + *cfg, + GNUNET_CONFIGURATION_Section_Iterator + iter, void *iter_cls) { struct ConfigSection *spos; struct ConfigSection *next; next = cfg->sections; while (next != NULL) - { - spos = next; - next = spos->next; - iter (iter_cls, spos->name); - } + { + spos = next; + next = spos->next; + iter (iter_cls, spos->name); + } } /** @@ -457,7 +455,7 @@ GNUNET_CONFIGURATION_iterate_sections (const struct */ void GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, - const char *section) + const char *section) { struct ConfigSection *spos; struct ConfigSection *prev; @@ -466,28 +464,28 @@ GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, prev = NULL; spos = cfg->sections; while (spos != NULL) + { + if (0 == strcmp (section, spos->name)) { - if (0 == strcmp (section, spos->name)) - { - if (prev == NULL) - cfg->sections = spos->next; - else - prev->next = spos->next; - while (NULL != (ent = spos->entries)) - { - spos->entries = ent->next; - GNUNET_free (ent->key); - GNUNET_free_non_null (ent->val); - GNUNET_free (ent); - cfg->dirty = GNUNET_YES; - } - GNUNET_free (spos->name); - GNUNET_free (spos); - return; - } - prev = spos; - spos = spos->next; + if (prev == NULL) + cfg->sections = spos->next; + else + prev->next = spos->next; + while (NULL != (ent = spos->entries)) + { + spos->entries = ent->next; + GNUNET_free (ent->key); + GNUNET_free_non_null (ent->val); + GNUNET_free (ent); + cfg->dirty = GNUNET_YES; + } + GNUNET_free (spos->name); + GNUNET_free (spos); + return; } + prev = spos; + spos = spos->next; + } } @@ -502,7 +500,7 @@ GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, */ static void copy_entry (void *cls, const char *section, const char *option, - const char *value) + const char *value) { struct GNUNET_CONFIGURATION_Handle *dst = cls; @@ -535,8 +533,7 @@ GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg) * @return matching entry, NULL if not found */ static struct ConfigSection * -findSection (const struct GNUNET_CONFIGURATION_Handle *cfg, - const char *section) +findSection (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section) { struct ConfigSection *pos; @@ -557,7 +554,7 @@ findSection (const struct GNUNET_CONFIGURATION_Handle *cfg, */ static struct ConfigEntry * findEntry (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, - const char *key) + const char *key) { struct ConfigSection *sec; struct ConfigEntry *pos; @@ -584,7 +581,7 @@ findEntry (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, */ static void compareEntries (void *cls, const char *section, const char *option, - const char *value) + const char *value) { struct DiffHandle *dh = cls; struct ConfigEntry *entNew; @@ -605,9 +602,9 @@ compareEntries (void *cls, const char *section, const char *option, */ int GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle - *cfgDefault, - const struct GNUNET_CONFIGURATION_Handle - *cfgNew, const char *filename) + *cfgDefault, + const struct GNUNET_CONFIGURATION_Handle + *cfgNew, const char *filename) { int ret; struct DiffHandle diffHandle; @@ -630,28 +627,28 @@ GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle * @param value value to set */ void -GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle - *cfg, const char *section, - const char *option, const char *value) +GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg, + const char *section, const char *option, + const char *value) { struct ConfigSection *sec; struct ConfigEntry *e; e = findEntry (cfg, section, option); if (e != NULL) - { - GNUNET_free_non_null (e->val); - e->val = GNUNET_strdup (value); - return; - } + { + GNUNET_free_non_null (e->val); + e->val = GNUNET_strdup (value); + return; + } sec = findSection (cfg, section); if (sec == NULL) - { - sec = GNUNET_malloc (sizeof (struct ConfigSection)); - sec->name = GNUNET_strdup (section); - sec->next = cfg->sections; - cfg->sections = sec; - } + { + sec = GNUNET_malloc (sizeof (struct ConfigSection)); + sec->name = GNUNET_strdup (section); + sec->next = cfg->sections; + cfg->sections = sec; + } e = GNUNET_malloc (sizeof (struct ConfigEntry)); e->key = GNUNET_strdup (option); e->val = GNUNET_strdup (value); @@ -669,10 +666,9 @@ GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle * @param number value to set */ void -GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle - *cfg, const char *section, - const char *option, - unsigned long long number) +GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg, + const char *section, const char *option, + unsigned long long number) { char s[64]; @@ -691,11 +687,10 @@ GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle * @return GNUNET_OK on success, GNUNET_SYSERR on error */ int -GNUNET_CONFIGURATION_get_value_number (const struct - GNUNET_CONFIGURATION_Handle *cfg, - const char *section, - const char *option, - unsigned long long *number) +GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle + *cfg, const char *section, + const char *option, + unsigned long long *number) { struct ConfigEntry *e; @@ -719,9 +714,9 @@ GNUNET_CONFIGURATION_get_value_number (const struct */ int GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle - *cfg, const char *section, - const char *option, - struct GNUNET_TIME_Relative *time) + *cfg, const char *section, + const char *option, + struct GNUNET_TIME_Relative *time) { struct ConfigEntry *e; @@ -729,8 +724,7 @@ GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle if (e == NULL) return GNUNET_SYSERR; - return GNUNET_STRINGS_fancy_time_to_relative (e->val, - time); + return GNUNET_STRINGS_fancy_time_to_relative (e->val, time); } @@ -754,8 +748,7 @@ GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle e = findEntry (cfg, section, option); if (e == NULL) return GNUNET_SYSERR; - return GNUNET_STRINGS_fancy_size_to_bytes (e->val, - size); + return GNUNET_STRINGS_fancy_size_to_bytes (e->val, size); } @@ -770,19 +763,18 @@ GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle * @return GNUNET_OK on success, GNUNET_SYSERR on error */ int -GNUNET_CONFIGURATION_get_value_string (const struct - GNUNET_CONFIGURATION_Handle *cfg, - const char *section, - const char *option, char **value) +GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle + *cfg, const char *section, + const char *option, char **value) { struct ConfigEntry *e; e = findEntry (cfg, section, option); if ((e == NULL) || (e->val == NULL)) - { - *value = NULL; - return GNUNET_SYSERR; - } + { + *value = NULL; + return GNUNET_SYSERR; + } *value = GNUNET_strdup (e->val); return GNUNET_OK; } @@ -801,12 +793,10 @@ GNUNET_CONFIGURATION_get_value_string (const struct * @return GNUNET_OK on success, GNUNET_SYSERR on error */ int -GNUNET_CONFIGURATION_get_value_choice (const struct - GNUNET_CONFIGURATION_Handle *cfg, - const char *section, - const char *option, - const char **choices, - const char **value) +GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle + *cfg, const char *section, + const char *option, const char **choices, + const char **value) { struct ConfigEntry *e; int i; @@ -816,19 +806,19 @@ GNUNET_CONFIGURATION_get_value_choice (const struct return GNUNET_SYSERR; i = 0; while (choices[i] != NULL) - { - if (0 == strcasecmp (choices[i], e->val)) - break; - i++; - } + { + if (0 == strcasecmp (choices[i], e->val)) + break; + i++; + } if (choices[i] == NULL) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Configuration value '%s' for '%s'" - " in section '%s' is not in set of legal choices\n"), e->val, - option, section); - return GNUNET_SYSERR; - } + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Configuration value '%s' for '%s'" + " in section '%s' is not in set of legal choices\n"), e->val, option, + section); + return GNUNET_SYSERR; + } *value = choices[i]; return GNUNET_OK; } @@ -842,9 +832,8 @@ GNUNET_CONFIGURATION_get_value_choice (const struct * @return GNUNET_YES if so, GNUNET_NO if not. */ int -GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle - *cfg, const char *section, - const char *option) +GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *section, const char *option) { struct ConfigEntry *e; @@ -865,7 +854,7 @@ GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle */ char * GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle - *cfg, char *orig) + *cfg, char *orig) { int i; char *prefix; @@ -879,25 +868,24 @@ GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle while ((orig[i] != '/') && (orig[i] != '\\') && (orig[i] != '\0')) i++; if (orig[i] == '\0') - { - post = ""; - } + { + post = ""; + } else - { - orig[i] = '\0'; - post = &orig[i + 1]; - } + { + orig[i] = '\0'; + post = &orig[i + 1]; + } if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (cfg, "PATHS", &orig[1], - &prefix)) + GNUNET_CONFIGURATION_get_value_filename (cfg, "PATHS", &orig[1], &prefix)) + { + if (NULL == (env = getenv (&orig[1]))) { - if (NULL == (env = getenv (&orig[1]))) - { - orig[i] = DIR_SEPARATOR; - return orig; - } - prefix = GNUNET_strdup (env); + orig[i] = DIR_SEPARATOR; + return orig; } + prefix = GNUNET_strdup (env); + } result = GNUNET_malloc (strlen (prefix) + strlen (post) + 2); strcpy (result, prefix); if ((strlen (prefix) == 0) || @@ -922,18 +910,18 @@ GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle */ int GNUNET_CONFIGURATION_get_value_filename (const struct - GNUNET_CONFIGURATION_Handle *cfg, - const char *section, - const char *option, char **value) + GNUNET_CONFIGURATION_Handle *cfg, + const char *section, + const char *option, char **value) { char *tmp; if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &tmp)) - { - *value = NULL; - return GNUNET_SYSERR; - } + { + *value = NULL; + return GNUNET_SYSERR; + } tmp = GNUNET_CONFIGURATION_expand_dollar (cfg, tmp); *value = GNUNET_STRINGS_filename_expand (tmp); GNUNET_free (tmp); @@ -954,15 +942,15 @@ GNUNET_CONFIGURATION_get_value_filename (const struct */ int GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle - *cfg, const char *section, - const char *option) + *cfg, const char *section, + const char *option) { static const char *yesno[] = { "YES", "NO", NULL }; const char *val; int ret; ret = - GNUNET_CONFIGURATION_get_value_choice (cfg, section, option, yesno, &val); + GNUNET_CONFIGURATION_get_value_choice (cfg, section, option, yesno, &val); if (ret == GNUNET_SYSERR) return ret; if (val == yesno[0]) @@ -983,11 +971,11 @@ GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle */ int GNUNET_CONFIGURATION_iterate_value_filenames (const struct - GNUNET_CONFIGURATION_Handle - *cfg, const char *section, - const char *option, - GNUNET_FileNameCallback cb, - void *cb_cls) + GNUNET_CONFIGURATION_Handle *cfg, + const char *section, + const char *option, + GNUNET_FileNameCallback cb, + void *cb_cls) { char *list; char *pos; @@ -1002,46 +990,46 @@ GNUNET_CONFIGURATION_iterate_value_filenames (const struct ret = 0; pos = list; while (1) + { + while (pos[0] == ' ') + pos++; + if (strlen (pos) == 0) + break; + end = pos + 1; + while ((end[0] != ' ') && (end[0] != '\0')) { - while (pos[0] == ' ') - pos++; - if (strlen (pos) == 0) - break; - end = pos + 1; - while ((end[0] != ' ') && (end[0] != '\0')) - { - if (end[0] == '\\') - { - switch (end[1]) - { - case '\\': - case ' ': - memmove (end, &end[1], strlen (&end[1]) + 1); - case '\0': - /* illegal, but just keep it */ - break; - default: - /* illegal, but just ignore that there was a '/' */ - break; - } - } - end++; - } - old = end[0]; - end[0] = '\0'; - if (strlen (pos) > 0) - { - ret++; - if ((cb != NULL) && (GNUNET_OK != cb (cb_cls, pos))) - { - ret = GNUNET_SYSERR; - break; - } - } - if (old == '\0') - break; - pos = end + 1; + if (end[0] == '\\') + { + switch (end[1]) + { + case '\\': + case ' ': + memmove (end, &end[1], strlen (&end[1]) + 1); + case '\0': + /* illegal, but just keep it */ + break; + default: + /* illegal, but just ignore that there was a '/' */ + break; + } + } + end++; } + old = end[0]; + end[0] = '\0'; + if (strlen (pos) > 0) + { + ret++; + if ((cb != NULL) && (GNUNET_OK != cb (cb_cls, pos))) + { + ret = GNUNET_SYSERR; + break; + } + } + if (old == '\0') + break; + pos = end + 1; + } GNUNET_free (list); return ret; } @@ -1065,21 +1053,21 @@ escape_name (const char *value) rpos = value; wpos = escaped; while (rpos[0] != '\0') + { + switch (rpos[0]) { - switch (rpos[0]) - { - case '\\': - case ' ': - wpos[0] = '\\'; - wpos[1] = rpos[0]; - wpos += 2; - break; - default: - wpos[0] = rpos[0]; - wpos++; - } - rpos++; + case '\\': + case ' ': + wpos[0] = '\\'; + wpos[1] = rpos[0]; + wpos += 2; + break; + default: + wpos[0] = rpos[0]; + wpos++; } + rpos++; + } return escaped; } @@ -1114,9 +1102,9 @@ test_match (void *cls, const char *fn) */ int GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle - *cfg, const char *section, - const char *option, - const char *value) + *cfg, const char *section, + const char *option, + const char *value) { char *escaped; char *old; @@ -1124,9 +1112,9 @@ GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle if (GNUNET_SYSERR == GNUNET_CONFIGURATION_iterate_value_filenames (cfg, section, option, - &test_match, - (void *) value)) - return GNUNET_NO; /* already exists */ + &test_match, + (void *) value)) + return GNUNET_NO; /* already exists */ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old)) old = GNUNET_strdup (""); @@ -1158,9 +1146,9 @@ GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle */ int GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle - *cfg, const char *section, - const char *option, - const char *value) + *cfg, const char *section, + const char *option, + const char *value) { char *list; char *pos; @@ -1174,55 +1162,55 @@ GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle match = escape_name (value); pos = list; while (1) + { + while (pos[0] == ' ') + pos++; + if (strlen (pos) == 0) + break; + end = pos + 1; + while ((end[0] != ' ') && (end[0] != '\0')) + { + if (end[0] == '\\') + { + switch (end[1]) + { + case '\\': + case ' ': + end++; + break; + case '\0': + /* illegal, but just keep it */ + break; + default: + /* illegal, but just ignore that there was a '/' */ + break; + } + } + end++; + } + old = end[0]; + end[0] = '\0'; + if (0 == strcmp (pos, match)) { - while (pos[0] == ' ') - pos++; - if (strlen (pos) == 0) - break; - end = pos + 1; - while ((end[0] != ' ') && (end[0] != '\0')) - { - if (end[0] == '\\') - { - switch (end[1]) - { - case '\\': - case ' ': - end++; - break; - case '\0': - /* illegal, but just keep it */ - break; - default: - /* illegal, but just ignore that there was a '/' */ - break; - } - } - end++; - } - old = end[0]; - end[0] = '\0'; - if (0 == strcmp (pos, match)) - { - if (old != '\0') - memmove (pos, &end[1], strlen (&end[1]) + 1); - else - { - if (pos != list) - pos[-1] = '\0'; - else - pos[0] = '\0'; - } - GNUNET_CONFIGURATION_set_value_string (cfg, section, option, list); - GNUNET_free (list); - GNUNET_free (match); - return GNUNET_OK; - } - if (old == '\0') - break; - end[0] = old; - pos = end + 1; + if (old != '\0') + memmove (pos, &end[1], strlen (&end[1]) + 1); + else + { + if (pos != list) + pos[-1] = '\0'; + else + pos[0] = '\0'; + } + GNUNET_CONFIGURATION_set_value_string (cfg, section, option, list); + GNUNET_free (list); + GNUNET_free (match); + return GNUNET_OK; } + if (old == '\0') + break; + end[0] = old; + pos = end + 1; + } GNUNET_free (list); GNUNET_free (match); return GNUNET_NO; @@ -1237,8 +1225,7 @@ GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle * @return GNUNET_OK on success */ static int -parse_configuration_file (void *cls, - const char *filename) +parse_configuration_file (void *cls, const char *filename) { struct GNUNET_CONFIGURATION_Handle *cfg = cls; int ret; @@ -1258,7 +1245,7 @@ parse_configuration_file (void *cls, */ int GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, - const char *filename) + const char *filename) { char *baseconfig; char *ipath; @@ -1267,29 +1254,26 @@ GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, if (ipath == NULL) return GNUNET_SYSERR; baseconfig = NULL; - GNUNET_asprintf (&baseconfig, "%s%s", ipath, - "config.d"); + GNUNET_asprintf (&baseconfig, "%s%s", ipath, "config.d"); GNUNET_free (ipath); if (GNUNET_SYSERR == - GNUNET_DISK_directory_scan (baseconfig, - &parse_configuration_file, - cfg)) + GNUNET_DISK_directory_scan (baseconfig, &parse_configuration_file, cfg)) { GNUNET_free (baseconfig); - return GNUNET_SYSERR; /* no configuration at all found */ + return GNUNET_SYSERR; /* no configuration at all found */ } - GNUNET_free (baseconfig); - if ( (filename != NULL) && - (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, filename)) ) + GNUNET_free (baseconfig); + if ((filename != NULL) && + (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, filename))) { /* specified configuration not found */ return GNUNET_SYSERR; } if (((GNUNET_YES != - GNUNET_CONFIGURATION_have_value (cfg, "PATHS", "DEFAULTCONFIG"))) && + GNUNET_CONFIGURATION_have_value (cfg, "PATHS", "DEFAULTCONFIG"))) && (filename != NULL)) GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG", - filename); + filename); if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (cfg, "TESTING", "WEAKRANDOM")) && (GNUNET_YES == diff --git a/src/util/connection.c b/src/util/connection.c index cd0035a8f..61c26673b 100644 --- a/src/util/connection.c +++ b/src/util/connection.c @@ -333,8 +333,7 @@ GNUNET_CONNECTION_disable_corking (struct GNUNET_CONNECTION_Handle *sock) * @return the boxed socket handle */ struct GNUNET_CONNECTION_Handle * -GNUNET_CONNECTION_create_from_existing (struct GNUNET_NETWORK_Handle - *osSocket) +GNUNET_CONNECTION_create_from_existing (struct GNUNET_NETWORK_Handle *osSocket) { struct GNUNET_CONNECTION_Handle *ret; @@ -357,8 +356,8 @@ GNUNET_CONNECTION_create_from_existing (struct GNUNET_NETWORK_Handle */ struct GNUNET_CONNECTION_Handle * GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access, - void *access_cls, - struct GNUNET_NETWORK_Handle *lsock) + void *access_cls, + struct GNUNET_NETWORK_Handle *lsock) { struct GNUNET_CONNECTION_Handle *ret; char addr[128]; @@ -379,94 +378,94 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access, addrlen = sizeof (addr); sock = - GNUNET_NETWORK_socket_accept (lsock, (struct sockaddr *) &addr, &addrlen); + GNUNET_NETWORK_socket_accept (lsock, (struct sockaddr *) &addr, &addrlen); if (NULL == sock) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "accept"); - return NULL; - } + { + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "accept"); + return NULL; + } if ((addrlen > sizeof (addr)) || (addrlen < sizeof (sa_family_t))) - { - GNUNET_break (0); - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); - return NULL; - } + { + GNUNET_break (0); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); + return NULL; + } sa = (struct sockaddr *) addr; v6 = (struct sockaddr_in6 *) addr; if ((sa->sa_family == AF_INET6) && (IN6_IS_ADDR_V4MAPPED (&v6->sin6_addr))) - { - /* convert to V4 address */ - v4 = GNUNET_malloc (sizeof (struct sockaddr_in)); - memset (v4, 0, sizeof (struct sockaddr_in)); - v4->sin_family = AF_INET; + { + /* convert to V4 address */ + v4 = GNUNET_malloc (sizeof (struct sockaddr_in)); + memset (v4, 0, sizeof (struct sockaddr_in)); + v4->sin_family = AF_INET; #if HAVE_SOCKADDR_IN_SIN_LEN - v4->sin_len = (u_char) sizeof (struct sockaddr_in); + v4->sin_len = (u_char) sizeof (struct sockaddr_in); #endif - memcpy (&v4->sin_addr, - &((char *) &v6->sin6_addr)[sizeof (struct in6_addr) - - sizeof (struct in_addr)], - sizeof (struct in_addr)); - v4->sin_port = v6->sin6_port; - uaddr = v4; - addrlen = sizeof (struct sockaddr_in); - } + memcpy (&v4->sin_addr, + &((char *) &v6->sin6_addr)[sizeof (struct in6_addr) - + sizeof (struct in_addr)], + sizeof (struct in_addr)); + v4->sin_port = v6->sin6_port; + uaddr = v4; + addrlen = sizeof (struct sockaddr_in); + } else - { - uaddr = GNUNET_malloc (addrlen); - memcpy (uaddr, addr, addrlen); - } + { + uaddr = GNUNET_malloc (addrlen); + memcpy (uaddr, addr, addrlen); + } gcp = NULL; gc.uid = 0; gc.gid = 0; if (sa->sa_family == AF_UNIX) - { + { #if HAVE_GETPEEREID - /* most BSDs */ - if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock), &gc.uid, &gc.gid)) - gcp = &gc; + /* most BSDs */ + if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock), &gc.uid, &gc.gid)) + gcp = &gc; #else #ifdef SO_PEERCRED - /* largely traditional GNU/Linux */ - olen = sizeof (uc); - if ((0 == - getsockopt (GNUNET_NETWORK_get_fd (sock), SOL_SOCKET, SO_PEERCRED, - &uc, &olen)) && (olen == sizeof (uc))) - { - gc.uid = uc.uid; - gc.gid = uc.gid; - gcp = &gc; - } + /* largely traditional GNU/Linux */ + olen = sizeof (uc); + if ((0 == + getsockopt (GNUNET_NETWORK_get_fd (sock), SOL_SOCKET, SO_PEERCRED, &uc, + &olen)) && (olen == sizeof (uc))) + { + gc.uid = uc.uid; + gc.gid = uc.gid; + gcp = &gc; + } #else #if HAVE_GETPEERUCRED - /* this is for Solaris 10 */ - ucred_t *uc; - - uc = NULL; - if (0 == getpeerucred (GNUNET_NETWORK_get_fd (sock), &uc)) - { - gc.uid = ucred_geteuid (uc); - gc.gid = ucred_getegid (uc); - gcp = &gc; - } - ucred_free (uc); + /* this is for Solaris 10 */ + ucred_t *uc; + + uc = NULL; + if (0 == getpeerucred (GNUNET_NETWORK_get_fd (sock), &uc)) + { + gc.uid = ucred_geteuid (uc); + gc.gid = ucred_getegid (uc); + gcp = &gc; + } + ucred_free (uc); #endif #endif #endif - } + } if ((access != NULL) && (GNUNET_YES != (aret = access (access_cls, gcp, uaddr, addrlen)))) - { - if (aret == GNUNET_NO) - LOG (GNUNET_ERROR_TYPE_INFO, _("Access denied to `%s'\n"), - GNUNET_a2s (uaddr, addrlen)); - GNUNET_break (GNUNET_OK == - GNUNET_NETWORK_socket_shutdown (sock, SHUT_RDWR)); - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); - GNUNET_free (uaddr); - return NULL; - } + { + if (aret == GNUNET_NO) + LOG (GNUNET_ERROR_TYPE_INFO, _("Access denied to `%s'\n"), + GNUNET_a2s (uaddr, addrlen)); + GNUNET_break (GNUNET_OK == + GNUNET_NETWORK_socket_shutdown (sock, SHUT_RDWR)); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); + GNUNET_free (uaddr); + return NULL; + } ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle)); ret->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE; ret->write_buffer = GNUNET_malloc (ret->write_buffer_size); @@ -490,7 +489,7 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access, */ int GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *sock, - void **addr, size_t * addrlen) + void **addr, size_t * addrlen) { if ((sock->addr == NULL) || (sock->addrlen == 0)) return GNUNET_NO; @@ -523,8 +522,7 @@ receive_again (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); * @param tc unused */ static void -destroy_continuation (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +destroy_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_CONNECTION_Handle *sock = cls; GNUNET_CONNECTION_TransmitReadyNotify notify; @@ -533,78 +531,77 @@ destroy_continuation (void *cls, sock->destroy_task = GNUNET_SCHEDULER_NO_TASK; GNUNET_assert (sock->dns_active == NULL); if (0 != (sock->ccs & COCO_TRANSMIT_READY)) - { + { #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Destroy waits for CCS-TR to be done (%p)\n", sock); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroy waits for CCS-TR to be done (%p)\n", + sock); #endif - sock->ccs |= COCO_DESTROY_CONTINUATION; - return; - } + sock->ccs |= COCO_DESTROY_CONTINUATION; + return; + } if (sock->write_task != GNUNET_SCHEDULER_NO_TASK) - { + { #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Destroy waits for write_task to be done (%p)\n", sock); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Destroy waits for write_task to be done (%p)\n", sock); #endif - GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); - sock->destroy_task = - GNUNET_SCHEDULER_add_after (sock->write_task, &destroy_continuation, - sock); - return; - } + GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); + sock->destroy_task = + GNUNET_SCHEDULER_add_after (sock->write_task, &destroy_continuation, + sock); + return; + } if (0 != (sock->ccs & COCO_RECEIVE_AGAIN)) - { - sock->ccs |= COCO_DESTROY_CONTINUATION; - return; - } + { + sock->ccs |= COCO_DESTROY_CONTINUATION; + return; + } if (sock->sock != NULL) - { + { #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down socket (%p)\n", sock); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down socket (%p)\n", sock); #endif - if (sock->persist != GNUNET_YES) - { - if ((GNUNET_YES != - GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR)) - && (errno != ENOTCONN) && (errno != ECONNRESET)) - LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "shutdown"); - } - } - if (sock->read_task != GNUNET_SCHEDULER_NO_TASK) + if (sock->persist != GNUNET_YES) { - GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); - sock->destroy_task = - GNUNET_SCHEDULER_add_after (sock->read_task, &destroy_continuation, - sock); - return; + if ((GNUNET_YES != GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR)) + && (errno != ENOTCONN) && (errno != ECONNRESET)) + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "shutdown"); } + } + if (sock->read_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); + sock->destroy_task = + GNUNET_SCHEDULER_add_after (sock->read_task, &destroy_continuation, + sock); + return; + } #if DEBUG_CONNECTION LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroy actually runs (%p)!\n", sock); #endif while (NULL != (pos = sock->ap_head)) - { - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); - GNUNET_SCHEDULER_cancel (pos->task); - GNUNET_CONTAINER_DLL_remove (sock->ap_head, sock->ap_tail, pos); - GNUNET_free (pos); - } + { + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); + GNUNET_SCHEDULER_cancel (pos->task); + GNUNET_CONTAINER_DLL_remove (sock->ap_head, sock->ap_tail, pos); + GNUNET_free (pos); + } GNUNET_assert (sock->nth.timeout_task == GNUNET_SCHEDULER_NO_TASK); GNUNET_assert (sock->ccs == COCO_NONE); if (NULL != (notify = sock->nth.notify_ready)) - { - sock->nth.notify_ready = NULL; - notify (sock->nth.notify_ready_cls, 0, NULL); - } + { + sock->nth.notify_ready = NULL; + notify (sock->nth.notify_ready_cls, 0, NULL); + } if (sock->sock != NULL) - { - if (sock->persist != GNUNET_YES) - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock)); - else - GNUNET_free (sock->sock); /* at least no memory leak (we deliberately - * leak the socket in this special case) ... */ - } + { + if (sock->persist != GNUNET_YES) + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock)); + else + GNUNET_free (sock->sock); /* at least no memory leak (we deliberately + * leak the socket in this special case) ... */ + } GNUNET_free_non_null (sock->addr); GNUNET_free_non_null (sock->hostname); GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); @@ -639,9 +636,8 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *h) { #if DEBUG_CONNECTION LOG ((0 != - strncmp (h->hostname, "localhost:", - 10)) ? GNUNET_ERROR_TYPE_INFO : - GNUNET_ERROR_TYPE_WARNING, + strncmp (h->hostname, "localhost:", + 10)) ? GNUNET_ERROR_TYPE_INFO : GNUNET_ERROR_TYPE_WARNING, _ ("Failed to establish TCP connection to `%s:%u', no further addresses to try.\n"), h->hostname, h->port); @@ -654,39 +650,39 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *h) /* trigger jobs that used to wait on "connect_task" */ if (0 != (h->ccs & COCO_RECEIVE_AGAIN)) - { + { #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "connect_fail_continuation triggers receive_again (%p)\n", h); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "connect_fail_continuation triggers receive_again (%p)\n", h); #endif - h->ccs -= COCO_RECEIVE_AGAIN; - h->read_task = GNUNET_SCHEDULER_add_now (&receive_again, h); - } + h->ccs -= COCO_RECEIVE_AGAIN; + h->read_task = GNUNET_SCHEDULER_add_now (&receive_again, h); + } if (0 != (h->ccs & COCO_TRANSMIT_READY)) - { + { #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "connect_fail_continuation cancels timeout_task, triggers transmit_ready (%p)\n", - h); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "connect_fail_continuation cancels timeout_task, triggers transmit_ready (%p)\n", + h); #endif - GNUNET_assert (h->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK); - GNUNET_SCHEDULER_cancel (h->nth.timeout_task); - h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; - h->ccs -= COCO_TRANSMIT_READY; - GNUNET_assert (h->nth.notify_ready != NULL); - GNUNET_assert (h->write_task == GNUNET_SCHEDULER_NO_TASK); - h->write_task = GNUNET_SCHEDULER_add_now (&transmit_ready, h); - } + GNUNET_assert (h->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK); + GNUNET_SCHEDULER_cancel (h->nth.timeout_task); + h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; + h->ccs -= COCO_TRANSMIT_READY; + GNUNET_assert (h->nth.notify_ready != NULL); + GNUNET_assert (h->write_task == GNUNET_SCHEDULER_NO_TASK); + h->write_task = GNUNET_SCHEDULER_add_now (&transmit_ready, h); + } if (0 != (h->ccs & COCO_DESTROY_CONTINUATION)) - { + { #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "connect_fail_continuation runs destroy_continuation (%p)\n", h); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "connect_fail_continuation runs destroy_continuation (%p)\n", h); #endif - h->ccs -= COCO_DESTROY_CONTINUATION; - GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->destroy_task); - h->destroy_task = GNUNET_SCHEDULER_add_now (&destroy_continuation, h); - } + h->ccs -= COCO_DESTROY_CONTINUATION; + GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->destroy_task); + h->destroy_task = GNUNET_SCHEDULER_add_now (&destroy_continuation, h); + } } @@ -704,43 +700,42 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *h) #endif /* trigger jobs that waited for the connection */ if (0 != (h->ccs & COCO_RECEIVE_AGAIN)) - { + { #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "connect_success_continuation runs receive_again (%p)\n", h); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "connect_success_continuation runs receive_again (%p)\n", h); #endif - h->ccs -= COCO_RECEIVE_AGAIN; - h->read_task = GNUNET_SCHEDULER_add_now (&receive_again, h); - } + h->ccs -= COCO_RECEIVE_AGAIN; + h->read_task = GNUNET_SCHEDULER_add_now (&receive_again, h); + } if (0 != (h->ccs & COCO_TRANSMIT_READY)) - { + { #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "connect_success_continuation runs transmit_ready, cancels timeout_task (%p)\n", - h); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "connect_success_continuation runs transmit_ready, cancels timeout_task (%p)\n", + h); #endif - GNUNET_assert (h->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK); - GNUNET_SCHEDULER_cancel (h->nth.timeout_task); - h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; - h->ccs -= COCO_TRANSMIT_READY; - GNUNET_assert (h->write_task == GNUNET_SCHEDULER_NO_TASK); - GNUNET_assert (h->nth.notify_ready != NULL); - h->write_task = - GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining - (h->nth.transmit_timeout), h->sock, - &transmit_ready, h); - } + GNUNET_assert (h->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK); + GNUNET_SCHEDULER_cancel (h->nth.timeout_task); + h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; + h->ccs -= COCO_TRANSMIT_READY; + GNUNET_assert (h->write_task == GNUNET_SCHEDULER_NO_TASK); + GNUNET_assert (h->nth.notify_ready != NULL); + h->write_task = + GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining + (h->nth.transmit_timeout), h->sock, + &transmit_ready, h); + } if (0 != (h->ccs & COCO_DESTROY_CONTINUATION)) - { + { #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "connect_success_continuation runs destroy_continuation (%p)\n", - h); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "connect_success_continuation runs destroy_continuation (%p)\n", h); #endif - h->ccs -= COCO_DESTROY_CONTINUATION; - GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->destroy_task); - h->destroy_task = GNUNET_SCHEDULER_add_now (&destroy_continuation, h); - } + h->ccs -= COCO_DESTROY_CONTINUATION; + GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->destroy_task); + h->destroy_task = GNUNET_SCHEDULER_add_now (&destroy_continuation, h); + } } @@ -753,7 +748,7 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *h) */ static void connect_probe_continuation (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) + const struct GNUNET_SCHEDULER_TaskContext *tc) { struct AddressProbe *ap = cls; struct GNUNET_CONNECTION_Handle *h = ap->h; @@ -768,15 +763,15 @@ connect_probe_continuation (void *cls, error = 0; if ((0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) || (GNUNET_OK != - GNUNET_NETWORK_socket_getsockopt (ap->sock, SOL_SOCKET, SO_ERROR, - &error, &len)) || (error != 0)) - { - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock)); - GNUNET_free (ap); - if ((NULL == h->ap_head) && (h->dns_active == GNUNET_NO)) - connect_fail_continuation (h); - return; - } + GNUNET_NETWORK_socket_getsockopt (ap->sock, SOL_SOCKET, SO_ERROR, &error, + &len)) || (error != 0)) + { + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock)); + GNUNET_free (ap); + if ((NULL == h->ap_head) && (h->dns_active == GNUNET_NO)) + connect_fail_continuation (h); + return; + } GNUNET_assert (h->sock == NULL); h->sock = ap->sock; GNUNET_assert (h->addr == NULL); @@ -786,12 +781,12 @@ connect_probe_continuation (void *cls, GNUNET_free (ap); /* cancel all other attempts */ while (NULL != (pos = h->ap_head)) - { - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); - GNUNET_SCHEDULER_cancel (pos->task); - GNUNET_CONTAINER_DLL_remove (h->ap_head, h->ap_tail, pos); - GNUNET_free (pos); - } + { + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); + GNUNET_SCHEDULER_cancel (pos->task); + GNUNET_CONTAINER_DLL_remove (h->ap_head, h->ap_tail, pos); + GNUNET_free (pos); + } connect_success_continuation (h); } @@ -806,27 +801,27 @@ connect_probe_continuation (void *cls, */ static void try_connect_using_address (void *cls, const struct sockaddr *addr, - socklen_t addrlen) + socklen_t addrlen) { struct GNUNET_CONNECTION_Handle *h = cls; struct AddressProbe *ap; struct GNUNET_TIME_Relative delay; if (addr == NULL) - { - h->dns_active = NULL; - if ((NULL == h->ap_head) && (NULL == h->sock)) - connect_fail_continuation (h); - return; - } + { + h->dns_active = NULL; + if ((NULL == h->ap_head) && (NULL == h->sock)) + connect_fail_continuation (h); + return; + } if (h->sock != NULL) - return; /* already connected */ + return; /* already connected */ GNUNET_assert (h->addr == NULL); /* try to connect */ #if DEBUG_CONNECTION LOG (GNUNET_ERROR_TYPE_DEBUG, - "Trying to connect using address `%s:%u/%s:%u'\n", h->hostname, - h->port, GNUNET_a2s (addr, addrlen), h->port); + "Trying to connect using address `%s:%u/%s:%u'\n", h->hostname, h->port, + GNUNET_a2s (addr, addrlen), h->port); #endif ap = GNUNET_malloc (sizeof (struct AddressProbe) + addrlen); ap->addr = (const struct sockaddr *) &ap[1]; @@ -835,25 +830,24 @@ try_connect_using_address (void *cls, const struct sockaddr *addr, ap->h = h; switch (ap->addr->sa_family) - { - case AF_INET: - ((struct sockaddr_in *) ap->addr)->sin_port = htons (h->port); - break; - case AF_INET6: - ((struct sockaddr_in6 *) ap->addr)->sin6_port = htons (h->port); - break; - default: - GNUNET_break (0); - GNUNET_free (ap); - return; /* not supported by us */ - } - ap->sock = - GNUNET_NETWORK_socket_create (ap->addr->sa_family, SOCK_STREAM, 0); + { + case AF_INET: + ((struct sockaddr_in *) ap->addr)->sin_port = htons (h->port); + break; + case AF_INET6: + ((struct sockaddr_in6 *) ap->addr)->sin6_port = htons (h->port); + break; + default: + GNUNET_break (0); + GNUNET_free (ap); + return; /* not supported by us */ + } + ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family, SOCK_STREAM, 0); if (ap->sock == NULL) - { - GNUNET_free (ap); - return; /* not supported by OS */ - } + { + GNUNET_free (ap); + return; /* not supported by OS */ + } #if DEBUG_CONNECTION LOG (GNUNET_ERROR_TYPE_INFO, _("Trying to connect to `%s' (%p)\n"), GNUNET_a2s (ap->addr, ap->addrlen), h); @@ -861,33 +855,32 @@ try_connect_using_address (void *cls, const struct sockaddr *addr, if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (ap->sock, ap->addr, ap->addrlen)) && (errno != EINPROGRESS)) - { - /* maybe refused / unsupported address, try next */ - LOG_STRERROR (GNUNET_ERROR_TYPE_INFO, "connect"); + { + /* maybe refused / unsupported address, try next */ + LOG_STRERROR (GNUNET_ERROR_TYPE_INFO, "connect"); #if 0 - LOG (GNUNET_ERROR_TYPE_INFO, - _("Failed to connect to `%s' (%p)\n"), - GNUNET_a2s (ap->addr, ap->addrlen), h); + LOG (GNUNET_ERROR_TYPE_INFO, _("Failed to connect to `%s' (%p)\n"), + GNUNET_a2s (ap->addr, ap->addrlen), h); #endif - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock)); - GNUNET_free (ap); - return; - } + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock)); + GNUNET_free (ap); + return; + } GNUNET_CONTAINER_DLL_insert (h->ap_head, h->ap_tail, ap); delay = GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT; if (h->nth.notify_ready != NULL) delay = - GNUNET_TIME_relative_min (delay, - GNUNET_TIME_absolute_get_remaining (h-> - nth.transmit_timeout)); + GNUNET_TIME_relative_min (delay, + GNUNET_TIME_absolute_get_remaining (h-> + nth.transmit_timeout)); if (h->receiver != NULL) delay = - GNUNET_TIME_relative_min (delay, - GNUNET_TIME_absolute_get_remaining - (h->receive_timeout)); + GNUNET_TIME_relative_min (delay, + GNUNET_TIME_absolute_get_remaining + (h->receive_timeout)); ap->task = - GNUNET_SCHEDULER_add_write_net (delay, ap->sock, - &connect_probe_continuation, ap); + GNUNET_SCHEDULER_add_write_net (delay, ap->sock, + &connect_probe_continuation, ap); } @@ -902,13 +895,13 @@ try_connect_using_address (void *cls, const struct sockaddr *addr, * @return the socket handle */ struct GNUNET_CONNECTION_Handle * -GNUNET_CONNECTION_create_from_connect (const struct - GNUNET_CONFIGURATION_Handle *cfg, - const char *hostname, uint16_t port) +GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle + *cfg, const char *hostname, + uint16_t port) { struct GNUNET_CONNECTION_Handle *ret; - GNUNET_assert (0 < strlen (hostname)); /* sanity check */ + GNUNET_assert (0 < strlen (hostname)); /* sanity check */ ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle)); ret->cfg = cfg; ret->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE; @@ -916,9 +909,9 @@ GNUNET_CONNECTION_create_from_connect (const struct ret->port = port; ret->hostname = GNUNET_strdup (hostname); ret->dns_active = - GNUNET_RESOLVER_ip_get (ret->hostname, AF_UNSPEC, - GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT, - &try_connect_using_address, ret); + GNUNET_RESOLVER_ip_get (ret->hostname, AF_UNSPEC, + GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT, + &try_connect_using_address, ret); return ret; } @@ -934,15 +927,15 @@ GNUNET_CONNECTION_create_from_connect (const struct */ struct GNUNET_CONNECTION_Handle * GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct - GNUNET_CONFIGURATION_Handle - *cfg, const char *unixpath) + GNUNET_CONFIGURATION_Handle + *cfg, const char *unixpath) { #ifdef AF_UNIX struct GNUNET_CONNECTION_Handle *ret; struct sockaddr_un *un; size_t slen; - GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ + GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ un = GNUNET_malloc (sizeof (struct sockaddr_un)); un->sun_family = AF_UNIX; slen = strlen (unixpath); @@ -967,20 +960,20 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct ret->addrlen = slen; ret->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); if (NULL == ret->sock) - { - GNUNET_free (ret->addr); - GNUNET_free (ret->write_buffer); - GNUNET_free (ret); - return NULL; - } + { + GNUNET_free (ret->addr); + GNUNET_free (ret->write_buffer); + GNUNET_free (ret); + return NULL; + } if (GNUNET_OK != GNUNET_NETWORK_socket_connect (ret->sock, ret->addr, ret->addrlen)) - { - /* Just return; we expect everything to work eventually so don't fail HARD */ - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret->sock)); - ret->sock = NULL; - return ret; - } + { + /* Just return; we expect everything to work eventually so don't fail HARD */ + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret->sock)); + ret->sock = NULL; + return ret; + } connect_success_continuation (ret); return ret; #else @@ -1001,8 +994,8 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct */ struct GNUNET_CONNECTION_Handle * GNUNET_CONNECTION_create_from_sockaddr (int af_family, - const struct sockaddr *serv_addr, - socklen_t addrlen) + const struct sockaddr *serv_addr, + socklen_t addrlen) { struct GNUNET_NETWORK_Handle *s; struct GNUNET_CONNECTION_Handle *ret; @@ -1010,22 +1003,20 @@ GNUNET_CONNECTION_create_from_sockaddr (int af_family, s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0); if (s == NULL) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, - "socket"); - return NULL; - } + { + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, "socket"); + return NULL; + } if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) && (errno != EINPROGRESS)) - { - /* maybe refused / unsupported address, try next */ - LOG_STRERROR (GNUNET_ERROR_TYPE_INFO, "connect"); - LOG (GNUNET_ERROR_TYPE_INFO, - _("Attempt to connect to `%s' failed\n"), GNUNET_a2s (serv_addr, - addrlen)); - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); - return NULL; - } + { + /* maybe refused / unsupported address, try next */ + LOG_STRERROR (GNUNET_ERROR_TYPE_INFO, "connect"); + LOG (GNUNET_ERROR_TYPE_INFO, _("Attempt to connect to `%s' failed\n"), + GNUNET_a2s (serv_addr, addrlen)); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); + return NULL; + } ret = GNUNET_CONNECTION_create_from_existing (s); ret->addr = GNUNET_malloc (addrlen); memcpy (ret->addr, serv_addr, addrlen); @@ -1050,7 +1041,7 @@ int GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *sock) { if ((sock->ap_head != NULL) || (sock->dns_active != NULL)) - return GNUNET_YES; /* still trying to connect */ + return GNUNET_YES; /* still trying to connect */ return (sock->sock == NULL) ? GNUNET_NO : GNUNET_YES; } @@ -1070,23 +1061,23 @@ GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *sock) */ void GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock, - int finish_pending_write) + int finish_pending_write) { if (GNUNET_NO == finish_pending_write) + { + if (sock->write_task != GNUNET_SCHEDULER_NO_TASK) { - if (sock->write_task != GNUNET_SCHEDULER_NO_TASK) - { - GNUNET_SCHEDULER_cancel (sock->write_task); - sock->write_task = GNUNET_SCHEDULER_NO_TASK; - sock->write_buffer_off = 0; - } - sock->nth.notify_ready = NULL; + GNUNET_SCHEDULER_cancel (sock->write_task); + sock->write_task = GNUNET_SCHEDULER_NO_TASK; + sock->write_buffer_off = 0; } + sock->nth.notify_ready = NULL; + } if ((sock->write_buffer_off == 0) && (sock->dns_active != NULL)) - { - GNUNET_RESOLVER_request_cancel (sock->dns_active); - sock->dns_active = NULL; - } + { + GNUNET_RESOLVER_request_cancel (sock->dns_active); + sock->dns_active = NULL; + } GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); sock->destroy_task = GNUNET_SCHEDULER_add_now (&destroy_continuation, sock); @@ -1102,8 +1093,8 @@ signal_timeout (struct GNUNET_CONNECTION_Handle *sh) GNUNET_CONNECTION_Receiver receiver; #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Network signals time out to receiver (%p)!\n", sh); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Network signals time out to receiver (%p)!\n", + sh); #endif GNUNET_assert (NULL != (receiver = sh->receiver)); sh->receiver = NULL; @@ -1141,62 +1132,61 @@ receive_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) sh->read_task = GNUNET_SCHEDULER_NO_TASK; if ((GNUNET_YES == sh->ignore_shutdown) && (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))) - { - /* ignore shutdown request, go again immediately */ + { + /* ignore shutdown request, go again immediately */ #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Ignoring shutdown signal per configuration\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Ignoring shutdown signal per configuration\n"); #endif - sh->read_task = - GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining - (sh->receive_timeout), sh->sock, - &receive_ready, sh); - return; - } + sh->read_task = + GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining + (sh->receive_timeout), sh->sock, + &receive_ready, sh); + return; + } now = GNUNET_TIME_absolute_get (); if ((now.abs_value > sh->receive_timeout.abs_value) || (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) || (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))) - { + { #if DEBUG_CONNECTION - if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Receive from `%s' encounters error: time out by %llums... (%p)\n", - GNUNET_a2s (sh->addr, sh->addrlen), - GNUNET_TIME_absolute_get_duration (sh->receive_timeout). - rel_value, sh); + if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Receive from `%s' encounters error: time out by %llums... (%p)\n", + GNUNET_a2s (sh->addr, sh->addrlen), + GNUNET_TIME_absolute_get_duration (sh->receive_timeout).rel_value, + sh); #endif - signal_timeout (sh); - return; - } + signal_timeout (sh); + return; + } if (sh->sock == NULL) - { - /* connect failed for good */ + { + /* connect failed for good */ #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Receive encounters error, socket closed... (%p)\n", sh); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Receive encounters error, socket closed... (%p)\n", sh); #endif - signal_error (sh, ECONNREFUSED); - return; - } + signal_error (sh, ECONNREFUSED); + return; + } GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, sh->sock)); RETRY: ret = GNUNET_NETWORK_socket_recv (sh->sock, buffer, sh->max); if (ret == -1) - { - if (errno == EINTR) - goto RETRY; + { + if (errno == EINTR) + goto RETRY; #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, "Error receiving: %s\n", - STRERROR (errno)); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Error receiving: %s\n", STRERROR (errno)); #endif - signal_error (sh, errno); - return; - } + signal_error (sh, errno); + return; + } #if DEBUG_CONNECTION LOG (GNUNET_ERROR_TYPE_DEBUG, - "receive_ready read %u/%u bytes from `%s' (%p)!\n", - (unsigned int) ret, sh->max, GNUNET_a2s (sh->addr, sh->addrlen), sh); + "receive_ready read %u/%u bytes from `%s' (%p)!\n", (unsigned int) ret, + sh->max, GNUNET_a2s (sh->addr, sh->addrlen), sh); #endif GNUNET_assert (NULL != (receiver = sh->receiver)); sh->receiver = NULL; @@ -1222,32 +1212,32 @@ receive_again (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) sh->read_task = GNUNET_SCHEDULER_NO_TASK; if (sh->sock == NULL) - { - /* not connected and no longer trying */ + { + /* not connected and no longer trying */ #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Receive encounters error, socket closed (%p)...\n", sh); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Receive encounters error, socket closed (%p)...\n", sh); #endif - signal_error (sh, ECONNREFUSED); - return; - } + signal_error (sh, ECONNREFUSED); + return; + } now = GNUNET_TIME_absolute_get (); if ((now.abs_value > sh->receive_timeout.abs_value) || (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))) - { + { #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Receive encounters error: time out (%p)...\n", sh); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Receive encounters error: time out (%p)...\n", sh); #endif - signal_timeout (sh); - return; - } + signal_timeout (sh); + return; + } GNUNET_assert (sh->sock != NULL); /* connect succeeded, wait for data! */ sh->read_task = - GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining - (sh->receive_timeout), sh->sock, - &receive_ready, sh); + GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining + (sh->receive_timeout), sh->sock, + &receive_ready, sh); } @@ -1266,31 +1256,31 @@ receive_again (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) */ void GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *sock, size_t max, - struct GNUNET_TIME_Relative timeout, - GNUNET_CONNECTION_Receiver receiver, - void *receiver_cls) + struct GNUNET_TIME_Relative timeout, + GNUNET_CONNECTION_Receiver receiver, + void *receiver_cls) { struct GNUNET_SCHEDULER_TaskContext tc; GNUNET_assert ((sock->read_task == GNUNET_SCHEDULER_NO_TASK) && - (0 == (sock->ccs & COCO_RECEIVE_AGAIN)) && - (sock->receiver == NULL)); + (0 == (sock->ccs & COCO_RECEIVE_AGAIN)) && + (sock->receiver == NULL)); sock->receiver = receiver; sock->receiver_cls = receiver_cls; sock->receive_timeout = GNUNET_TIME_relative_to_absolute (timeout); sock->max = max; if (sock->sock != NULL) - { - memset (&tc, 0, sizeof (tc)); - tc.reason = GNUNET_SCHEDULER_REASON_PREREQ_DONE; - receive_again (sock, &tc); - return; - } + { + memset (&tc, 0, sizeof (tc)); + tc.reason = GNUNET_SCHEDULER_REASON_PREREQ_DONE; + receive_again (sock, &tc); + return; + } if ((sock->dns_active == NULL) && (sock->ap_head == NULL)) - { - receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT); - return; - } + { + receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT); + return; + } sock->ccs += COCO_RECEIVE_AGAIN; } @@ -1303,7 +1293,7 @@ GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *sock, size_t max, */ void GNUNET_CONNECTION_ignore_shutdown (struct GNUNET_CONNECTION_Handle *sock, - int do_ignore) + int do_ignore) { sock->ignore_shutdown = do_ignore; } @@ -1321,15 +1311,15 @@ void * GNUNET_CONNECTION_receive_cancel (struct GNUNET_CONNECTION_Handle *sock) { if (sock->read_task != GNUNET_SCHEDULER_NO_TASK) - { - GNUNET_assert (sock == GNUNET_SCHEDULER_cancel (sock->read_task)); - sock->read_task = GNUNET_SCHEDULER_NO_TASK; - } + { + GNUNET_assert (sock == GNUNET_SCHEDULER_cancel (sock->read_task)); + sock->read_task = GNUNET_SCHEDULER_NO_TASK; + } else - { - GNUNET_assert (0 != (sock->ccs & COCO_RECEIVE_AGAIN)); - sock->ccs -= COCO_RECEIVE_AGAIN; - } + { + GNUNET_assert (0 != (sock->ccs & COCO_RECEIVE_AGAIN)); + sock->ccs -= COCO_RECEIVE_AGAIN; + } sock->receiver = NULL; return sock->receiver_cls; } @@ -1360,18 +1350,18 @@ process_notify (struct GNUNET_CONNECTION_Handle *sock) return GNUNET_NO; sock->nth.notify_ready = NULL; if (sock->write_buffer_size - sock->write_buffer_off < size) - { - /* need to compact */ - memmove (sock->write_buffer, - &sock->write_buffer[sock->write_buffer_pos], used); - sock->write_buffer_off -= sock->write_buffer_pos; - sock->write_buffer_pos = 0; - } + { + /* need to compact */ + memmove (sock->write_buffer, &sock->write_buffer[sock->write_buffer_pos], + used); + sock->write_buffer_off -= sock->write_buffer_pos; + sock->write_buffer_pos = 0; + } avail = sock->write_buffer_size - sock->write_buffer_off; GNUNET_assert (avail >= size); size = - notify (sock->nth.notify_ready_cls, avail, - &sock->write_buffer[sock->write_buffer_off]); + notify (sock->nth.notify_ready_cls, avail, + &sock->write_buffer[sock->write_buffer_off]); GNUNET_assert (size <= avail); sock->write_buffer_off += size; return GNUNET_YES; @@ -1401,12 +1391,11 @@ transmit_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) sock->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; #if DEBUG_CONNECTION LOG (GNUNET_ERROR_TYPE_DEBUG, - "Transmit to `%s:%u/%s' fails, time out reached (%p).\n", - sock->hostname, sock->port, GNUNET_a2s (sock->addr, - sock->addrlen), sock); + "Transmit to `%s:%u/%s' fails, time out reached (%p).\n", sock->hostname, + sock->port, GNUNET_a2s (sock->addr, sock->addrlen), sock); #endif GNUNET_assert (0 != (sock->ccs & COCO_TRANSMIT_READY)); - sock->ccs -= COCO_TRANSMIT_READY; /* remove request */ + sock->ccs -= COCO_TRANSMIT_READY; /* remove request */ notify = sock->nth.notify_ready; sock->nth.notify_ready = NULL; notify (sock->nth.notify_ready_cls, 0, NULL); @@ -1451,20 +1440,20 @@ transmit_error (struct GNUNET_CONNECTION_Handle *sock) GNUNET_CONNECTION_TransmitReadyNotify notify; if (NULL != sock->sock) - { - GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR); - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock)); - sock->sock = NULL; - } + { + GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock)); + sock->sock = NULL; + } if (sock->read_task != GNUNET_SCHEDULER_NO_TASK) - { - GNUNET_SCHEDULER_cancel (sock->read_task); - sock->read_task = GNUNET_SCHEDULER_NO_TASK; - signal_timeout (sock); - return; - } + { + GNUNET_SCHEDULER_cancel (sock->read_task); + sock->read_task = GNUNET_SCHEDULER_NO_TASK; + signal_timeout (sock); + return; + } if (sock->nth.notify_ready == NULL) - return; /* nobody to tell about it */ + return; /* nobody to tell about it */ notify = sock->nth.notify_ready; sock->nth.notify_ready = NULL; notify (sock->nth.notify_ready_cls, 0, NULL); @@ -1494,109 +1483,107 @@ transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) sock->write_task = GNUNET_SCHEDULER_NO_TASK; GNUNET_assert (sock->nth.timeout_task == GNUNET_SCHEDULER_NO_TASK); if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) - { - if ( (sock->ignore_shutdown == GNUNET_YES) && - (NULL != sock->sock) ) - goto SCHEDULE_WRITE; /* ignore shutdown, go again immediately */ + { + if ((sock->ignore_shutdown == GNUNET_YES) && (NULL != sock->sock)) + goto SCHEDULE_WRITE; /* ignore shutdown, go again immediately */ #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Transmit to `%s' fails, shutdown happened (%p).\n", - GNUNET_a2s (sock->addr, sock->addrlen), sock); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Transmit to `%s' fails, shutdown happened (%p).\n", + GNUNET_a2s (sock->addr, sock->addrlen), sock); #endif - notify = sock->nth.notify_ready; - if (NULL != notify) - { - sock->nth.notify_ready = NULL; - notify (sock->nth.notify_ready_cls, 0, NULL); - } - return; - } - if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) + notify = sock->nth.notify_ready; + if (NULL != notify) { -#if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Transmit to `%s' fails, time out reached (%p).\n", - GNUNET_a2s (sock->addr, sock->addrlen), sock); -#endif - notify = sock->nth.notify_ready; - GNUNET_assert (NULL != notify); sock->nth.notify_ready = NULL; notify (sock->nth.notify_ready_cls, 0, NULL); - return; } + return; + } + if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) + { +#if DEBUG_CONNECTION + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Transmit to `%s' fails, time out reached (%p).\n", + GNUNET_a2s (sock->addr, sock->addrlen), sock); +#endif + notify = sock->nth.notify_ready; + GNUNET_assert (NULL != notify); + sock->nth.notify_ready = NULL; + notify (sock->nth.notify_ready_cls, 0, NULL); + return; + } GNUNET_assert (NULL != sock->sock); if (tc->write_ready == NULL) - { - /* special circumstances (in particular, - * PREREQ_DONE after connect): not yet ready to write, - * but no "fatal" error either. Hence retry. */ - goto SCHEDULE_WRITE; - } + { + /* special circumstances (in particular, + * PREREQ_DONE after connect): not yet ready to write, + * but no "fatal" error either. Hence retry. */ + goto SCHEDULE_WRITE; + } if (!GNUNET_NETWORK_fdset_isset (tc->write_ready, sock->sock)) - { + { #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_INFO, - _ - ("Could not satisfy pending transmission request, socket closed or connect failed (%p).\n"), - sock); + LOG (GNUNET_ERROR_TYPE_INFO, + _ + ("Could not satisfy pending transmission request, socket closed or connect failed (%p).\n"), + sock); #endif - transmit_error (sock); - return; /* connect failed for good, we're finished */ - } + transmit_error (sock); + return; /* connect failed for good, we're finished */ + } GNUNET_assert (sock->write_buffer_off >= sock->write_buffer_pos); if ((sock->nth.notify_ready != NULL) && (sock->write_buffer_size < sock->nth.notify_size)) - { - sock->write_buffer = - GNUNET_realloc (sock->write_buffer, sock->nth.notify_size); - sock->write_buffer_size = sock->nth.notify_size; - } + { + sock->write_buffer = + GNUNET_realloc (sock->write_buffer, sock->nth.notify_size); + sock->write_buffer_size = sock->nth.notify_size; + } process_notify (sock); have = sock->write_buffer_off - sock->write_buffer_pos; if (have == 0) - { - /* no data ready for writing, terminate write loop */ - return; - } + { + /* no data ready for writing, terminate write loop */ + return; + } GNUNET_assert (have <= sock->write_buffer_size); GNUNET_assert (have + sock->write_buffer_pos <= sock->write_buffer_size); GNUNET_assert (sock->write_buffer_pos <= sock->write_buffer_size); RETRY: ret = - GNUNET_NETWORK_socket_send (sock->sock, - &sock->write_buffer[sock->write_buffer_pos], - have); + GNUNET_NETWORK_socket_send (sock->sock, + &sock->write_buffer[sock->write_buffer_pos], + have); if (ret == -1) - { - if (errno == EINTR) - goto RETRY; + { + if (errno == EINTR) + goto RETRY; #if 0 - int en = errno; + int en = errno; - LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to send to `%s': %s\n"), - GNUNET_a2s (sock->addr, sock->addrlen), STRERROR (en)); + LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to send to `%s': %s\n"), + GNUNET_a2s (sock->addr, sock->addrlen), STRERROR (en)); #endif #if DEBUG_CONNECTION - LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, "send"); + LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, "send"); #endif - transmit_error (sock); - return; - } + transmit_error (sock); + return; + } #if DEBUG_CONNECTION LOG (GNUNET_ERROR_TYPE_DEBUG, "transmit_ready transmitted %u/%u bytes to `%s' (%p)\n", - (unsigned int) ret, have, GNUNET_a2s (sock->addr, sock->addrlen), - sock); + (unsigned int) ret, have, GNUNET_a2s (sock->addr, sock->addrlen), sock); #endif sock->write_buffer_pos += ret; if (sock->write_buffer_pos == sock->write_buffer_off) - { - /* transmitted all pending data */ - sock->write_buffer_pos = 0; - sock->write_buffer_off = 0; - } + { + /* transmitted all pending data */ + sock->write_buffer_pos = 0; + sock->write_buffer_off = 0; + } if ((sock->write_buffer_off == 0) && (NULL == sock->nth.notify_ready)) - return; /* all data sent! */ + return; /* all data sent! */ /* not done writing, schedule more */ SCHEDULE_WRITE: #if DEBUG_CONNECTION @@ -1607,11 +1594,11 @@ SCHEDULE_WRITE: GNUNET_assert ((sock->nth.notify_ready != NULL) || (have > 0)); if (sock->write_task == GNUNET_SCHEDULER_NO_TASK) sock->write_task = - GNUNET_SCHEDULER_add_write_net ((sock->nth.notify_ready == - NULL) ? GNUNET_TIME_UNIT_FOREVER_REL : - GNUNET_TIME_absolute_get_remaining - (sock->nth.transmit_timeout), - sock->sock, &transmit_ready, sock); + GNUNET_SCHEDULER_add_write_net ((sock->nth.notify_ready == + NULL) ? GNUNET_TIME_UNIT_FOREVER_REL : + GNUNET_TIME_absolute_get_remaining + (sock->nth.transmit_timeout), + sock->sock, &transmit_ready, sock); } @@ -1630,17 +1617,17 @@ SCHEDULE_WRITE: * NULL if we are already going to notify someone else (busy) */ struct GNUNET_CONNECTION_TransmitHandle * -GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle - *sock, size_t size, - struct GNUNET_TIME_Relative timeout, - GNUNET_CONNECTION_TransmitReadyNotify - notify, void *notify_cls) +GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *sock, + size_t size, + struct GNUNET_TIME_Relative timeout, + GNUNET_CONNECTION_TransmitReadyNotify + notify, void *notify_cls) { if (sock->nth.notify_ready != NULL) - { - GNUNET_assert (0); - return NULL; - } + { + GNUNET_assert (0); + return NULL; + } GNUNET_assert (notify != NULL); GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE); GNUNET_assert (sock->write_buffer_off <= sock->write_buffer_size); @@ -1654,36 +1641,34 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->nth.timeout_task); if ((sock->sock == NULL) && (sock->ap_head == NULL) && (sock->dns_active == NULL)) - { - if (sock->write_task != GNUNET_SCHEDULER_NO_TASK) - GNUNET_SCHEDULER_cancel (sock->write_task); - sock->write_task = GNUNET_SCHEDULER_add_now (&connect_error, sock); - return &sock->nth; - } + { + if (sock->write_task != GNUNET_SCHEDULER_NO_TASK) + GNUNET_SCHEDULER_cancel (sock->write_task); + sock->write_task = GNUNET_SCHEDULER_add_now (&connect_error, sock); + return &sock->nth; + } if (GNUNET_SCHEDULER_NO_TASK != sock->write_task) return &sock->nth; if (sock->sock != NULL) - { + { #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, "Scheduling transmit_ready (%p).\n", - sock); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Scheduling transmit_ready (%p).\n", sock); #endif - sock->write_task = - GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining - (sock->nth.transmit_timeout), - sock->sock, &transmit_ready, sock); - } + sock->write_task = + GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining + (sock->nth.transmit_timeout), + sock->sock, &transmit_ready, sock); + } else - { + { #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "CCS-Scheduling transmit_ready, adding timeout task (%p).\n", - sock); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "CCS-Scheduling transmit_ready, adding timeout task (%p).\n", sock); #endif - sock->ccs |= COCO_TRANSMIT_READY; - sock->nth.timeout_task = - GNUNET_SCHEDULER_add_delayed (timeout, &transmit_timeout, sock); - } + sock->ccs |= COCO_TRANSMIT_READY; + sock->nth.timeout_task = + GNUNET_SCHEDULER_add_delayed (timeout, &transmit_timeout, sock); + } return &sock->nth; } @@ -1695,28 +1680,28 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle */ void GNUNET_CONNECTION_notify_transmit_ready_cancel (struct - GNUNET_CONNECTION_TransmitHandle - *th) + GNUNET_CONNECTION_TransmitHandle + *th) { GNUNET_assert (th->notify_ready != NULL); if (0 != (th->sh->ccs & COCO_TRANSMIT_READY)) - { + { #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "notify_transmit_ready_cancel cancels timeout_task (%p)\n", th); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "notify_transmit_ready_cancel cancels timeout_task (%p)\n", th); #endif - GNUNET_SCHEDULER_cancel (th->timeout_task); - th->timeout_task = GNUNET_SCHEDULER_NO_TASK; - th->sh->ccs -= COCO_TRANSMIT_READY; - } + GNUNET_SCHEDULER_cancel (th->timeout_task); + th->timeout_task = GNUNET_SCHEDULER_NO_TASK; + th->sh->ccs -= COCO_TRANSMIT_READY; + } else + { + if (th->sh->write_task != GNUNET_SCHEDULER_NO_TASK) { - if (th->sh->write_task != GNUNET_SCHEDULER_NO_TASK) - { - GNUNET_SCHEDULER_cancel (th->sh->write_task); - th->sh->write_task = GNUNET_SCHEDULER_NO_TASK; - } + GNUNET_SCHEDULER_cancel (th->sh->write_task); + th->sh->write_task = GNUNET_SCHEDULER_NO_TASK; } + } th->notify_ready = NULL; } diff --git a/src/util/container_bloomfilter.c b/src/util/container_bloomfilter.c index a33b619ff..180aab4c3 100644 --- a/src/util/container_bloomfilter.c +++ b/src/util/container_bloomfilter.c @@ -89,8 +89,8 @@ struct GNUNET_CONTAINER_BloomFilter * @return number of bytes used for the data of the bloom filter */ size_t -GNUNET_CONTAINER_bloomfilter_get_size (const struct - GNUNET_CONTAINER_BloomFilter *bf) +GNUNET_CONTAINER_bloomfilter_get_size (const struct GNUNET_CONTAINER_BloomFilter + *bf) { if (bf == NULL) return 0; @@ -106,10 +106,10 @@ GNUNET_CONTAINER_bloomfilter_get_size (const struct */ struct GNUNET_CONTAINER_BloomFilter * GNUNET_CONTAINER_bloomfilter_copy (const struct GNUNET_CONTAINER_BloomFilter - *bf) + *bf) { return GNUNET_CONTAINER_bloomfilter_init (bf->bitArray, bf->bitArraySize, - bf->addressesPerElement); + bf->addressesPerElement); } @@ -181,7 +181,7 @@ testBit (char *bitArray, unsigned int bitIdx) */ static void incrementBit (char *bitArray, unsigned int bitIdx, - const struct GNUNET_DISK_FileHandle *fh) + const struct GNUNET_DISK_FileHandle *fh) { off_t fileSlot; unsigned char value; @@ -197,25 +197,25 @@ incrementBit (char *bitArray, unsigned int bitIdx, targetLoc = bitIdx % 2; GNUNET_assert (fileSlot == - GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET)); + GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET)); if (1 != GNUNET_DISK_file_read (fh, &value, 1)) value = 0; low = value & 0xF; high = (value & (~0xF)) >> 4; if (targetLoc == 0) - { - if (low < 0xF) - low++; - } + { + if (low < 0xF) + low++; + } else - { - if (high < 0xF) - high++; - } + { + if (high < 0xF) + high++; + } value = ((high << 4) | low); GNUNET_assert (fileSlot == - GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET)); + GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET)); GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1)); } @@ -229,7 +229,7 @@ incrementBit (char *bitArray, unsigned int bitIdx, */ static void decrementBit (char *bitArray, unsigned int bitIdx, - const struct GNUNET_DISK_FileHandle *fh) + const struct GNUNET_DISK_FileHandle *fh) { off_t fileSlot; unsigned char value; @@ -238,7 +238,7 @@ decrementBit (char *bitArray, unsigned int bitIdx, unsigned int targetLoc; if (GNUNET_DISK_handle_invalid (fh)) - return; /* cannot decrement! */ + return; /* cannot decrement! */ /* Each char slot in the counter file holds two 4 bit counters */ fileSlot = bitIdx / 2; targetLoc = bitIdx % 2; @@ -250,23 +250,23 @@ decrementBit (char *bitArray, unsigned int bitIdx, /* decrement, but once we have reached the max, never go back! */ if (targetLoc == 0) + { + if ((low > 0) && (low < 0xF)) + low--; + if (low == 0) { - if ((low > 0) && (low < 0xF)) - low--; - if (low == 0) - { - clearBit (bitArray, bitIdx); - } + clearBit (bitArray, bitIdx); } + } else + { + if ((high > 0) && (high < 0xF)) + high--; + if (high == 0) { - if ((high > 0) && (high < 0xF)) - high--; - if (high == 0) - { - clearBit (bitArray, bitIdx); - } + clearBit (bitArray, bitIdx); } + } value = ((high << 4) | low); GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET); GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1)); @@ -295,19 +295,19 @@ makeEmptyFile (const struct GNUNET_DISK_FileHandle *fh, size_t size) GNUNET_DISK_file_seek (fh, 0, GNUNET_DISK_SEEK_SET); while (bytesleft > 0) + { + if (bytesleft > BUFFSIZE) { - if (bytesleft > BUFFSIZE) - { - res = GNUNET_DISK_file_write (fh, buffer, BUFFSIZE); - bytesleft -= BUFFSIZE; - } - else - { - res = GNUNET_DISK_file_write (fh, buffer, bytesleft); - bytesleft = 0; - } - GNUNET_assert (res != GNUNET_SYSERR); + res = GNUNET_DISK_file_write (fh, buffer, BUFFSIZE); + bytesleft -= BUFFSIZE; } + else + { + res = GNUNET_DISK_file_write (fh, buffer, bytesleft); + bytesleft = 0; + } + GNUNET_assert (res != GNUNET_SYSERR); + } GNUNET_free (buffer); return GNUNET_OK; } @@ -325,8 +325,8 @@ makeEmptyFile (const struct GNUNET_DISK_FileHandle *fh, size_t size) * @return GNUNET_YES to continue, GNUNET_NO to stop early */ typedef int (*BitIterator) (void *cls, - const struct GNUNET_CONTAINER_BloomFilter * bf, - unsigned int bit); + const struct GNUNET_CONTAINER_BloomFilter * bf, + unsigned int bit); /** @@ -340,7 +340,7 @@ typedef int (*BitIterator) (void *cls, */ static void iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf, - BitIterator callback, void *arg, const GNUNET_HashCode * key) + BitIterator callback, void *arg, const GNUNET_HashCode * key) { GNUNET_HashCode tmp[2]; int bitCount; @@ -351,27 +351,27 @@ iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf, tmp[0] = *key; round = 0; while (bitCount > 0) + { + while (slot < (sizeof (GNUNET_HashCode) / sizeof (uint32_t))) { - while (slot < (sizeof (GNUNET_HashCode) / sizeof (uint32_t))) - { - if (GNUNET_YES != - callback (arg, bf, - (((uint32_t *) & tmp[round & 1])[slot]) & - ((bf->bitArraySize * 8) - 1))) - return; - slot++; - bitCount--; - if (bitCount == 0) - break; - } - if (bitCount > 0) - { - GNUNET_CRYPTO_hash (&tmp[round & 1], sizeof (GNUNET_HashCode), - &tmp[(round + 1) & 1]); - round++; - slot = 0; - } + if (GNUNET_YES != + callback (arg, bf, + (((uint32_t *) & tmp[round & 1])[slot]) & + ((bf->bitArraySize * 8) - 1))) + return; + slot++; + bitCount--; + if (bitCount == 0) + break; } + if (bitCount > 0) + { + GNUNET_CRYPTO_hash (&tmp[round & 1], sizeof (GNUNET_HashCode), + &tmp[(round + 1) & 1]); + round++; + slot = 0; + } + } } @@ -384,9 +384,8 @@ iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf, * @return GNUNET_YES */ static int -incrementBitCallback (void *cls, - const struct GNUNET_CONTAINER_BloomFilter *bf, - unsigned int bit) +incrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, + unsigned int bit) { struct GNUNET_CONTAINER_BloomFilter *b = cls; @@ -404,9 +403,8 @@ incrementBitCallback (void *cls, * @return GNUNET_YES */ static int -decrementBitCallback (void *cls, - const struct GNUNET_CONTAINER_BloomFilter *bf, - unsigned int bit) +decrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, + unsigned int bit) { struct GNUNET_CONTAINER_BloomFilter *b = cls; @@ -425,15 +423,15 @@ decrementBitCallback (void *cls, */ static int testBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, - unsigned int bit) + unsigned int bit) { int *arg = cls; if (GNUNET_NO == testBit (bf->bitArray, bit)) - { - *arg = GNUNET_NO; - return GNUNET_NO; - } + { + *arg = GNUNET_NO; + return GNUNET_NO; + } return GNUNET_YES; } @@ -451,7 +449,7 @@ testBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, */ struct GNUNET_CONTAINER_BloomFilter * GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, - unsigned int k) + unsigned int k) { struct GNUNET_CONTAINER_BloomFilter *bf; char *rbuff; @@ -467,32 +465,32 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, ui = 1; while (ui < size) ui *= 2; - size = ui; /* make sure it's a power of 2 */ + size = ui; /* make sure it's a power of 2 */ bf = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_BloomFilter)); /* Try to open a bloomfilter file */ bf->fh = - GNUNET_DISK_file_open (filename, - GNUNET_DISK_OPEN_READWRITE | - GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE); + GNUNET_DISK_file_open (filename, + GNUNET_DISK_OPEN_READWRITE | + GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE); if (NULL == bf->fh) - { - GNUNET_free (bf); - return NULL; - } + { + GNUNET_free (bf); + return NULL; + } bf->filename = GNUNET_strdup (filename); /* Alloc block */ bf->bitArray = GNUNET_malloc_large (size); if (bf->bitArray == NULL) - { - if (bf->fh != NULL) - GNUNET_DISK_file_close (bf->fh); - GNUNET_free (bf->filename); - GNUNET_free (bf); - return NULL; - } + { + if (bf->fh != NULL) + GNUNET_DISK_file_close (bf->fh); + GNUNET_free (bf->filename); + GNUNET_free (bf); + return NULL; + } bf->bitArraySize = size; bf->addressesPerElement = k; memset (bf->bitArray, 0, bf->bitArraySize); @@ -501,27 +499,27 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, rbuff = GNUNET_malloc (BUFFSIZE); pos = 0; while (pos < size * 8) + { + int res; + + res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE); + if (res == -1) + { + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "read", bf->filename); + } + if (res == 0) + break; /* is ok! we just did not use that many bits yet */ + for (i = 0; i < res; i++) { - int res; - - res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE); - if (res == -1) - { - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "read", bf->filename); - } - if (res == 0) - break; /* is ok! we just did not use that many bits yet */ - for (i = 0; i < res; i++) - { - if ((rbuff[i] & 0x0F) != 0) - setBit (bf->bitArray, pos + i * 2); - if ((rbuff[i] & 0xF0) != 0) - setBit (bf->bitArray, pos + i * 2 + 1); - } - if (res < BUFFSIZE) - break; - pos += BUFFSIZE * 2; /* 2 bits per byte in the buffer */ + if ((rbuff[i] & 0x0F) != 0) + setBit (bf->bitArray, pos + i * 2); + if ((rbuff[i] & 0xF0) != 0) + setBit (bf->bitArray, pos + i * 2 + 1); } + if (res < BUFFSIZE) + break; + pos += BUFFSIZE * 2; /* 2 bits per byte in the buffer */ + } GNUNET_free (rbuff); return bf; } @@ -542,7 +540,7 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, */ struct GNUNET_CONTAINER_BloomFilter * GNUNET_CONTAINER_bloomfilter_init (const char *data, size_t size, - unsigned int k) + unsigned int k) { struct GNUNET_CONTAINER_BloomFilter *bf; size_t ui; @@ -553,19 +551,19 @@ GNUNET_CONTAINER_bloomfilter_init (const char *data, size_t size, while (ui < size) ui *= 2; if (size != ui) - { - GNUNET_break (0); - return NULL; - } + { + GNUNET_break (0); + return NULL; + } bf = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_BloomFilter)); bf->filename = NULL; bf->fh = NULL; bf->bitArray = GNUNET_malloc_large (size); if (bf->bitArray == NULL) - { - GNUNET_free (bf); - return NULL; - } + { + GNUNET_free (bf); + return NULL; + } bf->bitArraySize = size; bf->addressesPerElement = k; if (data != NULL) @@ -587,8 +585,8 @@ GNUNET_CONTAINER_bloomfilter_init (const char *data, size_t size, */ int GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct - GNUNET_CONTAINER_BloomFilter *bf, - char *data, size_t size) + GNUNET_CONTAINER_BloomFilter *bf, + char *data, size_t size) { if (NULL == bf) return GNUNET_SYSERR; @@ -645,7 +643,7 @@ GNUNET_CONTAINER_bloomfilter_clear (struct GNUNET_CONTAINER_BloomFilter *bf) */ int GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter - *bf, const GNUNET_HashCode * e) + *bf, const GNUNET_HashCode * e) { int res; @@ -665,7 +663,7 @@ GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter */ void GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf, - const GNUNET_HashCode * e) + const GNUNET_HashCode * e) { if (NULL == bf) return; @@ -685,7 +683,7 @@ GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf, */ int GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, - const char *data, size_t size) + const char *data, size_t size) { unsigned int i; unsigned int n; @@ -719,8 +717,8 @@ GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, */ int GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf, - const struct GNUNET_CONTAINER_BloomFilter - *to_or, size_t size) + const struct GNUNET_CONTAINER_BloomFilter + *to_or, size_t size) { unsigned int i; unsigned int n; @@ -750,7 +748,7 @@ GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf, */ void GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf, - const GNUNET_HashCode * e) + const GNUNET_HashCode * e) { if (NULL == bf) return; @@ -772,9 +770,9 @@ GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf, */ void GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf, - GNUNET_HashCodeIterator iterator, - void *iterator_cls, size_t size, - unsigned int k) + GNUNET_HashCodeIterator iterator, + void *iterator_cls, size_t size, + unsigned int k) { GNUNET_HashCode hc; unsigned int i; @@ -783,7 +781,7 @@ GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf, i = 1; while (i < size) i *= 2; - size = i; /* make sure it's a power of 2 */ + size = i; /* make sure it's a power of 2 */ bf->bitArraySize = size; bf->bitArray = GNUNET_malloc (size); diff --git a/src/util/container_heap.c b/src/util/container_heap.c index 051b85a25..c34e220ce 100644 --- a/src/util/container_heap.c +++ b/src/util/container_heap.c @@ -116,10 +116,10 @@ check (const struct GNUNET_CONTAINER_HeapNode *node) if (NULL == node) return; GNUNET_assert (node->tree_size == - ((node->left_child == - NULL) ? 0 : 1 + node->left_child->tree_size) + - ((node->right_child == - NULL) ? 0 : 1 + node->right_child->tree_size)); + ((node->left_child == + NULL) ? 0 : 1 + node->left_child->tree_size) + + ((node->right_child == + NULL) ? 0 : 1 + node->right_child->tree_size)); check (node->left_child); check (node->right_child); } @@ -198,7 +198,7 @@ GNUNET_CONTAINER_heap_get_size (const struct GNUNET_CONTAINER_Heap *heap) */ GNUNET_CONTAINER_HeapCostType GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode - * node) + *node) { return node->cost; } @@ -214,8 +214,8 @@ GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode */ static int node_iterator (const struct GNUNET_CONTAINER_Heap *heap, - struct GNUNET_CONTAINER_HeapNode *node, - GNUNET_CONTAINER_HeapIterator iterator, void *iterator_cls) + struct GNUNET_CONTAINER_HeapNode *node, + GNUNET_CONTAINER_HeapIterator iterator, void *iterator_cls) { if (node == NULL) return GNUNET_YES; @@ -238,8 +238,8 @@ node_iterator (const struct GNUNET_CONTAINER_Heap *heap, */ void GNUNET_CONTAINER_heap_iterate (const struct GNUNET_CONTAINER_Heap *heap, - GNUNET_CONTAINER_HeapIterator iterator, - void *iterator_cls) + GNUNET_CONTAINER_HeapIterator iterator, + void *iterator_cls) { (void) node_iterator (heap, heap->root, iterator, iterator_cls); } @@ -269,9 +269,9 @@ GNUNET_CONTAINER_heap_walk_get_next (struct GNUNET_CONTAINER_Heap *heap) pos = heap->root; element = pos->element; heap->walk_pos = - (0 == - GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, - 2)) ? pos->right_child : pos->left_child; + (0 == + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, + 2)) ? pos->right_child : pos->left_child; return element; } @@ -286,51 +286,51 @@ GNUNET_CONTAINER_heap_walk_get_next (struct GNUNET_CONTAINER_Heap *heap) */ static void insert_node (struct GNUNET_CONTAINER_Heap *heap, - struct GNUNET_CONTAINER_HeapNode *pos, - struct GNUNET_CONTAINER_HeapNode *node) + struct GNUNET_CONTAINER_HeapNode *pos, + struct GNUNET_CONTAINER_HeapNode *node) { struct GNUNET_CONTAINER_HeapNode *parent; GNUNET_assert (node->parent == NULL); while ((heap->order == GNUNET_CONTAINER_HEAP_ORDER_MAX) ? (pos->cost >= - node->cost) - : (pos->cost <= node->cost)) + node->cost) + : (pos->cost <= node->cost)) + { + /* node is descendent of pos */ + pos->tree_size += (1 + node->tree_size); + if (pos->left_child == NULL) { - /* node is descendent of pos */ - pos->tree_size += (1 + node->tree_size); - if (pos->left_child == NULL) - { - pos->left_child = node; - node->parent = pos; - return; - } - if (pos->right_child == NULL) - { - pos->right_child = node; - node->parent = pos; - return; - } - /* keep it balanced by descending into smaller subtree */ - if (pos->left_child->tree_size < pos->right_child->tree_size) - pos = pos->left_child; - else - pos = pos->right_child; + pos->left_child = node; + node->parent = pos; + return; } + if (pos->right_child == NULL) + { + pos->right_child = node; + node->parent = pos; + return; + } + /* keep it balanced by descending into smaller subtree */ + if (pos->left_child->tree_size < pos->right_child->tree_size) + pos = pos->left_child; + else + pos = pos->right_child; + } /* make 'node' parent of 'pos' */ parent = pos->parent; pos->parent = NULL; node->parent = parent; if (NULL == parent) - { - heap->root = node; - } + { + heap->root = node; + } else - { - if (parent->left_child == pos) - parent->left_child = node; - else - parent->right_child = node; - } + { + if (parent->left_child == pos) + parent->left_child = node; + else + parent->right_child = node; + } /* insert 'pos' below 'node' */ insert_node (heap, node, pos); CHECK (pos); @@ -346,9 +346,8 @@ insert_node (struct GNUNET_CONTAINER_Heap *heap, * @return node for the new element */ struct GNUNET_CONTAINER_HeapNode * -GNUNET_CONTAINER_heap_insert (struct GNUNET_CONTAINER_Heap *heap, - void *element, - GNUNET_CONTAINER_HeapCostType cost) +GNUNET_CONTAINER_heap_insert (struct GNUNET_CONTAINER_Heap *heap, void *element, + GNUNET_CONTAINER_HeapCostType cost) { struct GNUNET_CONTAINER_HeapNode *node; @@ -384,27 +383,27 @@ GNUNET_CONTAINER_heap_remove_root (struct GNUNET_CONTAINER_Heap *heap) heap->size--; ret = root->element; if (root->left_child == NULL) - { - heap->root = root->right_child; - if (root->right_child != NULL) - root->right_child->parent = NULL; - } + { + heap->root = root->right_child; + if (root->right_child != NULL) + root->right_child->parent = NULL; + } else if (root->right_child == NULL) - { - heap->root = root->left_child; - root->left_child->parent = NULL; - } + { + heap->root = root->left_child; + root->left_child->parent = NULL; + } else - { - root->left_child->parent = NULL; - root->right_child->parent = NULL; - heap->root = root->left_child; - insert_node (heap, heap->root, root->right_child); - } + { + root->left_child->parent = NULL; + root->right_child->parent = NULL; + heap->root = root->left_child; + insert_node (heap, heap->root, root->right_child); + } GNUNET_free (root); #if DEBUG GNUNET_assert (((heap->size == 0) && (heap->root == NULL)) || - (heap->size == heap->root->tree_size + 1)); + (heap->size == heap->root->tree_size + 1)); CHECK (heap->root); #endif return ret; @@ -436,43 +435,43 @@ remove_node (struct GNUNET_CONTAINER_HeapNode *node) /* unlink 'node' itself and insert children in its place */ if (node->parent == NULL) + { + if (node->left_child != NULL) { - if (node->left_child != NULL) - { - heap->root = node->left_child; - node->left_child->parent = NULL; - if (node->right_child != NULL) - { - node->right_child->parent = NULL; - insert_node (heap, heap->root, node->right_child); - } - } - else - { - heap->root = node->right_child; - if (node->right_child != NULL) - node->right_child->parent = NULL; - } + heap->root = node->left_child; + node->left_child->parent = NULL; + if (node->right_child != NULL) + { + node->right_child->parent = NULL; + insert_node (heap, heap->root, node->right_child); + } } - else + else { - if (node->parent->left_child == node) - node->parent->left_child = NULL; - else - node->parent->right_child = NULL; - if (node->left_child != NULL) - { - node->left_child->parent = NULL; - node->parent->tree_size -= (1 + node->left_child->tree_size); - insert_node (heap, node->parent, node->left_child); - } + heap->root = node->right_child; if (node->right_child != NULL) - { - node->right_child->parent = NULL; - node->parent->tree_size -= (1 + node->right_child->tree_size); - insert_node (heap, node->parent, node->right_child); - } + node->right_child->parent = NULL; + } + } + else + { + if (node->parent->left_child == node) + node->parent->left_child = NULL; + else + node->parent->right_child = NULL; + if (node->left_child != NULL) + { + node->left_child->parent = NULL; + node->parent->tree_size -= (1 + node->left_child->tree_size); + insert_node (heap, node->parent, node->left_child); + } + if (node->right_child != NULL) + { + node->right_child->parent = NULL; + node->parent->tree_size -= (1 + node->right_child->tree_size); + insert_node (heap, node->parent, node->right_child); } + } node->parent = NULL; node->left_child = NULL; node->right_child = NULL; @@ -506,7 +505,7 @@ GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_HeapNode *node) #if DEBUG CHECK (heap->root); GNUNET_assert (((heap->size == 0) && (heap->root == NULL)) || - (heap->size == heap->root->tree_size + 1)); + (heap->size == heap->root->tree_size + 1)); #endif return ret; } @@ -521,19 +520,19 @@ GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_HeapNode *node) */ void GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_Heap *heap, - struct GNUNET_CONTAINER_HeapNode *node, - GNUNET_CONTAINER_HeapCostType new_cost) + struct GNUNET_CONTAINER_HeapNode *node, + GNUNET_CONTAINER_HeapCostType new_cost) { #if DEBUG GNUNET_assert (((heap->size == 0) && (heap->root == NULL)) || - (heap->size == heap->root->tree_size + 1)); + (heap->size == heap->root->tree_size + 1)); CHECK (heap->root); #endif remove_node (node); #if DEBUG CHECK (heap->root); GNUNET_assert (((heap->size == 1) && (heap->root == NULL)) || - (heap->size == heap->root->tree_size + 2)); + (heap->size == heap->root->tree_size + 2)); #endif node->cost = new_cost; if (heap->root == NULL) @@ -543,7 +542,7 @@ GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_Heap *heap, #if DEBUG CHECK (heap->root); GNUNET_assert (((heap->size == 0) && (heap->root == NULL)) || - (heap->size == heap->root->tree_size + 1)); + (heap->size == heap->root->tree_size + 1)); #endif } diff --git a/src/util/container_meta_data.c b/src/util/container_meta_data.c index 1ea77f63a..c2ec01c04 100644 --- a/src/util/container_meta_data.c +++ b/src/util/container_meta_data.c @@ -162,10 +162,10 @@ GNUNET_CONTAINER_meta_data_destroy (struct GNUNET_CONTAINER_MetaData *md) if (md == NULL) return; while (NULL != (item = md->items)) - { - md->items = item->next; - meta_item_free (item); - } + { + md->items = item->next; + meta_item_free (item); + } GNUNET_free_non_null (md->sbuf); GNUNET_free (md); } @@ -184,10 +184,10 @@ GNUNET_CONTAINER_meta_data_clear (struct GNUNET_CONTAINER_MetaData *md) if (md == NULL) return; while (NULL != (item = md->items)) - { - md->items = item->next; - meta_item_free (item); - } + { + md->items = item->next; + meta_item_free (item); + } GNUNET_free_non_null (md->sbuf); memset (md, 0, sizeof (struct GNUNET_CONTAINER_MetaData)); } @@ -206,9 +206,9 @@ GNUNET_CONTAINER_meta_data_clear (struct GNUNET_CONTAINER_MetaData *md) */ int GNUNET_CONTAINER_meta_data_test_equal (const struct GNUNET_CONTAINER_MetaData - *md1, - const struct GNUNET_CONTAINER_MetaData - *md2) + *md1, + const struct GNUNET_CONTAINER_MetaData + *md2) { struct MetaItem *i; struct MetaItem *j; @@ -221,24 +221,24 @@ GNUNET_CONTAINER_meta_data_test_equal (const struct GNUNET_CONTAINER_MetaData i = md1->items; while (NULL != i) + { + found = GNUNET_NO; + j = md2->items; + while (NULL != j) { - found = GNUNET_NO; - j = md2->items; - while (NULL != j) - { - if ((i->type == j->type) && (i->format == j->format) && - (i->data_size == j->data_size) && - (0 == memcmp (i->data, j->data, i->data_size))) - { - found = GNUNET_YES; - break; - } - j = j->next; - } - if (found == GNUNET_NO) - return GNUNET_NO; - i = i->next; + if ((i->type == j->type) && (i->format == j->format) && + (i->data_size == j->data_size) && + (0 == memcmp (i->data, j->data, i->data_size))) + { + found = GNUNET_YES; + break; + } + j = j->next; } + if (found == GNUNET_NO) + return GNUNET_NO; + i = i->next; + } return GNUNET_YES; } @@ -263,11 +263,11 @@ GNUNET_CONTAINER_meta_data_test_equal (const struct GNUNET_CONTAINER_MetaData */ int GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md, - const char *plugin_name, - enum EXTRACTOR_MetaType type, - enum EXTRACTOR_MetaFormat format, - const char *data_mime_type, - const char *data, size_t data_len) + const char *plugin_name, + enum EXTRACTOR_MetaType type, + enum EXTRACTOR_MetaFormat format, + const char *data_mime_type, const char *data, + size_t data_len) { struct MetaItem *prev; struct MetaItem *pos; @@ -277,28 +277,28 @@ GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md, prev = NULL; pos = md->items; while (NULL != pos) + { + if (pos->data_size < data_len) + break; + if ((pos->type == type) && (pos->data_size == data_len) && + (0 == memcmp (pos->data, data, data_len))) { - if (pos->data_size < data_len) - break; - if ((pos->type == type) && (pos->data_size == data_len) && - (0 == memcmp (pos->data, data, data_len))) - { - if ((pos->mime_type == NULL) && (data_mime_type != NULL)) - { - pos->mime_type = GNUNET_strdup (data_mime_type); - invalidate_sbuf (md); - } - if ((pos->format == EXTRACTOR_METAFORMAT_C_STRING) && - (format == EXTRACTOR_METAFORMAT_UTF8)) - { - pos->format = EXTRACTOR_METAFORMAT_UTF8; - invalidate_sbuf (md); - } - return GNUNET_SYSERR; - } - prev = pos; - pos = pos->next; + if ((pos->mime_type == NULL) && (data_mime_type != NULL)) + { + pos->mime_type = GNUNET_strdup (data_mime_type); + invalidate_sbuf (md); + } + if ((pos->format == EXTRACTOR_METAFORMAT_C_STRING) && + (format == EXTRACTOR_METAFORMAT_UTF8)) + { + pos->format = EXTRACTOR_METAFORMAT_UTF8; + invalidate_sbuf (md); + } + return GNUNET_SYSERR; } + prev = pos; + pos = pos->next; + } md->item_count++; i = GNUNET_malloc (sizeof (struct MetaItem)); i->type = type; @@ -310,23 +310,23 @@ GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md, else prev->next = i; i->mime_type = - (data_mime_type == NULL) ? NULL : GNUNET_strdup (data_mime_type); + (data_mime_type == NULL) ? NULL : GNUNET_strdup (data_mime_type); i->plugin_name = (plugin_name == NULL) ? NULL : GNUNET_strdup (plugin_name); i->data = GNUNET_malloc (data_len); memcpy (i->data, data, data_len); /* change OS native dir separators to unix '/' and others to '_' */ if (type == EXTRACTOR_METATYPE_FILENAME) + { + p = i->data; + while ((*p != '\0') && (p < i->data + data_len)) { - p = i->data; - while ((*p != '\0') && (p < i->data + data_len)) - { - if (*p == DIR_SEPARATOR) - *p = '/'; - else if (*p == '\\') - *p = '_'; - p++; - } + if (*p == DIR_SEPARATOR) + *p = '/'; + else if (*p == '\\') + *p = '_'; + p++; } + } invalidate_sbuf (md); return GNUNET_OK; } @@ -349,14 +349,14 @@ GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md, * @return 0 (to continue) */ static int -merge_helper (void *cls, const char *plugin_name, - enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, - const char *data_mime_type, const char *data, size_t data_len) +merge_helper (void *cls, const char *plugin_name, enum EXTRACTOR_MetaType type, + enum EXTRACTOR_MetaFormat format, const char *data_mime_type, + const char *data, size_t data_len) { struct GNUNET_CONTAINER_MetaData *md = cls; (void) GNUNET_CONTAINER_meta_data_insert (md, plugin_name, type, format, - data_mime_type, data, data_len); + data_mime_type, data, data_len); return 0; } @@ -370,7 +370,7 @@ merge_helper (void *cls, const char *plugin_name, */ void GNUNET_CONTAINER_meta_data_merge (struct GNUNET_CONTAINER_MetaData *md, - const struct GNUNET_CONTAINER_MetaData *in) + const struct GNUNET_CONTAINER_MetaData *in) { GNUNET_CONTAINER_meta_data_iterate (in, &merge_helper, md); } @@ -388,8 +388,8 @@ GNUNET_CONTAINER_meta_data_merge (struct GNUNET_CONTAINER_MetaData *md, */ int GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md, - enum EXTRACTOR_MetaType type, - const char *data, size_t data_len) + enum EXTRACTOR_MetaType type, + const char *data, size_t data_len) { struct MetaItem *pos; struct MetaItem *prev; @@ -397,24 +397,24 @@ GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md, prev = NULL; pos = md->items; while (NULL != pos) + { + if ((pos->type == type) && + ((data == NULL) || + ((pos->data_size == data_len) && + (0 == memcmp (pos->data, data, data_len))))) { - if ((pos->type == type) && - ((data == NULL) || - ((pos->data_size == data_len) && - (0 == memcmp (pos->data, data, data_len))))) - { - if (prev == NULL) - md->items = pos->next; - else - prev->next = pos->next; - meta_item_free (pos); - md->item_count--; - invalidate_sbuf (md); - return GNUNET_OK; - } - prev = pos; - pos = pos->next; + if (prev == NULL) + md->items = pos->next; + else + prev->next = pos->next; + meta_item_free (pos); + md->item_count--; + invalidate_sbuf (md); + return GNUNET_OK; } + prev = pos; + pos = pos->next; + } return GNUNET_SYSERR; } @@ -427,20 +427,19 @@ GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md, */ void GNUNET_CONTAINER_meta_data_add_publication_date (struct - GNUNET_CONTAINER_MetaData - *md) + GNUNET_CONTAINER_MetaData *md) { char *dat; struct GNUNET_TIME_Absolute t; t = GNUNET_TIME_absolute_get (); GNUNET_CONTAINER_meta_data_delete (md, EXTRACTOR_METATYPE_PUBLICATION_DATE, - NULL, 0); + NULL, 0); dat = GNUNET_STRINGS_absolute_time_to_string (t); GNUNET_CONTAINER_meta_data_insert (md, "", - EXTRACTOR_METATYPE_PUBLICATION_DATE, - EXTRACTOR_METAFORMAT_UTF8, "text/plain", - dat, strlen (dat) + 1); + EXTRACTOR_METATYPE_PUBLICATION_DATE, + EXTRACTOR_METAFORMAT_UTF8, "text/plain", + dat, strlen (dat) + 1); GNUNET_free (dat); } @@ -454,9 +453,9 @@ GNUNET_CONTAINER_meta_data_add_publication_date (struct * @return number of entries */ int -GNUNET_CONTAINER_meta_data_iterate (const struct GNUNET_CONTAINER_MetaData - *md, EXTRACTOR_MetaDataProcessor iter, - void *iter_cls) +GNUNET_CONTAINER_meta_data_iterate (const struct GNUNET_CONTAINER_MetaData *md, + EXTRACTOR_MetaDataProcessor iter, + void *iter_cls) { struct MetaItem *pos; @@ -466,13 +465,13 @@ GNUNET_CONTAINER_meta_data_iterate (const struct GNUNET_CONTAINER_MetaData return md->item_count; pos = md->items; while (NULL != pos) - { - if (0 != - iter (iter_cls, pos->plugin_name, pos->type, pos->format, - pos->mime_type, pos->data, pos->data_size)) - return md->item_count; - pos = pos->next; - } + { + if (0 != + iter (iter_cls, pos->plugin_name, pos->type, pos->format, + pos->mime_type, pos->data, pos->data_size)) + return md->item_count; + pos = pos->next; + } return md->item_count; } @@ -489,7 +488,7 @@ GNUNET_CONTAINER_meta_data_iterate (const struct GNUNET_CONTAINER_MetaData */ char * GNUNET_CONTAINER_meta_data_get_by_type (const struct GNUNET_CONTAINER_MetaData - *md, enum EXTRACTOR_MetaType type) + *md, enum EXTRACTOR_MetaType type) { struct MetaItem *pos; @@ -497,13 +496,13 @@ GNUNET_CONTAINER_meta_data_get_by_type (const struct GNUNET_CONTAINER_MetaData return NULL; pos = md->items; while (NULL != pos) - { - if ((type == pos->type) && - ((pos->format == EXTRACTOR_METAFORMAT_UTF8) || - (pos->format == EXTRACTOR_METAFORMAT_C_STRING))) - return GNUNET_strdup (pos->data); - pos = pos->next; - } + { + if ((type == pos->type) && + ((pos->format == EXTRACTOR_METAFORMAT_UTF8) || + (pos->format == EXTRACTOR_METAFORMAT_C_STRING))) + return GNUNET_strdup (pos->data); + pos = pos->next; + } return NULL; } @@ -521,8 +520,8 @@ GNUNET_CONTAINER_meta_data_get_by_type (const struct GNUNET_CONTAINER_MetaData */ char * GNUNET_CONTAINER_meta_data_get_first_by_types (const struct - GNUNET_CONTAINER_MetaData *md, - ...) + GNUNET_CONTAINER_MetaData *md, + ...) { char *ret; va_list args; @@ -533,15 +532,15 @@ GNUNET_CONTAINER_meta_data_get_first_by_types (const struct ret = NULL; va_start (args, md); while (1) - { - type = va_arg (args, enum EXTRACTOR_MetaType); - - if (type == -1) - break; - ret = GNUNET_CONTAINER_meta_data_get_by_type (md, type); - if (ret != NULL) - break; - } + { + type = va_arg (args, enum EXTRACTOR_MetaType); + + if (type == -1) + break; + ret = GNUNET_CONTAINER_meta_data_get_by_type (md, type); + if (ret != NULL) + break; + } va_end (args); return ret; } @@ -556,9 +555,8 @@ GNUNET_CONTAINER_meta_data_get_first_by_types (const struct * @return number of bytes in thumbnail, 0 if not available */ size_t -GNUNET_CONTAINER_meta_data_get_thumbnail (const struct - GNUNET_CONTAINER_MetaData * md, - unsigned char **thumb) +GNUNET_CONTAINER_meta_data_get_thumbnail (const struct GNUNET_CONTAINER_MetaData + * md, unsigned char **thumb) { struct MetaItem *pos; struct MetaItem *match; @@ -568,19 +566,19 @@ GNUNET_CONTAINER_meta_data_get_thumbnail (const struct match = NULL; pos = md->items; while (NULL != pos) + { + if ((NULL != pos->mime_type) && + (0 == strncasecmp ("image/", pos->mime_type, strlen ("image/"))) && + (pos->format == EXTRACTOR_METAFORMAT_BINARY)) { - if ((NULL != pos->mime_type) && - (0 == strncasecmp ("image/", pos->mime_type, strlen ("image/"))) && - (pos->format == EXTRACTOR_METAFORMAT_BINARY)) - { - if (match == NULL) - match = pos; - else if ((match->type != EXTRACTOR_METATYPE_THUMBNAIL) && - (pos->type == EXTRACTOR_METATYPE_THUMBNAIL)) - match = pos; - } - pos = pos->next; + if (match == NULL) + match = pos; + else if ((match->type != EXTRACTOR_METATYPE_THUMBNAIL) && + (pos->type == EXTRACTOR_METATYPE_THUMBNAIL)) + match = pos; } + pos = pos->next; + } if ((match == NULL) || (match->data_size == 0)) return 0; *thumb = GNUNET_malloc (match->data_size); @@ -597,7 +595,7 @@ GNUNET_CONTAINER_meta_data_get_thumbnail (const struct */ struct GNUNET_CONTAINER_MetaData * GNUNET_CONTAINER_meta_data_duplicate (const struct GNUNET_CONTAINER_MetaData - *md) + *md) { struct GNUNET_CONTAINER_MetaData *ret; struct MetaItem *pos; @@ -607,12 +605,12 @@ GNUNET_CONTAINER_meta_data_duplicate (const struct GNUNET_CONTAINER_MetaData ret = GNUNET_CONTAINER_meta_data_create (); pos = md->items; while (NULL != pos) - { - GNUNET_CONTAINER_meta_data_insert (ret, pos->plugin_name, pos->type, - pos->format, pos->mime_type, - pos->data, pos->data_size); - pos = pos->next; - } + { + GNUNET_CONTAINER_meta_data_insert (ret, pos->plugin_name, pos->type, + pos->format, pos->mime_type, pos->data, + pos->data_size); + pos = pos->next; + } return ret; } @@ -633,7 +631,7 @@ GNUNET_CONTAINER_meta_data_duplicate (const struct GNUNET_CONTAINER_MetaData */ static int try_compression (const char *data, size_t oldSize, char **result, - size_t * newSize) + size_t * newSize) { char *tmp; uLongf dlen; @@ -648,14 +646,14 @@ try_compression (const char *data, size_t oldSize, char **result, tmp = GNUNET_malloc (dlen); if (Z_OK == compress2 ((Bytef *) tmp, &dlen, (const Bytef *) data, oldSize, 9)) + { + if (dlen < oldSize) { - if (dlen < oldSize) - { - *result = tmp; - *newSize = dlen; - return GNUNET_YES; - } + *result = tmp; + *newSize = dlen; + return GNUNET_YES; } + } GNUNET_free (tmp); return GNUNET_NO; } @@ -756,10 +754,10 @@ struct MetaDataEntry */ ssize_t GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData - *md, char **target, size_t max, - enum - GNUNET_CONTAINER_MetaDataSerializationOptions - opt) + *md, char **target, size_t max, + enum + GNUNET_CONTAINER_MetaDataSerializationOptions + opt) { struct GNUNET_CONTAINER_MetaData *vmd; struct MetaItem *pos; @@ -781,79 +779,79 @@ GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData int comp; if (max < sizeof (struct MetaDataHeader)) - return GNUNET_SYSERR; /* far too small */ + return GNUNET_SYSERR; /* far too small */ if (md == NULL) return 0; if (md->sbuf != NULL) + { + /* try to use serialization cache */ + if (md->sbuf_size <= max) { - /* try to use serialization cache */ - if (md->sbuf_size <= max) - { - if (NULL == *target) - *target = GNUNET_malloc (md->sbuf_size); - memcpy (*target, md->sbuf, md->sbuf_size); - return md->sbuf_size; - } - if (0 == (opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_PART)) - return GNUNET_SYSERR; /* can say that this will fail */ - /* need to compute a partial serialization, sbuf useless ... */ + if (NULL == *target) + *target = GNUNET_malloc (md->sbuf_size); + memcpy (*target, md->sbuf, md->sbuf_size); + return md->sbuf_size; } + if (0 == (opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_PART)) + return GNUNET_SYSERR; /* can say that this will fail */ + /* need to compute a partial serialization, sbuf useless ... */ + } dst = NULL; msize = 0; pos = md->items; while (NULL != pos) - { - msize += sizeof (struct MetaDataEntry); - msize += pos->data_size; - if (pos->plugin_name != NULL) - msize += strlen (pos->plugin_name) + 1; - if (pos->mime_type != NULL) - msize += strlen (pos->mime_type) + 1; - pos = pos->next; - } + { + msize += sizeof (struct MetaDataEntry); + msize += pos->data_size; + if (pos->plugin_name != NULL) + msize += strlen (pos->plugin_name) + 1; + if (pos->mime_type != NULL) + msize += strlen (pos->mime_type) + 1; + pos = pos->next; + } size = (size_t) msize; if (size != msize) - { - GNUNET_break (0); /* integer overflow */ - return GNUNET_SYSERR; - } + { + GNUNET_break (0); /* integer overflow */ + return GNUNET_SYSERR; + } if (size >= GNUNET_MAX_MALLOC_CHECKED) - { - /* too large to be processed */ - return GNUNET_SYSERR; - } + { + /* too large to be processed */ + return GNUNET_SYSERR; + } ent = GNUNET_malloc (size); mdata = (char *) &ent[md->item_count]; off = size - (md->item_count * sizeof (struct MetaDataEntry)); i = 0; pos = md->items; while (NULL != pos) - { - ent[i].type = htonl ((uint32_t) pos->type); - ent[i].format = htonl ((uint32_t) pos->format); - ent[i].data_size = htonl ((uint32_t) pos->data_size); - if (pos->plugin_name == NULL) - plen = 0; - else - plen = strlen (pos->plugin_name) + 1; - ent[i].plugin_name_len = htonl ((uint32_t) plen); - if (pos->mime_type == NULL) - mlen = 0; - else - mlen = strlen (pos->mime_type) + 1; - ent[i].mime_type_len = htonl ((uint32_t) mlen); - off -= pos->data_size; - memcpy (&mdata[off], pos->data, pos->data_size); - off -= plen; - if (pos->plugin_name != NULL) - memcpy (&mdata[off], pos->plugin_name, plen); - off -= mlen; - if (pos->mime_type != NULL) - memcpy (&mdata[off], pos->mime_type, mlen); - i++; - pos = pos->next; - } + { + ent[i].type = htonl ((uint32_t) pos->type); + ent[i].format = htonl ((uint32_t) pos->format); + ent[i].data_size = htonl ((uint32_t) pos->data_size); + if (pos->plugin_name == NULL) + plen = 0; + else + plen = strlen (pos->plugin_name) + 1; + ent[i].plugin_name_len = htonl ((uint32_t) plen); + if (pos->mime_type == NULL) + mlen = 0; + else + mlen = strlen (pos->mime_type) + 1; + ent[i].mime_type_len = htonl ((uint32_t) mlen); + off -= pos->data_size; + memcpy (&mdata[off], pos->data, pos->data_size); + off -= plen; + if (pos->plugin_name != NULL) + memcpy (&mdata[off], pos->plugin_name, plen); + off -= mlen; + if (pos->mime_type != NULL) + memcpy (&mdata[off], pos->mime_type, mlen); + i++; + pos = pos->next; + } GNUNET_assert (off == 0); clen = 0; @@ -862,95 +860,95 @@ GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData i = 0; pos = md->items; while (pos != NULL) + { + comp = GNUNET_NO; + if (0 == (opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS)) + comp = try_compression ((const char *) &ent[i], left, &cdata, &clen); + + if ((md->sbuf == NULL) && (i == 0)) + { + /* fill 'sbuf'; this "modifies" md, but since this is only + * an internal cache we will cast away the 'const' instead + * of making the API look strange. */ + vmd = (struct GNUNET_CONTAINER_MetaData *) md; + hdr = GNUNET_malloc (left + sizeof (struct MetaDataHeader)); + hdr->size = htonl (left); + hdr->entries = htonl (md->item_count); + if (GNUNET_YES == comp) + { + GNUNET_assert (clen < left); + hdr->version = htonl (2 | HEADER_COMPRESSED); + memcpy (&hdr[1], cdata, clen); + vmd->sbuf_size = clen + sizeof (struct MetaDataHeader); + } + else + { + hdr->version = htonl (2); + memcpy (&hdr[1], &ent[0], left); + vmd->sbuf_size = left + sizeof (struct MetaDataHeader); + } + vmd->sbuf = (char *) hdr; + } + + if (((left + sizeof (struct MetaDataHeader)) <= max) || + ((comp == GNUNET_YES) && (clen <= max))) + { + /* success, this now fits! */ + if (GNUNET_YES == comp) + { + if (dst == NULL) + dst = GNUNET_malloc (clen + sizeof (struct MetaDataHeader)); + hdr = (struct MetaDataHeader *) dst; + hdr->version = htonl (2 | HEADER_COMPRESSED); + hdr->size = htonl (left); + hdr->entries = htonl (md->item_count - i); + memcpy (&dst[sizeof (struct MetaDataHeader)], cdata, clen); + GNUNET_free (cdata); + GNUNET_free (ent); + rlen = clen + sizeof (struct MetaDataHeader); + } + else + { + if (dst == NULL) + dst = GNUNET_malloc (left + sizeof (struct MetaDataHeader)); + hdr = (struct MetaDataHeader *) dst; + hdr->version = htonl (2); + hdr->entries = htonl (md->item_count - i); + hdr->size = htonl (left); + memcpy (&dst[sizeof (struct MetaDataHeader)], &ent[i], left); + GNUNET_free (ent); + rlen = left + sizeof (struct MetaDataHeader); + } + if (NULL != *target) + { + memcpy (*target, dst, clen + sizeof (struct MetaDataHeader)); + GNUNET_free (dst); + } + else + { + *target = dst; + } + return rlen; + } + + if (0 == (opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_PART)) { - comp = GNUNET_NO; - if (0 == (opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS)) - comp = try_compression ((const char *) &ent[i], left, &cdata, &clen); - - if ((md->sbuf == NULL) && (i == 0)) - { - /* fill 'sbuf'; this "modifies" md, but since this is only - * an internal cache we will cast away the 'const' instead - * of making the API look strange. */ - vmd = (struct GNUNET_CONTAINER_MetaData *) md; - hdr = GNUNET_malloc (left + sizeof (struct MetaDataHeader)); - hdr->size = htonl (left); - hdr->entries = htonl (md->item_count); - if (GNUNET_YES == comp) - { - GNUNET_assert (clen < left); - hdr->version = htonl (2 | HEADER_COMPRESSED); - memcpy (&hdr[1], cdata, clen); - vmd->sbuf_size = clen + sizeof (struct MetaDataHeader); - } - else - { - hdr->version = htonl (2); - memcpy (&hdr[1], &ent[0], left); - vmd->sbuf_size = left + sizeof (struct MetaDataHeader); - } - vmd->sbuf = (char *) hdr; - } - - if (((left + sizeof (struct MetaDataHeader)) <= max) || - ((comp == GNUNET_YES) && (clen <= max))) - { - /* success, this now fits! */ - if (GNUNET_YES == comp) - { - if (dst == NULL) - dst = GNUNET_malloc (clen + sizeof (struct MetaDataHeader)); - hdr = (struct MetaDataHeader *) dst; - hdr->version = htonl (2 | HEADER_COMPRESSED); - hdr->size = htonl (left); - hdr->entries = htonl (md->item_count - i); - memcpy (&dst[sizeof (struct MetaDataHeader)], cdata, clen); - GNUNET_free (cdata); - GNUNET_free (ent); - rlen = clen + sizeof (struct MetaDataHeader); - } - else - { - if (dst == NULL) - dst = GNUNET_malloc (left + sizeof (struct MetaDataHeader)); - hdr = (struct MetaDataHeader *) dst; - hdr->version = htonl (2); - hdr->entries = htonl (md->item_count - i); - hdr->size = htonl (left); - memcpy (&dst[sizeof (struct MetaDataHeader)], &ent[i], left); - GNUNET_free (ent); - rlen = left + sizeof (struct MetaDataHeader); - } - if (NULL != *target) - { - memcpy (*target, dst, clen + sizeof (struct MetaDataHeader)); - GNUNET_free (dst); - } - else - { - *target = dst; - } - return rlen; - } - - if (0 == (opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_PART)) - { - /* does not fit! */ - GNUNET_free (ent); - return GNUNET_SYSERR; - } - - /* next iteration: ignore the corresponding meta data at the - * end and try again without it */ - left -= sizeof (struct MetaDataEntry); - left -= pos->data_size; - if (pos->plugin_name != NULL) - left -= strlen (pos->plugin_name) + 1; - if (pos->mime_type != NULL) - left -= strlen (pos->mime_type) + 1; - pos = pos->next; - i++; + /* does not fit! */ + GNUNET_free (ent); + return GNUNET_SYSERR; } + + /* next iteration: ignore the corresponding meta data at the + * end and try again without it */ + left -= sizeof (struct MetaDataEntry); + left -= pos->data_size; + if (pos->plugin_name != NULL) + left -= strlen (pos->plugin_name) + 1; + if (pos->mime_type != NULL) + left -= strlen (pos->mime_type) + 1; + pos = pos->next; + i++; + } GNUNET_free (ent); /* nothing fit, only write header! */ @@ -972,7 +970,7 @@ GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData */ ssize_t GNUNET_CONTAINER_meta_data_get_serialized_size (const struct - GNUNET_CONTAINER_MetaData *md) + GNUNET_CONTAINER_MetaData *md) { ssize_t ret; char *ptr; @@ -981,8 +979,8 @@ GNUNET_CONTAINER_meta_data_get_serialized_size (const struct return md->sbuf_size; ptr = NULL; ret = - GNUNET_CONTAINER_meta_data_serialize (md, &ptr, GNUNET_MAX_MALLOC_CHECKED, - GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL); + GNUNET_CONTAINER_meta_data_serialize (md, &ptr, GNUNET_MAX_MALLOC_CHECKED, + GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL); if (ret != -1) GNUNET_free (ptr); return ret; @@ -1009,14 +1007,14 @@ decompress (const char *input, size_t inputSize, size_t outputSize) output = GNUNET_malloc (olen); if (Z_OK == uncompress ((Bytef *) output, &olen, (const Bytef *) input, inputSize)) - { - return output; - } + { + return output; + } else - { - GNUNET_free (output); - return NULL; - } + { + GNUNET_free (output); + return NULL; + } } @@ -1058,121 +1056,121 @@ GNUNET_CONTAINER_meta_data_deserialize (const char *input, size_t size) compressed = (ntohl (hdr.version) & HEADER_COMPRESSED) != 0; if (version == 1) - return NULL; /* null pointer */ + return NULL; /* null pointer */ if (version != 2) - { - GNUNET_break_op (0); /* unsupported version */ - return NULL; - } + { + GNUNET_break_op (0); /* unsupported version */ + return NULL; + } ic = ntohl (hdr.entries); dataSize = ntohl (hdr.size); if ((sizeof (struct MetaDataEntry) * ic) > dataSize) + { + GNUNET_break_op (0); + return NULL; + } + + if (compressed) + { + if (dataSize >= GNUNET_MAX_MALLOC_CHECKED) { + /* make sure we don't blow our memory limit because of a mal-formed + * message... */ GNUNET_break_op (0); return NULL; } - - if (compressed) + data = + decompress ((const char *) &input[sizeof (struct MetaDataHeader)], + size - sizeof (struct MetaDataHeader), dataSize); + if (data == NULL) { - if (dataSize >= GNUNET_MAX_MALLOC_CHECKED) - { - /* make sure we don't blow our memory limit because of a mal-formed - * message... */ - GNUNET_break_op (0); - return NULL; - } - data = - decompress ((const char *) &input[sizeof (struct MetaDataHeader)], - size - sizeof (struct MetaDataHeader), dataSize); - if (data == NULL) - { - GNUNET_break_op (0); - return NULL; - } - cdata = data; + GNUNET_break_op (0); + return NULL; } + cdata = data; + } else + { + data = NULL; + cdata = (const char *) &input[sizeof (struct MetaDataHeader)]; + if (dataSize != size - sizeof (struct MetaDataHeader)) { - data = NULL; - cdata = (const char *) &input[sizeof (struct MetaDataHeader)]; - if (dataSize != size - sizeof (struct MetaDataHeader)) - { - GNUNET_break_op (0); - return NULL; - } + GNUNET_break_op (0); + return NULL; } + } md = GNUNET_CONTAINER_meta_data_create (); left = dataSize - ic * sizeof (struct MetaDataEntry); mdata = &cdata[ic * sizeof (struct MetaDataEntry)]; for (i = 0; i < ic; i++) + { + memcpy (&ent, &cdata[i * sizeof (struct MetaDataEntry)], + sizeof (struct MetaDataEntry)); + format = (enum EXTRACTOR_MetaFormat) ntohl (ent.format); + if ((format != EXTRACTOR_METAFORMAT_UTF8) && + (format != EXTRACTOR_METAFORMAT_C_STRING) && + (format != EXTRACTOR_METAFORMAT_BINARY)) { - memcpy (&ent, &cdata[i * sizeof (struct MetaDataEntry)], - sizeof (struct MetaDataEntry)); - format = (enum EXTRACTOR_MetaFormat) ntohl (ent.format); - if ((format != EXTRACTOR_METAFORMAT_UTF8) && - (format != EXTRACTOR_METAFORMAT_C_STRING) && - (format != EXTRACTOR_METAFORMAT_BINARY)) - { - GNUNET_break_op (0); - break; - } - dlen = ntohl (ent.data_size); - plen = ntohl (ent.plugin_name_len); - mlen = ntohl (ent.mime_type_len); - if (dlen > left) - { - GNUNET_break_op (0); - break; - } - left -= dlen; - meta_data = &mdata[left]; - if ((format == EXTRACTOR_METAFORMAT_UTF8) || - (format == EXTRACTOR_METAFORMAT_C_STRING)) - { - if ((dlen == 0) || (mdata[left + dlen - 1] != '\0')) - { - GNUNET_break_op (0); - break; - } - } - if (plen > left) - { - GNUNET_break_op (0); - break; - } - left -= plen; - if ((plen > 0) && (mdata[left + plen - 1] != '\0')) - { - GNUNET_break_op (0); - break; - } - if (plen == 0) - plugin_name = NULL; - else - plugin_name = &mdata[left]; - - if (mlen > left) - { - GNUNET_break_op (0); - break; - } - left -= mlen; - if ((mlen > 0) && (mdata[left + mlen - 1] != '\0')) - { - GNUNET_break_op (0); - break; - } - if (mlen == 0) - mime_type = NULL; - else - mime_type = &mdata[left]; - GNUNET_CONTAINER_meta_data_insert (md, plugin_name, - (enum EXTRACTOR_MetaType) - ntohl (ent.type), format, mime_type, - meta_data, dlen); + GNUNET_break_op (0); + break; + } + dlen = ntohl (ent.data_size); + plen = ntohl (ent.plugin_name_len); + mlen = ntohl (ent.mime_type_len); + if (dlen > left) + { + GNUNET_break_op (0); + break; + } + left -= dlen; + meta_data = &mdata[left]; + if ((format == EXTRACTOR_METAFORMAT_UTF8) || + (format == EXTRACTOR_METAFORMAT_C_STRING)) + { + if ((dlen == 0) || (mdata[left + dlen - 1] != '\0')) + { + GNUNET_break_op (0); + break; + } + } + if (plen > left) + { + GNUNET_break_op (0); + break; + } + left -= plen; + if ((plen > 0) && (mdata[left + plen - 1] != '\0')) + { + GNUNET_break_op (0); + break; + } + if (plen == 0) + plugin_name = NULL; + else + plugin_name = &mdata[left]; + + if (mlen > left) + { + GNUNET_break_op (0); + break; + } + left -= mlen; + if ((mlen > 0) && (mdata[left + mlen - 1] != '\0')) + { + GNUNET_break_op (0); + break; } + if (mlen == 0) + mime_type = NULL; + else + mime_type = &mdata[left]; + GNUNET_CONTAINER_meta_data_insert (md, plugin_name, + (enum EXTRACTOR_MetaType) + ntohl (ent.type), format, mime_type, + meta_data, dlen); + } GNUNET_free_non_null (data); return md; } diff --git a/src/util/container_multihashmap.c b/src/util/container_multihashmap.c index 60d4a43d5..7e53a6440 100644 --- a/src/util/container_multihashmap.c +++ b/src/util/container_multihashmap.c @@ -103,19 +103,19 @@ GNUNET_CONTAINER_multihashmap_create (unsigned int len) */ void GNUNET_CONTAINER_multihashmap_destroy (struct GNUNET_CONTAINER_MultiHashMap - *map) + *map) { unsigned int i; struct MapEntry *e; for (i = 0; i < map->map_length; i++) + { + while (NULL != (e = map->map[i])) { - while (NULL != (e = map->map[i])) - { - map->map[i] = e->next; - GNUNET_free (e); - } + map->map[i] = e->next; + GNUNET_free (e); } + } GNUNET_free (map->map); GNUNET_free (map); } @@ -130,7 +130,7 @@ GNUNET_CONTAINER_multihashmap_destroy (struct GNUNET_CONTAINER_MultiHashMap */ static unsigned int idx_of (const struct GNUNET_CONTAINER_MultiHashMap *m, - const GNUNET_HashCode * key) + const GNUNET_HashCode * key) { GNUNET_assert (m != NULL); return (*(unsigned int *) key) % m->map_length; @@ -145,7 +145,7 @@ idx_of (const struct GNUNET_CONTAINER_MultiHashMap *m, */ unsigned int GNUNET_CONTAINER_multihashmap_size (const struct GNUNET_CONTAINER_MultiHashMap - *map) + *map) { return map->size; } @@ -163,17 +163,17 @@ GNUNET_CONTAINER_multihashmap_size (const struct GNUNET_CONTAINER_MultiHashMap */ void * GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap - *map, const GNUNET_HashCode * key) + *map, const GNUNET_HashCode * key) { struct MapEntry *e; e = map->map[idx_of (map, key)]; while (e != NULL) - { - if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) - return e->value; - e = e->next; - } + { + if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) + return e->value; + e = e->next; + } return NULL; } @@ -189,9 +189,9 @@ GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap */ int GNUNET_CONTAINER_multihashmap_iterate (const struct - GNUNET_CONTAINER_MultiHashMap *map, - GNUNET_CONTAINER_HashMapIterator it, - void *it_cls) + GNUNET_CONTAINER_MultiHashMap *map, + GNUNET_CONTAINER_HashMapIterator it, + void *it_cls) { int count; unsigned int i; @@ -202,20 +202,20 @@ GNUNET_CONTAINER_multihashmap_iterate (const struct count = 0; GNUNET_assert (map != NULL); for (i = 0; i < map->map_length; i++) + { + n = map->map[i]; + while (NULL != (e = n)) { - n = map->map[i]; - while (NULL != (e = n)) - { - n = e->next; - if (NULL != it) - { - kc = e->key; - if (GNUNET_OK != it (it_cls, &kc, e->value)) - return GNUNET_SYSERR; - } - count++; - } + n = e->next; + if (NULL != it) + { + kc = e->key; + if (GNUNET_OK != it (it_cls, &kc, e->value)) + return GNUNET_SYSERR; + } + count++; } + } return count; } @@ -232,9 +232,8 @@ GNUNET_CONTAINER_multihashmap_iterate (const struct * is not in the map */ int -GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap - *map, const GNUNET_HashCode * key, - void *value) +GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map, + const GNUNET_HashCode * key, void *value) { struct MapEntry *e; struct MapEntry *p; @@ -244,21 +243,21 @@ GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap p = NULL; e = map->map[i]; while (e != NULL) + { + if ((0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) && + (value == e->value)) { - if ((0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) && - (value == e->value)) - { - if (p == NULL) - map->map[i] = e->next; - else - p->next = e->next; - GNUNET_free (e); - map->size--; - return GNUNET_YES; - } - p = e; - e = e->next; + if (p == NULL) + map->map[i] = e->next; + else + p->next = e->next; + GNUNET_free (e); + map->size--; + return GNUNET_YES; } + p = e; + e = e->next; + } return GNUNET_NO; } @@ -273,7 +272,7 @@ GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap */ int GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap - *map, const GNUNET_HashCode * key) + *map, const GNUNET_HashCode * key) { struct MapEntry *e; struct MapEntry *p; @@ -285,27 +284,27 @@ GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap p = NULL; e = map->map[i]; while (e != NULL) + { + if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) { - if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) - { - if (p == NULL) - map->map[i] = e->next; - else - p->next = e->next; - GNUNET_free (e); - map->size--; - if (p == NULL) - e = map->map[i]; - else - e = p->next; - ret++; - } + if (p == NULL) + map->map[i] = e->next; else - { - p = e; - e = e->next; - } + p->next = e->next; + GNUNET_free (e); + map->size--; + if (p == NULL) + e = map->map[i]; + else + e = p->next; + ret++; + } + else + { + p = e; + e = e->next; } + } return ret; } @@ -321,18 +320,18 @@ GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap */ int GNUNET_CONTAINER_multihashmap_contains (const struct - GNUNET_CONTAINER_MultiHashMap *map, - const GNUNET_HashCode * key) + GNUNET_CONTAINER_MultiHashMap *map, + const GNUNET_HashCode * key) { struct MapEntry *e; e = map->map[idx_of (map, key)]; while (e != NULL) - { - if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) - return GNUNET_YES; - e = e->next; - } + { + if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) + return GNUNET_YES; + e = e->next; + } return GNUNET_NO; } @@ -349,21 +348,20 @@ GNUNET_CONTAINER_multihashmap_contains (const struct */ int GNUNET_CONTAINER_multihashmap_contains_value (const struct - GNUNET_CONTAINER_MultiHashMap - *map, - const GNUNET_HashCode * key, - const void *value) + GNUNET_CONTAINER_MultiHashMap + *map, const GNUNET_HashCode * key, + const void *value) { struct MapEntry *e; e = map->map[idx_of (map, key)]; while (e != NULL) - { - if ((0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) && - (e->value == value)) - return GNUNET_YES; - e = e->next; - } + { + if ((0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) && + (e->value == value)) + return GNUNET_YES; + e = e->next; + } return GNUNET_NO; } @@ -391,15 +389,15 @@ grow (struct GNUNET_CONTAINER_MultiHashMap *map) map->map_length = new_len; map->map = new_map; for (i = 0; i < old_len; i++) + { + while (NULL != (e = old_map[i])) { - while (NULL != (e = old_map[i])) - { - old_map[i] = e->next; - idx = idx_of (map, &e->key); - e->next = new_map[idx]; - new_map[idx] = e; - } + old_map[i] = e->next; + idx = idx_of (map, &e->key); + e->next = new_map[idx]; + new_map[idx] = e; } + } GNUNET_free (old_map); } @@ -418,9 +416,8 @@ grow (struct GNUNET_CONTAINER_MultiHashMap *map) */ int GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map, - const GNUNET_HashCode * key, void *value, - enum GNUNET_CONTAINER_MultiHashMapOption - opt) + const GNUNET_HashCode * key, void *value, + enum GNUNET_CONTAINER_MultiHashMapOption opt) { struct MapEntry *e; unsigned int i; @@ -428,25 +425,25 @@ GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map, i = idx_of (map, key); if ((opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE) && (opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) + { + e = map->map[i]; + while (e != NULL) { - e = map->map[i]; - while (e != NULL) - { - if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) - { - if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) - return GNUNET_SYSERR; - e->value = value; - return GNUNET_NO; - } - e = e->next; - } + if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) + { + if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) + return GNUNET_SYSERR; + e->value = value; + return GNUNET_NO; + } + e = e->next; } + } if (map->size / 3 >= map->map_length / 4) - { - grow (map); - i = idx_of (map, key); - } + { + grow (map); + i = idx_of (map, key); + } e = GNUNET_malloc (sizeof (struct MapEntry)); e->key = *key; e->value = value; @@ -469,10 +466,10 @@ GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map, */ int GNUNET_CONTAINER_multihashmap_get_multiple (const struct - GNUNET_CONTAINER_MultiHashMap - *map, const GNUNET_HashCode * key, - GNUNET_CONTAINER_HashMapIterator - it, void *it_cls) + GNUNET_CONTAINER_MultiHashMap *map, + const GNUNET_HashCode * key, + GNUNET_CONTAINER_HashMapIterator it, + void *it_cls) { int count; struct MapEntry *e; @@ -481,14 +478,14 @@ GNUNET_CONTAINER_multihashmap_get_multiple (const struct count = 0; n = map->map[idx_of (map, key)]; while (NULL != (e = n)) - { - n = e->next; - if (0 != memcmp (key, &e->key, sizeof (GNUNET_HashCode))) - continue; - if ((it != NULL) && (GNUNET_OK != it (it_cls, key, e->value))) - return GNUNET_SYSERR; - count++; - } + { + n = e->next; + if (0 != memcmp (key, &e->key, sizeof (GNUNET_HashCode))) + continue; + if ((it != NULL) && (GNUNET_OK != it (it_cls, key, e->value))) + return GNUNET_SYSERR; + count++; + } return count; } diff --git a/src/util/container_slist.c b/src/util/container_slist.c index 2704713d4..7b85dc877 100644 --- a/src/util/container_slist.c +++ b/src/util/container_slist.c @@ -89,21 +89,21 @@ struct GNUNET_CONTAINER_SList */ static struct GNUNET_CONTAINER_SList_Elem * create_elem (enum GNUNET_CONTAINER_SListDisposition disp, const void *buf, - size_t len) + size_t len) { struct GNUNET_CONTAINER_SList_Elem *e; if (disp == GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT) - { - e = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_SList_Elem) + len); - memcpy (&e[1], buf, len); - e->elem = (void *) &e[1]; - } + { + e = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_SList_Elem) + len); + memcpy (&e[1], buf, len); + e->elem = (void *) &e[1]; + } else - { - e = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_SList_Elem)); - e->elem = (void *) buf; - } + { + e = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_SList_Elem)); + e->elem = (void *) buf; + } e->disp = disp; e->len = len; return e; @@ -119,8 +119,8 @@ create_elem (enum GNUNET_CONTAINER_SListDisposition disp, const void *buf, */ void GNUNET_CONTAINER_slist_add (struct GNUNET_CONTAINER_SList *l, - enum GNUNET_CONTAINER_SListDisposition disp, - const void *buf, size_t len) + enum GNUNET_CONTAINER_SListDisposition disp, + const void *buf, size_t len) { struct GNUNET_CONTAINER_SList_Elem *e; @@ -141,8 +141,8 @@ GNUNET_CONTAINER_slist_add (struct GNUNET_CONTAINER_SList *l, */ void GNUNET_CONTAINER_slist_add_end (struct GNUNET_CONTAINER_SList *l, - enum GNUNET_CONTAINER_SListDisposition disp, - const void *buf, size_t len) + enum GNUNET_CONTAINER_SListDisposition disp, + const void *buf, size_t len) { struct GNUNET_CONTAINER_SList_Elem *e; @@ -163,7 +163,7 @@ GNUNET_CONTAINER_slist_add_end (struct GNUNET_CONTAINER_SList *l, */ void GNUNET_CONTAINER_slist_append (struct GNUNET_CONTAINER_SList *dst, - struct GNUNET_CONTAINER_SList *src) + struct GNUNET_CONTAINER_SList *src) { struct GNUNET_CONTAINER_SList_Iterator i; @@ -171,15 +171,14 @@ GNUNET_CONTAINER_slist_append (struct GNUNET_CONTAINER_SList *dst, GNUNET_CONTAINER_slist_end (&i) != GNUNET_YES; GNUNET_CONTAINER_slist_next (&i)) - { - GNUNET_CONTAINER_slist_add (dst, - (i.elem->disp == - GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC) - ? GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC - : - GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, - i.elem->elem, i.elem->len); - } + { + GNUNET_CONTAINER_slist_add (dst, + (i.elem->disp == + GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC) ? + GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC : + GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, + i.elem->elem, i.elem->len); + } GNUNET_CONTAINER_slist_iter_destroy (&i); } @@ -236,13 +235,13 @@ GNUNET_CONTAINER_slist_clear (struct GNUNET_CONTAINER_SList *l) e = l->head; while (e != NULL) - { - n = e->next; - if (e->disp == GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC) - GNUNET_free (e->elem); - GNUNET_free (e); - e = n; - } + { + n = e->next; + if (e->disp == GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC) + GNUNET_free (e->elem); + GNUNET_free (e); + e = n; + } l->head = NULL; l->tail = NULL; l->length = 0; @@ -258,7 +257,7 @@ GNUNET_CONTAINER_slist_clear (struct GNUNET_CONTAINER_SList *l) */ int GNUNET_CONTAINER_slist_contains (const struct GNUNET_CONTAINER_SList *l, - const void *buf, size_t len) + const void *buf, size_t len) { struct GNUNET_CONTAINER_SList_Elem *e; @@ -315,8 +314,8 @@ GNUNET_CONTAINER_slist_erase (struct GNUNET_CONTAINER_SList_Iterator *i) */ void GNUNET_CONTAINER_slist_insert (struct GNUNET_CONTAINER_SList_Iterator *before, - enum GNUNET_CONTAINER_SListDisposition disp, - const void *buf, size_t len) + enum GNUNET_CONTAINER_SListDisposition disp, + const void *buf, size_t len) { struct GNUNET_CONTAINER_SList_Elem *e; @@ -369,7 +368,7 @@ GNUNET_CONTAINER_slist_end (struct GNUNET_CONTAINER_SList_Iterator *i) */ void * GNUNET_CONTAINER_slist_get (const struct GNUNET_CONTAINER_SList_Iterator *i, - size_t * len) + size_t * len) { if (len) *len = i->elem->len; @@ -381,8 +380,7 @@ GNUNET_CONTAINER_slist_get (const struct GNUNET_CONTAINER_SList_Iterator *i, * @param i iterator */ void -GNUNET_CONTAINER_slist_iter_destroy (struct GNUNET_CONTAINER_SList_Iterator - *i) +GNUNET_CONTAINER_slist_iter_destroy (struct GNUNET_CONTAINER_SList_Iterator *i) { } diff --git a/src/util/crypto_aes.c b/src/util/crypto_aes.c index 9e194094c..8b031f367 100644 --- a/src/util/crypto_aes.c +++ b/src/util/crypto_aes.c @@ -39,9 +39,9 @@ void GNUNET_CRYPTO_aes_create_session_key (struct GNUNET_CRYPTO_AesSessionKey *key) { gcry_randomize (&key->key[0], GNUNET_CRYPTO_AES_KEY_LENGTH, - GCRY_STRONG_RANDOM); + GCRY_STRONG_RANDOM); key->crc32 = - htonl (GNUNET_CRYPTO_crc32_n (key, GNUNET_CRYPTO_AES_KEY_LENGTH)); + htonl (GNUNET_CRYPTO_crc32_n (key, GNUNET_CRYPTO_AES_KEY_LENGTH)); } /** @@ -51,7 +51,7 @@ GNUNET_CRYPTO_aes_create_session_key (struct GNUNET_CRYPTO_AesSessionKey *key) */ int GNUNET_CRYPTO_aes_check_session_key (const struct GNUNET_CRYPTO_AesSessionKey - *key) + *key) { uint32_t crc; @@ -76,29 +76,28 @@ GNUNET_CRYPTO_aes_check_session_key (const struct GNUNET_CRYPTO_AesSessionKey */ ssize_t GNUNET_CRYPTO_aes_encrypt (const void *block, size_t len, - const struct GNUNET_CRYPTO_AesSessionKey * - sessionkey, - const struct GNUNET_CRYPTO_AesInitializationVector - * iv, void *result) + const struct GNUNET_CRYPTO_AesSessionKey * + sessionkey, + const struct GNUNET_CRYPTO_AesInitializationVector * + iv, void *result) { gcry_cipher_hd_t handle; int rc; if (sessionkey->crc32 != - htonl (GNUNET_CRYPTO_crc32_n - (sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH))) - { - GNUNET_break (0); - return -1; - } + htonl (GNUNET_CRYPTO_crc32_n (sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH))) + { + GNUNET_break (0); + return -1; + } GNUNET_assert (0 == - gcry_cipher_open (&handle, GCRY_CIPHER_AES256, - GCRY_CIPHER_MODE_CFB, 0)); + gcry_cipher_open (&handle, GCRY_CIPHER_AES256, + GCRY_CIPHER_MODE_CFB, 0)); rc = gcry_cipher_setkey (handle, sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH); GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); rc = gcry_cipher_setiv (handle, iv, - sizeof (struct - GNUNET_CRYPTO_AesInitializationVector)); + sizeof (struct + GNUNET_CRYPTO_AesInitializationVector)); GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); GNUNET_assert (0 == gcry_cipher_encrypt (handle, result, len, block, len)); gcry_cipher_close (handle); @@ -118,32 +117,30 @@ GNUNET_CRYPTO_aes_encrypt (const void *block, size_t len, */ ssize_t GNUNET_CRYPTO_aes_decrypt (const void *block, size_t size, - const struct GNUNET_CRYPTO_AesSessionKey * - sessionkey, - const struct GNUNET_CRYPTO_AesInitializationVector - * iv, void *result) + const struct GNUNET_CRYPTO_AesSessionKey * + sessionkey, + const struct GNUNET_CRYPTO_AesInitializationVector * + iv, void *result) { gcry_cipher_hd_t handle; int rc; if (sessionkey->crc32 != - htonl (GNUNET_CRYPTO_crc32_n - (sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH))) - { - GNUNET_break (0); - return -1; - } + htonl (GNUNET_CRYPTO_crc32_n (sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH))) + { + GNUNET_break (0); + return -1; + } GNUNET_assert (0 == - gcry_cipher_open (&handle, GCRY_CIPHER_AES256, - GCRY_CIPHER_MODE_CFB, 0)); + gcry_cipher_open (&handle, GCRY_CIPHER_AES256, + GCRY_CIPHER_MODE_CFB, 0)); rc = gcry_cipher_setkey (handle, sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH); GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); rc = gcry_cipher_setiv (handle, iv, - sizeof (struct - GNUNET_CRYPTO_AesInitializationVector)); + sizeof (struct + GNUNET_CRYPTO_AesInitializationVector)); GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); - GNUNET_assert (0 == - gcry_cipher_decrypt (handle, result, size, block, size)); + GNUNET_assert (0 == gcry_cipher_decrypt (handle, result, size, block, size)); gcry_cipher_close (handle); return size; } @@ -158,8 +155,8 @@ GNUNET_CRYPTO_aes_decrypt (const void *block, size_t size, */ void GNUNET_CRYPTO_aes_derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv, - const struct GNUNET_CRYPTO_AesSessionKey *skey, - const void *salt, size_t salt_len, ...) + const struct GNUNET_CRYPTO_AesSessionKey *skey, + const void *salt, size_t salt_len, ...) { va_list argp; @@ -177,14 +174,12 @@ GNUNET_CRYPTO_aes_derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv, * @param argp pairs of void * & size_t for context chunks, terminated by NULL */ void -GNUNET_CRYPTO_aes_derive_iv_v (struct GNUNET_CRYPTO_AesInitializationVector - *iv, - const struct GNUNET_CRYPTO_AesSessionKey *skey, - const void *salt, size_t salt_len, - va_list argp) +GNUNET_CRYPTO_aes_derive_iv_v (struct GNUNET_CRYPTO_AesInitializationVector *iv, + const struct GNUNET_CRYPTO_AesSessionKey *skey, + const void *salt, size_t salt_len, va_list argp) { GNUNET_CRYPTO_kdf_v (iv->iv, sizeof (iv->iv), salt, salt_len, skey->key, - sizeof (skey->key), argp); + sizeof (skey->key), argp); } /* end of crypto_aes.c */ diff --git a/src/util/crypto_crc.c b/src/util/crypto_crc.c index 5920ddc93..698d8d450 100644 --- a/src/util/crypto_crc.c +++ b/src/util/crypto_crc.c @@ -66,12 +66,12 @@ crc_init () once = 1; crc_table[0] = 0; for (i = 128; i; i >>= 1) - { - h = (h >> 1) ^ ((h & 1) ? POLYNOMIAL : 0); - /* h is now crc_table[i] */ - for (j = 0; j < 256; j += 2 * i) - crc_table[i + j] = crc_table[j] ^ h; - } + { + h = (h >> 1) ^ ((h & 1) ? POLYNOMIAL : 0); + /* h is now crc_table[i] */ + for (j = 0; j < 256; j += 2 * i) + crc_table[i + j] = crc_table[j] ^ h; + } } /* diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c index b8c9a8082..2ab682494 100644 --- a/src/util/crypto_hash.c +++ b/src/util/crypto_hash.c @@ -119,14 +119,14 @@ struct GNUNET_CRYPTO_FileHashContext */ static void file_hash_finish (struct GNUNET_CRYPTO_FileHashContext *fhc, - const GNUNET_HashCode * res) + const GNUNET_HashCode * res) { fhc->callback (fhc->callback_cls, res); GNUNET_free (fhc->filename); if (!GNUNET_DISK_handle_invalid (fhc->fh)) GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fhc->fh)); gcry_md_close (fhc->md); - GNUNET_free (fhc); /* also frees fhc->buffer */ + GNUNET_free (fhc); /* also frees fhc->buffer */ } @@ -149,19 +149,19 @@ file_hash_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) if (fhc->fsize - fhc->offset < delta) delta = fhc->fsize - fhc->offset; if (delta != GNUNET_DISK_file_read (fhc->fh, fhc->buffer, delta)) - { - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "read", fhc->filename); - file_hash_finish (fhc, NULL); - return; - } + { + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "read", fhc->filename); + file_hash_finish (fhc, NULL); + return; + } gcry_md_write (fhc->md, fhc->buffer, delta); fhc->offset += delta; if (fhc->offset == fhc->fsize) - { - res = (GNUNET_HashCode *) gcry_md_read (fhc->md, GCRY_MD_SHA512); - file_hash_finish (fhc, res); - return; - } + { + res = (GNUNET_HashCode *) gcry_md_read (fhc->md, GCRY_MD_SHA512); + file_hash_finish (fhc, res); + return; + } fhc->task = GNUNET_SCHEDULER_add_now (&file_hash_task, fhc); } @@ -178,43 +178,43 @@ file_hash_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) */ struct GNUNET_CRYPTO_FileHashContext * GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority, - const char *filename, size_t blocksize, - GNUNET_CRYPTO_HashCompletedCallback callback, - void *callback_cls) + const char *filename, size_t blocksize, + GNUNET_CRYPTO_HashCompletedCallback callback, + void *callback_cls) { struct GNUNET_CRYPTO_FileHashContext *fhc; GNUNET_assert (blocksize > 0); fhc = - GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_FileHashContext) + blocksize); + GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_FileHashContext) + blocksize); fhc->callback = callback; fhc->callback_cls = callback_cls; fhc->buffer = (unsigned char *) &fhc[1]; fhc->filename = GNUNET_strdup (filename); if (GPG_ERR_NO_ERROR != gcry_md_open (&fhc->md, GCRY_MD_SHA512, 0)) - { - GNUNET_break (0); - GNUNET_free (fhc); - return NULL; - } + { + GNUNET_break (0); + GNUNET_free (fhc); + return NULL; + } fhc->bsize = blocksize; if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fhc->fsize, GNUNET_NO)) - { - GNUNET_free (fhc->filename); - GNUNET_free (fhc); - return NULL; - } + { + GNUNET_free (fhc->filename); + GNUNET_free (fhc); + return NULL; + } fhc->fh = - GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, - GNUNET_DISK_PERM_NONE); + GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, + GNUNET_DISK_PERM_NONE); if (!fhc->fh) - { - GNUNET_free (fhc->filename); - GNUNET_free (fhc); - return NULL; - } + { + GNUNET_free (fhc->filename); + GNUNET_free (fhc); + return NULL; + } fhc->task = - GNUNET_SCHEDULER_add_with_priority (priority, &file_hash_task, fhc); + GNUNET_SCHEDULER_add_with_priority (priority, &file_hash_task, fhc); return fhc; } @@ -260,7 +260,7 @@ getValue__ (unsigned char a) */ void GNUNET_CRYPTO_hash_to_enc (const GNUNET_HashCode * block, - struct GNUNET_CRYPTO_HashAsciiEncoded *result) + struct GNUNET_CRYPTO_HashAsciiEncoded *result) { /** * 32 characters for encoding (GNUNET_CRYPTO_hash => 32 characters) @@ -278,23 +278,22 @@ GNUNET_CRYPTO_hash_to_enc (const GNUNET_HashCode * block, rpos = 0; bits = 0; while ((rpos < sizeof (GNUNET_HashCode)) || (vbit > 0)) + { + if ((rpos < sizeof (GNUNET_HashCode)) && (vbit < 5)) + { + bits = (bits << 8) | ((unsigned char *) block)[rpos++]; /* eat 8 more bits */ + vbit += 8; + } + if (vbit < 5) { - if ((rpos < sizeof (GNUNET_HashCode)) && (vbit < 5)) - { - bits = (bits << 8) | ((unsigned char *) block)[rpos++]; /* eat 8 more bits */ - vbit += 8; - } - if (vbit < 5) - { - bits <<= (5 - vbit); /* zero-padding */ - GNUNET_assert (vbit == 2); /* padding by 3: 512+3 mod 5 == 0 */ - vbit = 5; - } - GNUNET_assert (wpos < - sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1); - result->encoding[wpos++] = encTable__[(bits >> (vbit - 5)) & 31]; - vbit -= 5; + bits <<= (5 - vbit); /* zero-padding */ + GNUNET_assert (vbit == 2); /* padding by 3: 512+3 mod 5 == 0 */ + vbit = 5; } + GNUNET_assert (wpos < sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1); + result->encoding[wpos++] = encTable__[(bits >> (vbit - 5)) & 31]; + vbit -= 5; + } GNUNET_assert (wpos == sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1); GNUNET_assert (vbit == 0); result->encoding[wpos] = '\0'; @@ -318,22 +317,22 @@ GNUNET_CRYPTO_hash_from_string (const char *enc, GNUNET_HashCode * result) if (strlen (enc) != sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1) return GNUNET_SYSERR; - vbit = 2; /* padding! */ + vbit = 2; /* padding! */ wpos = sizeof (GNUNET_HashCode); rpos = sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1; bits = getValue__ (enc[--rpos]) >> 3; while (wpos > 0) + { + GNUNET_assert (rpos > 0); + bits = (getValue__ (enc[--rpos]) << vbit) | bits; + vbit += 5; + if (vbit >= 8) { - GNUNET_assert (rpos > 0); - bits = (getValue__ (enc[--rpos]) << vbit) | bits; - vbit += 5; - if (vbit >= 8) - { - ((unsigned char *) result)[--wpos] = (unsigned char) bits; - bits >>= 8; - vbit -= 8; - } + ((unsigned char *) result)[--wpos] = (unsigned char) bits; + bits >>= 8; + vbit -= 8; } + } GNUNET_assert (rpos == 0); GNUNET_assert (vbit == 0); return GNUNET_OK; @@ -352,7 +351,7 @@ GNUNET_CRYPTO_hash_from_string (const char *enc, GNUNET_HashCode * result) */ unsigned int GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a, - const GNUNET_HashCode * b) + const GNUNET_HashCode * b) { unsigned int x1 = (a->bits[1] - b->bits[1]) >> 16; unsigned int x2 = (b->bits[1] - a->bits[1]) >> 16; @@ -362,7 +361,7 @@ GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a, void GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode, - GNUNET_HashCode * result) + GNUNET_HashCode * result) { int i; @@ -372,37 +371,33 @@ GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode, void GNUNET_CRYPTO_hash_difference (const GNUNET_HashCode * a, - const GNUNET_HashCode * b, - GNUNET_HashCode * result) + const GNUNET_HashCode * b, + GNUNET_HashCode * result) { int i; - for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; - i--) + for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--) result->bits[i] = b->bits[i] - a->bits[i]; } void GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a, - const GNUNET_HashCode * delta, - GNUNET_HashCode * result) + const GNUNET_HashCode * delta, GNUNET_HashCode * result) { int i; - for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; - i--) + for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--) result->bits[i] = delta->bits[i] + a->bits[i]; } void GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, const GNUNET_HashCode * b, - GNUNET_HashCode * result) + GNUNET_HashCode * result) { int i; - for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; - i--) + for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--) result->bits[i] = a->bits[i] ^ b->bits[i]; } @@ -412,18 +407,17 @@ GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, const GNUNET_HashCode * b, */ void GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc, - struct GNUNET_CRYPTO_AesSessionKey *skey, - struct GNUNET_CRYPTO_AesInitializationVector - *iv) + struct GNUNET_CRYPTO_AesSessionKey *skey, + struct GNUNET_CRYPTO_AesInitializationVector *iv) { GNUNET_assert (sizeof (GNUNET_HashCode) >= - GNUNET_CRYPTO_AES_KEY_LENGTH + - sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); + GNUNET_CRYPTO_AES_KEY_LENGTH + + sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); memcpy (skey, hc, GNUNET_CRYPTO_AES_KEY_LENGTH); skey->crc32 = - htonl (GNUNET_CRYPTO_crc32_n (skey, GNUNET_CRYPTO_AES_KEY_LENGTH)); + htonl (GNUNET_CRYPTO_crc32_n (skey, GNUNET_CRYPTO_AES_KEY_LENGTH)); memcpy (iv, &((char *) hc)[GNUNET_CRYPTO_AES_KEY_LENGTH], - sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); + sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); } @@ -454,13 +448,13 @@ GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code, unsigned int bit) */ unsigned int GNUNET_CRYPTO_hash_matching_bits (const GNUNET_HashCode * first, - const GNUNET_HashCode * second) + const GNUNET_HashCode * second) { unsigned int i; for (i = 0; i < sizeof (GNUNET_HashCode) * 8; i++) if (GNUNET_CRYPTO_hash_get_bit (first, i) != - GNUNET_CRYPTO_hash_get_bit (second, i)) + GNUNET_CRYPTO_hash_get_bit (second, i)) return i; return sizeof (GNUNET_HashCode) * 8; } @@ -472,8 +466,7 @@ GNUNET_CRYPTO_hash_matching_bits (const GNUNET_HashCode * first, * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2. */ int -GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, - const GNUNET_HashCode * h2) +GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, const GNUNET_HashCode * h2) { unsigned int *i1; unsigned int *i2; @@ -481,14 +474,13 @@ GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, i1 = (unsigned int *) h1; i2 = (unsigned int *) h2; - for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; - i--) - { - if (i1[i] > i2[i]) - return 1; - if (i1[i] < i2[i]) - return -1; - } + for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--) + { + if (i1[i] > i2[i]) + return 1; + if (i1[i] < i2[i]) + return -1; + } return 0; } @@ -500,22 +492,22 @@ GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, */ int GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1, - const GNUNET_HashCode * h2, - const GNUNET_HashCode * target) + const GNUNET_HashCode * h2, + const GNUNET_HashCode * target) { int i; unsigned int d1; unsigned int d2; for (i = sizeof (GNUNET_HashCode) / sizeof (unsigned int) - 1; i >= 0; i--) - { - d1 = ((unsigned int *) h1)[i] ^ ((unsigned int *) target)[i]; - d2 = ((unsigned int *) h2)[i] ^ ((unsigned int *) target)[i]; - if (d1 > d2) - return 1; - else if (d1 < d2) - return -1; - } + { + d1 = ((unsigned int *) h1)[i] ^ ((unsigned int *) target)[i]; + d2 = ((unsigned int *) h2)[i] ^ ((unsigned int *) target)[i]; + if (d1 > d2) + return 1; + else if (d1 < d2) + return -1; + } return 0; } @@ -530,8 +522,8 @@ GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1, */ void GNUNET_CRYPTO_hmac_derive_key (struct GNUNET_CRYPTO_AuthKey *key, - const struct GNUNET_CRYPTO_AesSessionKey *rkey, - const void *salt, size_t salt_len, ...) + const struct GNUNET_CRYPTO_AesSessionKey *rkey, + const void *salt, size_t salt_len, ...) { va_list argp; @@ -551,12 +543,12 @@ GNUNET_CRYPTO_hmac_derive_key (struct GNUNET_CRYPTO_AuthKey *key, */ void GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key, - const struct GNUNET_CRYPTO_AesSessionKey - *rkey, const void *salt, size_t salt_len, - va_list argp) + const struct GNUNET_CRYPTO_AesSessionKey *rkey, + const void *salt, size_t salt_len, + va_list argp) { GNUNET_CRYPTO_kdf_v (key->key, sizeof (key->key), salt, salt_len, rkey->key, - sizeof (rkey->key), argp); + sizeof (rkey->key), argp); } @@ -570,14 +562,14 @@ GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key, */ void GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key, - const void *plaintext, size_t plaintext_len, - GNUNET_HashCode * hmac) + const void *plaintext, size_t plaintext_len, + GNUNET_HashCode * hmac) { gcry_md_hd_t md; const unsigned char *mc; GNUNET_assert (GPG_ERR_NO_ERROR == - gcry_md_open (&md, GCRY_MD_SHA512, GCRY_MD_FLAG_HMAC)); + gcry_md_open (&md, GCRY_MD_SHA512, GCRY_MD_FLAG_HMAC)); gcry_md_setkey (md, key->key, sizeof (key->key)); gcry_md_write (md, plaintext, plaintext_len); mc = gcry_md_read (md, GCRY_MD_SHA512); diff --git a/src/util/crypto_hkdf.c b/src/util/crypto_hkdf.c index 6af76ba68..40bfa6774 100644 --- a/src/util/crypto_hkdf.c +++ b/src/util/crypto_hkdf.c @@ -74,7 +74,7 @@ */ static const void * doHMAC (gcry_md_hd_t mac, const void *key, size_t key_len, const void *buf, - size_t buf_len) + size_t buf_len) { gcry_md_setkey (mac, key, key_len); gcry_md_write (mac, buf, buf_len); @@ -94,7 +94,7 @@ doHMAC (gcry_md_hd_t mac, const void *key, size_t key_len, const void *buf, */ static int getPRK (gcry_md_hd_t mac, const void *xts, size_t xts_len, const void *skm, - size_t skm_len, void *prk) + size_t skm_len, void *prk) { const void *ret; @@ -115,9 +115,9 @@ dump (const char *src, const void *p, unsigned int l) printf ("\n%s: ", src); for (i = 0; i < l; i++) - { - printf ("%2x", (int) ((const unsigned char *) p)[i]); - } + { + printf ("%2x", (int) ((const unsigned char *) p)[i]); + } printf ("\n"); } #endif @@ -137,9 +137,9 @@ dump (const char *src, const void *p, unsigned int l) * @return GNUNET_YES on success */ int -GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo, - int prf_algo, const void *xts, size_t xts_len, - const void *skm, size_t skm_len, va_list argp) +GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo, int prf_algo, + const void *xts, size_t xts_len, const void *skm, + size_t skm_len, va_list argp) { const void *hc; unsigned long i, t, d; @@ -158,16 +158,16 @@ GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo, return GNUNET_SYSERR; if (gcry_md_open (&prf, prf_algo, GCRY_MD_FLAG_HMAC) != GPG_ERR_NO_ERROR) - { - gcry_md_close (xtr); - return GNUNET_SYSERR; - } + { + gcry_md_close (xtr); + return GNUNET_SYSERR; + } va_copy (args, argp); ctx_len = 0; while (NULL != va_arg (args, void *)) - ctx_len += va_arg (args, size_t); + ctx_len += va_arg (args, size_t); va_end (args); @@ -191,65 +191,65 @@ GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo, dst = plain + k; va_copy (args, argp); while ((ctx = va_arg (args, void *))) - { - size_t len; + { + size_t len; - len = va_arg (args, size_t); - memcpy (dst, ctx, len); - dst += len; - } + len = va_arg (args, size_t); + memcpy (dst, ctx, len); + dst += len; + } va_end (args); if (t > 0) - { - memset (plain + k + ctx_len, 1, 1); + { + memset (plain + k + ctx_len, 1, 1); #if DEBUG_HKDF - dump ("K(1)", plain, plain_len); + dump ("K(1)", plain, plain_len); #endif - hc = doHMAC (prf, prk, xtr_len, &plain[k], ctx_len + 1); - if (hc == NULL) - goto hkdf_error; - memcpy (result, hc, k); - result += k; - } + hc = doHMAC (prf, prk, xtr_len, &plain[k], ctx_len + 1); + if (hc == NULL) + goto hkdf_error; + memcpy (result, hc, k); + result += k; + } /* K(i+1) */ for (i = 1; i < t; i++) - { - memcpy (plain, result - k, k); - memset (plain + k + ctx_len, i + 1, 1); - gcry_md_reset (prf); + { + memcpy (plain, result - k, k); + memset (plain + k + ctx_len, i + 1, 1); + gcry_md_reset (prf); #if DEBUG_HKDF - dump ("K(i+1)", plain, plain_len); + dump ("K(i+1)", plain, plain_len); #endif - hc = doHMAC (prf, prk, xtr_len, plain, plain_len); - if (hc == NULL) - goto hkdf_error; - memcpy (result, hc, k); - result += k; - } + hc = doHMAC (prf, prk, xtr_len, plain, plain_len); + if (hc == NULL) + goto hkdf_error; + memcpy (result, hc, k); + result += k; + } /* K(t):d */ if (d > 0) + { + if (t > 0) { - if (t > 0) - { - memcpy (plain, result - k, k); - i++; - } - memset (plain + k + ctx_len, i, 1); - gcry_md_reset (prf); + memcpy (plain, result - k, k); + i++; + } + memset (plain + k + ctx_len, i, 1); + gcry_md_reset (prf); #if DEBUG_HKDF - dump ("K(t):d", plain, plain_len); + dump ("K(t):d", plain, plain_len); #endif - if (t > 0) - hc = doHMAC (prf, prk, xtr_len, plain, plain_len); - else - hc = doHMAC (prf, prk, xtr_len, plain + k, plain_len - k); - if (hc == NULL) - goto hkdf_error; - memcpy (result, hc, d); - } + if (t > 0) + hc = doHMAC (prf, prk, xtr_len, plain, plain_len); + else + hc = doHMAC (prf, prk, xtr_len, plain + k, plain_len - k); + if (hc == NULL) + goto hkdf_error; + memcpy (result, hc, d); + } #if DEBUG_HKDF dump ("result", result - k, out_len); #endif @@ -281,16 +281,16 @@ hkdf_ok: */ int GNUNET_CRYPTO_hkdf (void *result, size_t out_len, int xtr_algo, int prf_algo, - const void *xts, size_t xts_len, const void *skm, - size_t skm_len, ...) + const void *xts, size_t xts_len, const void *skm, + size_t skm_len, ...) { va_list argp; int ret; va_start (argp, skm_len); ret = - GNUNET_CRYPTO_hkdf_v (result, out_len, xtr_algo, prf_algo, xts, xts_len, - skm, skm_len, argp); + GNUNET_CRYPTO_hkdf_v (result, out_len, xtr_algo, prf_algo, xts, xts_len, + skm, skm_len, argp); va_end (argp); return ret; diff --git a/src/util/crypto_kdf.c b/src/util/crypto_kdf.c index d8fcbd866..0e7fbbbec 100644 --- a/src/util/crypto_kdf.c +++ b/src/util/crypto_kdf.c @@ -44,8 +44,8 @@ */ int GNUNET_CRYPTO_kdf_v (void *result, size_t out_len, const void *xts, - size_t xts_len, const void *skm, size_t skm_len, - va_list argp) + size_t xts_len, const void *skm, size_t skm_len, + va_list argp) { /* * "Finally, we point out to a particularly advantageous instantiation using @@ -59,9 +59,8 @@ GNUNET_CRYPTO_kdf_v (void *result, size_t out_len, const void *xts, * http://eprint.iacr.org/2010/264 */ - return GNUNET_CRYPTO_hkdf_v (result, out_len, GCRY_MD_SHA512, - GCRY_MD_SHA256, xts, xts_len, skm, skm_len, - argp); + return GNUNET_CRYPTO_hkdf_v (result, out_len, GCRY_MD_SHA512, GCRY_MD_SHA256, + xts, xts_len, skm, skm_len, argp); } /** @@ -77,14 +76,13 @@ GNUNET_CRYPTO_kdf_v (void *result, size_t out_len, const void *xts, */ int GNUNET_CRYPTO_kdf (void *result, size_t out_len, const void *xts, - size_t xts_len, const void *skm, size_t skm_len, ...) + size_t xts_len, const void *skm, size_t skm_len, ...) { va_list argp; int ret; va_start (argp, skm_len); - ret = - GNUNET_CRYPTO_kdf_v (result, out_len, xts, xts_len, skm, skm_len, argp); + ret = GNUNET_CRYPTO_kdf_v (result, out_len, xts, xts_len, skm, skm_len, argp); va_end (argp); return ret; diff --git a/src/util/crypto_ksk.c b/src/util/crypto_ksk.c index 3d40ce27b..60639a709 100644 --- a/src/util/crypto_ksk.c +++ b/src/util/crypto_ksk.c @@ -51,12 +51,12 @@ typedef struct { - gcry_mpi_t n; /* public modulus */ - gcry_mpi_t e; /* public exponent */ - gcry_mpi_t d; /* exponent */ - gcry_mpi_t p; /* prime p. */ - gcry_mpi_t q; /* prime q. */ - gcry_mpi_t u; /* inverse of p mod q. */ + gcry_mpi_t n; /* public modulus */ + gcry_mpi_t e; /* public exponent */ + gcry_mpi_t d; /* exponent */ + gcry_mpi_t p; /* prime p. */ + gcry_mpi_t q; /* prime q. */ + gcry_mpi_t u; /* inverse of p mod q. */ } KBlock_secret_key; /** @@ -84,23 +84,23 @@ mpz_randomize (gcry_mpi_t n, unsigned int nbits, GNUNET_HashCode * rnd) tmp = *rnd; for (i = 0; i < cnt; i++) - { - int j; + { + int j; - if (i > 0) - GNUNET_CRYPTO_hash (&hc, sizeof (GNUNET_HashCode), &tmp); - for (j = 0; j < sizeof (GNUNET_HashCode) / sizeof (uint32_t); j++) - { + if (i > 0) + GNUNET_CRYPTO_hash (&hc, sizeof (GNUNET_HashCode), &tmp); + for (j = 0; j < sizeof (GNUNET_HashCode) / sizeof (uint32_t); j++) + { #if HAVE_GCRY_MPI_LSHIFT - gcry_mpi_lshift (n, n, sizeof (uint32_t) * 8); + gcry_mpi_lshift (n, n, sizeof (uint32_t) * 8); #else - gcry_mpi_mul_ui (n, n, 1 << (sizeof (uint32_t) * 4)); - gcry_mpi_mul_ui (n, n, 1 << (sizeof (uint32_t) * 4)); + gcry_mpi_mul_ui (n, n, 1 << (sizeof (uint32_t) * 4)); + gcry_mpi_mul_ui (n, n, 1 << (sizeof (uint32_t) * 4)); #endif - gcry_mpi_add_ui (n, n, ntohl (((uint32_t *) & tmp)[j])); - } - hc = tmp; + gcry_mpi_add_ui (n, n, ntohl (((uint32_t *) & tmp)[j])); } + hc = tmp; + } GNUNET_CRYPTO_hash (&hc, sizeof (GNUNET_HashCode), rnd); i = gcry_mpi_get_nbits (n); while (i > nbits) @@ -114,10 +114,10 @@ mpz_trailing_zeroes (gcry_mpi_t n) cnt = gcry_mpi_get_nbits (n); for (idx = 0; idx < cnt; idx++) - { - if (gcry_mpi_test_bit (n, idx) == 0) - return idx; - } + { + if (gcry_mpi_test_bit (n, idx) == 0) + return idx; + } return ULONG_MAX; } @@ -164,31 +164,31 @@ is_prime (gcry_mpi_t n, int steps, GNUNET_HashCode * hc) mpz_tdiv_q_2exp (q, q, k); for (i = 0; i < steps; i++) + { + if (!i) { - if (!i) - { - gcry_mpi_set_ui (x, 2); - } - else - { - mpz_randomize (x, nbits - 1, hc); - GNUNET_assert (gcry_mpi_cmp (x, nminus1) < 0); - GNUNET_assert (gcry_mpi_cmp_ui (x, 1) > 0); - } - gcry_mpi_powm (y, x, q, n); - if (gcry_mpi_cmp_ui (y, 1) && gcry_mpi_cmp (y, nminus1)) - { - for (j = 1; j < k && gcry_mpi_cmp (y, nminus1); j++) - { - gcry_mpi_powm (y, y, a2, n); - if (!gcry_mpi_cmp_ui (y, 1)) - goto leave; /* Not a prime. */ - } - if (gcry_mpi_cmp (y, nminus1)) - goto leave; /* Not a prime. */ - } + gcry_mpi_set_ui (x, 2); } - rc = 1; /* May be a prime. */ + else + { + mpz_randomize (x, nbits - 1, hc); + GNUNET_assert (gcry_mpi_cmp (x, nminus1) < 0); + GNUNET_assert (gcry_mpi_cmp_ui (x, 1) > 0); + } + gcry_mpi_powm (y, x, q, n); + if (gcry_mpi_cmp_ui (y, 1) && gcry_mpi_cmp (y, nminus1)) + { + for (j = 1; j < k && gcry_mpi_cmp (y, nminus1); j++) + { + gcry_mpi_powm (y, y, a2, n); + if (!gcry_mpi_cmp_ui (y, 1)) + goto leave; /* Not a prime. */ + } + if (gcry_mpi_cmp (y, nminus1)) + goto leave; /* Not a prime. */ + } + } + rc = 1; /* May be a prime. */ leave: gcry_mpi_release (x); @@ -210,10 +210,10 @@ static void adjust (unsigned char *buf, size_t size, size_t target) { if (size < target) - { - memmove (&buf[target - size], buf, size); - memset (buf, 0, target - size); - } + { + memmove (&buf[target - size], buf, size); + memset (buf, 0, target - size); + } } @@ -326,70 +326,70 @@ gen_prime (gcry_mpi_t * ptest, unsigned int nbits, GNUNET_HashCode * hc) tmp = gcry_mpi_new (0); sp = gcry_mpi_new (0); while (1) + { + /* generate a random number */ + mpz_randomize (prime, nbits, hc); + /* Set high order bit to 1, set low order bit to 1. If we are + * generating a secret prime we are most probably doing that + * for RSA, to make sure that the modulus does have the + * requested key size we set the 2 high order bits. */ + gcry_mpi_set_bit (prime, nbits - 1); + gcry_mpi_set_bit (prime, nbits - 2); + gcry_mpi_set_bit (prime, 0); + + /* Calculate all remainders. */ + for (i = 0; i < no_of_small_prime_numbers; i++) { - /* generate a random number */ - mpz_randomize (prime, nbits, hc); - /* Set high order bit to 1, set low order bit to 1. If we are - * generating a secret prime we are most probably doing that - * for RSA, to make sure that the modulus does have the - * requested key size we set the 2 high order bits. */ - gcry_mpi_set_bit (prime, nbits - 1); - gcry_mpi_set_bit (prime, nbits - 2); - gcry_mpi_set_bit (prime, 0); - - /* Calculate all remainders. */ + size_t written; + + gcry_mpi_set_ui (sp, small_prime_numbers[i]); + gcry_mpi_div (NULL, tmp, prime, sp, -1); + mods[i] = 0; + written = sizeof (unsigned int); + GNUNET_assert (0 == + gcry_mpi_print (GCRYMPI_FMT_USG, + (unsigned char *) &mods[i], written, + &written, tmp)); + adjust ((unsigned char *) &mods[i], written, sizeof (unsigned int)); + mods[i] = ntohl (mods[i]); + } + /* Now try some primes starting with prime. */ + for (step = 0; step < 20000; step += 2) + { + /* Check against all the small primes we have in mods. */ for (i = 0; i < no_of_small_prime_numbers; i++) - { - size_t written; - - gcry_mpi_set_ui (sp, small_prime_numbers[i]); - gcry_mpi_div (NULL, tmp, prime, sp, -1); - mods[i] = 0; - written = sizeof (unsigned int); - GNUNET_assert (0 == - gcry_mpi_print (GCRYMPI_FMT_USG, - (unsigned char *) &mods[i], written, - &written, tmp)); - adjust ((unsigned char *) &mods[i], written, sizeof (unsigned int)); - mods[i] = ntohl (mods[i]); - } - /* Now try some primes starting with prime. */ - for (step = 0; step < 20000; step += 2) - { - /* Check against all the small primes we have in mods. */ - for (i = 0; i < no_of_small_prime_numbers; i++) - { - uint16_t x = small_prime_numbers[i]; - - while (mods[i] + step >= x) - mods[i] -= x; - if (!(mods[i] + step)) - break; - } - if (i < no_of_small_prime_numbers) - continue; /* Found a multiple of an already known prime. */ - - gcry_mpi_add_ui (*ptest, prime, step); - if (!gcry_mpi_test_bit (*ptest, nbits - 2)) - break; - - /* Do a fast Fermat test now. */ - gcry_mpi_sub_ui (pminus1, *ptest, 1); - gcry_mpi_powm (result, val_2, pminus1, *ptest); - if ((!gcry_mpi_cmp_ui (result, 1)) && (is_prime (*ptest, 5, hc))) - { - /* Got it. */ - gcry_mpi_release (sp); - gcry_mpi_release (tmp); - gcry_mpi_release (val_2); - gcry_mpi_release (val_3); - gcry_mpi_release (result); - gcry_mpi_release (pminus1); - gcry_mpi_release (prime); - return; - } - } + { + uint16_t x = small_prime_numbers[i]; + + while (mods[i] + step >= x) + mods[i] -= x; + if (!(mods[i] + step)) + break; + } + if (i < no_of_small_prime_numbers) + continue; /* Found a multiple of an already known prime. */ + + gcry_mpi_add_ui (*ptest, prime, step); + if (!gcry_mpi_test_bit (*ptest, nbits - 2)) + break; + + /* Do a fast Fermat test now. */ + gcry_mpi_sub_ui (pminus1, *ptest, 1); + gcry_mpi_powm (result, val_2, pminus1, *ptest); + if ((!gcry_mpi_cmp_ui (result, 1)) && (is_prime (*ptest, 5, hc))) + { + /* Got it. */ + gcry_mpi_release (sp); + gcry_mpi_release (tmp); + gcry_mpi_release (val_2); + gcry_mpi_release (val_3); + gcry_mpi_release (result); + gcry_mpi_release (pminus1); + gcry_mpi_release (prime); + return; + } } + } } /** @@ -399,11 +399,11 @@ gen_prime (gcry_mpi_t * ptest, unsigned int nbits, GNUNET_HashCode * hc) * @param hc the HC to use for PRNG (modified!) */ static void -generate_kblock_key (KBlock_secret_key * sk, unsigned int nbits, - GNUNET_HashCode * hc) +generate_kblock_key (KBlock_secret_key *sk, unsigned int nbits, + GNUNET_HashCode * hc) { gcry_mpi_t t1, t2; - gcry_mpi_t phi; /* helper: (p-1)(q-1) */ + gcry_mpi_t phi; /* helper: (p-1)(q-1) */ gcry_mpi_t g; gcry_mpi_t f; @@ -425,36 +425,36 @@ generate_kblock_key (KBlock_secret_key * sk, unsigned int nbits, f = gcry_mpi_new (0); do + { + do { - do - { - gcry_mpi_release (sk->p); - gcry_mpi_release (sk->q); - gen_prime (&sk->p, nbits / 2, hc); - gen_prime (&sk->q, nbits / 2, hc); - - if (gcry_mpi_cmp (sk->p, sk->q) > 0) /* p shall be smaller than q (for calc of u) */ - gcry_mpi_swap (sk->p, sk->q); - /* calculate the modulus */ - gcry_mpi_mul (sk->n, sk->p, sk->q); - } - while (gcry_mpi_get_nbits (sk->n) != nbits); - - /* calculate Euler totient: phi = (p-1)(q-1) */ - gcry_mpi_sub_ui (t1, sk->p, 1); - gcry_mpi_sub_ui (t2, sk->q, 1); - gcry_mpi_mul (phi, t1, t2); - gcry_mpi_gcd (g, t1, t2); - gcry_mpi_div (f, NULL, phi, g, 0); - while (0 == gcry_mpi_gcd (t1, sk->e, phi)) - { /* (while gcd is not 1) */ - gcry_mpi_add_ui (sk->e, sk->e, 2); - } - - /* calculate the secret key d = e^1 mod phi */ + gcry_mpi_release (sk->p); + gcry_mpi_release (sk->q); + gen_prime (&sk->p, nbits / 2, hc); + gen_prime (&sk->q, nbits / 2, hc); + + if (gcry_mpi_cmp (sk->p, sk->q) > 0) /* p shall be smaller than q (for calc of u) */ + gcry_mpi_swap (sk->p, sk->q); + /* calculate the modulus */ + gcry_mpi_mul (sk->n, sk->p, sk->q); + } + while (gcry_mpi_get_nbits (sk->n) != nbits); + + /* calculate Euler totient: phi = (p-1)(q-1) */ + gcry_mpi_sub_ui (t1, sk->p, 1); + gcry_mpi_sub_ui (t2, sk->q, 1); + gcry_mpi_mul (phi, t1, t2); + gcry_mpi_gcd (g, t1, t2); + gcry_mpi_div (f, NULL, phi, g, 0); + while (0 == gcry_mpi_gcd (t1, sk->e, phi)) + { /* (while gcd is not 1) */ + gcry_mpi_add_ui (sk->e, sk->e, 2); } + + /* calculate the secret key d = e^1 mod phi */ + } while ((0 == gcry_mpi_invm (sk->d, sk->e, f)) || - (0 == gcry_mpi_invm (sk->u, sk->p, sk->q))); + (0 == gcry_mpi_invm (sk->u, sk->p, sk->q))); gcry_mpi_release (t1); gcry_mpi_release (t2); @@ -473,13 +473,13 @@ struct KskRsaPrivateKeyBinaryEncoded * Total size of the structure, in bytes, in big-endian! */ uint16_t len GNUNET_PACKED; - uint16_t sizen GNUNET_PACKED; /* in big-endian! */ - uint16_t sizee GNUNET_PACKED; /* in big-endian! */ - uint16_t sized GNUNET_PACKED; /* in big-endian! */ - uint16_t sizep GNUNET_PACKED; /* in big-endian! */ - uint16_t sizeq GNUNET_PACKED; /* in big-endian! */ - uint16_t sizedmp1 GNUNET_PACKED; /* in big-endian! */ - uint16_t sizedmq1 GNUNET_PACKED; /* in big-endian! */ + uint16_t sizen GNUNET_PACKED; /* in big-endian! */ + uint16_t sizee GNUNET_PACKED; /* in big-endian! */ + uint16_t sized GNUNET_PACKED; /* in big-endian! */ + uint16_t sizep GNUNET_PACKED; /* in big-endian! */ + uint16_t sizeq GNUNET_PACKED; /* in big-endian! */ + uint16_t sizedmp1 GNUNET_PACKED; /* in big-endian! */ + uint16_t sizedmq1 GNUNET_PACKED; /* in big-endian! */ /* followed by the actual values */ }; @@ -501,16 +501,16 @@ makeKblockKeyInternal (const GNUNET_HashCode * hc) size_t size; hx = *hc; - generate_kblock_key (&sk, 1024, /* at least 10x as fast than 2048 bits - * -- we simply cannot afford 2048 bits - * even on modern hardware, and especially - * not since clearly a dictionary attack - * will still be much cheaper - * than breaking a 1024 bit RSA key. - * If an adversary can spend the time to - * break a 1024 bit RSA key just to forge - * a signature -- SO BE IT. [ CG, 6/2005 ] */ - &hx); + generate_kblock_key (&sk, 1024, /* at least 10x as fast than 2048 bits + * -- we simply cannot afford 2048 bits + * even on modern hardware, and especially + * not since clearly a dictionary attack + * will still be much cheaper + * than breaking a 1024 bit RSA key. + * If an adversary can spend the time to + * break a 1024 bit RSA key just to forge + * a signature -- SO BE IT. [ CG, 6/2005 ] */ + &hx); pkv[0] = &sk.n; pkv[1] = &sk.e; pkv[2] = &sk.d; @@ -519,10 +519,10 @@ makeKblockKeyInternal (const GNUNET_HashCode * hc) pkv[5] = &sk.u; size = sizeof (struct KskRsaPrivateKeyBinaryEncoded); for (i = 0; i < 6; i++) - { - gcry_mpi_aprint (GCRYMPI_FMT_STD, &pbu[i], &sizes[i], *pkv[i]); - size += sizes[i]; - } + { + gcry_mpi_aprint (GCRYMPI_FMT_STD, &pbu[i], &sizes[i], *pkv[i]); + size += sizes[i]; + } GNUNET_assert (size < 65536); retval = GNUNET_malloc (size); retval->len = htons (size); @@ -547,10 +547,10 @@ makeKblockKeyInternal (const GNUNET_HashCode * hc) retval->sizedmq1 = htons (0); memcpy (&((char *) &retval[1])[i], pbu[5], sizes[5]); for (i = 0; i < 6; i++) - { - gcry_mpi_release (*pkv[i]); - free (pbu[i]); - } + { + gcry_mpi_release (*pkv[i]); + free (pbu[i]); + } return retval; } @@ -572,123 +572,122 @@ ksk_decode_key (const struct KskRsaPrivateKeyBinaryEncoded *encoding) pos = 0; size = ntohs (encoding->sizen); rc = gcry_mpi_scan (&n, GCRYMPI_FMT_USG, - &((const unsigned char *) (&encoding[1]))[pos], size, - &size); + &((const unsigned char *) (&encoding[1]))[pos], size, + &size); pos += ntohs (encoding->sizen); if (rc) - { - LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); - return NULL; - } + { + LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); + return NULL; + } size = ntohs (encoding->sizee); rc = gcry_mpi_scan (&e, GCRYMPI_FMT_USG, - &((const unsigned char *) (&encoding[1]))[pos], size, - &size); + &((const unsigned char *) (&encoding[1]))[pos], size, + &size); pos += ntohs (encoding->sizee); if (rc) - { - LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); - gcry_mpi_release (n); - return NULL; - } + { + LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); + gcry_mpi_release (n); + return NULL; + } size = ntohs (encoding->sized); rc = gcry_mpi_scan (&d, GCRYMPI_FMT_USG, - &((const unsigned char *) (&encoding[1]))[pos], size, - &size); + &((const unsigned char *) (&encoding[1]))[pos], size, + &size); pos += ntohs (encoding->sized); if (rc) + { + LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); + gcry_mpi_release (n); + gcry_mpi_release (e); + return NULL; + } + /* swap p and q! */ + size = ntohs (encoding->sizep); + if (size > 0) + { + rc = gcry_mpi_scan (&q, GCRYMPI_FMT_USG, + &((const unsigned char *) (&encoding[1]))[pos], size, + &size); + pos += ntohs (encoding->sizep); + if (rc) { LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); gcry_mpi_release (n); gcry_mpi_release (e); + gcry_mpi_release (d); return NULL; } - /* swap p and q! */ - size = ntohs (encoding->sizep); - if (size > 0) - { - rc = gcry_mpi_scan (&q, GCRYMPI_FMT_USG, - &((const unsigned char *) (&encoding[1]))[pos], - size, &size); - pos += ntohs (encoding->sizep); - if (rc) - { - LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); - gcry_mpi_release (n); - gcry_mpi_release (e); - gcry_mpi_release (d); - return NULL; - } - } + } else q = NULL; size = ntohs (encoding->sizeq); if (size > 0) + { + rc = gcry_mpi_scan (&p, GCRYMPI_FMT_USG, + &((const unsigned char *) (&encoding[1]))[pos], size, + &size); + pos += ntohs (encoding->sizeq); + if (rc) { - rc = gcry_mpi_scan (&p, GCRYMPI_FMT_USG, - &((const unsigned char *) (&encoding[1]))[pos], - size, &size); - pos += ntohs (encoding->sizeq); - if (rc) - { - LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); - gcry_mpi_release (n); - gcry_mpi_release (e); - gcry_mpi_release (d); - if (q != NULL) - gcry_mpi_release (q); - return NULL; - } + LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); + gcry_mpi_release (n); + gcry_mpi_release (e); + gcry_mpi_release (d); + if (q != NULL) + gcry_mpi_release (q); + return NULL; } + } else p = NULL; pos += ntohs (encoding->sizedmp1); pos += ntohs (encoding->sizedmq1); size = - ntohs (encoding->len) - sizeof (struct KskRsaPrivateKeyBinaryEncoded) - - pos; + ntohs (encoding->len) - sizeof (struct KskRsaPrivateKeyBinaryEncoded) - + pos; if (size > 0) + { + rc = gcry_mpi_scan (&u, GCRYMPI_FMT_USG, + &((const unsigned char *) (&encoding[1]))[pos], size, + &size); + if (rc) { - rc = gcry_mpi_scan (&u, GCRYMPI_FMT_USG, - &((const unsigned char *) (&encoding[1]))[pos], - size, &size); - if (rc) - { - LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); - gcry_mpi_release (n); - gcry_mpi_release (e); - gcry_mpi_release (d); - if (p != NULL) - gcry_mpi_release (p); - if (q != NULL) - gcry_mpi_release (q); - return NULL; - } + LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); + gcry_mpi_release (n); + gcry_mpi_release (e); + gcry_mpi_release (d); + if (p != NULL) + gcry_mpi_release (p); + if (q != NULL) + gcry_mpi_release (q); + return NULL; } + } else u = NULL; if ((p != NULL) && (q != NULL) && (u != NULL)) + { + rc = gcry_sexp_build (&res, &size, /* erroff */ + "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)(u %m)))", + n, e, d, p, q, u); + } + else + { + if ((p != NULL) && (q != NULL)) { - rc = gcry_sexp_build (&res, &size, /* erroff */ - "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)(u %m)))", - n, e, d, p, q, u); + rc = gcry_sexp_build (&res, &size, /* erroff */ + "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)))", + n, e, d, p, q); } - else + else { - if ((p != NULL) && (q != NULL)) - { - rc = gcry_sexp_build (&res, &size, /* erroff */ - "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)))", - n, e, d, p, q); - } - else - { - rc = gcry_sexp_build (&res, &size, /* erroff */ - "(private-key(rsa(n %m)(e %m)(d %m)))", n, e, - d); - } + rc = gcry_sexp_build (&res, &size, /* erroff */ + "(private-key(rsa(n %m)(e %m)(d %m)))", n, e, d); } + } gcry_mpi_release (n); gcry_mpi_release (e); gcry_mpi_release (d); @@ -703,10 +702,10 @@ ksk_decode_key (const struct KskRsaPrivateKeyBinaryEncoded *encoding) LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc); #if EXTRA_CHECKS if (gcry_pk_testkey (res)) - { - LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc); - return NULL; - } + { + LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc); + return NULL; + } #endif ret = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPrivateKey)); ret->sexp = res; @@ -736,13 +735,13 @@ GNUNET_CRYPTO_rsa_key_create_from_hash (const GNUNET_HashCode * hc) unsigned int i; for (i = 0; i < cacheSize; i++) + { + if (0 == memcmp (hc, &cache[i]->hc, sizeof (GNUNET_HashCode))) { - if (0 == memcmp (hc, &cache[i]->hc, sizeof (GNUNET_HashCode))) - { - ret = ksk_decode_key (cache[i]->pke); - return ret; - } + ret = ksk_decode_key (cache[i]->pke); + return ret; } + } line = GNUNET_malloc (sizeof (struct KBlockKeyCacheLine)); line->hc = *hc; @@ -758,10 +757,10 @@ void __attribute__ ((destructor)) GNUNET_CRYPTO_ksk_fini () unsigned int i; for (i = 0; i < cacheSize; i++) - { - GNUNET_free (cache[i]->pke); - GNUNET_free (cache[i]); - } + { + GNUNET_free (cache[i]->pke); + GNUNET_free (cache[i]); + } GNUNET_array_grow (cache, cacheSize, 0); } diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c index 7fb2d1428..c74d60f4f 100644 --- a/src/util/crypto_random.c +++ b/src/util/crypto_random.c @@ -65,37 +65,37 @@ GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, uint32_t i) GNUNET_assert (i > 0); switch (mode) - { - case GNUNET_CRYPTO_QUALITY_STRONG: - /* see http://lists.gnupg.org/pipermail/gcrypt-devel/2004-May/000613.html */ + { + case GNUNET_CRYPTO_QUALITY_STRONG: + /* see http://lists.gnupg.org/pipermail/gcrypt-devel/2004-May/000613.html */ #ifdef gcry_fast_random_poll - if ((invokeCount++ % 256) == 0) - gcry_fast_random_poll (); + if ((invokeCount++ % 256) == 0) + gcry_fast_random_poll (); #endif - ul = UINT32_MAX - (UINT32_MAX % i); - do - { - gcry_randomize ((unsigned char *) &ret, sizeof (uint32_t), - GCRY_STRONG_RANDOM); - } - while (ret >= ul); - return ret % i; - case GNUNET_CRYPTO_QUALITY_NONCE: - ul = UINT32_MAX - (UINT32_MAX % i); - do - { - gcry_create_nonce (&ret, sizeof (ret)); - } - while (ret >= ul); - return ret % i; - case GNUNET_CRYPTO_QUALITY_WEAK: - ret = i * weak_random (); - if (ret >= i) - ret = i - 1; - return ret; - default: - GNUNET_assert (0); + ul = UINT32_MAX - (UINT32_MAX % i); + do + { + gcry_randomize ((unsigned char *) &ret, sizeof (uint32_t), + GCRY_STRONG_RANDOM); + } + while (ret >= ul); + return ret % i; + case GNUNET_CRYPTO_QUALITY_NONCE: + ul = UINT32_MAX - (UINT32_MAX % i); + do + { + gcry_create_nonce (&ret, sizeof (ret)); } + while (ret >= ul); + return ret % i; + case GNUNET_CRYPTO_QUALITY_WEAK: + ret = i * weak_random (); + if (ret >= i) + ret = i - 1; + return ret; + default: + GNUNET_assert (0); + } return 0; } @@ -121,12 +121,12 @@ GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, unsigned int n) for (i = 0; i < n; i++) ret[i] = i; for (i = n - 1; i > 0; i--) - { - x = GNUNET_CRYPTO_random_u32 (mode, i + 1); - tmp = ret[x]; - ret[x] = ret[i]; - ret[i] = tmp; - } + { + x = GNUNET_CRYPTO_random_u32 (mode, i + 1); + tmp = ret[x]; + ret[x] = ret[i]; + ret[i] = tmp; + } return ret; } @@ -146,33 +146,33 @@ GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, uint64_t max) GNUNET_assert (max > 0); switch (mode) + { + case GNUNET_CRYPTO_QUALITY_STRONG: + ul = UINT64_MAX - (UINT64_MAX % max); + do { - case GNUNET_CRYPTO_QUALITY_STRONG: - ul = UINT64_MAX - (UINT64_MAX % max); - do - { - gcry_randomize ((unsigned char *) &ret, sizeof (uint64_t), - GCRY_STRONG_RANDOM); - } - while (ret >= ul); - return ret % max; - case GNUNET_CRYPTO_QUALITY_NONCE: - ul = UINT64_MAX - (UINT64_MAX % max); - do - { - gcry_create_nonce (&ret, sizeof (ret)); - } - while (ret >= ul); - - return ret % max; - case GNUNET_CRYPTO_QUALITY_WEAK: - ret = max * weak_random (); - if (ret >= max) - ret = max - 1; - return ret; - default: - GNUNET_assert (0); + gcry_randomize ((unsigned char *) &ret, sizeof (uint64_t), + GCRY_STRONG_RANDOM); } + while (ret >= ul); + return ret % max; + case GNUNET_CRYPTO_QUALITY_NONCE: + ul = UINT64_MAX - (UINT64_MAX % max); + do + { + gcry_create_nonce (&ret, sizeof (ret)); + } + while (ret >= ul); + + return ret % max; + case GNUNET_CRYPTO_QUALITY_WEAK: + ret = max * weak_random (); + if (ret >= max) + ret = max - 1; + return ret; + default: + GNUNET_assert (0); + } return 0; } @@ -200,7 +200,7 @@ static struct GNUNET_OS_Process *genproc; */ static void entropy_generator (void *cls, const char *what, int printchar, int current, - int total) + int total) { unsigned long code; enum GNUNET_OS_ProcessStatusType type; @@ -209,39 +209,39 @@ entropy_generator (void *cls, const char *what, int printchar, int current, if (0 != strcmp (what, "need_entropy")) return; if (current == total) + { + if (genproc != NULL) { - if (genproc != NULL) - { - if (0 != GNUNET_OS_process_kill (genproc, SIGTERM)) - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "kill"); - GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc)); - GNUNET_OS_process_close (genproc); - genproc = NULL; - } - return; - } - if (genproc != NULL) - { - ret = GNUNET_OS_process_status (genproc, &type, &code); - if (ret == GNUNET_NO) - return; /* still running */ - if (ret == GNUNET_SYSERR) - { - GNUNET_break (0); - return; - } if (0 != GNUNET_OS_process_kill (genproc, SIGTERM)) - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "kill"); + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "kill"); GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc)); GNUNET_OS_process_close (genproc); genproc = NULL; } - LOG (GNUNET_ERROR_TYPE_INFO, - _("Starting `%s' process to generate entropy\n"), "find"); + return; + } + if (genproc != NULL) + { + ret = GNUNET_OS_process_status (genproc, &type, &code); + if (ret == GNUNET_NO) + return; /* still running */ + if (ret == GNUNET_SYSERR) + { + GNUNET_break (0); + return; + } + if (0 != GNUNET_OS_process_kill (genproc, SIGTERM)) + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "kill"); + GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc)); + GNUNET_OS_process_close (genproc); + genproc = NULL; + } + LOG (GNUNET_ERROR_TYPE_INFO, _("Starting `%s' process to generate entropy\n"), + "find"); genproc = - GNUNET_OS_start_process (NULL, NULL, "sh", "sh", "-c", - "exec find / -mount -type f -exec cp {} /dev/null \\; 2>/dev/null", - NULL); + GNUNET_OS_start_process (NULL, NULL, "sh", "sh", "-c", + "exec find / -mount -type f -exec cp {} /dev/null \\; 2>/dev/null", + NULL); } @@ -249,11 +249,11 @@ static void killfind () { if (genproc != NULL) - { - GNUNET_OS_process_kill (genproc, SIGKILL); - GNUNET_OS_process_close (genproc); - genproc = NULL; - } + { + GNUNET_OS_process_kill (genproc, SIGKILL); + GNUNET_OS_process_close (genproc); + genproc = NULL; + } } @@ -261,21 +261,20 @@ void __attribute__ ((constructor)) GNUNET_CRYPTO_random_init () { gcry_control (GCRYCTL_DISABLE_SECMEM, 0); if (!gcry_check_version (GCRYPT_VERSION)) - { - fprintf (stderr, - _ - ("libgcrypt has not the expected version (version %s is required).\n"), - GCRYPT_VERSION); - abort (); - } + { + fprintf (stderr, + _ + ("libgcrypt has not the expected version (version %s is required).\n"), + GCRYPT_VERSION); + abort (); + } #ifdef gcry_fast_random_poll gcry_fast_random_poll (); #endif gcry_set_progress_handler (&entropy_generator, NULL); atexit (&killfind); SRANDOM (time (NULL) ^ - GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, - UINT32_MAX)); + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX)); } diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c index 7f0c81692..d29566ac8 100644 --- a/src/util/crypto_rsa.c +++ b/src/util/crypto_rsa.c @@ -66,13 +66,13 @@ struct RsaPrivateKeyBinaryEncoded * Total size of the structure, in bytes, in big-endian! */ uint16_t len GNUNET_PACKED; - uint16_t sizen GNUNET_PACKED; /* in big-endian! */ - uint16_t sizee GNUNET_PACKED; /* in big-endian! */ - uint16_t sized GNUNET_PACKED; /* in big-endian! */ - uint16_t sizep GNUNET_PACKED; /* in big-endian! */ - uint16_t sizeq GNUNET_PACKED; /* in big-endian! */ - uint16_t sizedmp1 GNUNET_PACKED; /* in big-endian! */ - uint16_t sizedmq1 GNUNET_PACKED; /* in big-endian! */ + uint16_t sizen GNUNET_PACKED; /* in big-endian! */ + uint16_t sizee GNUNET_PACKED; /* in big-endian! */ + uint16_t sized GNUNET_PACKED; /* in big-endian! */ + uint16_t sizep GNUNET_PACKED; /* in big-endian! */ + uint16_t sizeq GNUNET_PACKED; /* in big-endian! */ + uint16_t sizedmp1 GNUNET_PACKED; /* in big-endian! */ + uint16_t sizedmq1 GNUNET_PACKED; /* in big-endian! */ /* followed by the actual values */ }; @@ -98,10 +98,10 @@ static void adjust (unsigned char *buf, size_t size, size_t target) { if (size < target) - { - memmove (&buf[target - size], buf, size); - memset (buf, 0, target - size); - } + { + memmove (&buf[target - size], buf, size); + memset (buf, 0, target - size); + } } /** @@ -115,9 +115,9 @@ GNUNET_CRYPTO_rsa_key_create () gcry_sexp_t s_keyparam; GNUNET_assert (0 == - gcry_sexp_build (&s_keyparam, NULL, - "(genkey(rsa(nbits %d)(rsa-use-e 3:257)))", - HOSTKEY_LEN)); + gcry_sexp_build (&s_keyparam, NULL, + "(genkey(rsa(nbits %d)(rsa-use-e 3:257)))", + HOSTKEY_LEN)); GNUNET_assert (0 == gcry_pk_genkey (&s_key, s_keyparam)); gcry_sexp_release (s_keyparam); #if EXTRA_CHECKS @@ -140,7 +140,7 @@ GNUNET_CRYPTO_rsa_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *hostkey) static int key_from_sexp (gcry_mpi_t * array, gcry_sexp_t sexp, const char *topname, - const char *elems) + const char *elems) { gcry_sexp_t list, l2; const char *s; @@ -148,44 +148,44 @@ key_from_sexp (gcry_mpi_t * array, gcry_sexp_t sexp, const char *topname, list = gcry_sexp_find_token (sexp, topname, 0); if (!list) - { - return 1; - } + { + return 1; + } l2 = gcry_sexp_cadr (list); gcry_sexp_release (list); list = l2; if (!list) - { - return 2; - } + { + return 2; + } idx = 0; for (s = elems; *s; s++, idx++) + { + l2 = gcry_sexp_find_token (list, s, 1); + if (!l2) { - l2 = gcry_sexp_find_token (list, s, 1); - if (!l2) - { - for (i = 0; i < idx; i++) - { - gcry_free (array[i]); - array[i] = NULL; - } - gcry_sexp_release (list); - return 3; /* required parameter not found */ - } - array[idx] = gcry_sexp_nth_mpi (l2, 1, GCRYMPI_FMT_USG); - gcry_sexp_release (l2); - if (!array[idx]) - { - for (i = 0; i < idx; i++) - { - gcry_free (array[i]); - array[i] = NULL; - } - gcry_sexp_release (list); - return 4; /* required parameter is invalid */ - } + for (i = 0; i < idx; i++) + { + gcry_free (array[i]); + array[i] = NULL; + } + gcry_sexp_release (list); + return 3; /* required parameter not found */ } + array[idx] = gcry_sexp_nth_mpi (l2, 1, GCRYMPI_FMT_USG); + gcry_sexp_release (l2); + if (!array[idx]) + { + for (i = 0; i < idx; i++) + { + gcry_free (array[i]); + array[i] = NULL; + } + gcry_sexp_release (list); + return 4; /* required parameter is invalid */ + } + } gcry_sexp_release (list); return 0; } @@ -197,10 +197,9 @@ key_from_sexp (gcry_mpi_t * array, gcry_sexp_t sexp, const char *topname, */ void GNUNET_CRYPTO_rsa_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey - *priv, - struct - GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded - *pub) + *priv, + struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded + *pub) { gcry_mpi_t skey[2]; size_t size; @@ -213,25 +212,24 @@ GNUNET_CRYPTO_rsa_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey rc = key_from_sexp (skey, priv->sexp, "rsa", "ne"); GNUNET_assert (0 == rc); pub->len = - htons (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) - - sizeof (pub->padding)); + htons (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) - + sizeof (pub->padding)); pub->sizen = htons (GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH); pub->padding = 0; size = GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH; GNUNET_assert (0 == - gcry_mpi_print (GCRYMPI_FMT_USG, &pub->key[0], size, &size, - skey[0])); + gcry_mpi_print (GCRYMPI_FMT_USG, &pub->key[0], size, &size, + skey[0])); adjust (&pub->key[0], size, GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH); - size = - GNUNET_CRYPTO_RSA_KEY_LENGTH - GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH; + size = GNUNET_CRYPTO_RSA_KEY_LENGTH - GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH; GNUNET_assert (0 == - gcry_mpi_print (GCRYMPI_FMT_USG, - &pub->key - [GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH], - size, &size, skey[1])); + gcry_mpi_print (GCRYMPI_FMT_USG, + &pub->key + [GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH], size, + &size, skey[1])); adjust (&pub->key[GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH], size, - GNUNET_CRYPTO_RSA_KEY_LENGTH - - GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH); + GNUNET_CRYPTO_RSA_KEY_LENGTH - + GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH); gcry_mpi_release (skey[0]); gcry_mpi_release (skey[1]); } @@ -245,7 +243,7 @@ GNUNET_CRYPTO_rsa_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey */ static struct GNUNET_CRYPTO_RsaPrivateKey * public2PrivateKey (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded - *publicKey) + *publicKey) { struct GNUNET_CRYPTO_RsaPrivateKey *ret; gcry_sexp_t result; @@ -259,38 +257,36 @@ public2PrivateKey (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded (ntohs (publicKey->len) != sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) - sizeof (publicKey->padding))) - { - GNUNET_break (0); - return NULL; - } + { + GNUNET_break (0); + return NULL; + } size = GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH; rc = gcry_mpi_scan (&n, GCRYMPI_FMT_USG, &publicKey->key[0], size, &size); if (rc) - { - LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); - return NULL; - } - size = - GNUNET_CRYPTO_RSA_KEY_LENGTH - GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH; - rc = - gcry_mpi_scan (&e, GCRYMPI_FMT_USG, - &publicKey->key[GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH], - size, &size); + { + LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); + return NULL; + } + size = GNUNET_CRYPTO_RSA_KEY_LENGTH - GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH; + rc = gcry_mpi_scan (&e, GCRYMPI_FMT_USG, + &publicKey->key[GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH], + size, &size); if (rc) - { - LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); - gcry_mpi_release (n); - return NULL; - } + { + LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); + gcry_mpi_release (n); + return NULL; + } rc = gcry_sexp_build (&result, &erroff, "(public-key(rsa(n %m)(e %m)))", n, - e); + e); gcry_mpi_release (n); gcry_mpi_release (e); if (rc) - { - LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc); /* erroff gives more info */ - return NULL; - } + { + LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc); /* erroff gives more info */ + return NULL; + } ret = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPrivateKey)); ret->sexp = result; return ret; @@ -316,10 +312,10 @@ rsa_encode_key (const struct GNUNET_CRYPTO_RsaPrivateKey *hostkey) #if EXTRA_CHECKS if (gcry_pk_testkey (hostkey->sexp)) - { - GNUNET_break (0); - return NULL; - } + { + GNUNET_break (0); + return NULL; + } #endif memset (pkv, 0, sizeof (gcry_mpi_t) * 6); @@ -337,21 +333,21 @@ rsa_encode_key (const struct GNUNET_CRYPTO_RsaPrivateKey *hostkey) GNUNET_assert (0 == rc); size = sizeof (struct RsaPrivateKeyBinaryEncoded); for (i = 0; i < 6; i++) + { + if (pkv[i] != NULL) { - if (pkv[i] != NULL) - { - GNUNET_assert (0 == - gcry_mpi_aprint (GCRYMPI_FMT_USG, - (unsigned char **) &pbu[i], - &sizes[i], pkv[i])); - size += sizes[i]; - } - else - { - pbu[i] = NULL; - sizes[i] = 0; - } + GNUNET_assert (0 == + gcry_mpi_aprint (GCRYMPI_FMT_USG, + (unsigned char **) &pbu[i], &sizes[i], + pkv[i])); + size += sizes[i]; } + else + { + pbu[i] = NULL; + sizes[i] = 0; + } + } GNUNET_assert (size < 65536); retval = GNUNET_malloc (size); retval->len = htons (size); @@ -376,12 +372,12 @@ rsa_encode_key (const struct GNUNET_CRYPTO_RsaPrivateKey *hostkey) retval->sizedmq1 = htons (0); memcpy (&((char *) (&retval[1]))[i], pbu[5], sizes[5]); for (i = 0; i < 6; i++) - { - if (pkv[i] != NULL) - gcry_mpi_release (pkv[i]); - if (pbu[i] != NULL) - free (pbu[i]); - } + { + if (pkv[i] != NULL) + gcry_mpi_release (pkv[i]); + if (pbu[i] != NULL) + free (pbu[i]); + } return retval; } @@ -397,7 +393,7 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len) { struct GNUNET_CRYPTO_RsaPrivateKey *ret; const struct RsaPrivateKeyBinaryEncoded *encoding = - (const struct RsaPrivateKeyBinaryEncoded *) buf; + (const struct RsaPrivateKeyBinaryEncoded *) buf; gcry_sexp_t res; gcry_mpi_t n, e, d, p, q, u; int rc; @@ -412,122 +408,121 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len) pos = 0; size = ntohs (encoding->sizen); rc = gcry_mpi_scan (&n, GCRYMPI_FMT_USG, - &((const unsigned char *) (&encoding[1]))[pos], size, - &size); + &((const unsigned char *) (&encoding[1]))[pos], size, + &size); pos += ntohs (encoding->sizen); if (rc) - { - LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); - return NULL; - } + { + LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); + return NULL; + } size = ntohs (encoding->sizee); rc = gcry_mpi_scan (&e, GCRYMPI_FMT_USG, - &((const unsigned char *) (&encoding[1]))[pos], size, - &size); + &((const unsigned char *) (&encoding[1]))[pos], size, + &size); pos += ntohs (encoding->sizee); if (rc) - { - LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); - gcry_mpi_release (n); - return NULL; - } + { + LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); + gcry_mpi_release (n); + return NULL; + } size = ntohs (encoding->sized); rc = gcry_mpi_scan (&d, GCRYMPI_FMT_USG, - &((const unsigned char *) (&encoding[1]))[pos], size, - &size); + &((const unsigned char *) (&encoding[1]))[pos], size, + &size); pos += ntohs (encoding->sized); if (rc) + { + LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); + gcry_mpi_release (n); + gcry_mpi_release (e); + return NULL; + } + /* swap p and q! */ + size = ntohs (encoding->sizep); + if (size > 0) + { + rc = gcry_mpi_scan (&q, GCRYMPI_FMT_USG, + &((const unsigned char *) (&encoding[1]))[pos], size, + &size); + pos += ntohs (encoding->sizep); + if (rc) { LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); gcry_mpi_release (n); gcry_mpi_release (e); + gcry_mpi_release (d); return NULL; } - /* swap p and q! */ - size = ntohs (encoding->sizep); - if (size > 0) - { - rc = gcry_mpi_scan (&q, GCRYMPI_FMT_USG, - &((const unsigned char *) (&encoding[1]))[pos], - size, &size); - pos += ntohs (encoding->sizep); - if (rc) - { - LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); - gcry_mpi_release (n); - gcry_mpi_release (e); - gcry_mpi_release (d); - return NULL; - } - } + } else q = NULL; size = ntohs (encoding->sizeq); if (size > 0) + { + rc = gcry_mpi_scan (&p, GCRYMPI_FMT_USG, + &((const unsigned char *) (&encoding[1]))[pos], size, + &size); + pos += ntohs (encoding->sizeq); + if (rc) { - rc = gcry_mpi_scan (&p, GCRYMPI_FMT_USG, - &((const unsigned char *) (&encoding[1]))[pos], - size, &size); - pos += ntohs (encoding->sizeq); - if (rc) - { - LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); - gcry_mpi_release (n); - gcry_mpi_release (e); - gcry_mpi_release (d); - if (q != NULL) - gcry_mpi_release (q); - return NULL; - } + LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); + gcry_mpi_release (n); + gcry_mpi_release (e); + gcry_mpi_release (d); + if (q != NULL) + gcry_mpi_release (q); + return NULL; } + } else p = NULL; pos += ntohs (encoding->sizedmp1); pos += ntohs (encoding->sizedmq1); size = - ntohs (encoding->len) - sizeof (struct RsaPrivateKeyBinaryEncoded) - pos; + ntohs (encoding->len) - sizeof (struct RsaPrivateKeyBinaryEncoded) - pos; if (size > 0) + { + rc = gcry_mpi_scan (&u, GCRYMPI_FMT_USG, + &((const unsigned char *) (&encoding[1]))[pos], size, + &size); + if (rc) { - rc = gcry_mpi_scan (&u, GCRYMPI_FMT_USG, - &((const unsigned char *) (&encoding[1]))[pos], - size, &size); - if (rc) - { - LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); - gcry_mpi_release (n); - gcry_mpi_release (e); - gcry_mpi_release (d); - if (p != NULL) - gcry_mpi_release (p); - if (q != NULL) - gcry_mpi_release (q); - return NULL; - } + LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); + gcry_mpi_release (n); + gcry_mpi_release (e); + gcry_mpi_release (d); + if (p != NULL) + gcry_mpi_release (p); + if (q != NULL) + gcry_mpi_release (q); + return NULL; } + } else u = NULL; if ((p != NULL) && (q != NULL) && (u != NULL)) + { + rc = gcry_sexp_build (&res, &size, /* erroff */ + "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)(u %m)))", + n, e, d, p, q, u); + } + else + { + if ((p != NULL) && (q != NULL)) { - rc = gcry_sexp_build (&res, &size, /* erroff */ - "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)(u %m)))", - n, e, d, p, q, u); + rc = gcry_sexp_build (&res, &size, /* erroff */ + "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)))", + n, e, d, p, q); } - else + else { - if ((p != NULL) && (q != NULL)) - { - rc = gcry_sexp_build (&res, &size, /* erroff */ - "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)))", - n, e, d, p, q); - } - else - { - rc = gcry_sexp_build (&res, &size, /* erroff */ - "(private-key(rsa(n %m)(e %m)(d %m)))", n, e, - d); - } + rc = gcry_sexp_build (&res, &size, /* erroff */ + "(private-key(rsa(n %m)(e %m)(d %m)))", n, e, d); } + } gcry_mpi_release (n); gcry_mpi_release (e); gcry_mpi_release (d); @@ -542,10 +537,10 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len) LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc); #if EXTRA_CHECKS if (gcry_pk_testkey (res)) - { - LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc); - return NULL; - } + { + LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc); + return NULL; + } #endif ret = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPrivateKey)); ret->sexp = res; @@ -582,172 +577,165 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename)) return NULL; while (GNUNET_YES != GNUNET_DISK_file_test (filename)) + { + fd = GNUNET_DISK_file_open (filename, + GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE + | GNUNET_DISK_OPEN_FAILIFEXISTS, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE); + if (NULL == fd) { - fd = GNUNET_DISK_file_open (filename, - GNUNET_DISK_OPEN_WRITE | - GNUNET_DISK_OPEN_CREATE | - GNUNET_DISK_OPEN_FAILIFEXISTS, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE); - if (NULL == fd) - { - if (errno == EEXIST) - { - if (GNUNET_YES != GNUNET_DISK_file_test (filename)) - { - /* must exist but not be accessible, fail for good! */ - if (0 != ACCESS (filename, R_OK)) - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", - filename); - else - GNUNET_break (0); /* what is going on!? */ - return NULL; - } - continue; - } - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename); - return NULL; - } - cnt = 0; - - while (GNUNET_YES != - GNUNET_DISK_file_lock (fd, 0, - sizeof (struct - RsaPrivateKeyBinaryEncoded), - GNUNET_YES)) - { - sleep (1); - if (0 == ++cnt % 10) - { - ec = errno; - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Could not aquire lock on file `%s': %s...\n"), filename, - STRERROR (ec)); - } - } - LOG (GNUNET_ERROR_TYPE_INFO, - _("Creating a new private key. This may take a while.\n")); - ret = GNUNET_CRYPTO_rsa_key_create (); - GNUNET_assert (ret != NULL); - enc = rsa_encode_key (ret); - GNUNET_assert (enc != NULL); - GNUNET_assert (ntohs (enc->len) == - GNUNET_DISK_file_write (fd, enc, ntohs (enc->len))); - GNUNET_free (enc); - - GNUNET_DISK_file_sync (fd); - if (GNUNET_YES != - GNUNET_DISK_file_unlock (fd, 0, - sizeof (struct - RsaPrivateKeyBinaryEncoded))) - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); - GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); - GNUNET_CRYPTO_rsa_key_get_public (ret, &pub); - GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey); - LOG (GNUNET_ERROR_TYPE_INFO, - _("I am host `%s'. Stored new private key in `%s'.\n"), - GNUNET_i2s (&pid), filename); - return ret; + if (errno == EEXIST) + { + if (GNUNET_YES != GNUNET_DISK_file_test (filename)) + { + /* must exist but not be accessible, fail for good! */ + if (0 != ACCESS (filename, R_OK)) + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", filename); + else + GNUNET_break (0); /* what is going on!? */ + return NULL; + } + continue; + } + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename); + return NULL; + } + cnt = 0; + + while (GNUNET_YES != + GNUNET_DISK_file_lock (fd, 0, + sizeof (struct RsaPrivateKeyBinaryEncoded), + GNUNET_YES)) + { + sleep (1); + if (0 == ++cnt % 10) + { + ec = errno; + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Could not aquire lock on file `%s': %s...\n"), filename, + STRERROR (ec)); + } } + LOG (GNUNET_ERROR_TYPE_INFO, + _("Creating a new private key. This may take a while.\n")); + ret = GNUNET_CRYPTO_rsa_key_create (); + GNUNET_assert (ret != NULL); + enc = rsa_encode_key (ret); + GNUNET_assert (enc != NULL); + GNUNET_assert (ntohs (enc->len) == + GNUNET_DISK_file_write (fd, enc, ntohs (enc->len))); + GNUNET_free (enc); + + GNUNET_DISK_file_sync (fd); + if (GNUNET_YES != + GNUNET_DISK_file_unlock (fd, 0, + sizeof (struct RsaPrivateKeyBinaryEncoded))) + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); + GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); + GNUNET_CRYPTO_rsa_key_get_public (ret, &pub); + GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey); + LOG (GNUNET_ERROR_TYPE_INFO, + _("I am host `%s'. Stored new private key in `%s'.\n"), + GNUNET_i2s (&pid), filename); + return ret; + } /* hostkey file exists already, read it! */ fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, - GNUNET_DISK_PERM_NONE); + GNUNET_DISK_PERM_NONE); if (NULL == fd) + { + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename); + return NULL; + } + cnt = 0; + while (1) + { + if (GNUNET_YES != + GNUNET_DISK_file_lock (fd, 0, + sizeof (struct RsaPrivateKeyBinaryEncoded), + GNUNET_NO)) { - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename); + if (0 == ++cnt % 60) + { + ec = errno; + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Could not aquire lock on file `%s': %s...\n"), filename, + STRERROR (ec)); + LOG (GNUNET_ERROR_TYPE_ERROR, + _ + ("This may be ok if someone is currently generating a hostkey.\n")); + } + sleep (1); + continue; + } + if (GNUNET_YES != GNUNET_DISK_file_test (filename)) + { + /* eh, what!? File we opened is now gone!? */ + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", filename); + if (GNUNET_YES != + GNUNET_DISK_file_unlock (fd, 0, + sizeof (struct RsaPrivateKeyBinaryEncoded))) + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); + GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); + return NULL; } - cnt = 0; - while (1) + if (GNUNET_YES != GNUNET_DISK_file_size (filename, &fs, GNUNET_YES)) + fs = 0; + if (fs < sizeof (struct RsaPrivateKeyBinaryEncoded)) { + /* maybe we got the read lock before the hostkey generating + * process had a chance to get the write lock; give it up! */ if (GNUNET_YES != - GNUNET_DISK_file_lock (fd, 0, - sizeof (struct RsaPrivateKeyBinaryEncoded), - GNUNET_NO)) - { - if (0 == ++cnt % 60) - { - ec = errno; - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Could not aquire lock on file `%s': %s...\n"), filename, - STRERROR (ec)); - LOG (GNUNET_ERROR_TYPE_ERROR, - _ - ("This may be ok if someone is currently generating a hostkey.\n")); - } - sleep (1); - continue; - } - if (GNUNET_YES != GNUNET_DISK_file_test (filename)) - { - /* eh, what!? File we opened is now gone!? */ - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", filename); - if (GNUNET_YES != - GNUNET_DISK_file_unlock (fd, 0, - sizeof (struct - RsaPrivateKeyBinaryEncoded))) - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); - GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); - - return NULL; - } - if (GNUNET_YES != GNUNET_DISK_file_size (filename, &fs, GNUNET_YES)) - fs = 0; - if (fs < sizeof (struct RsaPrivateKeyBinaryEncoded)) - { - /* maybe we got the read lock before the hostkey generating - * process had a chance to get the write lock; give it up! */ - if (GNUNET_YES != - GNUNET_DISK_file_unlock (fd, 0, - sizeof (struct - RsaPrivateKeyBinaryEncoded))) - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); - if (0 == ++cnt % 10) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _ - ("When trying to read hostkey file `%s' I found %u bytes but I need at least %u.\n"), - filename, (unsigned int) fs, - (unsigned int) sizeof (struct RsaPrivateKeyBinaryEncoded)); - LOG (GNUNET_ERROR_TYPE_ERROR, - _ - ("This may be ok if someone is currently generating a hostkey.\n")); - } - sleep (2); /* wait a bit longer! */ - continue; - } - break; + GNUNET_DISK_file_unlock (fd, 0, + sizeof (struct RsaPrivateKeyBinaryEncoded))) + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); + if (0 == ++cnt % 10) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _ + ("When trying to read hostkey file `%s' I found %u bytes but I need at least %u.\n"), + filename, (unsigned int) fs, + (unsigned int) sizeof (struct RsaPrivateKeyBinaryEncoded)); + LOG (GNUNET_ERROR_TYPE_ERROR, + _ + ("This may be ok if someone is currently generating a hostkey.\n")); + } + sleep (2); /* wait a bit longer! */ + continue; } + break; + } enc = GNUNET_malloc (fs); GNUNET_assert (fs == GNUNET_DISK_file_read (fd, enc, fs)); len = ntohs (enc->len); ret = NULL; if ((len != fs) || (NULL == (ret = GNUNET_CRYPTO_rsa_decode_key ((char *) enc, len)))) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _("File `%s' does not contain a valid private key. Deleting it.\n"), + filename); + if (0 != UNLINK (filename)) { - LOG (GNUNET_ERROR_TYPE_ERROR, - _ - ("File `%s' does not contain a valid private key. Deleting it.\n"), - filename); - if (0 != UNLINK (filename)) - { - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); - } + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); } + } GNUNET_free (enc); if (GNUNET_YES != GNUNET_DISK_file_unlock (fd, 0, - sizeof (struct RsaPrivateKeyBinaryEncoded))) + sizeof (struct RsaPrivateKeyBinaryEncoded))) LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); if (ret != NULL) - { - GNUNET_CRYPTO_rsa_key_get_public (ret, &pub); - GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey); - LOG (GNUNET_ERROR_TYPE_INFO, - _("I am host `%s'. Read private key from `%s'.\n"), - GNUNET_i2s (&pid), filename); - } + { + GNUNET_CRYPTO_rsa_key_get_public (ret, &pub); + GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey); + LOG (GNUNET_ERROR_TYPE_INFO, + _("I am host `%s'. Read private key from `%s'.\n"), GNUNET_i2s (&pid), + filename); + } return ret; } @@ -764,9 +752,9 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) */ int GNUNET_CRYPTO_rsa_encrypt (const void *block, size_t size, - const struct - GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey, - struct GNUNET_CRYPTO_RsaEncryptedData *target) + const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded + *publicKey, + struct GNUNET_CRYPTO_RsaEncryptedData *target) { gcry_sexp_t result; gcry_sexp_t data; @@ -782,10 +770,10 @@ GNUNET_CRYPTO_rsa_encrypt (const void *block, size_t size, return GNUNET_SYSERR; isize = size; GNUNET_assert (0 == - gcry_mpi_scan (&val, GCRYMPI_FMT_USG, block, isize, &isize)); + gcry_mpi_scan (&val, GCRYMPI_FMT_USG, block, isize, &isize)); GNUNET_assert (0 == - gcry_sexp_build (&data, &erroff, - "(data (flags pkcs1)(value %m))", val)); + gcry_sexp_build (&data, &erroff, + "(data (flags pkcs1)(value %m))", val)); gcry_mpi_release (val); GNUNET_assert (0 == gcry_pk_encrypt (&result, data, pubkey->sexp)); gcry_sexp_release (data); @@ -795,11 +783,11 @@ GNUNET_CRYPTO_rsa_encrypt (const void *block, size_t size, gcry_sexp_release (result); isize = sizeof (struct GNUNET_CRYPTO_RsaEncryptedData); GNUNET_assert (0 == - gcry_mpi_print (GCRYMPI_FMT_USG, (unsigned char *) target, - isize, &isize, rval)); + gcry_mpi_print (GCRYMPI_FMT_USG, (unsigned char *) target, + isize, &isize, rval)); gcry_mpi_release (rval); adjust (&target->encoding[0], isize, - sizeof (struct GNUNET_CRYPTO_RsaEncryptedData)); + sizeof (struct GNUNET_CRYPTO_RsaEncryptedData)); return GNUNET_OK; } @@ -815,8 +803,8 @@ GNUNET_CRYPTO_rsa_encrypt (const void *block, size_t size, */ ssize_t GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey * key, - const struct GNUNET_CRYPTO_RsaEncryptedData * - block, void *result, size_t max) + const struct GNUNET_CRYPTO_RsaEncryptedData * block, + void *result, size_t max) { gcry_sexp_t resultsexp; gcry_sexp_t data; @@ -831,22 +819,21 @@ GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey * key, #endif size = sizeof (struct GNUNET_CRYPTO_RsaEncryptedData); GNUNET_assert (0 == - gcry_mpi_scan (&val, GCRYMPI_FMT_USG, &block->encoding[0], - size, &size)); + gcry_mpi_scan (&val, GCRYMPI_FMT_USG, &block->encoding[0], + size, &size)); GNUNET_assert (0 == - gcry_sexp_build (&data, &erroff, - "(enc-val(flags)(rsa(a %m)))", val)); + gcry_sexp_build (&data, &erroff, "(enc-val(flags)(rsa(a %m)))", + val)); gcry_mpi_release (val); GNUNET_assert (0 == gcry_pk_decrypt (&resultsexp, data, key->sexp)); gcry_sexp_release (data); /* resultsexp has format "(value %m)" */ GNUNET_assert (NULL != - (val = gcry_sexp_nth_mpi (resultsexp, 1, GCRYMPI_FMT_USG))); + (val = gcry_sexp_nth_mpi (resultsexp, 1, GCRYMPI_FMT_USG))); gcry_sexp_release (resultsexp); tmp = GNUNET_malloc (max + HOSTKEY_LEN / 8); size = max + HOSTKEY_LEN / 8; - GNUNET_assert (0 == - gcry_mpi_print (GCRYMPI_FMT_USG, tmp, size, &size, val)); + GNUNET_assert (0 == gcry_mpi_print (GCRYMPI_FMT_USG, tmp, size, &size, val)); gcry_mpi_release (val); endp = tmp; endp += (size - max); @@ -867,8 +854,8 @@ GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey * key, */ int GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_RsaPrivateKey *key, - const struct GNUNET_CRYPTO_RsaSignaturePurpose - *purpose, struct GNUNET_CRYPTO_RsaSignature *sig) + const struct GNUNET_CRYPTO_RsaSignaturePurpose *purpose, + struct GNUNET_CRYPTO_RsaSignature *sig) { gcry_sexp_t result; gcry_sexp_t data; @@ -884,10 +871,10 @@ GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_RsaPrivateKey *key, buff = GNUNET_malloc (bufSize); memcpy (buff, FORMATSTRING, bufSize); memcpy (&buff - [bufSize - - strlen - ("0123456789012345678901234567890123456789012345678901234567890123))") - - 1], &hc, sizeof (GNUNET_HashCode)); + [bufSize - + strlen + ("0123456789012345678901234567890123456789012345678901234567890123))") + - 1], &hc, sizeof (GNUNET_HashCode)); GNUNET_assert (0 == gcry_sexp_new (&data, buff, bufSize, 0)); GNUNET_free (buff); GNUNET_assert (0 == gcry_pk_sign (&result, data, key->sexp)); @@ -896,8 +883,8 @@ GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_RsaPrivateKey *key, gcry_sexp_release (result); ssize = sizeof (struct GNUNET_CRYPTO_RsaSignature); GNUNET_assert (0 == - gcry_mpi_print (GCRYMPI_FMT_USG, (unsigned char *) sig, - ssize, &ssize, rval)); + gcry_mpi_print (GCRYMPI_FMT_USG, (unsigned char *) sig, ssize, + &ssize, rval)); gcry_mpi_release (rval); adjust (sig->sig, ssize, sizeof (struct GNUNET_CRYPTO_RsaSignature)); return GNUNET_OK; @@ -915,11 +902,11 @@ GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_RsaPrivateKey *key, */ int GNUNET_CRYPTO_rsa_verify (uint32_t purpose, - const struct GNUNET_CRYPTO_RsaSignaturePurpose - *validate, - const struct GNUNET_CRYPTO_RsaSignature *sig, - const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded - *publicKey) + const struct GNUNET_CRYPTO_RsaSignaturePurpose + *validate, + const struct GNUNET_CRYPTO_RsaSignature *sig, + const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded + *publicKey) { gcry_sexp_t data; gcry_sexp_t sigdata; @@ -933,44 +920,44 @@ GNUNET_CRYPTO_rsa_verify (uint32_t purpose, int rc; if (purpose != ntohl (validate->purpose)) - return GNUNET_SYSERR; /* purpose mismatch */ + return GNUNET_SYSERR; /* purpose mismatch */ GNUNET_CRYPTO_hash (validate, ntohl (validate->size), &hc); size = sizeof (struct GNUNET_CRYPTO_RsaSignature); GNUNET_assert (0 == - gcry_mpi_scan (&val, GCRYMPI_FMT_USG, - (const unsigned char *) sig, size, &size)); + gcry_mpi_scan (&val, GCRYMPI_FMT_USG, + (const unsigned char *) sig, size, &size)); GNUNET_assert (0 == - gcry_sexp_build (&sigdata, &erroff, "(sig-val(rsa(s %m)))", - val)); + gcry_sexp_build (&sigdata, &erroff, "(sig-val(rsa(s %m)))", + val)); gcry_mpi_release (val); bufSize = strlen (FORMATSTRING) + 1; buff = GNUNET_malloc (bufSize); memcpy (buff, FORMATSTRING, bufSize); memcpy (&buff - [strlen (FORMATSTRING) - - strlen - ("0123456789012345678901234567890123456789012345678901234567890123))")], - &hc, sizeof (GNUNET_HashCode)); + [strlen (FORMATSTRING) - + strlen + ("0123456789012345678901234567890123456789012345678901234567890123))")], + &hc, sizeof (GNUNET_HashCode)); GNUNET_assert (0 == gcry_sexp_new (&data, buff, bufSize, 0)); GNUNET_free (buff); hostkey = public2PrivateKey (publicKey); if (hostkey == NULL) - { - gcry_sexp_release (data); - gcry_sexp_release (sigdata); - return GNUNET_SYSERR; - } + { + gcry_sexp_release (data); + gcry_sexp_release (sigdata); + return GNUNET_SYSERR; + } rc = gcry_pk_verify (sigdata, data, hostkey->sexp); GNUNET_CRYPTO_rsa_key_free (hostkey); gcry_sexp_release (data); gcry_sexp_release (sigdata); if (rc) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - _("RSA signature verification failed at %s:%d: %s\n"), __FILE__, - __LINE__, gcry_strerror (rc)); - return GNUNET_SYSERR; - } + { + LOG (GNUNET_ERROR_TYPE_WARNING, + _("RSA signature verification failed at %s:%d: %s\n"), __FILE__, + __LINE__, gcry_strerror (rc)); + return GNUNET_SYSERR; + } return GNUNET_OK; } diff --git a/src/util/disk.c b/src/util/disk.c index 12f985791..2bdcf3262 100644 --- a/src/util/disk.c +++ b/src/util/disk.c @@ -67,8 +67,8 @@ #define PIPE_BUF 512 ULONG PipeSerialNumber; #endif -#define _IFMT 0170000 /* type of file */ -#define _IFLNK 0120000 /* symbolic link */ +#define _IFMT 0170000 /* type of file */ +#define _IFLNK 0120000 /* symbolic link */ #define S_ISLNK(m) (((m)&_IFMT) == _IFLNK) #else #error PORT-ME: need to port statfs (how much space is left on the drive?) @@ -165,25 +165,25 @@ getSizeRec (void *cls, const char *fn) #ifdef HAVE_STAT64 if (0 != STAT64 (fn, &buf)) - { - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat64", fn); - return GNUNET_SYSERR; - } + { + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat64", fn); + return GNUNET_SYSERR; + } #else if (0 != STAT (fn, &buf)) - { - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", fn); - return GNUNET_SYSERR; - } + { + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", fn); + return GNUNET_SYSERR; + } #endif if ((!S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES)) gfsd->total += buf.st_size; if ((S_ISDIR (buf.st_mode)) && (0 == ACCESS (fn, X_OK)) && ((!S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES))) - { - if (GNUNET_SYSERR == GNUNET_DISK_directory_scan (fn, &getSizeRec, gfsd)) - return GNUNET_SYSERR; - } + { + if (GNUNET_SYSERR == GNUNET_DISK_directory_scan (fn, &getSizeRec, gfsd)) + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -215,13 +215,13 @@ GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h) */ off_t GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle * h, off_t offset, - enum GNUNET_DISK_Seek whence) + enum GNUNET_DISK_Seek whence) { if (h == NULL) - { - errno = EINVAL; - return GNUNET_SYSERR; - } + { + errno = EINVAL; + return GNUNET_SYSERR; + } #ifdef MINGW DWORD ret; @@ -232,10 +232,10 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle * h, off_t offset, ret = SetFilePointer (h->h, offset, NULL, t[whence]); if (ret == INVALID_SET_FILE_POINTER) - { - SetErrnoFromWinError (GetLastError ()); - return GNUNET_SYSERR; - } + { + SetErrnoFromWinError (GetLastError ()); + return GNUNET_SYSERR; + } return ret; #else static int t[] = {[GNUNET_DISK_SEEK_SET] = SEEK_SET, @@ -261,7 +261,7 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle * h, off_t offset, */ int GNUNET_DISK_file_size (const char *filename, uint64_t * size, - int includeSymLinks) + int includeSymLinks) { struct GetFileSizeData gfsd; int ret; @@ -292,29 +292,29 @@ GNUNET_DISK_file_size (const char *filename, uint64_t * size, */ int GNUNET_DISK_file_get_identifiers (const char *filename, uint64_t * dev, - uint64_t * ino) + uint64_t * ino) { #if LINUX struct stat sbuf; struct statvfs fbuf; if ((0 == stat (filename, &sbuf)) && (0 == statvfs (filename, &fbuf))) - { - *dev = (uint64_t) fbuf.f_fsid; - *ino = (uint64_t) sbuf.st_ino; - return GNUNET_OK; - } + { + *dev = (uint64_t) fbuf.f_fsid; + *ino = (uint64_t) sbuf.st_ino; + return GNUNET_OK; + } #elif SOMEBSD struct stat sbuf; struct statfs fbuf; if ((0 == stat (filename, &sbuf)) && (0 == statfs (filename, &fbuf))) - { - *dev = ((uint64_t) fbuf.f_fsid.val[0]) << 32 || - ((uint64_t) fbuf.f_fsid.val[1]); - *ino = (uint64_t) sbuf.st_ino; - return GNUNET_OK; - } + { + *dev = ((uint64_t) fbuf.f_fsid.val[0]) << 32 || + ((uint64_t) fbuf.f_fsid.val[1]); + *ino = (uint64_t) sbuf.st_ino; + return GNUNET_OK; + } #elif WINDOWS // FIXME NILS: test this struct GNUNET_DISK_FileHandle *fh; @@ -327,11 +327,11 @@ GNUNET_DISK_file_get_identifiers (const char *filename, uint64_t * dev, succ = GetFileInformationByHandle (fh->h, &info); GNUNET_DISK_file_close (fh); if (succ) - { - *dev = info.dwVolumeSerialNumber; - *ino = ((info.nFileIndexHigh << sizeof (DWORD)) | info.nFileIndexLow); - return GNUNET_OK; - } + { + *dev = info.dwVolumeSerialNumber; + *ino = ((info.nFileIndexHigh << sizeof (DWORD)) | info.nFileIndexLow); + return GNUNET_OK; + } else return GNUNET_SYSERR; @@ -363,35 +363,35 @@ GNUNET_DISK_mktemp (const char *t) #if WINDOWS && !(isalpha ((int) t[0]) && (t[0] != '\0') && (t[1] == ':')) #endif - ) - { - tmpdir = getenv ("TMPDIR"); - tmpdir = tmpdir ? tmpdir : "/tmp"; - GNUNET_asprintf (&tmpl, "%s/%s%s", tmpdir, t, "XXXXXX"); - } + ) + { + tmpdir = getenv ("TMPDIR"); + tmpdir = tmpdir ? tmpdir : "/tmp"; + GNUNET_asprintf (&tmpl, "%s/%s%s", tmpdir, t, "XXXXXX"); + } else - { - GNUNET_asprintf (&tmpl, "%s%s", t, "XXXXXX"); - } + { + GNUNET_asprintf (&tmpl, "%s%s", t, "XXXXXX"); + } #ifdef MINGW fn = (char *) GNUNET_malloc (MAX_PATH + 1); if (ERROR_SUCCESS != plibc_conv_to_win_path (tmpl, fn)) - { - GNUNET_free (fn); - GNUNET_free (tmpl); - return NULL; - } + { + GNUNET_free (fn); + GNUNET_free (tmpl); + return NULL; + } GNUNET_free (tmpl); #else fn = tmpl; #endif fd = mkstemp (fn); if (fd == -1) - { - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "mkstemp", fn); - GNUNET_free (fn); - return NULL; - } + { + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "mkstemp", fn); + GNUNET_free (fn); + return NULL; + } if (0 != CLOSE (fd)) LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "close", fn); return fn; @@ -412,10 +412,10 @@ GNUNET_DISK_get_blocks_available (const char *part) struct statvfs buf; if (0 != statvfs (part, &buf)) - { - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "statfs", part); - return -1; - } + { + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "statfs", part); + return -1; + } return buf.f_bavail; #elif MINGW DWORD dwDummy; @@ -430,22 +430,21 @@ GNUNET_DISK_get_blocks_available (const char *part) GNUNET_free (path); szDrive[3] = 0; if (!GetDiskFreeSpace (szDrive, &dwDummy, &dwDummy, &dwBlocks, &dwDummy)) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - _("`%s' failed for drive `%s': %u\n"), "GetDiskFreeSpace", - szDrive, GetLastError ()); + { + LOG (GNUNET_ERROR_TYPE_WARNING, _("`%s' failed for drive `%s': %u\n"), + "GetDiskFreeSpace", szDrive, GetLastError ()); - return -1; - } + return -1; + } return dwBlocks; #else struct statfs s; if (0 != statfs (part, &s)) - { - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "statfs", part); - return -1; - } + { + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "statfs", part); + return -1; + } return s.f_bavail; #endif } @@ -469,21 +468,21 @@ GNUNET_DISK_directory_test (const char *fil) ret = STAT (fil, &filestat); if (ret != 0) + { + if (errno != ENOENT) { - if (errno != ENOENT) - { - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", fil); - return GNUNET_SYSERR; - } - return GNUNET_NO; + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", fil); + return GNUNET_SYSERR; } + return GNUNET_NO; + } if (!S_ISDIR (filestat.st_mode)) return GNUNET_NO; if (ACCESS (fil, R_OK | X_OK) < 0) - { - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", fil); - return GNUNET_SYSERR; - } + { + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", fil); + return GNUNET_SYSERR; + } return GNUNET_YES; } @@ -508,27 +507,27 @@ GNUNET_DISK_file_test (const char *fil) ret = STAT (rdir, &filestat); if (ret != 0) + { + if (errno != ENOENT) { - if (errno != ENOENT) - { - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", rdir); - GNUNET_free (rdir); - return GNUNET_SYSERR; - } + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", rdir); GNUNET_free (rdir); - return GNUNET_NO; + return GNUNET_SYSERR; } + GNUNET_free (rdir); + return GNUNET_NO; + } if (!S_ISREG (filestat.st_mode)) - { - GNUNET_free (rdir); - return GNUNET_NO; - } + { + GNUNET_free (rdir); + return GNUNET_NO; + } if (ACCESS (rdir, R_OK) < 0) - { - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", rdir); - GNUNET_free (rdir); - return GNUNET_SYSERR; - } + { + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", rdir); + GNUNET_free (rdir); + return GNUNET_SYSERR; + } GNUNET_free (rdir); return GNUNET_YES; } @@ -553,56 +552,56 @@ GNUNET_DISK_directory_create (const char *dir) len = strlen (rdir); #ifndef MINGW - pos = 1; /* skip heading '/' */ + pos = 1; /* skip heading '/' */ #else /* Local or Network path? */ if (strncmp (rdir, "\\\\", 2) == 0) + { + pos = 2; + while (rdir[pos]) { - pos = 2; - while (rdir[pos]) - { - if (rdir[pos] == '\\') - { - pos++; - break; - } - pos++; - } + if (rdir[pos] == '\\') + { + pos++; + break; + } + pos++; } + } else - { - pos = 3; /* strlen("C:\\") */ - } + { + pos = 3; /* strlen("C:\\") */ + } #endif while (pos <= len) + { + if ((rdir[pos] == DIR_SEPARATOR) || (pos == len)) { - if ((rdir[pos] == DIR_SEPARATOR) || (pos == len)) - { - rdir[pos] = '\0'; - ret = GNUNET_DISK_directory_test (rdir); - if (ret == GNUNET_SYSERR) - { - GNUNET_free (rdir); - return GNUNET_SYSERR; - } - if (ret == GNUNET_NO) - { + rdir[pos] = '\0'; + ret = GNUNET_DISK_directory_test (rdir); + if (ret == GNUNET_SYSERR) + { + GNUNET_free (rdir); + return GNUNET_SYSERR; + } + if (ret == GNUNET_NO) + { #ifndef MINGW - ret = mkdir (rdir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); /* 755 */ + ret = mkdir (rdir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); /* 755 */ #else - ret = mkdir (rdir); + ret = mkdir (rdir); #endif - if ((ret != 0) && (errno != EEXIST)) - { - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "mkdir", rdir); - GNUNET_free (rdir); - return GNUNET_SYSERR; - } - } - rdir[pos] = DIR_SEPARATOR; - } - pos++; + if ((ret != 0) && (errno != EEXIST)) + { + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "mkdir", rdir); + GNUNET_free (rdir); + return GNUNET_SYSERR; + } + } + rdir[pos] = DIR_SEPARATOR; } + pos++; + } GNUNET_free (rdir); return GNUNET_OK; } @@ -649,37 +648,37 @@ GNUNET_DISK_directory_create_for_file (const char *filename) */ ssize_t GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle * h, void *result, - size_t len) + size_t len) { if (h == NULL) - { - errno = EINVAL; - return GNUNET_SYSERR; - } + { + errno = EINVAL; + return GNUNET_SYSERR; + } #ifdef MINGW DWORD bytesRead; if (h->type != GNUNET_PIPE) + { + if (!ReadFile (h->h, result, len, &bytesRead, NULL)) { - if (!ReadFile (h->h, result, len, &bytesRead, NULL)) - { - SetErrnoFromWinError (GetLastError ()); - return GNUNET_SYSERR; - } + SetErrnoFromWinError (GetLastError ()); + return GNUNET_SYSERR; } + } else + { + if (!ReadFile (h->h, result, len, NULL, h->oOverlapRead)) { - if (!ReadFile (h->h, result, len, NULL, h->oOverlapRead)) - { - if (GetLastError () != ERROR_IO_PENDING) - { - SetErrnoFromWinError (GetLastError ()); - return GNUNET_SYSERR; - } - } - GetOverlappedResult (h->h, h->oOverlapRead, &bytesRead, TRUE); + if (GetLastError () != ERROR_IO_PENDING) + { + SetErrnoFromWinError (GetLastError ()); + return GNUNET_SYSERR; + } } + GetOverlappedResult (h->h, h->oOverlapRead, &bytesRead, TRUE); + } return bytesRead; #else return read (h->fd, result, len); @@ -701,8 +700,7 @@ GNUNET_DISK_fn_read (const char *fn, void *result, size_t len) struct GNUNET_DISK_FileHandle *fh; ssize_t ret; - fh = - GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE); + fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE); if (!fh) return GNUNET_SYSERR; ret = GNUNET_DISK_file_read (fh, result, len); @@ -721,46 +719,46 @@ GNUNET_DISK_fn_read (const char *fn, void *result, size_t len) */ ssize_t GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h, - const void *buffer, size_t n) + const void *buffer, size_t n) { if (h == NULL) - { - errno = EINVAL; - return GNUNET_SYSERR; - } + { + errno = EINVAL; + return GNUNET_SYSERR; + } #ifdef MINGW DWORD bytesWritten; if (h->type != GNUNET_PIPE) + { + if (!WriteFile (h->h, buffer, n, &bytesWritten, NULL)) { - if (!WriteFile (h->h, buffer, n, &bytesWritten, NULL)) - { - SetErrnoFromWinError (GetLastError ()); - return GNUNET_SYSERR; - } + SetErrnoFromWinError (GetLastError ()); + return GNUNET_SYSERR; } + } else - { + { #if DEBUG_PIPE - LOG (GNUNET_ERROR_TYPE_DEBUG, "It is a pipe trying to write\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "It is a pipe trying to write\n"); #endif - if (!WriteFile (h->h, buffer, n, NULL, h->oOverlapWrite)) - { - if (GetLastError () != ERROR_IO_PENDING) - { - SetErrnoFromWinError (GetLastError ()); + if (!WriteFile (h->h, buffer, n, NULL, h->oOverlapWrite)) + { + if (GetLastError () != ERROR_IO_PENDING) + { + SetErrnoFromWinError (GetLastError ()); #if DEBUG_PIPE - LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe\n"); #endif - return GNUNET_SYSERR; - } - } + return GNUNET_SYSERR; + } + } #if DEBUG_PIPE - LOG (GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n"); #endif - GetOverlappedResult (h->h, h->oOverlapWrite, &bytesWritten, TRUE); - } + GetOverlappedResult (h->h, h->oOverlapWrite, &bytesWritten, TRUE); + } return bytesWritten; #else return write (h->fd, buffer, n); @@ -779,15 +777,14 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h, */ ssize_t GNUNET_DISK_fn_write (const char *fn, const void *buffer, size_t n, - enum GNUNET_DISK_AccessPermissions mode) + enum GNUNET_DISK_AccessPermissions mode) { struct GNUNET_DISK_FileHandle *fh; ssize_t ret; fh = GNUNET_DISK_file_open (fn, - GNUNET_DISK_OPEN_WRITE | - GNUNET_DISK_OPEN_TRUNCATE | - GNUNET_DISK_OPEN_CREATE, mode); + GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE + | GNUNET_DISK_OPEN_CREATE, mode); if (!fh) return GNUNET_SYSERR; ret = GNUNET_DISK_file_write (fh, buffer, n); @@ -808,8 +805,8 @@ GNUNET_DISK_fn_write (const char *fn, const void *buffer, size_t n, */ int GNUNET_DISK_directory_scan (const char *dirName, - GNUNET_FileNameCallback callback, - void *callback_cls) + GNUNET_FileNameCallback callback, + void *callback_cls) { DIR *dinfo; struct dirent *finfo; @@ -827,61 +824,61 @@ GNUNET_DISK_directory_scan (const char *dirName, while ((strlen (dname) > 0) && (dname[strlen (dname) - 1] == DIR_SEPARATOR)) dname[strlen (dname) - 1] = '\0'; if (0 != STAT (dname, &istat)) - { - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", dname); - GNUNET_free (dname); - return GNUNET_SYSERR; - } + { + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", dname); + GNUNET_free (dname); + return GNUNET_SYSERR; + } if (!S_ISDIR (istat.st_mode)) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - _("Expected `%s' to be a directory!\n"), dirName); - GNUNET_free (dname); - return GNUNET_SYSERR; - } + { + LOG (GNUNET_ERROR_TYPE_WARNING, _("Expected `%s' to be a directory!\n"), + dirName); + GNUNET_free (dname); + return GNUNET_SYSERR; + } errno = 0; dinfo = OPENDIR (dname); if ((errno == EACCES) || (dinfo == NULL)) - { - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "opendir", dname); - if (dinfo != NULL) - closedir (dinfo); - GNUNET_free (dname); - return GNUNET_SYSERR; - } + { + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "opendir", dname); + if (dinfo != NULL) + closedir (dinfo); + GNUNET_free (dname); + return GNUNET_SYSERR; + } name_len = 256; n_size = strlen (dname) + name_len + 2; name = GNUNET_malloc (n_size); while ((finfo = readdir (dinfo)) != NULL) + { + if ((0 == strcmp (finfo->d_name, ".")) || + (0 == strcmp (finfo->d_name, ".."))) + continue; + if (callback != NULL) { - if ((0 == strcmp (finfo->d_name, ".")) || - (0 == strcmp (finfo->d_name, ".."))) - continue; - if (callback != NULL) - { - if (name_len < strlen (finfo->d_name)) - { - GNUNET_free (name); - name_len = strlen (finfo->d_name); - n_size = strlen (dname) + name_len + 2; - name = GNUNET_malloc (n_size); - } - /* dname can end in "/" only if dname == "/"; - * if dname does not end in "/", we need to add - * a "/" (otherwise, we must not!) */ - GNUNET_snprintf (name, n_size, "%s%s%s", dname, - (strcmp (dname, DIR_SEPARATOR_STR) == - 0) ? "" : DIR_SEPARATOR_STR, finfo->d_name); - if (GNUNET_OK != callback (callback_cls, name)) - { - closedir (dinfo); - GNUNET_free (name); - GNUNET_free (dname); - return GNUNET_SYSERR; - } - } - count++; + if (name_len < strlen (finfo->d_name)) + { + GNUNET_free (name); + name_len = strlen (finfo->d_name); + n_size = strlen (dname) + name_len + 2; + name = GNUNET_malloc (n_size); + } + /* dname can end in "/" only if dname == "/"; + * if dname does not end in "/", we need to add + * a "/" (otherwise, we must not!) */ + GNUNET_snprintf (name, n_size, "%s%s%s", dname, + (strcmp (dname, DIR_SEPARATOR_STR) == + 0) ? "" : DIR_SEPARATOR_STR, finfo->d_name); + if (GNUNET_OK != callback (callback_cls, name)) + { + closedir (dinfo); + GNUNET_free (name); + GNUNET_free (dname); + return GNUNET_SYSERR; + } } + count++; + } closedir (dinfo); GNUNET_free (name); GNUNET_free (dname); @@ -933,7 +930,7 @@ struct GNUNET_DISK_DirectoryIterator */ static void directory_iterator_task (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) + const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_DISK_DirectoryIterator *iter = cls; char *name; @@ -958,35 +955,35 @@ directory_iterator_task (void *cls, * GNUNET_SYSERR if abort was YES */ int -GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator - *iter, int can) +GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator *iter, + int can) { struct dirent *finfo; GNUNET_assert (iter->next_name == NULL); if (can == GNUNET_YES) - { - closedir (iter->directory); - GNUNET_free (iter->dirname); - GNUNET_free (iter); - return GNUNET_SYSERR; - } + { + closedir (iter->directory); + GNUNET_free (iter->dirname); + GNUNET_free (iter); + return GNUNET_SYSERR; + } while (NULL != (finfo = readdir (iter->directory))) - { - if ((0 == strcmp (finfo->d_name, ".")) || - (0 == strcmp (finfo->d_name, ".."))) - continue; - GNUNET_asprintf (&iter->next_name, "%s%s%s", iter->dirname, - DIR_SEPARATOR_STR, finfo->d_name); - break; - } + { + if ((0 == strcmp (finfo->d_name, ".")) || + (0 == strcmp (finfo->d_name, ".."))) + continue; + GNUNET_asprintf (&iter->next_name, "%s%s%s", iter->dirname, + DIR_SEPARATOR_STR, finfo->d_name); + break; + } if (finfo == NULL) - { - GNUNET_DISK_directory_iterator_next (iter, GNUNET_YES); - return GNUNET_NO; - } - GNUNET_SCHEDULER_add_with_priority (iter->priority, - &directory_iterator_task, iter); + { + GNUNET_DISK_directory_iterator_next (iter, GNUNET_YES); + return GNUNET_NO; + } + GNUNET_SCHEDULER_add_with_priority (iter->priority, &directory_iterator_task, + iter); return GNUNET_YES; } @@ -1004,9 +1001,9 @@ GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator */ void GNUNET_DISK_directory_iterator_start (enum GNUNET_SCHEDULER_Priority prio, - const char *dirName, - GNUNET_DISK_DirectoryIteratorCallback - callback, void *callback_cls) + const char *dirName, + GNUNET_DISK_DirectoryIteratorCallback + callback, void *callback_cls) { struct GNUNET_DISK_DirectoryIterator *di; @@ -1015,11 +1012,11 @@ GNUNET_DISK_directory_iterator_start (enum GNUNET_SCHEDULER_Priority prio, di->callback_cls = callback_cls; di->directory = OPENDIR (dirName); if (di->directory == NULL) - { - GNUNET_free (di); - callback (callback_cls, NULL, NULL, NULL); - return; - } + { + GNUNET_free (di); + callback (callback_cls, NULL, NULL, NULL); + return; + } di->dirname = GNUNET_strdup (dirName); di->priority = prio; GNUNET_DISK_directory_iterator_next (di, GNUNET_NO); @@ -1056,7 +1053,7 @@ GNUNET_DISK_directory_remove (const char *fileName) struct stat istat; if (0 != LSTAT (fileName, &istat)) - return GNUNET_NO; /* file may not exist... */ + return GNUNET_NO; /* file may not exist... */ CHMOD (fileName, S_IWUSR | S_IRUSR | S_IXUSR); if (UNLINK (fileName) == 0) return GNUNET_OK; @@ -1065,18 +1062,18 @@ GNUNET_DISK_directory_remove (const char *fileName) * sticky /tmp directory may result in EPERM on BSD. * So we also explicitly check "isDirectory" */ (GNUNET_YES != GNUNET_DISK_directory_test (fileName))) - { - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "rmdir", fileName); - return GNUNET_SYSERR; - } + { + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "rmdir", fileName); + return GNUNET_SYSERR; + } if (GNUNET_SYSERR == GNUNET_DISK_directory_scan (fileName, &remove_helper, NULL)) return GNUNET_SYSERR; if (0 != RMDIR (fileName)) - { - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "rmdir", fileName); - return GNUNET_SYSERR; - } + { + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "rmdir", fileName); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -1102,34 +1099,34 @@ GNUNET_DISK_file_copy (const char *src, const char *dst) return GNUNET_SYSERR; pos = 0; in = GNUNET_DISK_file_open (src, GNUNET_DISK_OPEN_READ, - GNUNET_DISK_PERM_NONE); + GNUNET_DISK_PERM_NONE); if (!in) return GNUNET_SYSERR; out = - GNUNET_DISK_file_open (dst, - GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE | - GNUNET_DISK_OPEN_FAILIFEXISTS, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE | - GNUNET_DISK_PERM_GROUP_READ | - GNUNET_DISK_PERM_GROUP_WRITE); + GNUNET_DISK_file_open (dst, + GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE | + GNUNET_DISK_OPEN_FAILIFEXISTS, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE | + GNUNET_DISK_PERM_GROUP_READ | + GNUNET_DISK_PERM_GROUP_WRITE); if (!out) - { - GNUNET_DISK_file_close (in); - return GNUNET_SYSERR; - } + { + GNUNET_DISK_file_close (in); + return GNUNET_SYSERR; + } buf = GNUNET_malloc (COPY_BLK_SIZE); while (pos < size) - { - len = COPY_BLK_SIZE; - if (len > size - pos) - len = size - pos; - if (len != GNUNET_DISK_file_read (in, buf, len)) - goto FAIL; - if (len != GNUNET_DISK_file_write (out, buf, len)) - goto FAIL; - pos += len; - } + { + len = COPY_BLK_SIZE; + if (len > size - pos) + len = size - pos; + if (len != GNUNET_DISK_file_read (in, buf, len)) + goto FAIL; + if (len != GNUNET_DISK_file_write (out, buf, len)) + goto FAIL; + pos += len; + } GNUNET_free (buf); GNUNET_DISK_file_close (in); GNUNET_DISK_file_close (out); @@ -1154,17 +1151,17 @@ GNUNET_DISK_filename_canonicalize (char *fn) idx = fn; while (*idx) - { - c = *idx; - - if (c == '/' || c == '\\' || c == ':' || c == '*' || c == '?' - || c == '"' || c == '<' || c == '>' || c == '|') - { - *idx = '_'; - } + { + c = *idx; - idx++; + if (c == '/' || c == '\\' || c == ':' || c == '*' || c == '?' || c == '"' || + c == '<' || c == '>' || c == '|') + { + *idx = '_'; } + + idx++; + } } @@ -1184,12 +1181,12 @@ GNUNET_DISK_file_change_owner (const char *filename, const char *user) pws = getpwnam (user); if (pws == NULL) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Cannot obtain information about user `%s': %s\n"), user, - STRERROR (errno)); - return GNUNET_SYSERR; - } + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Cannot obtain information about user `%s': %s\n"), user, + STRERROR (errno)); + return GNUNET_SYSERR; + } if (0 != chown (filename, pws->pw_uid, pws->pw_gid)) LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "chown", filename); #endif @@ -1207,13 +1204,13 @@ GNUNET_DISK_file_change_owner (const char *filename, const char *user) */ int GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart, - off_t lockEnd, int excl) + off_t lockEnd, int excl) { if (fh == NULL) - { - errno = EINVAL; - return GNUNET_SYSERR; - } + { + errno = EINVAL; + return GNUNET_SYSERR; + } #ifndef MINGW struct flock fl; @@ -1232,13 +1229,12 @@ GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart, o.Offset = lockStart; if (!LockFileEx - (fh->h, - (excl ? LOCKFILE_EXCLUSIVE_LOCK : 0) | LOCKFILE_FAIL_IMMEDIATELY, 0, - lockEnd - lockStart, 0, &o)) - { - SetErrnoFromWinError (GetLastError ()); - return GNUNET_SYSERR; - } + (fh->h, (excl ? LOCKFILE_EXCLUSIVE_LOCK : 0) | LOCKFILE_FAIL_IMMEDIATELY, + 0, lockEnd - lockStart, 0, &o)) + { + SetErrnoFromWinError (GetLastError ()); + return GNUNET_SYSERR; + } return GNUNET_OK; #endif @@ -1254,13 +1250,13 @@ GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart, */ int GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, off_t unlockStart, - off_t unlockEnd) + off_t unlockEnd) { if (fh == NULL) - { - errno = EINVAL; - return GNUNET_SYSERR; - } + { + errno = EINVAL; + return GNUNET_SYSERR; + } #ifndef MINGW struct flock fl; @@ -1279,10 +1275,10 @@ GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, off_t unlockStart, o.Offset = unlockStart; if (!UnlockFileEx (fh->h, 0, unlockEnd - unlockStart, 0, &o)) - { - SetErrnoFromWinError (GetLastError ()); - return GNUNET_SYSERR; - } + { + SetErrnoFromWinError (GetLastError ()); + return GNUNET_SYSERR; + } return GNUNET_OK; #endif @@ -1303,7 +1299,7 @@ GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, off_t unlockStart, */ struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open (const char *fn, enum GNUNET_DISK_OpenFlags flags, - enum GNUNET_DISK_AccessPermissions perm) + enum GNUNET_DISK_AccessPermissions perm) { char *expfn; struct GNUNET_DISK_FileHandle *ret; @@ -1324,17 +1320,17 @@ GNUNET_DISK_file_open (const char *fn, enum GNUNET_DISK_OpenFlags flags, #ifndef MINGW mode = 0; if (GNUNET_DISK_OPEN_READWRITE == (flags & GNUNET_DISK_OPEN_READWRITE)) - oflags = O_RDWR; /* note: O_RDWR is NOT always O_RDONLY | O_WRONLY */ + oflags = O_RDWR; /* note: O_RDWR is NOT always O_RDONLY | O_WRONLY */ else if (flags & GNUNET_DISK_OPEN_READ) oflags = O_RDONLY; else if (flags & GNUNET_DISK_OPEN_WRITE) oflags = O_WRONLY; else - { - GNUNET_break (0); - GNUNET_free (expfn); - return NULL; - } + { + GNUNET_break (0); + GNUNET_free (expfn); + return NULL; + } if (flags & GNUNET_DISK_OPEN_FAILIFEXISTS) oflags |= (O_CREAT | O_EXCL); if (flags & GNUNET_DISK_OPEN_TRUNCATE) @@ -1342,22 +1338,22 @@ GNUNET_DISK_file_open (const char *fn, enum GNUNET_DISK_OpenFlags flags, if (flags & GNUNET_DISK_OPEN_APPEND) oflags |= O_APPEND; if (flags & GNUNET_DISK_OPEN_CREATE) - { - (void) GNUNET_DISK_directory_create_for_file (expfn); - oflags |= O_CREAT; - mode = translate_unix_perms (perm); - } + { + (void) GNUNET_DISK_directory_create_for_file (expfn); + oflags |= O_CREAT; + mode = translate_unix_perms (perm); + } fd = open (expfn, oflags | O_LARGEFILE, mode); if (fd == -1) - { - if (0 == (flags & GNUNET_DISK_OPEN_FAILIFEXISTS)) - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", expfn); - else - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_DEBUG, "open", expfn); - GNUNET_free (expfn); - return NULL; - } + { + if (0 == (flags & GNUNET_DISK_OPEN_FAILIFEXISTS)) + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", expfn); + else + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_DEBUG, "open", expfn); + GNUNET_free (expfn); + return NULL; + } #else access = 0; disp = OPEN_ALWAYS; @@ -1370,48 +1366,47 @@ GNUNET_DISK_file_open (const char *fn, enum GNUNET_DISK_OpenFlags flags, access = FILE_WRITE_DATA; if (flags & GNUNET_DISK_OPEN_FAILIFEXISTS) - { - disp = CREATE_NEW; - } + { + disp = CREATE_NEW; + } else if (flags & GNUNET_DISK_OPEN_CREATE) - { - (void) GNUNET_DISK_directory_create_for_file (expfn); - if (flags & GNUNET_DISK_OPEN_TRUNCATE) - disp = CREATE_ALWAYS; - else - disp = OPEN_ALWAYS; - } + { + (void) GNUNET_DISK_directory_create_for_file (expfn); + if (flags & GNUNET_DISK_OPEN_TRUNCATE) + disp = CREATE_ALWAYS; + else + disp = OPEN_ALWAYS; + } else if (flags & GNUNET_DISK_OPEN_TRUNCATE) - { - disp = TRUNCATE_EXISTING; - } + { + disp = TRUNCATE_EXISTING; + } else - { - disp = OPEN_EXISTING; - } + { + disp = OPEN_EXISTING; + } /* TODO: access priviledges? */ h = CreateFile (expfn, access, - FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, disp, FILE_ATTRIBUTE_NORMAL, NULL); + FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, + disp, FILE_ATTRIBUTE_NORMAL, NULL); if (h == INVALID_HANDLE_VALUE) + { + SetErrnoFromWinError (GetLastError ()); + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", expfn); + GNUNET_free (expfn); + return NULL; + } + + if (flags & GNUNET_DISK_OPEN_APPEND) + if (SetFilePointer (h, 0, 0, FILE_END) == INVALID_SET_FILE_POINTER) { SetErrnoFromWinError (GetLastError ()); - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", expfn); + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "SetFilePointer", expfn); + CloseHandle (h); GNUNET_free (expfn); return NULL; } - - if (flags & GNUNET_DISK_OPEN_APPEND) - if (SetFilePointer (h, 0, 0, FILE_END) == INVALID_SET_FILE_POINTER) - { - SetErrnoFromWinError (GetLastError ()); - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "SetFilePointer", - expfn); - CloseHandle (h); - GNUNET_free (expfn); - return NULL; - } #endif ret = GNUNET_malloc (sizeof (struct GNUNET_DISK_FileHandle)); @@ -1435,28 +1430,28 @@ int GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h) { if (h == NULL) - { - errno = EINVAL; - return GNUNET_SYSERR; - } + { + errno = EINVAL; + return GNUNET_SYSERR; + } #if MINGW if (!CloseHandle (h->h)) - { - SetErrnoFromWinError (GetLastError ()); - LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "close"); - GNUNET_free (h->oOverlapRead); - GNUNET_free (h->oOverlapWrite); - GNUNET_free (h); - return GNUNET_SYSERR; - } + { + SetErrnoFromWinError (GetLastError ()); + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "close"); + GNUNET_free (h->oOverlapRead); + GNUNET_free (h->oOverlapWrite); + GNUNET_free (h); + return GNUNET_SYSERR; + } #else if (close (h->fd) != 0) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "close"); - GNUNET_free (h); - return GNUNET_SYSERR; - } + { + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "close"); + GNUNET_free (h); + return GNUNET_SYSERR; + } #endif GNUNET_free (h); return GNUNET_OK; @@ -1479,7 +1474,7 @@ GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h) */ char * GNUNET_DISK_get_home_filename (const struct GNUNET_CONFIGURATION_Handle *cfg, - const char *serviceName, ...) + const char *serviceName, ...) { const char *c; char *pfx; @@ -1488,45 +1483,44 @@ GNUNET_DISK_get_home_filename (const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned int needed; if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (cfg, serviceName, "HOME", - &pfx)) + GNUNET_CONFIGURATION_get_value_filename (cfg, serviceName, "HOME", &pfx)) return NULL; if (pfx == NULL) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - _("No `%s' specified for service `%s' in configuration.\n"), - "HOME", serviceName); - return NULL; - } + { + LOG (GNUNET_ERROR_TYPE_WARNING, + _("No `%s' specified for service `%s' in configuration.\n"), "HOME", + serviceName); + return NULL; + } needed = strlen (pfx) + 2; if ((pfx[strlen (pfx) - 1] != '/') && (pfx[strlen (pfx) - 1] != '\\')) needed++; va_start (ap, serviceName); while (1) - { - c = va_arg (ap, const char *); + { + c = va_arg (ap, const char *); - if (c == NULL) - break; - needed += strlen (c); - if ((c[strlen (c) - 1] != '/') && (c[strlen (c) - 1] != '\\')) - needed++; - } + if (c == NULL) + break; + needed += strlen (c); + if ((c[strlen (c) - 1] != '/') && (c[strlen (c) - 1] != '\\')) + needed++; + } va_end (ap); ret = GNUNET_malloc (needed); strcpy (ret, pfx); GNUNET_free (pfx); va_start (ap, serviceName); while (1) - { - c = va_arg (ap, const char *); + { + c = va_arg (ap, const char *); - if (c == NULL) - break; - if ((c[strlen (c) - 1] != '/') && (c[strlen (c) - 1] != '\\')) - strcat (ret, DIR_SEPARATOR_STR); - strcat (ret, c); - } + if (c == NULL) + break; + if ((c[strlen (c) - 1] != '/') && (c[strlen (c) - 1] != '\\')) + strcat (ret, DIR_SEPARATOR_STR); + strcat (ret, c); + } va_end (ap); if ((ret[strlen (ret) - 1] != '/') && (ret[strlen (ret) - 1] != '\\')) (void) GNUNET_DISK_directory_create_for_file (ret); @@ -1575,56 +1569,56 @@ struct GNUNET_DISK_MapHandle */ void * GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h, - struct GNUNET_DISK_MapHandle **m, - enum GNUNET_DISK_MapType access, size_t len) + struct GNUNET_DISK_MapHandle **m, + enum GNUNET_DISK_MapType access, size_t len) { if (h == NULL) - { - errno = EINVAL; - return NULL; - } + { + errno = EINVAL; + return NULL; + } #ifdef MINGW DWORD mapAccess, protect; if ((access & GNUNET_DISK_MAP_TYPE_READ) && (access & GNUNET_DISK_MAP_TYPE_WRITE)) - { - protect = PAGE_READWRITE; - mapAccess = FILE_MAP_ALL_ACCESS; - } + { + protect = PAGE_READWRITE; + mapAccess = FILE_MAP_ALL_ACCESS; + } else if (access & GNUNET_DISK_MAP_TYPE_READ) - { - protect = PAGE_READONLY; - mapAccess = FILE_MAP_READ; - } + { + protect = PAGE_READONLY; + mapAccess = FILE_MAP_READ; + } else if (access & GNUNET_DISK_MAP_TYPE_WRITE) - { - protect = PAGE_READWRITE; - mapAccess = FILE_MAP_WRITE; - } + { + protect = PAGE_READWRITE; + mapAccess = FILE_MAP_WRITE; + } else - { - GNUNET_break (0); - return NULL; - } + { + GNUNET_break (0); + return NULL; + } *m = GNUNET_malloc (sizeof (struct GNUNET_DISK_MapHandle)); (*m)->h = CreateFileMapping (h->h, NULL, protect, 0, 0, NULL); if ((*m)->h == INVALID_HANDLE_VALUE) - { - SetErrnoFromWinError (GetLastError ()); - GNUNET_free (*m); - return NULL; - } + { + SetErrnoFromWinError (GetLastError ()); + GNUNET_free (*m); + return NULL; + } (*m)->addr = MapViewOfFile ((*m)->h, mapAccess, 0, 0, len); if (!(*m)->addr) - { - SetErrnoFromWinError (GetLastError ()); - CloseHandle ((*m)->h); - GNUNET_free (*m); - } + { + SetErrnoFromWinError (GetLastError ()); + CloseHandle ((*m)->h); + GNUNET_free (*m); + } return (*m)->addr; #else @@ -1639,10 +1633,10 @@ GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h, (*m)->addr = mmap (NULL, len, prot, MAP_SHARED, h->fd, 0); GNUNET_assert (NULL != (*m)->addr); if (MAP_FAILED == (*m)->addr) - { - GNUNET_free (*m); - return NULL; - } + { + GNUNET_free (*m); + return NULL; + } (*m)->len = len; return (*m)->addr; #endif @@ -1659,20 +1653,20 @@ GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h) int ret; if (h == NULL) - { - errno = EINVAL; - return GNUNET_SYSERR; - } + { + errno = EINVAL; + return GNUNET_SYSERR; + } #ifdef MINGW ret = UnmapViewOfFile (h->addr) ? GNUNET_OK : GNUNET_SYSERR; if (ret != GNUNET_OK) SetErrnoFromWinError (GetLastError ()); if (!CloseHandle (h->h) && (ret == GNUNET_OK)) - { - ret = GNUNET_SYSERR; - SetErrnoFromWinError (GetLastError ()); - } + { + ret = GNUNET_SYSERR; + SetErrnoFromWinError (GetLastError ()); + } #else ret = munmap (h->addr, h->len) != -1 ? GNUNET_OK : GNUNET_SYSERR; #endif @@ -1690,10 +1684,10 @@ int GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h) { if (h == NULL) - { - errno = EINVAL; - return GNUNET_SYSERR; - } + { + errno = EINVAL; + return GNUNET_SYSERR; + } #ifdef MINGW int ret; @@ -1722,8 +1716,8 @@ GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h) unlike CreatePipe, which returns a bool for success or failure. */ static int create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr, - LPSECURITY_ATTRIBUTES sa_ptr, DWORD psize, - DWORD dwReadMode, DWORD dwWriteMode) + LPSECURITY_ATTRIBUTES sa_ptr, DWORD psize, + DWORD dwReadMode, DWORD dwWriteMode) { /* Default to error. */ *read_pipe_ptr = *write_pipe_ptr = INVALID_HANDLE_VALUE; @@ -1740,103 +1734,103 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr, * Retrying will probably never be necessary, but we want * to be as robust as possible. */ while (1) - { - static volatile LONG pipe_unique_id; + { + static volatile LONG pipe_unique_id; - snprintf (pipename, sizeof pipename, "\\\\.\\pipe\\gnunet-%d-%ld", - getpid (), InterlockedIncrement ((LONG *) & pipe_unique_id)); + snprintf (pipename, sizeof pipename, "\\\\.\\pipe\\gnunet-%d-%ld", + getpid (), InterlockedIncrement ((LONG *) & pipe_unique_id)); #if DEBUG_PIPE - LOG (GNUNET_ERROR_TYPE_DEBUG, - "CreateNamedPipe: name = %s, size = %lu\n", pipename, psize); + LOG (GNUNET_ERROR_TYPE_DEBUG, "CreateNamedPipe: name = %s, size = %lu\n", + pipename, psize); #endif - /* Use CreateNamedPipe instead of CreatePipe, because the latter - * returns a write handle that does not permit FILE_READ_ATTRIBUTES - * access, on versions of win32 earlier than WinXP SP2. - * CreatePipe also stupidly creates a full duplex pipe, which is - * a waste, since only a single direction is actually used. - * It's important to only allow a single instance, to ensure that - * the pipe was not created earlier by some other process, even if - * the pid has been reused. We avoid FILE_FLAG_FIRST_PIPE_INSTANCE - * because that is only available for Win2k SP2 and WinXP. */ - read_pipe = CreateNamedPipeA (pipename, PIPE_ACCESS_INBOUND | dwReadMode, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 1, /* max instances */ - psize, /* output buffer size */ - psize, /* input buffer size */ - NMPWAIT_USE_DEFAULT_WAIT, sa_ptr); - - if (read_pipe != INVALID_HANDLE_VALUE) - { + /* Use CreateNamedPipe instead of CreatePipe, because the latter + * returns a write handle that does not permit FILE_READ_ATTRIBUTES + * access, on versions of win32 earlier than WinXP SP2. + * CreatePipe also stupidly creates a full duplex pipe, which is + * a waste, since only a single direction is actually used. + * It's important to only allow a single instance, to ensure that + * the pipe was not created earlier by some other process, even if + * the pid has been reused. We avoid FILE_FLAG_FIRST_PIPE_INSTANCE + * because that is only available for Win2k SP2 and WinXP. */ + read_pipe = CreateNamedPipeA (pipename, PIPE_ACCESS_INBOUND | dwReadMode, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 1, /* max instances */ + psize, /* output buffer size */ + psize, /* input buffer size */ + NMPWAIT_USE_DEFAULT_WAIT, sa_ptr); + + if (read_pipe != INVALID_HANDLE_VALUE) + { #if DEBUG_PIPE - LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe read handle = %p\n", read_pipe); + LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe read handle = %p\n", read_pipe); #endif - break; - } + break; + } - DWORD err = GetLastError (); + DWORD err = GetLastError (); - switch (err) - { - case ERROR_PIPE_BUSY: - /* The pipe is already open with compatible parameters. - * Pick a new name and retry. */ + switch (err) + { + case ERROR_PIPE_BUSY: + /* The pipe is already open with compatible parameters. + * Pick a new name and retry. */ #if DEBUG_PIPE - LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe busy, retrying\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe busy, retrying\n"); #endif - continue; - case ERROR_ACCESS_DENIED: - /* The pipe is already open with incompatible parameters. - * Pick a new name and retry. */ + continue; + case ERROR_ACCESS_DENIED: + /* The pipe is already open with incompatible parameters. + * Pick a new name and retry. */ #if DEBUG_PIPE - LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe access denied, retrying\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe access denied, retrying\n"); #endif - continue; - case ERROR_CALL_NOT_IMPLEMENTED: - /* We are on an older Win9x platform without named pipes. - * Return an anonymous pipe as the best approximation. */ + continue; + case ERROR_CALL_NOT_IMPLEMENTED: + /* We are on an older Win9x platform without named pipes. + * Return an anonymous pipe as the best approximation. */ #if DEBUG_PIPE - LOG (GNUNET_ERROR_TYPE_DEBUG, - "CreateNamedPipe not implemented, resorting to " - "CreatePipe: size = %lu\n", psize); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "CreateNamedPipe not implemented, resorting to " + "CreatePipe: size = %lu\n", psize); #endif - if (CreatePipe (read_pipe_ptr, write_pipe_ptr, sa_ptr, psize)) - { + if (CreatePipe (read_pipe_ptr, write_pipe_ptr, sa_ptr, psize)) + { #if DEBUG_PIPE - LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe read handle = %p\n", - *read_pipe_ptr); - LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe write handle = %p\n", - *write_pipe_ptr); + LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe read handle = %p\n", + *read_pipe_ptr); + LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe write handle = %p\n", + *write_pipe_ptr); #endif - return GNUNET_OK; - } - err = GetLastError (); - LOG (GNUNET_ERROR_TYPE_ERROR, "CreatePipe failed: %d\n", err); - return err; - default: - LOG (GNUNET_ERROR_TYPE_ERROR, "CreateNamedPipe failed: %d\n", err); - return err; - } - /* NOTREACHED */ + return GNUNET_OK; + } + err = GetLastError (); + LOG (GNUNET_ERROR_TYPE_ERROR, "CreatePipe failed: %d\n", err); + return err; + default: + LOG (GNUNET_ERROR_TYPE_ERROR, "CreateNamedPipe failed: %d\n", err); + return err; } + /* NOTREACHED */ + } #if DEBUG_PIPE LOG (GNUNET_ERROR_TYPE_DEBUG, "CreateFile: name = %s\n", pipename); #endif /* Open the named pipe for writing. * Be sure to permit FILE_READ_ATTRIBUTES access. */ - write_pipe = CreateFileA (pipename, GENERIC_WRITE | FILE_READ_ATTRIBUTES, 0, /* share mode */ - sa_ptr, OPEN_EXISTING, dwWriteMode, /* flags and attributes */ - 0); /* handle to template file */ + write_pipe = CreateFileA (pipename, GENERIC_WRITE | FILE_READ_ATTRIBUTES, 0, /* share mode */ + sa_ptr, OPEN_EXISTING, dwWriteMode, /* flags and attributes */ + 0); /* handle to template file */ if (write_pipe == INVALID_HANDLE_VALUE) - { - /* Failure. */ - DWORD err = GetLastError (); + { + /* Failure. */ + DWORD err = GetLastError (); #if DEBUG_PIPE - LOG (GNUNET_ERROR_TYPE_DEBUG, "CreateFile failed: %d\n", err); + LOG (GNUNET_ERROR_TYPE_DEBUG, "CreateFile failed: %d\n", err); #endif - CloseHandle (read_pipe); - return err; - } + CloseHandle (read_pipe); + return err; + } #if DEBUG_PIPE LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe write handle = %p\n", write_pipe); #endif @@ -1863,7 +1857,7 @@ GNUNET_DISK_pipe (int blocking, int inherit_read, int inherit_write) struct GNUNET_DISK_FileHandle *fds; p = GNUNET_malloc (sizeof (struct GNUNET_DISK_PipeHandle) + - 2 * sizeof (struct GNUNET_DISK_FileHandle)); + 2 * sizeof (struct GNUNET_DISK_FileHandle)); fds = (struct GNUNET_DISK_FileHandle *) &p[1]; p->fd[0] = &fds[0]; p->fd[1] = &fds[1]; @@ -1875,13 +1869,13 @@ GNUNET_DISK_pipe (int blocking, int inherit_read, int inherit_write) ret = pipe (fd); if (ret == -1) - { - eno = errno; - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe"); - GNUNET_free (p); - errno = eno; - return NULL; - } + { + eno = errno; + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe"); + GNUNET_free (p); + errno = eno; + return NULL; + } p->fd[0]->fd = fd[0]; p->fd[1]->fd = fd[1]; ret = 0; @@ -1905,62 +1899,62 @@ GNUNET_DISK_pipe (int blocking, int inherit_read, int inherit_write) if (0 > fcntl (fd[1], F_SETFD, flags)) ret = -1; if (ret == -1) - { - eno = errno; - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fcntl"); - GNUNET_break (0 == close (p->fd[0]->fd)); - GNUNET_break (0 == close (p->fd[1]->fd)); - GNUNET_free (p); - errno = eno; - return NULL; - } + { + eno = errno; + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fcntl"); + GNUNET_break (0 == close (p->fd[0]->fd)); + GNUNET_break (0 == close (p->fd[1]->fd)); + GNUNET_free (p); + errno = eno; + return NULL; + } #else BOOL ret; HANDLE tmp_handle; ret = - create_selectable_pipe (&p->fd[0]->h, &p->fd[1]->h, NULL, 0, - FILE_FLAG_OVERLAPPED, FILE_FLAG_OVERLAPPED); + create_selectable_pipe (&p->fd[0]->h, &p->fd[1]->h, NULL, 0, + FILE_FLAG_OVERLAPPED, FILE_FLAG_OVERLAPPED); if (!ret) - { - GNUNET_free (p); - SetErrnoFromWinError (GetLastError ()); - return NULL; - } + { + GNUNET_free (p); + SetErrnoFromWinError (GetLastError ()); + return NULL; + } if (!DuplicateHandle - (GetCurrentProcess (), p->fd[0]->h, GetCurrentProcess (), &tmp_handle, - 0, inherit_read == GNUNET_YES ? TRUE : FALSE, DUPLICATE_SAME_ACCESS)) - { - SetErrnoFromWinError (GetLastError ()); - CloseHandle (p->fd[0]->h); - CloseHandle (p->fd[1]->h); - GNUNET_free (p); - return NULL; - } + (GetCurrentProcess (), p->fd[0]->h, GetCurrentProcess (), &tmp_handle, 0, + inherit_read == GNUNET_YES ? TRUE : FALSE, DUPLICATE_SAME_ACCESS)) + { + SetErrnoFromWinError (GetLastError ()); + CloseHandle (p->fd[0]->h); + CloseHandle (p->fd[1]->h); + GNUNET_free (p); + return NULL; + } CloseHandle (p->fd[0]->h); p->fd[0]->h = tmp_handle; if (!DuplicateHandle - (GetCurrentProcess (), p->fd[1]->h, GetCurrentProcess (), &tmp_handle, - 0, inherit_write == GNUNET_YES ? TRUE : FALSE, DUPLICATE_SAME_ACCESS)) - { - SetErrnoFromWinError (GetLastError ()); - CloseHandle (p->fd[0]->h); - CloseHandle (p->fd[1]->h); - GNUNET_free (p); - return NULL; - } + (GetCurrentProcess (), p->fd[1]->h, GetCurrentProcess (), &tmp_handle, 0, + inherit_write == GNUNET_YES ? TRUE : FALSE, DUPLICATE_SAME_ACCESS)) + { + SetErrnoFromWinError (GetLastError ()); + CloseHandle (p->fd[0]->h); + CloseHandle (p->fd[1]->h); + GNUNET_free (p); + return NULL; + } CloseHandle (p->fd[1]->h); p->fd[1]->h = tmp_handle; if (!blocking) - { - DWORD mode; - - mode = PIPE_NOWAIT; - SetNamedPipeHandleState (p->fd[0]->h, &mode, NULL, NULL); - SetNamedPipeHandleState (p->fd[1]->h, &mode, NULL, NULL); - /* this always fails on Windows 95, so we don't care about error handling */ - } + { + DWORD mode; + + mode = PIPE_NOWAIT; + SetNamedPipeHandleState (p->fd[0]->h, &mode, NULL, NULL); + SetNamedPipeHandleState (p->fd[1]->h, &mode, NULL, NULL); + /* this always fails on Windows 95, so we don't care about error handling */ + } p->fd[0]->type = GNUNET_PIPE; p->fd[1]->type = GNUNET_PIPE; @@ -1989,51 +1983,51 @@ GNUNET_DISK_pipe (int blocking, int inherit_read, int inherit_write) */ int GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p, - enum GNUNET_DISK_PipeEnd end) + enum GNUNET_DISK_PipeEnd end) { int ret = GNUNET_OK; int save; #ifdef MINGW if (end == GNUNET_DISK_PIPE_END_READ) + { + if (!CloseHandle (p->fd[0]->h)) { - if (!CloseHandle (p->fd[0]->h)) - { - SetErrnoFromWinError (GetLastError ()); - ret = GNUNET_SYSERR; - } - p->fd[0]->h = INVALID_HANDLE_VALUE; + SetErrnoFromWinError (GetLastError ()); + ret = GNUNET_SYSERR; } + p->fd[0]->h = INVALID_HANDLE_VALUE; + } else if (end == GNUNET_DISK_PIPE_END_WRITE) + { + if (!CloseHandle (p->fd[1]->h)) { - if (!CloseHandle (p->fd[1]->h)) - { - SetErrnoFromWinError (GetLastError ()); - ret = GNUNET_SYSERR; - } - p->fd[1]->h = INVALID_HANDLE_VALUE; + SetErrnoFromWinError (GetLastError ()); + ret = GNUNET_SYSERR; } + p->fd[1]->h = INVALID_HANDLE_VALUE; + } save = errno; #else save = 0; if (end == GNUNET_DISK_PIPE_END_READ) + { + if (0 != close (p->fd[0]->fd)) { - if (0 != close (p->fd[0]->fd)) - { - ret = GNUNET_SYSERR; - save = errno; - } - p->fd[0]->fd = -1; + ret = GNUNET_SYSERR; + save = errno; } + p->fd[0]->fd = -1; + } else if (end == GNUNET_DISK_PIPE_END_WRITE) + { + if (0 != close (p->fd[1]->fd)) { - if (0 != close (p->fd[1]->fd)) - { - ret = GNUNET_SYSERR; - save = errno; - } - p->fd[1]->fd = -1; + ret = GNUNET_SYSERR; + save = errno; } + p->fd[1]->fd = -1; + } #endif errno = save; return ret; @@ -2053,35 +2047,35 @@ GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p) #ifdef MINGW if (!CloseHandle (p->fd[0]->h)) - { - SetErrnoFromWinError (GetLastError ()); - ret = GNUNET_SYSERR; - } + { + SetErrnoFromWinError (GetLastError ()); + ret = GNUNET_SYSERR; + } if (!CloseHandle (p->fd[1]->h)) - { - SetErrnoFromWinError (GetLastError ()); - ret = GNUNET_SYSERR; - } + { + SetErrnoFromWinError (GetLastError ()); + ret = GNUNET_SYSERR; + } save = errno; #else save = 0; if (p->fd[0]->fd != -1) + { + if (0 != close (p->fd[0]->fd)) { - if (0 != close (p->fd[0]->fd)) - { - ret = GNUNET_SYSERR; - save = errno; - } + ret = GNUNET_SYSERR; + save = errno; } + } if (p->fd[1]->fd != -1) + { + if (0 != close (p->fd[1]->fd)) { - if (0 != close (p->fd[1]->fd)) - { - ret = GNUNET_SYSERR; - save = errno; - } + ret = GNUNET_SYSERR; + save = errno; } + } #endif GNUNET_free (p); errno = save; @@ -2098,7 +2092,7 @@ GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p) */ struct GNUNET_DISK_FileHandle * GNUNET_DISK_npipe_create (char **fn, enum GNUNET_DISK_OpenFlags flags, - enum GNUNET_DISK_AccessPermissions perm) + enum GNUNET_DISK_AccessPermissions perm) { #ifdef MINGW struct GNUNET_DISK_FileHandle *ret; @@ -2118,71 +2112,70 @@ GNUNET_DISK_npipe_create (char **fn, enum GNUNET_DISK_OpenFlags flags, openMode |= FILE_FLAG_FIRST_PIPE_INSTANCE; while (h == NULL) - { - DWORD error_code; + { + DWORD error_code; - name = NULL; - if (*fn != NULL) - { - GNUNET_asprintf (&name, "\\\\.\\pipe\\%.246s", fn); + name = NULL; + if (*fn != NULL) + { + GNUNET_asprintf (&name, "\\\\.\\pipe\\%.246s", fn); #if DEBUG_NPIPE - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Trying to create an instance of named pipe `%s'\n", name); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Trying to create an instance of named pipe `%s'\n", name); #endif - h = CreateNamedPipe (name, openMode | FILE_FLAG_OVERLAPPED, - PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 2, 1, 1, - 0, NULL); - } - else - { - GNUNET_asprintf (fn, "\\\\.\\pipe\\gnunet-%llu", - GNUNET_CRYPTO_random_u64 - (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX)); + h = CreateNamedPipe (name, openMode | FILE_FLAG_OVERLAPPED, + PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 2, 1, 1, 0, + NULL); + } + else + { + GNUNET_asprintf (fn, "\\\\.\\pipe\\gnunet-%llu", + GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, + UINT64_MAX)); #if DEBUG_NPIPE - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Trying to create unique named pipe `%s'\n", *fn); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Trying to create unique named pipe `%s'\n", + *fn); #endif - h = CreateNamedPipe (*fn, - openMode | FILE_FLAG_OVERLAPPED | - FILE_FLAG_FIRST_PIPE_INSTANCE, - PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 2, 1, 1, - 0, NULL); - } - error_code = GetLastError (); - if (name) - GNUNET_free (name); - /* don't re-set name to NULL yet */ - if (h == INVALID_HANDLE_VALUE) - { - SetErrnoFromWinError (error_code); + h = CreateNamedPipe (*fn, + openMode | FILE_FLAG_OVERLAPPED | + FILE_FLAG_FIRST_PIPE_INSTANCE, + PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 2, 1, 1, 0, + NULL); + } + error_code = GetLastError (); + if (name) + GNUNET_free (name); + /* don't re-set name to NULL yet */ + if (h == INVALID_HANDLE_VALUE) + { + SetErrnoFromWinError (error_code); #if DEBUG_NPIPE - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Pipe creation have failed because of %d, errno is %d\n", - error_code, errno); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Pipe creation have failed because of %d, errno is %d\n", error_code, + errno); #endif - if (name == NULL) - { + if (name == NULL) + { #if DEBUG_NPIPE - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Pipe was to be unique, considering re-creation\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Pipe was to be unique, considering re-creation\n"); #endif - GNUNET_free (*fn); - *fn = NULL; - if (error_code != ERROR_ACCESS_DENIED - && error_code != ERROR_PIPE_BUSY) - { - return NULL; - } + GNUNET_free (*fn); + *fn = NULL; + if (error_code != ERROR_ACCESS_DENIED && error_code != ERROR_PIPE_BUSY) + { + return NULL; + } #if DEBUG_NPIPE - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Pipe name was not unique, trying again\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Pipe name was not unique, trying again\n"); #endif - h = NULL; - } - else - return NULL; - } + h = NULL; + } + else + return NULL; } + } errno = 0; ret = GNUNET_malloc (sizeof (*ret)); @@ -2198,22 +2191,22 @@ GNUNET_DISK_npipe_create (char **fn, enum GNUNET_DISK_OpenFlags flags, return ret; #else if (*fn == NULL) + { + char dir[] = "/tmp/gnunet-pipe-XXXXXX"; + + if (mkdtemp (dir) == NULL) { - char dir[] = "/tmp/gnunet-pipe-XXXXXX"; - - if (mkdtemp (dir) == NULL) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "mkdtemp"); - return NULL; - } - GNUNET_asprintf (fn, "%s/child-control", dir); + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "mkdtemp"); + return NULL; } + GNUNET_asprintf (fn, "%s/child-control", dir); + } if (mkfifo (*fn, translate_unix_perms (perm)) == -1) - { - if ((errno != EEXIST) || (0 != (flags & GNUNET_DISK_OPEN_FAILIFEXISTS))) - return NULL; - } + { + if ((errno != EEXIST) || (0 != (flags & GNUNET_DISK_OPEN_FAILIFEXISTS))) + return NULL; + } flags = flags & (~GNUNET_DISK_OPEN_FAILIFEXISTS); return GNUNET_DISK_file_open (*fn, flags, perm); @@ -2231,7 +2224,7 @@ GNUNET_DISK_npipe_create (char **fn, enum GNUNET_DISK_OpenFlags flags, */ struct GNUNET_DISK_FileHandle * GNUNET_DISK_npipe_open (const char *fn, enum GNUNET_DISK_OpenFlags flags, - enum GNUNET_DISK_AccessPermissions perm) + enum GNUNET_DISK_AccessPermissions perm) { #ifdef MINGW struct GNUNET_DISK_FileHandle *ret; @@ -2247,12 +2240,12 @@ GNUNET_DISK_npipe_open (const char *fn, enum GNUNET_DISK_OpenFlags flags, openMode = GENERIC_WRITE; h = CreateFile (fn, openMode, 0, NULL, OPEN_EXISTING, - FILE_FLAG_OVERLAPPED | FILE_READ_ATTRIBUTES, NULL); + FILE_FLAG_OVERLAPPED | FILE_READ_ATTRIBUTES, NULL); if (h == INVALID_HANDLE_VALUE) - { - SetErrnoFromWinError (GetLastError ()); - return NULL; - } + { + SetErrnoFromWinError (GetLastError ()); + return NULL; + } ret = GNUNET_malloc (sizeof (*ret)); ret->h = h; @@ -2284,10 +2277,10 @@ GNUNET_DISK_npipe_close (struct GNUNET_DISK_FileHandle *pipe) ret = CloseHandle (pipe->h); if (!ret) - { - SetErrnoFromWinError (GetLastError ()); - return GNUNET_SYSERR; - } + { + SetErrnoFromWinError (GetLastError ()); + return GNUNET_SYSERR; + } else return GNUNET_OK; #endif @@ -2303,17 +2296,17 @@ GNUNET_DISK_npipe_close (struct GNUNET_DISK_FileHandle *pipe) */ const struct GNUNET_DISK_FileHandle * GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p, - enum GNUNET_DISK_PipeEnd n) + enum GNUNET_DISK_PipeEnd n) { switch (n) - { - case GNUNET_DISK_PIPE_END_READ: - case GNUNET_DISK_PIPE_END_WRITE: - return p->fd[n]; - default: - GNUNET_break (0); - return NULL; - } + { + case GNUNET_DISK_PIPE_END_READ: + case GNUNET_DISK_PIPE_END_WRITE: + return p->fd[n]; + default: + GNUNET_break (0); + return NULL; + } } @@ -2327,7 +2320,7 @@ GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p, */ int GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh, - void *dst, size_t dst_len) + void *dst, size_t dst_len) { #ifdef MINGW if (dst_len < sizeof (HANDLE)) diff --git a/src/util/getopt.c b/src/util/getopt.c index 4a36678b2..317bc0748 100644 --- a/src/util/getopt.c +++ b/src/util/getopt.c @@ -198,19 +198,20 @@ static char *posixly_correct; /* Avoid depending on library functions or files whose names are inconsistent. */ -char *getenv (); +char * +getenv (); static char * my_index (str, chr) - const char *str; - int chr; + const char *str; + int chr; { while (*str) - { - if (*str == chr) - return (char *) str; - str++; - } + { + if (*str == chr) + return (char *) str; + str++; + } return 0; } @@ -222,7 +223,8 @@ my_index (str, chr) #if !defined (__STDC__) || !__STDC__ /* gcc with -traditional declares the built-in strlen to return int, and has done so at least since version 2.4.5. -- rms. */ -extern int strlen (const char *); +extern int +strlen (const char *); #endif /* not __STDC__ */ #endif /* __GNUC__ */ @@ -256,7 +258,7 @@ extern pid_t __libc_pid; is valid for the getopt call we must make sure that the ARGV passed to getopt is that one passed to the process. */ static void - __attribute__ ((unused)) store_args_and_env (int argc, char *const *argv) + __attribute__ ((unused)) store_args_and_env (int argc, char *const *argv) { /* XXX This is no good solution. We should rather copy the args so * that we can compare them later. But we must not use malloc(3). */ @@ -287,12 +289,13 @@ text_set_element (__libc_subinit, store_args_and_env); the new indices of the non-options in ARGV after they are moved. */ #if defined (__STDC__) && __STDC__ -static void exchange (char **); +static void +exchange (char **); #endif static void exchange (argv) - char **argv; + char **argv; { int bottom = first_nonopt; int middle = last_nonopt; @@ -309,61 +312,61 @@ exchange (argv) * string can work normally. Our top argument must be in the range * of the string. */ if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len) - { - /* We must extend the array. The user plays games with us and - * presents new arguments. */ - char *new_str = malloc (top + 1); + { + /* We must extend the array. The user plays games with us and + * presents new arguments. */ + char *new_str = malloc (top + 1); - if (new_str == NULL) - nonoption_flags_len = nonoption_flags_max_len = 0; - else - { - memcpy (new_str, __getopt_nonoption_flags, nonoption_flags_max_len); - memset (&new_str[nonoption_flags_max_len], '\0', - top + 1 - nonoption_flags_max_len); - nonoption_flags_max_len = top + 1; - __getopt_nonoption_flags = new_str; - } + if (new_str == NULL) + nonoption_flags_len = nonoption_flags_max_len = 0; + else + { + memcpy (new_str, __getopt_nonoption_flags, nonoption_flags_max_len); + memset (&new_str[nonoption_flags_max_len], '\0', + top + 1 - nonoption_flags_max_len); + nonoption_flags_max_len = top + 1; + __getopt_nonoption_flags = new_str; } + } #endif while (top > middle && middle > bottom) + { + if (top - middle > middle - bottom) { - if (top - middle > middle - bottom) - { - /* Bottom segment is the short one. */ - int len = middle - bottom; - register int i; - - /* Swap it with the top part of the top segment. */ - for (i = 0; i < len; i++) - { - tem = argv[bottom + i]; - argv[bottom + i] = argv[top - (middle - bottom) + i]; - argv[top - (middle - bottom) + i] = tem; - SWAP_FLAGS (bottom + i, top - (middle - bottom) + i); - } - /* Exclude the moved bottom segment from further swapping. */ - top -= len; - } - else - { - /* Top segment is the short one. */ - int len = top - middle; - register int i; - - /* Swap it with the bottom part of the bottom segment. */ - for (i = 0; i < len; i++) - { - tem = argv[bottom + i]; - argv[bottom + i] = argv[middle + i]; - argv[middle + i] = tem; - SWAP_FLAGS (bottom + i, middle + i); - } - /* Exclude the moved top segment from further swapping. */ - bottom += len; - } + /* Bottom segment is the short one. */ + int len = middle - bottom; + register int i; + + /* Swap it with the top part of the top segment. */ + for (i = 0; i < len; i++) + { + tem = argv[bottom + i]; + argv[bottom + i] = argv[top - (middle - bottom) + i]; + argv[top - (middle - bottom) + i] = tem; + SWAP_FLAGS (bottom + i, top - (middle - bottom) + i); + } + /* Exclude the moved bottom segment from further swapping. */ + top -= len; + } + else + { + /* Top segment is the short one. */ + int len = top - middle; + register int i; + + /* Swap it with the bottom part of the bottom segment. */ + for (i = 0; i < len; i++) + { + tem = argv[bottom + i]; + argv[bottom + i] = argv[middle + i]; + argv[middle + i] = tem; + SWAP_FLAGS (bottom + i, middle + i); + } + /* Exclude the moved top segment from further swapping. */ + bottom += len; } + } /* Update records for the slots the non-options now occupy. */ @@ -374,13 +377,14 @@ exchange (argv) /* Initialize the internal data when the first call is made. */ #if defined (__STDC__) && __STDC__ -static const char *_getopt_initialize (int, char *const *, const char *); +static const char * +_getopt_initialize (int, char *const *, const char *); #endif static const char * _getopt_initialize (argc, argv, optstring) - int argc; - char *const *argv; - const char *optstring; + int argc; + char *const *argv; + const char *optstring; { /* Start processing options with ARGV-element 1 (since ARGV-element 0 * is the program name); the sequence of previously skipped @@ -395,50 +399,48 @@ _getopt_initialize (argc, argv, optstring) /* Determine how to handle the ordering of options and nonoptions. */ if (optstring[0] == '-') - { - ordering = RETURN_IN_ORDER; - ++optstring; - } + { + ordering = RETURN_IN_ORDER; + ++optstring; + } else if (optstring[0] == '+') - { - ordering = REQUIRE_ORDER; - ++optstring; - } + { + ordering = REQUIRE_ORDER; + ++optstring; + } else if (posixly_correct != NULL) ordering = REQUIRE_ORDER; else ordering = PERMUTE; #ifdef _LIBC - if (posixly_correct == NULL && argc == original_argc - && argv == original_argv) + if (posixly_correct == NULL && argc == original_argc && argv == original_argv) + { + if (nonoption_flags_max_len == 0) { - if (nonoption_flags_max_len == 0) - { - if (__getopt_nonoption_flags == NULL || - __getopt_nonoption_flags[0] == '\0') - nonoption_flags_max_len = -1; - else - { - const char *orig_str = __getopt_nonoption_flags; - int len = nonoption_flags_max_len = strlen (orig_str); - - if (nonoption_flags_max_len < argc) - nonoption_flags_max_len = argc; - __getopt_nonoption_flags = - (char *) malloc (nonoption_flags_max_len); - if (__getopt_nonoption_flags == NULL) - nonoption_flags_max_len = -1; - else - { - memcpy (__getopt_nonoption_flags, orig_str, len); - memset (&__getopt_nonoption_flags[len], '\0', - nonoption_flags_max_len - len); - } - } - } - nonoption_flags_len = nonoption_flags_max_len; + if (__getopt_nonoption_flags == NULL || + __getopt_nonoption_flags[0] == '\0') + nonoption_flags_max_len = -1; + else + { + const char *orig_str = __getopt_nonoption_flags; + int len = nonoption_flags_max_len = strlen (orig_str); + + if (nonoption_flags_max_len < argc) + nonoption_flags_max_len = argc; + __getopt_nonoption_flags = (char *) malloc (nonoption_flags_max_len); + if (__getopt_nonoption_flags == NULL) + nonoption_flags_max_len = -1; + else + { + memcpy (__getopt_nonoption_flags, orig_str, len); + memset (&__getopt_nonoption_flags[len], '\0', + nonoption_flags_max_len - len); + } + } } + nonoption_flags_len = nonoption_flags_max_len; + } else nonoption_flags_len = 0; #endif @@ -504,8 +506,8 @@ _getopt_initialize (argc, argv, optstring) static int GN_getopt_internal (int argc, char *const *argv, const char *optstring, - const struct GNoption *longopts, int *longind, - int long_only) + const struct GNoption *longopts, int *longind, + int long_only) { static int __getopt_initialized = 0; static int GNopterr = 1; @@ -513,12 +515,12 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring, GNoptarg = NULL; if (GNoptind == 0 || !__getopt_initialized) - { - if (GNoptind == 0) - GNoptind = 1; /* Don't scan ARGV[0], the program name. */ - optstring = _getopt_initialize (argc, argv, optstring); - __getopt_initialized = 1; - } + { + if (GNoptind == 0) + GNoptind = 1; /* Don't scan ARGV[0], the program name. */ + optstring = _getopt_initialize (argc, argv, optstring); + __getopt_initialized = 1; + } /* Test whether ARGV[GNoptind] points to a non-option argument. * Either it does not have option syntax, or there is an environment flag @@ -533,81 +535,81 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring, #endif if (nextchar == NULL || *nextchar == '\0') + { + /* Advance to the next ARGV-element. */ + + /* Give FIRST_NONOPT & LAST_NONOPT rational values if GNoptind has been + * moved back by the user (who may also have changed the arguments). */ + if (last_nonopt > GNoptind) + last_nonopt = GNoptind; + if (first_nonopt > GNoptind) + first_nonopt = GNoptind; + + if (ordering == PERMUTE) { - /* Advance to the next ARGV-element. */ - - /* Give FIRST_NONOPT & LAST_NONOPT rational values if GNoptind has been - * moved back by the user (who may also have changed the arguments). */ - if (last_nonopt > GNoptind) - last_nonopt = GNoptind; - if (first_nonopt > GNoptind) - first_nonopt = GNoptind; - - if (ordering == PERMUTE) - { - /* If we have just processed some options following some non-options, - * exchange them so that the options come first. */ - - if (first_nonopt != last_nonopt && last_nonopt != GNoptind) - exchange ((char **) argv); - else if (last_nonopt != GNoptind) - first_nonopt = GNoptind; - - /* Skip any additional non-options - * and extend the range of non-options previously skipped. */ - - while (GNoptind < argc && NONOPTION_P) - GNoptind++; - last_nonopt = GNoptind; - } - - /* The special ARGV-element `--' means premature end of options. - * Skip it like a null option, - * then exchange with previous non-options as if it were an option, - * then skip everything else like a non-option. */ - if (GNoptind != argc && !strcmp (argv[GNoptind], "--")) - { - GNoptind++; - - if (first_nonopt != last_nonopt && last_nonopt != GNoptind) - exchange ((char **) argv); - else if (first_nonopt == last_nonopt) - first_nonopt = GNoptind; - last_nonopt = argc; - - GNoptind = argc; - } - - /* If we have done all the ARGV-elements, stop the scan - * and back over any non-options that we skipped and permuted. */ - - if (GNoptind == argc) - { - /* Set the next-arg-index to point at the non-options - * that we previously skipped, so the caller will digest them. */ - if (first_nonopt != last_nonopt) - GNoptind = first_nonopt; - return -1; - } - - /* If we have come to a non-option and did not permute it, - * either stop the scan or describe it to the caller and pass it by. */ - - if (NONOPTION_P) - { - if (ordering == REQUIRE_ORDER) - return -1; - GNoptarg = argv[GNoptind++]; - return 1; - } - - /* We have found another option-ARGV-element. - * Skip the initial punctuation. */ - - nextchar = - (argv[GNoptind] + 1 + (longopts != NULL && argv[GNoptind][1] == '-')); + /* If we have just processed some options following some non-options, + * exchange them so that the options come first. */ + + if (first_nonopt != last_nonopt && last_nonopt != GNoptind) + exchange ((char **) argv); + else if (last_nonopt != GNoptind) + first_nonopt = GNoptind; + + /* Skip any additional non-options + * and extend the range of non-options previously skipped. */ + + while (GNoptind < argc && NONOPTION_P) + GNoptind++; + last_nonopt = GNoptind; + } + + /* The special ARGV-element `--' means premature end of options. + * Skip it like a null option, + * then exchange with previous non-options as if it were an option, + * then skip everything else like a non-option. */ + if (GNoptind != argc && !strcmp (argv[GNoptind], "--")) + { + GNoptind++; + + if (first_nonopt != last_nonopt && last_nonopt != GNoptind) + exchange ((char **) argv); + else if (first_nonopt == last_nonopt) + first_nonopt = GNoptind; + last_nonopt = argc; + + GNoptind = argc; } + /* If we have done all the ARGV-elements, stop the scan + * and back over any non-options that we skipped and permuted. */ + + if (GNoptind == argc) + { + /* Set the next-arg-index to point at the non-options + * that we previously skipped, so the caller will digest them. */ + if (first_nonopt != last_nonopt) + GNoptind = first_nonopt; + return -1; + } + + /* If we have come to a non-option and did not permute it, + * either stop the scan or describe it to the caller and pass it by. */ + + if (NONOPTION_P) + { + if (ordering == REQUIRE_ORDER) + return -1; + GNoptarg = argv[GNoptind++]; + return 1; + } + + /* We have found another option-ARGV-element. + * Skip the initial punctuation. */ + + nextchar = + (argv[GNoptind] + 1 + (longopts != NULL && argv[GNoptind][1] == '-')); + } + /* Decode the current option-ARGV-element. */ /* Check whether the ARGV-element is a long option. @@ -626,138 +628,134 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring, if (longopts != NULL && (argv[GNoptind][1] == '-' || (long_only && - (argv[GNoptind][2] || !my_index (optstring, argv[GNoptind][1]))))) - { - char *nameend; - const struct GNoption *p; - const struct GNoption *pfound = NULL; - int exact = 0; - int ambig = 0; - int indfound = -1; - int option_index; - - for (nameend = nextchar; *nameend && *nameend != '='; nameend++) - /* Do nothing. */ ; + (argv[GNoptind][2] || !my_index (optstring, argv[GNoptind][1]))))) + { + char *nameend; + const struct GNoption *p; + const struct GNoption *pfound = NULL; + int exact = 0; + int ambig = 0; + int indfound = -1; + int option_index; + + for (nameend = nextchar; *nameend && *nameend != '='; nameend++) + /* Do nothing. */ ; + + /* Test all long options for either exact match + * or abbreviated matches. */ + for (p = longopts, option_index = 0; p->name; p++, option_index++) + if (!strncmp (p->name, nextchar, nameend - nextchar)) + { + if ((unsigned int) (nameend - nextchar) == + (unsigned int) strlen (p->name)) + { + /* Exact match found. */ + pfound = p; + indfound = option_index; + exact = 1; + break; + } + else if (pfound == NULL) + { + /* First nonexact match found. */ + pfound = p; + indfound = option_index; + } + else + /* Second or later nonexact match found. */ + ambig = 1; + } - /* Test all long options for either exact match - * or abbreviated matches. */ - for (p = longopts, option_index = 0; p->name; p++, option_index++) - if (!strncmp (p->name, nextchar, nameend - nextchar)) - { - if ((unsigned int) (nameend - nextchar) == - (unsigned int) strlen (p->name)) - { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } - else if (pfound == NULL) - { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } - else - /* Second or later nonexact match found. */ - ambig = 1; - } + if (ambig && !exact) + { + if (GNopterr) + fprintf (stderr, _("%s: option `%s' is ambiguous\n"), argv[0], + argv[GNoptind]); + nextchar += strlen (nextchar); + GNoptind++; + return '?'; + } - if (ambig && !exact) - { - if (GNopterr) - fprintf (stderr, _("%s: option `%s' is ambiguous\n"), argv[0], - argv[GNoptind]); - nextchar += strlen (nextchar); - GNoptind++; - return '?'; - } + if (pfound != NULL) + { + option_index = indfound; + GNoptind++; + if (*nameend) + { + /* Don't test has_arg with >, because some C compilers don't + * allow it to be used on enums. */ + if (pfound->has_arg) + GNoptarg = nameend + 1; + else + { + if (GNopterr) + { + if (argv[GNoptind - 1][1] == '-') + /* --option */ + fprintf (stderr, + _("%s: option `--%s' does not allow an argument\n"), + argv[0], pfound->name); + else + /* +option or -option */ + fprintf (stderr, + _("%s: option `%c%s' does not allow an argument\n"), + argv[0], argv[GNoptind - 1][0], pfound->name); + } + nextchar += strlen (nextchar); + return '?'; + } + } + else if (pfound->has_arg == 1) + { + if (GNoptind < argc) + { + GNoptarg = argv[GNoptind++]; + } + else + { + if (GNopterr) + { + fprintf (stderr, _("%s: option `%s' requires an argument\n"), + argv[0], argv[GNoptind - 1]); + } + nextchar += strlen (nextchar); + return (optstring[0] == ':') ? ':' : '?'; + } + } + nextchar += strlen (nextchar); + if (longind != NULL) + *longind = option_index; + if (pfound->flag) + { + *(pfound->flag) = pfound->val; + return 0; + } + return pfound->val; + } - if (pfound != NULL) - { - option_index = indfound; - GNoptind++; - if (*nameend) - { - /* Don't test has_arg with >, because some C compilers don't - * allow it to be used on enums. */ - if (pfound->has_arg) - GNoptarg = nameend + 1; - else - { - if (GNopterr) - { - if (argv[GNoptind - 1][1] == '-') - /* --option */ - fprintf (stderr, - _ - ("%s: option `--%s' does not allow an argument\n"), - argv[0], pfound->name); - else - /* +option or -option */ - fprintf (stderr, - _ - ("%s: option `%c%s' does not allow an argument\n"), - argv[0], argv[GNoptind - 1][0], - pfound->name); - } - nextchar += strlen (nextchar); - return '?'; - } - } - else if (pfound->has_arg == 1) - { - if (GNoptind < argc) - { - GNoptarg = argv[GNoptind++]; - } - else - { - if (GNopterr) - { - fprintf (stderr, - _("%s: option `%s' requires an argument\n"), - argv[0], argv[GNoptind - 1]); - } - nextchar += strlen (nextchar); - return (optstring[0] == ':') ? ':' : '?'; - } - } - nextchar += strlen (nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) - { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } - - /* Can't find it as a long option. If this is not getopt_long_only, - * or the option starts with '--' or is not a valid short - * option, then it's an error. - * Otherwise interpret it as a short option. */ - if (!long_only || argv[GNoptind][1] == '-' || - my_index (optstring, *nextchar) == NULL) - { - if (GNopterr) - { - if (argv[GNoptind][1] == '-') - /* --option */ - fprintf (stderr, _("%s: unrecognized option `--%s'\n"), - argv[0], nextchar); - else - /* +option or -option */ - fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), - argv[0], argv[GNoptind][0], nextchar); - } - nextchar = (char *) ""; - GNoptind++; - return '?'; - } + /* Can't find it as a long option. If this is not getopt_long_only, + * or the option starts with '--' or is not a valid short + * option, then it's an error. + * Otherwise interpret it as a short option. */ + if (!long_only || argv[GNoptind][1] == '-' || + my_index (optstring, *nextchar) == NULL) + { + if (GNopterr) + { + if (argv[GNoptind][1] == '-') + /* --option */ + fprintf (stderr, _("%s: unrecognized option `--%s'\n"), argv[0], + nextchar); + else + /* +option or -option */ + fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), argv[0], + argv[GNoptind][0], nextchar); + } + nextchar = (char *) ""; + GNoptind++; + return '?'; } + } /* Look at and handle the next short option-character. */ @@ -770,193 +768,191 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring, ++GNoptind; if (temp == NULL || c == ':') + { + if (GNopterr) { - if (GNopterr) - { - if (posixly_correct) - /* 1003.2 specifies the format of this message. */ - fprintf (stderr, _("%s: illegal option -- %c\n"), argv[0], c); - else - fprintf (stderr, _("%s: invalid option -- %c\n"), argv[0], c); - } - return '?'; + if (posixly_correct) + /* 1003.2 specifies the format of this message. */ + fprintf (stderr, _("%s: illegal option -- %c\n"), argv[0], c); + else + fprintf (stderr, _("%s: invalid option -- %c\n"), argv[0], c); } + return '?'; + } /* Convenience. Treat POSIX -W foo same as long option --foo */ if (temp[0] == 'W' && temp[1] == ';') + { + char *nameend; + const struct GNoption *p; + const struct GNoption *pfound = NULL; + int exact = 0; + int ambig = 0; + int indfound = 0; + int option_index; + + /* This is an option that requires an argument. */ + if (*nextchar != '\0') { - char *nameend; - const struct GNoption *p; - const struct GNoption *pfound = NULL; - int exact = 0; - int ambig = 0; - int indfound = 0; - int option_index; - - /* This is an option that requires an argument. */ - if (*nextchar != '\0') - { - GNoptarg = nextchar; - /* If we end this ARGV-element by taking the rest as an arg, - * we must advance to the next element now. */ - GNoptind++; - } - else if (GNoptind == argc) - { - if (GNopterr) - { - /* 1003.2 specifies the format of this message. */ - fprintf (stderr, _("%s: option requires an argument -- %c\n"), - argv[0], c); - } - if (optstring[0] == ':') - c = ':'; - else - c = '?'; - return c; - } - else - /* We already incremented `GNoptind' once; - * increment it again when taking next ARGV-elt as argument. */ - GNoptarg = argv[GNoptind++]; - - /* GNoptarg is now the argument, see if it's in the - * table of longopts. */ - - for (nextchar = nameend = GNoptarg; *nameend && *nameend != '='; - nameend++) - /* Do nothing. */ ; - - /* Test all long options for either exact match - * or abbreviated matches. */ - if (longopts != NULL) - for (p = longopts, option_index = 0; p->name; p++, option_index++) - if (!strncmp (p->name, nextchar, nameend - nextchar)) - { - if ((unsigned int) (nameend - nextchar) == strlen (p->name)) - { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } - else if (pfound == NULL) - { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } - else - /* Second or later nonexact match found. */ - ambig = 1; - } - if (ambig && !exact) - { - if (GNopterr) - fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), - argv[0], argv[GNoptind]); - nextchar += strlen (nextchar); - GNoptind++; - return '?'; - } - if (pfound != NULL) - { - option_index = indfound; - if (*nameend) - { - /* Don't test has_arg with >, because some C compilers don't - * allow it to be used on enums. */ - if (pfound->has_arg) - GNoptarg = nameend + 1; - else - { - if (GNopterr) - fprintf (stderr, _("\ + GNoptarg = nextchar; + /* If we end this ARGV-element by taking the rest as an arg, + * we must advance to the next element now. */ + GNoptind++; + } + else if (GNoptind == argc) + { + if (GNopterr) + { + /* 1003.2 specifies the format of this message. */ + fprintf (stderr, _("%s: option requires an argument -- %c\n"), + argv[0], c); + } + if (optstring[0] == ':') + c = ':'; + else + c = '?'; + return c; + } + else + /* We already incremented `GNoptind' once; + * increment it again when taking next ARGV-elt as argument. */ + GNoptarg = argv[GNoptind++]; + + /* GNoptarg is now the argument, see if it's in the + * table of longopts. */ + + for (nextchar = nameend = GNoptarg; *nameend && *nameend != '='; + nameend++) + /* Do nothing. */ ; + + /* Test all long options for either exact match + * or abbreviated matches. */ + if (longopts != NULL) + for (p = longopts, option_index = 0; p->name; p++, option_index++) + if (!strncmp (p->name, nextchar, nameend - nextchar)) + { + if ((unsigned int) (nameend - nextchar) == strlen (p->name)) + { + /* Exact match found. */ + pfound = p; + indfound = option_index; + exact = 1; + break; + } + else if (pfound == NULL) + { + /* First nonexact match found. */ + pfound = p; + indfound = option_index; + } + else + /* Second or later nonexact match found. */ + ambig = 1; + } + if (ambig && !exact) + { + if (GNopterr) + fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), argv[0], + argv[GNoptind]); + nextchar += strlen (nextchar); + GNoptind++; + return '?'; + } + if (pfound != NULL) + { + option_index = indfound; + if (*nameend) + { + /* Don't test has_arg with >, because some C compilers don't + * allow it to be used on enums. */ + if (pfound->has_arg) + GNoptarg = nameend + 1; + else + { + if (GNopterr) + fprintf (stderr, _("\ %s: option `-W %s' does not allow an argument\n"), argv[0], pfound->name); - nextchar += strlen (nextchar); - return '?'; - } - } - else if (pfound->has_arg == 1) - { - if (GNoptind < argc) - GNoptarg = argv[GNoptind++]; - else - { - if (GNopterr) - fprintf (stderr, - _("%s: option `%s' requires an argument\n"), - argv[0], argv[GNoptind - 1]); - nextchar += strlen (nextchar); - return optstring[0] == ':' ? ':' : '?'; - } - } - nextchar += strlen (nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) - { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } - nextchar = NULL; - return 'W'; /* Let the application handle it. */ + nextchar += strlen (nextchar); + return '?'; + } + } + else if (pfound->has_arg == 1) + { + if (GNoptind < argc) + GNoptarg = argv[GNoptind++]; + else + { + if (GNopterr) + fprintf (stderr, _("%s: option `%s' requires an argument\n"), + argv[0], argv[GNoptind - 1]); + nextchar += strlen (nextchar); + return optstring[0] == ':' ? ':' : '?'; + } + } + nextchar += strlen (nextchar); + if (longind != NULL) + *longind = option_index; + if (pfound->flag) + { + *(pfound->flag) = pfound->val; + return 0; + } + return pfound->val; } + nextchar = NULL; + return 'W'; /* Let the application handle it. */ + } if (temp[1] == ':') + { + if (temp[2] == ':') { - if (temp[2] == ':') - { - /* This is an option that accepts an argument optionally. */ - if (*nextchar != '\0') - { - GNoptarg = nextchar; - GNoptind++; - } - else - GNoptarg = NULL; - nextchar = NULL; - } - else - { - /* This is an option that requires an argument. */ - if (*nextchar != '\0') - { - GNoptarg = nextchar; - /* If we end this ARGV-element by taking the rest as an arg, - * we must advance to the next element now. */ - GNoptind++; - } - else if (GNoptind == argc) - { - if (GNopterr) - { - /* 1003.2 specifies the format of this message. */ - fprintf (stderr, - _("%s: option requires an argument -- %c\n"), - argv[0], c); - } - if (optstring[0] == ':') - c = ':'; - else - c = '?'; - } - else - /* We already incremented `GNoptind' once; - * increment it again when taking next ARGV-elt as argument. */ - GNoptarg = argv[GNoptind++]; - nextchar = NULL; - } + /* This is an option that accepts an argument optionally. */ + if (*nextchar != '\0') + { + GNoptarg = nextchar; + GNoptind++; + } + else + GNoptarg = NULL; + nextchar = NULL; } + else + { + /* This is an option that requires an argument. */ + if (*nextchar != '\0') + { + GNoptarg = nextchar; + /* If we end this ARGV-element by taking the rest as an arg, + * we must advance to the next element now. */ + GNoptind++; + } + else if (GNoptind == argc) + { + if (GNopterr) + { + /* 1003.2 specifies the format of this message. */ + fprintf (stderr, _("%s: option requires an argument -- %c\n"), + argv[0], c); + } + if (optstring[0] == ':') + c = ':'; + else + c = '?'; + } + else + /* We already incremented `GNoptind' once; + * increment it again when taking next ARGV-elt as argument. */ + GNoptarg = argv[GNoptind++]; + nextchar = NULL; + } + } return c; } } static int GNgetopt_long (int argc, char *const *argv, const char *options, - const struct GNoption *long_options, int *opt_index) + const struct GNoption *long_options, int *opt_index) { return GN_getopt_internal (argc, argv, options, long_options, opt_index, 0); } @@ -975,8 +971,8 @@ GNgetopt_long (int argc, char *const *argv, const char *options, */ int GNUNET_GETOPT_run (const char *binaryOptions, - const struct GNUNET_GETOPT_CommandLineOption *allOptions, - unsigned int argc, char *const *argv) + const struct GNUNET_GETOPT_CommandLineOption *allOptions, + unsigned int argc, char *const *argv) { struct GNoption *long_options; struct GNUNET_GETOPT_CommandLineProcessorContext clpc; @@ -1001,15 +997,15 @@ GNUNET_GETOPT_run (const char *binaryOptions, shorts = GNUNET_malloc (count * 2 + 1); spos = 0; for (i = 0; i < count; i++) - { - long_options[i].name = allOptions[i].name; - long_options[i].has_arg = allOptions[i].require_argument; - long_options[i].flag = NULL; - long_options[i].val = allOptions[i].shortName; - shorts[spos++] = allOptions[i].shortName; - if (allOptions[i].require_argument != 0) - shorts[spos++] = ':'; - } + { + long_options[i].name = allOptions[i].name; + long_options[i].has_arg = allOptions[i].require_argument; + long_options[i].flag = NULL; + long_options[i].val = allOptions[i].shortName; + shorts[spos++] = allOptions[i].shortName; + if (allOptions[i].require_argument != 0) + shorts[spos++] = ':'; + } long_options[count].name = NULL; long_options[count].has_arg = 0; long_options[count].flag = NULL; @@ -1018,31 +1014,31 @@ GNUNET_GETOPT_run (const char *binaryOptions, cont = GNUNET_OK; /* main getopt loop */ while (cont == GNUNET_OK) + { + int option_index = 0; + + c = GNgetopt_long (argc, argv, shorts, long_options, &option_index); + + if (c == GNUNET_SYSERR) + break; /* No more flags to process */ + + for (i = 0; i < count; i++) + { + clpc.currentArgument = GNoptind - 1; + if ((char) c == allOptions[i].shortName) + { + cont = + allOptions[i].processor (&clpc, allOptions[i].scls, + allOptions[i].name, GNoptarg); + break; + } + } + if (i == count) { - int option_index = 0; - - c = GNgetopt_long (argc, argv, shorts, long_options, &option_index); - - if (c == GNUNET_SYSERR) - break; /* No more flags to process */ - - for (i = 0; i < count; i++) - { - clpc.currentArgument = GNoptind - 1; - if ((char) c == allOptions[i].shortName) - { - cont = - allOptions[i].processor (&clpc, allOptions[i].scls, - allOptions[i].name, GNoptarg); - break; - } - } - if (i == count) - { - fprintf (stderr, _("Use --help to get a list of options.\n")); - cont = GNUNET_SYSERR; - } + fprintf (stderr, _("Use --help to get a list of options.\n")); + cont = GNUNET_SYSERR; } + } GNUNET_free (shorts); GNUNET_free (long_options); diff --git a/src/util/getopt_helpers.c b/src/util/getopt_helpers.c index 8564d591f..8b49c5907 100644 --- a/src/util/getopt_helpers.c +++ b/src/util/getopt_helpers.c @@ -42,8 +42,8 @@ */ int GNUNET_GETOPT_print_version_ (struct GNUNET_GETOPT_CommandLineProcessorContext - *ctx, void *scls, const char *option, - const char *value) + *ctx, void *scls, const char *option, + const char *value) { const char *version = scls; @@ -66,8 +66,8 @@ GNUNET_GETOPT_print_version_ (struct GNUNET_GETOPT_CommandLineProcessorContext */ int GNUNET_GETOPT_format_help_ (struct GNUNET_GETOPT_CommandLineProcessorContext - *ctx, void *scls, const char *option, - const char *value) + *ctx, void *scls, const char *option, + const char *value) { const char *about = scls; size_t slen; @@ -81,74 +81,74 @@ GNUNET_GETOPT_format_help_ (struct GNUNET_GETOPT_CommandLineProcessorContext printf ("%s\n%s\n", ctx->binaryOptions, gettext (about)); printf (_ - ("Arguments mandatory for long options are also mandatory for short options.\n")); + ("Arguments mandatory for long options are also mandatory for short options.\n")); i = 0; opt = ctx->allOptions; while (opt[i].description != NULL) + { + if (opt[i].shortName == '\0') + printf (" "); + else + printf (" -%c, ", opt[i].shortName); + printf ("--%s", opt[i].name); + slen = 8 + strlen (opt[i].name); + if (opt[i].argumentHelp != NULL) { - if (opt[i].shortName == '\0') - printf (" "); - else - printf (" -%c, ", opt[i].shortName); - printf ("--%s", opt[i].name); - slen = 8 + strlen (opt[i].name); - if (opt[i].argumentHelp != NULL) - { - printf ("=%s", opt[i].argumentHelp); - slen += 1 + strlen (opt[i].argumentHelp); - } - if (slen > BORDER) - { - printf ("\n%*s", BORDER, ""); - slen = BORDER; - } - if (slen < BORDER) - { - printf ("%*s", (int) (BORDER - slen), ""); - slen = BORDER; - } - if (0 < strlen (opt[i].description)) - trans = gettext (opt[i].description); - else - trans = ""; - ml = strlen (trans); - p = 0; - OUTER: - while (ml - p > 78 - slen) - { - for (j = p + 78 - slen; j > p; j--) - { - if (isspace ((unsigned char) trans[j])) - { - scp = GNUNET_malloc (j - p + 1); - memcpy (scp, &trans[p], j - p); - scp[j - p] = '\0'; - printf ("%s\n%*s", scp, BORDER + 2, ""); - GNUNET_free (scp); - p = j + 1; - slen = BORDER + 2; - goto OUTER; - } - } - /* could not find space to break line */ - scp = GNUNET_malloc (78 - slen + 1); - memcpy (scp, &trans[p], 78 - slen); - scp[78 - slen] = '\0'; - printf ("%s\n%*s", scp, BORDER + 2, ""); - GNUNET_free (scp); - slen = BORDER + 2; - p = p + 78 - slen; - } - /* print rest */ - if (p < ml) - printf ("%s\n", &trans[p]); - if (strlen (trans) == 0) - printf ("\n"); - i++; + printf ("=%s", opt[i].argumentHelp); + slen += 1 + strlen (opt[i].argumentHelp); } + if (slen > BORDER) + { + printf ("\n%*s", BORDER, ""); + slen = BORDER; + } + if (slen < BORDER) + { + printf ("%*s", (int) (BORDER - slen), ""); + slen = BORDER; + } + if (0 < strlen (opt[i].description)) + trans = gettext (opt[i].description); + else + trans = ""; + ml = strlen (trans); + p = 0; +OUTER: + while (ml - p > 78 - slen) + { + for (j = p + 78 - slen; j > p; j--) + { + if (isspace ((unsigned char) trans[j])) + { + scp = GNUNET_malloc (j - p + 1); + memcpy (scp, &trans[p], j - p); + scp[j - p] = '\0'; + printf ("%s\n%*s", scp, BORDER + 2, ""); + GNUNET_free (scp); + p = j + 1; + slen = BORDER + 2; + goto OUTER; + } + } + /* could not find space to break line */ + scp = GNUNET_malloc (78 - slen + 1); + memcpy (scp, &trans[p], 78 - slen); + scp[78 - slen] = '\0'; + printf ("%s\n%*s", scp, BORDER + 2, ""); + GNUNET_free (scp); + slen = BORDER + 2; + p = p + 78 - slen; + } + /* print rest */ + if (p < ml) + printf ("%s\n", &trans[p]); + if (strlen (trans) == 0) + printf ("\n"); + i++; + } printf ("Report bugs to gnunet-developers@gnu.org.\n" - "GNUnet home page: http://www.gnu.org/software/gnunet/\n" - "General help using GNU software: http://www.gnu.org/gethelp/\n"); + "GNUnet home page: http://www.gnu.org/software/gnunet/\n" + "General help using GNU software: http://www.gnu.org/gethelp/\n"); return GNUNET_SYSERR; } @@ -168,10 +168,9 @@ GNUNET_GETOPT_format_help_ (struct GNUNET_GETOPT_CommandLineProcessorContext * @return GNUNET_OK */ int -GNUNET_GETOPT_increment_value (struct - GNUNET_GETOPT_CommandLineProcessorContext *ctx, - void *scls, const char *option, - const char *value) +GNUNET_GETOPT_increment_value (struct GNUNET_GETOPT_CommandLineProcessorContext + *ctx, void *scls, const char *option, + const char *value) { int *val = scls; @@ -196,7 +195,7 @@ GNUNET_GETOPT_increment_value (struct */ int GNUNET_GETOPT_set_one (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, - void *scls, const char *option, const char *value) + void *scls, const char *option, const char *value) { int *val = scls; @@ -220,9 +219,8 @@ GNUNET_GETOPT_set_one (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, * @return GNUNET_OK */ int -GNUNET_GETOPT_set_string (struct GNUNET_GETOPT_CommandLineProcessorContext - *ctx, void *scls, const char *option, - const char *value) +GNUNET_GETOPT_set_string (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, + void *scls, const char *option, const char *value) { char **val = scls; @@ -247,18 +245,16 @@ GNUNET_GETOPT_set_string (struct GNUNET_GETOPT_CommandLineProcessorContext * @return GNUNET_OK if parsing the value worked */ int -GNUNET_GETOPT_set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext - *ctx, void *scls, const char *option, - const char *value) +GNUNET_GETOPT_set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, + void *scls, const char *option, const char *value) { unsigned long long *val = scls; if (1 != SSCANF (value, "%llu", val)) - { - fprintf (stderr, _("You must pass a number to the `%s' option.\n"), - option); - return GNUNET_SYSERR; - } + { + fprintf (stderr, _("You must pass a number to the `%s' option.\n"), option); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -278,16 +274,15 @@ GNUNET_GETOPT_set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext */ int GNUNET_GETOPT_set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, - void *scls, const char *option, const char *value) + void *scls, const char *option, const char *value) { unsigned int *val = scls; if (1 != SSCANF (value, "%u", val)) - { - fprintf (stderr, _("You must pass a number to the `%s' option.\n"), - option); - return GNUNET_SYSERR; - } + { + fprintf (stderr, _("You must pass a number to the `%s' option.\n"), option); + return GNUNET_SYSERR; + } return GNUNET_OK; } diff --git a/src/util/gnunet-config-diff.c b/src/util/gnunet-config-diff.c index 992480a30..207b9518a 100644 --- a/src/util/gnunet-config-diff.c +++ b/src/util/gnunet-config-diff.c @@ -8,10 +8,10 @@ main (int argc, char **argv) struct GNUNET_CONFIGURATION_Handle *i2; if (argc != 3) - { - fprintf (stderr, "Invoke using `%s DEFAULTS-IN DIFFS'\n", argv[0]); - return 1; - } + { + fprintf (stderr, "Invoke using `%s DEFAULTS-IN DIFFS'\n", argv[0]); + return 1; + } i1 = GNUNET_CONFIGURATION_create (); i2 = GNUNET_CONFIGURATION_create (); if ((GNUNET_OK != GNUNET_CONFIGURATION_load (i1, argv[1])) || diff --git a/src/util/gnunet-resolver.c b/src/util/gnunet-resolver.c index e97793114..131693dd1 100644 --- a/src/util/gnunet-resolver.c +++ b/src/util/gnunet-resolver.c @@ -72,9 +72,9 @@ main (int argc, char *const *argv) GNUNET_GETOPT_OPTION_END }; return (GNUNET_OK == - GNUNET_PROGRAM_run (argc, argv, "gnunet-resolver [hostname]", - gettext_noop ("Test GNUnet DNS resolver code."), - options, &run, NULL)) ? 0 : 1; + GNUNET_PROGRAM_run (argc, argv, "gnunet-resolver [hostname]", + gettext_noop ("Test GNUnet DNS resolver code."), + options, &run, NULL)) ? 0 : 1; } /* end of gnunet-resolver.c */ diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c index c15f0d3f5..5d4c5c224 100644 --- a/src/util/gnunet-service-resolver.c +++ b/src/util/gnunet-service-resolver.c @@ -89,7 +89,7 @@ getnameinfo_resolve (struct IPCache *cache) if (0 == getnameinfo (cache->sa, cache->salen, hostname, sizeof (hostname), NULL, - 0, 0)) + 0, 0)) cache->addr = GNUNET_strdup (hostname); } #endif @@ -107,20 +107,20 @@ gethostbyaddr_resolve (struct IPCache *cache) struct hostent *ent; switch (cache->sa->sa_family) - { - case AF_INET: - ent = - gethostbyaddr (&((struct sockaddr_in *) cache->sa)->sin_addr, - sizeof (struct in_addr), AF_INET); - break; - case AF_INET6: - ent = - gethostbyaddr (&((struct sockaddr_in6 *) cache->sa)->sin6_addr, - sizeof (struct in6_addr), AF_INET6); - break; - default: - ent = NULL; - } + { + case AF_INET: + ent = + gethostbyaddr (&((struct sockaddr_in *) cache->sa)->sin_addr, + sizeof (struct in_addr), AF_INET); + break; + case AF_INET6: + ent = + gethostbyaddr (&((struct sockaddr_in6 *) cache->sa)->sin6_addr, + sizeof (struct in6_addr), AF_INET6); + break; + default: + ent = NULL; + } if (ent != NULL) cache->addr = GNUNET_strdup (ent->h_name); } @@ -158,7 +158,7 @@ cache_resolve (struct IPCache *cache) */ static void get_ip_as_string (struct GNUNET_SERVER_Client *client, - const struct sockaddr *sa, socklen_t salen) + const struct sockaddr *sa, socklen_t salen) { struct IPCache *cache; struct IPCache *prev; @@ -166,73 +166,73 @@ get_ip_as_string (struct GNUNET_SERVER_Client *client, struct GNUNET_SERVER_TransmitContext *tc; if (salen < sizeof (struct sockaddr)) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } + { + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } now = GNUNET_TIME_absolute_get (); cache = head; prev = NULL; while ((cache != NULL) && - ((cache->salen != salen) || (0 != memcmp (cache->sa, sa, salen)))) + ((cache->salen != salen) || (0 != memcmp (cache->sa, sa, salen)))) + { + if (GNUNET_TIME_absolute_get_duration (cache->last_request).rel_value < + 60 * 60 * 1000) { - if (GNUNET_TIME_absolute_get_duration (cache->last_request).rel_value < - 60 * 60 * 1000) - { - if (prev != NULL) - { - prev->next = cache->next; - GNUNET_free_non_null (cache->addr); - GNUNET_free (cache->sa); - GNUNET_free (cache); - cache = prev->next; - } - else - { - head = cache->next; - GNUNET_free_non_null (cache->addr); - GNUNET_free (cache->sa); - GNUNET_free (cache); - cache = head; - } - continue; - } - prev = cache; - cache = cache->next; + if (prev != NULL) + { + prev->next = cache->next; + GNUNET_free_non_null (cache->addr); + GNUNET_free (cache->sa); + GNUNET_free (cache); + cache = prev->next; + } + else + { + head = cache->next; + GNUNET_free_non_null (cache->addr); + GNUNET_free (cache->sa); + GNUNET_free (cache); + cache = head; + } + continue; } + prev = cache; + cache = cache->next; + } if (cache != NULL) + { + cache->last_request = now; + if (GNUNET_TIME_absolute_get_duration (cache->last_request).rel_value < + 60 * 60 * 1000) { - cache->last_request = now; - if (GNUNET_TIME_absolute_get_duration (cache->last_request).rel_value < - 60 * 60 * 1000) - { - GNUNET_free_non_null (cache->addr); - cache->addr = NULL; - cache->salen = 0; - cache_resolve (cache); - } - } - else - { - cache = GNUNET_malloc (sizeof (struct IPCache)); - cache->next = head; - cache->salen = salen; - cache->sa = GNUNET_malloc (salen); - memcpy (cache->sa, sa, salen); - cache->last_request = GNUNET_TIME_absolute_get (); - cache->last_refresh = GNUNET_TIME_absolute_get (); + GNUNET_free_non_null (cache->addr); cache->addr = NULL; + cache->salen = 0; cache_resolve (cache); - head = cache; } + } + else + { + cache = GNUNET_malloc (sizeof (struct IPCache)); + cache->next = head; + cache->salen = salen; + cache->sa = GNUNET_malloc (salen); + memcpy (cache->sa, sa, salen); + cache->last_request = GNUNET_TIME_absolute_get (); + cache->last_refresh = GNUNET_TIME_absolute_get (); + cache->addr = NULL; + cache_resolve (cache); + head = cache; + } tc = GNUNET_SERVER_transmit_context_create (client); if (cache->addr != NULL) GNUNET_SERVER_transmit_context_append_data (tc, cache->addr, - strlen (cache->addr) + 1, - GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); + strlen (cache->addr) + 1, + GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, - GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); + GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); } @@ -240,7 +240,7 @@ get_ip_as_string (struct GNUNET_SERVER_Client *client, #if HAVE_GETADDRINFO static int getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc, - const char *hostname, int domain) + const char *hostname, int domain) { int s; struct addrinfo hints; @@ -254,37 +254,36 @@ getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc, #else hints.ai_family = AF_INET; #endif - hints.ai_socktype = SOCK_STREAM; /* go for TCP */ + hints.ai_socktype = SOCK_STREAM; /* go for TCP */ if (0 != (s = getaddrinfo (hostname, NULL, &hints, &result))) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Could not resolve `%s' (%s): %s\n"), hostname, - (domain == - AF_INET) ? "IPv4" : ((domain == - AF_INET6) ? "IPv6" : "any"), - gai_strerror (s)); - if ((s == EAI_BADFLAGS) || (s == EAI_MEMORY) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Could not resolve `%s' (%s): %s\n"), + hostname, + (domain == + AF_INET) ? "IPv4" : ((domain == AF_INET6) ? "IPv6" : "any"), + gai_strerror (s)); + if ((s == EAI_BADFLAGS) || (s == EAI_MEMORY) #ifndef MINGW - || (s == EAI_SYSTEM) + || (s == EAI_SYSTEM) #else - // FIXME NILS - || 1 + // FIXME NILS + || 1 #endif - ) - return GNUNET_NO; /* other function may still succeed */ - return GNUNET_SYSERR; - } + ) + return GNUNET_NO; /* other function may still succeed */ + return GNUNET_SYSERR; + } if (result == NULL) return GNUNET_SYSERR; pos = result; while (pos != NULL) - { - GNUNET_SERVER_transmit_context_append_data (tc, pos->ai_addr, - pos->ai_addrlen, - GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); - pos = pos->ai_next; - } + { + GNUNET_SERVER_transmit_context_append_data (tc, pos->ai_addr, + pos->ai_addrlen, + GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); + pos = pos->ai_next; + } freeaddrinfo (result); return GNUNET_OK; } @@ -293,7 +292,7 @@ getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc, #if HAVE_GETHOSTBYNAME2 static int gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc, - const char *hostname, int domain) + const char *hostname, int domain) { struct hostent *hp; struct sockaddr_in a4; @@ -302,48 +301,48 @@ gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc, int ret2; if (domain == AF_UNSPEC) - { - ret1 = gethostbyname2_resolve (tc, hostname, AF_INET); - ret2 = gethostbyname2_resolve (tc, hostname, AF_INET6); - if ((ret1 == GNUNET_OK) || (ret2 == GNUNET_OK)) - return GNUNET_OK; - if ((ret1 == GNUNET_SYSERR) || (ret2 == GNUNET_SYSERR)) - return GNUNET_SYSERR; - return GNUNET_NO; - } + { + ret1 = gethostbyname2_resolve (tc, hostname, AF_INET); + ret2 = gethostbyname2_resolve (tc, hostname, AF_INET6); + if ((ret1 == GNUNET_OK) || (ret2 == GNUNET_OK)) + return GNUNET_OK; + if ((ret1 == GNUNET_SYSERR) || (ret2 == GNUNET_SYSERR)) + return GNUNET_SYSERR; + return GNUNET_NO; + } hp = gethostbyname2 (hostname, domain); if (hp == NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Could not find IP of host `%s': %s\n"), hostname, - hstrerror (h_errno)); - return GNUNET_SYSERR; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _("Could not find IP of host `%s': %s\n"), hostname, + hstrerror (h_errno)); + return GNUNET_SYSERR; + } GNUNET_assert (hp->h_addrtype == domain); if (domain == AF_INET) - { - GNUNET_assert (hp->h_length == sizeof (struct in_addr)); - memset (&a4, 0, sizeof (a4)); - a4.sin_family = AF_INET; + { + GNUNET_assert (hp->h_length == sizeof (struct in_addr)); + memset (&a4, 0, sizeof (a4)); + a4.sin_family = AF_INET; #if HAVE_SOCKADDR_IN_SIN_LEN - a4.sin_len = (u_char) sizeof (struct sockaddr_in); + a4.sin_len = (u_char) sizeof (struct sockaddr_in); #endif - memcpy (&a4.sin_addr, hp->h_addr_list[0], hp->h_length); - GNUNET_SERVER_transmit_context_append_data (tc, &a4, sizeof (a4), - GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); - } + memcpy (&a4.sin_addr, hp->h_addr_list[0], hp->h_length); + GNUNET_SERVER_transmit_context_append_data (tc, &a4, sizeof (a4), + GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); + } else - { - GNUNET_assert (hp->h_length == sizeof (struct in6_addr)); - memset (&a6, 0, sizeof (a6)); - a6.sin6_family = AF_INET6; + { + GNUNET_assert (hp->h_length == sizeof (struct in6_addr)); + memset (&a6, 0, sizeof (a6)); + a6.sin6_family = AF_INET6; #if HAVE_SOCKADDR_IN_SIN_LEN - a6.sin6_len = (u_char) sizeof (struct sockaddr_in6); + a6.sin6_len = (u_char) sizeof (struct sockaddr_in6); #endif - memcpy (&a6.sin6_addr, hp->h_addr_list[0], hp->h_length); - GNUNET_SERVER_transmit_context_append_data (tc, &a6, sizeof (a6), - GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); - } + memcpy (&a6.sin6_addr, hp->h_addr_list[0], hp->h_length); + GNUNET_SERVER_transmit_context_append_data (tc, &a6, sizeof (a6), + GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); + } return GNUNET_OK; } #endif @@ -351,24 +350,24 @@ gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc, #if HAVE_GETHOSTBYNAME static int gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc, - const char *hostname) + const char *hostname) { struct hostent *hp; struct sockaddr_in addr; hp = GETHOSTBYNAME (hostname); if (hp == NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Could not find IP of host `%s': %s\n"), hostname, - hstrerror (h_errno)); - return GNUNET_SYSERR; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _("Could not find IP of host `%s': %s\n"), hostname, + hstrerror (h_errno)); + return GNUNET_SYSERR; + } if (hp->h_addrtype != AF_INET) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } GNUNET_assert (hp->h_length == sizeof (struct in_addr)); memset (&addr, 0, sizeof (addr)); addr.sin_family = AF_INET; @@ -377,7 +376,7 @@ gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc, #endif memcpy (&addr.sin_addr, hp->h_addr_list[0], hp->h_length); GNUNET_SERVER_transmit_context_append_data (tc, &addr, sizeof (addr), - GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); + GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); return GNUNET_OK; } #endif @@ -391,8 +390,8 @@ gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc, * @param domain AF_INET or AF_INET6; use AF_UNSPEC for "any" */ static void -get_ip_from_hostname (struct GNUNET_SERVER_Client *client, - const char *hostname, int domain) +get_ip_from_hostname (struct GNUNET_SERVER_Client *client, const char *hostname, + int domain) { int ret; struct GNUNET_SERVER_TransmitContext *tc; @@ -412,7 +411,7 @@ get_ip_from_hostname (struct GNUNET_SERVER_Client *client, gethostbyname_resolve (tc, hostname); #endif GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, - GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); + GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); } @@ -426,7 +425,7 @@ get_ip_from_hostname (struct GNUNET_SERVER_Client *client, */ static void handle_get (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) + const struct GNUNET_MessageHeader *message) { uint16_t msize; const struct GNUNET_RESOLVER_GetMessage *msg; @@ -438,78 +437,78 @@ handle_get (void *cls, struct GNUNET_SERVER_Client *client, msize = ntohs (message->size); if (msize < sizeof (struct GNUNET_RESOLVER_GetMessage)) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } + { + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } msg = (const struct GNUNET_RESOLVER_GetMessage *) message; size = msize - sizeof (struct GNUNET_RESOLVER_GetMessage); direction = ntohl (msg->direction); domain = ntohl (msg->domain); if (direction == GNUNET_NO) + { + /* IP from hostname */ + hostname = (const char *) &msg[1]; + if (hostname[size - 1] != '\0') { - /* IP from hostname */ - hostname = (const char *) &msg[1]; - if (hostname[size - 1] != '\0') - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } #if DEBUG_RESOLVER - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - _("Resolver asked to look up `%s'.\n"), hostname); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolver asked to look up `%s'.\n"), + hostname); #endif - get_ip_from_hostname (client, hostname, domain); - } + get_ip_from_hostname (client, hostname, domain); + } else - { + { #if DEBUG_RESOLVER - char buf[INET6_ADDRSTRLEN]; + char buf[INET6_ADDRSTRLEN]; #endif - if (size < sizeof (struct sockaddr)) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } - sa = (const struct sockaddr *) &msg[1]; - switch (sa->sa_family) - { - case AF_INET: - if (size != sizeof (struct sockaddr_in)) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } + if (size < sizeof (struct sockaddr)) + { + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } + sa = (const struct sockaddr *) &msg[1]; + switch (sa->sa_family) + { + case AF_INET: + if (size != sizeof (struct sockaddr_in)) + { + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } #if DEBUG_RESOLVER - inet_ntop (AF_INET, sa, buf, size); + inet_ntop (AF_INET, sa, buf, size); #endif - break; - case AF_INET6: - if (size != sizeof (struct sockaddr_in6)) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } + break; + case AF_INET6: + if (size != sizeof (struct sockaddr_in6)) + { + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } #if DEBUG_RESOLVER - inet_ntop (AF_INET6, sa, buf, size); + inet_ntop (AF_INET6, sa, buf, size); #endif - break; - default: - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } + break; + default: + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } #if DEBUG_RESOLVER - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - _("Resolver asked to look up IP address `%s'.\n"), buf); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + _("Resolver asked to look up IP address `%s'.\n"), buf); #endif - get_ip_as_string (client, sa, size); - } + get_ip_as_string (client, sa, size); + } } @@ -546,18 +545,18 @@ main (int argc, char *const *argv) struct IPCache *pos; ret = - (GNUNET_OK == - GNUNET_SERVICE_run (argc, argv, "resolver", GNUNET_SERVICE_OPTION_NONE, - &run, NULL)) ? 0 : 1; + (GNUNET_OK == + GNUNET_SERVICE_run (argc, argv, "resolver", GNUNET_SERVICE_OPTION_NONE, + &run, NULL)) ? 0 : 1; while (head != NULL) - { - pos = head->next; - GNUNET_free_non_null (head->addr); - GNUNET_free (head->sa); - GNUNET_free (head); - head = pos; - } + { + pos = head->next; + GNUNET_free_non_null (head->addr); + GNUNET_free (head->sa); + GNUNET_free (head); + head = pos; + } return ret; } diff --git a/src/util/load.c b/src/util/load.c index 1df1abc7c..e978a950d 100644 --- a/src/util/load.c +++ b/src/util/load.c @@ -94,23 +94,23 @@ internal_update (struct GNUNET_LOAD_Value *load) if (delta.rel_value < load->autodecline.rel_value) return; if (load->autodecline.rel_value == 0) - { - load->runavg_delay = 0.0; - load->load = 0; - return; - } + { + load->runavg_delay = 0.0; + load->load = 0; + return; + } n = delta.rel_value / load->autodecline.rel_value; if (n > 16) - { - load->runavg_delay = 0.0; - load->load = 0; - return; - } + { + load->runavg_delay = 0.0; + load->load = 0; + return; + } while (n > 0) - { - n--; - load->runavg_delay = (load->runavg_delay * 7.0) / 8.0; - } + { + n--; + load->runavg_delay = (load->runavg_delay * 7.0) / 8.0; + } } @@ -142,7 +142,7 @@ GNUNET_LOAD_value_init (struct GNUNET_TIME_Relative autodecline) */ void GNUNET_LOAD_value_set_decline (struct GNUNET_LOAD_Value *load, - struct GNUNET_TIME_Relative autodecline) + struct GNUNET_TIME_Relative autodecline) { internal_update (load); load->autodecline = autodecline; @@ -177,10 +177,10 @@ calculate_load (struct GNUNET_LOAD_Value *load) nm1 = n - 1.0; avgdel = sum_val_i / n; stddev = - (((double) load->cummulative_squared_delay) - 2.0 * avgdel * sum_val_i + - n * avgdel * avgdel) / nm1; + (((double) load->cummulative_squared_delay) - 2.0 * avgdel * sum_val_i + + n * avgdel * avgdel) / nm1; if (stddev <= 0) - stddev = 0.01; /* must have been rounding error or zero; prevent division by zero */ + stddev = 0.01; /* must have been rounding error or zero; prevent division by zero */ /* now calculate load based on how far out we are from * std dev; or if we are below average, simply assume load zero */ if (load->runavg_delay < avgdel) @@ -243,11 +243,11 @@ GNUNET_LOAD_update (struct GNUNET_LOAD_Value *load, uint64_t data) internal_update (load); load->last_update = GNUNET_TIME_absolute_get (); if (data > 64 * 1024) - { - /* very large */ - load->load = 100.0; - return; - } + { + /* very large */ + load->load = 100.0; + return; + } dv = (uint32_t) data; load->cummulative_delay += dv; load->cummulative_squared_delay += dv * dv; diff --git a/src/util/network.c b/src/util/network.c index 3fc71e666..180adc164 100644 --- a/src/util/network.c +++ b/src/util/network.c @@ -90,11 +90,11 @@ socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, int doBlock) mode = !doBlock; if (ioctlsocket (fd->fd, FIONBIO, &mode) == SOCKET_ERROR) - { - SetErrnoFromWinsockError (WSAGetLastError ()); - LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "ioctlsocket"); - return GNUNET_SYSERR; - } + { + SetErrnoFromWinsockError (WSAGetLastError ()); + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "ioctlsocket"); + return GNUNET_SYSERR; + } return GNUNET_OK; #else @@ -103,10 +103,10 @@ socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, int doBlock) if (flags == -1) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "fcntl"); - return GNUNET_SYSERR; - } + { + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "fcntl"); + return GNUNET_SYSERR; + } if (doBlock) flags &= ~O_NONBLOCK; @@ -114,10 +114,10 @@ socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, int doBlock) flags |= O_NONBLOCK; if (0 != fcntl (fd->fd, F_SETFL, flags)) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "fcntl"); - return GNUNET_SYSERR; - } + { + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "fcntl"); + return GNUNET_SYSERR; + } return GNUNET_OK; #endif } @@ -162,7 +162,7 @@ socket_set_nosigpipe (const struct GNUNET_NETWORK_Handle *h) if (0 != setsockopt (h->fd, SOL_SOCKET, SO_NOSIGPIPE, &abs_value, - sizeof (abs_value))) + sizeof (abs_value))) LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); } #endif @@ -181,15 +181,14 @@ socket_set_nodelay (const struct GNUNET_NETWORK_Handle *h) #ifndef WINDOWS int value = 1; - if (0 != - setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, &value, sizeof (value))) + if (0 != setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, &value, sizeof (value))) LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); #else const char *abs_value = "1"; if (0 != setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, abs_value, - sizeof (abs_value))) + sizeof (abs_value))) LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); #endif } @@ -205,8 +204,7 @@ socket_set_nodelay (const struct GNUNET_NETWORK_Handle *h) */ struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, - struct sockaddr *address, - socklen_t * address_len) + struct sockaddr *address, socklen_t * address_len) { struct GNUNET_NETWORK_Handle *ret; @@ -219,7 +217,7 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, if (gsn == 0) LOG (GNUNET_ERROR_TYPE_DEBUG, "Accepting connection on `%s'\n", - GNUNET_a2s (&name, namelen)); + GNUNET_a2s (&name, namelen)); } #endif ret->fd = accept (desc->fd, address, address_len); @@ -228,36 +226,36 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, else ret->af = desc->af; if (ret->fd == INVALID_SOCKET) - { + { #ifdef MINGW - SetErrnoFromWinsockError (WSAGetLastError ()); + SetErrnoFromWinsockError (WSAGetLastError ()); #endif - GNUNET_free (ret); - return NULL; - } + GNUNET_free (ret); + return NULL; + } #ifndef MINGW if (ret->fd >= FD_SETSIZE) - { - GNUNET_break (0 == close (ret->fd)); - GNUNET_free (ret); - errno = EMFILE; - return NULL; - } + { + GNUNET_break (0 == close (ret->fd)); + GNUNET_free (ret); + errno = EMFILE; + return NULL; + } #endif if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO)) - { + { - /* we might want to treat this one as fatal... */ - GNUNET_break (0); - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret)); - return NULL; - } + /* we might want to treat this one as fatal... */ + GNUNET_break (0); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret)); + return NULL; + } #ifndef MINGW if (GNUNET_OK != socket_set_inheritable (ret)) LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "socket_set_inheritable"); + "socket_set_inheritable"); #endif #ifdef DARWIN socket_set_nosigpipe (ret); @@ -279,8 +277,8 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, */ int GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, - const struct sockaddr *address, - socklen_t address_len) + const struct sockaddr *address, + socklen_t address_len) { int ret; @@ -289,8 +287,7 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, const int on = 1; if (desc->af == AF_INET6) - if (0 != - setsockopt (desc->fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on))) + if (0 != setsockopt (desc->fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on))) LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, "setsockopt"); #endif #endif @@ -302,11 +299,11 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, #ifndef LINUX #ifndef MINGW if (address->sa_family == AF_UNIX) - { - const struct sockaddr_un *un = (const struct sockaddr_un *) address; + { + const struct sockaddr_un *un = (const struct sockaddr_un *) address; - (void) unlink (un->sun_path); - } + (void) unlink (un->sun_path); + } #endif #endif ret = bind (desc->fd, address, address_len); @@ -341,8 +338,8 @@ GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc) DWORD error = 0; #if DEBUG_NETWORK - LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_NETWORK_socket_close", - "Closing 0x%x\n", desc->fd); + LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_NETWORK_socket_close", "Closing 0x%x\n", + desc->fd); #endif SetLastError (0); ret = closesocket (desc->fd); @@ -350,8 +347,8 @@ GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc) SetErrnoFromWinsockError (error); #if DEBUG_NETWORK LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_NETWORK_socket_close", - "Closed 0x%x, closesocket() returned %d, GLE is %u\n", - desc->fd, ret, error); + "Closed 0x%x, closesocket() returned %d, GLE is %u\n", desc->fd, ret, + error); #endif #else ret = close (desc->fd); @@ -359,12 +356,12 @@ GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc) #ifndef LINUX #ifndef MINGW if ((desc->af == AF_UNIX) && (NULL != desc->addr)) - { - const struct sockaddr_un *un = (const struct sockaddr_un *) desc->addr; + { + const struct sockaddr_un *un = (const struct sockaddr_un *) desc->addr; - if (0 != unlink (un->sun_path)) - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", un->sun_path); - } + if (0 != unlink (un->sun_path)) + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", un->sun_path); + } #endif #endif GNUNET_free_non_null (desc->addr); @@ -388,7 +385,7 @@ GNUNET_NETWORK_socket_box_native (int fd) struct GNUNET_NETWORK_Handle *ret; if (fcntl (fd, F_GETFD) < 0) - return NULL; /* invalid FD */ + return NULL; /* invalid FD */ ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle)); ret->fd = fd; ret->af = AF_UNSPEC; @@ -406,8 +403,8 @@ GNUNET_NETWORK_socket_box_native (int fd) */ int GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc, - const struct sockaddr *address, - socklen_t address_len) + const struct sockaddr *address, + socklen_t address_len) { int ret; @@ -415,11 +412,11 @@ GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc, #ifdef MINGW if (SOCKET_ERROR == ret) - { - SetErrnoFromWinsockError (WSAGetLastError ()); - if (errno == EWOULDBLOCK) - errno = EINPROGRESS; - } + { + SetErrnoFromWinsockError (WSAGetLastError ()); + if (errno == EWOULDBLOCK) + errno = EINPROGRESS; + } #endif return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; } @@ -437,8 +434,8 @@ GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc, */ int GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc, - int level, int optname, void *optval, - socklen_t * optlen) + int level, int optname, void *optval, + socklen_t * optlen) { int ret; @@ -463,7 +460,7 @@ GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc, */ int GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, - int backlog) + int backlog) { int ret; @@ -486,7 +483,7 @@ GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, */ ssize_t GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle * - desc) + desc) { int error; @@ -519,9 +516,8 @@ GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle * */ ssize_t GNUNET_NETWORK_socket_recvfrom (const struct GNUNET_NETWORK_Handle * desc, - void *buffer, size_t length, - struct sockaddr * src_addr, - socklen_t * addrlen) + void *buffer, size_t length, + struct sockaddr * src_addr, socklen_t * addrlen) { int ret; int flags; @@ -549,7 +545,7 @@ GNUNET_NETWORK_socket_recvfrom (const struct GNUNET_NETWORK_Handle * desc, */ ssize_t GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle * desc, - void *buffer, size_t length) + void *buffer, size_t length) { int ret; int flags; @@ -578,7 +574,7 @@ GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle * desc, */ ssize_t GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle * desc, - const void *buffer, size_t length) + const void *buffer, size_t length) { int ret; int flags; @@ -617,9 +613,9 @@ GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle * desc, */ ssize_t GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle * desc, - const void *message, size_t length, - const struct sockaddr * dest_addr, - socklen_t dest_len) + const void *message, size_t length, + const struct sockaddr * dest_addr, + socklen_t dest_len) { int ret; int flags; @@ -652,8 +648,8 @@ GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle * desc, */ int GNUNET_NETWORK_socket_setsockopt (struct GNUNET_NETWORK_Handle *fd, int level, - int option_name, const void *option_value, - socklen_t option_len) + int option_name, const void *option_value, + socklen_t option_len) { int ret; @@ -685,36 +681,36 @@ GNUNET_NETWORK_socket_create (int domain, int type, int protocol) ret->af = domain; ret->fd = socket (domain, type, protocol); if (INVALID_SOCKET == ret->fd) - { + { #ifdef MINGW - SetErrnoFromWinsockError (WSAGetLastError ()); + SetErrnoFromWinsockError (WSAGetLastError ()); #endif - GNUNET_free (ret); - return NULL; - } + GNUNET_free (ret); + return NULL; + } #ifndef MINGW if (ret->fd >= FD_SETSIZE) - { - GNUNET_break (0 == close (ret->fd)); - GNUNET_free (ret); - errno = EMFILE; - return NULL; - } + { + GNUNET_break (0 == close (ret->fd)); + GNUNET_free (ret); + errno = EMFILE; + return NULL; + } #endif if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO)) - { - /* we might want to treat this one as fatal... */ - GNUNET_break (0); - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret)); - return NULL; - } + { + /* we might want to treat this one as fatal... */ + GNUNET_break (0); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret)); + return NULL; + } #ifndef MINGW if (GNUNET_OK != socket_set_inheritable (ret)) LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "socket_set_inheritable"); + "socket_set_inheritable"); #endif #ifdef DARWIN socket_set_nosigpipe (ret); @@ -723,7 +719,7 @@ GNUNET_NETWORK_socket_create (int domain, int type, int protocol) #ifdef AF_UNIX && (domain != AF_UNIX) #endif - ) + ) socket_set_nodelay (ret); return ret; } @@ -762,18 +758,19 @@ int GNUNET_NETWORK_socket_disable_corking (struct GNUNET_NETWORK_Handle *desc) { int ret = 0; + #if WINDOWS int value = 0; if (0 != (ret = setsockopt (desc->fd, SOL_SOCKET, SO_SNDBUF, (char *) &value, - sizeof (value)))) + sizeof (value)))) LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); if (0 != (ret = setsockopt (desc->fd, SOL_SOCKET, SO_RCVBUF, (char *) &value, - sizeof (value)))) + sizeof (value)))) LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); #elif LINUX int value = 0; @@ -812,7 +809,7 @@ GNUNET_NETWORK_fdset_zero (struct GNUNET_NETWORK_FDSet *fds) */ void GNUNET_NETWORK_fdset_set (struct GNUNET_NETWORK_FDSet *fds, - const struct GNUNET_NETWORK_Handle *desc) + const struct GNUNET_NETWORK_Handle *desc) { FD_SET (desc->fd, &fds->sds); if (desc->fd + 1 > fds->nsds) @@ -828,7 +825,7 @@ GNUNET_NETWORK_fdset_set (struct GNUNET_NETWORK_FDSet *fds, */ int GNUNET_NETWORK_fdset_isset (const struct GNUNET_NETWORK_FDSet *fds, - const struct GNUNET_NETWORK_Handle *desc) + const struct GNUNET_NETWORK_Handle *desc) { return FD_ISSET (desc->fd, &fds->sds); } @@ -841,18 +838,18 @@ GNUNET_NETWORK_fdset_isset (const struct GNUNET_NETWORK_FDSet *fds, */ void GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst, - const struct GNUNET_NETWORK_FDSet *src) + const struct GNUNET_NETWORK_FDSet *src) { int nfds; for (nfds = src->nsds; nfds > 0; nfds--) if (FD_ISSET (nfds, &src->sds)) - { - FD_SET (nfds, &dst->sds); - if (nfds + 1 > dst->nsds) - dst->nsds = nfds + 1; - } + { + FD_SET (nfds, &dst->sds); + if (nfds + 1 > dst->nsds) + dst->nsds = nfds + 1; + } #ifdef MINGW GNUNET_CONTAINER_slist_append (dst->handles, src->handles); #endif @@ -867,7 +864,7 @@ GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst, */ void GNUNET_NETWORK_fdset_copy (struct GNUNET_NETWORK_FDSet *to, - const struct GNUNET_NETWORK_FDSet *from) + const struct GNUNET_NETWORK_FDSet *from) { FD_COPY (&from->sds, &to->sds); to->nsds = from->nsds; @@ -901,7 +898,7 @@ GNUNET_NETWORK_get_fd (struct GNUNET_NETWORK_Handle *desc) */ void GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to, - const fd_set * from, int nfds) + const fd_set * from, int nfds) { FD_COPY (from, &to->sds); to->nsds = nfds; @@ -932,7 +929,7 @@ GNUNET_NETWORK_fdset_set_native (struct GNUNET_NETWORK_FDSet *to, int nfd) */ int GNUNET_NETWORK_fdset_test_native (const struct GNUNET_NETWORK_FDSet *to, - int nfd) + int nfd) { if ((nfd == -1) || (to == NULL)) return GNUNET_NO; @@ -947,12 +944,12 @@ GNUNET_NETWORK_fdset_test_native (const struct GNUNET_NETWORK_FDSet *to, */ void GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds, - const struct GNUNET_DISK_FileHandle *h) + const struct GNUNET_DISK_FileHandle *h) { #ifdef MINGW GNUNET_CONTAINER_slist_add (fds->handles, - GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, h, - sizeof (struct GNUNET_DISK_FileHandle)); + GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, h, + sizeof (struct GNUNET_DISK_FileHandle)); #else int fd; @@ -974,13 +971,13 @@ GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds, */ int GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds, - const struct GNUNET_DISK_FileHandle *h) + const struct GNUNET_DISK_FileHandle *h) { #ifdef MINGW return GNUNET_CONTAINER_slist_contains (fds->handles, h, - sizeof (struct - GNUNET_DISK_FileHandle)); + sizeof (struct + GNUNET_DISK_FileHandle)); #else return FD_ISSET (h->fd, &fds->sds); #endif @@ -995,7 +992,7 @@ GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds, */ int GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, - const struct GNUNET_NETWORK_FDSet *fds2) + const struct GNUNET_NETWORK_FDSet *fds2) { #ifndef MINGW int nfds; @@ -1004,11 +1001,11 @@ GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, if (nfds > fds2->nsds) nfds = fds2->nsds; while (nfds > 0) - { - nfds--; - if (FD_ISSET (nfds, &fds1->sds) && FD_ISSET (nfds, &fds2->sds)) - return GNUNET_YES; - } + { + nfds--; + if (FD_ISSET (nfds, &fds1->sds) && FD_ISSET (nfds, &fds2->sds)) + return GNUNET_YES; + } #else struct GNUNET_CONTAINER_SList_Iterator it; struct GNUNET_DISK_FileHandle *h; @@ -1019,47 +1016,45 @@ GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, * inside of fd_set; also the O(n^2) is really bad... */ for (i = 0; i < fds1->sds.fd_count; i++) + { + for (j = 0; j < fds2->sds.fd_count; j++) { - for (j = 0; j < fds2->sds.fd_count; j++) - { - if (fds1->sds.fd_array[i] == fds2->sds.fd_array[j]) - return GNUNET_YES; - } + if (fds1->sds.fd_array[i] == fds2->sds.fd_array[j]) + return GNUNET_YES; } + } it = GNUNET_CONTAINER_slist_begin (fds1->handles); while (GNUNET_CONTAINER_slist_end (&it) != GNUNET_YES) - { + { #if DEBUG_NETWORK - struct GNUNET_CONTAINER_SList_Iterator t; + struct GNUNET_CONTAINER_SList_Iterator t; #endif - h = - (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&it, - NULL); + h = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&it, + NULL); #if DEBUG_NETWORK - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Checking that FD 0x%x is in another set:\n", h->h); - for (t = GNUNET_CONTAINER_slist_begin (fds2->handles); - GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES; - GNUNET_CONTAINER_slist_next (&t)) - { - struct GNUNET_DISK_FileHandle *fh; - - fh = - (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t, - NULL); - LOG (GNUNET_ERROR_TYPE_DEBUG, "0x%x\n", fh->h); - } -#endif - if (GNUNET_CONTAINER_slist_contains - (fds2->handles, h, sizeof (struct GNUNET_DISK_FileHandle))) - { + LOG (GNUNET_ERROR_TYPE_DEBUG, "Checking that FD 0x%x is in another set:\n", + h->h); + for (t = GNUNET_CONTAINER_slist_begin (fds2->handles); + GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES; + GNUNET_CONTAINER_slist_next (&t)) + { + struct GNUNET_DISK_FileHandle *fh; + + fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t, + NULL); + LOG (GNUNET_ERROR_TYPE_DEBUG, "0x%x\n", fh->h); + } +#endif + if (GNUNET_CONTAINER_slist_contains + (fds2->handles, h, sizeof (struct GNUNET_DISK_FileHandle))) + { #if DEBUG_NETWORK - LOG (GNUNET_ERROR_TYPE_DEBUG, "Match!\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Match!\n"); #endif - return GNUNET_YES; - } - GNUNET_CONTAINER_slist_next (&it); + return GNUNET_YES; } + GNUNET_CONTAINER_slist_next (&it); + } #endif return GNUNET_NO; } @@ -1106,9 +1101,9 @@ GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds) */ int GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, - struct GNUNET_NETWORK_FDSet *wfds, - struct GNUNET_NETWORK_FDSet *efds, - const struct GNUNET_TIME_Relative timeout) + struct GNUNET_NETWORK_FDSet *wfds, + struct GNUNET_NETWORK_FDSet *efds, + const struct GNUNET_TIME_Relative timeout) { int nfds = 0; @@ -1138,8 +1133,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, DWORD newretcode = 0; int returnedpos = 0; - struct GNUNET_CONTAINER_SList *handles_read, *handles_write, - *handles_except; + struct GNUNET_CONTAINER_SList *handles_read, *handles_write, *handles_except; fd_set aread, awrite, aexcept; @@ -1153,68 +1147,67 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, struct timeval tv; #endif if (NULL != rfds) - { - nfds = rfds->nsds; + { + nfds = rfds->nsds; #ifdef MINGW - handles += read_handles = GNUNET_CONTAINER_slist_count (rfds->handles); + handles += read_handles = GNUNET_CONTAINER_slist_count (rfds->handles); #if DEBUG_NETWORK + { + struct GNUNET_CONTAINER_SList_Iterator t; + + for (t = GNUNET_CONTAINER_slist_begin (rfds->handles); + GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES; + GNUNET_CONTAINER_slist_next (&t)) { - struct GNUNET_CONTAINER_SList_Iterator t; - - for (t = GNUNET_CONTAINER_slist_begin (rfds->handles); - GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES; - GNUNET_CONTAINER_slist_next (&t)) - { - struct GNUNET_DISK_FileHandle *fh; - - fh = - (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t, - NULL); - LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x (0x%x) is SET in rfds\n", - fh->h, fh); - } + struct GNUNET_DISK_FileHandle *fh; + + fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t, + NULL); + LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x (0x%x) is SET in rfds\n", fh->h, + fh); } + } #endif #endif - } + } if (NULL != wfds) - { - nfds = GNUNET_MAX (nfds, wfds->nsds); + { + nfds = GNUNET_MAX (nfds, wfds->nsds); #ifdef MINGW - handles += write_handles = GNUNET_CONTAINER_slist_count (wfds->handles); + handles += write_handles = GNUNET_CONTAINER_slist_count (wfds->handles); #endif - } + } if (NULL != efds) - { - nfds = GNUNET_MAX (nfds, efds->nsds); + { + nfds = GNUNET_MAX (nfds, efds->nsds); #ifdef MINGW - handles += ex_handles = GNUNET_CONTAINER_slist_count (efds->handles); + handles += ex_handles = GNUNET_CONTAINER_slist_count (efds->handles); #endif - } + } if ((nfds == 0) && (timeout.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value) #ifdef MINGW && handles == 0 #endif - ) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _ - ("Fatal internal logic error, process hangs in `%s' (abort with CTRL-C)!\n"), - "select"); - GNUNET_break (0); - } + ) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _ + ("Fatal internal logic error, process hangs in `%s' (abort with CTRL-C)!\n"), + "select"); + GNUNET_break (0); + } #ifndef MINGW tv.tv_sec = timeout.rel_value / GNUNET_TIME_UNIT_SECONDS.rel_value; tv.tv_usec = - 1000 * (timeout.rel_value - - (tv.tv_sec * GNUNET_TIME_UNIT_SECONDS.rel_value)); + 1000 * (timeout.rel_value - + (tv.tv_sec * GNUNET_TIME_UNIT_SECONDS.rel_value)); return select (nfds, (rfds != NULL) ? &rfds->sds : NULL, - (wfds != NULL) ? &wfds->sds : NULL, - (efds != NULL) ? &efds->sds : NULL, - (timeout.rel_value == - GNUNET_TIME_UNIT_FOREVER_REL.rel_value) ? NULL : &tv); + (wfds != NULL) ? &wfds->sds : NULL, + (efds != NULL) ? &efds->sds : NULL, + (timeout.rel_value == + GNUNET_TIME_UNIT_FOREVER_REL.rel_value) ? NULL : &tv); #else #define SAFE_FD_ISSET(fd, set) (set != NULL && FD_ISSET(fd, set)) @@ -1225,10 +1218,10 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, ms_total = timeout.rel_value / GNUNET_TIME_UNIT_MILLISECONDS.rel_value; /* select() may be used as a portable way to sleep */ if (!(rfds || wfds || efds)) - { - Sleep (ms_total); - return 0; - } + { + Sleep (ms_total); + return 0; + } /* Events for sockets */ if (!hEventRead) @@ -1264,194 +1257,184 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, FD_ZERO (&bexcept); #endif if (rfds) - { - FD_COPY (&rfds->sds, &aread); + { + FD_COPY (&rfds->sds, &aread); #if DEBUG_NETWORK - FD_COPY (&rfds->sds, &bread); + FD_COPY (&rfds->sds, &bread); #endif - } + } if (wfds) - { - FD_COPY (&wfds->sds, &awrite); + { + FD_COPY (&wfds->sds, &awrite); #if DEBUG_NETWORK - FD_COPY (&wfds->sds, &bwrite); + FD_COPY (&wfds->sds, &bwrite); #endif - } + } if (efds) - { - FD_COPY (&efds->sds, &aexcept); + { + FD_COPY (&efds->sds, &aexcept); #if DEBUG_NETWORK - FD_COPY (&efds->sds, &bexcept); + FD_COPY (&efds->sds, &bexcept); #endif - } + } /* We will first Add the PIPES to the events */ /* Read Pipes */ if (rfds && read_handles) + { + struct GNUNET_CONTAINER_SList_Iterator i; + + for (i = GNUNET_CONTAINER_slist_begin (rfds->handles); + GNUNET_CONTAINER_slist_end (&i) != GNUNET_YES; + GNUNET_CONTAINER_slist_next (&i)) { - struct GNUNET_CONTAINER_SList_Iterator i; - - for (i = GNUNET_CONTAINER_slist_begin (rfds->handles); - GNUNET_CONTAINER_slist_end (&i) != GNUNET_YES; - GNUNET_CONTAINER_slist_next (&i)) - { - struct GNUNET_DISK_FileHandle *fh; - - fh = - (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&i, - NULL); - if (fh->type == GNUNET_PIPE) - { - /* Read zero bytes to check the status of the pipe */ + struct GNUNET_DISK_FileHandle *fh; + + fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&i, + NULL); + if (fh->type == GNUNET_PIPE) + { + /* Read zero bytes to check the status of the pipe */ #if DEBUG_NETWORK - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Reading 0 bytes from the pipe 0x%x\n", fh->h); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Reading 0 bytes from the pipe 0x%x\n", + fh->h); #endif - if (!ReadFile (fh->h, NULL, 0, NULL, fh->oOverlapRead)) - { - DWORD error_code = GetLastError (); + if (!ReadFile (fh->h, NULL, 0, NULL, fh->oOverlapRead)) + { + DWORD error_code = GetLastError (); - if (error_code == ERROR_IO_PENDING) - { + if (error_code == ERROR_IO_PENDING) + { #if DEBUG_NETWORK - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Adding the pipe's 0x%x overlapped event to the array as %d\n", - fh->h, nhandles); -#endif - handle_array[nhandles++] = fh->oOverlapRead->hEvent; - readArray[readPipes++] = fh; - } - /* - * else - * { - * SetErrnoFromWinError (error_code); - * } - */ - } - else - { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Adding the pipe's 0x%x overlapped event to the array as %d\n", + fh->h, nhandles); +#endif + handle_array[nhandles++] = fh->oOverlapRead->hEvent; + readArray[readPipes++] = fh; + } + /* + * else + * { + * SetErrnoFromWinError (error_code); + * } + */ + } + else + { #if DEBUG_NETWORK - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Adding the read ready event to the array as %d\n", - nhandles); -#endif - handle_array[nhandles++] = hEventReadReady; - readArray[readPipes++] = fh; - } - } - else - { - GNUNET_CONTAINER_slist_add (handles_read, - GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, - fh, - sizeof (struct - GNUNET_DISK_FileHandle)); - } - } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Adding the read ready event to the array as %d\n", nhandles); +#endif + handle_array[nhandles++] = hEventReadReady; + readArray[readPipes++] = fh; + } + } + else + { + GNUNET_CONTAINER_slist_add (handles_read, + GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, + fh, sizeof (struct GNUNET_DISK_FileHandle)); + } } + } if (wfds && write_handles) - { + { #if DEBUG_NETWORK - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Adding the write ready event to the array as %d\n", nhandles); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Adding the write ready event to the array as %d\n", nhandles); #endif - handle_array[nhandles++] = hEventPipeWrite; - writePipePos = nhandles; - } + handle_array[nhandles++] = hEventPipeWrite; + writePipePos = nhandles; + } if (efds && ex_handles) + { + struct GNUNET_CONTAINER_SList_Iterator i; + + for (i = GNUNET_CONTAINER_slist_begin (efds->handles); + GNUNET_CONTAINER_slist_end (&i) != GNUNET_YES; + GNUNET_CONTAINER_slist_next (&i)) { - struct GNUNET_CONTAINER_SList_Iterator i; - - for (i = GNUNET_CONTAINER_slist_begin (efds->handles); - GNUNET_CONTAINER_slist_end (&i) != GNUNET_YES; - GNUNET_CONTAINER_slist_next (&i)) - { - struct GNUNET_DISK_FileHandle *fh; - DWORD dwBytes; - - fh = - (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&i, - NULL); - if (fh->type == GNUNET_PIPE) - { - if (!PeekNamedPipe (fh->h, NULL, 0, NULL, &dwBytes, NULL)) - { - GNUNET_CONTAINER_slist_add (handles_except, - GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, - fh, - sizeof (struct - GNUNET_DISK_FileHandle)); - newretcode++; - } - } - } + struct GNUNET_DISK_FileHandle *fh; + DWORD dwBytes; + + fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&i, + NULL); + if (fh->type == GNUNET_PIPE) + { + if (!PeekNamedPipe (fh->h, NULL, 0, NULL, &dwBytes, NULL)) + { + GNUNET_CONTAINER_slist_add (handles_except, + GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, + fh, + sizeof (struct GNUNET_DISK_FileHandle)); + newretcode++; + } + } } + } if (nfds > 0) + { + if (rfds) { - if (rfds) - { #if DEBUG_NETWORK - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Adding the socket read event to the array as %d\n", nhandles); -#endif - handle_array[nhandles++] = hEventRead; - nSockEvents++; - for (i = 0; i < rfds->sds.fd_count; i++) - { - WSAEventSelect (rfds->sds.fd_array[i], hEventRead, - FD_ACCEPT | FD_READ | FD_CLOSE); - nsock++; - } - } - if (wfds) - { - int wakeup = 0; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Adding the socket read event to the array as %d\n", nhandles); +#endif + handle_array[nhandles++] = hEventRead; + nSockEvents++; + for (i = 0; i < rfds->sds.fd_count; i++) + { + WSAEventSelect (rfds->sds.fd_array[i], hEventRead, + FD_ACCEPT | FD_READ | FD_CLOSE); + nsock++; + } + } + if (wfds) + { + int wakeup = 0; #if DEBUG_NETWORK - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Adding the socket write event to the array as %d\n", - nhandles); -#endif - handle_array[nhandles++] = hEventWrite; - nSockEvents++; - for (i = 0; i < wfds->sds.fd_count; i++) - { - DWORD error; - int status; - - status = send (wfds->sds.fd_array[i], NULL, 0, 0); - error = GetLastError (); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Adding the socket write event to the array as %d\n", nhandles); +#endif + handle_array[nhandles++] = hEventWrite; + nSockEvents++; + for (i = 0; i < wfds->sds.fd_count; i++) + { + DWORD error; + int status; + + status = send (wfds->sds.fd_array[i], NULL, 0, 0); + error = GetLastError (); #if DEBUG_NETWORK - LOG (GNUNET_ERROR_TYPE_DEBUG, - "pre-send to the socket %d returned %d (%u)\n", i, status, - error); -#endif - if (status == 0 - || (error != WSAEWOULDBLOCK && error != WSAENOTCONN)) - wakeup = 1; - WSAEventSelect (wfds->sds.fd_array[i], hEventWrite, - FD_WRITE | FD_CONNECT | FD_CLOSE); - nsock++; - } - if (wakeup) - SetEvent (hEventWrite); - } - if (efds) - { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "pre-send to the socket %d returned %d (%u)\n", i, status, error); +#endif + if (status == 0 || (error != WSAEWOULDBLOCK && error != WSAENOTCONN)) + wakeup = 1; + WSAEventSelect (wfds->sds.fd_array[i], hEventWrite, + FD_WRITE | FD_CONNECT | FD_CLOSE); + nsock++; + } + if (wakeup) + SetEvent (hEventWrite); + } + if (efds) + { #if DEBUG_NETWORK - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Adding the socket error event to the array as %d\n", - nhandles); -#endif - handle_array[nhandles++] = hEventException; - nSockEvents++; - for (i = 0; i < efds->sds.fd_count; i++) - { - WSAEventSelect (efds->sds.fd_array[i], hEventException, - FD_OOB | FD_CLOSE); - nsock++; - } - } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Adding the socket error event to the array as %d\n", nhandles); +#endif + handle_array[nhandles++] = hEventException; + nSockEvents++; + for (i = 0; i < efds->sds.fd_count; i++) + { + WSAEventSelect (efds->sds.fd_array[i], hEventException, + FD_OOB | FD_CLOSE); + nsock++; + } } + } handle_array[nhandles] = NULL; @@ -1464,7 +1447,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, if (nhandles) returncode = - WaitForMultipleObjects (nhandles, handle_array, FALSE, ms_total); + WaitForMultipleObjects (nhandles, handle_array, FALSE, ms_total); #if DEBUG_NETWORK LOG (GNUNET_ERROR_TYPE_DEBUG, "WaitForMultipleObjects Returned : %d\n", returncode); @@ -1481,239 +1464,230 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, * GNUNET_CONTAINER_slist_append (handles_read, rfds->handles); */ if (nhandles && (returnedpos < nhandles)) + { + DWORD waitstatus; + + /* Do the select */ + if (nfds) { - DWORD waitstatus; - - /* Do the select */ - if (nfds) - { - struct timeval tvslice; - - tvslice.tv_sec = 0; - tvslice.tv_usec = 10; - retcode = select (nfds, &aread, &awrite, &aexcept, &tvslice); - if (retcode == -1) - retcode = 0; + struct timeval tvslice; + + tvslice.tv_sec = 0; + tvslice.tv_usec = 10; + retcode = select (nfds, &aread, &awrite, &aexcept, &tvslice); + if (retcode == -1) + retcode = 0; #if DEBUG_NETWORK - LOG (GNUNET_ERROR_TYPE_DEBUG, "Select retcode : %d\n", retcode); -#endif - } - /* FIXME: <= writePipePos? Really? */ - if ((writePipePos != -1) && (returnedpos <= writePipePos)) - { - GNUNET_CONTAINER_slist_append (handles_write, wfds->handles); - retcode += write_handles; + LOG (GNUNET_ERROR_TYPE_DEBUG, "Select retcode : %d\n", retcode); +#endif + } + /* FIXME: <= writePipePos? Really? */ + if ((writePipePos != -1) && (returnedpos <= writePipePos)) + { + GNUNET_CONTAINER_slist_append (handles_write, wfds->handles); + retcode += write_handles; #if DEBUG_NETWORK - LOG (GNUNET_ERROR_TYPE_DEBUG, "Added write pipe\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Added write pipe\n"); #endif - } + } #if DEBUG_NETWORK - LOG (GNUNET_ERROR_TYPE_DEBUG, "ReadPipes is : %d\n", readPipes); -#endif - /* We have some pipes ready for read. */ - /* FIXME: it is supposed to work !! Only choose the Pipes who fired the event, but it is not working */ - - if (returnedpos < readPipes) - { - /* - * for (i = 0; i < readPipes; i++) - * { - * waitstatus = WaitForSingleObject (handle_array[i], 0); - * LOG (GNUNET_ERROR_TYPE_DEBUG, "Read pipe %d wait status is : %d\n", i, waitstatus); - * if (waitstatus != WAIT_OBJECT_0) - * continue; - * GNUNET_CONTAINER_slist_add (handles_read, - * GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, - * readArray[i], sizeof (struct GNUNET_DISK_FileHandle)); - * retcode++; - * LOG (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe\n"); - * } - */ - for (i = 0; i < readPipes; i++) - { - DWORD error; - BOOL bret; - - SetLastError (0); - waitstatus = 0; - bret = - PeekNamedPipe (readArray[i]->h, NULL, 0, NULL, &waitstatus, - NULL); - error = GetLastError (); + LOG (GNUNET_ERROR_TYPE_DEBUG, "ReadPipes is : %d\n", readPipes); +#endif + /* We have some pipes ready for read. */ + /* FIXME: it is supposed to work !! Only choose the Pipes who fired the event, but it is not working */ + + if (returnedpos < readPipes) + { + /* + * for (i = 0; i < readPipes; i++) + * { + * waitstatus = WaitForSingleObject (handle_array[i], 0); + * LOG (GNUNET_ERROR_TYPE_DEBUG, "Read pipe %d wait status is : %d\n", i, waitstatus); + * if (waitstatus != WAIT_OBJECT_0) + * continue; + * GNUNET_CONTAINER_slist_add (handles_read, + * GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, + * readArray[i], sizeof (struct GNUNET_DISK_FileHandle)); + * retcode++; + * LOG (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe\n"); + * } + */ + for (i = 0; i < readPipes; i++) + { + DWORD error; + BOOL bret; + + SetLastError (0); + waitstatus = 0; + bret = + PeekNamedPipe (readArray[i]->h, NULL, 0, NULL, &waitstatus, NULL); + error = GetLastError (); #if DEBUG_NETWORK - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Peek at read pipe %d (0x%x) returned %d (%d bytes available) GLE %u\n", - i, readArray[i]->h, bret, waitstatus, error); -#endif - if (bret == 0) - { - if (error != ERROR_BROKEN_PIPE) - continue; - } - else if (waitstatus <= 0) - continue; - GNUNET_CONTAINER_slist_add (handles_read, - GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, - readArray[i], - sizeof (struct - GNUNET_DISK_FileHandle)); - retcode++; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Peek at read pipe %d (0x%x) returned %d (%d bytes available) GLE %u\n", + i, readArray[i]->h, bret, waitstatus, error); +#endif + if (bret == 0) + { + if (error != ERROR_BROKEN_PIPE) + continue; + } + else if (waitstatus <= 0) + continue; + GNUNET_CONTAINER_slist_add (handles_read, + GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, + readArray[i], + sizeof (struct GNUNET_DISK_FileHandle)); + retcode++; #if DEBUG_NETWORK - LOG (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe 0x%x (0x%x)\n", - readArray[i], readArray[i]->h); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe 0x%x (0x%x)\n", + readArray[i], readArray[i]->h); #endif - } - } - waitstatus = WaitForSingleObject (hEventWrite, 0); + } + } + waitstatus = WaitForSingleObject (hEventWrite, 0); #if DEBUG_NETWORK - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Wait for the write event returned %d\n", waitstatus); -#endif - if (waitstatus == WAIT_OBJECT_0) - { - for (i = 0; i < wfds->sds.fd_count; i++) - { - DWORD error; - int status; - int so_error = 0; - int sizeof_so_error = sizeof (so_error); - int gso_result = - getsockopt (wfds->sds.fd_array[i], SOL_SOCKET, SO_ERROR, - (char *) &so_error, &sizeof_so_error); - - status = send (wfds->sds.fd_array[i], NULL, 0, 0); - error = GetLastError (); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Wait for the write event returned %d\n", + waitstatus); +#endif + if (waitstatus == WAIT_OBJECT_0) + { + for (i = 0; i < wfds->sds.fd_count; i++) + { + DWORD error; + int status; + int so_error = 0; + int sizeof_so_error = sizeof (so_error); + int gso_result = + getsockopt (wfds->sds.fd_array[i], SOL_SOCKET, SO_ERROR, + (char *) &so_error, &sizeof_so_error); + + status = send (wfds->sds.fd_array[i], NULL, 0, 0); + error = GetLastError (); #if DEBUG_NETWORK - LOG (GNUNET_ERROR_TYPE_DEBUG, - "send to the socket %d returned %d (%u)\n", i, status, - error); -#endif - if (status == 0 - || (error != WSAEWOULDBLOCK && error != WSAENOTCONN) - || (status == -1 && gso_result == 0 && error == WSAENOTCONN - && so_error == WSAECONNREFUSED)) - { - FD_SET (wfds->sds.fd_array[i], &awrite); - retcode += 1; - } - } - } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "send to the socket %d returned %d (%u)\n", i, status, error); +#endif + if (status == 0 || (error != WSAEWOULDBLOCK && error != WSAENOTCONN) || + (status == -1 && gso_result == 0 && error == WSAENOTCONN && + so_error == WSAECONNREFUSED)) + { + FD_SET (wfds->sds.fd_array[i], &awrite); + retcode += 1; + } + } } + } #if DEBUG_NETWORK if (!nhandles || (returnedpos >= nhandles)) LOG (GNUNET_ERROR_TYPE_DEBUG, "Returning from _select() with nothing!\n"); #endif if (rfds) + { + struct GNUNET_CONTAINER_SList_Iterator t; + + for (i = 0; i < rfds->sds.fd_count; i++) { - struct GNUNET_CONTAINER_SList_Iterator t; + WSAEventSelect (rfds->sds.fd_array[i], hEventRead, 0); + nsock++; + } + for (t = GNUNET_CONTAINER_slist_begin (rfds->handles); + GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES; + GNUNET_CONTAINER_slist_next (&t)) + { + struct GNUNET_DISK_FileHandle *fh; - for (i = 0; i < rfds->sds.fd_count; i++) - { - WSAEventSelect (rfds->sds.fd_array[i], hEventRead, 0); - nsock++; - } - for (t = GNUNET_CONTAINER_slist_begin (rfds->handles); - GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES; - GNUNET_CONTAINER_slist_next (&t)) - { - struct GNUNET_DISK_FileHandle *fh; - - fh = - (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t, - NULL); - if (fh->type == GNUNET_PIPE) - { - CancelIo (fh->h); - } - } + fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t, + NULL); + if (fh->type == GNUNET_PIPE) + { + CancelIo (fh->h); + } + } #if DEBUG_NETWORK - LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing rfds\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing rfds\n"); #endif - GNUNET_NETWORK_fdset_zero (rfds); - if (retcode != -1 && nhandles && (returnedpos < nhandles)) - GNUNET_NETWORK_fdset_copy_native (rfds, &aread, retcode); - GNUNET_CONTAINER_slist_append (rfds->handles, handles_read); - } + GNUNET_NETWORK_fdset_zero (rfds); + if (retcode != -1 && nhandles && (returnedpos < nhandles)) + GNUNET_NETWORK_fdset_copy_native (rfds, &aread, retcode); + GNUNET_CONTAINER_slist_append (rfds->handles, handles_read); + } if (wfds) + { + for (i = 0; i < wfds->sds.fd_count; i++) { - for (i = 0; i < wfds->sds.fd_count; i++) - { - WSAEventSelect (wfds->sds.fd_array[i], hEventWrite, 0); - nsock++; - } + WSAEventSelect (wfds->sds.fd_array[i], hEventWrite, 0); + nsock++; + } #if DEBUG_NETWORK - LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing wfds\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing wfds\n"); #endif - GNUNET_NETWORK_fdset_zero (wfds); - if (retcode != -1 && nhandles && (returnedpos < nhandles)) - GNUNET_NETWORK_fdset_copy_native (wfds, &awrite, retcode); - GNUNET_CONTAINER_slist_append (wfds->handles, handles_write); - } + GNUNET_NETWORK_fdset_zero (wfds); + if (retcode != -1 && nhandles && (returnedpos < nhandles)) + GNUNET_NETWORK_fdset_copy_native (wfds, &awrite, retcode); + GNUNET_CONTAINER_slist_append (wfds->handles, handles_write); + } if (efds) + { + for (i = 0; i < efds->sds.fd_count; i++) { - for (i = 0; i < efds->sds.fd_count; i++) - { - WSAEventSelect (efds->sds.fd_array[i], hEventException, 0); - nsock++; - } + WSAEventSelect (efds->sds.fd_array[i], hEventException, 0); + nsock++; + } #if DEBUG_NETWORK - LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing efds\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing efds\n"); #endif - GNUNET_NETWORK_fdset_zero (efds); - if (retcode != -1 && nhandles && (returnedpos < nhandles)) - GNUNET_NETWORK_fdset_copy_native (efds, &aexcept, retcode); - GNUNET_CONTAINER_slist_append (efds->handles, handles_except); - } + GNUNET_NETWORK_fdset_zero (efds); + if (retcode != -1 && nhandles && (returnedpos < nhandles)) + GNUNET_NETWORK_fdset_copy_native (efds, &aexcept, retcode); + GNUNET_CONTAINER_slist_append (efds->handles, handles_except); + } GNUNET_CONTAINER_slist_destroy (handles_read); GNUNET_CONTAINER_slist_destroy (handles_write); GNUNET_CONTAINER_slist_destroy (handles_except); #if DEBUG_NETWORK if (rfds) + { + struct GNUNET_CONTAINER_SList_Iterator t; + + for (i = 0; i < bread.fd_count; i++) { - struct GNUNET_CONTAINER_SList_Iterator t; + if (bread.fd_array[i] != 0) + LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in rfds\n", + bread.fd_array[i], + (SAFE_FD_ISSET (bread.fd_array[i], rfds)) ? "SET" : "NOT SET"); + } + for (t = GNUNET_CONTAINER_slist_begin (rfds->handles); + GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES; + GNUNET_CONTAINER_slist_next (&t)) + { + struct GNUNET_DISK_FileHandle *fh; - for (i = 0; i < bread.fd_count; i++) - { - if (bread.fd_array[i] != 0) - LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in rfds\n", - bread.fd_array[i], - (SAFE_FD_ISSET (bread.fd_array[i], rfds)) ? "SET" : - "NOT SET"); - } - for (t = GNUNET_CONTAINER_slist_begin (rfds->handles); - GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES; - GNUNET_CONTAINER_slist_next (&t)) - { - struct GNUNET_DISK_FileHandle *fh; - - fh = - (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t, - NULL); - LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is SET in rfds\n", fh->h); - } + fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t, + NULL); + LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is SET in rfds\n", fh->h); } + } if (wfds) + { + for (i = 0; i < bwrite.fd_count; i++) { - for (i = 0; i < bwrite.fd_count; i++) - { - if (bwrite.fd_array[i] != 0) - LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in wfds\n", - bwrite.fd_array[i], - (SAFE_FD_ISSET (bwrite.fd_array[i], rfds)) ? "SET" : - "NOT SET"); - } + if (bwrite.fd_array[i] != 0) + LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in wfds\n", + bwrite.fd_array[i], + (SAFE_FD_ISSET (bwrite.fd_array[i], rfds)) ? "SET" : "NOT SET"); } + } if (efds) + { + for (i = 0; i < bexcept.fd_count; i++) { - for (i = 0; i < bexcept.fd_count; i++) - { - if (bexcept.fd_array[i] != 0) - LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in efds\n", - bexcept.fd_array[i], - (SAFE_FD_ISSET (bexcept.fd_array[i], rfds)) ? "SET" : - "NOT SET"); - } + if (bexcept.fd_array[i] != 0) + LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in efds\n", + bexcept.fd_array[i], + (SAFE_FD_ISSET (bexcept.fd_array[i], rfds)) ? "SET" : "NOT SET"); } + } LOG (GNUNET_ERROR_TYPE_DEBUG, "Returning %d or 0\n", retcode); #endif if (nhandles && (returnedpos < nhandles)) diff --git a/src/util/os_installation.c b/src/util/os_installation.c index 98080a3ed..a7a6ae915 100644 --- a/src/util/os_installation.c +++ b/src/util/os_installation.c @@ -60,16 +60,16 @@ get_path_from_proc_maps () if (f == NULL) return NULL; while (NULL != fgets (line, sizeof (line), f)) + { + if ((1 == + sscanf (line, "%*x-%*x %*c%*c%*c%*c %*x %*2u:%*2u %*u%*[ ]%s", dir)) && + (NULL != (lgu = strstr (dir, "libgnunetutil")))) { - if ((1 == - sscanf (line, "%*x-%*x %*c%*c%*c%*c %*x %*2u:%*2u %*u%*[ ]%s", - dir)) && (NULL != (lgu = strstr (dir, "libgnunetutil")))) - { - lgu[0] = '\0'; - fclose (f); - return GNUNET_strdup (dir); - } + lgu[0] = '\0'; + fclose (f); + return GNUNET_strdup (dir); } + } fclose (f); return NULL; } @@ -87,19 +87,19 @@ get_path_from_proc_exe () GNUNET_snprintf (fn, sizeof (fn), "/proc/%u/exe", getpid ()); size = readlink (fn, lnk, sizeof (lnk) - 1); if (size <= 0) - { - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "readlink", fn); - return NULL; - } + { + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "readlink", fn); + return NULL; + } GNUNET_assert (size < sizeof (lnk)); lnk[size] = '\0'; while ((lnk[size] != '/') && (size > 0)) size--; if ((size < 4) || (lnk[size - 4] != '/')) - { - /* not installed in "/bin/" -- binary path probably useless */ - return NULL; - } + { + /* not installed in "/bin/" -- binary path probably useless */ + return NULL; + } lnk[size] = '\0'; return GNUNET_strdup (lnk); } @@ -138,7 +138,7 @@ get_path_from_NSGetExecutablePath () path = NULL; func = - (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT, "_NSGetExecutablePath"); + (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT, "_NSGetExecutablePath"); if (!func) return NULL; path = &zero; @@ -150,10 +150,10 @@ get_path_from_NSGetExecutablePath () path = GNUNET_malloc (len); ret = func (path, &len); if (ret != 0) - { - GNUNET_free (path); - return NULL; - } + { + GNUNET_free (path); + return NULL; + } len = strlen (path); while ((path[len] != '/') && (len > 0)) len--; @@ -172,22 +172,22 @@ get_path_from_dyld_image () p = NULL; c = _dyld_image_count (); for (i = 0; i < c; i++) + { + if (_dyld_get_image_header (i) == &_mh_dylib_header) { - if (_dyld_get_image_header (i) == &_mh_dylib_header) - { - path = _dyld_get_image_name (i); - if (path != NULL && strlen (path) > 0) - { - p = GNUNET_strdup (path); - s = p + strlen (p); - while ((s > p) && (*s != '/')) - s--; - s++; - *s = '\0'; - } - break; - } + path = _dyld_get_image_name (i); + if (path != NULL && strlen (path) > 0) + { + p = GNUNET_strdup (path); + s = p + strlen (p); + while ((s > p) && (*s != '/')) + s--; + s++; + *s = '\0'; + } + break; } + } return p; } #endif @@ -211,30 +211,30 @@ get_path_from_PATH (const char *binary) p = getenv ("PATH"); if (p == NULL) return NULL; - path = GNUNET_strdup (p); /* because we write on it */ + path = GNUNET_strdup (p); /* because we write on it */ buf = GNUNET_malloc (strlen (path) + 20); pos = path; while (NULL != (end = strchr (pos, PATH_SEPARATOR))) - { - *end = '\0'; - sprintf (buf, "%s/%s", pos, binary); - if (GNUNET_DISK_file_test (buf) == GNUNET_YES) - { - pos = GNUNET_strdup (pos); - GNUNET_free (buf); - GNUNET_free (path); - return pos; - } - pos = end + 1; - } - sprintf (buf, "%s/%s", pos, binary); - if (GNUNET_DISK_file_test (buf) == GNUNET_YES) + { + *end = '\0'; + sprintf (buf, "%s/%s", pos, binary); + if (GNUNET_DISK_file_test (buf) == GNUNET_YES) { pos = GNUNET_strdup (pos); GNUNET_free (buf); GNUNET_free (path); return pos; } + pos = end + 1; + } + sprintf (buf, "%s/%s", pos, binary); + if (GNUNET_DISK_file_test (buf) == GNUNET_YES) + { + pos = GNUNET_strdup (pos); + GNUNET_free (buf); + GNUNET_free (path); + return pos; + } GNUNET_free (buf); GNUNET_free (path); return NULL; @@ -359,11 +359,11 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind) n = strlen (execpath); if (n == 0) - { - /* should never happen, but better safe than sorry */ - GNUNET_free (execpath); - return NULL; - } + { + /* should never happen, but better safe than sorry */ + GNUNET_free (execpath); + return NULL; + } /* remove filename itself */ while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR)) execpath[--n] = '\0'; @@ -372,62 +372,59 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind) if ((n > 5) && ((0 == strcasecmp (&execpath[n - 5], "lib32")) || (0 == strcasecmp (&execpath[n - 5], "lib64")))) + { + if (dirkind != GNUNET_OS_IPK_LIBDIR) { - if (dirkind != GNUNET_OS_IPK_LIBDIR) - { - /* strip '/lib32' or '/lib64' */ - execpath[n - 5] = '\0'; - n -= 5; - } - else - isbasedir = 0; + /* strip '/lib32' or '/lib64' */ + execpath[n - 5] = '\0'; + n -= 5; } + else + isbasedir = 0; + } else if ((n > 3) && - ((0 == strcasecmp (&execpath[n - 3], "bin")) || - (0 == strcasecmp (&execpath[n - 3], "lib")))) - { - /* strip '/bin' or '/lib' */ - execpath[n - 3] = '\0'; - n -= 3; - } + ((0 == strcasecmp (&execpath[n - 3], "bin")) || + (0 == strcasecmp (&execpath[n - 3], "lib")))) + { + /* strip '/bin' or '/lib' */ + execpath[n - 3] = '\0'; + n -= 3; + } /* in case this was a directory named foo-bin, remove "foo-" */ while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR)) execpath[--n] = '\0'; switch (dirkind) - { - case GNUNET_OS_IPK_PREFIX: - case GNUNET_OS_IPK_SELF_PREFIX: - dirname = DIR_SEPARATOR_STR; - break; - case GNUNET_OS_IPK_BINDIR: - dirname = DIR_SEPARATOR_STR "bin" DIR_SEPARATOR_STR; - break; - case GNUNET_OS_IPK_LIBDIR: - if (isbasedir) - dirname = - DIR_SEPARATOR_STR "lib" DIR_SEPARATOR_STR "gnunet" - DIR_SEPARATOR_STR; - else - dirname = DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR; - break; - case GNUNET_OS_IPK_DATADIR: - dirname = - DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "gnunet" - DIR_SEPARATOR_STR; - break; - case GNUNET_OS_IPK_LOCALEDIR: - dirname = - DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "locale" - DIR_SEPARATOR_STR; - break; - case GNUNET_OS_IPK_ICONDIR: + { + case GNUNET_OS_IPK_PREFIX: + case GNUNET_OS_IPK_SELF_PREFIX: + dirname = DIR_SEPARATOR_STR; + break; + case GNUNET_OS_IPK_BINDIR: + dirname = DIR_SEPARATOR_STR "bin" DIR_SEPARATOR_STR; + break; + case GNUNET_OS_IPK_LIBDIR: + if (isbasedir) dirname = - DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "icons" DIR_SEPARATOR_STR; - break; - default: - GNUNET_free (execpath); - return NULL; - } + DIR_SEPARATOR_STR "lib" DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR; + else + dirname = DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR; + break; + case GNUNET_OS_IPK_DATADIR: + dirname = + DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR; + break; + case GNUNET_OS_IPK_LOCALEDIR: + dirname = + DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "locale" DIR_SEPARATOR_STR; + break; + case GNUNET_OS_IPK_ICONDIR: + dirname = + DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "icons" DIR_SEPARATOR_STR; + break; + default: + GNUNET_free (execpath); + return NULL; + } tmp = GNUNET_malloc (strlen (execpath) + strlen (dirname) + 1); sprintf (tmp, "%s%s", execpath, dirname); GNUNET_free (execpath); @@ -460,59 +457,58 @@ GNUNET_OS_check_helper_binary (const char *binary) GNUNET_asprintf (&binaryexe, "%s.exe", binary); p = get_path_from_PATH (binaryexe); if (p != NULL) - { - GNUNET_asprintf (&pf, "%s/%s", p, binaryexe); - GNUNET_free (p); - p = pf; - } + { + GNUNET_asprintf (&pf, "%s/%s", p, binaryexe); + GNUNET_free (p); + p = pf; + } free (binaryexe); #else p = get_path_from_PATH (binary); if (p != NULL) - { - GNUNET_asprintf (&pf, "%s/%s", p, binary); - GNUNET_free (p); - p = pf; - } + { + GNUNET_asprintf (&pf, "%s/%s", p, binary); + GNUNET_free (p); + p = pf; + } #endif if (p == NULL) - { - LOG (GNUNET_ERROR_TYPE_INFO, - _("Could not find binary `%s' in PATH!\n"), binary); - return GNUNET_SYSERR; - } + { + LOG (GNUNET_ERROR_TYPE_INFO, _("Could not find binary `%s' in PATH!\n"), + binary); + return GNUNET_SYSERR; + } if (0 != STAT (p, &statbuf)) - { - LOG (GNUNET_ERROR_TYPE_WARNING, _("stat (%s) failed: %s\n"), p, - STRERROR (errno)); - GNUNET_free (p); - return GNUNET_SYSERR; - } + { + LOG (GNUNET_ERROR_TYPE_WARNING, _("stat (%s) failed: %s\n"), p, + STRERROR (errno)); + GNUNET_free (p); + return GNUNET_SYSERR; + } #ifndef MINGW if ((0 != (statbuf.st_mode & S_ISUID)) && (statbuf.st_uid == 0)) - { - GNUNET_free (p); - return GNUNET_YES; - } + { + GNUNET_free (p); + return GNUNET_YES; + } if (0 == ACCESS (p, X_OK)) - { - GNUNET_free (p); - return GNUNET_NO; - } + { + GNUNET_free (p); + return GNUNET_NO; + } GNUNET_free (p); return GNUNET_SYSERR; #else GNUNET_free (p); rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP); if (INVALID_SOCKET == rawsock) - { - DWORD err = GetLastError (); + { + DWORD err = GetLastError (); - LOG (GNUNET_ERROR_TYPE_INFO, - "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) failed! GLE = %d\n", - err); - return GNUNET_NO; /* not running as administrator */ - } + LOG (GNUNET_ERROR_TYPE_INFO, + "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) failed! GLE = %d\n", err); + return GNUNET_NO; /* not running as administrator */ + } closesocket (rawsock); return GNUNET_YES; #endif diff --git a/src/util/os_network.c b/src/util/os_network.c index 2835e6193..70d143ba1 100644 --- a/src/util/os_network.c +++ b/src/util/os_network.c @@ -43,7 +43,7 @@ */ void GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc, - void *proc_cls) + void *proc_cls) { #ifdef MINGW PMIB_IFTABLE pTable; @@ -52,121 +52,118 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc, IPAddr theIP; /* Determine our external NIC */ - theIP = inet_addr ("192.0.34.166"); /* www.example.com */ + theIP = inet_addr ("192.0.34.166"); /* www.example.com */ if ((!GNGetBestInterface) || (GNGetBestInterface (theIP, &dwExternalNIC) != NO_ERROR)) - { - dwExternalNIC = 0; - } + { + dwExternalNIC = 0; + } /* Enumerate NICs */ EnumNICs (&pTable, &pAddrTable); if (pTable) + { + for (dwIfIdx = 0; dwIfIdx <= pTable->dwNumEntries; dwIfIdx++) { - for (dwIfIdx = 0; dwIfIdx <= pTable->dwNumEntries; dwIfIdx++) - { - char szEntry[1001]; - DWORD dwIP = 0; - PIP_ADAPTER_INFO pAdapterInfo; - PIP_ADAPTER_INFO pAdapter = NULL; - DWORD dwRetVal = 0; - - /* Get IP-Address */ - int i; - - for (i = 0; i < pAddrTable->dwNumEntries; i++) - { - if (pAddrTable->table[i].dwIndex == - pTable->table[dwIfIdx].dwIndex) - { - dwIP = pAddrTable->table[i].dwAddr; - break; - } - } - - if (dwIP) - { - BYTE bPhysAddr[MAXLEN_PHYSADDR]; - char *pszIfName = NULL; - char dst[INET_ADDRSTRLEN]; - struct sockaddr_in sa; - - /* Get friendly interface name */ - pAdapterInfo = - (IP_ADAPTER_INFO *) malloc (sizeof (IP_ADAPTER_INFO)); - ULONG ulOutBufLen = sizeof (IP_ADAPTER_INFO); - - /* Make an initial call to GetAdaptersInfo to get - * the necessary size into the ulOutBufLen variable */ - if (GGetAdaptersInfo (pAdapterInfo, &ulOutBufLen) == - ERROR_BUFFER_OVERFLOW) - { - free (pAdapterInfo); - pAdapterInfo = (IP_ADAPTER_INFO *) malloc (ulOutBufLen); - } - - if ((dwRetVal = - GGetAdaptersInfo (pAdapterInfo, &ulOutBufLen)) == NO_ERROR) - { - pAdapter = pAdapterInfo; - while (pAdapter) - { - if (pTable->table[dwIfIdx].dwIndex == pAdapter->Index) - { - char szKey[251]; - long lLen = 250; - - sprintf (szKey, - "SYSTEM\\CurrentControlSet\\Control\\Network\\" - "{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection", - pAdapter->AdapterName); - pszIfName = (char *) malloc (251); - if (QueryRegistry - (HKEY_LOCAL_MACHINE, szKey, "Name", pszIfName, - &lLen) != ERROR_SUCCESS) - { - free (pszIfName); - pszIfName = NULL; - } - } - pAdapter = pAdapter->Next; - } - } - free (pAdapterInfo); - - /* Set entry */ - memset (bPhysAddr, 0, MAXLEN_PHYSADDR); - memcpy (bPhysAddr, pTable->table[dwIfIdx].bPhysAddr, - pTable->table[dwIfIdx].dwPhysAddrLen); - - snprintf (szEntry, 1000, "%s (%s - %I64u)", - pszIfName ? pszIfName : (char *) - pTable->table[dwIfIdx].bDescr, inet_ntop (AF_INET, - &dwIP, dst, - INET_ADDRSTRLEN), - *((unsigned long long *) bPhysAddr)); - szEntry[1000] = 0; - - if (pszIfName) - free (pszIfName); - - sa.sin_family = AF_INET; + char szEntry[1001]; + DWORD dwIP = 0; + PIP_ADAPTER_INFO pAdapterInfo; + PIP_ADAPTER_INFO pAdapter = NULL; + DWORD dwRetVal = 0; + + /* Get IP-Address */ + int i; + + for (i = 0; i < pAddrTable->dwNumEntries; i++) + { + if (pAddrTable->table[i].dwIndex == pTable->table[dwIfIdx].dwIndex) + { + dwIP = pAddrTable->table[i].dwAddr; + break; + } + } + + if (dwIP) + { + BYTE bPhysAddr[MAXLEN_PHYSADDR]; + char *pszIfName = NULL; + char dst[INET_ADDRSTRLEN]; + struct sockaddr_in sa; + + /* Get friendly interface name */ + pAdapterInfo = (IP_ADAPTER_INFO *) malloc (sizeof (IP_ADAPTER_INFO)); + ULONG ulOutBufLen = sizeof (IP_ADAPTER_INFO); + + /* Make an initial call to GetAdaptersInfo to get + * the necessary size into the ulOutBufLen variable */ + if (GGetAdaptersInfo (pAdapterInfo, &ulOutBufLen) == + ERROR_BUFFER_OVERFLOW) + { + free (pAdapterInfo); + pAdapterInfo = (IP_ADAPTER_INFO *) malloc (ulOutBufLen); + } + + if ((dwRetVal = + GGetAdaptersInfo (pAdapterInfo, &ulOutBufLen)) == NO_ERROR) + { + pAdapter = pAdapterInfo; + while (pAdapter) + { + if (pTable->table[dwIfIdx].dwIndex == pAdapter->Index) + { + char szKey[251]; + long lLen = 250; + + sprintf (szKey, + "SYSTEM\\CurrentControlSet\\Control\\Network\\" + "{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection", + pAdapter->AdapterName); + pszIfName = (char *) malloc (251); + if (QueryRegistry + (HKEY_LOCAL_MACHINE, szKey, "Name", pszIfName, + &lLen) != ERROR_SUCCESS) + { + free (pszIfName); + pszIfName = NULL; + } + } + pAdapter = pAdapter->Next; + } + } + free (pAdapterInfo); + + /* Set entry */ + memset (bPhysAddr, 0, MAXLEN_PHYSADDR); + memcpy (bPhysAddr, pTable->table[dwIfIdx].bPhysAddr, + pTable->table[dwIfIdx].dwPhysAddrLen); + + snprintf (szEntry, 1000, "%s (%s - %I64u)", + pszIfName ? pszIfName : (char *) pTable-> + table[dwIfIdx].bDescr, inet_ntop (AF_INET, &dwIP, dst, + INET_ADDRSTRLEN), + *((unsigned long long *) bPhysAddr)); + szEntry[1000] = 0; + + if (pszIfName) + free (pszIfName); + + sa.sin_family = AF_INET; #if HAVE_SOCKADDR_IN_SIN_LEN - sa.sin_len = (u_char) sizeof (struct sockaddr_in); + sa.sin_len = (u_char) sizeof (struct sockaddr_in); #endif - sa.sin_addr.S_un.S_addr = dwIP; - - if (GNUNET_OK != - proc (proc_cls, szEntry, - pTable->table[dwIfIdx].dwIndex == dwExternalNIC, - (const struct sockaddr *) &sa, sizeof (sa))) - break; - } - } - GlobalFree (pAddrTable); - GlobalFree (pTable); + sa.sin_addr.S_un.S_addr = dwIP; + + if (GNUNET_OK != + proc (proc_cls, szEntry, + pTable->table[dwIfIdx].dwIndex == dwExternalNIC, + (const struct sockaddr *) &sa, sizeof (sa))) + break; + } } + GlobalFree (pAddrTable); + GlobalFree (pTable); + } return; @@ -177,29 +174,28 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc, socklen_t alen; if (getifaddrs (&ifa_first) == 0) + { + for (ifa_ptr = ifa_first; ifa_ptr != NULL; ifa_ptr = ifa_ptr->ifa_next) { - for (ifa_ptr = ifa_first; ifa_ptr != NULL; ifa_ptr = ifa_ptr->ifa_next) - { - if (ifa_ptr->ifa_name != NULL && ifa_ptr->ifa_addr != NULL && - (ifa_ptr->ifa_flags & IFF_UP) != 0) - { - if ((ifa_ptr->ifa_addr->sa_family != AF_INET) && - (ifa_ptr->ifa_addr->sa_family != AF_INET6)) - continue; - if (ifa_ptr->ifa_addr->sa_family == AF_INET) - alen = sizeof (struct sockaddr_in); - else - alen = sizeof (struct sockaddr_in6); - if (GNUNET_OK != - proc (proc_cls, ifa_ptr->ifa_name, - 0 == strcmp (ifa_ptr->ifa_name, - GNUNET_DEFAULT_INTERFACE), - ifa_ptr->ifa_addr, alen)) - break; - } - } - freeifaddrs (ifa_first); + if (ifa_ptr->ifa_name != NULL && ifa_ptr->ifa_addr != NULL && + (ifa_ptr->ifa_flags & IFF_UP) != 0) + { + if ((ifa_ptr->ifa_addr->sa_family != AF_INET) && + (ifa_ptr->ifa_addr->sa_family != AF_INET6)) + continue; + if (ifa_ptr->ifa_addr->sa_family == AF_INET) + alen = sizeof (struct sockaddr_in); + else + alen = sizeof (struct sockaddr_in6); + if (GNUNET_OK != + proc (proc_cls, ifa_ptr->ifa_name, + 0 == strcmp (ifa_ptr->ifa_name, GNUNET_DEFAULT_INTERFACE), + ifa_ptr->ifa_addr, alen)) + break; + } } + freeifaddrs (ifa_first); + } #else char line[1024]; const char *start; @@ -220,76 +216,73 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc, else f = popen ("ifconfig -a 2> /dev/null", "r"); if (!f) - { - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING | - GNUNET_ERROR_TYPE_BULK, "popen", "ifconfig"); - return; - } + { + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, + "popen", "ifconfig"); + return; + } have_ifc = GNUNET_NO; ifc[11] = '\0'; while (NULL != fgets (line, sizeof (line), f)) + { + if (strlen (line) == 0) + { + have_ifc = GNUNET_NO; + continue; + } + if (!isspace (line[0])) + { + have_ifc = (1 == SSCANF (line, "%11s", ifc)) ? GNUNET_YES : GNUNET_NO; + /* would end with ':' on OSX, fix it! */ + if (ifc[strlen (ifc) - 1] == ':') + ifc[strlen (ifc) - 1] = '\0'; + continue; + } + if (!have_ifc) + continue; /* strange input, hope for the best */ + start = line; + while (('\0' != *start) && (isspace (*start))) + start++; + if ( /* Linux */ + (1 == SSCANF (start, "inet addr:%127s", addrstr)) || + (1 == SSCANF (start, "inet6 addr:%127s", addrstr)) || + /* Solaris, OS X */ + (1 == SSCANF (start, "inet %127s", addrstr)) || + (1 == SSCANF (start, "inet6 %127s", addrstr))) { - if (strlen (line) == 0) - { - have_ifc = GNUNET_NO; - continue; - } - if (!isspace (line[0])) - { - have_ifc = - (1 == SSCANF (line, "%11s", ifc)) ? GNUNET_YES : GNUNET_NO; - /* would end with ':' on OSX, fix it! */ - if (ifc[strlen (ifc) - 1] == ':') - ifc[strlen (ifc) - 1] = '\0'; - continue; - } - if (!have_ifc) - continue; /* strange input, hope for the best */ - start = line; - while (('\0' != *start) && (isspace (*start))) - start++; - if ( /* Linux */ - (1 == SSCANF (start, "inet addr:%127s", addrstr)) || - (1 == SSCANF (start, "inet6 addr:%127s", addrstr)) || - /* Solaris, OS X */ - (1 == SSCANF (start, "inet %127s", addrstr)) || - (1 == SSCANF (start, "inet6 %127s", addrstr))) - { - /* IPv4 */ - if (1 == inet_pton (AF_INET, addrstr, &v4)) - { - memset (&a4, 0, sizeof (a4)); - a4.sin_family = AF_INET; + /* IPv4 */ + if (1 == inet_pton (AF_INET, addrstr, &v4)) + { + memset (&a4, 0, sizeof (a4)); + a4.sin_family = AF_INET; #if HAVE_SOCKADDR_IN_SIN_LEN - a4.sin_len = (u_char) sizeof (struct sockaddr_in); + a4.sin_len = (u_char) sizeof (struct sockaddr_in); #endif - a4.sin_addr = v4; - if (GNUNET_OK != - proc (proc_cls, ifc, - 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE), - (const struct sockaddr *) &a4, sizeof (a4))) - break; - continue; - } - /* IPv6 */ - if (1 == inet_pton (AF_INET6, addrstr, &v6)) - { - memset (&a6, 0, sizeof (a6)); - a6.sin6_family = AF_INET6; + a4.sin_addr = v4; + if (GNUNET_OK != + proc (proc_cls, ifc, 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE), + (const struct sockaddr *) &a4, sizeof (a4))) + break; + continue; + } + /* IPv6 */ + if (1 == inet_pton (AF_INET6, addrstr, &v6)) + { + memset (&a6, 0, sizeof (a6)); + a6.sin6_family = AF_INET6; #if HAVE_SOCKADDR_IN_SIN_LEN - a6.sin6_len = (u_char) sizeof (struct sockaddr_in6); + a6.sin6_len = (u_char) sizeof (struct sockaddr_in6); #endif - a6.sin6_addr = v6; - if (GNUNET_OK != - proc (proc_cls, ifc, - 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE), - (const struct sockaddr *) &a6, sizeof (a6))) - break; - continue; - } - } + a6.sin6_addr = v6; + if (GNUNET_OK != + proc (proc_cls, ifc, 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE), + (const struct sockaddr *) &a6, sizeof (a6))) + break; + continue; + } } + } pclose (f); #endif } diff --git a/src/util/os_priority.c b/src/util/os_priority.c index 4f21e7edb..a7ce0c5e5 100644 --- a/src/util/os_priority.c +++ b/src/util/os_priority.c @@ -59,43 +59,41 @@ static struct GNUNET_OS_Process current_process; */ static void parent_control_handler (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) + const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_DISK_FileHandle *control_pipe = - (struct GNUNET_DISK_FileHandle *) cls; + (struct GNUNET_DISK_FileHandle *) cls; int sig; #if DEBUG_OS - LOG (GNUNET_ERROR_TYPE_DEBUG, "`%s' invoked because of %d\n", - __FUNCTION__, tc->reason); + LOG (GNUNET_ERROR_TYPE_DEBUG, "`%s' invoked because of %d\n", __FUNCTION__, + tc->reason); #endif if (tc->reason & (GNUNET_SCHEDULER_REASON_SHUTDOWN | GNUNET_SCHEDULER_REASON_TIMEOUT | GNUNET_SCHEDULER_REASON_PREREQ_DONE)) + { + GNUNET_DISK_npipe_close (control_pipe); + } + else + { + if (GNUNET_DISK_file_read (control_pipe, &sig, sizeof (sig)) != + sizeof (sig)) { + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DISK_file_read"); GNUNET_DISK_npipe_close (control_pipe); } - else + else { - if (GNUNET_DISK_file_read (control_pipe, &sig, sizeof (sig)) != - sizeof (sig)) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DISK_file_read"); - GNUNET_DISK_npipe_close (control_pipe); - } - else - { #if DEBUG_OS - LOG (GNUNET_ERROR_TYPE_DEBUG, "Got control code %d from parent\n", - sig); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Got control code %d from parent\n", sig); #endif - GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, - control_pipe, - &parent_control_handler, - control_pipe); - raise (sig); - } + GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, + control_pipe, &parent_control_handler, + control_pipe); + raise (sig); } + } } @@ -104,35 +102,34 @@ parent_control_handler (void *cls, */ void GNUNET_OS_install_parent_control_handler (void *cls, - const struct - GNUNET_SCHEDULER_TaskContext *tc) + const struct + GNUNET_SCHEDULER_TaskContext *tc) { const char *env_buf; struct GNUNET_DISK_FileHandle *control_pipe; env_buf = getenv (GNUNET_OS_CONTROL_PIPE); if ((env_buf == NULL) || (strlen (env_buf) <= 0)) - { - LOG (GNUNET_ERROR_TYPE_INFO, - _("Not installing a handler because $%s=%s\n"), - GNUNET_OS_CONTROL_PIPE, env_buf); - return; - } + { + LOG (GNUNET_ERROR_TYPE_INFO, _("Not installing a handler because $%s=%s\n"), + GNUNET_OS_CONTROL_PIPE, env_buf); + return; + } control_pipe = - GNUNET_DISK_npipe_open (env_buf, GNUNET_DISK_OPEN_READ, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE); + GNUNET_DISK_npipe_open (env_buf, GNUNET_DISK_OPEN_READ, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE); if (control_pipe == NULL) - { - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", env_buf); - return; - } + { + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", env_buf); + return; + } #if DEBUG_OS LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding parent control handler pipe `%s' to the scheduler\n", env_buf); #endif GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, control_pipe, - &parent_control_handler, control_pipe); + &parent_control_handler, control_pipe); } @@ -166,90 +163,90 @@ GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig) ret = GNUNET_DISK_file_write (proc->control_pipe, &sig, sizeof (sig)); if (ret != sizeof (sig)) + { + if (errno == ECOMM) { - if (errno == ECOMM) - { - /* Child process is not controllable via pipe */ + /* Child process is not controllable via pipe */ #if DEBUG_OS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Child process is not controllable, will kill it directly\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Child process is not controllable, will kill it directly\n"); #endif - } - else if (errno == EPIPE) - { + } + else if (errno == EPIPE) + { #if DEBUG_OS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Failed to write into control pipe, because pipe is invalid (the child is most likely dead)\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Failed to write into control pipe, because pipe is invalid (the child is most likely dead)\n"); #endif - } - else - LOG (GNUNET_ERROR_TYPE_WARNING, - "Failed to write into control pipe , errno is %d\n", errno); + } + else + LOG (GNUNET_ERROR_TYPE_WARNING, + "Failed to write into control pipe , errno is %d\n", errno); #if WINDOWS && !defined(__CYGWIN__) - TerminateProcess (proc->handle, 0); + TerminateProcess (proc->handle, 0); #else - PLIBC_KILL (proc->pid, sig); + PLIBC_KILL (proc->pid, sig); #endif - } + } else - { + { #if DEBUG_OS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Wrote control code into control pipe, now waiting\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Wrote control code into control pipe, now waiting\n"); #endif #if WINDOWS - /* Give it 3 seconds to die, then kill it in a nice Windows-specific way */ - if (WaitForSingleObject (proc->handle, 3000) != WAIT_OBJECT_0) - TerminateProcess (proc->handle, 0); - res = 0; + /* Give it 3 seconds to die, then kill it in a nice Windows-specific way */ + if (WaitForSingleObject (proc->handle, 3000) != WAIT_OBJECT_0) + TerminateProcess (proc->handle, 0); + res = 0; #else - struct GNUNET_NETWORK_FDSet *rfds; - struct GNUNET_NETWORK_FDSet *efds; - - rfds = GNUNET_NETWORK_fdset_create (); - efds = GNUNET_NETWORK_fdset_create (); - - GNUNET_NETWORK_fdset_handle_set (rfds, proc->control_pipe); - GNUNET_NETWORK_fdset_handle_set (efds, proc->control_pipe); - - /* Ndurner thought this up, and i have no idea what it does. - * There's have never been any code to answer the shutdown call - * (write a single int into the pipe, so that this function can read it). - * On *nix select() will probably tell that pipe is ready - * for reading, once the other process shuts down, - * but the read () call will fail, triggering a kill () - * on the pid that is already dead. This will probably result in non-0 - * return from kill(), and therefore from this function. - */ - while (1) - { - ret = - GNUNET_NETWORK_socket_select (rfds, NULL, efds, - GNUNET_TIME_relative_multiply - (GNUNET_TIME_relative_get_unit (), - 5000)); - - if (ret < 1 || - GNUNET_NETWORK_fdset_handle_isset (efds, proc->control_pipe)) - { - /* Just to be sure */ - PLIBC_KILL (proc->pid, sig); - res = 0; - break; - } - else - { - if (GNUNET_DISK_file_read - (proc->control_pipe, &ret, sizeof (ret)) != GNUNET_OK) - res = PLIBC_KILL (proc->pid, sig); - - /* Child signaled shutdown is in progress */ - continue; - } - } -#endif + struct GNUNET_NETWORK_FDSet *rfds; + struct GNUNET_NETWORK_FDSet *efds; + + rfds = GNUNET_NETWORK_fdset_create (); + efds = GNUNET_NETWORK_fdset_create (); + + GNUNET_NETWORK_fdset_handle_set (rfds, proc->control_pipe); + GNUNET_NETWORK_fdset_handle_set (efds, proc->control_pipe); + + /* Ndurner thought this up, and i have no idea what it does. + * There's have never been any code to answer the shutdown call + * (write a single int into the pipe, so that this function can read it). + * On *nix select() will probably tell that pipe is ready + * for reading, once the other process shuts down, + * but the read () call will fail, triggering a kill () + * on the pid that is already dead. This will probably result in non-0 + * return from kill(), and therefore from this function. + */ + while (1) + { + ret = + GNUNET_NETWORK_socket_select (rfds, NULL, efds, + GNUNET_TIME_relative_multiply + (GNUNET_TIME_relative_get_unit (), + 5000)); + + if (ret < 1 || + GNUNET_NETWORK_fdset_handle_isset (efds, proc->control_pipe)) + { + /* Just to be sure */ + PLIBC_KILL (proc->pid, sig); + res = 0; + break; + } + else + { + if (GNUNET_DISK_file_read (proc->control_pipe, &ret, sizeof (ret)) != + GNUNET_OK) + res = PLIBC_KILL (proc->pid, sig); + + /* Child signaled shutdown is in progress */ + continue; + } } +#endif + } return res; #else @@ -324,7 +321,7 @@ ChildWaitThread (void *arg) */ int GNUNET_OS_set_process_priority (struct GNUNET_OS_Process *proc, - enum GNUNET_SCHEDULER_Priority prio) + enum GNUNET_SCHEDULER_Priority prio) { int rprio; @@ -334,51 +331,51 @@ GNUNET_OS_set_process_priority (struct GNUNET_OS_Process *proc, /* convert to MINGW/Unix values */ switch (prio) - { - case GNUNET_SCHEDULER_PRIORITY_UI: - case GNUNET_SCHEDULER_PRIORITY_URGENT: + { + case GNUNET_SCHEDULER_PRIORITY_UI: + case GNUNET_SCHEDULER_PRIORITY_URGENT: #ifdef MINGW - rprio = HIGH_PRIORITY_CLASS; + rprio = HIGH_PRIORITY_CLASS; #else - rprio = 0; + rprio = 0; #endif - break; + break; - case GNUNET_SCHEDULER_PRIORITY_HIGH: + case GNUNET_SCHEDULER_PRIORITY_HIGH: #ifdef MINGW - rprio = ABOVE_NORMAL_PRIORITY_CLASS; + rprio = ABOVE_NORMAL_PRIORITY_CLASS; #else - rprio = 5; + rprio = 5; #endif - break; + break; - case GNUNET_SCHEDULER_PRIORITY_DEFAULT: + case GNUNET_SCHEDULER_PRIORITY_DEFAULT: #ifdef MINGW - rprio = NORMAL_PRIORITY_CLASS; + rprio = NORMAL_PRIORITY_CLASS; #else - rprio = 7; + rprio = 7; #endif - break; + break; - case GNUNET_SCHEDULER_PRIORITY_BACKGROUND: + case GNUNET_SCHEDULER_PRIORITY_BACKGROUND: #ifdef MINGW - rprio = BELOW_NORMAL_PRIORITY_CLASS; + rprio = BELOW_NORMAL_PRIORITY_CLASS; #else - rprio = 10; + rprio = 10; #endif - break; + break; - case GNUNET_SCHEDULER_PRIORITY_IDLE: + case GNUNET_SCHEDULER_PRIORITY_IDLE: #ifdef MINGW - rprio = IDLE_PRIORITY_CLASS; + rprio = IDLE_PRIORITY_CLASS; #else - rprio = 19; + rprio = 19; #endif - break; - default: - GNUNET_assert (0); - return GNUNET_SYSERR; - } + break; + default: + GNUNET_assert (0); + return GNUNET_SYSERR; + } /* Set process priority */ #ifdef MINGW @@ -393,27 +390,26 @@ GNUNET_OS_set_process_priority (struct GNUNET_OS_Process *proc, pid = proc->pid; if ((0 == pid) || (pid == getpid ())) + { + int have = nice (0); + int delta = rprio - have; + + errno = 0; + if ((delta != 0) && (rprio == nice (delta)) && (errno != 0)) { - int have = nice (0); - int delta = rprio - have; - - errno = 0; - if ((delta != 0) && (rprio == nice (delta)) && (errno != 0)) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, - "nice"); - return GNUNET_SYSERR; - } + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, "nice"); + return GNUNET_SYSERR; } + } else + { + if (0 != setpriority (PRIO_PROCESS, pid, rprio)) { - if (0 != setpriority (PRIO_PROCESS, pid, rprio)) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, - "setpriority"); - return GNUNET_SYSERR; - } + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, + "setpriority"); + return GNUNET_SYSERR; } + } #else #if DEBUG_OS LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, @@ -440,84 +436,84 @@ CreateCustomEnvTable (char **vars) win32_env_table = GetEnvironmentStringsA (); if (win32_env_table == NULL) return NULL; - for (c = 0, var_ptr = vars; *var_ptr; var_ptr += 2, c++); + for (c = 0, var_ptr = vars; *var_ptr; var_ptr += 2, c++) ; n_var = c; index = GNUNET_malloc (sizeof (char *) * n_var); for (c = 0; c < n_var; c++) index[c] = 0; for (items_count = 0, ptr = win32_env_table; ptr[0] != 0; items_count++) + { + size_t len = strlen (ptr); + int found = 0; + + for (var_ptr = vars; *var_ptr; var_ptr++) { - size_t len = strlen (ptr); - int found = 0; - - for (var_ptr = vars; *var_ptr; var_ptr++) - { - var = *var_ptr++; - val = *var_ptr; - var_len = strlen (var); - if (strncmp (var, ptr, var_len) == 0) - { - found = 1; - index[c] = 1; - tablesize += var_len + strlen (val) + 1; - break; - } - } - if (!found) - tablesize += len + 1; - ptr += len + 1; + var = *var_ptr++; + val = *var_ptr; + var_len = strlen (var); + if (strncmp (var, ptr, var_len) == 0) + { + found = 1; + index[c] = 1; + tablesize += var_len + strlen (val) + 1; + break; + } } + if (!found) + tablesize += len + 1; + ptr += len + 1; + } for (n_found = 0, c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++) + { + var = *var_ptr++; + val = *var_ptr; + if (index[c] != 1) + n_found += strlen (var) + strlen (val) + 1; + } + result = GNUNET_malloc (tablesize + n_found + 1); + for (result_ptr = result, ptr = win32_env_table; ptr[0] != 0;) + { + size_t len = strlen (ptr); + int found = 0; + + for (c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++) { var = *var_ptr++; val = *var_ptr; - if (index[c] != 1) - n_found += strlen (var) + strlen (val) + 1; + var_len = strlen (var); + if (strncmp (var, ptr, var_len) == 0) + { + found = 1; + break; + } } - result = GNUNET_malloc (tablesize + n_found + 1); - for (result_ptr = result, ptr = win32_env_table; ptr[0] != 0;) + if (!found) { - size_t len = strlen (ptr); - int found = 0; - - for (c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++) - { - var = *var_ptr++; - val = *var_ptr; - var_len = strlen (var); - if (strncmp (var, ptr, var_len) == 0) - { - found = 1; - break; - } - } - if (!found) - { - strcpy (result_ptr, ptr); - result_ptr += len + 1; - } - else - { - strcpy (result_ptr, var); - result_ptr += var_len; - strcpy (result_ptr, val); - result_ptr += strlen (val) + 1; - } - ptr += len + 1; + strcpy (result_ptr, ptr); + result_ptr += len + 1; + } + else + { + strcpy (result_ptr, var); + result_ptr += var_len; + strcpy (result_ptr, val); + result_ptr += strlen (val) + 1; } + ptr += len + 1; + } for (c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++) + { + var = *var_ptr++; + val = *var_ptr; + var_len = strlen (var); + if (index[c] != 1) { - var = *var_ptr++; - val = *var_ptr; - var_len = strlen (var); - if (index[c] != 1) - { - strcpy (result_ptr, var); - result_ptr += var_len; - strcpy (result_ptr, val); - result_ptr += strlen (val) + 1; - } + strcpy (result_ptr, var); + result_ptr += var_len; + strcpy (result_ptr, val); + result_ptr += strlen (val) + 1; } + } FreeEnvironmentStrings (win32_env_table); GNUNET_free (index); *result_ptr = 0; @@ -537,8 +533,8 @@ CreateCustomEnvTable (char **vars) */ struct GNUNET_OS_Process * GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, - struct GNUNET_DISK_PipeHandle *pipe_stdout, - const char *filename, va_list va) + struct GNUNET_DISK_PipeHandle *pipe_stdout, + const char *filename, va_list va) { va_list ap; @@ -559,9 +555,9 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, #if ENABLE_WINDOWS_WORKAROUNDS control_pipe = - GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE); + GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE); if (control_pipe == NULL) return NULL; #endif @@ -569,38 +565,35 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, argc = 0; va_copy (ap, va); while (NULL != va_arg (ap, char *)) - argc++; + argc++; va_end (ap); argv = GNUNET_malloc (sizeof (char *) * (argc + 1)); argc = 0; va_copy (ap, va); while (NULL != (argv[argc] = va_arg (ap, char *))) - argc++; + argc++; va_end (ap); if (pipe_stdout != NULL) - { - GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle - (pipe_stdout, - GNUNET_DISK_PIPE_END_WRITE), - &fd_stdout_write, sizeof (int)); - GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle - (pipe_stdout, - GNUNET_DISK_PIPE_END_READ), - &fd_stdout_read, sizeof (int)); - } + { + GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle + (pipe_stdout, + GNUNET_DISK_PIPE_END_WRITE), + &fd_stdout_write, sizeof (int)); + GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle + (pipe_stdout, GNUNET_DISK_PIPE_END_READ), + &fd_stdout_read, sizeof (int)); + } if (pipe_stdin != NULL) - { - GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle - (pipe_stdin, - GNUNET_DISK_PIPE_END_READ), - &fd_stdin_read, sizeof (int)); - GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle - (pipe_stdin, - GNUNET_DISK_PIPE_END_WRITE), - &fd_stdin_write, sizeof (int)); - } + { + GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle + (pipe_stdin, GNUNET_DISK_PIPE_END_READ), + &fd_stdin_read, sizeof (int)); + GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle + (pipe_stdin, GNUNET_DISK_PIPE_END_WRITE), + &fd_stdin_write, sizeof (int)); + } #if HAVE_WORKING_VFORK ret = vfork (); @@ -608,46 +601,44 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, ret = fork (); #endif if (ret != 0) + { + if (ret == -1) { - if (ret == -1) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork"); + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork"); #if ENABLE_WINDOWS_WORKAROUNDS - GNUNET_DISK_npipe_close (control_pipe); + GNUNET_DISK_npipe_close (control_pipe); #endif - } - else - { + } + else + { #if HAVE_WORKING_VFORK - /* let's hope vfork actually works; for some extreme cases (including - * a testcase) we need 'execvp' to have run before we return, since - * we may send a signal to the process next and we don't want it - * to be caught by OUR signal handler (but either by the default - * handler or the actual handler as installed by the process itself). */ + /* let's hope vfork actually works; for some extreme cases (including + * a testcase) we need 'execvp' to have run before we return, since + * we may send a signal to the process next and we don't want it + * to be caught by OUR signal handler (but either by the default + * handler or the actual handler as installed by the process itself). */ #else - /* let's give the child process a chance to run execvp, 1s should - * be plenty in practice */ - if (pipe_stdout != NULL) - GNUNET_DISK_pipe_close_end (pipe_stdout, - GNUNET_DISK_PIPE_END_WRITE); - if (pipe_stdin != NULL) - GNUNET_DISK_pipe_close_end (pipe_stdin, - GNUNET_DISK_PIPE_END_READ); - sleep (1); + /* let's give the child process a chance to run execvp, 1s should + * be plenty in practice */ + if (pipe_stdout != NULL) + GNUNET_DISK_pipe_close_end (pipe_stdout, GNUNET_DISK_PIPE_END_WRITE); + if (pipe_stdin != NULL) + GNUNET_DISK_pipe_close_end (pipe_stdin, GNUNET_DISK_PIPE_END_READ); + sleep (1); #endif - gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process)); - gnunet_proc->pid = ret; + gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process)); + gnunet_proc->pid = ret; #if ENABLE_WINDOWS_WORKAROUNDS - gnunet_proc->control_pipe = control_pipe; + gnunet_proc->control_pipe = control_pipe; #endif - } - GNUNET_free (argv); + } + GNUNET_free (argv); #if ENABLE_WINDOWS_WORKAROUNDS - GNUNET_free (childpipename); + GNUNET_free (childpipename); #endif - return gnunet_proc; - } + return gnunet_proc; + } #if ENABLE_WINDOWS_WORKAROUNDS setenv (GNUNET_OS_CONTROL_PIPE, childpipename, 1); @@ -655,21 +646,21 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, #endif if (pipe_stdout != NULL) - { - GNUNET_break (0 == close (fd_stdout_read)); - if (-1 == dup2 (fd_stdout_write, 1)) - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2"); - GNUNET_break (0 == close (fd_stdout_write)); - } + { + GNUNET_break (0 == close (fd_stdout_read)); + if (-1 == dup2 (fd_stdout_write, 1)) + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2"); + GNUNET_break (0 == close (fd_stdout_write)); + } if (pipe_stdin != NULL) - { + { - GNUNET_break (0 == close (fd_stdin_write)); - if (-1 == dup2 (fd_stdin_read, 0)) - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2"); - GNUNET_break (0 == close (fd_stdin_read)); - } + GNUNET_break (0 == close (fd_stdin_write)); + if (-1 == dup2 (fd_stdin_read, 0)) + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2"); + GNUNET_break (0 == close (fd_stdin_read)); + } execvp (filename, argv); LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "execvp", filename); _exit (1); @@ -705,8 +696,8 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, pathbuf_len = GetEnvironmentVariableA ("PATH", (char *) &pathbuf, 0); alloc_len = - pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1 + - strlen (libdir); + pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1 + + strlen (libdir); pathbuf = GNUNET_malloc (alloc_len * sizeof (char)); @@ -729,39 +720,39 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, if (non_const_filename[1] == ':') snprintf (path, sizeof (path) / sizeof (char), "%s", non_const_filename); else if (!SearchPathA - (pathbuf, non_const_filename, NULL, sizeof (path) / sizeof (char), - path, NULL)) - { - SetErrnoFromWinError (GetLastError ()); - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "SearchPath", - non_const_filename); - GNUNET_free (non_const_filename); - GNUNET_free (pathbuf); - return NULL; - } + (pathbuf, non_const_filename, NULL, sizeof (path) / sizeof (char), + path, NULL)) + { + SetErrnoFromWinError (GetLastError ()); + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "SearchPath", + non_const_filename); + GNUNET_free (non_const_filename); + GNUNET_free (pathbuf); + return NULL; + } GNUNET_free (pathbuf); GNUNET_free (non_const_filename); cmdlen = 0; va_copy (ap, va); while (NULL != (arg = va_arg (ap, char *))) - { - if (cmdlen == 0) - cmdlen = cmdlen + strlen (path) + 3; - else - cmdlen = cmdlen + strlen (arg) + 3; - } + { + if (cmdlen == 0) + cmdlen = cmdlen + strlen (path) + 3; + else + cmdlen = cmdlen + strlen (arg) + 3; + } va_end (ap); cmd = idx = GNUNET_malloc (sizeof (char) * (cmdlen + 1)); va_copy (ap, va); while (NULL != (arg = va_arg (ap, char *))) - { - if (idx == cmd) - idx += sprintf (idx, "\"%s\" ", path); - else - idx += sprintf (idx, "\"%s\" ", arg); - } + { + if (idx == cmd) + idx += sprintf (idx, "\"%s\" ", path); + else + idx += sprintf (idx, "\"%s\" ", arg); + } va_end (ap); memset (&start, 0, sizeof (start)); @@ -771,37 +762,36 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, start.dwFlags |= STARTF_USESTDHANDLES; if (pipe_stdin != NULL) - { - GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle - (pipe_stdin, - GNUNET_DISK_PIPE_END_READ), - &stdin_handle, sizeof (HANDLE)); - start.hStdInput = stdin_handle; - } + { + GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle + (pipe_stdin, GNUNET_DISK_PIPE_END_READ), + &stdin_handle, sizeof (HANDLE)); + start.hStdInput = stdin_handle; + } if (pipe_stdout != NULL) - { - GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle - (pipe_stdout, - GNUNET_DISK_PIPE_END_WRITE), - &stdout_handle, sizeof (HANDLE)); - start.hStdOutput = stdout_handle; - } + { + GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle + (pipe_stdout, + GNUNET_DISK_PIPE_END_WRITE), + &stdout_handle, sizeof (HANDLE)); + start.hStdOutput = stdout_handle; + } control_pipe = - GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE); + GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE); if (control_pipe == NULL) - { - GNUNET_free (cmd); - GNUNET_free (path); - return NULL; - } + { + GNUNET_free (cmd); + GNUNET_free (path); + return NULL; + } #if DEBUG_OS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Opened the parent end of the pipe `%s'\n", childpipename); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Opened the parent end of the pipe `%s'\n", + childpipename); #endif GNUNET_asprintf (&our_env[0], "%s=", GNUNET_OS_CONTROL_PIPE); @@ -814,13 +804,13 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, if (!CreateProcessA (path, cmd, NULL, NULL, TRUE, DETACHED_PROCESS | CREATE_SUSPENDED, env_block, NULL, &start, &proc)) - { - SetErrnoFromWinError (GetLastError ()); - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "CreateProcess", path); - GNUNET_free (env_block); - GNUNET_free (cmd); - return NULL; - } + { + SetErrnoFromWinError (GetLastError ()); + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "CreateProcess", path); + GNUNET_free (env_block); + GNUNET_free (cmd); + return NULL; + } GNUNET_free (env_block); @@ -854,8 +844,8 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, */ struct GNUNET_OS_Process * GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, - struct GNUNET_DISK_PipeHandle *pipe_stdout, - const char *filename, ...) + struct GNUNET_DISK_PipeHandle *pipe_stdout, + const char *filename, ...) { struct GNUNET_OS_Process *ret; va_list ap; @@ -878,7 +868,7 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, */ struct GNUNET_OS_Process * GNUNET_OS_start_process_v (const int *lsocks, const char *filename, - char *const argv[]) + char *const argv[]) { #if ENABLE_WINDOWS_WORKAROUNDS struct GNUNET_DISK_FileHandle *control_pipe = NULL; @@ -900,9 +890,9 @@ GNUNET_OS_start_process_v (const int *lsocks, const char *filename, #if ENABLE_WINDOWS_WORKAROUNDS control_pipe = - GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE); + GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE); if (control_pipe == NULL) return NULL; #endif @@ -910,52 +900,52 @@ GNUNET_OS_start_process_v (const int *lsocks, const char *filename, lscp = NULL; ls = 0; if (lsocks != NULL) - { - i = 0; - while (-1 != (k = lsocks[i++])) - GNUNET_array_append (lscp, ls, k); - GNUNET_array_append (lscp, ls, -1); - } + { + i = 0; + while (-1 != (k = lsocks[i++])) + GNUNET_array_append (lscp, ls, k); + GNUNET_array_append (lscp, ls, -1); + } #if HAVE_WORKING_VFORK ret = vfork (); #else ret = fork (); #endif if (ret != 0) + { + if (ret == -1) { - if (ret == -1) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork"); + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork"); #if ENABLE_WINDOWS_WORKAROUNDS - GNUNET_DISK_npipe_close (control_pipe); + GNUNET_DISK_npipe_close (control_pipe); #endif - } - else - { + } + else + { #if HAVE_WORKING_VFORK - /* let's hope vfork actually works; for some extreme cases (including - * a testcase) we need 'execvp' to have run before we return, since - * we may send a signal to the process next and we don't want it - * to be caught by OUR signal handler (but either by the default - * handler or the actual handler as installed by the process itself). */ + /* let's hope vfork actually works; for some extreme cases (including + * a testcase) we need 'execvp' to have run before we return, since + * we may send a signal to the process next and we don't want it + * to be caught by OUR signal handler (but either by the default + * handler or the actual handler as installed by the process itself). */ #else - /* let's give the child process a chance to run execvp, 1s should - * be plenty in practice */ - sleep (1); + /* let's give the child process a chance to run execvp, 1s should + * be plenty in practice */ + sleep (1); #endif - gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process)); - gnunet_proc->pid = ret; + gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process)); + gnunet_proc->pid = ret; #if ENABLE_WINDOWS_WORKAROUNDS - gnunet_proc->control_pipe = control_pipe; + gnunet_proc->control_pipe = control_pipe; #endif - } - GNUNET_array_grow (lscp, ls, 0); + } + GNUNET_array_grow (lscp, ls, 0); #if ENABLE_WINDOWS_WORKAROUNDS - GNUNET_free (childpipename); + GNUNET_free (childpipename); #endif - return gnunet_proc; - } + return gnunet_proc; + } #if ENABLE_WINDOWS_WORKAROUNDS setenv (GNUNET_OS_CONTROL_PIPE, childpipename, 1); @@ -963,47 +953,47 @@ GNUNET_OS_start_process_v (const int *lsocks, const char *filename, #endif if (lscp != NULL) + { + /* read systemd documentation... */ + GNUNET_snprintf (lpid, sizeof (lpid), "%u", getpid ()); + setenv ("LISTEN_PID", lpid, 1); + i = 0; + tgt = 3; + while (-1 != lscp[i]) { - /* read systemd documentation... */ - GNUNET_snprintf (lpid, sizeof (lpid), "%u", getpid ()); - setenv ("LISTEN_PID", lpid, 1); - i = 0; - tgt = 3; - while (-1 != lscp[i]) - { - j = i + 1; - while (-1 != lscp[j]) - { - if (lscp[j] == tgt) - { - /* dup away */ - k = dup (lscp[j]); - GNUNET_assert (-1 != k); - GNUNET_assert (0 == close (lscp[j])); - lscp[j] = k; - break; - } - j++; - } - if (lscp[i] != tgt) - { - /* Bury any existing FD, no matter what; they should all be closed - * on exec anyway and the important onces have been dup'ed away */ - (void) close (tgt); - GNUNET_assert (-1 != dup2 (lscp[i], tgt)); - } - /* unset close-on-exec flag */ - flags = fcntl (tgt, F_GETFD); - GNUNET_assert (flags >= 0); - flags &= ~FD_CLOEXEC; - fflush (stderr); - (void) fcntl (tgt, F_SETFD, flags); - tgt++; - i++; - } - GNUNET_snprintf (fds, sizeof (fds), "%u", i); - setenv ("LISTEN_FDS", fds, 1); + j = i + 1; + while (-1 != lscp[j]) + { + if (lscp[j] == tgt) + { + /* dup away */ + k = dup (lscp[j]); + GNUNET_assert (-1 != k); + GNUNET_assert (0 == close (lscp[j])); + lscp[j] = k; + break; + } + j++; + } + if (lscp[i] != tgt) + { + /* Bury any existing FD, no matter what; they should all be closed + * on exec anyway and the important onces have been dup'ed away */ + (void) close (tgt); + GNUNET_assert (-1 != dup2 (lscp[i], tgt)); + } + /* unset close-on-exec flag */ + flags = fcntl (tgt, F_GETFD); + GNUNET_assert (flags >= 0); + flags &= ~FD_CLOEXEC; + fflush (stderr); + (void) fcntl (tgt, F_SETFD, flags); + tgt++; + i++; } + GNUNET_snprintf (fds, sizeof (fds), "%u", i); + setenv ("LISTEN_FDS", fds, 1); + } GNUNET_array_grow (lscp, ls, 0); execvp (filename, argv); LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "execvp", filename); @@ -1041,8 +1031,8 @@ GNUNET_OS_start_process_v (const int *lsocks, const char *filename, pathbuf_len = GetEnvironmentVariableA ("PATH", (char *) &pathbuf, 0); alloc_len = - pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1 + - strlen (libdir); + pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1 + + strlen (libdir); pathbuf = GNUNET_malloc (alloc_len * sizeof (char)); @@ -1054,11 +1044,11 @@ GNUNET_OS_start_process_v (const int *lsocks, const char *filename, alloc_len = GetEnvironmentVariableA ("PATH", ptr, pathbuf_len); if (alloc_len != pathbuf_len - 1) - { - GNUNET_free (pathbuf); - errno = ENOSYS; /* PATH changed on the fly. What kind of error is that? */ - return NULL; - } + { + GNUNET_free (pathbuf); + errno = ENOSYS; /* PATH changed on the fly. What kind of error is that? */ + return NULL; + } cmdlen = strlen (filename); if (cmdlen < 5 || strcmp (&filename[cmdlen - 4], ".exe") != 0) @@ -1070,26 +1060,26 @@ GNUNET_OS_start_process_v (const int *lsocks, const char *filename, if (non_const_filename[1] == ':') snprintf (path, sizeof (path) / sizeof (char), "%s", non_const_filename); else if (!SearchPathA - (pathbuf, non_const_filename, NULL, sizeof (path) / sizeof (char), - path, NULL)) - { - SetErrnoFromWinError (GetLastError ()); - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "SearchPath", - non_const_filename); - GNUNET_free (non_const_filename); - GNUNET_free (pathbuf); - return NULL; - } + (pathbuf, non_const_filename, NULL, sizeof (path) / sizeof (char), + path, NULL)) + { + SetErrnoFromWinError (GetLastError ()); + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "SearchPath", + non_const_filename); + GNUNET_free (non_const_filename); + GNUNET_free (pathbuf); + return NULL; + } GNUNET_free (pathbuf); GNUNET_free (non_const_filename); /* Count the number of arguments */ arg = (char **) argv; while (*arg) - { - arg++; - argcount++; - } + { + arg++; + argcount++; + } /* Allocate a copy argv */ non_const_argv = GNUNET_malloc (sizeof (char *) * (argcount + 1)); @@ -1098,33 +1088,33 @@ GNUNET_OS_start_process_v (const int *lsocks, const char *filename, argcount = 0; arg = (char **) argv; while (*arg) - { - if (arg == argv) - non_const_argv[argcount] = GNUNET_strdup (path); - else - non_const_argv[argcount] = GNUNET_strdup (*arg); - arg++; - argcount++; - } + { + if (arg == argv) + non_const_argv[argcount] = GNUNET_strdup (path); + else + non_const_argv[argcount] = GNUNET_strdup (*arg); + arg++; + argcount++; + } non_const_argv[argcount] = NULL; /* Count cmd len */ cmdlen = 1; arg = non_const_argv; while (*arg) - { - cmdlen = cmdlen + strlen (*arg) + 3; - arg++; - } + { + cmdlen = cmdlen + strlen (*arg) + 3; + arg++; + } /* Allocate and create cmd */ cmd = idx = GNUNET_malloc (sizeof (char) * cmdlen); arg = non_const_argv; while (*arg) - { - idx += sprintf (idx, "\"%s\" ", *arg); - arg++; - } + { + idx += sprintf (idx, "\"%s\" ", *arg); + arg++; + } while (argcount > 0) GNUNET_free (non_const_argv[--argcount]); @@ -1134,19 +1124,19 @@ GNUNET_OS_start_process_v (const int *lsocks, const char *filename, start.cb = sizeof (start); control_pipe = - GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE); + GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE); if (control_pipe == NULL) - { - GNUNET_free (cmd); - GNUNET_free (path); - return NULL; - } + { + GNUNET_free (cmd); + GNUNET_free (path); + return NULL; + } #if DEBUG_OS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Opened the parent end of the pipe `%s'\n", childpipename); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Opened the parent end of the pipe `%s'\n", + childpipename); #endif GNUNET_asprintf (&our_env[0], "%s=", GNUNET_OS_CONTROL_PIPE); @@ -1159,13 +1149,13 @@ GNUNET_OS_start_process_v (const int *lsocks, const char *filename, if (!CreateProcess (path, cmd, NULL, NULL, FALSE, DETACHED_PROCESS | CREATE_SUSPENDED, env_block, NULL, &start, &proc)) - { - SetErrnoFromWinError (GetLastError ()); - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "CreateProcess"); - GNUNET_free (env_block); - GNUNET_free (cmd); - return NULL; - } + { + SetErrnoFromWinError (GetLastError ()); + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "CreateProcess"); + GNUNET_free (env_block); + GNUNET_free (cmd); + return NULL; + } GNUNET_free (env_block); @@ -1194,8 +1184,8 @@ GNUNET_OS_start_process_v (const int *lsocks, const char *filename, */ int GNUNET_OS_process_status (struct GNUNET_OS_Process *proc, - enum GNUNET_OS_ProcessStatusType *type, - unsigned long *code) + enum GNUNET_OS_ProcessStatusType *type, + unsigned long *code) { #ifndef MINGW int status; @@ -1204,48 +1194,48 @@ GNUNET_OS_process_status (struct GNUNET_OS_Process *proc, GNUNET_assert (0 != proc); ret = waitpid (proc->pid, &status, WNOHANG); if (ret < 0) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid"); - return GNUNET_SYSERR; - } + { + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid"); + return GNUNET_SYSERR; + } if (0 == ret) - { - *type = GNUNET_OS_PROCESS_RUNNING; - *code = 0; - return GNUNET_NO; - } + { + *type = GNUNET_OS_PROCESS_RUNNING; + *code = 0; + return GNUNET_NO; + } if (proc->pid != ret) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid"); - return GNUNET_SYSERR; - } + { + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid"); + return GNUNET_SYSERR; + } if (WIFEXITED (status)) - { - *type = GNUNET_OS_PROCESS_EXITED; - *code = WEXITSTATUS (status); - } + { + *type = GNUNET_OS_PROCESS_EXITED; + *code = WEXITSTATUS (status); + } else if (WIFSIGNALED (status)) - { - *type = GNUNET_OS_PROCESS_SIGNALED; - *code = WTERMSIG (status); - } + { + *type = GNUNET_OS_PROCESS_SIGNALED; + *code = WTERMSIG (status); + } else if (WIFSTOPPED (status)) - { - *type = GNUNET_OS_PROCESS_SIGNALED; - *code = WSTOPSIG (status); - } + { + *type = GNUNET_OS_PROCESS_SIGNALED; + *code = WSTOPSIG (status); + } #ifdef WIFCONTINUED else if (WIFCONTINUED (status)) - { - *type = GNUNET_OS_PROCESS_RUNNING; - *code = 0; - } + { + *type = GNUNET_OS_PROCESS_RUNNING; + *code = 0; + } #endif else - { - *type = GNUNET_OS_PROCESS_UNKNOWN; - *code = 0; - } + { + *type = GNUNET_OS_PROCESS_UNKNOWN; + *code = 0; + } #else HANDLE h; DWORD c, error_code, ret; @@ -1253,11 +1243,11 @@ GNUNET_OS_process_status (struct GNUNET_OS_Process *proc, h = proc->handle; ret = proc->pid; if (h == NULL || ret == 0) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - "Invalid process information {%d, %08X}\n", ret, h); - return GNUNET_SYSERR; - } + { + LOG (GNUNET_ERROR_TYPE_WARNING, "Invalid process information {%d, %08X}\n", + ret, h); + return GNUNET_SYSERR; + } if (h == NULL) h = GetCurrentProcess (); @@ -1265,17 +1255,17 @@ GNUNET_OS_process_status (struct GNUNET_OS_Process *proc, ret = GetExitCodeProcess (h, &c); error_code = GetLastError (); if (ret == 0 || error_code != NO_ERROR) - { - SetErrnoFromWinError (error_code); - LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "GetExitCodeProcess"); - return GNUNET_SYSERR; - } + { + SetErrnoFromWinError (error_code); + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "GetExitCodeProcess"); + return GNUNET_SYSERR; + } if (STILL_ACTIVE == c) - { - *type = GNUNET_OS_PROCESS_RUNNING; - *code = 0; - return GNUNET_NO; - } + { + *type = GNUNET_OS_PROCESS_RUNNING; + *code = 0; + return GNUNET_NO; + } *type = GNUNET_OS_PROCESS_EXITED; *code = c; #endif @@ -1305,19 +1295,19 @@ GNUNET_OS_process_wait (struct GNUNET_OS_Process *proc) h = proc->handle; if (NULL == h) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - "Invalid process information {%d, %08X}\n", proc->pid, h); - return GNUNET_SYSERR; - } + { + LOG (GNUNET_ERROR_TYPE_WARNING, "Invalid process information {%d, %08X}\n", + proc->pid, h); + return GNUNET_SYSERR; + } if (h == NULL) h = GetCurrentProcess (); if (WAIT_OBJECT_0 != WaitForSingleObject (h, INFINITE)) - { - SetErrnoFromWinError (GetLastError ()); - ret = GNUNET_SYSERR; - } + { + SetErrnoFromWinError (GetLastError ()); + ret = GNUNET_SYSERR; + } else ret = GNUNET_OK; @@ -1391,10 +1381,10 @@ GNUNET_OS_command_stop (struct GNUNET_OS_CommandHandle *cmd) { if (cmd->proc != NULL) - { - GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != cmd->rtask); - GNUNET_SCHEDULER_cancel (cmd->rtask); - } + { + GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != cmd->rtask); + GNUNET_SCHEDULER_cancel (cmd->rtask); + } (void) GNUNET_OS_process_kill (cmd->eip, SIGKILL); GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (cmd->eip)); GNUNET_OS_process_close (cmd->eip); @@ -1418,43 +1408,42 @@ cmd_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) ssize_t ret; cmd->rtask = GNUNET_SCHEDULER_NO_TASK; - if (GNUNET_YES != - GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, cmd->r)) - { - /* timeout, shutdown, etc. */ - proc = cmd->proc; - cmd->proc = NULL; - proc (cmd->proc_cls, NULL); - return; - } + if (GNUNET_YES != GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, cmd->r)) + { + /* timeout, shutdown, etc. */ + proc = cmd->proc; + cmd->proc = NULL; + proc (cmd->proc_cls, NULL); + return; + } ret = - GNUNET_DISK_file_read (cmd->r, &cmd->buf[cmd->off], - sizeof (cmd->buf) - cmd->off); + GNUNET_DISK_file_read (cmd->r, &cmd->buf[cmd->off], + sizeof (cmd->buf) - cmd->off); if (ret <= 0) + { + if ((cmd->off > 0) && (cmd->off < sizeof (cmd->buf))) { - if ((cmd->off > 0) && (cmd->off < sizeof (cmd->buf))) - { - cmd->buf[cmd->off] = '\0'; - cmd->proc (cmd->proc_cls, cmd->buf); - } - proc = cmd->proc; - cmd->proc = NULL; - proc (cmd->proc_cls, NULL); - return; + cmd->buf[cmd->off] = '\0'; + cmd->proc (cmd->proc_cls, cmd->buf); } + proc = cmd->proc; + cmd->proc = NULL; + proc (cmd->proc_cls, NULL); + return; + } end = memchr (&cmd->buf[cmd->off], '\n', ret); cmd->off += ret; while (end != NULL) - { - *end = '\0'; - cmd->proc (cmd->proc_cls, cmd->buf); - memmove (cmd->buf, end + 1, cmd->off - (end + 1 - cmd->buf)); - cmd->off -= (end + 1 - cmd->buf); - end = memchr (cmd->buf, '\n', cmd->off); - } + { + *end = '\0'; + cmd->proc (cmd->proc_cls, cmd->buf); + memmove (cmd->buf, end + 1, cmd->off - (end + 1 - cmd->buf)); + cmd->off -= (end + 1 - cmd->buf); + end = memchr (cmd->buf, '\n', cmd->off); + } cmd->rtask = - GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining - (cmd->timeout), cmd->r, &cmd_read, cmd); + GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining + (cmd->timeout), cmd->r, &cmd_read, cmd); } @@ -1471,8 +1460,8 @@ cmd_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) */ struct GNUNET_OS_CommandHandle * GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc, void *proc_cls, - struct GNUNET_TIME_Relative timeout, - const char *binary, ...) + struct GNUNET_TIME_Relative timeout, const char *binary, + ...) { struct GNUNET_OS_CommandHandle *cmd; struct GNUNET_OS_Process *eip; @@ -1486,10 +1475,10 @@ GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc, void *proc_cls, eip = GNUNET_OS_start_process_va (NULL, opipe, binary, ap); va_end (ap); if (NULL == eip) - { - GNUNET_DISK_pipe_close (opipe); - return NULL; - } + { + GNUNET_DISK_pipe_close (opipe); + return NULL; + } GNUNET_DISK_pipe_close_end (opipe, GNUNET_DISK_PIPE_END_WRITE); cmd = GNUNET_malloc (sizeof (struct GNUNET_OS_CommandHandle)); cmd->timeout = GNUNET_TIME_relative_to_absolute (timeout); @@ -1498,8 +1487,7 @@ GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc, void *proc_cls, cmd->proc = proc; cmd->proc_cls = proc_cls; cmd->r = GNUNET_DISK_pipe_handle (opipe, GNUNET_DISK_PIPE_END_READ); - cmd->rtask = - GNUNET_SCHEDULER_add_read_file (timeout, cmd->r, &cmd_read, cmd); + cmd->rtask = GNUNET_SCHEDULER_add_read_file (timeout, cmd->r, &cmd_read, cmd); return cmd; } diff --git a/src/util/peer.c b/src/util/peer.c index c88e03c15..2444cb9f8 100644 --- a/src/util/peer.c +++ b/src/util/peer.c @@ -107,7 +107,7 @@ GNUNET_PEER_search (const struct GNUNET_PeerIdentity *pid) * @return the interned identity. */ GNUNET_PEER_Id -GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid) +GNUNET_PEER_intern (const struct GNUNET_PeerIdentity *pid) { GNUNET_PEER_Id ret; struct PeerEntry *e; @@ -121,24 +121,24 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid) off = (long) GNUNET_CONTAINER_multihashmap_get (map, &pid->hashPubKey); e = (off == 0) ? NULL : &table[off]; if (e != NULL) - { - GNUNET_assert (e->rc > 0); - e->rc++; - return e->pid; - } + { + GNUNET_assert (e->rc > 0); + e->rc++; + return e->pid; + } ret = free_list_start; if (ret == size) - { - GNUNET_array_grow (table, size, size + 16); - for (i = ret; i < size; i++) - table[i].pid = i + 1; - } + { + GNUNET_array_grow (table, size, size + 16); + for (i = ret; i < size; i++) + table[i].pid = i + 1; + } if (ret == 0) - { - table[0].pid = 0; - table[0].rc = 1; - ret = 1; - } + { + table[0].pid = 0; + table[0].rc = 1; + ret = 1; + } GNUNET_assert (ret < size); GNUNET_assert (table[ret].rc == 0); free_list_start = table[ret].pid; @@ -146,9 +146,9 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid) table[ret].rc = 1; table[ret].pid = ret; GNUNET_break (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put (map, &pid->hashPubKey, - (void *) (long) ret, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + GNUNET_CONTAINER_multihashmap_put (map, &pid->hashPubKey, + (void *) (long) ret, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); return ret; } @@ -160,7 +160,7 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid) * @param count size of the ids array */ void -GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id * ids, unsigned int count) +GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id *ids, unsigned int count) { int i; GNUNET_PEER_Id id; @@ -168,25 +168,24 @@ GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id * ids, unsigned int count) if (count == 0) return; for (i = count - 1; i >= 0; i--) + { + id = ids[i]; + if (id == 0) + continue; + GNUNET_assert (id < size); + GNUNET_assert (table[id].rc > 0); + table[id].rc--; + if (table[id].rc == 0) { - id = ids[i]; - if (id == 0) - continue; - GNUNET_assert (id < size); - GNUNET_assert (table[id].rc > 0); - table[id].rc--; - if (table[id].rc == 0) - { - GNUNET_break (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_remove (map, - &table[id]. - id.hashPubKey, - (void *) (long) - id)); - table[id].pid = free_list_start; - free_list_start = id; - } + GNUNET_break (GNUNET_OK == + GNUNET_CONTAINER_multihashmap_remove (map, + &table[id]. + id.hashPubKey, + (void *) (long) id)); + table[id].pid = free_list_start; + free_list_start = id; } + } } @@ -206,16 +205,15 @@ GNUNET_PEER_change_rc (GNUNET_PEER_Id id, int delta) GNUNET_assert ((delta >= 0) || (table[id].rc >= -delta)); table[id].rc += delta; if (table[id].rc == 0) - { - GNUNET_break (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_remove (map, - &table[id]. - id.hashPubKey, - (void *) (long) - id)); - table[id].pid = free_list_start; - free_list_start = id; - } + { + GNUNET_break (GNUNET_OK == + GNUNET_CONTAINER_multihashmap_remove (map, + &table[id]. + id.hashPubKey, + (void *) (long) id)); + table[id].pid = free_list_start; + free_list_start = id; + } } @@ -229,11 +227,11 @@ void GNUNET_PEER_resolve (GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid) { if (id == 0) - { - memset (pid, 0, sizeof (struct GNUNET_PeerIdentity)); - GNUNET_break (0); - return; - } + { + memset (pid, 0, sizeof (struct GNUNET_PeerIdentity)); + GNUNET_break (0); + return; + } GNUNET_assert (id < size); GNUNET_assert (table[id].rc > 0); *pid = table[id].id; diff --git a/src/util/perf_crypto_hash.c b/src/util/perf_crypto_hash.c index 746b33eca..d883776b4 100644 --- a/src/util/perf_crypto_hash.c +++ b/src/util/perf_crypto_hash.c @@ -42,11 +42,11 @@ perfHash () memset (buf, 1, 1024 * 64); GNUNET_CRYPTO_hash ("foo", 3, &hc1); for (i = 0; i < 1024; i++) - { - GNUNET_CRYPTO_hash (&hc1, sizeof (GNUNET_HashCode), &hc2); - GNUNET_CRYPTO_hash (&hc2, sizeof (GNUNET_HashCode), &hc1); - GNUNET_CRYPTO_hash (buf, 1024 * 64, &hc3); - } + { + GNUNET_CRYPTO_hash (&hc1, sizeof (GNUNET_HashCode), &hc2); + GNUNET_CRYPTO_hash (&hc2, sizeof (GNUNET_HashCode), &hc1); + GNUNET_CRYPTO_hash (buf, 1024 * 64, &hc3); + } GNUNET_free (buf); } @@ -58,12 +58,12 @@ main (int argc, char *argv[]) start = GNUNET_TIME_absolute_get (); perfHash (); printf ("Hash perf took %llu ms\n", - (unsigned long long) - GNUNET_TIME_absolute_get_duration (start).rel_value); + (unsigned long long) + GNUNET_TIME_absolute_get_duration (start).rel_value); GAUGER ("UTIL", "Cryptographic hashing", - 1024 * 64 * 1024 / (1 + - GNUNET_TIME_absolute_get_duration - (start).rel_value), "kb/s"); + 1024 * 64 * 1024 / (1 + + GNUNET_TIME_absolute_get_duration + (start).rel_value), "kb/s"); return 0; } diff --git a/src/util/plugin.c b/src/util/plugin.c index dffc8ecd6..fe5fb87f9 100644 --- a/src/util/plugin.c +++ b/src/util/plugin.c @@ -85,30 +85,30 @@ plugin_init () err = lt_dlinit (); if (err > 0) - { - fprintf (stderr, _("Initialization of plugin mechanism failed: %s!\n"), - lt_dlerror ()); - return; - } + { + fprintf (stderr, _("Initialization of plugin mechanism failed: %s!\n"), + lt_dlerror ()); + return; + } opath = lt_dlgetsearchpath (); if (opath != NULL) old_dlsearchpath = GNUNET_strdup (opath); path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBDIR); if (path != NULL) + { + if (opath != NULL) { - if (opath != NULL) - { - GNUNET_asprintf (&cpath, "%s:%s", opath, path); - lt_dlsetsearchpath (cpath); - GNUNET_free (path); - GNUNET_free (cpath); - } - else - { - lt_dlsetsearchpath (path); - GNUNET_free (path); - } + GNUNET_asprintf (&cpath, "%s:%s", opath, path); + lt_dlsetsearchpath (cpath); + GNUNET_free (path); + GNUNET_free (cpath); } + else + { + lt_dlsetsearchpath (path); + GNUNET_free (path); + } + } } @@ -120,10 +120,10 @@ plugin_fini () { lt_dlsetsearchpath (old_dlsearchpath); if (old_dlsearchpath != NULL) - { - GNUNET_free (old_dlsearchpath); - old_dlsearchpath = NULL; - } + { + GNUNET_free (old_dlsearchpath); + old_dlsearchpath = NULL; + } lt_dlexit (); } @@ -143,8 +143,8 @@ resolve_function (struct PluginList *plug, const char *name) mptr = lt_dlsym (plug->handle, initName); if (mptr == NULL) LOG (GNUNET_ERROR_TYPE_ERROR, - _("`%s' failed to resolve method '%s' with error: %s\n"), - "lt_dlsym", &initName[1], lt_dlerror ()); + _("`%s' failed to resolve method '%s' with error: %s\n"), "lt_dlsym", + &initName[1], lt_dlerror ()); GNUNET_free (initName); return mptr; } @@ -166,10 +166,10 @@ GNUNET_PLUGIN_test (const char *library_name) struct PluginList plug; if (!initialized) - { - initialized = GNUNET_YES; - plugin_init (); - } + { + initialized = GNUNET_YES; + plugin_init (); + } libhandle = lt_dlopenext (library_name); if (libhandle == NULL) return GNUNET_NO; @@ -177,11 +177,11 @@ GNUNET_PLUGIN_test (const char *library_name) plug.name = (char *) library_name; init = resolve_function (&plug, "init"); if (init == NULL) - { - GNUNET_break (0); - lt_dlclose (libhandle); - return GNUNET_NO; - } + { + GNUNET_break (0); + lt_dlclose (libhandle); + return GNUNET_NO; + } lt_dlclose (libhandle); return GNUNET_YES; } @@ -208,18 +208,18 @@ GNUNET_PLUGIN_load (const char *library_name, void *arg) void *ret; if (!initialized) - { - initialized = GNUNET_YES; - plugin_init (); - } + { + initialized = GNUNET_YES; + plugin_init (); + } libhandle = lt_dlopenext (library_name); if (libhandle == NULL) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _("`%s' failed for library `%s' with error: %s\n"), - "lt_dlopenext", library_name, lt_dlerror ()); - return NULL; - } + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _("`%s' failed for library `%s' with error: %s\n"), "lt_dlopenext", + library_name, lt_dlerror ()); + return NULL; + } plug = GNUNET_malloc (sizeof (struct PluginList)); plug->handle = libhandle; plug->name = GNUNET_strdup (library_name); @@ -227,13 +227,13 @@ GNUNET_PLUGIN_load (const char *library_name, void *arg) plugins = plug; init = resolve_function (plug, "init"); if ((init == NULL) || (NULL == (ret = init (arg)))) - { - lt_dlclose (libhandle); - GNUNET_free (plug->name); - plugins = plug->next; - GNUNET_free (plug); - return NULL; - } + { + lt_dlclose (libhandle); + GNUNET_free (plug->name); + plugins = plug->next; + GNUNET_free (plug); + return NULL; + } return ret; } @@ -257,10 +257,10 @@ GNUNET_PLUGIN_unload (const char *library_name, void *arg) prev = NULL; pos = plugins; while ((pos != NULL) && (0 != strcmp (pos->name, library_name))) - { - prev = pos; - pos = pos->next; - } + { + prev = pos; + pos = pos->next; + } if (pos == NULL) return NULL; @@ -276,10 +276,10 @@ GNUNET_PLUGIN_unload (const char *library_name, void *arg) GNUNET_free (pos->name); GNUNET_free (pos); if (plugins == NULL) - { - plugin_fini (); - initialized = GNUNET_NO; - } + { + plugin_fini (); + initialized = GNUNET_NO; + } return ret; } @@ -294,8 +294,7 @@ struct LoadAllContext static int -find_libraries (void *cls, - const char *filename) +find_libraries (void *cls, const char *filename) { struct LoadAllContext *lac = cls; const char *slashpos; @@ -309,14 +308,10 @@ find_libraries (void *cls, while (NULL != (slashpos = strstr (libname, DIR_SEPARATOR_STR))) libname = slashpos + 1; n = strlen (libname); - if (0 != strncmp (lac->basename, - libname, - strlen (lac->basename))) - return GNUNET_OK; /* wrong name */ - if ( (n > 3) && - (0 == strcmp (&libname[n-3], - ".la")) ) - return GNUNET_OK; /* .la file */ + if (0 != strncmp (lac->basename, libname, strlen (lac->basename))) + return GNUNET_OK; /* wrong name */ + if ((n > 3) && (0 == strcmp (&libname[n - 3], ".la"))) + return GNUNET_OK; /* .la file */ basename = GNUNET_strdup (libname); if (NULL != (dot = strstr (basename, "."))) *dot = '\0'; @@ -340,11 +335,9 @@ find_libraries (void *cls, * @param cb function to call for each plugin found * @param cb_cls closure for 'cb' */ -void -GNUNET_PLUGIN_load_all (const char *basename, - void *arg, - GNUNET_PLUGIN_LoaderCallback cb, - void *cb_cls) +void +GNUNET_PLUGIN_load_all (const char *basename, void *arg, + GNUNET_PLUGIN_LoaderCallback cb, void *cb_cls) { struct LoadAllContext lac; char *path; @@ -353,16 +346,14 @@ GNUNET_PLUGIN_load_all (const char *basename, if (path == NULL) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Could not determine plugin installation path.\n")); + _("Could not determine plugin installation path.\n")); return; } lac.basename = basename; lac.arg = arg; lac.cb = cb; lac.cb_cls = cb_cls; - GNUNET_DISK_directory_scan (path, - &find_libraries, - &lac); + GNUNET_DISK_directory_scan (path, &find_libraries, &lac); GNUNET_free (path); } diff --git a/src/util/program.c b/src/util/program.c index 5582f30c6..6a0e5a555 100644 --- a/src/util/program.c +++ b/src/util/program.c @@ -129,9 +129,9 @@ cmd_sorter (__const void *a1, __const void *a2) */ int GNUNET_PROGRAM_run (int argc, char *const *argv, const char *binaryName, - const char *binaryHelp, - const struct GNUNET_GETOPT_CommandLineOption *options, - GNUNET_PROGRAM_Main task, void *task_cls) + const char *binaryHelp, + const struct GNUNET_GETOPT_CommandLineOption *options, + GNUNET_PROGRAM_Main task, void *task_cls) { struct CommandContext cc; char *path; @@ -159,29 +159,29 @@ GNUNET_PROGRAM_run (int argc, char *const *argv, const char *binaryName, logfile = NULL; gargs = getenv ("GNUNET_ARGS"); if (gargs != NULL) - { - char **gargv; - unsigned int gargc; - int i; - char *tok; - char *cargs; + { + char **gargv; + unsigned int gargc; + int i; + char *tok; + char *cargs; - gargv = NULL; - gargc = 0; - for (i = 0; i < argc; i++) - GNUNET_array_append (gargv, gargc, GNUNET_strdup (argv[i])); - cargs = GNUNET_strdup (gargs); - tok = strtok (cargs, " "); - while (NULL != tok) - { - GNUNET_array_append (gargv, gargc, GNUNET_strdup (tok)); - tok = strtok (NULL, " "); - } - GNUNET_free (cargs); - GNUNET_array_append (gargv, gargc, NULL); - argv = (char *const *) gargv; - argc = gargc - 1; + gargv = NULL; + gargc = 0; + for (i = 0; i < argc; i++) + GNUNET_array_append (gargv, gargc, GNUNET_strdup (argv[i])); + cargs = GNUNET_strdup (gargs); + tok = strtok (cargs, " "); + while (NULL != tok) + { + GNUNET_array_append (gargv, gargc, GNUNET_strdup (tok)); + tok = strtok (NULL, " "); } + GNUNET_free (cargs); + GNUNET_array_append (gargv, gargc, NULL); + argv = (char *const *) gargv; + argc = gargc - 1; + } memset (&cc, 0, sizeof (cc)); loglev = NULL; cc.task = task; @@ -193,28 +193,27 @@ GNUNET_PROGRAM_run (int argc, char *const *argv, const char *binaryName, setlocale (LC_ALL, ""); path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR); if (path != NULL) - { - BINDTEXTDOMAIN ("GNUnet", path); - GNUNET_free (path); - } + { + BINDTEXTDOMAIN ("GNUnet", path); + GNUNET_free (path); + } textdomain ("GNUnet"); #endif cnt = 0; while (options[cnt].name != NULL) cnt++; allopts = - GNUNET_malloc ((cnt + - 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption) + - sizeof (defoptions)); + GNUNET_malloc ((cnt + + 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption) + + sizeof (defoptions)); memcpy (allopts, defoptions, sizeof (defoptions)); memcpy (&allopts - [sizeof (defoptions) / - sizeof (struct GNUNET_GETOPT_CommandLineOption)], options, - (cnt + 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption)); - cnt += - sizeof (defoptions) / sizeof (struct GNUNET_GETOPT_CommandLineOption); + [sizeof (defoptions) / + sizeof (struct GNUNET_GETOPT_CommandLineOption)], options, + (cnt + 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption)); + cnt += sizeof (defoptions) / sizeof (struct GNUNET_GETOPT_CommandLineOption); qsort (allopts, cnt, sizeof (struct GNUNET_GETOPT_CommandLineOption), - &cmd_sorter); + &cmd_sorter); loglev = NULL; cc.cfgfile = GNUNET_strdup (GNUNET_DEFAULT_USER_CONFIG_FILE); lpfx = GNUNET_strdup (binaryName); @@ -222,31 +221,30 @@ GNUNET_PROGRAM_run (int argc, char *const *argv, const char *binaryName, *spc = '\0'; if ((-1 == (ret = - GNUNET_GETOPT_run (binaryName, allopts, (unsigned int) argc, argv))) - || (GNUNET_OK != GNUNET_log_setup (lpfx, loglev, logfile))) - { - GNUNET_CONFIGURATION_destroy (cfg); - GNUNET_free_non_null (cc.cfgfile); - GNUNET_free_non_null (loglev); - GNUNET_free_non_null (logfile); - GNUNET_free (allopts); - GNUNET_free (lpfx); - return GNUNET_SYSERR; - } + GNUNET_GETOPT_run (binaryName, allopts, (unsigned int) argc, argv))) || + (GNUNET_OK != GNUNET_log_setup (lpfx, loglev, logfile))) + { + GNUNET_CONFIGURATION_destroy (cfg); + GNUNET_free_non_null (cc.cfgfile); + GNUNET_free_non_null (loglev); + GNUNET_free_non_null (logfile); + GNUNET_free (allopts); + GNUNET_free (lpfx); + return GNUNET_SYSERR; + } (void) GNUNET_CONFIGURATION_load (cfg, cc.cfgfile); GNUNET_free (allopts); GNUNET_free (lpfx); if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cc.cfg, "testing", "skew_offset", - &skew_offset) && + &skew_offset) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cc.cfg, "testing", - "skew_variance", - &skew_variance))) - { - clock_offset = skew_offset - skew_variance; - GNUNET_TIME_set_offset (clock_offset); - } + "skew_variance", &skew_variance))) + { + clock_offset = skew_offset - skew_variance; + GNUNET_TIME_set_offset (clock_offset); + } /* run */ cc.args = &argv[ret]; GNUNET_SCHEDULER_run (&program_main, &cc); diff --git a/src/util/pseudonym.c b/src/util/pseudonym.c index b6e51af18..2a736bc46 100644 --- a/src/util/pseudonym.c +++ b/src/util/pseudonym.c @@ -82,16 +82,16 @@ static struct DiscoveryCallback *head; */ static void internal_notify (const GNUNET_HashCode * id, - const struct GNUNET_CONTAINER_MetaData *md, int rating) + const struct GNUNET_CONTAINER_MetaData *md, int rating) { struct DiscoveryCallback *pos; pos = head; while (pos != NULL) - { - pos->callback (pos->closure, id, md, rating); - pos = pos->next; - } + { + pos->callback (pos->closure, id, md, rating); + pos = pos->next; + } } /** @@ -103,10 +103,9 @@ internal_notify (const GNUNET_HashCode * id, */ int GNUNET_PSEUDONYM_discovery_callback_register (const struct - GNUNET_CONFIGURATION_Handle - *cfg, - GNUNET_PSEUDONYM_Iterator - iterator, void *closure) + GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_PSEUDONYM_Iterator + iterator, void *closure) { struct DiscoveryCallback *list; @@ -126,7 +125,7 @@ GNUNET_PSEUDONYM_discovery_callback_register (const struct */ int GNUNET_PSEUDONYM_discovery_callback_unregister (GNUNET_PSEUDONYM_Iterator - iterator, void *closure) + iterator, void *closure) { struct DiscoveryCallback *prev; struct DiscoveryCallback *pos; @@ -134,11 +133,11 @@ GNUNET_PSEUDONYM_discovery_callback_unregister (GNUNET_PSEUDONYM_Iterator prev = NULL; pos = head; while ((pos != NULL) && - ((pos->callback != iterator) || (pos->closure != closure))) - { - prev = pos; - pos = pos->next; - } + ((pos->callback != iterator) || (pos->closure != closure))) + { + prev = pos; + pos = pos->next; + } if (pos == NULL) return GNUNET_SYSERR; if (prev == NULL) @@ -160,17 +159,16 @@ GNUNET_PSEUDONYM_discovery_callback_unregister (GNUNET_PSEUDONYM_Iterator */ static char * get_data_filename (const struct GNUNET_CONFIGURATION_Handle *cfg, - const char *prefix, const GNUNET_HashCode * psid) + const char *prefix, const GNUNET_HashCode * psid) { struct GNUNET_CRYPTO_HashAsciiEncoded enc; if (psid != NULL) GNUNET_CRYPTO_hash_to_enc (psid, &enc); - return GNUNET_DISK_get_home_filename (cfg, GNUNET_CLIENT_SERVICE_NAME, - prefix, - (psid == - NULL) ? NULL : (const char *) &enc, - NULL); + return GNUNET_DISK_get_home_filename (cfg, GNUNET_CLIENT_SERVICE_NAME, prefix, + (psid == + NULL) ? NULL : (const char *) &enc, + NULL); } @@ -184,9 +182,9 @@ get_data_filename (const struct GNUNET_CONFIGURATION_Handle *cfg, */ static void write_pseudonym_info (const struct GNUNET_CONFIGURATION_Handle *cfg, - const GNUNET_HashCode * nsid, - const struct GNUNET_CONTAINER_MetaData *meta, - int32_t ranking, const char *ns_name) + const GNUNET_HashCode * nsid, + const struct GNUNET_CONTAINER_MetaData *meta, + int32_t ranking, const char *ns_name) { char *fn; struct GNUNET_BIO_WriteHandle *fileW; @@ -195,23 +193,23 @@ write_pseudonym_info (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_assert (fn != NULL); fileW = GNUNET_BIO_write_open (fn); if (NULL != fileW) + { + if ((GNUNET_OK != GNUNET_BIO_write_int32 (fileW, ranking)) || + (GNUNET_OK != GNUNET_BIO_write_string (fileW, ns_name)) || + (GNUNET_OK != GNUNET_BIO_write_meta_data (fileW, meta))) { - if ((GNUNET_OK != GNUNET_BIO_write_int32 (fileW, ranking)) || - (GNUNET_OK != GNUNET_BIO_write_string (fileW, ns_name)) || - (GNUNET_OK != GNUNET_BIO_write_meta_data (fileW, meta))) - { - (void) GNUNET_BIO_write_close (fileW); - GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn)); - GNUNET_free (fn); - return; - } - if (GNUNET_OK != GNUNET_BIO_write_close (fileW)) - { - GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn)); - GNUNET_free (fn); - return; - } + (void) GNUNET_BIO_write_close (fileW); + GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn)); + GNUNET_free (fn); + return; } + if (GNUNET_OK != GNUNET_BIO_write_close (fileW)) + { + GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn)); + GNUNET_free (fn); + return; + } + } GNUNET_free (fn); /* create entry for pseudonym name in names */ /* FIXME: 90% of what this call does is not needed @@ -230,9 +228,9 @@ write_pseudonym_info (const struct GNUNET_CONFIGURATION_Handle *cfg, */ static int read_info (const struct GNUNET_CONFIGURATION_Handle *cfg, - const GNUNET_HashCode * nsid, - struct GNUNET_CONTAINER_MetaData **meta, int32_t * ranking, - char **ns_name) + const GNUNET_HashCode * nsid, + struct GNUNET_CONTAINER_MetaData **meta, int32_t * ranking, + char **ns_name) { char *fn; char *emsg; @@ -242,10 +240,10 @@ read_info (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_assert (fn != NULL); fileR = GNUNET_BIO_read_open (fn); if (fileR == NULL) - { - GNUNET_free (fn); - return GNUNET_SYSERR; - } + { + GNUNET_free (fn); + return GNUNET_SYSERR; + } emsg = NULL; *ns_name = NULL; if ((GNUNET_OK != GNUNET_BIO_read_int32 (fileR, ranking)) || @@ -253,30 +251,29 @@ read_info (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_BIO_read_string (fileR, "Read string error!", ns_name, 200)) || (GNUNET_OK != GNUNET_BIO_read_meta_data (fileR, "Read meta data error!", meta))) - { - (void) GNUNET_BIO_read_close (fileR, &emsg); - GNUNET_free_non_null (emsg); - GNUNET_free_non_null (*ns_name); - *ns_name = NULL; - GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn)); - GNUNET_free (fn); - return GNUNET_SYSERR; - } + { + (void) GNUNET_BIO_read_close (fileR, &emsg); + GNUNET_free_non_null (emsg); + GNUNET_free_non_null (*ns_name); + *ns_name = NULL; + GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn)); + GNUNET_free (fn); + return GNUNET_SYSERR; + } if (GNUNET_OK != GNUNET_BIO_read_close (fileR, &emsg)) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - _ - ("Failed to parse metadata about pseudonym from file `%s': %s\n"), - fn, emsg); - GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn)); - GNUNET_CONTAINER_meta_data_destroy (*meta); - *meta = NULL; - GNUNET_free_non_null (*ns_name); - *ns_name = NULL; - GNUNET_free_non_null (emsg); - GNUNET_free (fn); - return GNUNET_SYSERR; - } + { + LOG (GNUNET_ERROR_TYPE_WARNING, + _("Failed to parse metadata about pseudonym from file `%s': %s\n"), fn, + emsg); + GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn)); + GNUNET_CONTAINER_meta_data_destroy (*meta); + *meta = NULL; + GNUNET_free_non_null (*ns_name); + *ns_name = NULL; + GNUNET_free_non_null (emsg); + GNUNET_free (fn); + return GNUNET_SYSERR; + } GNUNET_free (fn); return GNUNET_OK; } @@ -292,7 +289,7 @@ read_info (const struct GNUNET_CONFIGURATION_Handle *cfg, */ char * GNUNET_PSEUDONYM_id_to_name (const struct GNUNET_CONFIGURATION_Handle *cfg, - const GNUNET_HashCode * nsid) + const GNUNET_HashCode * nsid) { struct GNUNET_CONTAINER_MetaData *meta; char *name; @@ -310,25 +307,25 @@ GNUNET_PSEUDONYM_id_to_name (const struct GNUNET_CONFIGURATION_Handle *cfg, meta = NULL; name = NULL; if (GNUNET_OK == read_info (cfg, nsid, &meta, rank, &name)) + { + if ((meta != NULL) && (name == NULL)) + name = + GNUNET_CONTAINER_meta_data_get_first_by_types (meta, + EXTRACTOR_METATYPE_TITLE, + EXTRACTOR_METATYPE_FILENAME, + EXTRACTOR_METATYPE_DESCRIPTION, + EXTRACTOR_METATYPE_SUBJECT, + EXTRACTOR_METATYPE_PUBLISHER, + EXTRACTOR_METATYPE_AUTHOR_NAME, + EXTRACTOR_METATYPE_COMMENT, + EXTRACTOR_METATYPE_SUMMARY, + -1); + if (meta != NULL) { - if ((meta != NULL) && (name == NULL)) - name = - GNUNET_CONTAINER_meta_data_get_first_by_types (meta, - EXTRACTOR_METATYPE_TITLE, - EXTRACTOR_METATYPE_FILENAME, - EXTRACTOR_METATYPE_DESCRIPTION, - EXTRACTOR_METATYPE_SUBJECT, - EXTRACTOR_METATYPE_PUBLISHER, - EXTRACTOR_METATYPE_AUTHOR_NAME, - EXTRACTOR_METATYPE_COMMENT, - EXTRACTOR_METATYPE_SUMMARY, - -1); - if (meta != NULL) - { - GNUNET_CONTAINER_meta_data_destroy (meta); - meta = NULL; - } + GNUNET_CONTAINER_meta_data_destroy (meta); + meta = NULL; } + } if (name == NULL) name = GNUNET_strdup (_("no-name")); GNUNET_CRYPTO_hash (name, strlen (name), &nh); @@ -339,31 +336,31 @@ GNUNET_PSEUDONYM_id_to_name (const struct GNUNET_CONFIGURATION_Handle *cfg, if (0 == STAT (fn, &sbuf)) GNUNET_DISK_file_size (fn, &len, GNUNET_YES); fh = GNUNET_DISK_file_open (fn, - GNUNET_DISK_OPEN_CREATE | - GNUNET_DISK_OPEN_READWRITE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE); + GNUNET_DISK_OPEN_CREATE | + GNUNET_DISK_OPEN_READWRITE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE); i = 0; idx = -1; while ((len >= sizeof (GNUNET_HashCode)) && - (sizeof (GNUNET_HashCode) == - GNUNET_DISK_file_read (fh, &nh, sizeof (GNUNET_HashCode)))) - { - if (0 == memcmp (&nh, nsid, sizeof (GNUNET_HashCode))) - { - idx = i; - break; - } - i++; - len -= sizeof (GNUNET_HashCode); - } - if (idx == -1) + (sizeof (GNUNET_HashCode) == + GNUNET_DISK_file_read (fh, &nh, sizeof (GNUNET_HashCode)))) + { + if (0 == memcmp (&nh, nsid, sizeof (GNUNET_HashCode))) { idx = i; - if (sizeof (GNUNET_HashCode) != - GNUNET_DISK_file_write (fh, nsid, sizeof (GNUNET_HashCode))) - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "write", fn); + break; } + i++; + len -= sizeof (GNUNET_HashCode); + } + if (idx == -1) + { + idx = i; + if (sizeof (GNUNET_HashCode) != + GNUNET_DISK_file_write (fh, nsid, sizeof (GNUNET_HashCode))) + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "write", fn); + } GNUNET_DISK_file_close (fh); ret = GNUNET_malloc (strlen (name) + 32); GNUNET_snprintf (ret, strlen (name) + 32, "%s-%u", name, idx); @@ -382,7 +379,7 @@ GNUNET_PSEUDONYM_id_to_name (const struct GNUNET_CONFIGURATION_Handle *cfg, */ int GNUNET_PSEUDONYM_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg, - const char *ns_uname, GNUNET_HashCode * nsid) + const char *ns_uname, GNUNET_HashCode * nsid) { size_t slen; uint64_t len; @@ -408,24 +405,24 @@ GNUNET_PSEUDONYM_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg, if ((GNUNET_OK != GNUNET_DISK_file_test (fn) || (GNUNET_OK != GNUNET_DISK_file_size (fn, &len, GNUNET_YES))) || ((idx + 1) * sizeof (GNUNET_HashCode) > len)) - { - GNUNET_free (fn); - return GNUNET_SYSERR; - } + { + GNUNET_free (fn); + return GNUNET_SYSERR; + } fh = GNUNET_DISK_file_open (fn, - GNUNET_DISK_OPEN_CREATE | - GNUNET_DISK_OPEN_READWRITE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE); + GNUNET_DISK_OPEN_CREATE | + GNUNET_DISK_OPEN_READWRITE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE); GNUNET_free (fn); GNUNET_DISK_file_seek (fh, idx * sizeof (GNUNET_HashCode), - GNUNET_DISK_SEEK_SET); + GNUNET_DISK_SEEK_SET); if (sizeof (GNUNET_HashCode) != GNUNET_DISK_file_read (fh, nsid, sizeof (GNUNET_HashCode))) - { - GNUNET_DISK_file_close (fh); - return GNUNET_SYSERR; - } + { + GNUNET_DISK_file_close (fh); + return GNUNET_SYSERR; + } GNUNET_DISK_file_close (fh); return GNUNET_OK; } @@ -475,15 +472,15 @@ list_pseudonym_helper (void *cls, const char *fullname) if (strlen (fullname) < sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) return GNUNET_OK; fn = &fullname[strlen (fullname) + 1 - - sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]; + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]; if (fn[-1] != DIR_SEPARATOR) return GNUNET_OK; ret = GNUNET_OK; if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (fn, &id)) - return GNUNET_OK; /* invalid name */ + return GNUNET_OK; /* invalid name */ str = NULL; if (GNUNET_OK != read_info (c->cfg, &id, &meta, &rating, &str)) - return GNUNET_OK; /* ignore entry */ + return GNUNET_OK; /* ignore entry */ GNUNET_free_non_null (str); if (c->iterator != NULL) ret = c->iterator (c->closure, &id, meta, rating); @@ -502,7 +499,7 @@ list_pseudonym_helper (void *cls, const char *fullname) */ int GNUNET_PSEUDONYM_list_all (const struct GNUNET_CONFIGURATION_Handle *cfg, - GNUNET_PSEUDONYM_Iterator iterator, void *closure) + GNUNET_PSEUDONYM_Iterator iterator, void *closure) { struct ListPseudonymClosure cls; char *fn; @@ -531,7 +528,7 @@ GNUNET_PSEUDONYM_list_all (const struct GNUNET_CONFIGURATION_Handle *cfg, */ int GNUNET_PSEUDONYM_rank (const struct GNUNET_CONFIGURATION_Handle *cfg, - const GNUNET_HashCode * nsid, int delta) + const GNUNET_HashCode * nsid, int delta) { struct GNUNET_CONTAINER_MetaData *meta; int ret; @@ -541,10 +538,10 @@ GNUNET_PSEUDONYM_rank (const struct GNUNET_CONFIGURATION_Handle *cfg, name = NULL; ret = read_info (cfg, nsid, &meta, &ranking, &name); if (ret == GNUNET_SYSERR) - { - ranking = 0; - meta = GNUNET_CONTAINER_meta_data_create (); - } + { + ranking = 0; + meta = GNUNET_CONTAINER_meta_data_create (); + } ranking += delta; write_pseudonym_info (cfg, nsid, meta, ranking, name); GNUNET_CONTAINER_meta_data_destroy (meta); @@ -564,8 +561,8 @@ GNUNET_PSEUDONYM_rank (const struct GNUNET_CONFIGURATION_Handle *cfg, */ void GNUNET_PSEUDONYM_add (const struct GNUNET_CONFIGURATION_Handle *cfg, - const GNUNET_HashCode * id, - const struct GNUNET_CONTAINER_MetaData *meta) + const GNUNET_HashCode * id, + const struct GNUNET_CONTAINER_MetaData *meta) { char *name; int32_t ranking; @@ -579,16 +576,16 @@ GNUNET_PSEUDONYM_add (const struct GNUNET_CONFIGURATION_Handle *cfg, if ((0 == STAT (fn, &sbuf)) && (GNUNET_OK == read_info (cfg, id, &old, &ranking, &name))) - { - GNUNET_CONTAINER_meta_data_merge (old, meta); - write_pseudonym_info (cfg, id, old, ranking, name); - GNUNET_CONTAINER_meta_data_destroy (old); - GNUNET_free_non_null (name); - } + { + GNUNET_CONTAINER_meta_data_merge (old, meta); + write_pseudonym_info (cfg, id, old, ranking, name); + GNUNET_CONTAINER_meta_data_destroy (old); + GNUNET_free_non_null (name); + } else - { - write_pseudonym_info (cfg, id, meta, ranking, NULL); - } + { + write_pseudonym_info (cfg, id, meta, ranking, NULL); + } GNUNET_free (fn); internal_notify (id, meta, ranking); } diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c index 3bdc40143..03dc2ce89 100644 --- a/src/util/resolver_api.c +++ b/src/util/resolver_api.c @@ -196,26 +196,26 @@ check_config () #endif if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (resolver_cfg, "resolver", - "HOSTNAME", &hostname)) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Must specify `%s' for `%s' in configuration!\n"), "HOSTNAME", - "resolver"); - GNUNET_assert (0); - } + "HOSTNAME", &hostname)) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Must specify `%s' for `%s' in configuration!\n"), "HOSTNAME", + "resolver"); + GNUNET_assert (0); + } if ((1 != inet_pton (AF_INET, hostname, &v4)) || (1 != inet_pton (AF_INET6, hostname, &v6))) + { + GNUNET_free (hostname); + return; + } + i = 0; + while (loopback[i] != NULL) + if (0 == strcasecmp (loopback[i++], hostname)) { GNUNET_free (hostname); return; } - i = 0; - while (loopback[i] != NULL) - if (0 == strcasecmp (loopback[i++], hostname)) - { - GNUNET_free (hostname); - return; - } LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Must specify `%s' or numeric IP address for `%s' of `%s' in configuration!\n"), @@ -249,23 +249,23 @@ GNUNET_RESOLVER_disconnect () GNUNET_assert (NULL == req_head); GNUNET_assert (NULL == req_tail); if (NULL != client) - { + { #if DEBUG_RESOLVER - LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from DNS service\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from DNS service\n"); #endif - GNUNET_CLIENT_disconnect (client, GNUNET_NO); - client = NULL; - } + GNUNET_CLIENT_disconnect (client, GNUNET_NO); + client = NULL; + } if (r_task != GNUNET_SCHEDULER_NO_TASK) - { - GNUNET_SCHEDULER_cancel (r_task); - r_task = GNUNET_SCHEDULER_NO_TASK; - } + { + GNUNET_SCHEDULER_cancel (r_task); + r_task = GNUNET_SCHEDULER_NO_TASK; + } if (s_task != GNUNET_SCHEDULER_NO_TASK) - { - GNUNET_SCHEDULER_cancel (s_task); - s_task = GNUNET_SCHEDULER_NO_TASK; - } + { + GNUNET_SCHEDULER_cancel (s_task); + s_task = GNUNET_SCHEDULER_NO_TASK; + } } @@ -286,35 +286,35 @@ no_resolve (const struct sockaddr *sa, socklen_t salen) if (salen < sizeof (struct sockaddr)) return NULL; switch (sa->sa_family) + { + case AF_INET: + if (salen != sizeof (struct sockaddr_in)) + return NULL; + if (NULL == + inet_ntop (AF_INET, &((struct sockaddr_in *) sa)->sin_addr, inet4, + INET_ADDRSTRLEN)) { - case AF_INET: - if (salen != sizeof (struct sockaddr_in)) - return NULL; - if (NULL == - inet_ntop (AF_INET, &((struct sockaddr_in *) sa)->sin_addr, inet4, - INET_ADDRSTRLEN)) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); - return NULL; - } - ret = GNUNET_strdup (inet4); - break; - case AF_INET6: - if (salen != sizeof (struct sockaddr_in6)) - return NULL; - if (NULL == - inet_ntop (AF_INET6, &((struct sockaddr_in6 *) sa)->sin6_addr, - inet6, INET6_ADDRSTRLEN)) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); - return NULL; - } - ret = GNUNET_strdup (inet6); - break; - default: - ret = NULL; - break; + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); + return NULL; } + ret = GNUNET_strdup (inet4); + break; + case AF_INET6: + if (salen != sizeof (struct sockaddr_in6)) + return NULL; + if (NULL == + inet_ntop (AF_INET6, &((struct sockaddr_in6 *) sa)->sin6_addr, inet6, + INET6_ADDRSTRLEN)) + { + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); + return NULL; + } + ret = GNUNET_strdup (inet6); + break; + default: + ret = NULL; + break; + } return ret; } @@ -322,13 +322,15 @@ no_resolve (const struct sockaddr *sa, socklen_t salen) /** * Adjust exponential back-off and reconnect to the service. */ -static void reconnect (); +static void +reconnect (); /** * Process pending requests to the resolver. */ -static void process_requests (); +static void +process_requests (); /** @@ -350,122 +352,120 @@ handle_response (void *cls, const struct GNUNET_MessageHeader *msg) LOG (GNUNET_ERROR_TYPE_DEBUG, "Receiving response from DNS service\n"); #endif if (msg == NULL) + { + if (NULL != rh->name_callback) + LOG (GNUNET_ERROR_TYPE_INFO, + _("Timeout trying to resolve IP address `%s'.\n"), + GNUNET_a2s ((const void *) &rh[1], rh->data_len)); + else + LOG (GNUNET_ERROR_TYPE_INFO, + _("Timeout trying to resolve hostname `%s'.\n"), + (const char *) &rh[1]); + /* check if request was canceled */ + if (rh->was_transmitted != GNUNET_SYSERR) { if (NULL != rh->name_callback) - LOG (GNUNET_ERROR_TYPE_INFO, - _("Timeout trying to resolve IP address `%s'.\n"), - GNUNET_a2s ((const void *) &rh[1], rh->data_len)); - else - LOG (GNUNET_ERROR_TYPE_INFO, - _("Timeout trying to resolve hostname `%s'.\n"), - (const char *) &rh[1]); - /* check if request was canceled */ - if (rh->was_transmitted != GNUNET_SYSERR) - { - if (NULL != rh->name_callback) - { - /* no reverse lookup was successful, return ip as string */ - if (rh->received_response == GNUNET_NO) - rh->name_callback (rh->cls, - no_resolve ((const struct sockaddr *) - &rh[1], rh->data_len)); - /* at least one reverse lookup was successful */ - else - rh->name_callback (rh->cls, NULL); - } - if (NULL != rh->addr_callback) - rh->addr_callback (rh->cls, NULL, 0); - } - GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); - GNUNET_free (rh); - GNUNET_CLIENT_disconnect (client, GNUNET_NO); - client = NULL; - reconnect (); - return; + { + /* no reverse lookup was successful, return ip as string */ + if (rh->received_response == GNUNET_NO) + rh->name_callback (rh->cls, + no_resolve ((const struct sockaddr *) &rh[1], + rh->data_len)); + /* at least one reverse lookup was successful */ + else + rh->name_callback (rh->cls, NULL); + } + if (NULL != rh->addr_callback) + rh->addr_callback (rh->cls, NULL, 0); } + GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); + GNUNET_free (rh); + GNUNET_CLIENT_disconnect (client, GNUNET_NO); + client = NULL; + reconnect (); + return; + } if (GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE != ntohs (msg->type)) - { - GNUNET_break (0); - GNUNET_CLIENT_disconnect (client, GNUNET_NO); - client = NULL; - reconnect (); - return; - } + { + GNUNET_break (0); + GNUNET_CLIENT_disconnect (client, GNUNET_NO); + client = NULL; + reconnect (); + return; + } size = ntohs (msg->size); /* message contains not data, just header */ if (size == sizeof (struct GNUNET_MessageHeader)) + { + /* check if request was canceled */ + if (rh->was_transmitted != GNUNET_SYSERR) + { + if (NULL != rh->name_callback) + rh->name_callback (rh->cls, NULL); + if (NULL != rh->addr_callback) + rh->addr_callback (rh->cls, NULL, 0); + } + GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); + GNUNET_free (rh); + process_requests (); + return; + } + /* return reverse lookup results to caller */ + if (NULL != rh->name_callback) + { + hostname = (const char *) &msg[1]; + if (hostname[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0') { - /* check if request was canceled */ + GNUNET_break (0); if (rh->was_transmitted != GNUNET_SYSERR) - { - if (NULL != rh->name_callback) - rh->name_callback (rh->cls, NULL); - if (NULL != rh->addr_callback) - rh->addr_callback (rh->cls, NULL, 0); - } + rh->name_callback (rh->cls, NULL); GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); GNUNET_free (rh); - process_requests (); + GNUNET_CLIENT_disconnect (client, GNUNET_NO); + client = NULL; + reconnect (); return; } - /* return reverse lookup results to caller */ - if (NULL != rh->name_callback) - { - hostname = (const char *) &msg[1]; - if (hostname[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0') - { - GNUNET_break (0); - if (rh->was_transmitted != GNUNET_SYSERR) - rh->name_callback (rh->cls, NULL); - GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); - GNUNET_free (rh); - GNUNET_CLIENT_disconnect (client, GNUNET_NO); - client = NULL; - reconnect (); - return; - } #if DEBUG_RESOLVER - LOG (GNUNET_ERROR_TYPE_DEBUG, _("Resolver returns `%s' for IP `%s'.\n"), - hostname, GNUNET_a2s ((const void *) &rh[1], rh->data_len)); + LOG (GNUNET_ERROR_TYPE_DEBUG, _("Resolver returns `%s' for IP `%s'.\n"), + hostname, GNUNET_a2s ((const void *) &rh[1], rh->data_len)); #endif - if (rh->was_transmitted != GNUNET_SYSERR) - rh->name_callback (rh->cls, hostname); - rh->received_response = GNUNET_YES; - GNUNET_CLIENT_receive (client, &handle_response, rh, - GNUNET_TIME_absolute_get_remaining - (rh->timeout)); - } + if (rh->was_transmitted != GNUNET_SYSERR) + rh->name_callback (rh->cls, hostname); + rh->received_response = GNUNET_YES; + GNUNET_CLIENT_receive (client, &handle_response, rh, + GNUNET_TIME_absolute_get_remaining (rh->timeout)); + } /* return lookup results to caller */ if (NULL != rh->addr_callback) + { + sa = (const struct sockaddr *) &msg[1]; + salen = size - sizeof (struct GNUNET_MessageHeader); + if (salen < sizeof (struct sockaddr)) { - sa = (const struct sockaddr *) &msg[1]; - salen = size - sizeof (struct GNUNET_MessageHeader); - if (salen < sizeof (struct sockaddr)) - { - GNUNET_break (0); - if (rh->was_transmitted != GNUNET_SYSERR) - rh->addr_callback (rh->cls, NULL, 0); - GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); - GNUNET_free (rh); - GNUNET_CLIENT_disconnect (client, GNUNET_NO); - client = NULL; - reconnect (); - return; - } + GNUNET_break (0); + if (rh->was_transmitted != GNUNET_SYSERR) + rh->addr_callback (rh->cls, NULL, 0); + GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); + GNUNET_free (rh); + GNUNET_CLIENT_disconnect (client, GNUNET_NO); + client = NULL; + reconnect (); + return; + } #if DEBUG_RESOLVER - { - char *ips = no_resolve (sa, salen); + { + char *ips = no_resolve (sa, salen); - LOG (GNUNET_ERROR_TYPE_DEBUG, "Resolver returns `%s' for `%s'.\n", - ips, (const char *) &rh[1]); - GNUNET_free (ips); - } -#endif - rh->addr_callback (rh->cls, sa, salen); - GNUNET_CLIENT_receive (client, &handle_response, rh, - GNUNET_TIME_absolute_get_remaining - (rh->timeout)); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Resolver returns `%s' for `%s'.\n", ips, + (const char *) &rh[1]); + GNUNET_free (ips); } +#endif + rh->addr_callback (rh->cls, sa, salen); + GNUNET_CLIENT_receive (client, &handle_response, rh, + GNUNET_TIME_absolute_get_remaining (rh->timeout)); + } } @@ -498,27 +498,26 @@ numeric_resolution (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) hostname = (const char *) &rh[1]; if (((rh->domain == AF_UNSPEC) || (rh->domain == AF_INET)) && (1 == inet_pton (AF_INET, hostname, &v4.sin_addr))) + { + rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4)); + if ((rh->domain == AF_UNSPEC) && + (1 == inet_pton (AF_INET6, hostname, &v6.sin6_addr))) { - rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4)); - if ((rh->domain == AF_UNSPEC) && - (1 == inet_pton (AF_INET6, hostname, &v6.sin6_addr))) - { - /* this can happen on some systems IF "hostname" is "localhost" */ - rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, - sizeof (v6)); - } - rh->addr_callback (rh->cls, NULL, 0); - GNUNET_free (rh); - return; + /* this can happen on some systems IF "hostname" is "localhost" */ + rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6)); } + rh->addr_callback (rh->cls, NULL, 0); + GNUNET_free (rh); + return; + } if (((rh->domain == AF_UNSPEC) || (rh->domain == AF_INET6)) && (1 == inet_pton (AF_INET6, hostname, &v6.sin6_addr))) - { - rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6)); - rh->addr_callback (rh->cls, NULL, 0); - GNUNET_free (rh); - return; - } + { + rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6)); + rh->addr_callback (rh->cls, NULL, 0); + GNUNET_free (rh); + return; + } /* why are we here? this task should not have been scheduled! */ GNUNET_assert (0); GNUNET_free (rh); @@ -553,21 +552,21 @@ loopback_resolution (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) #endif v6.sin6_addr = in6addr_loopback; switch (rh->domain) - { - case AF_INET: - rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4)); - break; - case AF_INET6: - rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6)); - break; - case AF_UNSPEC: - rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6)); - rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4)); - break; - default: - GNUNET_break (0); - break; - } + { + case AF_INET: + rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4)); + break; + case AF_INET6: + rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6)); + break; + case AF_UNSPEC: + rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6)); + rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4)); + break; + default: + GNUNET_break (0); + break; + } rh->addr_callback (rh->cls, NULL, 0); GNUNET_free (rh); } @@ -595,25 +594,25 @@ process_requests () struct GNUNET_RESOLVER_RequestHandle *rh; if (NULL == client) - { - reconnect (); - return; - } + { + reconnect (); + return; + } rh = req_head; if (NULL == rh) - { - /* nothing to do, release socket really soon if there is nothing - * else happening... */ - s_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, - &shutdown_task, NULL); - return; - } + { + /* nothing to do, release socket really soon if there is nothing + * else happening... */ + s_task = + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, + &shutdown_task, NULL); + return; + } if (GNUNET_YES == rh->was_transmitted) - return; /* waiting for reply */ + return; /* waiting for reply */ msg = (struct GNUNET_RESOLVER_GetMessage *) buf; msg->header.size = - htons (sizeof (struct GNUNET_RESOLVER_GetMessage) + rh->data_len); + htons (sizeof (struct GNUNET_RESOLVER_GetMessage) + rh->data_len); msg->header.type = htons (GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST); msg->direction = htonl (rh->direction); msg->domain = htonl (rh->domain); @@ -624,15 +623,15 @@ process_requests () #endif if (GNUNET_OK != GNUNET_CLIENT_transmit_and_get_response (client, &msg->header, - GNUNET_TIME_absolute_get_remaining - (rh->timeout), GNUNET_YES, - &handle_response, rh)) - { - GNUNET_CLIENT_disconnect (client, GNUNET_NO); - client = NULL; - reconnect (); - return; - } + GNUNET_TIME_absolute_get_remaining + (rh->timeout), GNUNET_YES, + &handle_response, rh)) + { + GNUNET_CLIENT_disconnect (client, GNUNET_NO); + client = NULL; + reconnect (); + return; + } rh->was_transmitted = GNUNET_YES; } @@ -648,7 +647,7 @@ reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { r_task = GNUNET_SCHEDULER_NO_TASK; if (NULL == req_head) - return; /* no work pending */ + return; /* no work pending */ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) return; #if DEBUG_RESOLVER @@ -656,12 +655,11 @@ reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) #endif client = GNUNET_CLIENT_connect ("resolver", resolver_cfg); if (NULL == client) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Failed to connect, will try again later\n"); - reconnect (); - return; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect, will try again later\n"); + reconnect (); + return; + } process_requests (); } @@ -678,26 +676,26 @@ reconnect () return; GNUNET_assert (NULL == client); if (NULL != (rh = req_head)) + { + switch (rh->was_transmitted) { - switch (rh->was_transmitted) - { - case GNUNET_NO: - /* nothing more to do */ - break; - case GNUNET_YES: - /* disconnected, transmit again! */ - rh->was_transmitted = GNUNET_NO; - break; - case GNUNET_SYSERR: - /* request was cancelled, remove entirely */ - GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); - GNUNET_free (rh); - break; - default: - GNUNET_assert (0); - break; - } + case GNUNET_NO: + /* nothing more to do */ + break; + case GNUNET_YES: + /* disconnected, transmit again! */ + rh->was_transmitted = GNUNET_NO; + break; + case GNUNET_SYSERR: + /* request was cancelled, remove entirely */ + GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); + GNUNET_free (rh); + break; + default: + GNUNET_assert (0); + break; } + } #if DEBUG_RESOLVER LOG (GNUNET_ERROR_TYPE_DEBUG, "Will try to connect to DNS service in %llu ms\n", @@ -721,9 +719,9 @@ reconnect () */ struct GNUNET_RESOLVER_RequestHandle * GNUNET_RESOLVER_ip_get (const char *hostname, int domain, - struct GNUNET_TIME_Relative timeout, - GNUNET_RESOLVER_AddressCallback callback, - void *callback_cls) + struct GNUNET_TIME_Relative timeout, + GNUNET_RESOLVER_AddressCallback callback, + void *callback_cls) { struct GNUNET_RESOLVER_RequestHandle *rh; size_t slen; @@ -734,10 +732,10 @@ GNUNET_RESOLVER_ip_get (const char *hostname, int domain, slen = strlen (hostname) + 1; if (slen + sizeof (struct GNUNET_RESOLVER_GetMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) - { - GNUNET_break (0); - return NULL; - } + { + GNUNET_break (0); + return NULL; + } rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + slen); rh->domain = domain; rh->addr_callback = callback; @@ -751,25 +749,25 @@ GNUNET_RESOLVER_ip_get (const char *hostname, int domain, ((domain == AF_INET) || (domain == AF_UNSPEC))) || ((1 == inet_pton (AF_INET6, hostname, &v6)) && ((domain == AF_INET6) || (domain == AF_UNSPEC)))) - { - rh->task = GNUNET_SCHEDULER_add_now (&numeric_resolution, rh); - return rh; - } + { + rh->task = GNUNET_SCHEDULER_add_now (&numeric_resolution, rh); + return rh; + } /* then, check if this is a loopback address */ i = 0; while (loopback[i] != NULL) if (0 == strcasecmp (loopback[i++], hostname)) - { - rh->task = GNUNET_SCHEDULER_add_now (&loopback_resolution, rh); - return rh; - } + { + rh->task = GNUNET_SCHEDULER_add_now (&loopback_resolution, rh); + return rh; + } GNUNET_CONTAINER_DLL_insert_tail (req_head, req_tail, rh); rh->was_queued = GNUNET_YES; if (s_task != GNUNET_SCHEDULER_NO_TASK) - { - GNUNET_SCHEDULER_cancel (s_task); - s_task = GNUNET_SCHEDULER_NO_TASK; - } + { + GNUNET_SCHEDULER_cancel (s_task); + s_task = GNUNET_SCHEDULER_NO_TASK; + } process_requests (); return rh; } @@ -793,10 +791,10 @@ numeric_reverse (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) LOG (GNUNET_ERROR_TYPE_DEBUG, _("Resolver returns `%s'.\n"), result); #endif if (result != NULL) - { - rh->name_callback (rh->cls, result); - GNUNET_free (result); - } + { + rh->name_callback (rh->cls, result); + GNUNET_free (result); + } rh->name_callback (rh->cls, NULL); GNUNET_free (rh); } @@ -816,10 +814,10 @@ numeric_reverse (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) */ struct GNUNET_RESOLVER_RequestHandle * GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa, socklen_t salen, - int do_resolve, - struct GNUNET_TIME_Relative timeout, - GNUNET_RESOLVER_HostnameCallback callback, - void *cls) + int do_resolve, + struct GNUNET_TIME_Relative timeout, + GNUNET_RESOLVER_HostnameCallback callback, + void *cls) { struct GNUNET_RESOLVER_RequestHandle *rh; @@ -833,24 +831,24 @@ GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa, socklen_t salen, rh->direction = GNUNET_YES; rh->received_response = GNUNET_NO; if (GNUNET_NO == do_resolve) - { - rh->task = GNUNET_SCHEDULER_add_now (&numeric_reverse, rh); - return rh; - } + { + rh->task = GNUNET_SCHEDULER_add_now (&numeric_reverse, rh); + return rh; + } if (salen + sizeof (struct GNUNET_RESOLVER_GetMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) - { - GNUNET_break (0); - GNUNET_free (rh); - return NULL; - } + { + GNUNET_break (0); + GNUNET_free (rh); + return NULL; + } GNUNET_CONTAINER_DLL_insert_tail (req_head, req_tail, rh); rh->was_queued = GNUNET_YES; if (s_task != GNUNET_SCHEDULER_NO_TASK) - { - GNUNET_SCHEDULER_cancel (s_task); - s_task = GNUNET_SCHEDULER_NO_TASK; - } + { + GNUNET_SCHEDULER_cancel (s_task); + s_task = GNUNET_SCHEDULER_NO_TASK; + } process_requests (); return rh; } @@ -868,21 +866,21 @@ GNUNET_RESOLVER_local_fqdn_get () char hostname[GNUNET_OS_get_hostname_max_length () + 1]; if (0 != gethostname (hostname, sizeof (hostname) - 1)) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "gethostname"); - return NULL; - } + { + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "gethostname"); + return NULL; + } #if DEBUG_RESOLVER LOG (GNUNET_ERROR_TYPE_DEBUG, _("Resolving our FQDN `%s'\n"), hostname); #endif host = gethostbyname (hostname); if (NULL == host) - { - LOG (GNUNET_ERROR_TYPE_ERROR, _("Could not resolve our FQDN : %s\n"), - hstrerror (h_errno)); - return NULL; - } + { + LOG (GNUNET_ERROR_TYPE_ERROR, _("Could not resolve our FQDN : %s\n"), + hstrerror (h_errno)); + return NULL; + } return GNUNET_strdup (host->h_name); } @@ -898,18 +896,18 @@ GNUNET_RESOLVER_local_fqdn_get () */ struct GNUNET_RESOLVER_RequestHandle * GNUNET_RESOLVER_hostname_resolve (int domain, - struct GNUNET_TIME_Relative timeout, - GNUNET_RESOLVER_AddressCallback callback, - void *cls) + struct GNUNET_TIME_Relative timeout, + GNUNET_RESOLVER_AddressCallback callback, + void *cls) { char hostname[GNUNET_OS_get_hostname_max_length () + 1]; if (0 != gethostname (hostname, sizeof (hostname) - 1)) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "gethostname"); - return NULL; - } + { + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "gethostname"); + return NULL; + } #if DEBUG_RESOLVER LOG (GNUNET_ERROR_TYPE_DEBUG, _("Resolving our hostname `%s'\n"), hostname); #endif @@ -929,19 +927,19 @@ void GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *rh) { if (rh->task != GNUNET_SCHEDULER_NO_TASK) - { - GNUNET_SCHEDULER_cancel (rh->task); - rh->task = GNUNET_SCHEDULER_NO_TASK; - } + { + GNUNET_SCHEDULER_cancel (rh->task); + rh->task = GNUNET_SCHEDULER_NO_TASK; + } if (rh->was_transmitted == GNUNET_NO) - { - if (rh->was_queued == GNUNET_YES) - GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); - GNUNET_free (rh); - return; - } + { + if (rh->was_queued == GNUNET_YES) + GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); + GNUNET_free (rh); + return; + } GNUNET_assert (rh->was_transmitted == GNUNET_YES); - rh->was_transmitted = GNUNET_SYSERR; /* mark as cancelled */ + rh->was_transmitted = GNUNET_SYSERR; /* mark as cancelled */ } diff --git a/src/util/scheduler.c b/src/util/scheduler.c index 7c5077fab..0c4374471 100644 --- a/src/util/scheduler.c +++ b/src/util/scheduler.c @@ -269,7 +269,7 @@ static void *scheduler_select_cls; */ void GNUNET_SCHEDULER_set_select (GNUNET_SCHEDULER_select new_select, - void *new_select_cls) + void *new_select_cls) { scheduler_select = new_select; scheduler_select_cls = new_select_cls; @@ -288,7 +288,7 @@ check_priority (enum GNUNET_SCHEDULER_Priority p) if ((p >= 0) && (p < GNUNET_SCHEDULER_PRIORITY_COUNT)) return p; GNUNET_assert (0); - return 0; /* make compiler happy */ + return 0; /* make compiler happy */ } @@ -310,37 +310,37 @@ is_pending (GNUNET_SCHEDULER_TaskIdentifier id) if (id < lowest_pending_id) return GNUNET_NO; - min = -1; /* maximum value */ + min = -1; /* maximum value */ pos = pending; while (pos != NULL) - { - if (pos->id == id) - return GNUNET_YES; - if (pos->id < min) - min = pos->id; - pos = pos->next; - } + { + if (pos->id == id) + return GNUNET_YES; + if (pos->id < min) + min = pos->id; + pos = pos->next; + } pos = pending_timeout; while (pos != NULL) + { + if (pos->id == id) + return GNUNET_YES; + if (pos->id < min) + min = pos->id; + pos = pos->next; + } + for (p = 0; p < GNUNET_SCHEDULER_PRIORITY_COUNT; p++) + { + pos = ready[p]; + while (pos != NULL) { if (pos->id == id) - return GNUNET_YES; + return GNUNET_YES; if (pos->id < min) - min = pos->id; + min = pos->id; pos = pos->next; } - for (p = 0; p < GNUNET_SCHEDULER_PRIORITY_COUNT; p++) - { - pos = ready[p]; - while (pos != NULL) - { - if (pos->id == id) - return GNUNET_YES; - if (pos->id < min) - min = pos->id; - pos = pos->next; - } - } + } lowest_pending_id = min; return GNUNET_NO; } @@ -355,7 +355,7 @@ is_pending (GNUNET_SCHEDULER_TaskIdentifier id) */ static void update_sets (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws, - struct GNUNET_TIME_Relative *timeout) + struct GNUNET_TIME_Relative *timeout) { struct Task *pos; struct GNUNET_TIME_Absolute now; @@ -364,40 +364,40 @@ update_sets (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws, now = GNUNET_TIME_absolute_get (); pos = pending_timeout; if (pos != NULL) - { - to = GNUNET_TIME_absolute_get_difference (now, pos->timeout); - if (timeout->rel_value > to.rel_value) - *timeout = to; - if (pos->reason != 0) - *timeout = GNUNET_TIME_UNIT_ZERO; - } + { + to = GNUNET_TIME_absolute_get_difference (now, pos->timeout); + if (timeout->rel_value > to.rel_value) + *timeout = to; + if (pos->reason != 0) + *timeout = GNUNET_TIME_UNIT_ZERO; + } pos = pending; while (pos != NULL) + { + if ((pos->prereq_id != GNUNET_SCHEDULER_NO_TASK) && + (GNUNET_YES == is_pending (pos->prereq_id))) { - if ((pos->prereq_id != GNUNET_SCHEDULER_NO_TASK) && - (GNUNET_YES == is_pending (pos->prereq_id))) - { - pos = pos->next; - continue; - } - if (pos->timeout.abs_value != GNUNET_TIME_UNIT_FOREVER_ABS.abs_value) - { - to = GNUNET_TIME_absolute_get_difference (now, pos->timeout); - if (timeout->rel_value > to.rel_value) - *timeout = to; - } - if (pos->read_fd != -1) - GNUNET_NETWORK_fdset_set_native (rs, pos->read_fd); - if (pos->write_fd != -1) - GNUNET_NETWORK_fdset_set_native (ws, pos->write_fd); - if (pos->read_set != NULL) - GNUNET_NETWORK_fdset_add (rs, pos->read_set); - if (pos->write_set != NULL) - GNUNET_NETWORK_fdset_add (ws, pos->write_set); - if (pos->reason != 0) - *timeout = GNUNET_TIME_UNIT_ZERO; pos = pos->next; + continue; + } + if (pos->timeout.abs_value != GNUNET_TIME_UNIT_FOREVER_ABS.abs_value) + { + to = GNUNET_TIME_absolute_get_difference (now, pos->timeout); + if (timeout->rel_value > to.rel_value) + *timeout = to; } + if (pos->read_fd != -1) + GNUNET_NETWORK_fdset_set_native (rs, pos->read_fd); + if (pos->write_fd != -1) + GNUNET_NETWORK_fdset_set_native (ws, pos->write_fd); + if (pos->read_set != NULL) + GNUNET_NETWORK_fdset_add (rs, pos->read_set); + if (pos->write_set != NULL) + GNUNET_NETWORK_fdset_add (ws, pos->write_set); + if (pos->reason != 0) + *timeout = GNUNET_TIME_UNIT_ZERO; + pos = pos->next; + } } @@ -412,17 +412,17 @@ update_sets (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws, */ static int set_overlaps (const struct GNUNET_NETWORK_FDSet *ready, - struct GNUNET_NETWORK_FDSet *want) + struct GNUNET_NETWORK_FDSet *want) { if ((NULL == want) || (NULL == ready)) return GNUNET_NO; if (GNUNET_NETWORK_fdset_overlap (ready, want)) - { - /* copy all over (yes, there maybe unrelated bits, - * but this should not hurt well-written clients) */ - GNUNET_NETWORK_fdset_copy (want, ready); - return GNUNET_YES; - } + { + /* copy all over (yes, there maybe unrelated bits, + * but this should not hurt well-written clients) */ + GNUNET_NETWORK_fdset_copy (want, ready); + return GNUNET_YES; + } return GNUNET_NO; } @@ -439,8 +439,8 @@ set_overlaps (const struct GNUNET_NETWORK_FDSet *ready, */ static int is_ready (struct Task *task, struct GNUNET_TIME_Absolute now, - const struct GNUNET_NETWORK_FDSet *rs, - const struct GNUNET_NETWORK_FDSet *ws) + const struct GNUNET_NETWORK_FDSet *rs, + const struct GNUNET_NETWORK_FDSet *ws) { enum GNUNET_SCHEDULER_Reason reason; @@ -449,25 +449,25 @@ is_ready (struct Task *task, struct GNUNET_TIME_Absolute now, reason |= GNUNET_SCHEDULER_REASON_TIMEOUT; if ((0 == (reason & GNUNET_SCHEDULER_REASON_READ_READY)) && (((task->read_fd != -1) && - (GNUNET_YES == GNUNET_NETWORK_fdset_test_native (rs, task->read_fd))) - || (set_overlaps (rs, task->read_set)))) + (GNUNET_YES == GNUNET_NETWORK_fdset_test_native (rs, task->read_fd))) || + (set_overlaps (rs, task->read_set)))) reason |= GNUNET_SCHEDULER_REASON_READ_READY; if ((0 == (reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) && (((task->write_fd != -1) && - (GNUNET_YES == GNUNET_NETWORK_fdset_test_native (ws, task->write_fd))) + (GNUNET_YES == GNUNET_NETWORK_fdset_test_native (ws, task->write_fd))) || (set_overlaps (ws, task->write_set)))) reason |= GNUNET_SCHEDULER_REASON_WRITE_READY; if (reason == 0) - return GNUNET_NO; /* not ready */ + return GNUNET_NO; /* not ready */ if (task->prereq_id != GNUNET_SCHEDULER_NO_TASK) + { + if (GNUNET_YES == is_pending (task->prereq_id)) { - if (GNUNET_YES == is_pending (task->prereq_id)) - { - task->reason = reason; - return GNUNET_NO; /* prereq waiting */ - } - reason |= GNUNET_SCHEDULER_REASON_PREREQ_DONE; + task->reason = reason; + return GNUNET_NO; /* prereq waiting */ } + reason |= GNUNET_SCHEDULER_REASON_PREREQ_DONE; + } task->reason = reason; return GNUNET_YES; } @@ -500,7 +500,7 @@ queue_ready_task (struct Task *task) */ static void check_ready (const struct GNUNET_NETWORK_FDSet *rs, - const struct GNUNET_NETWORK_FDSet *ws) + const struct GNUNET_NETWORK_FDSet *ws) { struct Task *pos; struct Task *prev; @@ -511,40 +511,39 @@ check_ready (const struct GNUNET_NETWORK_FDSet *rs, prev = NULL; pos = pending_timeout; while (pos != NULL) - { - next = pos->next; - if (now.abs_value >= pos->timeout.abs_value) - pos->reason |= GNUNET_SCHEDULER_REASON_TIMEOUT; - if (0 == pos->reason) - break; - pending_timeout = next; - if (pending_timeout_last == pos) - pending_timeout_last = NULL; - queue_ready_task (pos); - pos = next; - } + { + next = pos->next; + if (now.abs_value >= pos->timeout.abs_value) + pos->reason |= GNUNET_SCHEDULER_REASON_TIMEOUT; + if (0 == pos->reason) + break; + pending_timeout = next; + if (pending_timeout_last == pos) + pending_timeout_last = NULL; + queue_ready_task (pos); + pos = next; + } pos = pending; while (pos != NULL) - { + { #if DEBUG_TASKS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Checking readiness of task: %llu / %p\n", pos->id, - pos->callback_cls); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Checking readiness of task: %llu / %p\n", + pos->id, pos->callback_cls); #endif - next = pos->next; - if (GNUNET_YES == is_ready (pos, now, rs, ws)) - { - if (prev == NULL) - pending = next; - else - prev->next = next; - queue_ready_task (pos); - pos = next; - continue; - } - prev = pos; + next = pos->next; + if (GNUNET_YES == is_ready (pos, now, rs, ws)) + { + if (prev == NULL) + pending = next; + else + prev->next = next; + queue_ready_task (pos); pos = next; + continue; } + prev = pos; + pos = next; + } } @@ -563,15 +562,26 @@ GNUNET_SCHEDULER_shutdown () pos = pending_timeout; while (pos != NULL) - { - pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; - /* we don't move the task into the ready queue yet; check_ready - * will do that later, possibly adding additional - * readiness-factors */ - pos = pos->next; - } + { + pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; + /* we don't move the task into the ready queue yet; check_ready + * will do that later, possibly adding additional + * readiness-factors */ + pos = pos->next; + } pos = pending; while (pos != NULL) + { + pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; + /* we don't move the task into the ready queue yet; check_ready + * will do that later, possibly adding additional + * readiness-factors */ + pos = pos->next; + } + for (i = 0; i < GNUNET_SCHEDULER_PRIORITY_COUNT; i++) + { + pos = ready[i]; + while (pos != NULL) { pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; /* we don't move the task into the ready queue yet; check_ready @@ -579,18 +589,7 @@ GNUNET_SCHEDULER_shutdown () * readiness-factors */ pos = pos->next; } - for (i = 0; i < GNUNET_SCHEDULER_PRIORITY_COUNT; i++) - { - pos = ready[i]; - while (pos != NULL) - { - pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; - /* we don't move the task into the ready queue yet; check_ready - * will do that later, possibly adding additional - * readiness-factors */ - pos = pos->next; - } - } + } } @@ -632,69 +631,68 @@ run_ready (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws) max_priority_added = GNUNET_SCHEDULER_PRIORITY_KEEP; do + { + if (ready_count == 0) + return; + GNUNET_assert (ready[GNUNET_SCHEDULER_PRIORITY_KEEP] == NULL); + /* yes, p>0 is correct, 0 is "KEEP" which should + * always be an empty queue (see assertion)! */ + for (p = GNUNET_SCHEDULER_PRIORITY_COUNT - 1; p > 0; p--) { - if (ready_count == 0) - return; - GNUNET_assert (ready[GNUNET_SCHEDULER_PRIORITY_KEEP] == NULL); - /* yes, p>0 is correct, 0 is "KEEP" which should - * always be an empty queue (see assertion)! */ - for (p = GNUNET_SCHEDULER_PRIORITY_COUNT - 1; p > 0; p--) - { - pos = ready[p]; - if (pos != NULL) - break; - } - GNUNET_assert (pos != NULL); /* ready_count wrong? */ - ready[p] = pos->next; - ready_count--; - if (current_priority != pos->priority) - { - current_priority = pos->priority; - (void) GNUNET_OS_set_process_priority (GNUNET_OS_process_current (), - pos->priority); - } - current_lifeness = pos->lifeness; - active_task = pos; + pos = ready[p]; + if (pos != NULL) + break; + } + GNUNET_assert (pos != NULL); /* ready_count wrong? */ + ready[p] = pos->next; + ready_count--; + if (current_priority != pos->priority) + { + current_priority = pos->priority; + (void) GNUNET_OS_set_process_priority (GNUNET_OS_process_current (), + pos->priority); + } + current_lifeness = pos->lifeness; + active_task = pos; #if PROFILE_DELAYS - if (GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value > - DELAY_THRESHOLD.rel_value) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - "Task %llu took %llums to be scheduled\n", pos->id, - (unsigned long long) - GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value); - } + if (GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value > + DELAY_THRESHOLD.rel_value) + { + LOG (GNUNET_ERROR_TYPE_ERROR, "Task %llu took %llums to be scheduled\n", + pos->id, + (unsigned long long) + GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value); + } #endif - tc.reason = pos->reason; - tc.read_ready = (pos->read_set == NULL) ? rs : pos->read_set; - if ((pos->read_fd != -1) && - (0 != (pos->reason & GNUNET_SCHEDULER_REASON_READ_READY))) - GNUNET_NETWORK_fdset_set_native (rs, pos->read_fd); - tc.write_ready = (pos->write_set == NULL) ? ws : pos->write_set; - if ((pos->write_fd != -1) && - (0 != (pos->reason & GNUNET_SCHEDULER_REASON_WRITE_READY))) - GNUNET_NETWORK_fdset_set_native (ws, pos->write_fd); - if (((tc.reason & GNUNET_SCHEDULER_REASON_WRITE_READY) != 0) && - (pos->write_fd != -1) && - (!GNUNET_NETWORK_fdset_test_native (ws, pos->write_fd))) - abort (); // added to ready in previous select loop! + tc.reason = pos->reason; + tc.read_ready = (pos->read_set == NULL) ? rs : pos->read_set; + if ((pos->read_fd != -1) && + (0 != (pos->reason & GNUNET_SCHEDULER_REASON_READ_READY))) + GNUNET_NETWORK_fdset_set_native (rs, pos->read_fd); + tc.write_ready = (pos->write_set == NULL) ? ws : pos->write_set; + if ((pos->write_fd != -1) && + (0 != (pos->reason & GNUNET_SCHEDULER_REASON_WRITE_READY))) + GNUNET_NETWORK_fdset_set_native (ws, pos->write_fd); + if (((tc.reason & GNUNET_SCHEDULER_REASON_WRITE_READY) != 0) && + (pos->write_fd != -1) && + (!GNUNET_NETWORK_fdset_test_native (ws, pos->write_fd))) + abort (); // added to ready in previous select loop! #if DEBUG_TASKS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Running task: %llu / %p\n", pos->id, pos->callback_cls); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Running task: %llu / %p\n", pos->id, + pos->callback_cls); #endif - pos->callback (pos->callback_cls, &tc); + pos->callback (pos->callback_cls, &tc); #if EXECINFO - int i; + int i; - for (i = 0; i < pos->num_backtrace_strings; i++) - LOG (GNUNET_ERROR_TYPE_ERROR, - "Task %llu trace %d: %s\n", pos->id, - i, pos->backtrace_strings[i]); + for (i = 0; i < pos->num_backtrace_strings; i++) + LOG (GNUNET_ERROR_TYPE_ERROR, "Task %llu trace %d: %s\n", pos->id, i, + pos->backtrace_strings[i]); #endif - active_task = NULL; - destroy_task (pos); - tasks_run++; - } + active_task = NULL; + destroy_task (pos); + tasks_run++; + } while ((pending == NULL) || (p >= max_priority_added)); } @@ -720,11 +718,11 @@ static void sighandler_shutdown () { static char c; - int old_errno = errno; /* backup errno */ + int old_errno = errno; /* backup errno */ GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle - (shutdown_pipe_handle, GNUNET_DISK_PIPE_END_WRITE), - &c, sizeof (c)); + (shutdown_pipe_handle, GNUNET_DISK_PIPE_END_WRITE), + &c, sizeof (c)); errno = old_errno; } @@ -750,10 +748,10 @@ check_lifeness () if (t->lifeness == GNUNET_YES) return GNUNET_OK; if ((NULL != pending) || (NULL != pending_timeout)) - { - GNUNET_SCHEDULER_shutdown (); - return GNUNET_OK; - } + { + GNUNET_SCHEDULER_shutdown (); + return GNUNET_OK; + } return GNUNET_NO; } @@ -799,7 +797,7 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls) shutdown_pipe_handle = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO); GNUNET_assert (shutdown_pipe_handle != NULL); pr = GNUNET_DISK_pipe_handle (shutdown_pipe_handle, - GNUNET_DISK_PIPE_END_READ); + GNUNET_DISK_PIPE_END_READ); GNUNET_assert (pr != NULL); shc_int = GNUNET_SIGNAL_handler_install (SIGINT, &sighandler_shutdown); shc_term = GNUNET_SIGNAL_handler_install (SIGTERM, &sighandler_shutdown); @@ -811,77 +809,76 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls) current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT; current_lifeness = GNUNET_YES; GNUNET_SCHEDULER_add_continuation (task, task_cls, - GNUNET_SCHEDULER_REASON_STARTUP); + GNUNET_SCHEDULER_REASON_STARTUP); #if ENABLE_WINDOWS_WORKAROUNDS - active_task = (void *) (long) -1; /* force passing of sanity check */ + active_task = (void *) (long) -1; /* force passing of sanity check */ GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO, - &GNUNET_OS_install_parent_control_handler, - NULL); + &GNUNET_OS_install_parent_control_handler, + NULL); active_task = NULL; #endif last_tr = 0; busy_wait_warning = 0; while (GNUNET_OK == check_lifeness ()) + { + GNUNET_NETWORK_fdset_zero (rs); + GNUNET_NETWORK_fdset_zero (ws); + timeout = GNUNET_TIME_UNIT_FOREVER_REL; + update_sets (rs, ws, &timeout); + GNUNET_NETWORK_fdset_handle_set (rs, pr); + if (ready_count > 0) { - GNUNET_NETWORK_fdset_zero (rs); - GNUNET_NETWORK_fdset_zero (ws); - timeout = GNUNET_TIME_UNIT_FOREVER_REL; - update_sets (rs, ws, &timeout); - GNUNET_NETWORK_fdset_handle_set (rs, pr); - if (ready_count > 0) - { - /* no blocking, more work already ready! */ - timeout = GNUNET_TIME_UNIT_ZERO; - } - if (NULL == scheduler_select) - ret = GNUNET_NETWORK_socket_select (rs, ws, NULL, timeout); - else - ret = scheduler_select (scheduler_select_cls, rs, ws, NULL, timeout); - if (ret == GNUNET_SYSERR) - { - if (errno == EINTR) - continue; + /* no blocking, more work already ready! */ + timeout = GNUNET_TIME_UNIT_ZERO; + } + if (NULL == scheduler_select) + ret = GNUNET_NETWORK_socket_select (rs, ws, NULL, timeout); + else + ret = scheduler_select (scheduler_select_cls, rs, ws, NULL, timeout); + if (ret == GNUNET_SYSERR) + { + if (errno == EINTR) + continue; - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "select"); + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "select"); #ifndef MINGW #if USE_LSOF - char lsof[512]; + char lsof[512]; - snprintf (lsof, sizeof (lsof), "lsof -p %d", getpid ()); - (void) close (1); - (void) dup2 (2, 1); - if (0 != system (lsof)) - LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "system"); + snprintf (lsof, sizeof (lsof), "lsof -p %d", getpid ()); + (void) close (1); + (void) dup2 (2, 1); + if (0 != system (lsof)) + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "system"); #endif #endif - abort (); - break; - } - if ((ret == 0) && (timeout.rel_value == 0) && (busy_wait_warning > 16)) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - _("Looks like we're busy waiting...\n")); - sleep (1); /* mitigate */ - } - check_ready (rs, ws); - run_ready (rs, ws); - if (GNUNET_NETWORK_fdset_handle_isset (rs, pr)) - { - /* consume the signal */ - GNUNET_DISK_file_read (pr, &c, sizeof (c)); - /* mark all active tasks as ready due to shutdown */ - GNUNET_SCHEDULER_shutdown (); - } - if (last_tr == tasks_run) - { - busy_wait_warning++; - } - else - { - last_tr = tasks_run; - busy_wait_warning = 0; - } + abort (); + break; + } + if ((ret == 0) && (timeout.rel_value == 0) && (busy_wait_warning > 16)) + { + LOG (GNUNET_ERROR_TYPE_WARNING, _("Looks like we're busy waiting...\n")); + sleep (1); /* mitigate */ + } + check_ready (rs, ws); + run_ready (rs, ws); + if (GNUNET_NETWORK_fdset_handle_isset (rs, pr)) + { + /* consume the signal */ + GNUNET_DISK_file_read (pr, &c, sizeof (c)); + /* mark all active tasks as ready due to shutdown */ + GNUNET_SCHEDULER_shutdown (); + } + if (last_tr == tasks_run) + { + busy_wait_warning++; + } + else + { + last_tr = tasks_run; + busy_wait_warning = 0; } + } GNUNET_SIGNAL_handler_uninstall (shc_int); GNUNET_SIGNAL_handler_uninstall (shc_term); #ifndef MINGW @@ -934,10 +931,10 @@ GNUNET_SCHEDULER_get_load (enum GNUNET_SCHEDULER_Priority p) ret = 0; pos = ready[check_priority (p)]; while (pos != NULL) - { - pos = pos->next; - ret++; - } + { + pos = pos->next; + ret++; + } return ret; } @@ -963,77 +960,76 @@ GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_TaskIdentifier task) prev = NULL; t = pending; while (t != NULL) + { + if (t->id == task) + break; + prev = t; + t = t->next; + } + if (t == NULL) + { + prev = NULL; + to = 1; + t = pending_timeout; + while (t != NULL) { if (t->id == task) - break; + break; prev = t; t = t->next; } - if (t == NULL) - { - prev = NULL; - to = 1; - t = pending_timeout; - while (t != NULL) - { - if (t->id == task) - break; - prev = t; - t = t->next; - } - if (pending_timeout_last == t) - pending_timeout_last = NULL; - } + if (pending_timeout_last == t) + pending_timeout_last = NULL; + } p = 0; while (t == NULL) + { + p++; + if (p >= GNUNET_SCHEDULER_PRIORITY_COUNT) { - p++; - if (p >= GNUNET_SCHEDULER_PRIORITY_COUNT) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Attempt to cancel dead task %llu!\n"), - (unsigned long long) task); - GNUNET_assert (0); - } - prev = NULL; - t = ready[p]; - while (t != NULL) - { - if (t->id == task) - { - ready_count--; - break; - } - prev = t; - t = t->next; - } + LOG (GNUNET_ERROR_TYPE_ERROR, _("Attempt to cancel dead task %llu!\n"), + (unsigned long long) task); + GNUNET_assert (0); } + prev = NULL; + t = ready[p]; + while (t != NULL) + { + if (t->id == task) + { + ready_count--; + break; + } + prev = t; + t = t->next; + } + } if (prev == NULL) + { + if (p == 0) { - if (p == 0) - { - if (to == 0) - { - pending = t->next; - } - else - { - pending_timeout = t->next; - } - } + if (to == 0) + { + pending = t->next; + } else - { - ready[p] = t->next; - } + { + pending_timeout = t->next; + } } - else + else { - prev->next = t->next; + ready[p] = t->next; } + } + else + { + prev->next = t->next; + } ret = t->callback_cls; #if DEBUG_TASKS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Canceling task: %llu / %p\n", task, t->callback_cls); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Canceling task: %llu / %p\n", task, + t->callback_cls); #endif destroy_task (t); return ret; @@ -1051,7 +1047,7 @@ GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_TaskIdentifier task) */ void GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls, - enum GNUNET_SCHEDULER_Reason reason) + enum GNUNET_SCHEDULER_Reason reason) { struct Task *t; @@ -1061,12 +1057,12 @@ GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls, GNUNET_assert (NULL != task); GNUNET_assert ((active_task != NULL) || - (reason == GNUNET_SCHEDULER_REASON_STARTUP)); + (reason == GNUNET_SCHEDULER_REASON_STARTUP)); t = GNUNET_malloc (sizeof (struct Task)); #if EXECINFO t->num_backtrace_strings = backtrace (backtrace_array, 50); t->backtrace_strings = - backtrace_symbols (backtrace_array, t->num_backtrace_strings); + backtrace_symbols (backtrace_array, t->num_backtrace_strings); #endif t->read_fd = -1; t->write_fd = -1; @@ -1080,8 +1076,8 @@ GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls, t->priority = current_priority; t->lifeness = current_lifeness; #if DEBUG_TASKS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Adding continuation task: %llu / %p\n", t->id, t->callback_cls); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding continuation task: %llu / %p\n", t->id, + t->callback_cls); #endif queue_ready_task (t); } @@ -1106,12 +1102,11 @@ GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls, */ GNUNET_SCHEDULER_TaskIdentifier GNUNET_SCHEDULER_add_after (GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, - GNUNET_SCHEDULER_Task task, void *task_cls) + GNUNET_SCHEDULER_Task task, void *task_cls) { return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, - prerequisite_task, - GNUNET_TIME_UNIT_ZERO, NULL, NULL, task, - task_cls); + prerequisite_task, GNUNET_TIME_UNIT_ZERO, + NULL, NULL, task, task_cls); } @@ -1126,12 +1121,11 @@ GNUNET_SCHEDULER_add_after (GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, */ GNUNET_SCHEDULER_TaskIdentifier GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio, - GNUNET_SCHEDULER_Task task, - void *task_cls) + GNUNET_SCHEDULER_Task task, void *task_cls) { return GNUNET_SCHEDULER_add_select (prio, GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_UNIT_ZERO, NULL, NULL, task, - task_cls); + GNUNET_TIME_UNIT_ZERO, NULL, NULL, task, + task_cls); } @@ -1150,7 +1144,7 @@ GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio, */ GNUNET_SCHEDULER_TaskIdentifier GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay, - GNUNET_SCHEDULER_Task task, void *task_cls) + GNUNET_SCHEDULER_Task task, void *task_cls) { #if 1 /* new, optimized version */ @@ -1170,7 +1164,7 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay, #if EXECINFO t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH); t->backtrace_strings = - backtrace_symbols (backtrace_array, t->num_backtrace_strings); + backtrace_symbols (backtrace_array, t->num_backtrace_strings); #endif t->read_fd = -1; t->write_fd = -1; @@ -1185,24 +1179,24 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay, * appending to a long list of tasks with timeouts) */ prev = pending_timeout_last; if (prev != NULL) - { - if (prev->timeout.abs_value > t->timeout.abs_value) - prev = NULL; - else - pos = prev->next; /* heuristic success! */ - } + { + if (prev->timeout.abs_value > t->timeout.abs_value) + prev = NULL; + else + pos = prev->next; /* heuristic success! */ + } if (prev == NULL) - { - /* heuristic failed, do traversal of timeout list */ - pos = pending_timeout; - } + { + /* heuristic failed, do traversal of timeout list */ + pos = pending_timeout; + } while ((pos != NULL) && - ((pos->timeout.abs_value <= t->timeout.abs_value) || - (pos->reason != 0))) - { - prev = pos; - pos = pos->next; - } + ((pos->timeout.abs_value <= t->timeout.abs_value) || + (pos->reason != 0))) + { + prev = pos; + pos = pos->next; + } if (prev == NULL) pending_timeout = t; else @@ -1212,23 +1206,23 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay, pending_timeout_last = t; #if DEBUG_TASKS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Adding task: %llu / %p\n", t->id, t->callback_cls); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding task: %llu / %p\n", t->id, + t->callback_cls); #endif #if EXECINFO int i; for (i = 0; i < t->num_backtrace_strings; i++) - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Task %llu trace %d: %s\n", t->id, i, t->backtrace_strings[i]); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Task %llu trace %d: %s\n", t->id, i, + t->backtrace_strings[i]); #endif return t->id; #else /* unoptimized version */ return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, delay, NULL, - NULL, task, task_cls); + GNUNET_SCHEDULER_NO_TASK, delay, NULL, + NULL, task, task_cls); #endif } @@ -1247,9 +1241,9 @@ GNUNET_SCHEDULER_TaskIdentifier GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_Task task, void *task_cls) { return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_UNIT_ZERO, NULL, NULL, task, - task_cls); + GNUNET_SCHEDULER_NO_TASK, + GNUNET_TIME_UNIT_ZERO, NULL, NULL, task, + task_cls); } @@ -1269,16 +1263,16 @@ GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_Task task, void *task_cls) */ GNUNET_SCHEDULER_TaskIdentifier GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness, - GNUNET_SCHEDULER_Task task, - void *task_cls) + GNUNET_SCHEDULER_Task task, + void *task_cls) { GNUNET_SCHEDULER_TaskIdentifier ret; ret = - GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_UNIT_ZERO, NULL, NULL, task, - task_cls); + GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, + GNUNET_SCHEDULER_NO_TASK, + GNUNET_TIME_UNIT_ZERO, NULL, NULL, task, + task_cls); GNUNET_assert (pending->id == ret); pending->lifeness = lifeness; return ret; @@ -1316,7 +1310,7 @@ GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness, #ifndef MINGW GNUNET_SCHEDULER_TaskIdentifier add_without_sets (struct GNUNET_TIME_Relative delay, int rfd, int wfd, - GNUNET_SCHEDULER_Task task, void *task_cls) + GNUNET_SCHEDULER_Task task, void *task_cls) { struct Task *t; @@ -1332,45 +1326,41 @@ add_without_sets (struct GNUNET_TIME_Relative delay, int rfd, int wfd, #if EXECINFO t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH); t->backtrace_strings = - backtrace_symbols (backtrace_array, t->num_backtrace_strings); + backtrace_symbols (backtrace_array, t->num_backtrace_strings); #endif #if DEBUG_FDS if (-1 != rfd) - { - int flags = fcntl (rfd, F_GETFD); + { + int flags = fcntl (rfd, F_GETFD); - if ((flags == -1) && (errno == EBADF)) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - "Got invalid file descriptor %d!\n", rfd); + if ((flags == -1) && (errno == EBADF)) + { + LOG (GNUNET_ERROR_TYPE_ERROR, "Got invalid file descriptor %d!\n", rfd); #if EXECINFO - int i; + int i; - for (i = 0; i < t->num_backtrace_strings; i++) - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Trace: %s\n", t->backtrace_strings[i]); + for (i = 0; i < t->num_backtrace_strings; i++) + LOG (GNUNET_ERROR_TYPE_DEBUG, "Trace: %s\n", t->backtrace_strings[i]); #endif - GNUNET_assert (0); - } + GNUNET_assert (0); } + } if (-1 != wfd) - { - int flags = fcntl (wfd, F_GETFD); + { + int flags = fcntl (wfd, F_GETFD); - if (flags == -1 && errno == EBADF) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - "Got invalid file descriptor %d!\n", wfd); + if (flags == -1 && errno == EBADF) + { + LOG (GNUNET_ERROR_TYPE_ERROR, "Got invalid file descriptor %d!\n", wfd); #if EXECINFO - int i; + int i; - for (i = 0; i < t->num_backtrace_strings; i++) - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Trace: %s\n", t->backtrace_strings[i]); + for (i = 0; i < t->num_backtrace_strings; i++) + LOG (GNUNET_ERROR_TYPE_DEBUG, "Trace: %s\n", t->backtrace_strings[i]); #endif - GNUNET_assert (0); - } + GNUNET_assert (0); } + } #endif t->read_fd = rfd; GNUNET_assert (wfd >= -1); @@ -1387,15 +1377,15 @@ add_without_sets (struct GNUNET_TIME_Relative delay, int rfd, int wfd, pending = t; max_priority_added = GNUNET_MAX (max_priority_added, t->priority); #if DEBUG_TASKS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Adding task: %llu / %p\n", t->id, t->callback_cls); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding task: %llu / %p\n", t->id, + t->callback_cls); #endif #if EXECINFO int i; for (i = 0; i < t->num_backtrace_strings; i++) - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Task %llu trace %d: %s\n", t->id, i, t->backtrace_strings[i]); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Task %llu trace %d: %s\n", t->id, i, + t->backtrace_strings[i]); #endif return t->id; } @@ -1421,8 +1411,8 @@ add_without_sets (struct GNUNET_TIME_Relative delay, int rfd, int wfd, */ GNUNET_SCHEDULER_TaskIdentifier GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay, - struct GNUNET_NETWORK_Handle * rfd, - GNUNET_SCHEDULER_Task task, void *task_cls) + struct GNUNET_NETWORK_Handle *rfd, + GNUNET_SCHEDULER_Task task, void *task_cls) { #if MINGW struct GNUNET_NETWORK_FDSet *rs; @@ -1432,14 +1422,14 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay, rs = GNUNET_NETWORK_fdset_create (); GNUNET_NETWORK_fdset_set (rs, rfd); ret = - GNUNET_SCHEDULER_add_select (check_priority (current_priority), - GNUNET_SCHEDULER_NO_TASK, delay, rs, NULL, - task, task_cls); + GNUNET_SCHEDULER_add_select (check_priority (current_priority), + GNUNET_SCHEDULER_NO_TASK, delay, rs, NULL, + task, task_cls); GNUNET_NETWORK_fdset_destroy (rs); return ret; #else return add_without_sets (delay, GNUNET_NETWORK_get_fd (rfd), -1, task, - task_cls); + task_cls); #endif } @@ -1462,8 +1452,8 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay, */ GNUNET_SCHEDULER_TaskIdentifier GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay, - struct GNUNET_NETWORK_Handle * wfd, - GNUNET_SCHEDULER_Task task, void *task_cls) + struct GNUNET_NETWORK_Handle *wfd, + GNUNET_SCHEDULER_Task task, void *task_cls) { #if MINGW struct GNUNET_NETWORK_FDSet *ws; @@ -1473,15 +1463,15 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay, ws = GNUNET_NETWORK_fdset_create (); GNUNET_NETWORK_fdset_set (ws, wfd); ret = - GNUNET_SCHEDULER_add_select (check_priority (current_priority), - GNUNET_SCHEDULER_NO_TASK, delay, NULL, ws, - task, task_cls); + GNUNET_SCHEDULER_add_select (check_priority (current_priority), + GNUNET_SCHEDULER_NO_TASK, delay, NULL, ws, + task, task_cls); GNUNET_NETWORK_fdset_destroy (ws); return ret; #else GNUNET_assert (GNUNET_NETWORK_get_fd (wfd) >= 0); return add_without_sets (delay, -1, GNUNET_NETWORK_get_fd (wfd), task, - task_cls); + task_cls); #endif } @@ -1504,8 +1494,8 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay, */ GNUNET_SCHEDULER_TaskIdentifier GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay, - const struct GNUNET_DISK_FileHandle * rfd, - GNUNET_SCHEDULER_Task task, void *task_cls) + const struct GNUNET_DISK_FileHandle *rfd, + GNUNET_SCHEDULER_Task task, void *task_cls) { #if MINGW struct GNUNET_NETWORK_FDSet *rs; @@ -1515,9 +1505,9 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay, rs = GNUNET_NETWORK_fdset_create (); GNUNET_NETWORK_fdset_handle_set (rs, rfd); ret = - GNUNET_SCHEDULER_add_select (check_priority (current_priority), - GNUNET_SCHEDULER_NO_TASK, delay, rs, NULL, - task, task_cls); + GNUNET_SCHEDULER_add_select (check_priority (current_priority), + GNUNET_SCHEDULER_NO_TASK, delay, rs, NULL, + task, task_cls); GNUNET_NETWORK_fdset_destroy (rs); return ret; #else @@ -1548,8 +1538,8 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay, */ GNUNET_SCHEDULER_TaskIdentifier GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay, - const struct GNUNET_DISK_FileHandle * wfd, - GNUNET_SCHEDULER_Task task, void *task_cls) + const struct GNUNET_DISK_FileHandle *wfd, + GNUNET_SCHEDULER_Task task, void *task_cls) { #if MINGW struct GNUNET_NETWORK_FDSet *ws; @@ -1559,9 +1549,9 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay, ws = GNUNET_NETWORK_fdset_create (); GNUNET_NETWORK_fdset_handle_set (ws, wfd); ret = - GNUNET_SCHEDULER_add_select (check_priority (current_priority), - GNUNET_SCHEDULER_NO_TASK, delay, NULL, ws, - task, task_cls); + GNUNET_SCHEDULER_add_select (check_priority (current_priority), + GNUNET_SCHEDULER_NO_TASK, delay, NULL, ws, + task, task_cls); GNUNET_NETWORK_fdset_destroy (ws); return ret; #else @@ -1610,12 +1600,11 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay, */ GNUNET_SCHEDULER_TaskIdentifier GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, - GNUNET_SCHEDULER_TaskIdentifier - prerequisite_task, - struct GNUNET_TIME_Relative delay, - const struct GNUNET_NETWORK_FDSet * rs, - const struct GNUNET_NETWORK_FDSet * ws, - GNUNET_SCHEDULER_Task task, void *task_cls) + GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, + struct GNUNET_TIME_Relative delay, + const struct GNUNET_NETWORK_FDSet *rs, + const struct GNUNET_NETWORK_FDSet *ws, + GNUNET_SCHEDULER_Task task, void *task_cls) { struct Task *t; @@ -1631,20 +1620,20 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, #if EXECINFO t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH); t->backtrace_strings = - backtrace_symbols (backtrace_array, t->num_backtrace_strings); + backtrace_symbols (backtrace_array, t->num_backtrace_strings); #endif t->read_fd = -1; t->write_fd = -1; if (rs != NULL) - { - t->read_set = GNUNET_NETWORK_fdset_create (); - GNUNET_NETWORK_fdset_copy (t->read_set, rs); - } + { + t->read_set = GNUNET_NETWORK_fdset_create (); + GNUNET_NETWORK_fdset_copy (t->read_set, rs); + } if (ws != NULL) - { - t->write_set = GNUNET_NETWORK_fdset_create (); - GNUNET_NETWORK_fdset_copy (t->write_set, ws); - } + { + t->write_set = GNUNET_NETWORK_fdset_create (); + GNUNET_NETWORK_fdset_copy (t->write_set, ws); + } t->id = ++last_id; #if PROFILE_DELAYS t->start_time = GNUNET_TIME_absolute_get (); @@ -1652,23 +1641,23 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, t->prereq_id = prerequisite_task; t->timeout = GNUNET_TIME_relative_to_absolute (delay); t->priority = - check_priority ((prio == - GNUNET_SCHEDULER_PRIORITY_KEEP) ? current_priority : - prio); + check_priority ((prio == + GNUNET_SCHEDULER_PRIORITY_KEEP) ? current_priority : + prio); t->lifeness = current_lifeness; t->next = pending; pending = t; max_priority_added = GNUNET_MAX (max_priority_added, t->priority); #if DEBUG_TASKS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Adding task: %llu / %p\n", t->id, t->callback_cls); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding task: %llu / %p\n", t->id, + t->callback_cls); #endif #if EXECINFO int i; for (i = 0; i < t->num_backtrace_strings; i++) - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Task %llu trace %d: %s\n", t->id, i, t->backtrace_strings[i]); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Task %llu trace %d: %s\n", t->id, i, + t->backtrace_strings[i]); #endif return t->id; } diff --git a/src/util/server.c b/src/util/server.c index f792e5a67..6f1b8cdb4 100644 --- a/src/util/server.c +++ b/src/util/server.c @@ -264,8 +264,7 @@ struct GNUNET_SERVER_Client * @param tc reason why we are running right now */ static void -process_listen_socket (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +process_listen_socket (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_SERVER_Handle *server = cls; struct GNUNET_CONNECTION_Handle *sock; @@ -279,47 +278,45 @@ process_listen_socket (void *cls, while (NULL != server->listen_sockets[i]) GNUNET_NETWORK_fdset_set (r, server->listen_sockets[i++]); if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) - { - /* ignore shutdown, someone else will take care of it! */ - server->listen_task = - GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_UNIT_FOREVER_REL, r, NULL, - &process_listen_socket, server); - GNUNET_NETWORK_fdset_destroy (r); - return; - } + { + /* ignore shutdown, someone else will take care of it! */ + server->listen_task = + GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, + GNUNET_SCHEDULER_NO_TASK, + GNUNET_TIME_UNIT_FOREVER_REL, r, NULL, + &process_listen_socket, server); + GNUNET_NETWORK_fdset_destroy (r); + return; + } i = 0; while (NULL != server->listen_sockets[i]) + { + if (GNUNET_NETWORK_fdset_isset (tc->read_ready, server->listen_sockets[i])) { - if (GNUNET_NETWORK_fdset_isset - (tc->read_ready, server->listen_sockets[i])) - { - sock = - GNUNET_CONNECTION_create_from_accept (server->access, - server->access_cls, - server->listen_sockets[i]); - if (sock != NULL) - { + sock = + GNUNET_CONNECTION_create_from_accept (server->access, + server->access_cls, + server->listen_sockets[i]); + if (sock != NULL) + { #if DEBUG_SERVER - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Server accepted incoming connection.\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Server accepted incoming connection.\n"); #endif - client = GNUNET_SERVER_connect_socket (server, sock); - GNUNET_CONNECTION_ignore_shutdown (sock, - server->clients_ignore_shutdown); - /* decrement reference count, we don't keep "client" alive */ - GNUNET_SERVER_client_drop (client); - } - } - i++; + client = GNUNET_SERVER_connect_socket (server, sock); + GNUNET_CONNECTION_ignore_shutdown (sock, + server->clients_ignore_shutdown); + /* decrement reference count, we don't keep "client" alive */ + GNUNET_SERVER_client_drop (client); + } } + i++; + } /* listen for more! */ server->listen_task = - GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_UNIT_FOREVER_REL, r, NULL, - &process_listen_socket, server); + GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, + GNUNET_SCHEDULER_NO_TASK, + GNUNET_TIME_UNIT_FOREVER_REL, r, NULL, + &process_listen_socket, server); GNUNET_NETWORK_fdset_destroy (r); } @@ -340,87 +337,87 @@ open_listen_socket (const struct sockaddr *serverAddr, socklen_t socklen) int eno; switch (serverAddr->sa_family) - { - case AF_INET: - port = ntohs (((const struct sockaddr_in *) serverAddr)->sin_port); - break; - case AF_INET6: - port = ntohs (((const struct sockaddr_in6 *) serverAddr)->sin6_port); - break; - case AF_UNIX: - port = 0; - break; - default: - GNUNET_break (0); - port = 0; - break; - } + { + case AF_INET: + port = ntohs (((const struct sockaddr_in *) serverAddr)->sin_port); + break; + case AF_INET6: + port = ntohs (((const struct sockaddr_in6 *) serverAddr)->sin6_port); + break; + case AF_UNIX: + port = 0; + break; + default: + GNUNET_break (0); + port = 0; + break; + } sock = GNUNET_NETWORK_socket_create (serverAddr->sa_family, SOCK_STREAM, 0); if (NULL == sock) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket"); - errno = 0; - return NULL; - } + { + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket"); + errno = 0; + return NULL; + } if (port != 0) - { - if (GNUNET_NETWORK_socket_setsockopt - (sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "setsockopt"); + { + if (GNUNET_NETWORK_socket_setsockopt + (sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "setsockopt"); #ifdef IPV6_V6ONLY - if ((serverAddr->sa_family == AF_INET6) && - (GNUNET_NETWORK_socket_setsockopt - (sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on)) != GNUNET_OK)) - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "setsockopt"); + if ((serverAddr->sa_family == AF_INET6) && + (GNUNET_NETWORK_socket_setsockopt + (sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on)) != GNUNET_OK)) + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "setsockopt"); #endif - } + } /* bind the socket */ if (GNUNET_NETWORK_socket_bind (sock, serverAddr, socklen) != GNUNET_OK) + { + eno = errno; + if (errno != EADDRINUSE) { - eno = errno; - if (errno != EADDRINUSE) - { - /* we don't log 'EADDRINUSE' here since an IPv4 bind may - * fail if we already took the port on IPv6; if both IPv4 and - * IPv6 binds fail, then our caller will log using the - * errno preserved in 'eno' */ - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "bind"); - if (port != 0) - LOG (GNUNET_ERROR_TYPE_ERROR, - _("`%s' failed for port %d (%s).\n"), "bind", port, - (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6"); - eno = 0; - } - else - { - if (port != 0) - LOG (GNUNET_ERROR_TYPE_WARNING, - _("`%s' failed for port %d (%s): address already in use\n"), - "bind", port, - (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6"); - else if (serverAddr->sa_family == AF_UNIX) - LOG (GNUNET_ERROR_TYPE_WARNING, - _("`%s' failed for `%s': address already in use\n"), "bind", - ((const struct sockaddr_un *) serverAddr)->sun_path); - - } - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); - errno = eno; - return NULL; + /* we don't log 'EADDRINUSE' here since an IPv4 bind may + * fail if we already took the port on IPv6; if both IPv4 and + * IPv6 binds fail, then our caller will log using the + * errno preserved in 'eno' */ + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "bind"); + if (port != 0) + LOG (GNUNET_ERROR_TYPE_ERROR, _("`%s' failed for port %d (%s).\n"), + "bind", port, + (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6"); + eno = 0; } - if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock, 5)) + else { - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "listen"); - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); - errno = 0; - return NULL; + if (port != 0) + LOG (GNUNET_ERROR_TYPE_WARNING, + _("`%s' failed for port %d (%s): address already in use\n"), + "bind", port, + (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6"); + else if (serverAddr->sa_family == AF_UNIX) + LOG (GNUNET_ERROR_TYPE_WARNING, + _("`%s' failed for `%s': address already in use\n"), "bind", + ((const struct sockaddr_un *) serverAddr)->sun_path); + } + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); + errno = eno; + return NULL; + } + if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock, 5)) + { + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "listen"); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); + errno = 0; + return NULL; + } #if DEBUG_SERVER if (port != 0) - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Server starts to listen on port %u.\n", port); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Server starts to listen on port %u.\n", + port); #endif return sock; } @@ -440,10 +437,10 @@ open_listen_socket (const struct sockaddr *serverAddr, socklen_t socklen) */ struct GNUNET_SERVER_Handle * GNUNET_SERVER_create_with_sockets (GNUNET_CONNECTION_AccessCheck access, - void *access_cls, - struct GNUNET_NETWORK_Handle **lsocks, - struct GNUNET_TIME_Relative idle_timeout, - int require_found) + void *access_cls, + struct GNUNET_NETWORK_Handle **lsocks, + struct GNUNET_TIME_Relative idle_timeout, + int require_found) { struct GNUNET_SERVER_Handle *ret; struct GNUNET_NETWORK_FDSet *r; @@ -456,18 +453,18 @@ GNUNET_SERVER_create_with_sockets (GNUNET_CONNECTION_AccessCheck access, ret->access_cls = access_cls; ret->require_found = require_found; if (lsocks != NULL) - { - r = GNUNET_NETWORK_fdset_create (); - i = 0; - while (NULL != ret->listen_sockets[i]) - GNUNET_NETWORK_fdset_set (r, ret->listen_sockets[i++]); - ret->listen_task = - GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_UNIT_FOREVER_REL, r, NULL, - &process_listen_socket, ret); - GNUNET_NETWORK_fdset_destroy (r); - } + { + r = GNUNET_NETWORK_fdset_create (); + i = 0; + while (NULL != ret->listen_sockets[i]) + GNUNET_NETWORK_fdset_set (r, ret->listen_sockets[i++]); + ret->listen_task = + GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, + GNUNET_SCHEDULER_NO_TASK, + GNUNET_TIME_UNIT_FOREVER_REL, r, NULL, + &process_listen_socket, ret); + GNUNET_NETWORK_fdset_destroy (r); + } return ret; } @@ -487,10 +484,10 @@ GNUNET_SERVER_create_with_sockets (GNUNET_CONNECTION_AccessCheck access, */ struct GNUNET_SERVER_Handle * GNUNET_SERVER_create (GNUNET_CONNECTION_AccessCheck access, void *access_cls, - struct sockaddr *const *serverAddr, - const socklen_t * socklen, - struct GNUNET_TIME_Relative idle_timeout, - int require_found) + struct sockaddr *const *serverAddr, + const socklen_t * socklen, + struct GNUNET_TIME_Relative idle_timeout, + int require_found) { struct GNUNET_NETWORK_Handle **lsocks; unsigned int i; @@ -500,32 +497,31 @@ GNUNET_SERVER_create (GNUNET_CONNECTION_AccessCheck access, void *access_cls, while (serverAddr[i] != NULL) i++; if (i > 0) + { + lsocks = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (i + 1)); + i = 0; + j = 0; + while (serverAddr[i] != NULL) { - lsocks = - GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (i + 1)); - i = 0; - j = 0; - while (serverAddr[i] != NULL) - { - lsocks[j] = open_listen_socket (serverAddr[i], socklen[i]); - if (lsocks[j] != NULL) - j++; - i++; - } - if (j == 0) - { - if (errno != 0) - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "bind"); - GNUNET_free (lsocks); - lsocks = NULL; - } + lsocks[j] = open_listen_socket (serverAddr[i], socklen[i]); + if (lsocks[j] != NULL) + j++; + i++; } - else + if (j == 0) { + if (errno != 0) + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "bind"); + GNUNET_free (lsocks); lsocks = NULL; } + } + else + { + lsocks = NULL; + } return GNUNET_SERVER_create_with_sockets (access, access_cls, lsocks, - idle_timeout, require_found); + idle_timeout, require_found); } @@ -545,32 +541,32 @@ GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *s) LOG (GNUNET_ERROR_TYPE_DEBUG, "Server shutting down.\n"); #endif if (GNUNET_SCHEDULER_NO_TASK != s->listen_task) - { - GNUNET_SCHEDULER_cancel (s->listen_task); - s->listen_task = GNUNET_SCHEDULER_NO_TASK; - } + { + GNUNET_SCHEDULER_cancel (s->listen_task); + s->listen_task = GNUNET_SCHEDULER_NO_TASK; + } if (s->listen_sockets != NULL) - { - i = 0; - while (s->listen_sockets[i] != NULL) - GNUNET_break (GNUNET_OK == - GNUNET_NETWORK_socket_close (s->listen_sockets[i++])); - GNUNET_free (s->listen_sockets); - s->listen_sockets = NULL; - } + { + i = 0; + while (s->listen_sockets[i] != NULL) + GNUNET_break (GNUNET_OK == + GNUNET_NETWORK_socket_close (s->listen_sockets[i++])); + GNUNET_free (s->listen_sockets); + s->listen_sockets = NULL; + } while (s->clients != NULL) GNUNET_SERVER_client_disconnect (s->clients); while (NULL != (hpos = s->handlers)) - { - s->handlers = hpos->next; - GNUNET_free (hpos); - } + { + s->handlers = hpos->next; + GNUNET_free (hpos); + } while (NULL != (npos = s->disconnect_notify_list)) - { - npos->callback (npos->callback_cls, NULL); - s->disconnect_notify_list = npos->next; - GNUNET_free (npos); - } + { + npos->callback (npos->callback_cls, NULL); + s->disconnect_notify_list = npos->next; + GNUNET_free (npos); + } GNUNET_free (s); } @@ -590,8 +586,7 @@ GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *s) */ void GNUNET_SERVER_add_handlers (struct GNUNET_SERVER_Handle *server, - const struct GNUNET_SERVER_MessageHandler - *handlers) + const struct GNUNET_SERVER_MessageHandler *handlers) { struct HandlerList *p; @@ -609,21 +604,20 @@ GNUNET_SERVER_add_handlers (struct GNUNET_SERVER_Handle *server, * @param tc scheduler context (unused) */ static void -warn_no_receive_done (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +warn_no_receive_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_SERVER_Client *client = cls; client->warn_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, - &warn_no_receive_done, client); + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, + &warn_no_receive_done, client); if (0 == (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) LOG (GNUNET_ERROR_TYPE_WARNING, - _ - ("Processing code for message of type %u did not call GNUNET_SERVER_receive_done after %llums\n"), - (unsigned int) client->warn_type, - (unsigned long long) - GNUNET_TIME_absolute_get_duration (client->warn_start).rel_value); + _ + ("Processing code for message of type %u did not call GNUNET_SERVER_receive_done after %llums\n"), + (unsigned int) client->warn_type, + (unsigned long long) + GNUNET_TIME_absolute_get_duration (client->warn_start).rel_value); } @@ -635,14 +629,13 @@ warn_no_receive_done (void *cls, * @param client client for which to disable the warning */ void -GNUNET_SERVER_disable_receive_done_warning (struct GNUNET_SERVER_Client - *client) +GNUNET_SERVER_disable_receive_done_warning (struct GNUNET_SERVER_Client *client) { if (GNUNET_SCHEDULER_NO_TASK != client->warn_task) - { - GNUNET_SCHEDULER_cancel (client->warn_task); - client->warn_task = GNUNET_SCHEDULER_NO_TASK; - } + { + GNUNET_SCHEDULER_cancel (client->warn_task); + client->warn_task = GNUNET_SCHEDULER_NO_TASK; + } } @@ -663,8 +656,8 @@ GNUNET_SERVER_disable_receive_done_warning (struct GNUNET_SERVER_Client */ int GNUNET_SERVER_inject (struct GNUNET_SERVER_Handle *server, - struct GNUNET_SERVER_Client *sender, - const struct GNUNET_MessageHeader *message) + struct GNUNET_SERVER_Client *sender, + const struct GNUNET_MessageHeader *message) { struct HandlerList *pos; const struct GNUNET_SERVER_MessageHandler *mh; @@ -684,50 +677,49 @@ GNUNET_SERVER_inject (struct GNUNET_SERVER_Handle *server, pos = server->handlers; found = GNUNET_NO; while (pos != NULL) + { + i = 0; + while (pos->handlers[i].callback != NULL) { - i = 0; - while (pos->handlers[i].callback != NULL) - { - mh = &pos->handlers[i]; - if ((mh->type == type) || (mh->type == GNUNET_MESSAGE_TYPE_ALL)) - { - if ((mh->expected_size != 0) && (mh->expected_size != size)) - { + mh = &pos->handlers[i]; + if ((mh->type == type) || (mh->type == GNUNET_MESSAGE_TYPE_ALL)) + { + if ((mh->expected_size != 0) && (mh->expected_size != size)) + { #if GNUNET8_NETWORK_IS_DEAD - LOG (GNUNET_ERROR_TYPE_WARNING, - "Expected %u bytes for message of type %u, got %u\n", - mh->expected_size, mh->type, size); - GNUNET_break_op (0); + LOG (GNUNET_ERROR_TYPE_WARNING, + "Expected %u bytes for message of type %u, got %u\n", + mh->expected_size, mh->type, size); + GNUNET_break_op (0); #endif - return GNUNET_SYSERR; - } - if (sender != NULL) - { - if (0 == sender->suspended) - { - sender->warn_start = GNUNET_TIME_absolute_get (); - sender->warn_task = - GNUNET_SCHEDULER_add_delayed - (GNUNET_TIME_UNIT_MINUTES, &warn_no_receive_done, - sender); - sender->warn_type = type; - } - sender->suspended++; - } - mh->callback (mh->callback_cls, sender, message); - found = GNUNET_YES; - } - i++; - } - pos = pos->next; + return GNUNET_SYSERR; + } + if (sender != NULL) + { + if (0 == sender->suspended) + { + sender->warn_start = GNUNET_TIME_absolute_get (); + sender->warn_task = + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, + &warn_no_receive_done, sender); + sender->warn_type = type; + } + sender->suspended++; + } + mh->callback (mh->callback_cls, sender, message); + found = GNUNET_YES; + } + i++; } + pos = pos->next; + } if (found == GNUNET_NO) - { - LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, - "Received message of unknown type %d\n", type); - if (server->require_found == GNUNET_YES) - return GNUNET_SYSERR; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, + "Received message of unknown type %d\n", type); + if (server->require_found == GNUNET_YES) + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -744,8 +736,7 @@ GNUNET_SERVER_inject (struct GNUNET_SERVER_Handle *server, */ static void process_incoming (void *cls, const void *buf, size_t available, - const struct sockaddr *addr, socklen_t addrlen, - int errCode); + const struct sockaddr *addr, socklen_t addrlen, int errCode); /** @@ -765,30 +756,30 @@ static void process_mst (struct GNUNET_SERVER_Client *client, int ret) { while ((ret != GNUNET_SYSERR) && (client->server != NULL) && - (GNUNET_YES != client->shutdown_now) && (0 == client->suspended)) + (GNUNET_YES != client->shutdown_now) && (0 == client->suspended)) + { + if (ret == GNUNET_OK) { - if (ret == GNUNET_OK) - { - client->receive_pending = GNUNET_YES; -#if DEBUG_SERVER - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Server re-enters receive loop, timeout: %llu.\n", - client->idle_timeout.rel_value); -#endif - GNUNET_CONNECTION_receive (client->connection, - GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, - client->idle_timeout, &process_incoming, - client); - break; - } + client->receive_pending = GNUNET_YES; #if DEBUG_SERVER LOG (GNUNET_ERROR_TYPE_DEBUG, - "Server processes additional messages instantly.\n"); + "Server re-enters receive loop, timeout: %llu.\n", + client->idle_timeout.rel_value); #endif - ret = - GNUNET_SERVER_mst_receive (client->mst, client, NULL, 0, GNUNET_NO, - GNUNET_YES); + GNUNET_CONNECTION_receive (client->connection, + GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, + client->idle_timeout, &process_incoming, + client); + break; } +#if DEBUG_SERVER + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Server processes additional messages instantly.\n"); +#endif + ret = + GNUNET_SERVER_mst_receive (client->mst, client, NULL, 0, GNUNET_NO, + GNUNET_YES); + } #if DEBUG_SERVER LOG (GNUNET_ERROR_TYPE_DEBUG, "Server leaves instant processing loop: ret = %d, server = %p, shutdown = %d, suspended = %u\n", @@ -796,13 +787,13 @@ process_mst (struct GNUNET_SERVER_Client *client, int ret) #endif if (ret == GNUNET_NO) - { + { #if DEBUG_SERVER - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Server has more data pending but is suspended.\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Server has more data pending but is suspended.\n"); #endif - client->receive_pending = GNUNET_SYSERR; /* data pending */ - } + client->receive_pending = GNUNET_SYSERR; /* data pending */ + } if ((ret == GNUNET_SYSERR) || (GNUNET_YES == client->shutdown_now)) GNUNET_SERVER_client_disconnect (client); GNUNET_SERVER_client_drop (client); @@ -821,7 +812,7 @@ process_mst (struct GNUNET_SERVER_Client *client, int ret) */ static void process_incoming (void *cls, const void *buf, size_t available, - const struct sockaddr *addr, socklen_t addrlen, int errCode) + const struct sockaddr *addr, socklen_t addrlen, int errCode) { struct GNUNET_SERVER_Client *client = cls; struct GNUNET_SERVER_Handle *server = client->server; @@ -832,35 +823,34 @@ process_incoming (void *cls, const void *buf, size_t available, GNUNET_assert (client->receive_pending == GNUNET_YES); client->receive_pending = GNUNET_NO; now = GNUNET_TIME_absolute_get (); - end = - GNUNET_TIME_absolute_add (client->last_activity, client->idle_timeout); + end = GNUNET_TIME_absolute_add (client->last_activity, client->idle_timeout); if ((buf == NULL) && (available == 0) && (addr == NULL) && (errCode == 0) && (client->shutdown_now != GNUNET_YES) && (server != NULL) && (GNUNET_YES == GNUNET_CONNECTION_check (client->connection)) && (end.abs_value > now.abs_value)) - { - /* wait longer, timeout changed (i.e. due to us sending) */ + { + /* wait longer, timeout changed (i.e. due to us sending) */ #if DEBUG_SERVER - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Receive time out, but no disconnect due to sending (%p)\n", - GNUNET_a2s (addr, addrlen)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Receive time out, but no disconnect due to sending (%p)\n", + GNUNET_a2s (addr, addrlen)); #endif - client->receive_pending = GNUNET_YES; - GNUNET_CONNECTION_receive (client->connection, - GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, - GNUNET_TIME_absolute_get_remaining (end), - &process_incoming, client); - return; - } - if ((buf == NULL) || (available == 0) || (errCode != 0) || (server == NULL) - || (client->shutdown_now == GNUNET_YES) - || (GNUNET_YES != GNUNET_CONNECTION_check (client->connection))) - { - /* other side closed connection, error connecting, etc. */ - GNUNET_SERVER_client_disconnect (client); - return; - } + client->receive_pending = GNUNET_YES; + GNUNET_CONNECTION_receive (client->connection, + GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, + GNUNET_TIME_absolute_get_remaining (end), + &process_incoming, client); + return; + } + if ((buf == NULL) || (available == 0) || (errCode != 0) || (server == NULL) || + (client->shutdown_now == GNUNET_YES) || + (GNUNET_YES != GNUNET_CONNECTION_check (client->connection))) + { + /* other side closed connection, error connecting, etc. */ + GNUNET_SERVER_client_disconnect (client); + return; + } #if DEBUG_SERVER LOG (GNUNET_ERROR_TYPE_DEBUG, "Server receives %u bytes from `%s'.\n", (unsigned int) available, GNUNET_a2s (addr, addrlen)); @@ -868,8 +858,8 @@ process_incoming (void *cls, const void *buf, size_t available, GNUNET_SERVER_client_keep (client); client->last_activity = now; ret = - GNUNET_SERVER_mst_receive (client->mst, client, buf, available, GNUNET_NO, - GNUNET_YES); + GNUNET_SERVER_mst_receive (client->mst, client, buf, available, GNUNET_NO, + GNUNET_YES); process_mst (client, ret); } @@ -890,23 +880,21 @@ restart_processing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) client->restart_task = GNUNET_SCHEDULER_NO_TASK; if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) && (GNUNET_NO == server->clients_ignore_shutdown)) - { - GNUNET_SERVER_client_disconnect (client); - return; - } + { + GNUNET_SERVER_client_disconnect (client); + return; + } if (client->receive_pending == GNUNET_NO) - { + { #if DEBUG_SERVER - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Server begins to read again from client.\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Server begins to read again from client.\n"); #endif - client->receive_pending = GNUNET_YES; - GNUNET_CONNECTION_receive (client->connection, - GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, - client->idle_timeout, &process_incoming, - client); - return; - } + client->receive_pending = GNUNET_YES; + GNUNET_CONNECTION_receive (client->connection, + GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, + client->idle_timeout, &process_incoming, client); + return; + } #if DEBUG_SERVER LOG (GNUNET_ERROR_TYPE_DEBUG, "Server continues processing messages still in the buffer.\n"); @@ -927,7 +915,7 @@ restart_processing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) */ static void client_message_tokenizer_callback (void *cls, void *client, - const struct GNUNET_MessageHeader *message) + const struct GNUNET_MessageHeader *message) { struct GNUNET_SERVER_Handle *server = cls; struct GNUNET_SERVER_Client *sender = client; @@ -961,14 +949,14 @@ client_message_tokenizer_callback (void *cls, void *client, */ struct GNUNET_SERVER_Client * GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server, - struct GNUNET_CONNECTION_Handle *connection) + struct GNUNET_CONNECTION_Handle *connection) { struct GNUNET_SERVER_Client *client; client = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Client)); client->connection = connection; client->mst = - GNUNET_SERVER_mst_create (&client_message_tokenizer_callback, server); + GNUNET_SERVER_mst_create (&client_message_tokenizer_callback, server); client->reference_count = 1; client->server = server; client->last_activity = GNUNET_TIME_absolute_get (); @@ -979,8 +967,8 @@ GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server, client->callback = NULL; client->callback_cls = NULL; GNUNET_CONNECTION_receive (client->connection, - GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, - client->idle_timeout, &process_incoming, client); + GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, + client->idle_timeout, &process_incoming, client); return client; } @@ -995,7 +983,7 @@ GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server, */ void GNUNET_SERVER_client_set_timeout (struct GNUNET_SERVER_Client *client, - struct GNUNET_TIME_Relative timeout) + struct GNUNET_TIME_Relative timeout) { client->idle_timeout = timeout; } @@ -1043,7 +1031,7 @@ GNUNET_SERVER_client_drop (struct GNUNET_SERVER_Client *client) */ int GNUNET_SERVER_client_get_address (struct GNUNET_SERVER_Client *client, - void **addr, size_t * addrlen) + void **addr, size_t * addrlen) { return GNUNET_CONNECTION_get_address (client->connection, addr, addrlen); } @@ -1061,8 +1049,8 @@ GNUNET_SERVER_client_get_address (struct GNUNET_SERVER_Client *client, */ void GNUNET_SERVER_disconnect_notify (struct GNUNET_SERVER_Handle *server, - GNUNET_SERVER_DisconnectCallback callback, - void *callback_cls) + GNUNET_SERVER_DisconnectCallback callback, + void *callback_cls) { struct NotifyList *n; @@ -1083,8 +1071,8 @@ GNUNET_SERVER_disconnect_notify (struct GNUNET_SERVER_Handle *server, */ void GNUNET_SERVER_disconnect_notify_cancel (struct GNUNET_SERVER_Handle *server, - GNUNET_SERVER_DisconnectCallback - callback, void *callback_cls) + GNUNET_SERVER_DisconnectCallback + callback, void *callback_cls) { struct NotifyList *pos; struct NotifyList *prev; @@ -1092,17 +1080,17 @@ GNUNET_SERVER_disconnect_notify_cancel (struct GNUNET_SERVER_Handle *server, prev = NULL; pos = server->disconnect_notify_list; while (pos != NULL) - { - if ((pos->callback == callback) && (pos->callback_cls == callback_cls)) - break; - prev = pos; - pos = pos->next; - } + { + if ((pos->callback == callback) && (pos->callback_cls == callback_cls)) + break; + prev = pos; + pos = pos->next; + } if (pos == NULL) - { - GNUNET_break (0); - return; - } + { + GNUNET_break (0); + return; + } if (prev == NULL) server->disconnect_notify_list = pos->next; else @@ -1133,72 +1121,72 @@ GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client) "Client is being disconnected from the server.\n"); #endif if (client->restart_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel (client->restart_task); + client->restart_task = GNUNET_SCHEDULER_NO_TASK; + } + if (client->warn_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel (client->warn_task); + client->warn_task = GNUNET_SCHEDULER_NO_TASK; + } + if (GNUNET_YES == client->receive_pending) + { + GNUNET_CONNECTION_receive_cancel (client->connection); + client->receive_pending = GNUNET_NO; + } + + rc = client->reference_count; + if (client->server != NULL) + { + server = client->server; + client->server = NULL; + client->shutdown_now = GNUNET_YES; + prev = NULL; + pos = server->clients; + while ((pos != NULL) && (pos != client)) + { + prev = pos; + pos = pos->next; + } + GNUNET_assert (pos != NULL); + if (prev == NULL) + server->clients = pos->next; + else + prev->next = pos->next; + if (client->restart_task != GNUNET_SCHEDULER_NO_TASK) { GNUNET_SCHEDULER_cancel (client->restart_task); client->restart_task = GNUNET_SCHEDULER_NO_TASK; } - if (client->warn_task != GNUNET_SCHEDULER_NO_TASK) + if (client->warn_task != GNUNET_SCHEDULER_NO_TASK) { GNUNET_SCHEDULER_cancel (client->warn_task); client->warn_task = GNUNET_SCHEDULER_NO_TASK; } - if (GNUNET_YES == client->receive_pending) - { - GNUNET_CONNECTION_receive_cancel (client->connection); - client->receive_pending = GNUNET_NO; - } - - rc = client->reference_count; - if (client->server != NULL) + n = server->disconnect_notify_list; + while (n != NULL) { - server = client->server; - client->server = NULL; - client->shutdown_now = GNUNET_YES; - prev = NULL; - pos = server->clients; - while ((pos != NULL) && (pos != client)) - { - prev = pos; - pos = pos->next; - } - GNUNET_assert (pos != NULL); - if (prev == NULL) - server->clients = pos->next; - else - prev->next = pos->next; - if (client->restart_task != GNUNET_SCHEDULER_NO_TASK) - { - GNUNET_SCHEDULER_cancel (client->restart_task); - client->restart_task = GNUNET_SCHEDULER_NO_TASK; - } - if (client->warn_task != GNUNET_SCHEDULER_NO_TASK) - { - GNUNET_SCHEDULER_cancel (client->warn_task); - client->warn_task = GNUNET_SCHEDULER_NO_TASK; - } - n = server->disconnect_notify_list; - while (n != NULL) - { - n->callback (n->callback_cls, client); - n = n->next; - } + n->callback (n->callback_cls, client); + n = n->next; } + } if (rc > 0) - { + { #if DEBUG_SERVER - LOG (GNUNET_ERROR_TYPE_DEBUG, - "RC still positive, not destroying everything.\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "RC still positive, not destroying everything.\n"); #endif - return; - } + return; + } if (client->in_process_client_buffer == GNUNET_YES) - { + { #if DEBUG_SERVER - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Still processing inputs, not destroying everything.\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Still processing inputs, not destroying everything.\n"); #endif - return; - } + return; + } if (client->persist == GNUNET_YES) GNUNET_CONNECTION_persist_ (client->connection); @@ -1262,17 +1250,17 @@ transmit_ready_callback_wrapper (void *cls, size_t size, void *buf) */ struct GNUNET_CONNECTION_TransmitHandle * GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client, - size_t size, - struct GNUNET_TIME_Relative timeout, - GNUNET_CONNECTION_TransmitReadyNotify - callback, void *callback_cls) + size_t size, + struct GNUNET_TIME_Relative timeout, + GNUNET_CONNECTION_TransmitReadyNotify + callback, void *callback_cls) { client->callback_cls = callback_cls; client->callback = callback; return GNUNET_CONNECTION_notify_transmit_ready (client->connection, size, - timeout, - &transmit_ready_callback_wrapper, - client); + timeout, + &transmit_ready_callback_wrapper, + client); } @@ -1309,47 +1297,46 @@ GNUNET_SERVER_receive_done (struct GNUNET_SERVER_Client *client, int success) GNUNET_assert (client->suspended > 0); client->suspended--; if (success != GNUNET_OK) - { + { #if DEBUG_SERVER - LOG (GNUNET_ERROR_TYPE_DEBUG, - "GNUNET_SERVER_receive_done called with failure indication\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "GNUNET_SERVER_receive_done called with failure indication\n"); #endif - GNUNET_SERVER_client_disconnect (client); - return; - } + GNUNET_SERVER_client_disconnect (client); + return; + } if (client->suspended > 0) - { + { #if DEBUG_SERVER - LOG (GNUNET_ERROR_TYPE_DEBUG, - "GNUNET_SERVER_receive_done called, but more clients pending\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "GNUNET_SERVER_receive_done called, but more clients pending\n"); #endif - return; - } + return; + } if (GNUNET_SCHEDULER_NO_TASK != client->warn_task) - { - GNUNET_SCHEDULER_cancel (client->warn_task); - client->warn_task = GNUNET_SCHEDULER_NO_TASK; - } + { + GNUNET_SCHEDULER_cancel (client->warn_task); + client->warn_task = GNUNET_SCHEDULER_NO_TASK; + } if (client->in_process_client_buffer == GNUNET_YES) - { + { #if DEBUG_SERVER - LOG (GNUNET_ERROR_TYPE_DEBUG, - "GNUNET_SERVER_receive_done called while still in processing loop\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "GNUNET_SERVER_receive_done called while still in processing loop\n"); #endif - return; - } + return; + } if (client->server == NULL) - { - GNUNET_SERVER_client_disconnect (client); - return; - } + { + GNUNET_SERVER_client_disconnect (client); + return; + } #if DEBUG_SERVER LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_SERVER_receive_done causes restart in reading from the socket\n"); #endif GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == client->restart_task); - client->restart_task = - GNUNET_SCHEDULER_add_now (&restart_processing, client); + client->restart_task = GNUNET_SCHEDULER_add_now (&restart_processing, client); } diff --git a/src/util/server_mst.c b/src/util/server_mst.c index 6fd2647d7..dcb8c4810 100644 --- a/src/util/server_mst.c +++ b/src/util/server_mst.c @@ -91,7 +91,7 @@ struct GNUNET_SERVER_MessageStreamTokenizer */ struct GNUNET_SERVER_MessageStreamTokenizer * GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb, - void *cb_cls) + void *cb_cls) { struct GNUNET_SERVER_MessageStreamTokenizer *ret; @@ -121,8 +121,8 @@ GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb, */ int GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst, - void *client_identity, const char *buf, - size_t size, int purge, int one_shot) + void *client_identity, const char *buf, size_t size, + int purge, int one_shot) { const struct GNUNET_MessageHeader *hdr; size_t delta; @@ -140,148 +140,148 @@ GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst, ret = GNUNET_OK; ibuf = (char *) mst->hdr; while (mst->pos > 0) + { +do_align: + if ((mst->curr_buf - mst->off < sizeof (struct GNUNET_MessageHeader)) || + (0 != (mst->off % ALIGN_FACTOR))) { - do_align: - if ((mst->curr_buf - mst->off < sizeof (struct GNUNET_MessageHeader)) || - (0 != (mst->off % ALIGN_FACTOR))) - { - /* need to align or need more space */ - mst->pos -= mst->off; - memmove (ibuf, &ibuf[mst->off], mst->pos); - mst->off = 0; - } - if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader)) - { - delta = - GNUNET_MIN (sizeof (struct GNUNET_MessageHeader) - - (mst->pos - mst->off), size); - memcpy (&ibuf[mst->pos], buf, delta); - mst->pos += delta; - buf += delta; - size -= delta; - } - if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader)) - { - if (purge) - { - mst->off = 0; - mst->pos = 0; - } - return GNUNET_OK; - } - hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off]; + /* need to align or need more space */ + mst->pos -= mst->off; + memmove (ibuf, &ibuf[mst->off], mst->pos); + mst->off = 0; + } + if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader)) + { + delta = + GNUNET_MIN (sizeof (struct GNUNET_MessageHeader) - + (mst->pos - mst->off), size); + memcpy (&ibuf[mst->pos], buf, delta); + mst->pos += delta; + buf += delta; + size -= delta; + } + if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader)) + { + if (purge) + { + mst->off = 0; + mst->pos = 0; + } + return GNUNET_OK; + } + hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off]; + want = ntohs (hdr->size); + if (want < sizeof (struct GNUNET_MessageHeader)) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + if (mst->curr_buf - mst->off < want) + { + /* need more space */ + mst->pos -= mst->off; + memmove (ibuf, &ibuf[mst->off], mst->pos); + mst->off = 0; + } + if (want > mst->curr_buf) + { + mst->hdr = GNUNET_realloc (mst->hdr, want); + ibuf = (char *) mst->hdr; + mst->curr_buf = want; + } + hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off]; + if (mst->pos - mst->off < want) + { + delta = GNUNET_MIN (want - (mst->pos - mst->off), size); + memcpy (&ibuf[mst->pos], buf, delta); + mst->pos += delta; + buf += delta; + size -= delta; + } + if (mst->pos - mst->off < want) + { + if (purge) + { + mst->off = 0; + mst->pos = 0; + } + return GNUNET_OK; + } + if (one_shot == GNUNET_SYSERR) + { + /* cannot call callback again, but return value saying that + * we have another full message in the buffer */ + ret = GNUNET_NO; + goto copy; + } + if (one_shot == GNUNET_YES) + one_shot = GNUNET_SYSERR; + mst->cb (mst->cb_cls, client_identity, hdr); + mst->off += want; + if (mst->off == mst->pos) + { + /* reset to beginning of buffer, it's free right now! */ + mst->off = 0; + mst->pos = 0; + } + } + while (size > 0) + { +#if DEBUG_SERVER_MST + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Server-mst has %u bytes left in inbound buffer\n", + (unsigned int) size); +#endif + if (size < sizeof (struct GNUNET_MessageHeader)) + break; + offset = (unsigned long) buf; + need_align = (0 != offset % ALIGN_FACTOR) ? GNUNET_YES : GNUNET_NO; + if (GNUNET_NO == need_align) + { + /* can try to do zero-copy and process directly from original buffer */ + hdr = (const struct GNUNET_MessageHeader *) buf; want = ntohs (hdr->size); if (want < sizeof (struct GNUNET_MessageHeader)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - if (mst->curr_buf - mst->off < want) - { - /* need more space */ - mst->pos -= mst->off; - memmove (ibuf, &ibuf[mst->off], mst->pos); - mst->off = 0; - } - if (want > mst->curr_buf) - { - mst->hdr = GNUNET_realloc (mst->hdr, want); - ibuf = (char *) mst->hdr; - mst->curr_buf = want; - } - hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off]; - if (mst->pos - mst->off < want) - { - delta = GNUNET_MIN (want - (mst->pos - mst->off), size); - memcpy (&ibuf[mst->pos], buf, delta); - mst->pos += delta; - buf += delta; - size -= delta; - } - if (mst->pos - mst->off < want) - { - if (purge) - { - mst->off = 0; - mst->pos = 0; - } - return GNUNET_OK; - } + { + GNUNET_break_op (0); + mst->off = 0; + return GNUNET_SYSERR; + } + if (size < want) + break; /* or not, buffer incomplete, so copy to private buffer... */ if (one_shot == GNUNET_SYSERR) - { - /* cannot call callback again, but return value saying that - * we have another full message in the buffer */ - ret = GNUNET_NO; - goto copy; - } + { + /* cannot call callback again, but return value saying that + * we have another full message in the buffer */ + ret = GNUNET_NO; + goto copy; + } if (one_shot == GNUNET_YES) - one_shot = GNUNET_SYSERR; + one_shot = GNUNET_SYSERR; mst->cb (mst->cb_cls, client_identity, hdr); - mst->off += want; - if (mst->off == mst->pos) - { - /* reset to beginning of buffer, it's free right now! */ - mst->off = 0; - mst->pos = 0; - } + buf += want; + size -= want; } - while (size > 0) + else { -#if DEBUG_SERVER_MST - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Server-mst has %u bytes left in inbound buffer\n", - (unsigned int) size); -#endif - if (size < sizeof (struct GNUNET_MessageHeader)) - break; - offset = (unsigned long) buf; - need_align = (0 != offset % ALIGN_FACTOR) ? GNUNET_YES : GNUNET_NO; - if (GNUNET_NO == need_align) - { - /* can try to do zero-copy and process directly from original buffer */ - hdr = (const struct GNUNET_MessageHeader *) buf; - want = ntohs (hdr->size); - if (want < sizeof (struct GNUNET_MessageHeader)) - { - GNUNET_break_op (0); - mst->off = 0; - return GNUNET_SYSERR; - } - if (size < want) - break; /* or not, buffer incomplete, so copy to private buffer... */ - if (one_shot == GNUNET_SYSERR) - { - /* cannot call callback again, but return value saying that - * we have another full message in the buffer */ - ret = GNUNET_NO; - goto copy; - } - if (one_shot == GNUNET_YES) - one_shot = GNUNET_SYSERR; - mst->cb (mst->cb_cls, client_identity, hdr); - buf += want; - size -= want; - } - else - { - /* need to copy to private buffer to align; - * yes, we go a bit more spagetti than usual here */ - goto do_align; - } + /* need to copy to private buffer to align; + * yes, we go a bit more spagetti than usual here */ + goto do_align; } + } copy: if ((size > 0) && (!purge)) + { + if (size + mst->pos > mst->curr_buf) { - if (size + mst->pos > mst->curr_buf) - { - mst->hdr = GNUNET_realloc (mst->hdr, size + mst->pos); - ibuf = (char *) mst->hdr; - mst->curr_buf = size + mst->pos; - } - GNUNET_assert (mst->pos + size <= mst->curr_buf); - memcpy (&ibuf[mst->pos], buf, size); - mst->pos += size; + mst->hdr = GNUNET_realloc (mst->hdr, size + mst->pos); + ibuf = (char *) mst->hdr; + mst->curr_buf = size + mst->pos; } + GNUNET_assert (mst->pos + size <= mst->curr_buf); + memcpy (&ibuf[mst->pos], buf, size); + mst->pos += size; + } if (purge) mst->off = 0; #if DEBUG_SERVER_MST diff --git a/src/util/server_nc.c b/src/util/server_nc.c index cbe98a014..a36fa0c50 100644 --- a/src/util/server_nc.c +++ b/src/util/server_nc.c @@ -156,19 +156,19 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) struct PendingMessageList *pml; if (client == NULL) - { - nc->server = NULL; - return; - } + { + nc->server = NULL; + return; + } prev = NULL; pos = nc->clients; while (NULL != pos) - { - if (pos->client == client) - break; - prev = pos; - pos = pos->next; - } + { + if (pos->client == client) + break; + prev = pos; + pos = pos->next; + } if (pos == NULL) return; #if DEBUG_SERVER_NC @@ -181,15 +181,15 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) else prev->next = pos->next; while (NULL != (pml = pos->pending_head)) - { - GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, pml); - GNUNET_free (pml); - } + { + GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, pml); + GNUNET_free (pml); + } if (pos->th != NULL) - { - GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->th); - pos->th = NULL; - } + { + GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->th); + pos->th = NULL; + } GNUNET_SERVER_client_drop (client); GNUNET_free (pos); } @@ -205,8 +205,8 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) * @return handle to the notification context */ struct GNUNET_SERVER_NotificationContext * -GNUNET_SERVER_notification_context_create (struct GNUNET_SERVER_Handle - *server, unsigned int queue_length) +GNUNET_SERVER_notification_context_create (struct GNUNET_SERVER_Handle *server, + unsigned int queue_length) { struct GNUNET_SERVER_NotificationContext *ret; @@ -225,27 +225,26 @@ GNUNET_SERVER_notification_context_create (struct GNUNET_SERVER_Handle */ void GNUNET_SERVER_notification_context_destroy (struct - GNUNET_SERVER_NotificationContext - *nc) + GNUNET_SERVER_NotificationContext + *nc) { struct ClientList *pos; struct PendingMessageList *pml; while (NULL != (pos = nc->clients)) + { + nc->clients = pos->next; + GNUNET_SERVER_client_drop (pos->client); + while (NULL != (pml = pos->pending_head)) { - nc->clients = pos->next; - GNUNET_SERVER_client_drop (pos->client); - while (NULL != (pml = pos->pending_head)) - { - GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, - pml); - GNUNET_free (pml); - } - GNUNET_free (pos); + GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, pml); + GNUNET_free (pml); } + GNUNET_free (pos); + } if (nc->server != NULL) GNUNET_SERVER_disconnect_notify_cancel (nc->server, - &handle_client_disconnect, nc); + &handle_client_disconnect, nc); GNUNET_free (nc); } @@ -257,9 +256,9 @@ GNUNET_SERVER_notification_context_destroy (struct * @param client client to add */ void -GNUNET_SERVER_notification_context_add (struct - GNUNET_SERVER_NotificationContext *nc, - struct GNUNET_SERVER_Client *client) +GNUNET_SERVER_notification_context_add (struct GNUNET_SERVER_NotificationContext + *nc, + struct GNUNET_SERVER_Client *client) { struct ClientList *cl; @@ -293,45 +292,44 @@ transmit_message (void *cls, size_t size, void *buf) cl->th = NULL; if (buf == NULL) - { - /* 'cl' should be freed via disconnect notification shortly */ + { + /* 'cl' should be freed via disconnect notification shortly */ #if DEBUG_SERVER_NC - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Failed to transmit message from NC queue to client\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Failed to transmit message from NC queue to client\n"); #endif - return 0; - } + return 0; + } ret = 0; while (NULL != (pml = cl->pending_head)) - { - msize = ntohs (pml->msg->size); - if (size < msize) - break; - GNUNET_CONTAINER_DLL_remove (cl->pending_head, cl->pending_tail, pml); + { + msize = ntohs (pml->msg->size); + if (size < msize) + break; + GNUNET_CONTAINER_DLL_remove (cl->pending_head, cl->pending_tail, pml); #if DEBUG_SERVER_NC - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Copying message of type %u and size %u from pending queue to transmission buffer\n", - ntohs (pml->msg->type), msize); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Copying message of type %u and size %u from pending queue to transmission buffer\n", + ntohs (pml->msg->type), msize); #endif - memcpy (&cbuf[ret], pml->msg, msize); - ret += msize; - size -= msize; - GNUNET_free (pml); - cl->num_pending--; - } + memcpy (&cbuf[ret], pml->msg, msize); + ret += msize; + size -= msize; + GNUNET_free (pml); + cl->num_pending--; + } if (pml != NULL) - { + { #if DEBUG_SERVER_NC - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Have %u messages left in NC queue, will try transmission again\n", - cl->num_pending); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Have %u messages left in NC queue, will try transmission again\n", + cl->num_pending); #endif - cl->th = - GNUNET_SERVER_notify_transmit_ready (cl->client, - ntohs (pml->msg->size), - GNUNET_TIME_UNIT_FOREVER_REL, - &transmit_message, cl); - } + cl->th = + GNUNET_SERVER_notify_transmit_ready (cl->client, ntohs (pml->msg->size), + GNUNET_TIME_UNIT_FOREVER_REL, + &transmit_message, cl); + } else GNUNET_assert (cl->num_pending == 0); return ret; @@ -348,25 +346,24 @@ transmit_message (void *cls, size_t size, void *buf) */ static void do_unicast (struct GNUNET_SERVER_NotificationContext *nc, - struct ClientList *client, const struct GNUNET_MessageHeader *msg, - int can_drop) + struct ClientList *client, const struct GNUNET_MessageHeader *msg, + int can_drop) { struct PendingMessageList *pml; uint16_t size; if ((client->num_pending > nc->queue_length) && (GNUNET_YES == can_drop)) - { - LOG (GNUNET_ERROR_TYPE_INFO, - "Dropping message of type %u and size %u due to full queue (%u entries)\n", - ntohs (msg->type), ntohs (msg->size), - (unsigned int) nc->queue_length); - return; /* drop! */ - } + { + LOG (GNUNET_ERROR_TYPE_INFO, + "Dropping message of type %u and size %u due to full queue (%u entries)\n", + ntohs (msg->type), ntohs (msg->size), (unsigned int) nc->queue_length); + return; /* drop! */ + } if (client->num_pending > nc->queue_length) - { - /* FIXME: consider checking for other messages in the - * queue that are 'droppable' */ - } + { + /* FIXME: consider checking for other messages in the + * queue that are 'droppable' */ + } client->num_pending++; size = ntohs (msg->size); pml = GNUNET_malloc (sizeof (struct PendingMessageList) + size); @@ -379,15 +376,15 @@ do_unicast (struct GNUNET_SERVER_NotificationContext *nc, #endif memcpy (&pml[1], msg, size); /* append */ - GNUNET_CONTAINER_DLL_insert_tail (client->pending_head, - client->pending_tail, pml); + GNUNET_CONTAINER_DLL_insert_tail (client->pending_head, client->pending_tail, + pml); if (client->th == NULL) client->th = - GNUNET_SERVER_notify_transmit_ready (client->client, - ntohs (client->pending_head-> - msg->size), - GNUNET_TIME_UNIT_FOREVER_REL, - &transmit_message, client); + GNUNET_SERVER_notify_transmit_ready (client->client, + ntohs (client->pending_head-> + msg->size), + GNUNET_TIME_UNIT_FOREVER_REL, + &transmit_message, client); } @@ -402,22 +399,21 @@ do_unicast (struct GNUNET_SERVER_NotificationContext *nc, */ void GNUNET_SERVER_notification_context_unicast (struct - GNUNET_SERVER_NotificationContext - *nc, - struct GNUNET_SERVER_Client - *client, - const struct GNUNET_MessageHeader - *msg, int can_drop) + GNUNET_SERVER_NotificationContext + *nc, + struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader + *msg, int can_drop) { struct ClientList *pos; pos = nc->clients; while (NULL != pos) - { - if (pos->client == client) - break; - pos = pos->next; - } + { + if (pos->client == client) + break; + pos = pos->next; + } GNUNET_assert (pos != NULL); do_unicast (nc, pos, msg, can_drop); } @@ -432,20 +428,19 @@ GNUNET_SERVER_notification_context_unicast (struct */ void GNUNET_SERVER_notification_context_broadcast (struct - GNUNET_SERVER_NotificationContext - *nc, - const struct - GNUNET_MessageHeader *msg, - int can_drop) + GNUNET_SERVER_NotificationContext + *nc, + const struct GNUNET_MessageHeader + *msg, int can_drop) { struct ClientList *pos; pos = nc->clients; while (NULL != pos) - { - do_unicast (nc, pos, msg, can_drop); - pos = pos->next; - } + { + do_unicast (nc, pos, msg, can_drop); + pos = pos->next; + } } diff --git a/src/util/server_tc.c b/src/util/server_tc.c index 020fd86db..ce40db19c 100644 --- a/src/util/server_tc.c +++ b/src/util/server_tc.c @@ -83,10 +83,10 @@ transmit_response (void *cls, size_t size, void *buf) size_t msize; if (buf == NULL) - { - GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR); - return 0; - } + { + GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR); + return 0; + } if (tc->total - tc->off > size) msize = size; else @@ -94,28 +94,27 @@ transmit_response (void *cls, size_t size, void *buf) memcpy (buf, &tc->buf[tc->off], msize); tc->off += msize; if (tc->total == tc->off) - { + { - GNUNET_SERVER_receive_done (tc->client, GNUNET_OK); - GNUNET_SERVER_client_drop (tc->client); - GNUNET_free_non_null (tc->buf); - GNUNET_free (tc); - } + GNUNET_SERVER_receive_done (tc->client, GNUNET_OK); + GNUNET_SERVER_client_drop (tc->client); + GNUNET_free_non_null (tc->buf); + GNUNET_free (tc); + } else + { + if (NULL == + GNUNET_SERVER_notify_transmit_ready (tc->client, + GNUNET_MIN (MIN_BLOCK_SIZE, + tc->total - tc->off), + GNUNET_TIME_absolute_get_remaining + (tc->timeout), &transmit_response, + tc)) { - if (NULL == - GNUNET_SERVER_notify_transmit_ready (tc->client, - GNUNET_MIN (MIN_BLOCK_SIZE, - tc->total - - tc->off), - GNUNET_TIME_absolute_get_remaining - (tc->timeout), - &transmit_response, tc)) - { - GNUNET_break (0); - GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR); - } + GNUNET_break (0); + GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR); } + } return msize; } @@ -151,10 +150,9 @@ GNUNET_SERVER_transmit_context_create (struct GNUNET_SERVER_Client *client) * @param type type of the message */ void -GNUNET_SERVER_transmit_context_append_data (struct - GNUNET_SERVER_TransmitContext *tc, - const void *data, size_t length, - uint16_t type) +GNUNET_SERVER_transmit_context_append_data (struct GNUNET_SERVER_TransmitContext + *tc, const void *data, + size_t length, uint16_t type) { struct GNUNET_MessageHeader *msg; size_t size; @@ -181,10 +179,10 @@ GNUNET_SERVER_transmit_context_append_data (struct */ void GNUNET_SERVER_transmit_context_append_message (struct - GNUNET_SERVER_TransmitContext - *tc, - const struct - GNUNET_MessageHeader *msg) + GNUNET_SERVER_TransmitContext + *tc, + const struct GNUNET_MessageHeader + *msg) { struct GNUNET_MessageHeader *m; uint16_t size; @@ -208,18 +206,18 @@ GNUNET_SERVER_transmit_context_append_message (struct */ void GNUNET_SERVER_transmit_context_run (struct GNUNET_SERVER_TransmitContext *tc, - struct GNUNET_TIME_Relative timeout) + struct GNUNET_TIME_Relative timeout) { tc->timeout = GNUNET_TIME_relative_to_absolute (timeout); if (NULL == GNUNET_SERVER_notify_transmit_ready (tc->client, - GNUNET_MIN (MIN_BLOCK_SIZE, - tc->total), timeout, - &transmit_response, tc)) - { - GNUNET_break (0); - GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR); - } + GNUNET_MIN (MIN_BLOCK_SIZE, + tc->total), timeout, + &transmit_response, tc)) + { + GNUNET_break (0); + GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR); + } } @@ -237,7 +235,7 @@ GNUNET_SERVER_transmit_context_run (struct GNUNET_SERVER_TransmitContext *tc, */ void GNUNET_SERVER_transmit_context_destroy (struct GNUNET_SERVER_TransmitContext - *tc, int success) + *tc, int success) { GNUNET_SERVER_receive_done (tc->client, success); GNUNET_SERVER_client_drop (tc->client); diff --git a/src/util/service.c b/src/util/service.c index 7cafe35c8..cf1002ca9 100644 --- a/src/util/service.c +++ b/src/util/service.c @@ -104,121 +104,119 @@ parse_ipv4_specification (const char *routeList) i = 0; pos = 0; while (i < count) + { + cnt = + sscanf (&routeList[pos], "%u.%u.%u.%u/%u.%u.%u.%u;", &temps[0], + &temps[1], &temps[2], &temps[3], &temps[4], &temps[5], + &temps[6], &temps[7]); + if (cnt == 8) { - cnt = - sscanf (&routeList[pos], "%u.%u.%u.%u/%u.%u.%u.%u;", &temps[0], - &temps[1], &temps[2], &temps[3], &temps[4], &temps[5], - &temps[6], &temps[7]); - if (cnt == 8) - { - for (j = 0; j < 8; j++) - if (temps[j] > 0xFF) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Invalid format for IP: `%s'\n"), &routeList[pos]); - GNUNET_free (result); - return NULL; - } - result[i].network.s_addr = - htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) + - temps[3]); - result[i].netmask.s_addr = - htonl ((temps[4] << 24) + (temps[5] << 16) + (temps[6] << 8) + - temps[7]); - while (routeList[pos] != ';') - pos++; - pos++; - i++; - continue; - } - /* try second notation */ - cnt = - sscanf (&routeList[pos], "%u.%u.%u.%u/%u;", &temps[0], &temps[1], - &temps[2], &temps[3], &slash); - if (cnt == 5) - { - for (j = 0; j < 4; j++) - if (temps[j] > 0xFF) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Invalid format for IP: `%s'\n"), &routeList[pos]); - GNUNET_free (result); - return NULL; - } - result[i].network.s_addr = - htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) + - temps[3]); - if ((slash <= 32) && (slash >= 0)) - { - result[i].netmask.s_addr = 0; - while (slash > 0) - { - result[i].netmask.s_addr = - (result[i].netmask.s_addr >> 1) + 0x80000000; - slash--; - } - result[i].netmask.s_addr = htonl (result[i].netmask.s_addr); - while (routeList[pos] != ';') - pos++; - pos++; - i++; - continue; - } - else - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _ - ("Invalid network notation ('/%d' is not legal in IPv4 CIDR)."), - slash); - GNUNET_free (result); - return NULL; /* error */ - } - } - /* try third notation */ - slash = 32; - cnt = - sscanf (&routeList[pos], "%u.%u.%u.%u;", &temps[0], &temps[1], - &temps[2], &temps[3]); - if (cnt == 4) - { - for (j = 0; j < 4; j++) - if (temps[j] > 0xFF) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Invalid format for IP: `%s'\n"), &routeList[pos]); - GNUNET_free (result); - return NULL; - } - result[i].network.s_addr = - htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) + - temps[3]); - result[i].netmask.s_addr = 0; - while (slash > 0) - { - result[i].netmask.s_addr = - (result[i].netmask.s_addr >> 1) + 0x80000000; - slash--; - } - result[i].netmask.s_addr = htonl (result[i].netmask.s_addr); - while (routeList[pos] != ';') - pos++; - pos++; - i++; - continue; - } - LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid format for IP: `%s'\n"), - &routeList[pos]); - GNUNET_free (result); - return NULL; /* error */ + for (j = 0; j < 8; j++) + if (temps[j] > 0xFF) + { + LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid format for IP: `%s'\n"), + &routeList[pos]); + GNUNET_free (result); + return NULL; + } + result[i].network.s_addr = + htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) + + temps[3]); + result[i].netmask.s_addr = + htonl ((temps[4] << 24) + (temps[5] << 16) + (temps[6] << 8) + + temps[7]); + while (routeList[pos] != ';') + pos++; + pos++; + i++; + continue; } - if (pos < strlen (routeList)) + /* try second notation */ + cnt = + sscanf (&routeList[pos], "%u.%u.%u.%u/%u;", &temps[0], &temps[1], + &temps[2], &temps[3], &slash); + if (cnt == 5) { - LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid format for IP: `%s'\n"), - &routeList[pos]); - GNUNET_free (result); - return NULL; /* oops */ + for (j = 0; j < 4; j++) + if (temps[j] > 0xFF) + { + LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid format for IP: `%s'\n"), + &routeList[pos]); + GNUNET_free (result); + return NULL; + } + result[i].network.s_addr = + htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) + + temps[3]); + if ((slash <= 32) && (slash >= 0)) + { + result[i].netmask.s_addr = 0; + while (slash > 0) + { + result[i].netmask.s_addr = + (result[i].netmask.s_addr >> 1) + 0x80000000; + slash--; + } + result[i].netmask.s_addr = htonl (result[i].netmask.s_addr); + while (routeList[pos] != ';') + pos++; + pos++; + i++; + continue; + } + else + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Invalid network notation ('/%d' is not legal in IPv4 CIDR)."), + slash); + GNUNET_free (result); + return NULL; /* error */ + } } - return result; /* ok */ + /* try third notation */ + slash = 32; + cnt = + sscanf (&routeList[pos], "%u.%u.%u.%u;", &temps[0], &temps[1], + &temps[2], &temps[3]); + if (cnt == 4) + { + for (j = 0; j < 4; j++) + if (temps[j] > 0xFF) + { + LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid format for IP: `%s'\n"), + &routeList[pos]); + GNUNET_free (result); + return NULL; + } + result[i].network.s_addr = + htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) + + temps[3]); + result[i].netmask.s_addr = 0; + while (slash > 0) + { + result[i].netmask.s_addr = (result[i].netmask.s_addr >> 1) + 0x80000000; + slash--; + } + result[i].netmask.s_addr = htonl (result[i].netmask.s_addr); + while (routeList[pos] != ';') + pos++; + pos++; + i++; + continue; + } + LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid format for IP: `%s'\n"), + &routeList[pos]); + GNUNET_free (result); + return NULL; /* error */ + } + if (pos < strlen (routeList)) + { + LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid format for IP: `%s'\n"), + &routeList[pos]); + GNUNET_free (result); + return NULL; /* oops */ + } + return result; /* ok */ } @@ -260,85 +258,82 @@ parse_ipv6_specification (const char *routeListX) if (routeList[i] == ';') count++; if (routeList[len - 1] != ';') - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Invalid network notation (does not end with ';': `%s')\n"), - routeList); - GNUNET_free (routeList); - return NULL; - } + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Invalid network notation (does not end with ';': `%s')\n"), + routeList); + GNUNET_free (routeList); + return NULL; + } result = GNUNET_malloc (sizeof (struct IPv6NetworkSet) * (count + 1)); memset (result, 0, sizeof (struct IPv6NetworkSet) * (count + 1)); i = 0; pos = 0; while (i < count) + { + start = pos; + while (routeList[pos] != ';') + pos++; + slash = pos; + while ((slash >= start) && (routeList[slash] != '/')) + slash--; + if (slash < start) { - start = pos; - while (routeList[pos] != ';') - pos++; + memset (&result[i].netmask, 0xFF, sizeof (struct in6_addr)); slash = pos; - while ((slash >= start) && (routeList[slash] != '/')) - slash--; - if (slash < start) - { - memset (&result[i].netmask, 0xFF, sizeof (struct in6_addr)); - slash = pos; - } - else - { - routeList[pos] = '\0'; - ret = - inet_pton (AF_INET6, &routeList[slash + 1], &result[i].netmask); - if (ret <= 0) - { - save = errno; - if ((1 != SSCANF (&routeList[slash + 1], "%u", &bits)) - || (bits >= 128)) - { - if (ret == 0) - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Wrong format `%s' for netmask\n"), - &routeList[slash + 1]); - else - { - errno = save; - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "inet_pton"); - } - GNUNET_free (result); - GNUNET_free (routeList); - return NULL; - } - off = 0; - while (bits > 8) - { - result[i].netmask.s6_addr[off++] = 0xFF; - bits -= 8; - } - while (bits > 0) - { - result[i].netmask.s6_addr[off] = - (result[i].netmask.s6_addr[off] >> 1) + 0x80; - bits--; - } - } - } - routeList[slash] = '\0'; - ret = inet_pton (AF_INET6, &routeList[start], &result[i].network); + } + else + { + routeList[pos] = '\0'; + ret = inet_pton (AF_INET6, &routeList[slash + 1], &result[i].netmask); if (ret <= 0) - { - if (ret == 0) - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Wrong format `%s' for network\n"), &routeList[slash + 1]); - else - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "inet_pton"); - GNUNET_free (result); - GNUNET_free (routeList); - return NULL; - } - pos++; - i++; + { + save = errno; + if ((1 != SSCANF (&routeList[slash + 1], "%u", &bits)) || (bits >= 128)) + { + if (ret == 0) + LOG (GNUNET_ERROR_TYPE_ERROR, _("Wrong format `%s' for netmask\n"), + &routeList[slash + 1]); + else + { + errno = save; + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "inet_pton"); + } + GNUNET_free (result); + GNUNET_free (routeList); + return NULL; + } + off = 0; + while (bits > 8) + { + result[i].netmask.s6_addr[off++] = 0xFF; + bits -= 8; + } + while (bits > 0) + { + result[i].netmask.s6_addr[off] = + (result[i].netmask.s6_addr[off] >> 1) + 0x80; + bits--; + } + } + } + routeList[slash] = '\0'; + ret = inet_pton (AF_INET6, &routeList[start], &result[i].network); + if (ret <= 0) + { + if (ret == 0) + LOG (GNUNET_ERROR_TYPE_ERROR, _("Wrong format `%s' for network\n"), + &routeList[slash + 1]); + else + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "inet_pton"); + GNUNET_free (result); + GNUNET_free (routeList); + return NULL; } + pos++; + i++; + } GNUNET_free (routeList); return result; } @@ -352,8 +347,7 @@ parse_ipv6_specification (const char *routeListX) * @return GNUNET_NO if the IP is not in the list, GNUNET_YES if it it is */ static int -check_ipv4_listed (const struct IPv4NetworkSet *list, - const struct in_addr *add) +check_ipv4_listed (const struct IPv4NetworkSet *list, const struct in_addr *add) { int i; @@ -362,12 +356,12 @@ check_ipv4_listed (const struct IPv4NetworkSet *list, return GNUNET_NO; while ((list[i].network.s_addr != 0) || (list[i].netmask.s_addr != 0)) - { - if ((add->s_addr & list[i].netmask.s_addr) == - (list[i].network.s_addr & list[i].netmask.s_addr)) - return GNUNET_YES; - i++; - } + { + if ((add->s_addr & list[i].netmask.s_addr) == + (list[i].network.s_addr & list[i].netmask.s_addr)) + return GNUNET_YES; + i++; + } return GNUNET_NO; } @@ -379,8 +373,7 @@ check_ipv4_listed (const struct IPv4NetworkSet *list, * @return GNUNET_NO if the IP is not in the list, GNUNET_YES if it it is */ static int -check_ipv6_listed (const struct IPv6NetworkSet *list, - const struct in6_addr *ip) +check_ipv6_listed (const struct IPv6NetworkSet *list, const struct in6_addr *ip) { unsigned int i; unsigned int j; @@ -393,16 +386,16 @@ check_ipv6_listed (const struct IPv6NetworkSet *list, i = 0; NEXT: while (memcmp (&zero, &list[i].network, sizeof (struct in6_addr)) != 0) - { - for (j = 0; j < sizeof (struct in6_addr) / sizeof (int); j++) - if (((((int *) ip)[j] & ((int *) &list[i].netmask)[j])) != - (((int *) &list[i].network)[j] & ((int *) &list[i].netmask)[j])) - { - i++; - goto NEXT; - } - return GNUNET_YES; - } + { + for (j = 0; j < sizeof (struct in6_addr) / sizeof (int); j++) + if (((((int *) ip)[j] & ((int *) &list[i].netmask)[j])) != + (((int *) &list[i].network)[j] & ((int *) &list[i].netmask)[j])) + { + i++; + goto NEXT; + } + return GNUNET_YES; + } return GNUNET_NO; } @@ -536,10 +529,10 @@ write_test (void *cls, size_t size, void *buf) struct GNUNET_MessageHeader *msg; if (size < sizeof (struct GNUNET_MessageHeader)) - { - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return 0; /* client disconnected */ - } + { + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return 0; /* client disconnected */ + } msg = (struct GNUNET_MessageHeader *) buf; msg->type = htons (GNUNET_MESSAGE_TYPE_TEST); msg->size = htons (sizeof (struct GNUNET_MessageHeader)); @@ -556,15 +549,14 @@ write_test (void *cls, size_t size, void *buf) */ static void handle_test (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) + const struct GNUNET_MessageHeader *message) { /* simply bounce message back to acknowledge */ if (NULL == GNUNET_SERVER_notify_transmit_ready (client, - sizeof (struct - GNUNET_MessageHeader), - GNUNET_TIME_UNIT_FOREVER_REL, - &write_test, client)) + sizeof (struct GNUNET_MessageHeader), + GNUNET_TIME_UNIT_FOREVER_REL, + &write_test, client)) GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); } @@ -597,7 +589,7 @@ static const struct GNUNET_SERVER_MessageHandler defhandlers[] = { */ static int check_access (void *cls, const struct GNUNET_CONNECTION_Credentials *uc, - const struct sockaddr *addr, socklen_t addrlen) + const struct sockaddr *addr, socklen_t addrlen) { struct GNUNET_SERVICE_Context *sctx = cls; const struct sockaddr_in *i4; @@ -605,51 +597,51 @@ check_access (void *cls, const struct GNUNET_CONNECTION_Credentials *uc, int ret; switch (addr->sa_family) - { - case AF_INET: - GNUNET_assert (addrlen == sizeof (struct sockaddr_in)); - i4 = (const struct sockaddr_in *) addr; - ret = ((sctx->v4_allowed == NULL) || - (check_ipv4_listed (sctx->v4_allowed, &i4->sin_addr))) && - ((sctx->v4_denied == NULL) || - (!check_ipv4_listed (sctx->v4_denied, &i4->sin_addr))); - break; - case AF_INET6: - GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); - i6 = (const struct sockaddr_in6 *) addr; - ret = ((sctx->v6_allowed == NULL) || - (check_ipv6_listed (sctx->v6_allowed, &i6->sin6_addr))) && - ((sctx->v6_denied == NULL) || - (!check_ipv6_listed (sctx->v6_denied, &i6->sin6_addr))); - break; + { + case AF_INET: + GNUNET_assert (addrlen == sizeof (struct sockaddr_in)); + i4 = (const struct sockaddr_in *) addr; + ret = ((sctx->v4_allowed == NULL) || + (check_ipv4_listed (sctx->v4_allowed, &i4->sin_addr))) && + ((sctx->v4_denied == NULL) || + (!check_ipv4_listed (sctx->v4_denied, &i4->sin_addr))); + break; + case AF_INET6: + GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); + i6 = (const struct sockaddr_in6 *) addr; + ret = ((sctx->v6_allowed == NULL) || + (check_ipv6_listed (sctx->v6_allowed, &i6->sin6_addr))) && + ((sctx->v6_denied == NULL) || + (!check_ipv6_listed (sctx->v6_denied, &i6->sin6_addr))); + break; #ifndef WINDOWS - case AF_UNIX: - ret = GNUNET_OK; /* always OK for now */ - if ((sctx->match_uid == GNUNET_YES) || (sctx->match_gid == GNUNET_YES)) - ret = GNUNET_NO; - if ((uc != NULL) && - ((sctx->match_uid != GNUNET_YES) || (uc->uid == geteuid ()) || - (uc->uid == getuid ())) && ((sctx->match_gid != GNUNET_YES) || - (uc->gid == getegid ()) || - (uc->gid == getgid ()))) - ret = GNUNET_YES; - else - LOG (GNUNET_ERROR_TYPE_WARNING, - _("Access denied to UID %d / GID %d\n"), - (uc == NULL) ? -1 : uc->uid, (uc == NULL) ? -1 : uc->gid); - break; + case AF_UNIX: + ret = GNUNET_OK; /* always OK for now */ + if ((sctx->match_uid == GNUNET_YES) || (sctx->match_gid == GNUNET_YES)) + ret = GNUNET_NO; + if ((uc != NULL) && + ((sctx->match_uid != GNUNET_YES) || (uc->uid == geteuid ()) || + (uc->uid == getuid ())) && ((sctx->match_gid != GNUNET_YES) || + (uc->gid == getegid ()) || + (uc->gid == getgid ()))) + ret = GNUNET_YES; + else + LOG (GNUNET_ERROR_TYPE_WARNING, _("Access denied to UID %d / GID %d\n"), + (uc == NULL) ? -1 : uc->uid, (uc == NULL) ? -1 : uc->gid); + break; #endif - default: - LOG (GNUNET_ERROR_TYPE_WARNING, _("Unknown address family %d\n"), - addr->sa_family); - return GNUNET_SYSERR; - } + default: + LOG (GNUNET_ERROR_TYPE_WARNING, _("Unknown address family %d\n"), + addr->sa_family); + return GNUNET_SYSERR; + } if (ret != GNUNET_OK) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - _("Access from `%s' denied to service `%s'\n"), - GNUNET_a2s (addr, addrlen), sctx->serviceName); - } + { + LOG (GNUNET_ERROR_TYPE_WARNING, + _("Access from `%s' denied to service `%s'\n"), GNUNET_a2s (addr, + addrlen), + sctx->serviceName); + } return ret; } @@ -666,7 +658,7 @@ get_pid_file_name (struct GNUNET_SERVICE_Context *sctx) if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, sctx->serviceName, - "PIDFILE", &pif)) + "PIDFILE", &pif)) return NULL; return pif; } @@ -676,26 +668,25 @@ get_pid_file_name (struct GNUNET_SERVICE_Context *sctx) * Parse an IPv4 access control list. */ static int -process_acl4 (struct IPv4NetworkSet **ret, - struct GNUNET_SERVICE_Context *sctx, const char *option) +process_acl4 (struct IPv4NetworkSet **ret, struct GNUNET_SERVICE_Context *sctx, + const char *option) { char *opt; if (!GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->serviceName, option)) return GNUNET_OK; GNUNET_break (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_string (sctx->cfg, - sctx->serviceName, - option, &opt)); + GNUNET_CONFIGURATION_get_value_string (sctx->cfg, + sctx->serviceName, + option, &opt)); if (NULL == (*ret = parse_ipv4_specification (opt))) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - _ - ("Could not parse IPv4 network specification `%s' for `%s:%s'\n"), - opt, sctx->serviceName, option); - GNUNET_free (opt); - return GNUNET_SYSERR; - } + { + LOG (GNUNET_ERROR_TYPE_WARNING, + _("Could not parse IPv4 network specification `%s' for `%s:%s'\n"), + opt, sctx->serviceName, option); + GNUNET_free (opt); + return GNUNET_SYSERR; + } GNUNET_free (opt); return GNUNET_OK; } @@ -705,26 +696,25 @@ process_acl4 (struct IPv4NetworkSet **ret, * Parse an IPv4 access control list. */ static int -process_acl6 (struct IPv6NetworkSet **ret, - struct GNUNET_SERVICE_Context *sctx, const char *option) +process_acl6 (struct IPv6NetworkSet **ret, struct GNUNET_SERVICE_Context *sctx, + const char *option) { char *opt; if (!GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->serviceName, option)) return GNUNET_OK; GNUNET_break (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_string (sctx->cfg, - sctx->serviceName, - option, &opt)); + GNUNET_CONFIGURATION_get_value_string (sctx->cfg, + sctx->serviceName, + option, &opt)); if (NULL == (*ret = parse_ipv6_specification (opt))) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - _ - ("Could not parse IPv6 network specification `%s' for `%s:%s'\n"), - opt, sctx->serviceName, option); - GNUNET_free (opt); - return GNUNET_SYSERR; - } + { + LOG (GNUNET_ERROR_TYPE_WARNING, + _("Could not parse IPv6 network specification `%s' for `%s:%s'\n"), + opt, sctx->serviceName, option); + GNUNET_free (opt); + return GNUNET_SYSERR; + } GNUNET_free (opt); return GNUNET_OK; } @@ -739,7 +729,7 @@ process_acl6 (struct IPv6NetworkSet **ret, */ static void add_unixpath (struct sockaddr **saddrs, socklen_t * saddrlens, - const char *unixpath) + const char *unixpath) { #ifdef AF_UNIX struct sockaddr_un *un; @@ -791,9 +781,9 @@ add_unixpath (struct sockaddr **saddrs, socklen_t * saddrlens, */ int GNUNET_SERVICE_get_server_addresses (const char *serviceName, - const struct GNUNET_CONFIGURATION_Handle - *cfg, struct sockaddr ***addrs, - socklen_t ** addr_lens) + const struct GNUNET_CONFIGURATION_Handle + *cfg, struct sockaddr ***addrs, + socklen_t ** addr_lens) { int disablev6; struct GNUNET_NETWORK_Handle *desc; @@ -814,64 +804,61 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName, *addr_lens = NULL; desc = NULL; if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "DISABLEV6")) - { - if (GNUNET_SYSERR == - (disablev6 = - GNUNET_CONFIGURATION_get_value_yesno (cfg, serviceName, - "DISABLEV6"))) - return GNUNET_SYSERR; - } + { + if (GNUNET_SYSERR == + (disablev6 = + GNUNET_CONFIGURATION_get_value_yesno (cfg, serviceName, "DISABLEV6"))) + return GNUNET_SYSERR; + } else disablev6 = GNUNET_NO; if (!disablev6) + { + /* probe IPv6 support */ + desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0); + if (NULL == desc) { - /* probe IPv6 support */ - desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0); - if (NULL == desc) - { - if ((errno == ENOBUFS) || (errno == ENOMEM) || (errno == ENFILE) || - (errno == EACCES)) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket"); - return GNUNET_SYSERR; - } - LOG (GNUNET_ERROR_TYPE_INFO, - _ - ("Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"), - serviceName, STRERROR (errno)); - disablev6 = GNUNET_YES; - } - else - { - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc)); - desc = NULL; - } + if ((errno == ENOBUFS) || (errno == ENOMEM) || (errno == ENFILE) || + (errno == EACCES)) + { + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket"); + return GNUNET_SYSERR; + } + LOG (GNUNET_ERROR_TYPE_INFO, + _ + ("Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"), + serviceName, STRERROR (errno)); + disablev6 = GNUNET_YES; } + else + { + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc)); + desc = NULL; + } + } port = 0; if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "PORT")) + { + GNUNET_break (GNUNET_OK == + GNUNET_CONFIGURATION_get_value_number (cfg, serviceName, + "PORT", &port)); + if (port > 65535) { - GNUNET_break (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_number (cfg, serviceName, - "PORT", &port)); - if (port > 65535) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _ - ("Require valid port number for service `%s' in configuration!\n"), - serviceName); - return GNUNET_SYSERR; - } + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Require valid port number for service `%s' in configuration!\n"), + serviceName); + return GNUNET_SYSERR; } + } if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "BINDTO")) - { - GNUNET_break (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_string (cfg, serviceName, - "BINDTO", - &hostname)); - } + { + GNUNET_break (GNUNET_OK == + GNUNET_CONFIGURATION_get_value_string (cfg, serviceName, + "BINDTO", &hostname)); + } else hostname = NULL; @@ -881,211 +868,210 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName, GNUNET_CONFIGURATION_have_value (cfg, serviceName, "UNIXPATH")) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, serviceName, "UNIXPATH", - &unixpath)) && + &unixpath)) && (0 < strlen (unixpath))) + { + /* probe UNIX support */ + struct sockaddr_un s_un; + + if (strlen (unixpath) >= sizeof (s_un.sun_path)) { - /* probe UNIX support */ - struct sockaddr_un s_un; - - if (strlen (unixpath) >= sizeof (s_un.sun_path)) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - _("UNIXPATH `%s' too long, maximum length is %llu\n"), - unixpath, sizeof (s_un.sun_path)); - GNUNET_free_non_null (hostname); - GNUNET_free (unixpath); - return GNUNET_SYSERR; - } - - desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); - if (NULL == desc) - { - if ((errno == ENOBUFS) || (errno == ENOMEM) || (errno == ENFILE) || - (errno == EACCES)) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket"); - GNUNET_free_non_null (hostname); - GNUNET_free (unixpath); - return GNUNET_SYSERR; - } - LOG (GNUNET_ERROR_TYPE_INFO, - _ - ("Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"), - serviceName, STRERROR (errno)); - GNUNET_free (unixpath); - unixpath = NULL; - } - else - { - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc)); - desc = NULL; - } + LOG (GNUNET_ERROR_TYPE_WARNING, + _("UNIXPATH `%s' too long, maximum length is %llu\n"), unixpath, + sizeof (s_un.sun_path)); + GNUNET_free_non_null (hostname); + GNUNET_free (unixpath); + return GNUNET_SYSERR; + } + + desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); + if (NULL == desc) + { + if ((errno == ENOBUFS) || (errno == ENOMEM) || (errno == ENFILE) || + (errno == EACCES)) + { + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket"); + GNUNET_free_non_null (hostname); + GNUNET_free (unixpath); + return GNUNET_SYSERR; + } + LOG (GNUNET_ERROR_TYPE_INFO, + _ + ("Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"), + serviceName, STRERROR (errno)); + GNUNET_free (unixpath); + unixpath = NULL; + } + else + { + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc)); + desc = NULL; } + } #endif if ((port == 0) && (unixpath == NULL)) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _ + ("Have neither PORT nor UNIXPATH for service `%s', but one is required\n"), + serviceName); + GNUNET_free_non_null (hostname); + return GNUNET_SYSERR; + } + if (port == 0) + { + saddrs = GNUNET_malloc (2 * sizeof (struct sockaddr *)); + saddrlens = GNUNET_malloc (2 * sizeof (socklen_t)); + add_unixpath (saddrs, saddrlens, unixpath); + GNUNET_free_non_null (unixpath); + GNUNET_free_non_null (hostname); + *addrs = saddrs; + *addr_lens = saddrlens; + return 1; + } + + if (hostname != NULL) + { +#if DEBUG_SERVICE + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Resolving `%s' since that is where `%s' will bind to.\n", hostname, + serviceName); +#endif + memset (&hints, 0, sizeof (struct addrinfo)); + if (disablev6) + hints.ai_family = AF_INET; + if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) || + (res == NULL)) { - LOG (GNUNET_ERROR_TYPE_ERROR, - _ - ("Have neither PORT nor UNIXPATH for service `%s', but one is required\n"), - serviceName); - GNUNET_free_non_null (hostname); + LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to resolve `%s': %s\n"), hostname, + gai_strerror (ret)); + GNUNET_free (hostname); + GNUNET_free_non_null (unixpath); return GNUNET_SYSERR; } - if (port == 0) + next = res; + i = 0; + while (NULL != (pos = next)) { - saddrs = GNUNET_malloc (2 * sizeof (struct sockaddr *)); - saddrlens = GNUNET_malloc (2 * sizeof (socklen_t)); - add_unixpath (saddrs, saddrlens, unixpath); + next = pos->ai_next; + if ((disablev6) && (pos->ai_family == AF_INET6)) + continue; + i++; + } + if (0 == i) + { + LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to find %saddress for `%s'.\n"), + disablev6 ? "IPv4 " : "", hostname); + freeaddrinfo (res); + GNUNET_free (hostname); GNUNET_free_non_null (unixpath); - GNUNET_free_non_null (hostname); - *addrs = saddrs; - *addr_lens = saddrlens; - return 1; + return GNUNET_SYSERR; } - - if (hostname != NULL) + resi = i; + if (NULL != unixpath) + resi++; + saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *)); + saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t)); + i = 0; + if (NULL != unixpath) { + add_unixpath (saddrs, saddrlens, unixpath); + i++; + } + next = res; + while (NULL != (pos = next)) + { + next = pos->ai_next; + if ((disablev6) && (pos->ai_family == AF_INET6)) + continue; + if ((pos->ai_protocol != IPPROTO_TCP) && (pos->ai_protocol != 0)) + continue; /* not TCP */ + if ((pos->ai_socktype != SOCK_STREAM) && (pos->ai_socktype != 0)) + continue; /* huh? */ #if DEBUG_SERVICE - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Resolving `%s' since that is where `%s' will bind to.\n", - hostname, serviceName); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Service `%s' will bind to `%s'\n", + serviceName, GNUNET_a2s (pos->ai_addr, pos->ai_addrlen)); #endif - memset (&hints, 0, sizeof (struct addrinfo)); - if (disablev6) - hints.ai_family = AF_INET; - if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) || - (res == NULL)) - { - LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to resolve `%s': %s\n"), - hostname, gai_strerror (ret)); - GNUNET_free (hostname); - GNUNET_free_non_null (unixpath); - return GNUNET_SYSERR; - } - next = res; - i = 0; - while (NULL != (pos = next)) - { - next = pos->ai_next; - if ((disablev6) && (pos->ai_family == AF_INET6)) - continue; - i++; - } - if (0 == i) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Failed to find %saddress for `%s'.\n"), - disablev6 ? "IPv4 " : "", hostname); - freeaddrinfo (res); - GNUNET_free (hostname); - GNUNET_free_non_null (unixpath); - return GNUNET_SYSERR; - } - resi = i; + if (pos->ai_family == AF_INET) + { + GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in)); + saddrlens[i] = pos->ai_addrlen; + saddrs[i] = GNUNET_malloc (saddrlens[i]); + memcpy (saddrs[i], pos->ai_addr, saddrlens[i]); + ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); + } + else + { + GNUNET_assert (pos->ai_family == AF_INET6); + GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in6)); + saddrlens[i] = pos->ai_addrlen; + saddrs[i] = GNUNET_malloc (saddrlens[i]); + memcpy (saddrs[i], pos->ai_addr, saddrlens[i]); + ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port); + } + i++; + } + GNUNET_free (hostname); + freeaddrinfo (res); + resi = i; + } + else + { + /* will bind against everything, just set port */ + if (disablev6) + { + /* V4-only */ + resi = 1; if (NULL != unixpath) - resi++; + resi++; + i = 0; saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *)); saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t)); - i = 0; if (NULL != unixpath) - { - add_unixpath (saddrs, saddrlens, unixpath); - i++; - } - next = res; - while (NULL != (pos = next)) - { - next = pos->ai_next; - if ((disablev6) && (pos->ai_family == AF_INET6)) - continue; - if ((pos->ai_protocol != IPPROTO_TCP) && (pos->ai_protocol != 0)) - continue; /* not TCP */ - if ((pos->ai_socktype != SOCK_STREAM) && (pos->ai_socktype != 0)) - continue; /* huh? */ -#if DEBUG_SERVICE - LOG (GNUNET_ERROR_TYPE_DEBUG, "Service `%s' will bind to `%s'\n", - serviceName, GNUNET_a2s (pos->ai_addr, pos->ai_addrlen)); + { + add_unixpath (saddrs, saddrlens, unixpath); + i++; + } + saddrlens[i] = sizeof (struct sockaddr_in); + saddrs[i] = GNUNET_malloc (saddrlens[i]); +#if HAVE_SOCKADDR_IN_SIN_LEN + ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i]; #endif - if (pos->ai_family == AF_INET) - { - GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in)); - saddrlens[i] = pos->ai_addrlen; - saddrs[i] = GNUNET_malloc (saddrlens[i]); - memcpy (saddrs[i], pos->ai_addr, saddrlens[i]); - ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); - } - else - { - GNUNET_assert (pos->ai_family == AF_INET6); - GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in6)); - saddrlens[i] = pos->ai_addrlen; - saddrs[i] = GNUNET_malloc (saddrlens[i]); - memcpy (saddrs[i], pos->ai_addr, saddrlens[i]); - ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port); - } - i++; - } - GNUNET_free (hostname); - freeaddrinfo (res); - resi = i; + ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET; + ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); } - else + else { - /* will bind against everything, just set port */ - if (disablev6) - { - /* V4-only */ - resi = 1; - if (NULL != unixpath) - resi++; - i = 0; - saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *)); - saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t)); - if (NULL != unixpath) - { - add_unixpath (saddrs, saddrlens, unixpath); - i++; - } - saddrlens[i] = sizeof (struct sockaddr_in); - saddrs[i] = GNUNET_malloc (saddrlens[i]); -#if HAVE_SOCKADDR_IN_SIN_LEN - ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i]; -#endif - ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET; - ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); - } - else - { - /* dual stack */ - resi = 2; - if (NULL != unixpath) - resi++; - saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *)); - saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t)); - i = 0; - if (NULL != unixpath) - { - add_unixpath (saddrs, saddrlens, unixpath); - i++; - } - saddrlens[i] = sizeof (struct sockaddr_in6); - saddrs[i] = GNUNET_malloc (saddrlens[i]); + /* dual stack */ + resi = 2; + if (NULL != unixpath) + resi++; + saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *)); + saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t)); + i = 0; + if (NULL != unixpath) + { + add_unixpath (saddrs, saddrlens, unixpath); + i++; + } + saddrlens[i] = sizeof (struct sockaddr_in6); + saddrs[i] = GNUNET_malloc (saddrlens[i]); #if HAVE_SOCKADDR_IN_SIN_LEN - ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0]; + ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0]; #endif - ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6; - ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port); - i++; - saddrlens[i] = sizeof (struct sockaddr_in); - saddrs[i] = GNUNET_malloc (saddrlens[i]); + ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6; + ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port); + i++; + saddrlens[i] = sizeof (struct sockaddr_in); + saddrs[i] = GNUNET_malloc (saddrlens[i]); #if HAVE_SOCKADDR_IN_SIN_LEN - ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1]; + ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1]; #endif - ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET; - ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); - } + ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET; + ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); } + } GNUNET_free_non_null (unixpath); *addrs = saddrs; *addr_lens = saddrlens; @@ -1124,37 +1110,36 @@ setup_service (struct GNUNET_SERVICE_Context *sctx) int flags; #endif - if (GNUNET_CONFIGURATION_have_value - (sctx->cfg, sctx->serviceName, "TIMEOUT")) + if (GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->serviceName, "TIMEOUT")) + { + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_time (sctx->cfg, sctx->serviceName, + "TIMEOUT", &idleout)) { - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_time (sctx->cfg, sctx->serviceName, - "TIMEOUT", &idleout)) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Specified value for `%s' of service `%s' is invalid\n"), - "TIMEOUT", sctx->serviceName); - return GNUNET_SYSERR; - } - sctx->timeout = idleout; + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Specified value for `%s' of service `%s' is invalid\n"), + "TIMEOUT", sctx->serviceName); + return GNUNET_SYSERR; } + sctx->timeout = idleout; + } else sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL; if (GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->serviceName, "TOLERANT")) + { + if (GNUNET_SYSERR == + (tolerant = + GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->serviceName, + "TOLERANT"))) { - if (GNUNET_SYSERR == - (tolerant = - GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->serviceName, - "TOLERANT"))) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Specified value for `%s' of service `%s' is invalid\n"), - "TOLERANT", sctx->serviceName); - return GNUNET_SYSERR; - } + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Specified value for `%s' of service `%s' is invalid\n"), + "TOLERANT", sctx->serviceName); + return GNUNET_SYSERR; } + } else tolerant = GNUNET_NO; @@ -1165,48 +1150,45 @@ setup_service (struct GNUNET_SERVICE_Context *sctx) (NULL != (nfds = getenv ("LISTEN_FDS"))) && (1 == sscanf (nfds, "%u", &cnt)) && (cnt > 0) && (cnt < FD_SETSIZE) && (cnt + 4 < FD_SETSIZE)) + { + sctx->lsocks = + GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (cnt + 1)); + while (0 < cnt--) { - sctx->lsocks = - GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (cnt + 1)); - while (0 < cnt--) - { - flags = fcntl (3 + cnt, F_GETFD); - if ((flags < 0) || (0 != (flags & FD_CLOEXEC)) || - (NULL == - (sctx->lsocks[cnt] = - GNUNET_NETWORK_socket_box_native (3 + cnt)))) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _ - ("Could not access pre-bound socket %u, will try to bind myself\n"), - (unsigned int) 3 + cnt); - cnt++; - while (sctx->lsocks[cnt] != NULL) - GNUNET_break (0 == - GNUNET_NETWORK_socket_close (sctx->lsocks - [cnt++])); - GNUNET_free (sctx->lsocks); - sctx->lsocks = NULL; - break; - } - } - unsetenv ("LISTEN_PID"); - unsetenv ("LISTEN_FDS"); + flags = fcntl (3 + cnt, F_GETFD); + if ((flags < 0) || (0 != (flags & FD_CLOEXEC)) || + (NULL == + (sctx->lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt)))) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _ + ("Could not access pre-bound socket %u, will try to bind myself\n"), + (unsigned int) 3 + cnt); + cnt++; + while (sctx->lsocks[cnt] != NULL) + GNUNET_break (0 == GNUNET_NETWORK_socket_close (sctx->lsocks[cnt++])); + GNUNET_free (sctx->lsocks); + sctx->lsocks = NULL; + break; + } } + unsetenv ("LISTEN_PID"); + unsetenv ("LISTEN_FDS"); + } #endif if ((sctx->lsocks == NULL) && (GNUNET_SYSERR == GNUNET_SERVICE_get_server_addresses (sctx->serviceName, sctx->cfg, - &sctx->addrs, &sctx->addrlens))) + &sctx->addrs, &sctx->addrlens))) return GNUNET_SYSERR; sctx->require_found = tolerant ? GNUNET_NO : GNUNET_YES; sctx->match_uid = - GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->serviceName, - "UNIX_MATCH_UID"); + GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->serviceName, + "UNIX_MATCH_UID"); sctx->match_gid = - GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->serviceName, - "UNIX_MATCH_GID"); + GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->serviceName, + "UNIX_MATCH_GID"); process_acl4 (&sctx->v4_denied, sctx, "REJECT_FROM"); process_acl4 (&sctx->v4_allowed, sctx, "ACCEPT_FROM"); process_acl6 (&sctx->v6_denied, sctx, "REJECT_FROM6"); @@ -1228,7 +1210,7 @@ get_user_name (struct GNUNET_SERVICE_Context *sctx) if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, sctx->serviceName, - "USERNAME", &un)) + "USERNAME", &un)) return NULL; return un; } @@ -1246,7 +1228,7 @@ write_pid_file (struct GNUNET_SERVICE_Context *sctx, pid_t pid) int len; if (NULL == (pif = get_pid_file_name (sctx))) - return GNUNET_OK; /* no file desired */ + return GNUNET_OK; /* no file desired */ user = get_user_name (sctx); rdir = GNUNET_strdup (pif); len = strlen (rdir); @@ -1254,30 +1236,30 @@ write_pid_file (struct GNUNET_SERVICE_Context *sctx, pid_t pid) len--; rdir[len] = '\0'; if (0 != ACCESS (rdir, F_OK)) - { - /* we get to create a directory -- and claim it - * as ours! */ - GNUNET_DISK_directory_create (rdir); - if ((user != NULL) && (0 < strlen (user))) - GNUNET_DISK_file_change_owner (rdir, user); - } + { + /* we get to create a directory -- and claim it + * as ours! */ + GNUNET_DISK_directory_create (rdir); + if ((user != NULL) && (0 < strlen (user))) + GNUNET_DISK_file_change_owner (rdir, user); + } if (0 != ACCESS (rdir, W_OK | X_OK)) - { - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", rdir); - GNUNET_free (rdir); - GNUNET_free_non_null (user); - GNUNET_free (pif); - return GNUNET_SYSERR; - } + { + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", rdir); + GNUNET_free (rdir); + GNUNET_free_non_null (user); + GNUNET_free (pif); + return GNUNET_SYSERR; + } GNUNET_free (rdir); pidfd = FOPEN (pif, "w"); if (pidfd == NULL) - { - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "fopen", pif); - GNUNET_free (pif); - GNUNET_free_non_null (user); - return GNUNET_SYSERR; - } + { + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "fopen", pif); + GNUNET_free (pif); + GNUNET_free_non_null (user); + return GNUNET_SYSERR; + } if (0 > FPRINTF (pidfd, "%u", pid)) LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fprintf", pif); GNUNET_break (0 == fclose (pidfd)); @@ -1316,35 +1298,34 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_RESOLVER_connect (sctx->cfg); if (sctx->lsocks != NULL) sctx->server = - GNUNET_SERVER_create_with_sockets (&check_access, sctx, sctx->lsocks, - sctx->timeout, sctx->require_found); + GNUNET_SERVER_create_with_sockets (&check_access, sctx, sctx->lsocks, + sctx->timeout, sctx->require_found); else sctx->server = - GNUNET_SERVER_create (&check_access, sctx, sctx->addrs, sctx->addrlens, - sctx->timeout, sctx->require_found); + GNUNET_SERVER_create (&check_access, sctx, sctx->addrs, sctx->addrlens, + sctx->timeout, sctx->require_found); if (sctx->server == NULL) + { + if (sctx->addrs != NULL) { - if (sctx->addrs != NULL) - { - i = 0; - while (sctx->addrs[i] != NULL) - { - LOG (GNUNET_ERROR_TYPE_INFO, - _("Failed to start `%s' at `%s'\n"), sctx->serviceName, - GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i])); - i++; - } - } - sctx->ret = GNUNET_SYSERR; - return; + i = 0; + while (sctx->addrs[i] != NULL) + { + LOG (GNUNET_ERROR_TYPE_INFO, _("Failed to start `%s' at `%s'\n"), + sctx->serviceName, GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i])); + i++; + } } + sctx->ret = GNUNET_SYSERR; + return; + } if (0 == (sctx->options & GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN)) - { - /* install a task that will kill the server - * process if the scheduler ever gets a shutdown signal */ - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, - &shutdown_task, sctx->server); - } + { + /* install a task that will kill the server + * process if the scheduler ever gets a shutdown signal */ + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, + sctx->server); + } sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers)); memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers)); i = 0; @@ -1352,23 +1333,22 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) sctx->my_handlers[i++].callback_cls = sctx; GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers); if (sctx->ready_confirm_fd != -1) - { - GNUNET_break (1 == WRITE (sctx->ready_confirm_fd, ".", 1)); - GNUNET_break (0 == CLOSE (sctx->ready_confirm_fd)); - sctx->ready_confirm_fd = -1; - write_pid_file (sctx, getpid ()); - } + { + GNUNET_break (1 == WRITE (sctx->ready_confirm_fd, ".", 1)); + GNUNET_break (0 == CLOSE (sctx->ready_confirm_fd)); + sctx->ready_confirm_fd = -1; + write_pid_file (sctx, getpid ()); + } if (sctx->addrs != NULL) + { + i = 0; + while (sctx->addrs[i] != NULL) { - i = 0; - while (sctx->addrs[i] != NULL) - { - LOG (GNUNET_ERROR_TYPE_INFO, _("Service `%s' runs at %s\n"), - sctx->serviceName, GNUNET_a2s (sctx->addrs[i], - sctx->addrlens[i])); - i++; - } + LOG (GNUNET_ERROR_TYPE_INFO, _("Service `%s' runs at %s\n"), + sctx->serviceName, GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i])); + i++; } + } sctx->task (sctx->task_cls, sctx->server, sctx->cfg); } @@ -1385,45 +1365,44 @@ detach_terminal (struct GNUNET_SERVICE_Context *sctx) int filedes[2]; if (0 != PIPE (filedes)) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe"); - return GNUNET_SYSERR; - } + { + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe"); + return GNUNET_SYSERR; + } pid = fork (); if (pid < 0) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork"); - return GNUNET_SYSERR; - } + { + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork"); + return GNUNET_SYSERR; + } if (pid != 0) + { + /* Parent */ + char c; + + GNUNET_break (0 == CLOSE (filedes[1])); + c = 'X'; + if (1 != READ (filedes[0], &c, sizeof (char))) + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "read"); + fflush (stdout); + switch (c) { - /* Parent */ - char c; - - GNUNET_break (0 == CLOSE (filedes[1])); - c = 'X'; - if (1 != READ (filedes[0], &c, sizeof (char))) - LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "read"); - fflush (stdout); - switch (c) - { - case '.': - exit (0); - case 'I': - LOG (GNUNET_ERROR_TYPE_INFO, - _("Service process failed to initialize\n")); - break; - case 'S': - LOG (GNUNET_ERROR_TYPE_INFO, - _("Service process could not initialize server function\n")); - break; - case 'X': - LOG (GNUNET_ERROR_TYPE_INFO, - _("Service process failed to report status\n")); - break; - } - exit (1); /* child reported error */ + case '.': + exit (0); + case 'I': + LOG (GNUNET_ERROR_TYPE_INFO, _("Service process failed to initialize\n")); + break; + case 'S': + LOG (GNUNET_ERROR_TYPE_INFO, + _("Service process could not initialize server function\n")); + break; + case 'X': + LOG (GNUNET_ERROR_TYPE_INFO, + _("Service process failed to report status\n")); + break; } + exit (1); /* child reported error */ + } GNUNET_break (0 == CLOSE (0)); GNUNET_break (0 == CLOSE (1)); GNUNET_break (0 == CLOSE (filedes[0])); @@ -1432,11 +1411,11 @@ detach_terminal (struct GNUNET_SERVICE_Context *sctx) return GNUNET_SYSERR; /* set stdin/stdout to /dev/null */ if ((dup2 (nullfd, 0) < 0) || (dup2 (nullfd, 1) < 0)) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2"); - (void) CLOSE (nullfd); - return GNUNET_SYSERR; - } + { + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2"); + (void) CLOSE (nullfd); + return GNUNET_SYSERR; + } (void) CLOSE (nullfd); /* Detach from controlling terminal */ pid = setsid (); @@ -1461,36 +1440,35 @@ set_user_id (struct GNUNET_SERVICE_Context *sctx) char *user; if (NULL == (user = get_user_name (sctx))) - return GNUNET_OK; /* keep */ + return GNUNET_OK; /* keep */ #ifndef MINGW struct passwd *pws; errno = 0; pws = getpwnam (user); if (pws == NULL) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Cannot obtain information about user `%s': %s\n"), user, - errno == 0 ? _("No such user") : STRERROR (errno)); - GNUNET_free (user); - return GNUNET_SYSERR; - } + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Cannot obtain information about user `%s': %s\n"), user, + errno == 0 ? _("No such user") : STRERROR (errno)); + GNUNET_free (user); + return GNUNET_SYSERR; + } if ((0 != setgid (pws->pw_gid)) || (0 != setegid (pws->pw_gid)) || #if HAVE_INITGROUPS (0 != initgroups (user, pws->pw_gid)) || #endif (0 != setuid (pws->pw_uid)) || (0 != seteuid (pws->pw_uid))) + { + if ((0 != setregid (pws->pw_gid, pws->pw_gid)) || + (0 != setreuid (pws->pw_uid, pws->pw_uid))) { - if ((0 != setregid (pws->pw_gid, pws->pw_gid)) || - (0 != setreuid (pws->pw_uid, pws->pw_uid))) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Cannot change user/group to `%s': %s\n"), user, - STRERROR (errno)); - GNUNET_free (user); - return GNUNET_SYSERR; - } + LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot change user/group to `%s': %s\n"), + user, STRERROR (errno)); + GNUNET_free (user); + return GNUNET_SYSERR; } + } #endif GNUNET_free (user); return GNUNET_OK; @@ -1506,7 +1484,7 @@ pid_file_delete (struct GNUNET_SERVICE_Context *sctx) char *pif = get_pid_file_name (sctx); if (pif == NULL) - return; /* no PID file */ + return; /* no PID file */ if (0 != UNLINK (pif)) LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", pif); GNUNET_free (pif); @@ -1528,8 +1506,8 @@ pid_file_delete (struct GNUNET_SERVICE_Context *sctx) */ int GNUNET_SERVICE_run (int argc, char *const *argv, const char *serviceName, - enum GNUNET_SERVICE_Options opt, GNUNET_SERVICE_Main task, - void *task_cls) + enum GNUNET_SERVICE_Options opt, GNUNET_SERVICE_Main task, + void *task_cls) { #define HANDLE_ERROR do { GNUNET_break (0); goto shutdown; } while (0) @@ -1586,23 +1564,21 @@ GNUNET_SERVICE_run (int argc, char *const *argv, const char *serviceName, goto shutdown; #if DEBUG_SERVICE LOG (GNUNET_ERROR_TYPE_DEBUG, - "Service `%s' runs with configuration from `%s'\n", serviceName, - cfg_fn); + "Service `%s' runs with configuration from `%s'\n", serviceName, cfg_fn); #endif if (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "testing", - "skew_offset", &skew_offset) - && (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "testing", - "skew_variance", - &skew_variance))) - { - clock_offset = skew_offset - skew_variance; - GNUNET_TIME_set_offset (clock_offset); + GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "testing", "skew_offset", + &skew_offset) && + (GNUNET_OK == + GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "testing", + "skew_variance", &skew_variance))) + { + clock_offset = skew_offset - skew_variance; + GNUNET_TIME_set_offset (clock_offset); #if DEBUG_SERVICE - LOG (GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %dll\n", clock_offset); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %dll\n", clock_offset); #endif - } + } /* actually run service */ err = 0; GNUNET_SCHEDULER_run (&service_task, &sctx); @@ -1614,11 +1590,11 @@ GNUNET_SERVICE_run (int argc, char *const *argv, const char *serviceName, shutdown: if (sctx.ready_confirm_fd != -1) - { - if (1 != WRITE (sctx.ready_confirm_fd, err ? "I" : "S", 1)) - LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "write"); - GNUNET_break (0 == CLOSE (sctx.ready_confirm_fd)); - } + { + if (1 != WRITE (sctx.ready_confirm_fd, err ? "I" : "S", 1)) + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "write"); + GNUNET_break (0 == CLOSE (sctx.ready_confirm_fd)); + } GNUNET_CONFIGURATION_destroy (cfg); i = 0; @@ -1649,13 +1625,13 @@ shutdown: */ struct GNUNET_SERVICE_Context * GNUNET_SERVICE_start (const char *serviceName, - const struct GNUNET_CONFIGURATION_Handle *cfg) + const struct GNUNET_CONFIGURATION_Handle *cfg) { int i; struct GNUNET_SERVICE_Context *sctx; sctx = GNUNET_malloc (sizeof (struct GNUNET_SERVICE_Context)); - sctx->ready_confirm_fd = -1; /* no daemonizing */ + sctx->ready_confirm_fd = -1; /* no daemonizing */ sctx->ret = GNUNET_OK; sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL; sctx->serviceName = serviceName; @@ -1663,24 +1639,24 @@ GNUNET_SERVICE_start (const char *serviceName, /* setup subsystems */ if (GNUNET_OK != setup_service (sctx)) - { - GNUNET_SERVICE_stop (sctx); - return NULL; - } + { + GNUNET_SERVICE_stop (sctx); + return NULL; + } if (sctx->lsocks != NULL) sctx->server = - GNUNET_SERVER_create_with_sockets (&check_access, sctx, sctx->lsocks, - sctx->timeout, sctx->require_found); + GNUNET_SERVER_create_with_sockets (&check_access, sctx, sctx->lsocks, + sctx->timeout, sctx->require_found); else sctx->server = - GNUNET_SERVER_create (&check_access, sctx, sctx->addrs, sctx->addrlens, - sctx->timeout, sctx->require_found); + GNUNET_SERVER_create (&check_access, sctx, sctx->addrs, sctx->addrlens, + sctx->timeout, sctx->require_found); if (NULL == sctx->server) - { - GNUNET_SERVICE_stop (sctx); - return NULL; - } + { + GNUNET_SERVICE_stop (sctx); + return NULL; + } sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers)); memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers)); i = 0; @@ -1718,12 +1694,12 @@ GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Context *sctx) GNUNET_SERVER_destroy (sctx->server); GNUNET_free_non_null (sctx->my_handlers); if (sctx->addrs != NULL) - { - i = 0; - while (sctx->addrs[i] != NULL) - GNUNET_free (sctx->addrs[i++]); - GNUNET_free (sctx->addrs); - } + { + i = 0; + while (sctx->addrs[i] != NULL) + GNUNET_free (sctx->addrs[i++]); + GNUNET_free (sctx->addrs); + } GNUNET_free_non_null (sctx->addrlens); GNUNET_free_non_null (sctx->v4_denied); GNUNET_free_non_null (sctx->v6_denied); diff --git a/src/util/signal.c b/src/util/signal.c index a986b6260..c3bb718bf 100644 --- a/src/util/signal.c +++ b/src/util/signal.c @@ -63,7 +63,7 @@ GNUNET_SIGNAL_handler_install (int signum, GNUNET_SIGNAL_Handler handler) sig.sa_handler = (void *) handler; sigemptyset (&sig.sa_mask); #ifdef SA_INTERRUPT - sig.sa_flags = SA_INTERRUPT; /* SunOS */ + sig.sa_flags = SA_INTERRUPT; /* SunOS */ #else sig.sa_flags = SA_RESTART; #endif @@ -72,15 +72,15 @@ GNUNET_SIGNAL_handler_install (int signum, GNUNET_SIGNAL_Handler handler) if (signum == GNUNET_SIGCHLD) w32_sigchld_handler = handler; else - { - __p_sig_fn_t sigret = signal (signum, (__p_sig_fn_t) handler); + { + __p_sig_fn_t sigret = signal (signum, (__p_sig_fn_t) handler); - if (sigret == SIG_ERR) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - _("signal (%d, %p) returned %d.\n"), signum, handler, sigret); - } + if (sigret == SIG_ERR) + { + LOG (GNUNET_ERROR_TYPE_WARNING, _("signal (%d, %p) returned %d.\n"), + signum, handler, sigret); } + } #endif return ret; } diff --git a/src/util/strings.c b/src/util/strings.c index d48d552a1..dc4037a1f 100644 --- a/src/util/strings.c +++ b/src/util/strings.c @@ -59,8 +59,7 @@ * (or number of bytes that would have been written) */ size_t -GNUNET_STRINGS_buffer_fill (char *buffer, size_t size, unsigned int count, - ...) +GNUNET_STRINGS_buffer_fill (char *buffer, size_t size, unsigned int count, ...) { size_t needed; size_t slen; @@ -70,18 +69,18 @@ GNUNET_STRINGS_buffer_fill (char *buffer, size_t size, unsigned int count, needed = 0; va_start (ap, count); while (count > 0) - { - s = va_arg (ap, const char *); + { + s = va_arg (ap, const char *); - slen = strlen (s) + 1; - if (buffer != NULL) - { - GNUNET_assert (needed + slen <= size); - memcpy (&buffer[needed], s, slen); - } - needed += slen; - count--; + slen = strlen (s) + 1; + if (buffer != NULL) + { + GNUNET_assert (needed + slen <= size); + memcpy (&buffer[needed], s, slen); } + needed += slen; + count--; + } va_end (ap); return needed; } @@ -102,7 +101,7 @@ GNUNET_STRINGS_buffer_fill (char *buffer, size_t size, unsigned int count, */ unsigned int GNUNET_STRINGS_buffer_tokenize (const char *buffer, size_t size, - unsigned int count, ...) + unsigned int count, ...) { unsigned int start; unsigned int needed; @@ -112,21 +111,21 @@ GNUNET_STRINGS_buffer_tokenize (const char *buffer, size_t size, needed = 0; va_start (ap, count); while (count > 0) + { + r = va_arg (ap, const char **); + + start = needed; + while ((needed < size) && (buffer[needed] != '\0')) + needed++; + if (needed == size) { - r = va_arg (ap, const char **); - - start = needed; - while ((needed < size) && (buffer[needed] != '\0')) - needed++; - if (needed == size) - { - va_end (ap); - return 0; /* error */ - } - *r = &buffer[start]; - needed++; /* skip 0-termination */ - count--; + va_end (ap); + return 0; /* error */ } + *r = &buffer[start]; + needed++; /* skip 0-termination */ + count--; + } va_end (ap); return needed; } @@ -145,25 +144,25 @@ GNUNET_STRINGS_byte_size_fancy (unsigned long long size) char *ret; if (size > 5 * 1024) + { + size = size / 1024; + unit = "KiB"; + if (size > 5 * 1024) { size = size / 1024; - unit = "KiB"; + unit = "MiB"; if (size > 5 * 1024) - { - size = size / 1024; - unit = "MiB"; - if (size > 5 * 1024) - { - size = size / 1024; - unit = "GiB"; - if (size > 5 * 1024) - { - size = size / 1024; - unit = "TiB"; - } - } - } + { + size = size / 1024; + unit = "GiB"; + if (size > 5 * 1024) + { + size = size / 1024; + unit = "TiB"; + } + } } + } ret = GNUNET_malloc (32); GNUNET_snprintf (ret, 32, "%llu %s", size, unit); return ret; @@ -179,26 +178,42 @@ GNUNET_STRINGS_byte_size_fancy (unsigned long long size) */ int GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size, - unsigned long long *size) + unsigned long long *size) { - struct { - const char *name; + struct + { + const char *name; unsigned long long value; - } table[] = { - { "B", 1 }, - { "KiB", 1024 }, - { "kB", 1000 }, - { "MiB", 1024 * 1024 }, - { "MB", 1000 * 1000 }, - { "GiB", 1024 * 1024 * 1024 }, - { "GB", 1000 * 1000 * 1000 }, - { "TiB", 1024LL * 1024LL * 1024LL * 1024LL }, - { "TB", 1000LL * 1000LL * 1000LL * 1024LL }, - { "PiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL }, - { "PB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL}, - { "EiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL}, - { "EB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL * 1000LL }, - { NULL, 0 } + } table[] = + { + { + "B", 1}, + { + "KiB", 1024}, + { + "kB", 1000}, + { + "MiB", 1024 * 1024}, + { + "MB", 1000 * 1000}, + { + "GiB", 1024 * 1024 * 1024}, + { + "GB", 1000 * 1000 * 1000}, + { + "TiB", 1024LL * 1024LL * 1024LL * 1024LL}, + { + "TB", 1000LL * 1000LL * 1000LL * 1024LL}, + { + "PiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL}, + { + "PB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL}, + { + "EiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL}, + { + "EB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL * 1000LL}, + { + NULL, 0} }; unsigned long long ret; char *in; @@ -211,9 +226,8 @@ GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size, in = GNUNET_strdup (fancy_size); for (tok = strtok (in, " "); tok != NULL; tok = strtok (NULL, " ")) { - i=0; - while ( (table[i].name != NULL) && - (0 != strcasecmp (table[i].name, tok) ) ) + i = 0; + while ((table[i].name != NULL) && (0 != strcasecmp (table[i].name, tok))) i++; if (table[i].name != NULL) last *= table[i].value; @@ -222,8 +236,8 @@ GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size, ret += last; last = 0; if (1 != sscanf (tok, "%llu", &last)) - return GNUNET_SYSERR; /* expected number */ - } + return GNUNET_SYSERR; /* expected number */ + } } ret += last; *size = ret; @@ -241,43 +255,54 @@ GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size, */ int GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_size, - struct GNUNET_TIME_Relative *rtime) + struct GNUNET_TIME_Relative *rtime) { - struct { - const char *name; + struct + { + const char *name; unsigned long long value; - } table[] = { - { "ms", 1 }, - { "s", 1000 }, - { "\"", 1000 }, - { "min", 60 * 1000 }, - { "minutes", 60 * 1000 }, - { "'", 60 * 1000 }, - { "h", 60 * 60 * 1000 }, - { "d", 24 * 60 * 60 * 1000 }, - { "a", 31557600 /* year */ }, - { NULL, 0 } + } table[] = + { + { + "ms", 1}, + { + "s", 1000}, + { + "\"", 1000}, + { + "min", 60 * 1000}, + { + "minutes", 60 * 1000}, + { + "'", 60 * 1000}, + { + "h", 60 * 60 * 1000}, + { + "d", 24 * 60 * 60 * 1000}, + { + "a", 31557600 /* year */ }, + { + NULL, 0} }; unsigned long long ret; char *in; const char *tok; unsigned long long last; unsigned int i; - + if ((0 == strcasecmp (fancy_size, "infinity")) || (0 == strcasecmp (fancy_size, "forever"))) - { - *rtime = GNUNET_TIME_UNIT_FOREVER_REL; - return GNUNET_OK; - } + { + *rtime = GNUNET_TIME_UNIT_FOREVER_REL; + return GNUNET_OK; + } ret = 0; last = 0; in = GNUNET_strdup (fancy_size); for (tok = strtok (in, " "); tok != NULL; tok = strtok (NULL, " ")) { - i=0; - while ( (table[i].name != NULL) && - (0 != strcasecmp (table[i].name, tok) ) ) + i = 0; + while ((table[i].name != NULL) && (0 != strcasecmp (table[i].name, tok))) i++; if (table[i].name != NULL) last *= table[i].value; @@ -286,8 +311,8 @@ GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_size, ret += last; last = 0; if (1 != sscanf (tok, "%llu", &last)) - return GNUNET_SYSERR; /* expected number */ - } + return GNUNET_SYSERR; /* expected number */ + } } ret += last; rtime->rel_value = (uint64_t) ret; @@ -317,35 +342,35 @@ GNUNET_STRINGS_to_utf8 (const char *input, size_t len, const char *charset) cd = iconv_open ("UTF-8", charset); if (cd == (iconv_t) - 1) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "iconv_open"); - LOG (GNUNET_ERROR_TYPE_WARNING, - _("Character set requested was `%s'\n"), charset); - ret = GNUNET_malloc (len + 1); - memcpy (ret, input, len); - ret[len] = '\0'; - return ret; - } + { + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "iconv_open"); + LOG (GNUNET_ERROR_TYPE_WARNING, _("Character set requested was `%s'\n"), + charset); + ret = GNUNET_malloc (len + 1); + memcpy (ret, input, len); + ret[len] = '\0'; + return ret; + } tmpSize = 3 * len + 4; tmp = GNUNET_malloc (tmpSize); itmp = tmp; finSize = tmpSize; if (iconv (cd, #if FREEBSD || DARWIN || WINDOWS - (const char **) &input, + (const char **) &input, #else - (char **) &input, + (char **) &input, #endif - &len, &itmp, &finSize) == SIZE_MAX) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "iconv"); - iconv_close (cd); - GNUNET_free (tmp); - ret = GNUNET_malloc (len + 1); - memcpy (ret, input, len); - ret[len] = '\0'; - return ret; - } + &len, &itmp, &finSize) == SIZE_MAX) + { + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "iconv"); + iconv_close (cd); + GNUNET_free (tmp); + ret = GNUNET_malloc (len + 1); + memcpy (ret, input, len); + ret[len] = '\0'; + return ret; + } ret = GNUNET_malloc (tmpSize - finSize + 1); memcpy (ret, tmp, tmpSize - finSize); ret[tmpSize - finSize] = '\0'; @@ -392,89 +417,88 @@ GNUNET_STRINGS_filename_expand (const char *fil) /* absolute path, just copy */ return GNUNET_strdup (fil); if (fil[0] == '~') + { + fm = getenv ("HOME"); + if (fm == NULL) { - fm = getenv ("HOME"); - if (fm == NULL) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - _ - ("Failed to expand `$HOME': environment variable `HOME' not set")); - return NULL; - } - fm = GNUNET_strdup (fm); - /* do not copy '~' */ - fil_ptr = fil + 1; - - /* skip over dir seperator to be consistent */ - if (fil_ptr[0] == DIR_SEPARATOR) - fil_ptr++; + LOG (GNUNET_ERROR_TYPE_WARNING, + _("Failed to expand `$HOME': environment variable `HOME' not set")); + return NULL; } + fm = GNUNET_strdup (fm); + /* do not copy '~' */ + fil_ptr = fil + 1; + + /* skip over dir seperator to be consistent */ + if (fil_ptr[0] == DIR_SEPARATOR) + fil_ptr++; + } else + { + /* relative path */ + fil_ptr = fil; + len = 512; + fm = NULL; + while (1) { - /* relative path */ - fil_ptr = fil; - len = 512; - fm = NULL; - while (1) - { - buffer = GNUNET_malloc (len); - if (getcwd (buffer, len) != NULL) - { - fm = buffer; - break; - } - if ((errno == ERANGE) && (len < 1024 * 1024 * 4)) - { - len *= 2; - GNUNET_free (buffer); - continue; - } - GNUNET_free (buffer); - break; - } - if (fm == NULL) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "getcwd"); - buffer = getenv ("PWD"); /* alternative */ - if (buffer != NULL) - fm = GNUNET_strdup (buffer); - } - if (fm == NULL) - fm = GNUNET_strdup ("./"); /* give up */ + buffer = GNUNET_malloc (len); + if (getcwd (buffer, len) != NULL) + { + fm = buffer; + break; + } + if ((errno == ERANGE) && (len < 1024 * 1024 * 4)) + { + len *= 2; + GNUNET_free (buffer); + continue; + } + GNUNET_free (buffer); + break; + } + if (fm == NULL) + { + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "getcwd"); + buffer = getenv ("PWD"); /* alternative */ + if (buffer != NULL) + fm = GNUNET_strdup (buffer); } + if (fm == NULL) + fm = GNUNET_strdup ("./"); /* give up */ + } n = strlen (fm) + 1 + strlen (fil_ptr) + 1; buffer = GNUNET_malloc (n); GNUNET_snprintf (buffer, n, "%s%s%s", fm, - (fm[strlen (fm) - 1] == - DIR_SEPARATOR) ? "" : DIR_SEPARATOR_STR, fil_ptr); + (fm[strlen (fm) - 1] == + DIR_SEPARATOR) ? "" : DIR_SEPARATOR_STR, fil_ptr); GNUNET_free (fm); return buffer; #else fn = GNUNET_malloc (MAX_PATH + 1); if ((lRet = plibc_conv_to_win_path (fil, fn)) != ERROR_SUCCESS) - { - SetErrnoFromWinError (lRet); - LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "plibc_conv_to_win_path"); - return NULL; - } + { + SetErrnoFromWinError (lRet); + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "plibc_conv_to_win_path"); + return NULL; + } /* is the path relative? */ if ((strncmp (fn + 1, ":\\", 2) != 0) && (strncmp (fn, "\\\\", 2) != 0)) + { + char szCurDir[MAX_PATH + 1]; + + lRet = GetCurrentDirectory (MAX_PATH + 1, szCurDir); + if (lRet + strlen (fn) + 1 > (MAX_PATH + 1)) { - char szCurDir[MAX_PATH + 1]; - - lRet = GetCurrentDirectory (MAX_PATH + 1, szCurDir); - if (lRet + strlen (fn) + 1 > (MAX_PATH + 1)) - { - SetErrnoFromWinError (ERROR_BUFFER_OVERFLOW); - LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "GetCurrentDirectory"); - return NULL; - } - buffer = GNUNET_malloc (MAX_PATH + 1); - GNUNET_snprintf (buffer, MAX_PATH + 1, "%s\\%s", szCurDir, fn); - GNUNET_free (fn); - fn = buffer; + SetErrnoFromWinError (ERROR_BUFFER_OVERFLOW); + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "GetCurrentDirectory"); + return NULL; } + buffer = GNUNET_malloc (MAX_PATH + 1); + GNUNET_snprintf (buffer, MAX_PATH + 1, "%s\\%s", szCurDir, fn); + GNUNET_free (fn); + fn = buffer; + } return fn; #endif @@ -497,25 +521,25 @@ GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta) if (delta.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value) return GNUNET_strdup (_("eternity")); if (dval > 5 * 1000) + { + dval = dval / 1000; + unit = _( /* time unit */ "s"); + if (dval > 5 * 60) { - dval = dval / 1000; - unit = _( /* time unit */ "s"); + dval = dval / 60; + unit = _( /* time unit */ "m"); if (dval > 5 * 60) - { - dval = dval / 60; - unit = _( /* time unit */ "m"); - if (dval > 5 * 60) - { - dval = dval / 60; - unit = _( /* time unit */ "h"); - if (dval > 5 * 24) - { - dval = dval / 24; - unit = _( /* time unit */ " days"); - } - } - } + { + dval = dval / 60; + unit = _( /* time unit */ "h"); + if (dval > 5 * 24) + { + dval = dval / 24; + unit = _( /* time unit */ " days"); + } + } } + } GNUNET_asprintf (&ret, "%llu %s", dval, unit); return ret; } diff --git a/src/util/test_bio.c b/src/util/test_bio.c index e72c95295..df4becdd1 100644 --- a/src/util/test_bio.c +++ b/src/util/test_bio.c @@ -57,17 +57,16 @@ test_normal_rw () GNUNET_assert (NULL != fileR); readResultString = NULL; GNUNET_assert (GNUNET_OK == - GNUNET_BIO_read_string (fileR, "Read string error", - &readResultString, 200)); + GNUNET_BIO_read_string (fileR, "Read string error", + &readResultString, 200)); GNUNET_assert (NULL != readResultString); GNUNET_assert (0 == strcmp (TESTSTRING, readResultString)); GNUNET_free (readResultString); GNUNET_assert (GNUNET_OK == - GNUNET_BIO_read_meta_data (fileR, "Read meta error", - &metaDataR)); + GNUNET_BIO_read_meta_data (fileR, "Read meta error", + &metaDataR)); GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_meta_data_test_equal (metaDataR, - metaDataW)); + GNUNET_CONTAINER_meta_data_test_equal (metaDataR, metaDataW)); GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_int64 (fileR, &testNum)); GNUNET_BIO_read_close (fileR, &msg); GNUNET_CONTAINER_meta_data_destroy (metaDataW); @@ -94,8 +93,8 @@ test_nullstring_rw () fileR = GNUNET_BIO_read_open (fileName); GNUNET_assert (NULL != fileR); GNUNET_assert (GNUNET_OK == - GNUNET_BIO_read_string (fileR, "Read string error", - &readResultString, 200)); + GNUNET_BIO_read_string (fileR, "Read string error", + &readResultString, 200)); GNUNET_assert (NULL == readResultString); GNUNET_BIO_read_close (fileR, &msg); GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName)); @@ -122,8 +121,8 @@ test_emptystring_rw () GNUNET_assert (NULL != fileR); readResultString = NULL; GNUNET_assert (GNUNET_OK == - GNUNET_BIO_read_string (fileR, "Read string error", - &readResultString, 200)); + GNUNET_BIO_read_string (fileR, "Read string error", + &readResultString, 200)); GNUNET_free (readResultString); GNUNET_BIO_read_close (fileR, &msg); GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName)); @@ -149,8 +148,8 @@ test_bigstring_rw () GNUNET_assert (NULL != fileR); readResultString = NULL; GNUNET_assert (GNUNET_SYSERR == - GNUNET_BIO_read_string (fileR, "Read string error", - &readResultString, 1)); + GNUNET_BIO_read_string (fileR, "Read string error", + &readResultString, 1)); GNUNET_assert (NULL == readResultString); msg = NULL; GNUNET_BIO_read_close (fileR, &msg); @@ -182,8 +181,8 @@ test_bigmeta_rw () GNUNET_assert (NULL != fileR); metaDataR = NULL; GNUNET_assert (GNUNET_SYSERR == - GNUNET_BIO_read_meta_data (fileR, "Read meta error", - &metaDataR)); + GNUNET_BIO_read_meta_data (fileR, "Read meta error", + &metaDataR)); msg = NULL; GNUNET_BIO_read_close (fileR, &msg); GNUNET_free (msg); @@ -204,8 +203,8 @@ test_directory_r () fileR = GNUNET_BIO_read_open ("/dev"); GNUNET_assert (NULL != fileR); GNUNET_assert (GNUNET_SYSERR == - GNUNET_BIO_read (fileR, "Read error", readResult, - sizeof (readResult))); + GNUNET_BIO_read (fileR, "Read error", readResult, + sizeof (readResult))); msg = NULL; GNUNET_BIO_read_close (fileR, &msg); GNUNET_free (msg); @@ -268,18 +267,18 @@ test_fullfile_rw () fileR = GNUNET_BIO_read_open ("/dev/null"); GNUNET_assert (NULL != fileR); GNUNET_assert (GNUNET_SYSERR == - GNUNET_BIO_read (fileR, "Read error", readResult, - sizeof (readResult))); + GNUNET_BIO_read (fileR, "Read error", readResult, + sizeof (readResult))); readResultString = NULL; GNUNET_assert (GNUNET_SYSERR == - GNUNET_BIO_read_string (fileR, "Read string error", - &readResultString, 200)); + GNUNET_BIO_read_string (fileR, "Read string error", + &readResultString, 200)); GNUNET_assert (NULL == readResultString); GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_int64 (fileR, &testNum)); metaDataR = NULL; GNUNET_assert (GNUNET_SYSERR == - GNUNET_BIO_read_meta_data (fileR, "Read meta error", - &metaDataR)); + GNUNET_BIO_read_meta_data (fileR, "Read meta error", + &metaDataR)); msg = NULL; GNUNET_BIO_read_close (fileR, &msg); GNUNET_free (msg); @@ -306,8 +305,8 @@ test_fakestring_rw () fileR = GNUNET_BIO_read_open (fileName); GNUNET_assert (NULL != fileR); GNUNET_assert (GNUNET_SYSERR == - GNUNET_BIO_read_string (fileR, "Read string error", - &readResult, 200)); + GNUNET_BIO_read_string (fileR, "Read string error", + &readResult, 200)); msg = NULL; GNUNET_BIO_read_close (fileR, &msg); GNUNET_free (msg); @@ -335,8 +334,8 @@ test_fakemeta_rw () GNUNET_assert (NULL != fileR); metaDataR = NULL; GNUNET_assert (GNUNET_SYSERR == - GNUNET_BIO_read_meta_data (fileR, "Read meta error", - &metaDataR)); + GNUNET_BIO_read_meta_data (fileR, "Read meta error", + &metaDataR)); GNUNET_assert (NULL == metaDataR); msg = NULL; GNUNET_BIO_read_close (fileR, &msg); @@ -365,8 +364,8 @@ test_fakebigmeta_rw () GNUNET_assert (NULL != fileR); metaDataR = NULL; GNUNET_assert (GNUNET_SYSERR == - GNUNET_BIO_read_meta_data (fileR, "Read meta error", - &metaDataR)); + GNUNET_BIO_read_meta_data (fileR, "Read meta error", + &metaDataR)); msg = NULL; GNUNET_BIO_read_close (fileR, &msg); GNUNET_free (msg); diff --git a/src/util/test_client.c b/src/util/test_client.c index ad88874f2..bb7d5008a 100644 --- a/src/util/test_client.c +++ b/src/util/test_client.c @@ -71,25 +71,24 @@ copy_msg (void *cls, size_t size, void *buf) */ static void echo_cb (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) + const struct GNUNET_MessageHeader *message) { struct CopyContext *cc; struct GNUNET_MessageHeader *cpy; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Receiving message from client, bouncing back\n"); - GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == - ntohs (message->size)); + "Receiving message from client, bouncing back\n"); + GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)); cc = GNUNET_malloc (sizeof (struct CopyContext)); cc->client = client; cpy = GNUNET_malloc (ntohs (message->size)); memcpy (cpy, message, ntohs (message->size)); cc->cpy = cpy; GNUNET_assert (NULL != - GNUNET_SERVER_notify_transmit_ready (client, - ntohs (message->size), - GNUNET_TIME_UNIT_SECONDS, - ©_msg, cc)); + GNUNET_SERVER_notify_transmit_ready (client, + ntohs (message->size), + GNUNET_TIME_UNIT_SECONDS, + ©_msg, cc)); } @@ -105,13 +104,11 @@ recv_bounce (void *cls, const struct GNUNET_MessageHeader *got) int *ok = cls; struct GNUNET_MessageHeader msg; - GNUNET_assert (got != NULL); /* timeout */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Receiving bounce, checking content\n"); + GNUNET_assert (got != NULL); /* timeout */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving bounce, checking content\n"); msg.type = htons (MY_TYPE); msg.size = htons (sizeof (struct GNUNET_MessageHeader)); - GNUNET_assert (0 == - memcmp (got, &msg, sizeof (struct GNUNET_MessageHeader))); + GNUNET_assert (0 == memcmp (got, &msg, sizeof (struct GNUNET_MessageHeader))); GNUNET_CLIENT_disconnect (client, GNUNET_YES); client = NULL; GNUNET_SERVER_destroy (server); @@ -151,9 +148,9 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) sa.sin_family = AF_INET; sa.sin_port = htons (PORT); server = - GNUNET_SERVER_create (NULL, NULL, sap, slens, - GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_MILLISECONDS, 10000), GNUNET_NO); + GNUNET_SERVER_create (NULL, NULL, sap, slens, + GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_MILLISECONDS, 10000), GNUNET_NO); GNUNET_assert (server != NULL); handlers[0].callback_cls = cls; handlers[1].callback_cls = cls; @@ -161,15 +158,15 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) client = GNUNET_CLIENT_connect (MYNAME, cfg); GNUNET_assert (client != NULL); GNUNET_assert (NULL != - GNUNET_CLIENT_notify_transmit_ready (client, - sizeof (struct - GNUNET_MessageHeader), - GNUNET_TIME_UNIT_SECONDS, - GNUNET_NO, &make_msg, - NULL)); + GNUNET_CLIENT_notify_transmit_ready (client, + sizeof (struct + GNUNET_MessageHeader), + GNUNET_TIME_UNIT_SECONDS, + GNUNET_NO, &make_msg, + NULL)); GNUNET_CLIENT_receive (client, &recv_bounce, cls, - GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_MILLISECONDS, 10000)); + GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_MILLISECONDS, 10000)); } @@ -184,10 +181,9 @@ check () cfg = GNUNET_CONFIGURATION_create (); GNUNET_CONFIGURATION_set_value_number (cfg, MYNAME, "PORT", PORT); - GNUNET_CONFIGURATION_set_value_string (cfg, MYNAME, "HOSTNAME", - "localhost"); + GNUNET_CONFIGURATION_set_value_string (cfg, MYNAME, "HOSTNAME", "localhost"); GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", - "localhost"); + "localhost"); ok = 1; GNUNET_SCHEDULER_run (&task, &ok); GNUNET_CONFIGURATION_destroy (cfg); @@ -201,11 +197,11 @@ main (int argc, char *argv[]) GNUNET_log_setup ("test_client", #if VERBOSE - "DEBUG", + "DEBUG", #else - "WARNING", + "WARNING", #endif - NULL); + NULL); ret += check (); return ret; diff --git a/src/util/test_common_allocation.c b/src/util/test_common_allocation.c index 2fb1329b1..950f0cedb 100644 --- a/src/util/test_common_allocation.c +++ b/src/util/test_common_allocation.c @@ -36,21 +36,21 @@ check () unsigned int ui; /* GNUNET_malloc/GNUNET_free test */ - k = 352; /* random start value */ + k = 352; /* random start value */ for (i = 1; i < MAX_TESTVAL; i++) - { - ptrs[i] = GNUNET_malloc (i); - for (j = 0; j < i; j++) - ptrs[i][j] = k++; - } + { + ptrs[i] = GNUNET_malloc (i); + for (j = 0; j < i; j++) + ptrs[i][j] = k++; + } for (i = MAX_TESTVAL - 1; i >= 1; i--) - { - for (j = i - 1; j >= 0; j--) - if (ptrs[i][j] != (char) --k) - return 1; - GNUNET_free (ptrs[i]); - } + { + for (j = i - 1; j >= 0; j--) + if (ptrs[i][j] != (char) --k) + return 1; + GNUNET_free (ptrs[i]); + } /* GNUNET_free_non_null test */ GNUNET_free_non_null (NULL); diff --git a/src/util/test_common_logging.c b/src/util/test_common_logging.c index a940d3c07..cf291161e 100644 --- a/src/util/test_common_logging.c +++ b/src/util/test_common_logging.c @@ -28,7 +28,7 @@ static void my_log (void *ctx, enum GNUNET_ErrorType kind, const char *component, - const char *date, const char *msg) + const char *date, const char *msg) { unsigned int *c = ctx; @@ -44,9 +44,7 @@ main (int argc, char *argv[]) unsigned int logs = 0; if (0 != setenv ("GNUNET_FORCE_LOG", "", 1)) - fprintf (stderr, - "Failed to setenv: %s\n", - strerror (errno)); + fprintf (stderr, "Failed to setenv: %s\n", strerror (errno)); GNUNET_log_setup ("test-common-logging", "DEBUG", "/dev/null"); GNUNET_logger_add (&my_log, &logs); GNUNET_logger_add (&my_log, &logs); @@ -61,26 +59,23 @@ main (int argc, char *argv[]) /* the last 6 calls should be merged (repated bulk messages!) */ GNUNET_logger_remove (&my_log, &logs); if (logs != 4) - { - fprintf (stdout, "Expected 4 log calls, got %u\n", logs); - failureCount++; - } + { + fprintf (stdout, "Expected 4 log calls, got %u\n", logs); + failureCount++; + } GNUNET_break (0 == - strcmp (_("ERROR"), - GNUNET_error_type_to_string - (GNUNET_ERROR_TYPE_ERROR))); + strcmp (_("ERROR"), + GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_ERROR))); GNUNET_break (0 == - strcmp (_("WARNING"), - GNUNET_error_type_to_string - (GNUNET_ERROR_TYPE_WARNING))); + strcmp (_("WARNING"), + GNUNET_error_type_to_string + (GNUNET_ERROR_TYPE_WARNING))); GNUNET_break (0 == - strcmp (_("INFO"), - GNUNET_error_type_to_string - (GNUNET_ERROR_TYPE_INFO))); + strcmp (_("INFO"), + GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_INFO))); GNUNET_break (0 == - strcmp (_("DEBUG"), - GNUNET_error_type_to_string - (GNUNET_ERROR_TYPE_DEBUG))); + strcmp (_("DEBUG"), + GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_DEBUG))); GNUNET_log_setup ("test_common_logging", "WARNING", "/dev/null"); logs = 0; GNUNET_logger_add (&my_log, &logs); @@ -88,17 +83,17 @@ main (int argc, char *argv[]) GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Drop me...\n"); GNUNET_logger_remove (&my_log, &logs); if (logs != 1) - { - fprintf (stdout, "Expected 1 log call, got %u\n", logs); - failureCount++; - } + { + fprintf (stdout, "Expected 1 log call, got %u\n", logs); + failureCount++; + } if (failureCount != 0) - { - fprintf (stdout, "%u TESTS FAILED!\n", failureCount); - return -1; - } + { + fprintf (stdout, "%u TESTS FAILED!\n", failureCount); + return -1; + } return 0; -} /* end of main */ +} /* end of main */ /* end of test_common_logging.c */ diff --git a/src/util/test_common_logging_dummy.c b/src/util/test_common_logging_dummy.c index d87f56d42..005b5caef 100644 --- a/src/util/test_common_logging_dummy.c +++ b/src/util/test_common_logging_dummy.c @@ -33,7 +33,7 @@ static void my_log (void *ctx, enum GNUNET_ErrorType kind, const char *component, - const char *date, const char *msg) + const char *date, const char *msg) { if (strncmp ("test-common-logging-dummy", component, 25) != 0) return; @@ -87,6 +87,6 @@ main (int argc, char *argv[]) pr2 (GNUNET_ERROR_TYPE_INFO, "INFO"); pr2 (GNUNET_ERROR_TYPE_DEBUG, "DEBUG"); return 0; -} /* end of main */ +} /* end of main */ /* end of test_common_logging_dummy.c */ diff --git a/src/util/test_common_logging_runtime_loglevels.c b/src/util/test_common_logging_runtime_loglevels.c index 6485e4e4a..5b89b7221 100644 --- a/src/util/test_common_logging_runtime_loglevels.c +++ b/src/util/test_common_logging_runtime_loglevels.c @@ -42,108 +42,110 @@ static struct GNUNET_DISK_PipeHandle *pipe_stdout; static GNUNET_SCHEDULER_TaskIdentifier die_task; -static void runone (); +static void +runone (); static void end_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending phase %d, ok is %d\n", phase, - ok); + ok); if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) - { - GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - } + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); + } GNUNET_OS_process_wait (proc); GNUNET_OS_process_close (proc); proc = NULL; GNUNET_DISK_pipe_close (pipe_stdout); if (ok == 1) + { + if (phase < 9) { - if (phase < 9) - { - phase += 1; - runone (); - } - else - ok = 0; + phase += 1; + runone (); } + else + ok = 0; + } else GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "failing\n"); } static char * read_output_line (int phase_from1, int phase_to1, int phase_from2, - int phase_to2, char c, char *expect_level, - long delay_morethan, long delay_lessthan, int phase, - char *p, int *len, long *delay, char level[8]) + int phase_to2, char c, char *expect_level, + long delay_morethan, long delay_lessthan, int phase, char *p, + int *len, long *delay, char level[8]) { char *r = p; char t[7]; int i, j, stop = 0; + j = 0; int stage = 0; + if (!(phase >= phase_from1 && phase <= phase_to1) && !(phase >= phase_from2 && phase <= phase_to2)) return p; #if 0 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Trying to match '%c%s \\d\\r\\n' on %s\n", c, expect_level, p); + "Trying to match '%c%s \\d\\r\\n' on %s\n", c, expect_level, p); #endif for (i = 0; i < *len && !stop; i++) + { + switch (stage) { - switch (stage) - { - case 0: /* read first char */ - if (r[i] != c) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Expected '%c', but got '%c'\n", c, r[i]); - GNUNET_break (0); - return NULL; - } - stage += 1; - break; - case 1: /* read at most 7 char-long error level string, finished by ' ' */ - if (r[i] == ' ') - { - level[j] = '\0'; - stage += 1; - j = 0; - } - else if (i == 8) - { - GNUNET_break (0); - ok = 2; - return NULL; - } - else - level[j++] = r[i]; - break; - case 2: /* read the delay, finished by '\n' */ - t[j++] = r[i]; + case 0: /* read first char */ + if (r[i] != c) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expected '%c', but got '%c'\n", c, + r[i]); + GNUNET_break (0); + return NULL; + } + stage += 1; + break; + case 1: /* read at most 7 char-long error level string, finished by ' ' */ + if (r[i] == ' ') + { + level[j] = '\0'; + stage += 1; + j = 0; + } + else if (i == 8) + { + GNUNET_break (0); + ok = 2; + return NULL; + } + else + level[j++] = r[i]; + break; + case 2: /* read the delay, finished by '\n' */ + t[j++] = r[i]; #if WINDOWS - if (r[i] == '\r' && r[i + 1] == '\n') - { - i += 1; - t[j - 1] = '\0'; - *delay = strtol (t, NULL, 10); - stop = 1; - } + if (r[i] == '\r' && r[i + 1] == '\n') + { + i += 1; + t[j - 1] = '\0'; + *delay = strtol (t, NULL, 10); + stop = 1; + } #else - if (r[i] == '\n') - { - t[j - 1] = '\0'; - *delay = strtol (t, NULL, 10); - stop = 1; - } + if (r[i] == '\n') + { + t[j - 1] = '\0'; + *delay = strtol (t, NULL, 10); + stop = 1; + } #endif - break; - } + break; } - if (!stop || strcmp (expect_level, level) != 0 || *delay < 0 - || *delay > 1000 - || (!((*delay < delay_lessthan) || !(*delay > delay_morethan)) - && c != '1' && c != '2')) + } + if (!stop || strcmp (expect_level, level) != 0 || *delay < 0 || *delay > 1000 + || (!((*delay < delay_lessthan) || !(*delay > delay_morethan)) && c != '1' + && c != '2')) return NULL; *len = *len - i; return &r[i]; @@ -162,20 +164,20 @@ read_call (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) long delays[8]; int rd; - rd = - GNUNET_DISK_file_read (stdout_read_handle, buf_ptr, sizeof (buf) - bytes); + rd = GNUNET_DISK_file_read (stdout_read_handle, buf_ptr, + sizeof (buf) - bytes); if (rd > 0) - { - buf_ptr += rd; - bytes += rd; + { + buf_ptr += rd; + bytes += rd; #if VERBOSE - fprintf (stderr, "got %d bytes, reading more\n", rd); + fprintf (stderr, "got %d bytes, reading more\n", rd); #endif - GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, - stdout_read_handle, &read_call, - (void *) stdout_read_handle); - return; - } + GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, + stdout_read_handle, &read_call, + (void *) stdout_read_handle); + return; + } #if VERBOSE fprintf (stderr, "bytes is %d:%s\n", bytes, buf); @@ -197,64 +199,65 @@ read_call (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) * | 9 * * * * */ char *p = buf; + if (bytes == 20 * 16 || !(p = - read_output_line (0, 3, 4, 9, 'L', "ERROR", -1, 1, phase, p, &bytes, - &delay, level)) - || !(p = - read_output_line (0, 3, 4, 9, '1', "ERROR", 200, 400, phase, p, - &bytes, &delays[0], level)) - || !(p = - read_output_line (1, 3, 5, 9, 'L', "WARNING", -1, 1, phase, p, - &bytes, &delay, level)) - || !(p = - read_output_line (0, 3, 4, 9, '1', "WARNING", 200, 400, phase, p, - &bytes, &delays[1], level)) - || !(p = - read_output_line (2, 3, 6, 7, 'L', "INFO", -1, 1, phase, p, &bytes, - &delay, level)) - || !(p = - read_output_line (0, 3, 4, 9, '1', "INFO", 200, 400, phase, p, - &bytes, &delays[2], level)) - || !(p = - read_output_line (3, 3, 7, 7, 'L', "DEBUG", -1, 1, phase, p, - &bytes, &delay, level)) - || !(p = - read_output_line (0, 3, 4, 9, '1', "DEBUG", 200, 400, phase, p, - &bytes, &delays[3], level)) - || !(p = - read_output_line (0, 3, 4, 9, 'L', "ERROR", -1, 1, phase, p, - &bytes, &delay, level)) - || !(p = - read_output_line (0, 3, 4, 9, '2', "ERROR", 200, 400, phase, p, - &bytes, &delays[4], level)) - || !(p = - read_output_line (0, 3, 5, 9, 'L', "WARNING", -1, 1, phase, p, - &bytes, &delay, level)) - || !(p = - read_output_line (0, 3, 4, 9, '2', "WARNING", 200, 400, phase, p, - &bytes, &delays[5], level)) - || !(p = - read_output_line (-1, -1, 6, 7, 'L', "INFO", -1, 1, phase, p, - &bytes, &delay, level)) - || !(p = - read_output_line (0, 3, 4, 9, '2', "INFO", 200, 400, phase, p, - &bytes, &delays[6], level)) - || !(p = - read_output_line (-1, -1, 7, 7, 'L', "DEBUG", -1, 1, phase, p, - &bytes, &delay, level)) - || !(p = - read_output_line (0, 3, 4, 9, '2', "DEBUG", 200, 400, phase, p, - &bytes, &delays[7], level))) - { - if (bytes == 20 * 16) - fprintf (stderr, "Ran out of buffer space!\n"); - GNUNET_break (0); - ok = 2; - GNUNET_SCHEDULER_cancel (die_task); - GNUNET_SCHEDULER_add_now (&end_task, NULL); - return; - } + read_output_line (0, 3, 4, 9, 'L', "ERROR", -1, 1, phase, p, &bytes, + &delay, level)) || + !(p = + read_output_line (0, 3, 4, 9, '1', "ERROR", 200, 400, phase, p, &bytes, + &delays[0], level)) || + !(p = + read_output_line (1, 3, 5, 9, 'L', "WARNING", -1, 1, phase, p, &bytes, + &delay, level)) || + !(p = + read_output_line (0, 3, 4, 9, '1', "WARNING", 200, 400, phase, p, + &bytes, &delays[1], level)) || + !(p = + read_output_line (2, 3, 6, 7, 'L', "INFO", -1, 1, phase, p, &bytes, + &delay, level)) || + !(p = + read_output_line (0, 3, 4, 9, '1', "INFO", 200, 400, phase, p, &bytes, + &delays[2], level)) || + !(p = + read_output_line (3, 3, 7, 7, 'L', "DEBUG", -1, 1, phase, p, &bytes, + &delay, level)) || + !(p = + read_output_line (0, 3, 4, 9, '1', "DEBUG", 200, 400, phase, p, &bytes, + &delays[3], level)) || + !(p = + read_output_line (0, 3, 4, 9, 'L', "ERROR", -1, 1, phase, p, &bytes, + &delay, level)) || + !(p = + read_output_line (0, 3, 4, 9, '2', "ERROR", 200, 400, phase, p, &bytes, + &delays[4], level)) || + !(p = + read_output_line (0, 3, 5, 9, 'L', "WARNING", -1, 1, phase, p, &bytes, + &delay, level)) || + !(p = + read_output_line (0, 3, 4, 9, '2', "WARNING", 200, 400, phase, p, + &bytes, &delays[5], level)) || + !(p = + read_output_line (-1, -1, 6, 7, 'L', "INFO", -1, 1, phase, p, &bytes, + &delay, level)) || + !(p = + read_output_line (0, 3, 4, 9, '2', "INFO", 200, 400, phase, p, &bytes, + &delays[6], level)) || + !(p = + read_output_line (-1, -1, 7, 7, 'L', "DEBUG", -1, 1, phase, p, &bytes, + &delay, level)) || + !(p = + read_output_line (0, 3, 4, 9, '2', "DEBUG", 200, 400, phase, p, &bytes, + &delays[7], level))) + { + if (bytes == 20 * 16) + fprintf (stderr, "Ran out of buffer space!\n"); + GNUNET_break (0); + ok = 2; + GNUNET_SCHEDULER_cancel (die_task); + GNUNET_SCHEDULER_add_now (&end_task, NULL); + return; + } GNUNET_SCHEDULER_cancel (die_task); GNUNET_SCHEDULER_add_now (&end_task, NULL); @@ -268,52 +271,51 @@ runone () pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES); if (pipe_stdout == NULL) - { - GNUNET_break (0); - ok = 2; - return; - } + { + GNUNET_break (0); + ok = 2; + return; + } putenv ("GNUNET_LOG="); putenv ("GNUNET_FORCE_LOG="); switch (phase) - { - case 0: - putenv ("GNUNET_LOG=;;;;ERROR"); - break; - case 1: - putenv ("GNUNET_LOG=;;;;WARNING"); - break; - case 2: - putenv ("GNUNET_LOG=;;;;INFO"); - break; - case 3: - putenv ("GNUNET_LOG=;;;;DEBUG"); - break; - case 4: - putenv ("GNUNET_FORCE_LOG=;;;;ERROR"); - break; - case 5: - putenv ("GNUNET_FORCE_LOG=;;;;WARNING"); - break; - case 6: - putenv ("GNUNET_FORCE_LOG=;;;;INFO"); - break; - case 7: - putenv ("GNUNET_FORCE_LOG=;;;;DEBUG"); - break; - case 8: - putenv ("GNUNET_LOG=blah;;;;ERROR"); - break; - case 9: - putenv ("GNUNET_FORCE_LOG=blah;;;;ERROR"); - break; - } + { + case 0: + putenv ("GNUNET_LOG=;;;;ERROR"); + break; + case 1: + putenv ("GNUNET_LOG=;;;;WARNING"); + break; + case 2: + putenv ("GNUNET_LOG=;;;;INFO"); + break; + case 3: + putenv ("GNUNET_LOG=;;;;DEBUG"); + break; + case 4: + putenv ("GNUNET_FORCE_LOG=;;;;ERROR"); + break; + case 5: + putenv ("GNUNET_FORCE_LOG=;;;;WARNING"); + break; + case 6: + putenv ("GNUNET_FORCE_LOG=;;;;INFO"); + break; + case 7: + putenv ("GNUNET_FORCE_LOG=;;;;DEBUG"); + break; + case 8: + putenv ("GNUNET_LOG=blah;;;;ERROR"); + break; + case 9: + putenv ("GNUNET_FORCE_LOG=blah;;;;ERROR"); + break; + } proc = - GNUNET_OS_start_process (NULL, pipe_stdout, - "./test_common_logging_dummy", - "test_common_logging_dummy", NULL); + GNUNET_OS_start_process (NULL, pipe_stdout, "./test_common_logging_dummy", + "test_common_logging_dummy", NULL); putenv ("GNUNET_FORCE_LOG="); putenv ("GNUNET_LOG="); @@ -321,20 +323,20 @@ runone () GNUNET_DISK_pipe_close_end (pipe_stdout, GNUNET_DISK_PIPE_END_WRITE); stdout_read_handle = - GNUNET_DISK_pipe_handle (pipe_stdout, GNUNET_DISK_PIPE_END_READ); + GNUNET_DISK_pipe_handle (pipe_stdout, GNUNET_DISK_PIPE_END_READ); die_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_SECONDS, 10), &end_task, - NULL); + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, 10), &end_task, + NULL); bytes = 0; buf_ptr = buf; memset (&buf, 0, sizeof (buf)); GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, - stdout_read_handle, &read_call, - (void *) stdout_read_handle); + stdout_read_handle, &read_call, + (void *) stdout_read_handle); } static void @@ -364,11 +366,11 @@ main (int argc, char *argv[]) GNUNET_log_setup ("test-common-logging-runtime-loglevels", #if VERBOSE - "DEBUG", + "DEBUG", #else - "WARNING", + "WARNING", #endif - NULL); + NULL); ret = check (); return ret; diff --git a/src/util/test_configuration.c b/src/util/test_configuration.c index 9deb4fc35..3780b3649 100644 --- a/src/util/test_configuration.c +++ b/src/util/test_configuration.c @@ -42,7 +42,7 @@ enum REMOVE_ENTRY, COMPARE #if DEBUG - , PRINT + , PRINT #endif }; @@ -76,80 +76,80 @@ initDiffsCBData (struct DiffsCBData *cbData) */ static void diffsCallBack (void *cls, const char *section, const char *option, - const char *value) + const char *value) { struct DiffsCBData *cbData = cls; int cbOption = cbData->callBackOption; switch (cbOption) + { + case EDIT_SECTION: + if (NULL == cbData->section) + cbData->section = section; + if (strcmp (cbData->section, section) == 0) { - case EDIT_SECTION: - if (NULL == cbData->section) - cbData->section = section; - if (strcmp (cbData->section, section) == 0) - { - GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, option, - "new-value"); - GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section, - option, "new-value"); - } - break; - case EDIT_ALL: GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, option, - "new-value"); + "new-value"); + GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section, option, + "new-value"); + } + break; + case EDIT_ALL: + GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, option, + "new-value"); + GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section, option, + "new-value"); + break; + case ADD_NEW_ENTRY: + { + static int hit = 0; + + if (hit == 0) + { + hit = 1; + GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, "new-key", + "new-value"); GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section, - option, "new-value"); - break; - case ADD_NEW_ENTRY: - { - static int hit = 0; - - if (hit == 0) - { - hit = 1; - GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, - "new-key", "new-value"); - GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section, - "new-key", "new-value"); - } - break; - } - case COMPARE: - { - int ret; - char *diffValue; - - diffValue = NULL; - ret = - GNUNET_CONFIGURATION_get_value_string (cbData->cfgDiffs, section, - option, &diffValue); - if (NULL != diffValue) - { - if (ret == GNUNET_SYSERR || strcmp (diffValue, value) != 0) - cbData->status = 1; - } - else - cbData->status = 1; - GNUNET_free_non_null (diffValue); - break; - } + "new-key", "new-value"); + } + break; + } + case COMPARE: + { + int ret; + char *diffValue; + + diffValue = NULL; + ret = + GNUNET_CONFIGURATION_get_value_string (cbData->cfgDiffs, section, + option, &diffValue); + if (NULL != diffValue) + { + if (ret == GNUNET_SYSERR || strcmp (diffValue, value) != 0) + cbData->status = 1; + } + else + cbData->status = 1; + GNUNET_free_non_null (diffValue); + break; + } #if 0 - case PRINT: - if (NULL == cbData->section) - { - cbData->section = section; - printf ("\nSection: %s\n", section); - } - else if (strcmp (cbData->section, section) != 0) - { - cbData->section = section; - printf ("\nSection: %s\n", section); - } - printf ("%s = %s\n", option, value); -#endif - default: - break; + case PRINT: + if (NULL == cbData->section) + { + cbData->section = section; + printf ("\nSection: %s\n", section); } + else if (strcmp (cbData->section, section) != 0) + { + cbData->section = section; + printf ("\nSection: %s\n", section); + } + printf ("%s = %s\n", option, value); +#endif + default: + break; + } } @@ -162,41 +162,40 @@ editConfiguration (struct GNUNET_CONFIGURATION_Handle *cfg, int option) diffsCB.cfgDiffs = GNUNET_CONFIGURATION_create (); switch (option) + { + case EDIT_SECTION: + case EDIT_ALL: + case ADD_NEW_ENTRY: + diffsCB.callBackOption = option; + diffsCB.cfg = cfg; + GNUNET_CONFIGURATION_iterate (cfg, diffsCallBack, &diffsCB); + break; + case EDIT_NOTHING: + /* Do nothing */ + break; + case ADD_NEW_SECTION: + { + int i; + char *key; + + for (i = 0; i < 5; i++) { - case EDIT_SECTION: - case EDIT_ALL: - case ADD_NEW_ENTRY: - diffsCB.callBackOption = option; - diffsCB.cfg = cfg; - GNUNET_CONFIGURATION_iterate (cfg, diffsCallBack, &diffsCB); - break; - case EDIT_NOTHING: - /* Do nothing */ - break; - case ADD_NEW_SECTION: - { - int i; - char *key; - - for (i = 0; i < 5; i++) - { - GNUNET_asprintf (&key, "key%d", i); - GNUNET_CONFIGURATION_set_value_string (cfg, "new-section", key, - "new-value"); - GNUNET_CONFIGURATION_set_value_string (diffsCB.cfgDiffs, - "new-section", key, - "new-value"); - GNUNET_free (key); - } - break; - } - case REMOVE_SECTION: - break; - case REMOVE_ENTRY: - break; - default: - break; + GNUNET_asprintf (&key, "key%d", i); + GNUNET_CONFIGURATION_set_value_string (cfg, "new-section", key, + "new-value"); + GNUNET_CONFIGURATION_set_value_string (diffsCB.cfgDiffs, "new-section", + key, "new-value"); + GNUNET_free (key); } + break; + } + case REMOVE_SECTION: + break; + case REMOVE_ENTRY: + break; + default: + break; + } return diffsCB.cfgDiffs; } @@ -221,37 +220,35 @@ checkDiffs (struct GNUNET_CONFIGURATION_Handle *cfgDefault, int option) /* Modify configuration and save it */ cfgDiffs = editConfiguration (cfg, option); - diffsFileName = - GNUNET_DISK_mktemp ("gnunet-test-configurations-diffs.conf"); + diffsFileName = GNUNET_DISK_mktemp ("gnunet-test-configurations-diffs.conf"); if (diffsFileName == NULL) - { - GNUNET_break (0); - GNUNET_CONFIGURATION_destroy (cfg); - GNUNET_CONFIGURATION_destroy (cfgDiffs); - return 1; - } + { + GNUNET_break (0); + GNUNET_CONFIGURATION_destroy (cfg); + GNUNET_CONFIGURATION_destroy (cfgDiffs); + return 1; + } GNUNET_CONFIGURATION_write_diffs (cfgDefault, cfg, diffsFileName); GNUNET_CONFIGURATION_destroy (cfg); /* Compare the dumped configuration with modifications done */ cfg = GNUNET_CONFIGURATION_create (); - GNUNET_assert (GNUNET_OK == - GNUNET_CONFIGURATION_parse (cfg, diffsFileName)); + GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_parse (cfg, diffsFileName)); remove (diffsFileName); cbData.callBackOption = COMPARE; cbData.cfgDiffs = cfgDiffs; GNUNET_CONFIGURATION_iterate (cfg, diffsCallBack, &cbData); if (1 == (ret = cbData.status)) - { - fprintf (stderr, - "Incorrect Configuration Diffs: Diffs may contain data not actually edited\n"); - goto housekeeping; - } + { + fprintf (stderr, + "Incorrect Configuration Diffs: Diffs may contain data not actually edited\n"); + goto housekeeping; + } cbData.cfgDiffs = cfg; GNUNET_CONFIGURATION_iterate (cfgDiffs, diffsCallBack, &cbData); if ((ret = cbData.status) == 1) fprintf (stderr, - "Incorrect Configuration Diffs: Data may be missing in diffs\n"); + "Incorrect Configuration Diffs: Data may be missing in diffs\n"); housekeeping: #if 0 @@ -276,65 +273,64 @@ testConfig () char *c; unsigned long long l; - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string (cfg, "test", "b", &c)) + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "test", "b", &c)) return 1; if (0 != strcmp ("b", c)) - { - fprintf (stderr, "Got `%s'\n", c); - GNUNET_free (c); - return 2; - } + { + fprintf (stderr, "Got `%s'\n", c); + GNUNET_free (c); + return 2; + } GNUNET_free (c); if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "test", "five", &l)) - { - GNUNET_break (0); - return 3; - } + { + GNUNET_break (0); + return 3; + } if (5 != l) - { - GNUNET_break (0); - return 4; - } + { + GNUNET_break (0); + return 4; + } GNUNET_CONFIGURATION_set_value_string (cfg, "more", "c", "YES"); if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_yesno (cfg, "more", "c")) - { - GNUNET_break (0); - return 5; - } + { + GNUNET_break (0); + return 5; + } GNUNET_CONFIGURATION_set_value_number (cfg, "NUMBERS", "TEN", 10); if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "NUMBERS", "TEN", &c)) - { - GNUNET_break (0); - return 6; - } + { + GNUNET_break (0); + return 6; + } if (0 != strcmp (c, "10")) - { - GNUNET_free (c); - GNUNET_break (0); - return 7; - } + { + GNUNET_free (c); + GNUNET_break (0); + return 7; + } GNUNET_free (c); if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "last", "test", &c)) - { - GNUNET_break (0); - return 8; - } + { + GNUNET_break (0); + return 8; + } #ifndef MINGW if (0 != strcmp (c, "/hello/world")) #else #define HI "\\hello\\world" if (strstr (c, HI) != c + strlen (c) - strlen (HI)) #endif - { - GNUNET_break (0); - GNUNET_free (c); - return 9; - } + { + GNUNET_break (0); + GNUNET_free (c); + return 9; + } GNUNET_free (c); if (GNUNET_OK != @@ -365,10 +361,10 @@ check (void *data, const char *fn) int *idx = data; if (0 == strcmp (want[*idx], fn)) - { - (*idx)++; - return GNUNET_OK; - } + { + (*idx)++; + return GNUNET_OK; + } GNUNET_break (0); return GNUNET_SYSERR; } @@ -381,66 +377,66 @@ testConfigFilenames () idx = 0; if (3 != GNUNET_CONFIGURATION_iterate_value_filenames (cfg, "FILENAMES", "test", - &check, &idx)) - { - GNUNET_break (0); - return 8; - } + &check, &idx)) + { + GNUNET_break (0); + return 8; + } if (idx != 3) return 16; if (GNUNET_OK != GNUNET_CONFIGURATION_remove_value_filename (cfg, "FILENAMES", "test", - "/File Name")) - { - GNUNET_break (0); - return 24; - } + "/File Name")) + { + GNUNET_break (0); + return 24; + } if (GNUNET_NO != GNUNET_CONFIGURATION_remove_value_filename (cfg, "FILENAMES", "test", - "/File Name")) - { - GNUNET_break (0); - return 32; - } + "/File Name")) + { + GNUNET_break (0); + return 32; + } if (GNUNET_NO != GNUNET_CONFIGURATION_remove_value_filename (cfg, "FILENAMES", "test", - "Stuff")) - { - GNUNET_break (0); - return 40; - } + "Stuff")) + { + GNUNET_break (0); + return 40; + } if (GNUNET_NO != GNUNET_CONFIGURATION_append_value_filename (cfg, "FILENAMES", "test", - "/Hello")) - { - GNUNET_break (0); - return 48; - } + "/Hello")) + { + GNUNET_break (0); + return 48; + } if (GNUNET_NO != GNUNET_CONFIGURATION_append_value_filename (cfg, "FILENAMES", "test", - "/World")) - { - GNUNET_break (0); - return 56; - } + "/World")) + { + GNUNET_break (0); + return 56; + } if (GNUNET_YES != GNUNET_CONFIGURATION_append_value_filename (cfg, "FILENAMES", "test", - "/File 1")) - { - GNUNET_break (0); - return 64; - } + "/File 1")) + { + GNUNET_break (0); + return 64; + } if (GNUNET_YES != GNUNET_CONFIGURATION_append_value_filename (cfg, "FILENAMES", "test", - "/File 2")) - { - GNUNET_break (0); - return 72; - } + "/File 2")) + { + GNUNET_break (0); + return 72; + } idx = 0; want[1] = "/World"; @@ -448,16 +444,16 @@ testConfigFilenames () want[3] = "/File 2"; if (4 != GNUNET_CONFIGURATION_iterate_value_filenames (cfg, "FILENAMES", "test", - &check, &idx)) - { - GNUNET_break (0); - return 80; - } + &check, &idx)) + { + GNUNET_break (0); + return 80; + } if (idx != 4) - { - GNUNET_break (0); - return 88; - } + { + GNUNET_break (0); + return 88; + } return 0; } @@ -473,11 +469,11 @@ main (int argc, char *argv[]) GNUNET_assert (cfg != NULL); if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, "test_configuration_data.conf")) - { - fprintf (stderr, "Failed to parse configuration file\n"); - GNUNET_CONFIGURATION_destroy (cfg); - return 1; - } + { + fprintf (stderr, "Failed to parse configuration file\n"); + GNUNET_CONFIGURATION_destroy (cfg); + return 1; + } failureCount += testConfig (); if (failureCount > 0) goto error; @@ -487,37 +483,36 @@ main (int argc, char *argv[]) goto error; if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, "/tmp/gnunet-test.conf")) - { - fprintf (stderr, "Failed to write configuration file\n"); - GNUNET_CONFIGURATION_destroy (cfg); - return 1; - } + { + fprintf (stderr, "Failed to write configuration file\n"); + GNUNET_CONFIGURATION_destroy (cfg); + return 1; + } GNUNET_CONFIGURATION_destroy (cfg); GNUNET_assert (0 == UNLINK ("/tmp/gnunet-test.conf")); cfg = GNUNET_CONFIGURATION_create (); if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, "test_configuration_data.conf")) - { - GNUNET_break (0); - GNUNET_CONFIGURATION_destroy (cfg); - return 1; - } + { + GNUNET_break (0); + GNUNET_CONFIGURATION_destroy (cfg); + return 1; + } if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", "WEAKRANDOM", - &c)) - { - GNUNET_break (0); - GNUNET_CONFIGURATION_destroy (cfg); - return 1; - } + GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", "WEAKRANDOM", &c)) + { + GNUNET_break (0); + GNUNET_CONFIGURATION_destroy (cfg); + return 1; + } if (0 != strcmp (c, "YES")) - { - GNUNET_break (0); - GNUNET_free (c); - GNUNET_CONFIGURATION_destroy (cfg); - return 1; - } + { + GNUNET_break (0); + GNUNET_free (c); + GNUNET_CONFIGURATION_destroy (cfg); + return 1; + } GNUNET_free (c); GNUNET_CONFIGURATION_destroy (cfg); @@ -525,11 +520,11 @@ main (int argc, char *argv[]) /* Testing configuration diffs */ cfgDefault = GNUNET_CONFIGURATION_create (); if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfgDefault, NULL)) - { - GNUNET_break (0); - GNUNET_CONFIGURATION_destroy (cfgDefault); - return 1; - } + { + GNUNET_break (0); + GNUNET_CONFIGURATION_destroy (cfgDefault); + return 1; + } /* Nothing changed in the new configuration */ failureCount += checkDiffs (cfgDefault, EDIT_NOTHING); @@ -550,9 +545,9 @@ main (int argc, char *argv[]) error: if (failureCount != 0) - { - fprintf (stderr, "Test failed: %u\n", failureCount); - return 1; - } + { + fprintf (stderr, "Test failed: %u\n", failureCount); + return 1; + } return 0; } diff --git a/src/util/test_connection.c b/src/util/test_connection.c index 1ac5b99cd..92c0cea2e 100644 --- a/src/util/test_connection.c +++ b/src/util/test_connection.c @@ -66,46 +66,44 @@ open_listen_socket () GNUNET_assert (desc != NULL); if (GNUNET_NETWORK_socket_setsockopt (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) - GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "setsockopt"); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); GNUNET_assert (GNUNET_NETWORK_socket_bind - (desc, (const struct sockaddr *) &sa, - sizeof (sa)) == GNUNET_OK); + (desc, (const struct sockaddr *) &sa, + sizeof (sa)) == GNUNET_OK); GNUNET_NETWORK_socket_listen (desc, 5); return desc; } static void receive_check (void *cls, const void *buf, size_t available, - const struct sockaddr *addr, socklen_t addrlen, int errCode) + const struct sockaddr *addr, socklen_t addrlen, int errCode) { int *ok = cls; #if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receive validates incoming data\n"); #endif - GNUNET_assert (buf != NULL); /* no timeout */ + GNUNET_assert (buf != NULL); /* no timeout */ if (0 == memcmp (&"Hello World"[sofar], buf, available)) sofar += available; if (sofar < 12) - { + { #if VERBOSE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receive needs more data\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receive needs more data\n"); #endif - GNUNET_CONNECTION_receive (asock, 1024, - GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_SECONDS, 5), - &receive_check, cls); - } + GNUNET_CONNECTION_receive (asock, 1024, + GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check, + cls); + } else - { + { #if VERBOSE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Receive closes accepted socket\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receive closes accepted socket\n"); #endif - *ok = 0; - GNUNET_CONNECTION_destroy (asock, GNUNET_YES); - } + *ok = 0; + GNUNET_CONNECTION_destroy (asock, GNUNET_YES); + } } @@ -124,12 +122,12 @@ run_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_CONNECTION_destroy (lsock, GNUNET_YES); #if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Test asks to receive on accepted socket\n"); + "Test asks to receive on accepted socket\n"); #endif GNUNET_CONNECTION_receive (asock, 1024, - GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check, - cls); + GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check, + cls); } static size_t @@ -137,7 +135,7 @@ make_hello (void *cls, size_t size, void *buf) { #if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Test prepares to transmit on connect socket\n"); + "Test prepares to transmit on connect socket\n"); #endif GNUNET_assert (size >= 12); strcpy ((char *) buf, "Hello World"); @@ -160,14 +158,14 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test asks for write notification\n"); #endif GNUNET_assert (NULL != - GNUNET_CONNECTION_notify_transmit_ready (csock, 12, - GNUNET_TIME_UNIT_SECONDS, - &make_hello, NULL)); + GNUNET_CONNECTION_notify_transmit_ready (csock, 12, + GNUNET_TIME_UNIT_SECONDS, + &make_hello, NULL)); #if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test prepares to accept\n"); #endif - GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, ls, - &run_accept, cls); + GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, ls, &run_accept, + cls); } @@ -183,7 +181,7 @@ check () ok = 1; cfg = GNUNET_CONFIGURATION_create (); GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", - "localhost"); + "localhost"); GNUNET_SCHEDULER_run (&task, &ok); GNUNET_CONFIGURATION_destroy (cfg); return ok; @@ -198,11 +196,11 @@ main (int argc, char *argv[]) GNUNET_log_setup ("test_connection", #if VERBOSE - "DEBUG", + "DEBUG", #else - "WARNING", + "WARNING", #endif - NULL); + NULL); ret += check (); return ret; } diff --git a/src/util/test_connection_addressing.c b/src/util/test_connection_addressing.c index c413c18c8..018cf61fb 100644 --- a/src/util/test_connection_addressing.c +++ b/src/util/test_connection_addressing.c @@ -66,16 +66,15 @@ open_listen_socket () GNUNET_assert (desc != 0); if (GNUNET_NETWORK_socket_setsockopt (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) - GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "setsockopt"); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); if (GNUNET_OK != GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr *) &sa, - sizeof (sa))) - { - GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "bind"); - GNUNET_assert (0); - } + sizeof (sa))) + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "bind"); + GNUNET_assert (0); + } GNUNET_NETWORK_socket_listen (desc, 5); return desc; } @@ -83,25 +82,25 @@ open_listen_socket () static void receive_check (void *cls, const void *buf, size_t available, - const struct sockaddr *addr, socklen_t addrlen, int errCode) + const struct sockaddr *addr, socklen_t addrlen, int errCode) { int *ok = cls; - GNUNET_assert (buf != NULL); /* no timeout */ + GNUNET_assert (buf != NULL); /* no timeout */ if (0 == memcmp (&"Hello World"[sofar], buf, available)) sofar += available; if (sofar < 12) - { - GNUNET_CONNECTION_receive (asock, 1024, - GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_SECONDS, 5), - &receive_check, cls); - } + { + GNUNET_CONNECTION_receive (asock, 1024, + GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check, + cls); + } else - { - *ok = 0; - GNUNET_CONNECTION_destroy (asock, GNUNET_YES); - } + { + *ok = 0; + GNUNET_CONNECTION_destroy (asock, GNUNET_YES); + } } @@ -117,7 +116,7 @@ run_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_assert (asock != NULL); GNUNET_assert (GNUNET_YES == GNUNET_CONNECTION_check (asock)); GNUNET_assert (GNUNET_OK == - GNUNET_CONNECTION_get_address (asock, &addr, &alen)); + GNUNET_CONNECTION_get_address (asock, &addr, &alen)); GNUNET_assert (alen == sizeof (struct sockaddr_in)); v4 = addr; memset (&expect, 0, sizeof (expect)); @@ -131,9 +130,9 @@ run_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_free (addr); GNUNET_CONNECTION_destroy (lsock, GNUNET_YES); GNUNET_CONNECTION_receive (asock, 1024, - GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check, - cls); + GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check, + cls); } static size_t @@ -160,17 +159,17 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) v4.sin_port = htons (PORT); v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK); csock = - GNUNET_CONNECTION_create_from_sockaddr (AF_INET, - (const struct sockaddr *) &v4, - sizeof (v4)); + GNUNET_CONNECTION_create_from_sockaddr (AF_INET, + (const struct sockaddr *) &v4, + sizeof (v4)); GNUNET_assert (csock != NULL); GNUNET_assert (NULL != - GNUNET_CONNECTION_notify_transmit_ready (csock, 12, - GNUNET_TIME_UNIT_SECONDS, - &make_hello, NULL)); + GNUNET_CONNECTION_notify_transmit_ready (csock, 12, + GNUNET_TIME_UNIT_SECONDS, + &make_hello, NULL)); GNUNET_CONNECTION_destroy (csock, GNUNET_YES); - GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, ls, - &run_accept, cls); + GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, ls, &run_accept, + cls); } @@ -197,11 +196,11 @@ main (int argc, char *argv[]) GNUNET_log_setup ("test_connection_addressing", #if VERBOSE - "DEBUG", + "DEBUG", #else - "WARNING", + "WARNING", #endif - NULL); + NULL); ret += check (); return ret; } diff --git a/src/util/test_connection_receive_cancel.c b/src/util/test_connection_receive_cancel.c index bd095fdda..63829344d 100644 --- a/src/util/test_connection_receive_cancel.c +++ b/src/util/test_connection_receive_cancel.c @@ -65,11 +65,10 @@ open_listen_socket () GNUNET_assert (desc != NULL); if (GNUNET_NETWORK_socket_setsockopt (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) - GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "setsockopt"); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); GNUNET_assert (GNUNET_NETWORK_socket_bind - (desc, (const struct sockaddr *) &sa, - sizeof (sa)) == GNUNET_OK); + (desc, (const struct sockaddr *) &sa, + sizeof (sa)) == GNUNET_OK); GNUNET_NETWORK_socket_listen (desc, 5); return desc; } @@ -78,7 +77,7 @@ open_listen_socket () static void dead_receive (void *cls, const void *buf, size_t available, - const struct sockaddr *addr, socklen_t addrlen, int errCode) + const struct sockaddr *addr, socklen_t addrlen, int errCode) { GNUNET_assert (0); } @@ -93,9 +92,8 @@ run_accept_cancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_assert (GNUNET_YES == GNUNET_CONNECTION_check (asock)); GNUNET_CONNECTION_destroy (lsock, GNUNET_YES); GNUNET_CONNECTION_receive (asock, 1024, - GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_SECONDS, 5), &dead_receive, - cls); + GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, 5), &dead_receive, cls); } @@ -121,9 +119,9 @@ task_receive_cancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT); GNUNET_assert (csock != NULL); GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, ls, - &run_accept_cancel, cls); - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, - &receive_cancel_task, cls); + &run_accept_cancel, cls); + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &receive_cancel_task, + cls); } @@ -139,7 +137,7 @@ check_receive_cancel () ok = 1; cfg = GNUNET_CONFIGURATION_create (); GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", - "localhost"); + "localhost"); GNUNET_SCHEDULER_run (&task_receive_cancel, &ok); GNUNET_CONFIGURATION_destroy (cfg); return ok; diff --git a/src/util/test_connection_timeout.c b/src/util/test_connection_timeout.c index 5a0bb7c3a..1700718b9 100644 --- a/src/util/test_connection_timeout.c +++ b/src/util/test_connection_timeout.c @@ -62,11 +62,10 @@ open_listen_socket () GNUNET_assert (desc != NULL); if (GNUNET_NETWORK_socket_setsockopt (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) - GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "setsockopt"); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); GNUNET_assert (GNUNET_NETWORK_socket_bind - (desc, (const struct sockaddr *) &sa, - sizeof (sa)) == GNUNET_OK); + (desc, (const struct sockaddr *) &sa, + sizeof (sa)) == GNUNET_OK); GNUNET_NETWORK_socket_listen (desc, 5); return desc; } @@ -78,16 +77,16 @@ send_kilo (void *cls, size_t size, void *buf) int *ok = cls; if (size == 0) - { + { #if VERBOSE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got the desired timeout!\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got the desired timeout!\n"); #endif - GNUNET_assert (buf == NULL); - *ok = 0; - GNUNET_CONNECTION_destroy (lsock, GNUNET_YES); - GNUNET_CONNECTION_destroy (csock, GNUNET_YES); - return 0; - } + GNUNET_assert (buf == NULL); + *ok = 0; + GNUNET_CONNECTION_destroy (lsock, GNUNET_YES); + GNUNET_CONNECTION_destroy (csock, GNUNET_YES); + return 0; + } #if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending kilo to fill buffer.\n"); #endif @@ -95,9 +94,9 @@ send_kilo (void *cls, size_t size, void *buf) memset (buf, 42, 1024); GNUNET_assert (NULL != - GNUNET_CONNECTION_notify_transmit_ready (csock, 1024, - GNUNET_TIME_UNIT_SECONDS, - &send_kilo, cls)); + GNUNET_CONNECTION_notify_transmit_ready (csock, 1024, + GNUNET_TIME_UNIT_SECONDS, + &send_kilo, cls)); return 1024; } @@ -112,9 +111,9 @@ task_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT); GNUNET_assert (csock != NULL); GNUNET_assert (NULL != - GNUNET_CONNECTION_notify_transmit_ready (csock, 1024, - GNUNET_TIME_UNIT_SECONDS, - &send_kilo, cls)); + GNUNET_CONNECTION_notify_transmit_ready (csock, 1024, + GNUNET_TIME_UNIT_SECONDS, + &send_kilo, cls)); } @@ -130,7 +129,7 @@ check_timeout () ok = 1; cfg = GNUNET_CONFIGURATION_create (); GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", - "localhost"); + "localhost"); GNUNET_SCHEDULER_run (&task_timeout, &ok); GNUNET_CONFIGURATION_destroy (cfg); return ok; @@ -143,11 +142,11 @@ main (int argc, char *argv[]) GNUNET_log_setup ("test_connection_timeout", #if VERBOSE - "DEBUG", + "DEBUG", #else - "WARNING", + "WARNING", #endif - NULL); + NULL); ret += check_timeout (); return ret; } diff --git a/src/util/test_connection_timeout_no_connect.c b/src/util/test_connection_timeout_no_connect.c index 00b247c52..b598907ec 100644 --- a/src/util/test_connection_timeout_no_connect.c +++ b/src/util/test_connection_timeout_no_connect.c @@ -57,10 +57,10 @@ task_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT); GNUNET_assert (csock != NULL); GNUNET_assert (NULL != - GNUNET_CONNECTION_notify_transmit_ready (csock, 1024, - GNUNET_TIME_UNIT_SECONDS, - &handle_timeout, - cls)); + GNUNET_CONNECTION_notify_transmit_ready (csock, 1024, + GNUNET_TIME_UNIT_SECONDS, + &handle_timeout, + cls)); } @@ -76,7 +76,7 @@ check_timeout () ok = 1; cfg = GNUNET_CONFIGURATION_create (); GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", - "localhost"); + "localhost"); GNUNET_SCHEDULER_run (&task_timeout, &ok); GNUNET_CONFIGURATION_destroy (cfg); return ok; @@ -89,11 +89,11 @@ main (int argc, char *argv[]) GNUNET_log_setup ("test_connection_timeout_no_connect", #if VERBOSE - "DEBUG", + "DEBUG", #else - "WARNING", + "WARNING", #endif - NULL); + NULL); ret += check_timeout (); return ret; } diff --git a/src/util/test_connection_transmit_cancel.c b/src/util/test_connection_transmit_cancel.c index 540d8c51d..50308a2d0 100644 --- a/src/util/test_connection_transmit_cancel.c +++ b/src/util/test_connection_transmit_cancel.c @@ -43,8 +43,7 @@ not_run (void *cls, size_t size, void *buf) static void -task_transmit_cancel (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +task_transmit_cancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { int *ok = cls; struct GNUNET_CONNECTION_TransmitHandle *th; @@ -53,8 +52,8 @@ task_transmit_cancel (void *cls, csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT); GNUNET_assert (csock != NULL); th = GNUNET_CONNECTION_notify_transmit_ready (csock, 12, - GNUNET_TIME_UNIT_MINUTES, - ¬_run, cls); + GNUNET_TIME_UNIT_MINUTES, + ¬_run, cls); GNUNET_assert (NULL != th); GNUNET_CONNECTION_notify_transmit_ready_cancel (th); GNUNET_CONNECTION_destroy (csock, GNUNET_YES); @@ -75,7 +74,7 @@ check_transmit_cancel () ok = 1; cfg = GNUNET_CONFIGURATION_create (); GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", - "localhost"); + "localhost"); GNUNET_SCHEDULER_run (&task_transmit_cancel, &ok); GNUNET_CONFIGURATION_destroy (cfg); return ok; @@ -89,11 +88,11 @@ main (int argc, char *argv[]) GNUNET_log_setup ("test_connection_transmit_cancel", #if VERBOSE - "DEBUG", + "DEBUG", #else - "WARNING", + "WARNING", #endif - NULL); + NULL); ret += check_transmit_cancel (); return ret; diff --git a/src/util/test_container_bloomfilter.c b/src/util/test_container_bloomfilter.c index 04bb34889..c14adb075 100644 --- a/src/util/test_container_bloomfilter.c +++ b/src/util/test_container_bloomfilter.c @@ -75,30 +75,29 @@ main (int argc, char *argv[]) bf = GNUNET_CONTAINER_bloomfilter_load (TESTFILE, SIZE, K); for (i = 0; i < 200; i++) - { - nextHC (&tmp); - GNUNET_CONTAINER_bloomfilter_add (bf, &tmp); - } + { + nextHC (&tmp); + GNUNET_CONTAINER_bloomfilter_add (bf, &tmp); + } SRANDOM (1); ok1 = 0; for (i = 0; i < 200; i++) - { - nextHC (&tmp); - if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES) - ok1++; - } + { + nextHC (&tmp); + if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES) + ok1++; + } if (ok1 != 200) - { - printf ("Got %d elements out of" "200 expected after insertion.\n", - ok1); - GNUNET_CONTAINER_bloomfilter_free (bf); - return -1; - } + { + printf ("Got %d elements out of" "200 expected after insertion.\n", ok1); + GNUNET_CONTAINER_bloomfilter_free (bf); + return -1; + } if (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_get_raw_data (bf, buf, SIZE)) - { - GNUNET_CONTAINER_bloomfilter_free (bf); - return -1; - } + { + GNUNET_CONTAINER_bloomfilter_free (bf); + return -1; + } GNUNET_CONTAINER_bloomfilter_free (bf); @@ -111,94 +110,93 @@ main (int argc, char *argv[]) ok1 = 0; ok2 = 0; for (i = 0; i < 200; i++) - { - nextHC (&tmp); - if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES) - ok1++; - if (GNUNET_CONTAINER_bloomfilter_test (bfi, &tmp) == GNUNET_YES) - ok2++; - } + { + nextHC (&tmp); + if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES) + ok1++; + if (GNUNET_CONTAINER_bloomfilter_test (bfi, &tmp) == GNUNET_YES) + ok2++; + } if (ok1 != 200) - { - printf ("Got %d elements out of 200 " "expected after reloading.\n", - ok1); - GNUNET_CONTAINER_bloomfilter_free (bf); - GNUNET_CONTAINER_bloomfilter_free (bfi); - return -1; - } + { + printf ("Got %d elements out of 200 " "expected after reloading.\n", ok1); + GNUNET_CONTAINER_bloomfilter_free (bf); + GNUNET_CONTAINER_bloomfilter_free (bfi); + return -1; + } if (ok2 != 200) - { - printf ("Got %d elements out of 200 " - "expected after initialization.\n", ok2); - GNUNET_CONTAINER_bloomfilter_free (bf); - GNUNET_CONTAINER_bloomfilter_free (bfi); - return -1; - } + { + printf ("Got %d elements out of 200 " "expected after initialization.\n", + ok2); + GNUNET_CONTAINER_bloomfilter_free (bf); + GNUNET_CONTAINER_bloomfilter_free (bfi); + return -1; + } SRANDOM (1); for (i = 0; i < 100; i++) - { - nextHC (&tmp); - GNUNET_CONTAINER_bloomfilter_remove (bf, &tmp); - GNUNET_CONTAINER_bloomfilter_remove (bfi, &tmp); - } + { + nextHC (&tmp); + GNUNET_CONTAINER_bloomfilter_remove (bf, &tmp); + GNUNET_CONTAINER_bloomfilter_remove (bfi, &tmp); + } SRANDOM (1); ok1 = 0; ok2 = 0; for (i = 0; i < 200; i++) - { - nextHC (&tmp); - if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES) - ok1++; - if (GNUNET_CONTAINER_bloomfilter_test (bfi, &tmp) == GNUNET_YES) - ok2++; - } + { + nextHC (&tmp); + if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES) + ok1++; + if (GNUNET_CONTAINER_bloomfilter_test (bfi, &tmp) == GNUNET_YES) + ok2++; + } if (ok1 != 100) - { - printf ("Expected 100 elements in loaded filter" - " after adding 200 and deleting 100, got %d\n", ok1); - GNUNET_CONTAINER_bloomfilter_free (bf); - GNUNET_CONTAINER_bloomfilter_free (bfi); - return -1; - } + { + printf ("Expected 100 elements in loaded filter" + " after adding 200 and deleting 100, got %d\n", ok1); + GNUNET_CONTAINER_bloomfilter_free (bf); + GNUNET_CONTAINER_bloomfilter_free (bfi); + return -1; + } if (ok2 != 200) - { - printf ("Expected 200 elements in initialized filter" - " after adding 200 and deleting 100 " - "(which should do nothing for a filter not backed by a file), got %d\n", - ok2); - GNUNET_CONTAINER_bloomfilter_free (bf); - GNUNET_CONTAINER_bloomfilter_free (bfi); - return -1; - } + { + printf ("Expected 200 elements in initialized filter" + " after adding 200 and deleting 100 " + "(which should do nothing for a filter not backed by a file), got %d\n", + ok2); + GNUNET_CONTAINER_bloomfilter_free (bf); + GNUNET_CONTAINER_bloomfilter_free (bfi); + return -1; + } SRANDOM (3); GNUNET_CONTAINER_bloomfilter_clear (bf); falseok = 0; for (i = 0; i < 1000; i++) - { - nextHC (&tmp); - if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES) - falseok++; - } + { + nextHC (&tmp); + if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES) + falseok++; + } if (falseok > 0) - { - GNUNET_CONTAINER_bloomfilter_free (bf); - GNUNET_CONTAINER_bloomfilter_free (bfi); - return -1; - } + { + GNUNET_CONTAINER_bloomfilter_free (bf); + GNUNET_CONTAINER_bloomfilter_free (bfi); + return -1; + } if (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_or (bf, buf, SIZE)) - { - GNUNET_CONTAINER_bloomfilter_free (bf); - GNUNET_CONTAINER_bloomfilter_free (bfi); - return -1; - } + { + GNUNET_CONTAINER_bloomfilter_free (bf); + GNUNET_CONTAINER_bloomfilter_free (bfi); + return -1; + } SRANDOM (2); i = 20; @@ -212,30 +210,30 @@ main (int argc, char *argv[]) ok1 = 0; ok2 = 0; for (i = 0; i < 20; i++) - { - nextHC (&tmp); - if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES) - ok1++; - if (GNUNET_CONTAINER_bloomfilter_test (bfi, &tmp) == GNUNET_YES) - ok2++; - } + { + nextHC (&tmp); + if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES) + ok1++; + if (GNUNET_CONTAINER_bloomfilter_test (bfi, &tmp) == GNUNET_YES) + ok2++; + } if (ok1 != 20) - { - printf ("Expected 20 elements in resized file-backed filter" - " after adding 20, got %d\n", ok1); - GNUNET_CONTAINER_bloomfilter_free (bf); - GNUNET_CONTAINER_bloomfilter_free (bfi); - return -1; - } + { + printf ("Expected 20 elements in resized file-backed filter" + " after adding 20, got %d\n", ok1); + GNUNET_CONTAINER_bloomfilter_free (bf); + GNUNET_CONTAINER_bloomfilter_free (bfi); + return -1; + } if (ok2 != 20) - { - printf ("Expected 20 elements in resized filter" - " after adding 20, got %d\n", ok2); - GNUNET_CONTAINER_bloomfilter_free (bf); - GNUNET_CONTAINER_bloomfilter_free (bfi); - return -1; - } + { + printf ("Expected 20 elements in resized filter" + " after adding 20, got %d\n", ok2); + GNUNET_CONTAINER_bloomfilter_free (bf); + GNUNET_CONTAINER_bloomfilter_free (bfi); + return -1; + } GNUNET_CONTAINER_bloomfilter_free (bf); diff --git a/src/util/test_container_heap.c b/src/util/test_container_heap.c index c1c4eb360..a2a004aa7 100644 --- a/src/util/test_container_heap.c +++ b/src/util/test_container_heap.c @@ -30,7 +30,7 @@ static int iterator_callback (void *cls, struct GNUNET_CONTAINER_HeapNode *node, - void *element, GNUNET_CONTAINER_HeapCostType cost) + void *element, GNUNET_CONTAINER_HeapCostType cost) { return GNUNET_OK; } @@ -107,15 +107,15 @@ check () n6 = GNUNET_CONTAINER_heap_insert (myHeap, "30/200", 30); GNUNET_assert (5 == GNUNET_CONTAINER_heap_get_size (myHeap)); GNUNET_CONTAINER_heap_remove_node (n5); - r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n1 */ + r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n1 */ GNUNET_assert (NULL != r); GNUNET_assert (0 == strcmp ("11", r)); GNUNET_CONTAINER_heap_update_cost (myHeap, n6, 200); GNUNET_CONTAINER_heap_remove_node (n3); - r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n4 */ + r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n4 */ GNUNET_assert (NULL != r); GNUNET_assert (0 == strcmp ("50", r)); - r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n6 */ + r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n6 */ GNUNET_assert (NULL != r); GNUNET_assert (0 == strcmp ("30/200", r)); GNUNET_assert (0 == GNUNET_CONTAINER_heap_get_size (myHeap)); @@ -172,9 +172,9 @@ check () GNUNET_assert (0 == nstrcmp ("20", GNUNET_CONTAINER_heap_remove_node (n2))); GNUNET_assert (0 == - nstrcmp ("10", GNUNET_CONTAINER_heap_remove_root (myHeap))); + nstrcmp ("10", GNUNET_CONTAINER_heap_remove_root (myHeap))); GNUNET_assert (0 == - nstrcmp ("30", GNUNET_CONTAINER_heap_remove_root (myHeap))); + nstrcmp ("30", GNUNET_CONTAINER_heap_remove_root (myHeap))); n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 20); @@ -232,7 +232,7 @@ check () GNUNET_CONTAINER_heap_remove_node (n2); GNUNET_CONTAINER_heap_remove_node (n1); GNUNET_assert (0 == - nstrcmp ("30", GNUNET_CONTAINER_heap_remove_root (myHeap))); + nstrcmp ("30", GNUNET_CONTAINER_heap_remove_root (myHeap))); n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 10); diff --git a/src/util/test_container_meta_data.c b/src/util/test_container_meta_data.c index 66f90ff10..fe1dd79c1 100644 --- a/src/util/test_container_meta_data.c +++ b/src/util/test_container_meta_data.c @@ -41,55 +41,51 @@ testMeta (int i) m = GNUNET_CONTAINER_meta_data_create (); if (GNUNET_OK != - GNUNET_CONTAINER_meta_data_insert (m, "", - EXTRACTOR_METATYPE_TITLE, - EXTRACTOR_METAFORMAT_UTF8, - "text/plain", "TestTitle", - strlen ("TestTitle") + 1)) + GNUNET_CONTAINER_meta_data_insert (m, "", EXTRACTOR_METATYPE_TITLE, + EXTRACTOR_METAFORMAT_UTF8, + "text/plain", "TestTitle", + strlen ("TestTitle") + 1)) ABORT (m); if (GNUNET_OK != GNUNET_CONTAINER_meta_data_insert (m, "", - EXTRACTOR_METATYPE_AUTHOR_NAME, - EXTRACTOR_METAFORMAT_UTF8, - "text/plain", "TestTitle", - strlen ("TestTitle") + 1)) + EXTRACTOR_METATYPE_AUTHOR_NAME, + EXTRACTOR_METAFORMAT_UTF8, + "text/plain", "TestTitle", + strlen ("TestTitle") + 1)) ABORT (m); - if (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (m, "", EXTRACTOR_METATYPE_TITLE, EXTRACTOR_METAFORMAT_UTF8, "text/plain", "TestTitle", strlen ("TestTitle") + 1)) /* dup! */ + if (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (m, "", EXTRACTOR_METATYPE_TITLE, EXTRACTOR_METAFORMAT_UTF8, "text/plain", "TestTitle", strlen ("TestTitle") + 1)) /* dup! */ ABORT (m); - if (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (m, "", EXTRACTOR_METATYPE_AUTHOR_NAME, EXTRACTOR_METAFORMAT_UTF8, "text/plain", "TestTitle", strlen ("TestTitle") + 1)) /* dup! */ + if (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (m, "", EXTRACTOR_METATYPE_AUTHOR_NAME, EXTRACTOR_METAFORMAT_UTF8, "text/plain", "TestTitle", strlen ("TestTitle") + 1)) /* dup! */ ABORT (m); if (2 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL)) ABORT (m); if (GNUNET_OK != GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_AUTHOR_NAME, - "TestTitle", - strlen ("TestTitle") + 1)) + "TestTitle", strlen ("TestTitle") + 1)) ABORT (m); - if (GNUNET_OK == GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_AUTHOR_NAME, "TestTitle", strlen ("TestTitle") + 1)) /* already gone */ + if (GNUNET_OK == GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_AUTHOR_NAME, "TestTitle", strlen ("TestTitle") + 1)) /* already gone */ ABORT (m); if (1 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL)) ABORT (m); if (GNUNET_OK != GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_TITLE, - "TestTitle", - strlen ("TestTitle") + 1)) + "TestTitle", strlen ("TestTitle") + 1)) ABORT (m); - if (GNUNET_OK == GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_TITLE, "TestTitle", strlen ("TestTitle") + 1)) /* already gone */ + if (GNUNET_OK == GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_TITLE, "TestTitle", strlen ("TestTitle") + 1)) /* already gone */ ABORT (m); if (0 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL)) ABORT (m); for (j = 0; j < i; j++) - { - GNUNET_snprintf (val, sizeof (val), "%s.%d", - "A teststring that should compress well.", j); - if (GNUNET_OK != - GNUNET_CONTAINER_meta_data_insert (m, "", - EXTRACTOR_METATYPE_UNKNOWN, - EXTRACTOR_METAFORMAT_UTF8, - "text/plain", val, - strlen (val) + 1)) - ABORT (m); - } + { + GNUNET_snprintf (val, sizeof (val), "%s.%d", + "A teststring that should compress well.", j); + if (GNUNET_OK != + GNUNET_CONTAINER_meta_data_insert (m, "", + EXTRACTOR_METATYPE_UNKNOWN, + EXTRACTOR_METAFORMAT_UTF8, + "text/plain", val, strlen (val) + 1)) + ABORT (m); + } if (i != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL)) ABORT (m); @@ -97,27 +93,27 @@ testMeta (int i) sval = NULL; if (size != GNUNET_CONTAINER_meta_data_serialize (m, &sval, size, - GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL)) - { - GNUNET_free_non_null (sval); - ABORT (m); - } + GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL)) + { + GNUNET_free_non_null (sval); + ABORT (m); + } GNUNET_CONTAINER_meta_data_destroy (m); m = GNUNET_CONTAINER_meta_data_deserialize (sval, size); GNUNET_free (sval); if (m == NULL) ABORT (m); for (j = 0; j < i; j++) + { + GNUNET_snprintf (val, sizeof (val), "%s.%d", + "A teststring that should compress well.", j); + if (GNUNET_OK != + GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_UNKNOWN, val, + strlen (val) + 1)) { - GNUNET_snprintf (val, sizeof (val), "%s.%d", - "A teststring that should compress well.", j); - if (GNUNET_OK != - GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_UNKNOWN, - val, strlen (val) + 1)) - { - ABORT (m); - } + ABORT (m); } + } if (0 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL)) ABORT (m); GNUNET_CONTAINER_meta_data_destroy (m); @@ -135,22 +131,22 @@ testMetaMore (int i) meta = GNUNET_CONTAINER_meta_data_create (); for (q = 0; q <= i; q++) - { - GNUNET_snprintf (txt, 128, "%u -- %u\n", i, q); - GNUNET_CONTAINER_meta_data_insert (meta, "", - q % EXTRACTOR_metatype_get_max (), - EXTRACTOR_METAFORMAT_UTF8, - "text/plain", txt, strlen (txt) + 1); - } + { + GNUNET_snprintf (txt, 128, "%u -- %u\n", i, q); + GNUNET_CONTAINER_meta_data_insert (meta, "", + q % EXTRACTOR_metatype_get_max (), + EXTRACTOR_METAFORMAT_UTF8, "text/plain", + txt, strlen (txt) + 1); + } size = GNUNET_CONTAINER_meta_data_get_serialized_size (meta); data = GNUNET_malloc (size * 4); if (size != GNUNET_CONTAINER_meta_data_serialize (meta, &data, size * 4, - GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL)) - { - GNUNET_free (data); - ABORT (meta); - } + GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL)) + { + GNUNET_free (data); + ABORT (meta); + } GNUNET_CONTAINER_meta_data_destroy (meta); GNUNET_free (data); return 0; @@ -166,22 +162,22 @@ testMetaLink () m = GNUNET_CONTAINER_meta_data_create (); if (GNUNET_OK != GNUNET_CONTAINER_meta_data_insert (m, "", - EXTRACTOR_METATYPE_UNKNOWN, - EXTRACTOR_METAFORMAT_UTF8, - "text/plain", "link", - strlen ("link") + 1)) + EXTRACTOR_METATYPE_UNKNOWN, + EXTRACTOR_METAFORMAT_UTF8, + "text/plain", "link", + strlen ("link") + 1)) ABORT (m); if (GNUNET_OK != GNUNET_CONTAINER_meta_data_insert (m, "", - EXTRACTOR_METATYPE_FILENAME, - EXTRACTOR_METAFORMAT_UTF8, - "text/plain", "lib-link.m4", - strlen ("lib-link.m4") + 1)) + EXTRACTOR_METATYPE_FILENAME, + EXTRACTOR_METAFORMAT_UTF8, + "text/plain", "lib-link.m4", + strlen ("lib-link.m4") + 1)) ABORT (m); val = NULL; size = - GNUNET_CONTAINER_meta_data_serialize (m, &val, (size_t) - 1, - GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL); + GNUNET_CONTAINER_meta_data_serialize (m, &val, (size_t) - 1, + GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL); GNUNET_CONTAINER_meta_data_destroy (m); m = GNUNET_CONTAINER_meta_data_deserialize (val, size); GNUNET_free (val); @@ -205,46 +201,44 @@ check () meta = GNUNET_CONTAINER_meta_data_create (); meta2 = GNUNET_CONTAINER_meta_data_create (); for (q = 0; q <= i; q++) - { - GNUNET_snprintf (txt, 128, "%u -- %u\n", i, q); - GNUNET_CONTAINER_meta_data_insert (meta, "", - EXTRACTOR_METATYPE_UNKNOWN, - EXTRACTOR_METAFORMAT_UTF8, - "text/plain", "TestTitle", - strlen ("TestTitle") + 1); - GNUNET_CONTAINER_meta_data_insert (meta2, "", - EXTRACTOR_METATYPE_UNKNOWN, - EXTRACTOR_METAFORMAT_UTF8, - "text/plain", "TestTitle", - strlen ("TestTitle") + 1); - } + { + GNUNET_snprintf (txt, 128, "%u -- %u\n", i, q); + GNUNET_CONTAINER_meta_data_insert (meta, "", + EXTRACTOR_METATYPE_UNKNOWN, + EXTRACTOR_METAFORMAT_UTF8, "text/plain", + "TestTitle", strlen ("TestTitle") + 1); + GNUNET_CONTAINER_meta_data_insert (meta2, "", + EXTRACTOR_METATYPE_UNKNOWN, + EXTRACTOR_METAFORMAT_UTF8, "text/plain", + "TestTitle", strlen ("TestTitle") + 1); + } //check meta_data_test_equal if (GNUNET_YES != GNUNET_CONTAINER_meta_data_test_equal (meta, meta2)) - { - GNUNET_CONTAINER_meta_data_destroy (meta2); - ABORT (meta); - } + { + GNUNET_CONTAINER_meta_data_destroy (meta2); + ABORT (meta); + } //check meta_data_clear GNUNET_CONTAINER_meta_data_clear (meta2); if (0 != GNUNET_CONTAINER_meta_data_iterate (meta2, NULL, NULL)) - { - GNUNET_CONTAINER_meta_data_destroy (meta2); - ABORT (meta); - } + { + GNUNET_CONTAINER_meta_data_destroy (meta2); + ABORT (meta); + } // check equal branch in meta_data_test_equal if (GNUNET_YES != GNUNET_CONTAINER_meta_data_test_equal (meta, meta)) - { - GNUNET_CONTAINER_meta_data_destroy (meta2); - ABORT (meta); - } + { + GNUNET_CONTAINER_meta_data_destroy (meta2); + ABORT (meta); + } // check "count" branch in meta_data_test_equal if (GNUNET_NO != GNUNET_CONTAINER_meta_data_test_equal (meta, meta2)) - { - GNUNET_CONTAINER_meta_data_destroy (meta2); - ABORT (meta); - } + { + GNUNET_CONTAINER_meta_data_destroy (meta2); + ABORT (meta); + } // check meta_data_add_publication_date GNUNET_CONTAINER_meta_data_add_publication_date (meta2); @@ -253,74 +247,74 @@ check () GNUNET_CONTAINER_meta_data_clear (meta2); GNUNET_CONTAINER_meta_data_merge (meta2, meta); if (100 == GNUNET_CONTAINER_meta_data_iterate (meta2, NULL, NULL)) - { - GNUNET_CONTAINER_meta_data_destroy (meta2); - ABORT (meta); - } + { + GNUNET_CONTAINER_meta_data_destroy (meta2); + ABORT (meta); + } // check meta_data_get_by_type GNUNET_CONTAINER_meta_data_clear (meta2); if (NULL != (str = GNUNET_CONTAINER_meta_data_get_by_type (meta2, - EXTRACTOR_METATYPE_UNKNOWN))) - { - GNUNET_CONTAINER_meta_data_destroy (meta2); - GNUNET_free (str); - ABORT (meta); - } + EXTRACTOR_METATYPE_UNKNOWN))) + { + GNUNET_CONTAINER_meta_data_destroy (meta2); + GNUNET_free (str); + ABORT (meta); + } str = - GNUNET_CONTAINER_meta_data_get_by_type (meta, EXTRACTOR_METATYPE_UNKNOWN); + GNUNET_CONTAINER_meta_data_get_by_type (meta, EXTRACTOR_METATYPE_UNKNOWN); GNUNET_assert (NULL != str); if (str[0] != 'T') - { - GNUNET_CONTAINER_meta_data_destroy (meta2); - GNUNET_free (str); - ABORT (meta); - } + { + GNUNET_CONTAINER_meta_data_destroy (meta2); + GNUNET_free (str); + ABORT (meta); + } GNUNET_free (str); // check branch if (NULL != (str = GNUNET_CONTAINER_meta_data_get_by_type (meta, - EXTRACTOR_METATYPE_PUBLICATION_DATE))) - { - GNUNET_free (str); - GNUNET_CONTAINER_meta_data_destroy (meta2); - ABORT (meta); - } + EXTRACTOR_METATYPE_PUBLICATION_DATE))) + { + GNUNET_free (str); + GNUNET_CONTAINER_meta_data_destroy (meta2); + ABORT (meta); + } //check meta_data_get_first_by_types str = - GNUNET_CONTAINER_meta_data_get_first_by_types (meta, - EXTRACTOR_METATYPE_UNKNOWN, - -1); + GNUNET_CONTAINER_meta_data_get_first_by_types (meta, + EXTRACTOR_METATYPE_UNKNOWN, + -1); GNUNET_assert (NULL != str); if (str[0] != 'T') - { - GNUNET_CONTAINER_meta_data_destroy (meta2); - GNUNET_free (str); - ABORT (meta); - } + { + GNUNET_CONTAINER_meta_data_destroy (meta2); + GNUNET_free (str); + ABORT (meta); + } GNUNET_free (str); //check meta_data_get_thumbnail if (GNUNET_CONTAINER_meta_data_get_thumbnail (meta, &thumb) != 0) - { - GNUNET_free (thumb); - GNUNET_CONTAINER_meta_data_destroy (meta2); - ABORT (meta); - } + { + GNUNET_free (thumb); + GNUNET_CONTAINER_meta_data_destroy (meta2); + ABORT (meta); + } GNUNET_CONTAINER_meta_data_destroy (meta2); //check meta_data_duplicate meta2 = GNUNET_CONTAINER_meta_data_duplicate (meta); if (200 == GNUNET_CONTAINER_meta_data_iterate (meta2, NULL, NULL)) - { - GNUNET_CONTAINER_meta_data_destroy (meta2); - ABORT (meta); - } + { + GNUNET_CONTAINER_meta_data_destroy (meta2); + ABORT (meta); + } GNUNET_CONTAINER_meta_data_destroy (meta2); GNUNET_CONTAINER_meta_data_destroy (meta); return 0; diff --git a/src/util/test_container_multihashmap.c b/src/util/test_container_multihashmap.c index 5732ace93..ba621c17e 100644 --- a/src/util/test_container_multihashmap.c +++ b/src/util/test_container_multihashmap.c @@ -52,41 +52,38 @@ testMap (int i) CHECK (0 == GNUNET_CONTAINER_multihashmap_remove_all (m, &k1)); CHECK (0 == GNUNET_CONTAINER_multihashmap_size (m)); CHECK (0 == GNUNET_CONTAINER_multihashmap_iterate (m, NULL, NULL)); - CHECK (0 == - GNUNET_CONTAINER_multihashmap_get_multiple (m, &k1, NULL, NULL)); + CHECK (0 == GNUNET_CONTAINER_multihashmap_get_multiple (m, &k1, NULL, NULL)); CHECK (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put (m, &k1, "v1", - GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE)); + GNUNET_CONTAINER_multihashmap_put (m, &k1, "v1", + GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE)); CHECK (1 == GNUNET_CONTAINER_multihashmap_size (m)); ret = GNUNET_CONTAINER_multihashmap_get (m, &k1); GNUNET_assert (ret != NULL); CHECK (0 == strcmp ("v1", ret)); CHECK (GNUNET_NO == - GNUNET_CONTAINER_multihashmap_put (m, &k1, "v1", - GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE)); + GNUNET_CONTAINER_multihashmap_put (m, &k1, "v1", + GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE)); CHECK (1 == GNUNET_CONTAINER_multihashmap_size (m)); CHECK (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put (m, &k1, "v2", - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); + GNUNET_CONTAINER_multihashmap_put (m, &k1, "v2", + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); CHECK (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put (m, &k1, "v3", - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); + GNUNET_CONTAINER_multihashmap_put (m, &k1, "v3", + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); CHECK (3 == GNUNET_CONTAINER_multihashmap_size (m)); CHECK (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (m, &k1, "v3")); CHECK (2 == GNUNET_CONTAINER_multihashmap_size (m)); CHECK (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (m, &k1)); CHECK (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (m, &k2)); - CHECK (2 == - GNUNET_CONTAINER_multihashmap_get_multiple (m, &k1, NULL, NULL)); - CHECK (0 == - GNUNET_CONTAINER_multihashmap_get_multiple (m, &k2, NULL, NULL)); + CHECK (2 == GNUNET_CONTAINER_multihashmap_get_multiple (m, &k1, NULL, NULL)); + CHECK (0 == GNUNET_CONTAINER_multihashmap_get_multiple (m, &k2, NULL, NULL)); CHECK (2 == GNUNET_CONTAINER_multihashmap_iterate (m, NULL, NULL)); CHECK (2 == GNUNET_CONTAINER_multihashmap_remove_all (m, &k1)); for (j = 0; j < 1024; j++) CHECK (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put (m, &k1, "v2", - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); + GNUNET_CONTAINER_multihashmap_put (m, &k1, "v2", + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); GNUNET_CONTAINER_multihashmap_destroy (m); return 0; } diff --git a/src/util/test_container_slist.c b/src/util/test_container_slist.c index 394dc4cdb..1b63d3dbc 100644 --- a/src/util/test_container_slist.c +++ b/src/util/test_container_slist.c @@ -46,66 +46,64 @@ main (int argc, char *argv[]) GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 0); for (i = 0; i < 100; i++) - GNUNET_CONTAINER_slist_add (l, - GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, - &i, sizeof (i)); + GNUNET_CONTAINER_slist_add (l, GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, + &i, sizeof (i)); GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 100); for (it = GNUNET_CONTAINER_slist_begin (l), i = 99; GNUNET_CONTAINER_slist_end (&it) != GNUNET_YES; GNUNET_CONTAINER_slist_next (&it), i--) + { + p = GNUNET_CONTAINER_slist_get (&it, &s); + + if ((p == NULL) || (i != (j = *(int *) p)) || (s != sizeof (i))) { - p = GNUNET_CONTAINER_slist_get (&it, &s); - - if ((p == NULL) || (i != (j = *(int *) p)) || (s != sizeof (i))) - { - GNUNET_CONTAINER_slist_iter_destroy (&it); - GNUNET_assert (0); - } - j *= 2; - GNUNET_CONTAINER_slist_insert (&it, - GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, - &j, sizeof (j)); + GNUNET_CONTAINER_slist_iter_destroy (&it); + GNUNET_assert (0); } + j *= 2; + GNUNET_CONTAINER_slist_insert (&it, + GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, + &j, sizeof (j)); + } GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 200); i = 198; GNUNET_assert (GNUNET_CONTAINER_slist_contains (l, &i, sizeof (i))); for (it = GNUNET_CONTAINER_slist_begin (l); GNUNET_CONTAINER_slist_end (&it) != GNUNET_YES;) - { - p = GNUNET_CONTAINER_slist_get (&it, &s); - GNUNET_assert (p != NULL); - GNUNET_assert (s == sizeof (i)); - i = *(int *) p; + { + p = GNUNET_CONTAINER_slist_get (&it, &s); + GNUNET_assert (p != NULL); + GNUNET_assert (s == sizeof (i)); + i = *(int *) p; - GNUNET_assert (GNUNET_CONTAINER_slist_next (&it) == GNUNET_YES); - GNUNET_assert (GNUNET_CONTAINER_slist_end (&it) != GNUNET_YES); + GNUNET_assert (GNUNET_CONTAINER_slist_next (&it) == GNUNET_YES); + GNUNET_assert (GNUNET_CONTAINER_slist_end (&it) != GNUNET_YES); - p = GNUNET_CONTAINER_slist_get (&it, &s); - GNUNET_assert (p != NULL); - GNUNET_assert (s == sizeof (j)); - j = *(int *) p; + p = GNUNET_CONTAINER_slist_get (&it, &s); + GNUNET_assert (p != NULL); + GNUNET_assert (s == sizeof (j)); + j = *(int *) p; - GNUNET_assert (j * 2 == i); + GNUNET_assert (j * 2 == i); - GNUNET_CONTAINER_slist_erase (&it); - } + GNUNET_CONTAINER_slist_erase (&it); + } GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 100); i = 99; GNUNET_assert (GNUNET_CONTAINER_slist_contains (l, &i, sizeof (i)) == - GNUNET_NO); + GNUNET_NO); i = 198; GNUNET_assert (GNUNET_CONTAINER_slist_contains (l, &i, sizeof (i)) == - GNUNET_YES); + GNUNET_YES); GNUNET_CONTAINER_slist_clear (l); GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 0); for (i = 0; i < 100; i++) - GNUNET_CONTAINER_slist_add (l, - GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, - &i, sizeof (i)); + GNUNET_CONTAINER_slist_add (l, GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, + &i, sizeof (i)); /*check slist_append */ GNUNET_CONTAINER_slist_append (l, l); GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 200); @@ -116,35 +114,34 @@ main (int argc, char *argv[]) l = GNUNET_CONTAINER_slist_create (); for (i = 0; i < 100; i++) GNUNET_CONTAINER_slist_add_end (l, - GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, - &i, sizeof (i)); + GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, + &i, sizeof (i)); GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 100); for (it = GNUNET_CONTAINER_slist_begin (l), i = 0; GNUNET_CONTAINER_slist_end (&it) != GNUNET_YES; GNUNET_CONTAINER_slist_next (&it), i++) - { - p = GNUNET_CONTAINER_slist_get (&it, &s); + { + p = GNUNET_CONTAINER_slist_get (&it, &s); - if ((p == NULL) || (i != *(int *) p) || (s != sizeof (i))) - { - GNUNET_assert (0); - } + if ((p == NULL) || (i != *(int *) p) || (s != sizeof (i))) + { + GNUNET_assert (0); } + } GNUNET_CONTAINER_slist_destroy (l); /*check if disp = GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC */ l = GNUNET_CONTAINER_slist_create (); for (i = 0; i < 100; i++) - { - ip = GNUNET_malloc (sizeof (int)); - *ip = i; - GNUNET_CONTAINER_slist_add (l, - GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC, - ip, sizeof (int)); - } + { + ip = GNUNET_malloc (sizeof (int)); + *ip = i; + GNUNET_CONTAINER_slist_add (l, GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC, + ip, sizeof (int)); + } //creat_add it = GNUNET_CONTAINER_slist_begin (l); p = GNUNET_CONTAINER_slist_get (&it, &s); diff --git a/src/util/test_crypto_aes.c b/src/util/test_crypto_aes.c index e928b96a7..971e9afbe 100644 --- a/src/util/test_crypto_aes.c +++ b/src/util/test_crypto_aes.c @@ -40,30 +40,30 @@ testSymcipher () GNUNET_CRYPTO_aes_create_session_key (&key); size = - GNUNET_CRYPTO_aes_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, &key, - (const struct - GNUNET_CRYPTO_AesInitializationVector *) - INITVALUE, result); + GNUNET_CRYPTO_aes_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, &key, + (const struct + GNUNET_CRYPTO_AesInitializationVector *) + INITVALUE, result); if (size == -1) - { - printf ("symciphertest failed: encryptBlock returned %d\n", size); - return 1; - } + { + printf ("symciphertest failed: encryptBlock returned %d\n", size); + return 1; + } size = - GNUNET_CRYPTO_aes_decrypt (result, size, &key, - (const struct - GNUNET_CRYPTO_AesInitializationVector *) - INITVALUE, res); + GNUNET_CRYPTO_aes_decrypt (result, size, &key, + (const struct + GNUNET_CRYPTO_AesInitializationVector *) + INITVALUE, res); if (strlen (TESTSTRING) + 1 != size) - { - printf ("symciphertest failed: decryptBlock returned %d\n", size); - return 1; - } + { + printf ("symciphertest failed: decryptBlock returned %d\n", size); + return 1; + } if (0 != strcmp (res, TESTSTRING)) - { - printf ("symciphertest failed: %s != %s\n", res, TESTSTRING); - return 1; - } + { + printf ("symciphertest failed: %s != %s\n", res, TESTSTRING); + return 1; + } else return 0; } @@ -77,16 +77,16 @@ verifyCrypto () int ret; unsigned char plain[] = - { 29, 128, 192, 253, 74, 171, 38, 187, 84, 219, 76, 76, 209, 118, 33, 249, + { 29, 128, 192, 253, 74, 171, 38, 187, 84, 219, 76, 76, 209, 118, 33, 249, 172, 124, 96, 9, 157, 110, 8, 215, 200, 63, 69, 230, 157, 104, 247, 164 }; unsigned char raw_key[] = - { 106, 74, 209, 88, 145, 55, 189, 135, 125, 180, 225, 108, 183, 54, 25, + { 106, 74, 209, 88, 145, 55, 189, 135, 125, 180, 225, 108, 183, 54, 25, 169, 129, 188, 131, 75, 227, 245, 105, 10, 225, 15, 115, 159, 148, 184, 34, 191 }; unsigned char encrresult[] = - { 167, 102, 230, 233, 127, 195, 176, 107, 17, 91, 199, 127, 96, 113, 75, + { 167, 102, 230, 233, 127, 195, 176, 107, 17, 91, 199, 127, 96, 113, 75, 195, 245, 217, 61, 236, 159, 165, 103, 121, 203, 99, 202, 41, 23, 222, 25, 102 }; @@ -96,54 +96,54 @@ verifyCrypto () memcpy (key.key, raw_key, GNUNET_CRYPTO_AES_KEY_LENGTH); key.crc32 = - htonl (GNUNET_CRYPTO_crc32_n (&key, GNUNET_CRYPTO_AES_KEY_LENGTH)); + htonl (GNUNET_CRYPTO_crc32_n (&key, GNUNET_CRYPTO_AES_KEY_LENGTH)); if (ntohl (key.crc32) != (unsigned int) 38125195LL) - { - printf ("Static key has different CRC: %u - %u\n", ntohl (key.crc32), - key.crc32); + { + printf ("Static key has different CRC: %u - %u\n", ntohl (key.crc32), + key.crc32); - ret = 1; - goto error; - } + ret = 1; + goto error; + } if (GNUNET_CRYPTO_AES_KEY_LENGTH != GNUNET_CRYPTO_aes_encrypt (plain, GNUNET_CRYPTO_AES_KEY_LENGTH, &key, - (const struct - GNUNET_CRYPTO_AesInitializationVector *) - "testtesttesttest", result)) - { - printf ("Wrong return value from encrypt block.\n"); - ret = 1; - goto error; - } + (const struct + GNUNET_CRYPTO_AesInitializationVector *) + "testtesttesttest", result)) + { + printf ("Wrong return value from encrypt block.\n"); + ret = 1; + goto error; + } if (memcmp (encrresult, result, GNUNET_CRYPTO_AES_KEY_LENGTH) != 0) - { - printf ("Encrypted result wrong.\n"); - ret = 1; - goto error; - } + { + printf ("Encrypted result wrong.\n"); + ret = 1; + goto error; + } res = GNUNET_malloc (GNUNET_CRYPTO_AES_KEY_LENGTH); if (GNUNET_CRYPTO_AES_KEY_LENGTH != GNUNET_CRYPTO_aes_decrypt (result, GNUNET_CRYPTO_AES_KEY_LENGTH, &key, - (const struct - GNUNET_CRYPTO_AesInitializationVector *) - "testtesttesttest", res)) - { - printf ("Wrong return value from decrypt block.\n"); - ret = 1; - goto error; - } + (const struct + GNUNET_CRYPTO_AesInitializationVector *) + "testtesttesttest", res)) + { + printf ("Wrong return value from decrypt block.\n"); + ret = 1; + goto error; + } if (memcmp (res, plain, GNUNET_CRYPTO_AES_KEY_LENGTH) != 0) - { - printf ("Decrypted result does not match input.\n"); + { + printf ("Decrypted result does not match input.\n"); - ret = 1; - } + ret = 1; + } error: @@ -160,15 +160,15 @@ main (int argc, char *argv[]) GNUNET_log_setup ("test-crypto-aes", "WARNING", NULL); GNUNET_CRYPTO_random_disable_entropy_gathering (); GNUNET_assert (strlen (INITVALUE) > - sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); + sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); failureCount += testSymcipher (); failureCount += verifyCrypto (); if (failureCount != 0) - { - printf ("%d TESTS FAILED!\n", failureCount); - return -1; - } + { + printf ("%d TESTS FAILED!\n", failureCount); + return -1; + } return 0; } diff --git a/src/util/test_crypto_aes_weak.c b/src/util/test_crypto_aes_weak.c index 25931b625..a0161b575 100644 --- a/src/util/test_crypto_aes_weak.c +++ b/src/util/test_crypto_aes_weak.c @@ -40,9 +40,9 @@ printWeakKey (struct GNUNET_CRYPTO_AesSessionKey *key) int i; for (i = 0; i < GNUNET_CRYPTO_AES_KEY_LENGTH; i++) - { - printf ("%x ", (int) (key->key[i])); - } + { + printf ("%x ", (int) (key->key[i])); + } } static int @@ -55,7 +55,7 @@ testWeakKey () struct GNUNET_CRYPTO_AesInitializationVector INITVALUE; memset (&INITVALUE, 42, - sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); + sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); /* sorry, this is not a weak key -- I don't have * any at the moment! */ weak_key.key[0] = (char) (0x4c); @@ -92,31 +92,31 @@ testWeakKey () weak_key.key[31] = (char) (0xaa); /* memset(&weak_key, 0, 32); */ weak_key.crc32 = - htonl (GNUNET_CRYPTO_crc32_n (&weak_key, GNUNET_CRYPTO_AES_KEY_LENGTH)); + htonl (GNUNET_CRYPTO_crc32_n (&weak_key, GNUNET_CRYPTO_AES_KEY_LENGTH)); size = - GNUNET_CRYPTO_aes_encrypt (WEAK_KEY_TESTSTRING, - strlen (WEAK_KEY_TESTSTRING) + 1, &weak_key, - &INITVALUE, result); + GNUNET_CRYPTO_aes_encrypt (WEAK_KEY_TESTSTRING, + strlen (WEAK_KEY_TESTSTRING) + 1, &weak_key, + &INITVALUE, result); if (size == -1) - { - GNUNET_break (0); - return 1; - } + { + GNUNET_break (0); + return 1; + } size = GNUNET_CRYPTO_aes_decrypt (result, size, &weak_key, &INITVALUE, res); if ((strlen (WEAK_KEY_TESTSTRING) + 1) != size) - { - GNUNET_break (0); - return 1; - } + { + GNUNET_break (0); + return 1; + } if (0 != strcmp (res, WEAK_KEY_TESTSTRING)) - { - GNUNET_break (0); - return 1; - } + { + GNUNET_break (0); + return 1; + } else return 0; } @@ -133,45 +133,42 @@ getWeakKeys () for (number_of_runs = 0; number_of_runs < MAX_WEAK_KEY_TRIALS; number_of_runs++) + { + + if (number_of_runs % 1000 == 0) + fprintf (stderr, "."); + /*printf("Got to run number %d.\n", number_of_runs); */ + GNUNET_CRYPTO_aes_create_session_key (&sessionkey); + + rc = gcry_cipher_open (&handle, GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CFB, + 0); + + if (rc) { + printf ("testweakkey: gcry_cipher_open failed on trial %d. %s\n", + number_of_runs, gcry_strerror (rc)); + continue; + } - if (number_of_runs % 1000 == 0) - fprintf (stderr, "."); - /*printf("Got to run number %d.\n", number_of_runs); */ - GNUNET_CRYPTO_aes_create_session_key (&sessionkey); - - rc = - gcry_cipher_open (&handle, GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CFB, - 0); - - if (rc) - { - printf ("testweakkey: gcry_cipher_open failed on trial %d. %s\n", - number_of_runs, gcry_strerror (rc)); - continue; - } - - rc = - gcry_cipher_setkey (handle, &sessionkey, - GNUNET_CRYPTO_AES_KEY_LENGTH); - - if ((char) rc == GPG_ERR_WEAK_KEY) - { - printf ("\nWeak key (in hex): "); - printWeakKey (&sessionkey); - printf ("\n"); - number_of_weak_keys++; - } - else if (rc) - { - printf ("\nUnexpected error generating keys. Error is %s\n", - gcry_strerror (rc)); - } - - gcry_cipher_close (handle); + rc = gcry_cipher_setkey (handle, &sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH); + if ((char) rc == GPG_ERR_WEAK_KEY) + { + printf ("\nWeak key (in hex): "); + printWeakKey (&sessionkey); + printf ("\n"); + number_of_weak_keys++; + } + else if (rc) + { + printf ("\nUnexpected error generating keys. Error is %s\n", + gcry_strerror (rc)); } + gcry_cipher_close (handle); + + } + return number_of_weak_keys; } @@ -183,19 +180,19 @@ main (int argc, char *argv[]) GNUNET_log_setup ("test-crypto-aes-weak", "WARNING", NULL); GNUNET_CRYPTO_random_disable_entropy_gathering (); if (GENERATE_WEAK_KEYS) + { + weak_keys = getWeakKeys (); + + if (weak_keys == 0) + { + printf ("\nNo weak keys found in %d runs.\n", MAX_WEAK_KEY_TRIALS); + } + else { - weak_keys = getWeakKeys (); - - if (weak_keys == 0) - { - printf ("\nNo weak keys found in %d runs.\n", MAX_WEAK_KEY_TRIALS); - } - else - { - printf ("\n%d weak keys found in %d runs.\n", weak_keys, - MAX_WEAK_KEY_TRIALS); - } + printf ("\n%d weak keys found in %d runs.\n", weak_keys, + MAX_WEAK_KEY_TRIALS); } + } if (testWeakKey () != 0) return -1; diff --git a/src/util/test_crypto_hash.c b/src/util/test_crypto_hash.c index a32a28ef0..b0fa4f332 100644 --- a/src/util/test_crypto_hash.c +++ b/src/util/test_crypto_hash.c @@ -42,10 +42,10 @@ test (int number) memset (&h1, number, sizeof (GNUNET_HashCode)); GNUNET_CRYPTO_hash_to_enc (&h1, &enc); if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char *) &enc, &h2)) - { - printf ("enc2hash failed!\n"); - return 1; - } + { + printf ("enc2hash failed!\n"); + return 1; + } if (0 != memcmp (&h1, &h2, sizeof (GNUNET_HashCode))) return 1; return 0; @@ -124,9 +124,8 @@ static void file_hasher (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { GNUNET_assert (NULL != - GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_DEFAULT, - FILENAME, 1024, &finished_task, - cls)); + GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_DEFAULT, + FILENAME, 1024, &finished_task, cls)); } diff --git a/src/util/test_crypto_hkdf.c b/src/util/test_crypto_hkdf.c index d5ee4d433..752116194 100644 --- a/src/util/test_crypto_hkdf.c +++ b/src/util/test_crypto_hkdf.c @@ -36,17 +36,17 @@ void tc1 () { unsigned char ikm[22] = - { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, + { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b }; unsigned char salt[13] = - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c }; unsigned char info[10] = - { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 }; + { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 }; unsigned char okm[42] = - { 0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a, 0x90, 0x43, + { 0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a, 0x90, 0x43, 0x4f, 0x64, 0xd0, 0x36, 0x2f, 0x2a, 0x2d, 0x2d, 0x0a, 0x90, 0xcf, 0x1a, 0x5a, 0x4c, 0x5d, 0xb0, 0x2d, 0x56, 0xec, 0xc4, 0xc5, 0xbf, 0x34, 0x00, 0x72, 0x08, 0xd5, 0xb8, 0x87, 0x18, 0x58, 0x65 @@ -56,9 +56,9 @@ tc1 () memset (result, 0, sizeof (result)); GNUNET_assert (GNUNET_CRYPTO_hkdf - (result, l, GCRY_MD_SHA256, GCRY_MD_SHA256, salt, - sizeof (salt), ikm, sizeof (ikm), info, sizeof (info), - NULL) == GNUNET_YES); + (result, l, GCRY_MD_SHA256, GCRY_MD_SHA256, salt, + sizeof (salt), ikm, sizeof (ikm), info, sizeof (info), + NULL) == GNUNET_YES); GNUNET_assert (memcmp (result, okm, l) == 0); GNUNET_assert (memcmp (result + l, "\0", 2) == 0); } @@ -67,7 +67,7 @@ void tc2 () { unsigned char ikm[80] = - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, @@ -76,7 +76,7 @@ tc2 () 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f }; unsigned char salt[80] = - { 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, + { 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, @@ -85,7 +85,7 @@ tc2 () 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf }; unsigned char info[80] = - { 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, + { 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, @@ -94,7 +94,7 @@ tc2 () 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff }; unsigned char okm[82] = - { 0xb1, 0x1e, 0x39, 0x8d, 0xc8, 0x03, 0x27, 0xa1, 0xc8, 0xe7, + { 0xb1, 0x1e, 0x39, 0x8d, 0xc8, 0x03, 0x27, 0xa1, 0xc8, 0xe7, 0xf7, 0x8c, 0x59, 0x6a, 0x49, 0x34, 0x4f, 0x01, 0x2e, 0xda, 0x2d, 0x4e, 0xfa, 0xd8, 0xa0, 0x50, 0xcc, 0x4c, 0x19, 0xaf, 0xa9, 0x7c, 0x59, 0x04, 0x5a, 0x99, 0xca, 0xc7, 0x82, 0x72, 0x71, 0xcb, 0x41, 0xc6, 0x5e, 0x59, @@ -107,9 +107,9 @@ tc2 () memset (result, 0, sizeof (result)); GNUNET_assert (GNUNET_CRYPTO_hkdf - (result, l, GCRY_MD_SHA256, GCRY_MD_SHA256, salt, - sizeof (salt), ikm, sizeof (ikm), info, sizeof (info), - NULL) == GNUNET_YES); + (result, l, GCRY_MD_SHA256, GCRY_MD_SHA256, salt, + sizeof (salt), ikm, sizeof (ikm), info, sizeof (info), + NULL) == GNUNET_YES); GNUNET_assert (memcmp (result, okm, l) == 0); GNUNET_assert (memcmp (result + l, "\0", 2) == 0); } @@ -118,11 +118,11 @@ void tc3 () { unsigned char ikm[22] = - { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, + { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b }; unsigned char okm[42] = - { 0x8d, 0xa4, 0xe7, 0x75, 0xa5, 0x63, 0xc1, 0x8f, 0x71, 0x5f, + { 0x8d, 0xa4, 0xe7, 0x75, 0xa5, 0x63, 0xc1, 0x8f, 0x71, 0x5f, 0x80, 0x2a, 0x06, 0x3c, 0x5a, 0x31, 0xb8, 0xa1, 0x1f, 0x5c, 0x5e, 0xe1, 0x87, 0x9e, 0xc3, 0x45, 0x4e, 0x5f, 0x3c, 0x73, 0x8d, 0x2d, 0x9d, 0x20, 0x13, 0x95, 0xfa, 0xa4, 0xb6, 0x1a, 0x96, 0xc8 @@ -132,8 +132,8 @@ tc3 () memset (result, 0, sizeof (result)); GNUNET_assert (GNUNET_CRYPTO_hkdf - (result, l, GCRY_MD_SHA256, GCRY_MD_SHA256, NULL, 0, ikm, - sizeof (ikm), NULL, 0, NULL) == GNUNET_YES); + (result, l, GCRY_MD_SHA256, GCRY_MD_SHA256, NULL, 0, ikm, + sizeof (ikm), NULL, 0, NULL) == GNUNET_YES); GNUNET_assert (memcmp (result, okm, l) == 0); GNUNET_assert (memcmp (result + l, "\0", 2) == 0); } @@ -142,17 +142,17 @@ void tc4 () { unsigned char ikm[11] = - { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, + { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b }; unsigned char salt[13] = - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c }; unsigned char info[10] = - { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 }; + { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 }; unsigned char okm[42] = - { 0x08, 0x5a, 0x01, 0xea, 0x1b, 0x10, 0xf3, 0x69, 0x33, 0x06, + { 0x08, 0x5a, 0x01, 0xea, 0x1b, 0x10, 0xf3, 0x69, 0x33, 0x06, 0x8b, 0x56, 0xef, 0xa5, 0xad, 0x81, 0xa4, 0xf1, 0x4b, 0x82, 0x2f, 0x5b, 0x09, 0x15, 0x68, 0xa9, 0xcd, 0xd4, 0xf1, 0x55, 0xfd, 0xa2, 0xc2, 0x2e, 0x42, 0x24, 0x78, 0xd3, 0x05, 0xf3, 0xf8, 0x96 @@ -162,9 +162,8 @@ tc4 () memset (result, 0, sizeof (result)); GNUNET_assert (GNUNET_CRYPTO_hkdf - (result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, salt, sizeof (salt), - ikm, sizeof (ikm), info, sizeof (info), - NULL) == GNUNET_YES); + (result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, salt, sizeof (salt), + ikm, sizeof (ikm), info, sizeof (info), NULL) == GNUNET_YES); GNUNET_assert (memcmp (result, okm, l) == 0); GNUNET_assert (memcmp (result + l, "\0", 2) == 0); } @@ -173,7 +172,7 @@ void tc5 () { unsigned char ikm[80] = - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, @@ -182,7 +181,7 @@ tc5 () 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f }; unsigned char salt[80] = - { 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, + { 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, @@ -191,7 +190,7 @@ tc5 () 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf }; unsigned char info[80] = - { 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, + { 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, @@ -200,7 +199,7 @@ tc5 () 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff }; unsigned char okm[82] = - { 0x0b, 0xd7, 0x70, 0xa7, 0x4d, 0x11, 0x60, 0xf7, 0xc9, 0xf1, + { 0x0b, 0xd7, 0x70, 0xa7, 0x4d, 0x11, 0x60, 0xf7, 0xc9, 0xf1, 0x2c, 0xd5, 0x91, 0x2a, 0x06, 0xeb, 0xff, 0x6a, 0xdc, 0xae, 0x89, 0x9d, 0x92, 0x19, 0x1f, 0xe4, 0x30, 0x56, 0x73, 0xba, 0x2f, 0xfe, 0x8f, 0xa3, 0xf1, 0xa4, 0xe5, 0xad, 0x79, 0xf3, 0xf3, 0x34, 0xb3, 0xb2, 0x02, 0xb2, @@ -213,9 +212,8 @@ tc5 () memset (result, 0, sizeof (result)); GNUNET_assert (GNUNET_CRYPTO_hkdf - (result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, salt, sizeof (salt), - ikm, sizeof (ikm), info, sizeof (info), - NULL) == GNUNET_YES); + (result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, salt, sizeof (salt), + ikm, sizeof (ikm), info, sizeof (info), NULL) == GNUNET_YES); GNUNET_assert (memcmp (result, okm, l) == 0); GNUNET_assert (memcmp (result + l, "\0", 2) == 0); } @@ -224,11 +222,11 @@ void tc6 () { unsigned char ikm[22] = - { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, + { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b }; unsigned char okm[42] = - { 0x0a, 0xc1, 0xaf, 0x70, 0x02, 0xb3, 0xd7, 0x61, 0xd1, 0xe5, + { 0x0a, 0xc1, 0xaf, 0x70, 0x02, 0xb3, 0xd7, 0x61, 0xd1, 0xe5, 0x52, 0x98, 0xda, 0x9d, 0x05, 0x06, 0xb9, 0xae, 0x52, 0x05, 0x72, 0x20, 0xa3, 0x06, 0xe0, 0x7b, 0x6b, 0x87, 0xe8, 0xdf, 0x21, 0xd0, 0xea, 0x00, 0x03, 0x3d, 0xe0, 0x39, 0x84, 0xd3, 0x49, 0x18 @@ -238,8 +236,8 @@ tc6 () memset (result, 0, sizeof (result)); GNUNET_assert (GNUNET_CRYPTO_hkdf - (result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, NULL, 0, ikm, - sizeof (ikm), NULL, 0, NULL) == GNUNET_YES); + (result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, NULL, 0, ikm, + sizeof (ikm), NULL, 0, NULL) == GNUNET_YES); GNUNET_assert (memcmp (result, okm, l) == 0); GNUNET_assert (memcmp (result + l, "\0", 2) == 0); } @@ -248,7 +246,7 @@ void tc7 () { unsigned char ikm[80] = - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, @@ -257,7 +255,7 @@ tc7 () 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f }; unsigned char salt[80] = - { 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, + { 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, @@ -277,7 +275,7 @@ tc7 () 0xfe, 0xff }; unsigned char okm[82] = - { 0x0b, 0xd7, 0x70, 0xa7, 0x4d, 0x11, 0x60, 0xf7, 0xc9, 0xf1, + { 0x0b, 0xd7, 0x70, 0xa7, 0x4d, 0x11, 0x60, 0xf7, 0xc9, 0xf1, 0x2c, 0xd5, 0x91, 0x2a, 0x06, 0xeb, 0xff, 0x6a, 0xdc, 0xae, 0x89, 0x9d, 0x92, 0x19, 0x1f, 0xe4, 0x30, 0x56, 0x73, 0xba, 0x2f, 0xfe, 0x8f, 0xa3, 0xf1, 0xa4, 0xe5, 0xad, 0x79, 0xf3, 0xf3, 0x34, 0xb3, 0xb2, 0x02, 0xb2, @@ -290,9 +288,9 @@ tc7 () memset (result, 0, sizeof (result)); GNUNET_assert (GNUNET_CRYPTO_hkdf - (result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, salt, sizeof (salt), - ikm, sizeof (ikm), info1, sizeof (info1), info2, - sizeof (info2), NULL) == GNUNET_YES); + (result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, salt, sizeof (salt), + ikm, sizeof (ikm), info1, sizeof (info1), info2, + sizeof (info2), NULL) == GNUNET_YES); GNUNET_assert (memcmp (result, okm, l) == 0); GNUNET_assert (memcmp (result + l, "\0", 2) == 0); } @@ -301,13 +299,13 @@ void tc8 () { unsigned char ikm[32] = - { 0xbf, 0x16, 0x6e, 0x46, 0x3a, 0x6c, 0xf3, 0x93, 0xa7, 0x72, + { 0xbf, 0x16, 0x6e, 0x46, 0x3a, 0x6c, 0xf3, 0x93, 0xa7, 0x72, 0x11, 0xa1, 0xdc, 0x0b, 0x07, 0xdb, 0x1a, 0x5e, 0xd9, 0xb9, 0x81, 0xbe, 0xea, 0xe4, 0x31, 0x5f, 0x24, 0xff, 0xfe, 0x50, 0x8a, 0xde }; unsigned char salt[4] = { 0xfc, 0x62, 0x76, 0x35 }; unsigned char info[86] = - { 0x8c, 0x0d, 0xcf, 0xb3, 0x25, 0x6e, 0x88, 0x0d, 0xc1, 0x0b, + { 0x8c, 0x0d, 0xcf, 0xb3, 0x25, 0x6e, 0x88, 0x0d, 0xc1, 0x0b, 0x1d, 0x33, 0x15, 0x3e, 0x52, 0x0b, 0xb0, 0x77, 0xff, 0x7d, 0xc3, 0xc7, 0xef, 0xe5, 0x8e, 0x3c, 0xc4, 0x4e, 0x8b, 0x41, 0x46, 0x1f, 0x02, 0x94, 0x82, 0x35, 0xc5, 0xa6, 0x5e, 0x91, 0xd8, 0xa2, 0x90, 0xfd, 0x6f, 0xb4, @@ -317,7 +315,7 @@ tc8 () 0x74, 0x6f, 0x72, 0x00 }; unsigned char okm[16] = - { 0xd6, 0x90, 0xec, 0x9e, 0x62, 0xdf, 0xb9, 0x41, 0xff, 0x92, + { 0xd6, 0x90, 0xec, 0x9e, 0x62, 0xdf, 0xb9, 0x41, 0xff, 0x92, 0x4f, 0xd2, 0xf6, 0x1d, 0x67, 0xe0 }; char result[18]; @@ -325,9 +323,9 @@ tc8 () memset (result, 0, sizeof (result)); GNUNET_assert (GNUNET_CRYPTO_hkdf - (result, l, GCRY_MD_SHA512, GCRY_MD_SHA256, salt, - sizeof (salt), ikm, sizeof (ikm), info, sizeof (info), - NULL) == GNUNET_YES); + (result, l, GCRY_MD_SHA512, GCRY_MD_SHA256, salt, + sizeof (salt), ikm, sizeof (ikm), info, sizeof (info), + NULL) == GNUNET_YES); GNUNET_assert (memcmp (result, okm, l) == 0); GNUNET_assert (memcmp (result + l, "\0", 2) == 0); } diff --git a/src/util/test_crypto_ksk.c b/src/util/test_crypto_ksk.c index 55d2dffcb..2789f5edb 100644 --- a/src/util/test_crypto_ksk.c +++ b/src/util/test_crypto_ksk.c @@ -39,7 +39,7 @@ static int testCorrectKey () { const char *want = - "010601000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b73c215f7a5e6b09bec55713c901786c09324a150980e014bdb0d04426934929c3b4971a9711af5455536cd6eeb8bfa004ee904972a737455f53c752987d8c82b755bc02882b44950c4acdc1672ba74c3b94d81a4c1ea3d74e7700ae5594c3a4f3c559e4bff2df6844fac302e4b66175e14dc8bad3ce44281d2fec1a1abef06301010000"; + "010601000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b73c215f7a5e6b09bec55713c901786c09324a150980e014bdb0d04426934929c3b4971a9711af5455536cd6eeb8bfa004ee904972a737455f53c752987d8c82b755bc02882b44950c4acdc1672ba74c3b94d81a4c1ea3d74e7700ae5594c3a4f3c559e4bff2df6844fac302e4b66175e14dc8bad3ce44281d2fec1a1abef06301010000"; GNUNET_HashCode in; struct GNUNET_CRYPTO_RsaPrivateKey *hostkey; struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey; @@ -50,29 +50,27 @@ testCorrectKey () GNUNET_CRYPTO_hash ("X", strlen ("X"), &in); hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in); if (hostkey == NULL) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } GNUNET_CRYPTO_rsa_key_get_public (hostkey, &pkey); GNUNET_CRYPTO_rsa_key_free (hostkey); #if 0 - for (i = 0; i < sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded); - i++) + for (i = 0; i < sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded); i++) printf ("%02x", ((unsigned char *) &pkey)[i]); printf ("\n"); #endif - for (i = 0; i < sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded); - i++) + for (i = 0; i < sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded); i++) + { + snprintf (out, sizeof (out), "%02x", ((unsigned char *) &pkey)[i]); + if (0 != strncmp (out, &want[i * 2], 2)) { - snprintf (out, sizeof (out), "%02x", ((unsigned char *) &pkey)[i]); - if (0 != strncmp (out, &want[i * 2], 2)) - { - fprintf (stderr, " Failed! Wanted %.2s but got %2s at %d\n", - &want[i * 2], out, i); - return GNUNET_SYSERR; - } + fprintf (stderr, " Failed! Wanted %.2s but got %2s at %d\n", &want[i * 2], + out, i); + return GNUNET_SYSERR; } + } fprintf (stderr, " OK\n"); return GNUNET_OK; } @@ -91,10 +89,10 @@ testMultiKey (const char *word) GNUNET_CRYPTO_hash (word, strlen (word), &in); hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in); if (hostkey == NULL) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } GNUNET_CRYPTO_rsa_key_get_public (hostkey, &pkey); /* * for (i=0;i (buf[i] = GNUNET_CRYPTO_random_u32 (mode, 1024))); for (i = 0; i < 10; i++) + { + b2 = GNUNET_CRYPTO_random_permute (mode, 1024); + if (0 == memcmp (b2, buf, sizeof (buf))) { - b2 = GNUNET_CRYPTO_random_permute (mode, 1024); - if (0 == memcmp (b2, buf, sizeof (buf))) - { - fprintf (stderr, "!"); - GNUNET_free (b2); - continue; - } + fprintf (stderr, "!"); GNUNET_free (b2); - break; + continue; } + GNUNET_free (b2); + break; + } if (i == 10) - return 1; /* virtually impossible... */ + return 1; /* virtually impossible... */ for (n = 10; n < 1024LL * 1024LL * 1024LL; n *= 10) GNUNET_break (n > GNUNET_CRYPTO_random_u64 (mode, n)); diff --git a/src/util/test_crypto_rsa.c b/src/util/test_crypto_rsa.c index 6a2c1b355..f26a76a38 100644 --- a/src/util/test_crypto_rsa.c +++ b/src/util/test_crypto_rsa.c @@ -54,36 +54,36 @@ testEncryptDecrypt () ok = 0; start = GNUNET_TIME_absolute_get (); for (i = 0; i < ITER; i++) + { + fprintf (stderr, "."); + if (GNUNET_SYSERR == + GNUNET_CRYPTO_rsa_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, &pkey, + &target)) { - fprintf (stderr, "."); - if (GNUNET_SYSERR == - GNUNET_CRYPTO_rsa_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, - &pkey, &target)) - { - fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n"); - ok++; - continue; - } - if (-1 == - GNUNET_CRYPTO_rsa_decrypt (hostkey, &target, result, - strlen (TESTSTRING) + 1)) - { - fprintf (stderr, "GNUNET_CRYPTO_rsa_decrypt returned SYSERR\n"); - ok++; - continue; + fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n"); + ok++; + continue; + } + if (-1 == + GNUNET_CRYPTO_rsa_decrypt (hostkey, &target, result, + strlen (TESTSTRING) + 1)) + { + fprintf (stderr, "GNUNET_CRYPTO_rsa_decrypt returned SYSERR\n"); + ok++; + continue; - } - if (strncmp (TESTSTRING, result, strlen (TESTSTRING)) != 0) - { - printf ("%s != %.*s - testEncryptDecrypt failed!\n", TESTSTRING, - (int) MAX_TESTVAL, result); - ok++; - continue; - } } + if (strncmp (TESTSTRING, result, strlen (TESTSTRING)) != 0) + { + printf ("%s != %.*s - testEncryptDecrypt failed!\n", TESTSTRING, + (int) MAX_TESTVAL, result); + ok++; + continue; + } + } printf ("%d RSA encrypt/decrypt operations %llums (%d failures)\n", ITER, - (unsigned long long) - GNUNET_TIME_absolute_get_duration (start).rel_value, ok); + (unsigned long long) + GNUNET_TIME_absolute_get_duration (start).rel_value, ok); GNUNET_CRYPTO_rsa_key_free (hostkey); if (ok == 0) return GNUNET_OK; @@ -109,20 +109,20 @@ testEncryptPerformance () ok = 0; start = GNUNET_TIME_absolute_get (); for (i = 0; i < ITER; i++) + { + fprintf (stderr, "."); + if (GNUNET_SYSERR == + GNUNET_CRYPTO_rsa_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, &pkey, + &target)) { - fprintf (stderr, "."); - if (GNUNET_SYSERR == - GNUNET_CRYPTO_rsa_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, - &pkey, &target)) - { - fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n"); - ok++; - continue; - } + fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n"); + ok++; + continue; } + } printf ("%d RSA encrypt operations %llu ms (%d failures)\n", ITER, - (unsigned long long) - GNUNET_TIME_absolute_get_duration (start).rel_value, ok); + (unsigned long long) + GNUNET_TIME_absolute_get_duration (start).rel_value, ok); GNUNET_CRYPTO_rsa_key_free (hostkey); if (ok != 0) return GNUNET_SYSERR; @@ -149,39 +149,37 @@ testEncryptDecryptSK () ok = 0; start = GNUNET_TIME_absolute_get (); for (i = 0; i < ITER; i++) + { + fprintf (stderr, "."); + GNUNET_CRYPTO_aes_create_session_key (&insk); + if (GNUNET_SYSERR == + GNUNET_CRYPTO_rsa_encrypt (&insk, + sizeof (struct GNUNET_CRYPTO_AesSessionKey), + &pkey, &target)) + { + fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n"); + ok++; + continue; + } + if (-1 == + GNUNET_CRYPTO_rsa_decrypt (hostkey, &target, &outsk, + sizeof (struct GNUNET_CRYPTO_AesSessionKey))) + { + fprintf (stderr, "GNUNET_CRYPTO_rsa_decrypt returned SYSERR\n"); + ok++; + continue; + } + if (0 != + memcmp (&insk, &outsk, sizeof (struct GNUNET_CRYPTO_AesSessionKey))) { - fprintf (stderr, "."); - GNUNET_CRYPTO_aes_create_session_key (&insk); - if (GNUNET_SYSERR == - GNUNET_CRYPTO_rsa_encrypt (&insk, - sizeof (struct - GNUNET_CRYPTO_AesSessionKey), - &pkey, &target)) - { - fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n"); - ok++; - continue; - } - if (-1 == - GNUNET_CRYPTO_rsa_decrypt (hostkey, &target, &outsk, - sizeof (struct - GNUNET_CRYPTO_AesSessionKey))) - { - fprintf (stderr, "GNUNET_CRYPTO_rsa_decrypt returned SYSERR\n"); - ok++; - continue; - } - if (0 != - memcmp (&insk, &outsk, sizeof (struct GNUNET_CRYPTO_AesSessionKey))) - { - printf ("testEncryptDecryptSK failed!\n"); - ok++; - continue; - } + printf ("testEncryptDecryptSK failed!\n"); + ok++; + continue; } + } printf ("%d RSA encrypt/decrypt SK operations %llums (%d failures)\n", ITER, - (unsigned long long) - GNUNET_TIME_absolute_get_duration (start).rel_value, ok); + (unsigned long long) + GNUNET_TIME_absolute_get_duration (start).rel_value, ok); GNUNET_CRYPTO_rsa_key_free (hostkey); if (ok != 0) return GNUNET_SYSERR; @@ -208,34 +206,34 @@ testSignVerify () purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); for (i = 0; i < ITER; i++) + { + fprintf (stderr, "."); + if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_sign (hostkey, &purp, &sig)) + { + fprintf (stderr, "GNUNET_CRYPTO_rsa_sign returned SYSERR\n"); + ok = GNUNET_SYSERR; + continue; + } + if (GNUNET_SYSERR == + GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TEST, &purp, &sig, + &pkey)) { - fprintf (stderr, "."); - if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_sign (hostkey, &purp, &sig)) - { - fprintf (stderr, "GNUNET_CRYPTO_rsa_sign returned SYSERR\n"); - ok = GNUNET_SYSERR; - continue; - } - if (GNUNET_SYSERR == - GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TEST, &purp, - &sig, &pkey)) - { - printf ("GNUNET_CRYPTO_rsa_verify failed!\n"); - ok = GNUNET_SYSERR; - continue; - } - if (GNUNET_SYSERR != - GNUNET_CRYPTO_rsa_verify - (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, &purp, &sig, &pkey)) - { - printf ("GNUNET_CRYPTO_rsa_verify failed to fail!\n"); - ok = GNUNET_SYSERR; - continue; - } + printf ("GNUNET_CRYPTO_rsa_verify failed!\n"); + ok = GNUNET_SYSERR; + continue; } + if (GNUNET_SYSERR != + GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, + &purp, &sig, &pkey)) + { + printf ("GNUNET_CRYPTO_rsa_verify failed to fail!\n"); + ok = GNUNET_SYSERR; + continue; + } + } printf ("%d RSA sign/verify operations %llums\n", ITER, - (unsigned long long) - GNUNET_TIME_absolute_get_duration (start).rel_value); + (unsigned long long) + GNUNET_TIME_absolute_get_duration (start).rel_value); GNUNET_CRYPTO_rsa_key_free (hostkey); return ok; } @@ -260,18 +258,18 @@ testSignPerformance () GNUNET_CRYPTO_rsa_key_get_public (hostkey, &pkey); start = GNUNET_TIME_absolute_get (); for (i = 0; i < ITER; i++) + { + fprintf (stderr, "."); + if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_sign (hostkey, &purp, &sig)) { - fprintf (stderr, "."); - if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_sign (hostkey, &purp, &sig)) - { - fprintf (stderr, "GNUNET_CRYPTO_rsa_sign returned SYSERR\n"); - ok = GNUNET_SYSERR; - continue; - } + fprintf (stderr, "GNUNET_CRYPTO_rsa_sign returned SYSERR\n"); + ok = GNUNET_SYSERR; + continue; } + } printf ("%d RSA sign operations %llu ms\n", ITER, - (unsigned long long) - GNUNET_TIME_absolute_get_duration (start).rel_value); + (unsigned long long) + GNUNET_TIME_absolute_get_duration (start).rel_value); GNUNET_CRYPTO_rsa_key_free (hostkey); return ok; } @@ -328,9 +326,9 @@ main (int argc, char *argv[]) failureCount++; if (failureCount != 0) - { - printf ("\n\n%d TESTS FAILED!\n\n", failureCount); - return -1; - } + { + printf ("\n\n%d TESTS FAILED!\n\n", failureCount); + return -1; + } return 0; -} /* end of main */ +} /* end of main */ diff --git a/src/util/test_disk.c b/src/util/test_disk.c index e8ec88c9f..91154a6f5 100644 --- a/src/util/test_disk.c +++ b/src/util/test_disk.c @@ -38,41 +38,40 @@ testReadWrite () if (strlen (TESTSTRING) != GNUNET_DISK_fn_write (".testfile", TESTSTRING, strlen (TESTSTRING), - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE)) + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE)) return 1; if (GNUNET_OK != GNUNET_DISK_file_test (".testfile")) return 1; ret = GNUNET_DISK_fn_read (".testfile", tmp, sizeof (tmp) - 1); if (ret < 0) - { - fprintf (stderr, "Error reading file `%s' in testReadWrite\n", - ".testfile"); - return 1; - } + { + fprintf (stderr, "Error reading file `%s' in testReadWrite\n", ".testfile"); + return 1; + } tmp[ret] = '\0'; if (0 != memcmp (tmp, TESTSTRING, strlen (TESTSTRING) + 1)) - { - fprintf (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n", - tmp, TESTSTRING, ".testfile"); - return 1; - } + { + fprintf (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n", tmp, + TESTSTRING, ".testfile"); + return 1; + } GNUNET_DISK_file_copy (".testfile", ".testfile2"); memset (tmp, 0, sizeof (tmp)); ret = GNUNET_DISK_fn_read (".testfile2", tmp, sizeof (tmp) - 1); if (ret < 0) - { - fprintf (stderr, "Error reading file `%s' in testReadWrite\n", - ".testfile2"); - return 1; - } + { + fprintf (stderr, "Error reading file `%s' in testReadWrite\n", + ".testfile2"); + return 1; + } tmp[ret] = '\0'; if (0 != memcmp (tmp, TESTSTRING, strlen (TESTSTRING) + 1)) - { - fprintf (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n", - tmp, TESTSTRING, ".testfile2"); - return 1; - } + { + fprintf (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n", tmp, + TESTSTRING, ".testfile2"); + return 1; + } GNUNET_break (0 == UNLINK (".testfile")); GNUNET_break (0 == UNLINK (".testfile2")); @@ -90,15 +89,15 @@ testOpenClose () long avail; fh = GNUNET_DISK_file_open (".testfile", - GNUNET_DISK_OPEN_READWRITE | - GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE); + GNUNET_DISK_OPEN_READWRITE | + GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE); GNUNET_assert (GNUNET_NO == GNUNET_DISK_handle_invalid (fh)); GNUNET_break (5 == GNUNET_DISK_file_write (fh, "Hello", 5)); GNUNET_DISK_file_close (fh); GNUNET_break (GNUNET_OK == - GNUNET_DISK_file_size (".testfile", &size, GNUNET_NO)); + GNUNET_DISK_file_size (".testfile", &size, GNUNET_NO)); if (size != 5) return 1; GNUNET_break (0 == UNLINK (".testfile")); @@ -108,19 +107,19 @@ testOpenClose () avail = GNUNET_DISK_get_blocks_available (".testfile"); GNUNET_log_skip (0, GNUNET_NO); fh = GNUNET_DISK_file_open (".testfile", - GNUNET_DISK_OPEN_READWRITE | - GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_WRITE | - GNUNET_DISK_PERM_USER_READ); + GNUNET_DISK_OPEN_READWRITE | + GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_WRITE | + GNUNET_DISK_PERM_USER_READ); GNUNET_assert (GNUNET_NO == GNUNET_DISK_handle_invalid (fh)); while ((avail == GNUNET_DISK_get_blocks_available (".testfile")) && - (avail != -1)) + (avail != -1)) if (16 != GNUNET_DISK_file_write (fh, "HelloWorld123456", 16)) - { - GNUNET_DISK_file_close (fh); - GNUNET_break (0 == UNLINK (".testfile")); - return 1; - } + { + GNUNET_DISK_file_close (fh); + GNUNET_break (0 == UNLINK (".testfile")); + return 1; + } GNUNET_DISK_file_close (fh); GNUNET_break (0 == UNLINK (".testfile")); @@ -147,7 +146,7 @@ testDirScan () GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry_more")) return 1; GNUNET_DISK_directory_scan ("test", &scan_callback, - "test" DIR_SEPARATOR_STR "entry"); + "test" DIR_SEPARATOR_STR "entry"); if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) return 1; if (ok < 2) @@ -157,7 +156,7 @@ testDirScan () static void iter_callback (void *cls, struct GNUNET_DISK_DirectoryIterator *di, - const char *filename, const char *dirname) + const char *filename, const char *dirname) { int *i = cls; @@ -169,7 +168,7 @@ static void iter_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { GNUNET_DISK_directory_iterator_start (GNUNET_SCHEDULER_PRIORITY_DEFAULT, - "test", &iter_callback, cls); + "test", &iter_callback, cls); } static int @@ -203,14 +202,14 @@ testGetHome () cfg = GNUNET_CONFIGURATION_create (); GNUNET_assert (cfg != NULL); GNUNET_CONFIGURATION_set_value_string (cfg, "service", "HOME", - "/tmp/test-gnunet-disk-a/b/c"); + "/tmp/test-gnunet-disk-a/b/c"); fn = GNUNET_DISK_get_home_filename (cfg, "service", "d", "e", NULL); GNUNET_assert (fn != NULL); GNUNET_CONFIGURATION_destroy (cfg); ret = strcmp ("/tmp/test-gnunet-disk-a/b/c/d/e", fn); GNUNET_free (fn); GNUNET_break (GNUNET_OK == - GNUNET_DISK_directory_remove ("/tmp/test-gnunet-disk-a")); + GNUNET_DISK_directory_remove ("/tmp/test-gnunet-disk-a")); return ret; } @@ -221,10 +220,10 @@ testCanonicalize () GNUNET_DISK_filename_canonicalize (fn); if (0 != strcmp (fn, "ab____cd_ef__g_")) - { - GNUNET_free (fn); - return 1; - } + { + GNUNET_free (fn); + return 1; + } GNUNET_free (fn); return 0; } @@ -276,9 +275,9 @@ main (int argc, char *argv[]) failureCount += testChangeOwner (); failureCount += testDirMani (); if (failureCount != 0) - { - fprintf (stderr, "\n%u TESTS FAILED!\n", failureCount); - return -1; - } + { + fprintf (stderr, "\n%u TESTS FAILED!\n", failureCount); + return -1; + } return 0; -} /* end of main */ +} /* end of main */ diff --git a/src/util/test_getopt.c b/src/util/test_getopt.c index f830454cd..a517887bf 100644 --- a/src/util/test_getopt.c +++ b/src/util/test_getopt.c @@ -63,15 +63,15 @@ testVerbose () }; if (3 != GNUNET_GETOPT_run ("test", verboseoptionlist, 4, myargv)) - { - GNUNET_break (0); - return 1; - } + { + GNUNET_break (0); + return 1; + } if (vflags != 2) - { - GNUNET_break (0); - return 1; - } + { + GNUNET_break (0); + return 1; + } return 0; } @@ -89,10 +89,10 @@ testVersion () }; if (-1 != GNUNET_GETOPT_run ("test_getopt", versionoptionlist, 2, myargv)) - { - GNUNET_break (0); - return 1; - } + { + GNUNET_break (0); + return 1; + } return 0; } @@ -110,10 +110,10 @@ testAbout () }; if (-1 != GNUNET_GETOPT_run ("test_getopt", aboutoptionlist, 2, myargv)) - { - GNUNET_break (0); - return 1; - } + { + GNUNET_break (0); + return 1; + } return 0; } @@ -136,18 +136,18 @@ testLogOpts () }; if (5 != GNUNET_GETOPT_run ("test_getopt", logoptionlist, 5, myargv)) - { - GNUNET_break (0); - return 1; - } + { + GNUNET_break (0); + return 1; + } GNUNET_assert (fn != NULL); if ((0 != strcmp (level, "WARNING")) || (0 != strcmp (fn, "filename"))) - { - GNUNET_break (0); - GNUNET_free (level); - GNUNET_free (fn); - return 1; - } + { + GNUNET_break (0); + GNUNET_free (level); + GNUNET_free (fn); + return 1; + } GNUNET_free (level); GNUNET_free (fn); return 0; @@ -178,15 +178,15 @@ testFlagNum () }; if (6 != GNUNET_GETOPT_run ("test_getopt", logoptionlist, 6, myargv)) - { - GNUNET_break (0); - return 1; - } + { + GNUNET_break (0); + return 1; + } if ((1 != flag) || (42 != num) || (42 != lnum)) - { - GNUNET_break (0); - return 1; - } + { + GNUNET_break (0); + return 1; + } return 0; } diff --git a/src/util/test_os_network.c b/src/util/test_os_network.c index 28cc9cd3a..315f97d97 100644 --- a/src/util/test_os_network.c +++ b/src/util/test_os_network.c @@ -44,10 +44,10 @@ proc (void *cls, const char *name, int isDefault, const struct sockaddr *addr, return GNUNET_OK; inet_ntop (addr->sa_family, - (addr->sa_family == - AF_INET) ? (void *) &((struct sockaddr_in *) addr)->sin_addr - : (void *) &((struct sockaddr_in6 *) addr)->sin6_addr, buf, - sizeof (buf)); + (addr->sa_family == + AF_INET) ? (void *) &((struct sockaddr_in *) addr)->sin_addr + : (void *) &((struct sockaddr_in6 *) addr)->sin6_addr, buf, + sizeof (buf)); if ((0 == strcmp ("::1", buf)) || (0 == strcmp ("127.0.0.1", buf))) *ok = 0; return GNUNET_OK; diff --git a/src/util/test_os_priority.c b/src/util/test_os_priority.c index 59f3ee816..94e2719a2 100644 --- a/src/util/test_os_priority.c +++ b/src/util/test_os_priority.c @@ -32,27 +32,27 @@ testprio () { if (GNUNET_OK != GNUNET_OS_set_process_priority (GNUNET_OS_process_current (), - GNUNET_SCHEDULER_PRIORITY_DEFAULT)) + GNUNET_SCHEDULER_PRIORITY_DEFAULT)) return 1; if (GNUNET_OK != GNUNET_OS_set_process_priority (GNUNET_OS_process_current (), - GNUNET_SCHEDULER_PRIORITY_UI)) + GNUNET_SCHEDULER_PRIORITY_UI)) return 1; if (GNUNET_OK != GNUNET_OS_set_process_priority (GNUNET_OS_process_current (), - GNUNET_SCHEDULER_PRIORITY_IDLE)) + GNUNET_SCHEDULER_PRIORITY_IDLE)) return 1; if (GNUNET_OK != GNUNET_OS_set_process_priority (GNUNET_OS_process_current (), - GNUNET_SCHEDULER_PRIORITY_BACKGROUND)) + GNUNET_SCHEDULER_PRIORITY_BACKGROUND)) return 1; if (GNUNET_OK != GNUNET_OS_set_process_priority (GNUNET_OS_process_current (), - GNUNET_SCHEDULER_PRIORITY_HIGH)) + GNUNET_SCHEDULER_PRIORITY_HIGH)) return 1; if (GNUNET_OK != GNUNET_OS_set_process_priority (GNUNET_OS_process_current (), - GNUNET_SCHEDULER_PRIORITY_HIGH)) + GNUNET_SCHEDULER_PRIORITY_HIGH)) return 1; return 0; } diff --git a/src/util/test_os_start_process.c b/src/util/test_os_start_process.c index 918ef1bc5..df8520546 100644 --- a/src/util/test_os_start_process.c +++ b/src/util/test_os_start_process.c @@ -53,9 +53,9 @@ end_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) - { - GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - } + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); + } GNUNET_OS_process_wait (proc); GNUNET_OS_process_close (proc); proc = NULL; @@ -79,28 +79,28 @@ read_call (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) #endif if (bytes < 1) - { - GNUNET_break (0); - ok = 1; - GNUNET_SCHEDULER_cancel (die_task); - GNUNET_SCHEDULER_add_now (&end_task, NULL); - return; - } + { + GNUNET_break (0); + ok = 1; + GNUNET_SCHEDULER_cancel (die_task); + GNUNET_SCHEDULER_add_now (&end_task, NULL); + return; + } ok = strncmp (&buf[0], test_phrase, strlen (test_phrase)); #if VERBOSE fprintf (stderr, "read %s\n", &buf[0]); #endif if (ok == 0) - { - GNUNET_SCHEDULER_cancel (die_task); - GNUNET_SCHEDULER_add_now (&end_task, NULL); - return; - } + { + GNUNET_SCHEDULER_cancel (die_task); + GNUNET_SCHEDULER_add_now (&end_task, NULL); + return; + } GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, - stdout_read_handle, &read_call, - stdout_read_handle); + stdout_read_handle, &read_call, + stdout_read_handle); } @@ -118,16 +118,16 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) hello_pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES); if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL)) - { - GNUNET_break (0); - ok = 1; - GNUNET_free (fn); - return; - } + { + GNUNET_break (0); + ok = 1; + GNUNET_free (fn); + return; + } proc = - GNUNET_OS_start_process (hello_pipe_stdin, hello_pipe_stdout, fn, - "test_gnunet_echo_hello", "-", NULL); + GNUNET_OS_start_process (hello_pipe_stdin, hello_pipe_stdout, fn, + "test_gnunet_echo_hello", "-", NULL); GNUNET_free (fn); /* Close the write end of the read pipe */ @@ -140,26 +140,26 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) /* Write the test_phrase to the cat process */ if (GNUNET_DISK_file_write (wh, test_phrase, strlen (test_phrase) + 1) != strlen (test_phrase) + 1) - { - GNUNET_break (0); - ok = 1; - return; - } + { + GNUNET_break (0); + ok = 1; + return; + } /* Close the write end to end the cycle! */ GNUNET_DISK_pipe_close_end (hello_pipe_stdin, GNUNET_DISK_PIPE_END_WRITE); stdout_read_handle = - GNUNET_DISK_pipe_handle (hello_pipe_stdout, GNUNET_DISK_PIPE_END_READ); + GNUNET_DISK_pipe_handle (hello_pipe_stdout, GNUNET_DISK_PIPE_END_READ); die_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_MINUTES, 1), &end_task, - NULL); + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_MINUTES, 1), &end_task, + NULL); GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, - stdout_read_handle, &read_call, - (void *) stdout_read_handle); + stdout_read_handle, &read_call, + (void *) stdout_read_handle); } @@ -183,11 +183,11 @@ main (int argc, char *argv[]) GNUNET_log_setup ("test-os-start-process", #if VERBOSE - "DEBUG", + "DEBUG", #else - "WARNING", + "WARNING", #endif - NULL); + NULL); ret = check (); return ret; diff --git a/src/util/test_peer.c b/src/util/test_peer.c index 5bf5108bc..3817d8243 100644 --- a/src/util/test_peer.c +++ b/src/util/test_peer.c @@ -43,13 +43,13 @@ generatePeerIdList () int i; for (i = 0; i < NUMBER_OF_PEERS; i++) - { - GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, - &pidArr[i].hashPubKey); + { + GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, + &pidArr[i].hashPubKey); #if DEBUG - printf ("Peer %d: %s\n", i, GNUNET_i2s (&pidArr[i])); + printf ("Peer %d: %s\n", i, GNUNET_i2s (&pidArr[i])); #endif - } + } } @@ -65,27 +65,25 @@ check () GNUNET_assert (0 == GNUNET_PEER_intern (NULL)); /* Insert Peers into PeerEntry table and hashmap */ for (i = 0; i < NUMBER_OF_PEERS; i++) + { + pid = GNUNET_PEER_intern (&pidArr[i]); + if (pid != (i + 1)) { - pid = GNUNET_PEER_intern (&pidArr[i]); - if (pid != (i + 1)) - { - fprintf (stderr, - "Unexpected Peer ID returned by intern function\n"); - return 1; - } + fprintf (stderr, "Unexpected Peer ID returned by intern function\n"); + return 1; } + } /* Referencing the first 3 peers once again */ for (i = 0; i < 3; i++) + { + pid = GNUNET_PEER_intern (&pidArr[i]); + if (pid != (i + 1)) { - pid = GNUNET_PEER_intern (&pidArr[i]); - if (pid != (i + 1)) - { - fprintf (stderr, - "Unexpected Peer ID returned by intern function\n"); - return 1; - } + fprintf (stderr, "Unexpected Peer ID returned by intern function\n"); + return 1; } + } /* Dereferencing the first 3 peers once [decrementing their reference count] */ GNUNET_PEER_decrement_rcs (ids, 3); @@ -130,11 +128,11 @@ main () GNUNET_log_setup ("test-peer", "ERROR", NULL); for (i = 0; i < 1; i++) - { - generatePeerIdList (); - if (0 != check ()) - return 1; - } + { + generatePeerIdList (); + if (0 != check ()) + return 1; + } return 0; } diff --git a/src/util/test_plugin.c b/src/util/test_plugin.c index bfa3cf110..4635e1357 100644 --- a/src/util/test_plugin.c +++ b/src/util/test_plugin.c @@ -27,9 +27,7 @@ #define VERBOSE GNUNET_EXTRA_LOGGING static void -test_cb (void *cls, - const char *libname, - void *lib_ret) +test_cb (void *cls, const char *libname, void *lib_ret) { void *ret; @@ -39,7 +37,7 @@ test_cb (void *cls, GNUNET_assert (NULL != ret); GNUNET_assert (0 == strcmp (ret, "World")); } - + static int check () diff --git a/src/util/test_program.c b/src/util/test_program.c index 0ff49b81e..faeb4e716 100644 --- a/src/util/test_program.c +++ b/src/util/test_program.c @@ -58,7 +58,7 @@ static struct GNUNET_GETOPT_CommandLineOption options4[] = { static void runner (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) + const struct GNUNET_CONFIGURATION_Handle *cfg) { int *ok = cls; @@ -91,18 +91,18 @@ check () }; GNUNET_assert (GNUNET_OK == - GNUNET_PROGRAM_run (7, argv, "test_program", "A test", - options1, &runner, &ok)); + GNUNET_PROGRAM_run (7, argv, "test_program", "A test", + options1, &runner, &ok)); GNUNET_assert (GNUNET_OK == - GNUNET_PROGRAM_run (7, argv, "test_program", "A test", - options2, &runner, &ok)); + GNUNET_PROGRAM_run (7, argv, "test_program", "A test", + options2, &runner, &ok)); GNUNET_assert (GNUNET_OK == - GNUNET_PROGRAM_run (7, argv, "test_program", "A test", - options3, &runner, &ok)); + GNUNET_PROGRAM_run (7, argv, "test_program", "A test", + options3, &runner, &ok)); GNUNET_assert (GNUNET_OK == - GNUNET_PROGRAM_run (7, argv, "test_program", "A test", - options4, &runner, &ok)); + GNUNET_PROGRAM_run (7, argv, "test_program", "A test", + options4, &runner, &ok)); return ok; } diff --git a/src/util/test_pseudonym.c b/src/util/test_pseudonym.c index 30a04598c..20a3d3d96 100644 --- a/src/util/test_pseudonym.c +++ b/src/util/test_pseudonym.c @@ -45,16 +45,16 @@ iter (void *cls, const GNUNET_HashCode * pseudonym, if ((0 == memcmp (pseudonym, &id1, sizeof (GNUNET_HashCode))) && (!GNUNET_CONTAINER_meta_data_test_equal (md, meta))) - { - *ok = GNUNET_NO; - GNUNET_break (0); - } + { + *ok = GNUNET_NO; + GNUNET_break (0); + } return GNUNET_OK; } static int noti_callback (void *cls, const GNUNET_HashCode * pseudonym, - const struct GNUNET_CONTAINER_MetaData *md, int rating) + const struct GNUNET_CONTAINER_MetaData *md, int rating) { int *ret = cls; @@ -64,7 +64,7 @@ noti_callback (void *cls, const GNUNET_HashCode * pseudonym, static int fake_noti_callback (void *cls, const GNUNET_HashCode * pseudonym, - const struct GNUNET_CONTAINER_MetaData *md, int rating) + const struct GNUNET_CONTAINER_MetaData *md, int rating) { int *ret = cls; @@ -74,7 +74,7 @@ fake_noti_callback (void *cls, const GNUNET_HashCode * pseudonym, static int false_callback (void *cls, const GNUNET_HashCode * pseudonym, - const struct GNUNET_CONTAINER_MetaData *md, int rating) + const struct GNUNET_CONTAINER_MetaData *md, int rating) { return GNUNET_OK; } @@ -109,28 +109,28 @@ main (int argc, char *argv[]) (void) GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test"); cfg = GNUNET_CONFIGURATION_create (); if (-1 == GNUNET_CONFIGURATION_parse (cfg, "test_pseudonym_data.conf")) - { - GNUNET_CONFIGURATION_destroy (cfg); - GNUNET_break (0); - return -1; - } + { + GNUNET_CONFIGURATION_destroy (cfg); + GNUNET_break (0); + return -1; + } notiCount = 0; fakenotiCount = 0; count = 0; GNUNET_PSEUDONYM_discovery_callback_register (cfg, &fake_noti_callback, - &fakenotiCount); + &fakenotiCount); GNUNET_PSEUDONYM_discovery_callback_register (cfg, ¬i_callback, - ¬iCount); + ¬iCount); GNUNET_PSEUDONYM_discovery_callback_unregister (&false_callback, &count); GNUNET_PSEUDONYM_discovery_callback_unregister (&fake_noti_callback, - &fakenotiCount); + &fakenotiCount); /* ACTUAL TEST CODE */ old = GNUNET_PSEUDONYM_list_all (cfg, NULL, NULL); meta = GNUNET_CONTAINER_meta_data_create (); GNUNET_CONTAINER_meta_data_insert (meta, "", EXTRACTOR_METATYPE_TITLE, - EXTRACTOR_METAFORMAT_UTF8, "text/plain", - "test", strlen ("test") + 1); + EXTRACTOR_METAFORMAT_UTF8, "text/plain", + "test", strlen ("test") + 1); GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id1); GNUNET_PSEUDONYM_add (cfg, &id1, meta); CHECK (notiCount == 1); @@ -145,11 +145,11 @@ main (int argc, char *argv[]) newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok); CHECK (old < newVal); GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_meta_data_insert (meta, "", - EXTRACTOR_METATYPE_COMMENT, - EXTRACTOR_METAFORMAT_UTF8, - "text/plain", m, - strlen (m) + 1)); + GNUNET_CONTAINER_meta_data_insert (meta, "", + EXTRACTOR_METATYPE_COMMENT, + EXTRACTOR_METAFORMAT_UTF8, + "text/plain", m, + strlen (m) + 1)); GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id3); GNUNET_PSEUDONYM_add (cfg, &id3, meta); name3 = GNUNET_PSEUDONYM_id_to_name (cfg, &id3); @@ -184,7 +184,7 @@ FAILURE: GNUNET_CONTAINER_meta_data_destroy (meta); GNUNET_CONFIGURATION_destroy (cfg); GNUNET_break (GNUNET_OK == - GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test")); + GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test")); return (ok == GNUNET_YES) ? 0 : 1; } diff --git a/src/util/test_resolver_api.c b/src/util/test_resolver_api.c index 24c71b41f..4e248aa72 100644 --- a/src/util/test_resolver_api.c +++ b/src/util/test_resolver_api.c @@ -46,13 +46,12 @@ check_hostname (void *cls, const struct sockaddr *sa, socklen_t salen) int *ok = cls; if (salen == 0) - { - (*ok) &= ~8; - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Got IP address `%s' for our host.\n"), GNUNET_a2s (sa, - salen)); + { + (*ok) &= ~8; + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Got IP address `%s' for our host.\n"), + GNUNET_a2s (sa, salen)); } @@ -64,21 +63,21 @@ check_localhost_num (void *cls, const char *hostname) if (hostname == NULL) return; if (0 == strcmp (hostname, "127.0.0.1")) - { + { #if DEBUG_RESOLVER - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received correct hostname `%s'.\n", hostname); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct hostname `%s'.\n", + hostname); #endif - (*ok) &= ~4; - } + (*ok) &= ~4; + } else - { + { #if DEBUG_RESOLVER - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received invalid hostname `%s'.\n", hostname); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received invalid hostname `%s'.\n", + hostname); #endif - GNUNET_break (0); - } + GNUNET_break (0); + } } @@ -90,19 +89,19 @@ check_localhost (void *cls, const char *hostname) if (hostname == NULL) return; if (0 == strcmp (hostname, "localhost")) - { + { #if DEBUG_RESOLVER - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received correct hostname `%s'.\n", hostname); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct hostname `%s'.\n", + hostname); #endif - (*ok) &= ~2; - } + (*ok) &= ~2; + } else - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Received unexpected hostname `%s', expected `localhost' (this could be OK).\n", - hostname); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Received unexpected hostname `%s', expected `localhost' (this could be OK).\n", + hostname); + } } static void @@ -115,19 +114,19 @@ check_127 (void *cls, const struct sockaddr *sa, socklen_t salen) return; GNUNET_assert (sizeof (struct sockaddr_in) == salen); if (sai->sin_addr.s_addr == htonl (INADDR_LOOPBACK)) - { + { #if DEBUG_RESOLVER - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct address.\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct address.\n"); #endif - (*ok) &= ~1; - } + (*ok) &= ~1; + } else - { + { #if DEBUG_RESOLVER - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received incorrect address.\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received incorrect address.\n"); #endif - GNUNET_break (0); - } + GNUNET_break (0); + } } static void @@ -139,32 +138,32 @@ check_local_fqdn (void *cls, const char *gnunet_fqdn) char hostname[GNUNET_OS_get_hostname_max_length () + 1]; if (0 != gethostname (hostname, sizeof (hostname) - 1)) - { - GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "gethostname"); - return; - } + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "gethostname"); + return; + } #if DEBUG_RESOLVER GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolving our FQDN `%s'\n"), - hostname); + hostname); #endif host = gethostbyname (hostname); if (NULL == host) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Could not resolve our FQDN : %s %u\n"), - hstrerror (h_errno), h_errno); - return; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Could not resolve our FQDN : %s %u\n"), hstrerror (h_errno), + h_errno); + return; + } GNUNET_assert (0 != host); result = strcmp (host->h_name, gnunet_fqdn); if (0 != result) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Local resolved and resolver resolved fqdns are not equal\n"); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Local resolved and resolver resolved fqdns are not equal\n"); + } GNUNET_assert (0 == result); } @@ -181,21 +180,21 @@ check_rootserver_ip (void *cls, const struct sockaddr *sa, socklen_t salen) GNUNET_assert (sizeof (struct sockaddr_in) == salen); if (0 == strcmp (inet_ntoa (sai->sin_addr), ROOTSERVER_IP)) - { + { #if DEBUG_RESOLVER - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received correct rootserver ip address.\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received correct rootserver ip address.\n"); #endif - (*ok) &= ~1; - } + (*ok) &= ~1; + } else - { + { #if DEBUG_RESOLVER - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received incorrect rootserver ip address.\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received incorrect rootserver ip address.\n"); #endif - GNUNET_break (0); - } + GNUNET_break (0); + } } static void @@ -207,21 +206,21 @@ check_rootserver_name (void *cls, const char *hostname) return; if (0 == strcmp (hostname, ROOTSERVER_NAME)) - { + { #if DEBUG_RESOLVER - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received correct rootserver hostname `%s'.\n", hostname); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received correct rootserver hostname `%s'.\n", hostname); #endif - (*ok) &= ~2; - } + (*ok) &= ~2; + } else - { + { #if DEBUG_RESOLVER - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received invalid rootserver hostname `%s'.\n", hostname); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received invalid rootserver hostname `%s'.\n", hostname); #endif - GNUNET_break (0); - } + GNUNET_break (0); + } } static void @@ -231,7 +230,7 @@ run (void *cls, char *const *args, const char *cfgfile, int *ok = cls; struct sockaddr_in sa; struct GNUNET_TIME_Relative timeout = - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); int count_ips = 0; char *own_fqdn; @@ -258,50 +257,50 @@ run (void *cls, char *const *args, const char *cfgfile, rootserver = gethostbyname (rootserver_name); if (rootserver == NULL) - { - /* Error: resolving ip addresses does not work */ + { + /* Error: resolving ip addresses does not work */ #if DEBUG_RESOLVER - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("gethostbyname() could not lookup IP address: %s\n"), - hstrerror (h_errno)); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + _("gethostbyname() could not lookup IP address: %s\n"), + hstrerror (h_errno)); #endif - fprintf (stderr, - "System seems to be off-line, will not run all DNS tests\n"); - *ok = 0; /* mark test as passing anyway */ - return; - } + fprintf (stderr, + "System seems to be off-line, will not run all DNS tests\n"); + *ok = 0; /* mark test as passing anyway */ + return; + } /* Counting returned IP addresses */ while (rootserver->h_addr_list[count_ips] != NULL) count_ips++; if (count_ips > 1) - { + { #if DEBUG_RESOLVER - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "IP received range for root name server, but a root name server has only 1 IP\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "IP received range for root name server, but a root name server has only 1 IP\n"); #endif - GNUNET_break (0); - } + GNUNET_break (0); + } /* Comparing to resolved address to the address the root name server should have */ if (strcmp (inet_ntoa (*(struct in_addr *) rootserver->h_addr_list[0]), ROOTSERVER_IP) != 0) - { + { #if DEBUG_RESOLVER - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "IP received and IP for root name server differ\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "IP received and IP for root name server differ\n"); #endif - GNUNET_break (0); - } + GNUNET_break (0); + } #if DEBUG_RESOLVER GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "System's own forward name resolution is working\n"); + "System's own forward name resolution is working\n"); #endif /* Resolve the same using GNUNET */ GNUNET_RESOLVER_ip_get (ROOTSERVER_NAME, AF_INET, timeout, - &check_rootserver_ip, cls); + &check_rootserver_ip, cls); /* * Success: forward lookups work as expected @@ -312,41 +311,41 @@ run (void *cls, char *const *args, const char *cfgfile, rootserver->h_name = ""; if (1 != inet_pton (AF_INET, ROOTSERVER_IP, &rootserver_addr)) - { + { #if DEBUG_RESOLVER - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Could not transform root name server IP address\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Could not transform root name server IP address\n"); #endif - GNUNET_break (0); - } + GNUNET_break (0); + } rootserver = - gethostbyaddr (&rootserver_addr, sizeof (rootserver_addr), AF_INET); + gethostbyaddr (&rootserver_addr, sizeof (rootserver_addr), AF_INET); if (rootserver == NULL) - { - /* Error: resolving IP addresses does not work */ + { + /* Error: resolving IP addresses does not work */ #if DEBUG_RESOLVER - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("gethostbyaddr() could not lookup hostname: %s\n"), - hstrerror (h_errno)); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + _("gethostbyaddr() could not lookup hostname: %s\n"), + hstrerror (h_errno)); #endif - GNUNET_break (0); - } + GNUNET_break (0); + } else + { + if (0 != strcmp (rootserver->h_name, ROOTSERVER_NAME)) { - if (0 != strcmp (rootserver->h_name, ROOTSERVER_NAME)) - { #if DEBUG_RESOLVER - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received hostname and hostname for root name server differ\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received hostname and hostname for root name server differ\n"); #endif - GNUNET_break (0); - } + GNUNET_break (0); } + } #if DEBUG_RESOLVER GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "System's own reverse name resolution is working\n"); + "System's own reverse name resolution is working\n"); #endif /* Resolve the same using GNUNET */ @@ -361,8 +360,8 @@ run (void *cls, char *const *args, const char *cfgfile, sa.sin_addr.S_un.S_addr = inet_addr (ROOTSERVER_IP); #endif GNUNET_RESOLVER_hostname_get ((const struct sockaddr *) &sa, - sizeof (struct sockaddr), GNUNET_YES, timeout, - &check_rootserver_name, cls); + sizeof (struct sockaddr), GNUNET_YES, timeout, + &check_rootserver_name, cls); memset (&sa, 0, sizeof (sa)); sa.sin_family = AF_INET; @@ -373,12 +372,12 @@ run (void *cls, char *const *args, const char *cfgfile, GNUNET_RESOLVER_ip_get ("localhost", AF_INET, timeout, &check_127, cls); GNUNET_RESOLVER_hostname_get ((const struct sockaddr *) &sa, - sizeof (struct sockaddr), GNUNET_YES, timeout, - &check_localhost, cls); + sizeof (struct sockaddr), GNUNET_YES, timeout, + &check_localhost, cls); GNUNET_RESOLVER_hostname_get ((const struct sockaddr *) &sa, - sizeof (struct sockaddr), GNUNET_NO, timeout, - &check_localhost_num, cls); + sizeof (struct sockaddr), GNUNET_NO, timeout, + &check_localhost_num, cls); GNUNET_RESOLVER_hostname_resolve (AF_UNSPEC, timeout, &check_hostname, cls); } @@ -392,33 +391,33 @@ check () struct GNUNET_OS_Process *proc; char *const argv[] = - { "test-resolver-api", "-c", "test_resolver_api_data.conf", + { "test-resolver-api", "-c", "test_resolver_api_data.conf", #if VERBOSE "-L", "DEBUG", #endif NULL }; struct GNUNET_GETOPT_CommandLineOption options[] = - { GNUNET_GETOPT_OPTION_END }; + { GNUNET_GETOPT_OPTION_END }; pfx = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR); GNUNET_asprintf (&fn, "%s%cgnunet-service-resolver", pfx, DIR_SEPARATOR); GNUNET_free (pfx); proc = GNUNET_OS_start_process (NULL, NULL, fn, "gnunet-service-resolver", #if VERBOSE - "-L", "DEBUG", + "-L", "DEBUG", #endif - "-c", "test_resolver_api_data.conf", NULL); + "-c", "test_resolver_api_data.conf", NULL); GNUNET_assert (NULL != proc); GNUNET_free (fn); GNUNET_assert (GNUNET_OK == - GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, - argv, "test-resolver-api", "nohelp", - options, &run, &ok)); + GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, + argv, "test-resolver-api", "nohelp", + options, &run, &ok)); if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) - { - GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - ok = 1; - } + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); + ok = 1; + } GNUNET_OS_process_wait (proc); GNUNET_OS_process_close (proc); proc = NULL; @@ -434,11 +433,11 @@ main (int argc, char *argv[]) GNUNET_log_setup ("test-resolver-api", #if VERBOSE - "DEBUG", + "DEBUG", #else - "WARNING", + "WARNING", #endif - NULL); + NULL); ret = check (); return ret; diff --git a/src/util/test_scheduler.c b/src/util/test_scheduler.c index e2a28c1b7..788ba13fa 100644 --- a/src/util/test_scheduler.c +++ b/src/util/test_scheduler.c @@ -36,7 +36,7 @@ task3 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) /* t4 should be ready (albeit with lower priority) */ GNUNET_assert (1 == - GNUNET_SCHEDULER_get_load (GNUNET_SCHEDULER_PRIORITY_COUNT)); + GNUNET_SCHEDULER_get_load (GNUNET_SCHEDULER_PRIORITY_COUNT)); GNUNET_assert (3 == *ok); (*ok) = 4; } @@ -51,7 +51,7 @@ task2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) (*ok) = 3; /* t3 will go before t4: higher priority */ GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI, &task3, - cls); + cls); } static void @@ -106,8 +106,8 @@ taskRd (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, fds[0])); GNUNET_assert (1 == GNUNET_DISK_file_read (fds[0], &c, 1)); (*ok) = 8; - GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, - &taskLast, cls); + GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, &taskLast, + cls); GNUNET_SCHEDULER_shutdown (); } @@ -123,10 +123,10 @@ task5 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_assert (NULL != p); fds[0] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_READ); fds[1] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_WRITE); - GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, fds[0], - &taskRd, cls); + GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, fds[0], &taskRd, + cls); GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, fds[1], - &taskWrt, cls); + &taskWrt, cls); } @@ -226,7 +226,7 @@ taskCancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_assert (1 == *ok); *ok = 0; GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_add_after - (GNUNET_SCHEDULER_NO_TASK, &taskNeverRun, NULL)); + (GNUNET_SCHEDULER_NO_TASK, &taskNeverRun, NULL)); } diff --git a/src/util/test_scheduler_delay.c b/src/util/test_scheduler_delay.c index 20783da8d..ff6966a87 100644 --- a/src/util/test_scheduler_delay.c +++ b/src/util/test_scheduler_delay.c @@ -57,17 +57,17 @@ test_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) else cumDelta += (target.abs_value - now.abs_value); target = - GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_MILLISECONDS, i)); + GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_MILLISECONDS, i)); fprintf (stderr, "."); if (i > MAXV) - { - fprintf (stderr, "\n"); - return; - } + { + fprintf (stderr, "\n"); + return; + } GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_MILLISECONDS, i), - &test_task, NULL); + (GNUNET_TIME_UNIT_MILLISECONDS, i), &test_task, + NULL); i += INCR; } @@ -77,10 +77,10 @@ check () target = GNUNET_TIME_absolute_get (); GNUNET_SCHEDULER_run (&test_task, NULL); FPRINTF (stdout, "Sleep precision: %llu ms. ", - cumDelta / 1000 / (MAXV / INCR)); + cumDelta / 1000 / (MAXV / INCR)); if (cumDelta <= 10 * MAXV / INCR) fprintf (stdout, "Timer precision is excellent.\n"); - else if (cumDelta <= 50 * MAXV / INCR) /* 50 ms average deviation */ + else if (cumDelta <= 50 * MAXV / INCR) /* 50 ms average deviation */ fprintf (stdout, "Timer precision is good.\n"); else if (cumDelta > 250 * MAXV / INCR) fprintf (stdout, "Timer precision is awful.\n"); diff --git a/src/util/test_server.c b/src/util/test_server.c index 8adde5346..625829042 100644 --- a/src/util/test_server.c +++ b/src/util/test_server.c @@ -61,7 +61,7 @@ finish_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static void recv_fin_cb (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) + const struct GNUNET_MessageHeader *message) { GNUNET_assert (ok == 5); ok = 6; @@ -98,20 +98,19 @@ reply_msg (void *cls, size_t size, void *buf) static void recv_cb (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) + const struct GNUNET_MessageHeader *message) { GNUNET_assert (ok == 2); ok = 3; argclient = client; GNUNET_SERVER_client_keep (argclient); - GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == - ntohs (message->size)); + GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)); GNUNET_assert (MY_TYPE == ntohs (message->type)); GNUNET_assert (NULL != - GNUNET_SERVER_notify_transmit_ready (client, - ntohs (message->size), - TIMEOUT, &reply_msg, - NULL)); + GNUNET_SERVER_notify_transmit_ready (client, + ntohs (message->size), + TIMEOUT, &reply_msg, + NULL)); } @@ -139,7 +138,7 @@ static size_t transmit_initial_message (void *cls, size_t size, void *buf) { struct GNUNET_MessageHeader msg; - + GNUNET_assert (ok == 1); ok = 2; GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); @@ -147,12 +146,12 @@ transmit_initial_message (void *cls, size_t size, void *buf) msg.size = htons (sizeof (struct GNUNET_MessageHeader)); memcpy (buf, &msg, sizeof (struct GNUNET_MessageHeader)); GNUNET_assert (NULL != - GNUNET_CLIENT_notify_transmit_ready (cc, - sizeof (struct - GNUNET_MessageHeader), - TIMEOUT, GNUNET_YES, - &transmit_second_message, - NULL)); + GNUNET_CLIENT_notify_transmit_ready (cc, + sizeof (struct + GNUNET_MessageHeader), + TIMEOUT, GNUNET_YES, + &transmit_second_message, + NULL)); GNUNET_CLIENT_receive (cc, &first_reply_handler, NULL, TIMEOUT); return sizeof (struct GNUNET_MessageHeader); } @@ -181,18 +180,18 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) cfg = GNUNET_CONFIGURATION_create (); GNUNET_CONFIGURATION_set_value_number (cfg, "test-server", "PORT", PORT); GNUNET_CONFIGURATION_set_value_string (cfg, "test-server", "HOSTNAME", - "localhost"); + "localhost"); GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", - "localhost"); + "localhost"); cc = GNUNET_CLIENT_connect ("test-server", cfg); GNUNET_assert (cc != NULL); GNUNET_assert (NULL != - GNUNET_CLIENT_notify_transmit_ready (cc, - sizeof (struct - GNUNET_MessageHeader), - TIMEOUT, GNUNET_YES, - &transmit_initial_message, - NULL)); + GNUNET_CLIENT_notify_transmit_ready (cc, + sizeof (struct + GNUNET_MessageHeader), + TIMEOUT, GNUNET_YES, + &transmit_initial_message, + NULL)); } diff --git a/src/util/test_server_disconnect.c b/src/util/test_server_disconnect.c index e38840d92..69207f81a 100644 --- a/src/util/test_server_disconnect.c +++ b/src/util/test_server_disconnect.c @@ -81,14 +81,13 @@ server_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static void recv_cb (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) + const struct GNUNET_MessageHeader *message) { GNUNET_assert (ok == 2); ok = 3; GNUNET_SERVER_client_keep (client); GNUNET_SCHEDULER_add_now (&server_disconnect, client); - GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == - ntohs (message->size)); + GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)); GNUNET_assert (MY_TYPE == ntohs (message->type)); GNUNET_SERVER_receive_done (client, GNUNET_OK); } @@ -139,18 +138,18 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) cfg = GNUNET_CONFIGURATION_create (); GNUNET_CONFIGURATION_set_value_number (cfg, "test-server", "PORT", PORT); GNUNET_CONFIGURATION_set_value_string (cfg, "test-server", "HOSTNAME", - "localhost"); + "localhost"); GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", - "localhost"); + "localhost"); cc = GNUNET_CLIENT_connect ("test-server", cfg); GNUNET_assert (cc != NULL); GNUNET_assert (NULL != - GNUNET_CLIENT_notify_transmit_ready (cc, - sizeof (struct - GNUNET_MessageHeader), - TIMEOUT, GNUNET_YES, - &transmit_initial_message, - NULL)); + GNUNET_CLIENT_notify_transmit_ready (cc, + sizeof (struct + GNUNET_MessageHeader), + TIMEOUT, GNUNET_YES, + &transmit_initial_message, + NULL)); } diff --git a/src/util/test_server_with_client.c b/src/util/test_server_with_client.c index 21c706b07..5b6e51718 100644 --- a/src/util/test_server_with_client.c +++ b/src/util/test_server_with_client.c @@ -58,7 +58,7 @@ send_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static void recv_cb (void *cls, struct GNUNET_SERVER_Client *argclient, - const struct GNUNET_MessageHeader *message) + const struct GNUNET_MessageHeader *message) { void *addr; size_t addrlen; @@ -66,8 +66,7 @@ recv_cb (void *cls, struct GNUNET_SERVER_Client *argclient, struct sockaddr_in *have; GNUNET_assert (GNUNET_OK == - GNUNET_SERVER_client_get_address (argclient, &addr, - &addrlen)); + GNUNET_SERVER_client_get_address (argclient, &addr, &addrlen)); GNUNET_assert (addrlen == sizeof (struct sockaddr_in)); have = addr; @@ -81,21 +80,21 @@ recv_cb (void *cls, struct GNUNET_SERVER_Client *argclient, GNUNET_assert (0 == memcmp (&sa, addr, addrlen)); GNUNET_free (addr); switch (ok) - { - case 2: - ok++; - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_MILLISECONDS, 50), - &send_done, argclient); - break; - case 4: - ok++; - GNUNET_CLIENT_disconnect (client, GNUNET_YES); - GNUNET_SERVER_receive_done (argclient, GNUNET_OK); - break; - default: - GNUNET_assert (0); - } + { + case 2: + ok++; + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_MILLISECONDS, 50), + &send_done, argclient); + break; + case 4: + ok++; + GNUNET_CLIENT_disconnect (client, GNUNET_YES); + GNUNET_SERVER_receive_done (argclient, GNUNET_OK); + break; + default: + GNUNET_assert (0); + } } @@ -170,25 +169,24 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) sa.sin_family = AF_INET; sa.sin_port = htons (PORT); server = - GNUNET_SERVER_create (NULL, NULL, sap, slens, - GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_MILLISECONDS, 250), GNUNET_NO); + GNUNET_SERVER_create (NULL, NULL, sap, slens, + GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_MILLISECONDS, 250), GNUNET_NO); GNUNET_assert (server != NULL); handlers[0].callback_cls = cls; GNUNET_SERVER_add_handlers (server, handlers); GNUNET_SERVER_disconnect_notify (server, ¬ify_disconnect, cls); cfg = GNUNET_CONFIGURATION_create (); GNUNET_CONFIGURATION_set_value_number (cfg, "test", "PORT", PORT); - GNUNET_CONFIGURATION_set_value_string (cfg, "test", "HOSTNAME", - "localhost"); + GNUNET_CONFIGURATION_set_value_string (cfg, "test", "HOSTNAME", "localhost"); GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", - "localhost"); + "localhost"); client = GNUNET_CLIENT_connect ("test", cfg); GNUNET_assert (client != NULL); GNUNET_CLIENT_notify_transmit_ready (client, 256, - GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_MILLISECONDS, 250), - GNUNET_NO, ¬ify_ready, NULL); + GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_MILLISECONDS, 250), + GNUNET_NO, ¬ify_ready, NULL); } @@ -213,11 +211,11 @@ main (int argc, char *argv[]) GNUNET_log_setup ("test_server_with_client", #if VERBOSE - "DEBUG", + "DEBUG", #else - "WARNING", + "WARNING", #endif - NULL); + NULL); ret += check (); return ret; diff --git a/src/util/test_server_with_client_unix.c b/src/util/test_server_with_client_unix.c index 11f731243..4f80f188c 100644 --- a/src/util/test_server_with_client_unix.c +++ b/src/util/test_server_with_client_unix.c @@ -56,24 +56,24 @@ send_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static void recv_cb (void *cls, struct GNUNET_SERVER_Client *argclient, - const struct GNUNET_MessageHeader *message) + const struct GNUNET_MessageHeader *message) { switch (ok) - { - case 2: - ok++; - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_MILLISECONDS, 50), - &send_done, argclient); - break; - case 4: - ok++; - GNUNET_CLIENT_disconnect (client, GNUNET_YES); - GNUNET_SERVER_receive_done (argclient, GNUNET_OK); - break; - default: - GNUNET_assert (0); - } + { + case 2: + ok++; + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_MILLISECONDS, 50), + &send_done, argclient); + break; + case 4: + ok++; + GNUNET_CLIENT_disconnect (client, GNUNET_YES); + GNUNET_SERVER_receive_done (argclient, GNUNET_OK); + break; + default: + GNUNET_assert (0); + } } @@ -156,9 +156,9 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) sap[1] = NULL; slens[1] = 0; server = - GNUNET_SERVER_create (NULL, NULL, sap, slens, - GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_MILLISECONDS, 250), GNUNET_NO); + GNUNET_SERVER_create (NULL, NULL, sap, slens, + GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_MILLISECONDS, 250), GNUNET_NO); GNUNET_assert (server != NULL); handlers[0].callback_cls = cls; GNUNET_SERVER_add_handlers (server, handlers); @@ -167,14 +167,14 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_CONFIGURATION_set_value_string (cfg, "test", "UNIXPATH", unixpath); GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", - "localhost"); + "localhost"); client = GNUNET_CLIENT_connect ("test", cfg); GNUNET_assert (client != NULL); GNUNET_CLIENT_notify_transmit_ready (client, 256, - GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_MILLISECONDS, 250), - GNUNET_NO, ¬ify_ready, NULL); + GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_MILLISECONDS, 250), + GNUNET_NO, ¬ify_ready, NULL); } @@ -199,11 +199,11 @@ main (int argc, char *argv[]) GNUNET_log_setup ("test_server_with_client_unix", #if VERBOSE - "DEBUG", + "DEBUG", #else - "WARNING", + "WARNING", #endif - NULL); + NULL); ret += check (); return ret; diff --git a/src/util/test_service.c b/src/util/test_service.c index 33d69db10..1b78932f8 100644 --- a/src/util/test_service.c +++ b/src/util/test_service.c @@ -68,11 +68,11 @@ ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) client = GNUNET_CLIENT_connect ("test_service", cfg); GNUNET_assert (client != NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client connecting, waiting to transmit\n"); + "Client connecting, waiting to transmit\n"); GNUNET_CLIENT_notify_transmit_ready (client, - sizeof (struct GNUNET_MessageHeader), - GNUNET_TIME_UNIT_SECONDS, GNUNET_NO, - &build_msg, client); + sizeof (struct GNUNET_MessageHeader), + GNUNET_TIME_UNIT_SECONDS, GNUNET_NO, + &build_msg, client); } @@ -85,7 +85,7 @@ do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static void recv_cb (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) + const struct GNUNET_MessageHeader *message) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving client message...\n"); GNUNET_SERVER_receive_done (client, GNUNET_OK); @@ -105,12 +105,12 @@ static struct GNUNET_SERVER_MessageHandler myhandlers[] = { static void runner (void *cls, struct GNUNET_SERVER_Handle *server, - const struct GNUNET_CONFIGURATION_Handle *cfg) + const struct GNUNET_CONFIGURATION_Handle *cfg) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service initializing\n"); GNUNET_SERVER_add_handlers (server, myhandlers); GNUNET_CLIENT_service_test ("test_service", cfg, GNUNET_TIME_UNIT_SECONDS, - &ready, (void *) cfg); + &ready, (void *) cfg); } @@ -136,9 +136,8 @@ check () }; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting service\n"); GNUNET_assert (GNUNET_OK == - GNUNET_SERVICE_run (5, argv, "test_service", - GNUNET_SERVICE_OPTION_NONE, &runner, - &ok)); + GNUNET_SERVICE_run (5, argv, "test_service", + GNUNET_SERVICE_OPTION_NONE, &runner, &ok)); GNUNET_assert (0 == ok); return ok; } @@ -155,19 +154,19 @@ ready6 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_assert (client != NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "V6 client connected\n"); GNUNET_CLIENT_notify_transmit_ready (client, - sizeof (struct GNUNET_MessageHeader), - GNUNET_TIME_UNIT_SECONDS, GNUNET_NO, - &build_msg, client); + sizeof (struct GNUNET_MessageHeader), + GNUNET_TIME_UNIT_SECONDS, GNUNET_NO, + &build_msg, client); } static void runner6 (void *cls, struct GNUNET_SERVER_Handle *server, - const struct GNUNET_CONFIGURATION_Handle *cfg) + const struct GNUNET_CONFIGURATION_Handle *cfg) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initializing v6 service\n"); GNUNET_SERVER_add_handlers (server, myhandlers); GNUNET_CLIENT_service_test ("test_service6", cfg, GNUNET_TIME_UNIT_SECONDS, - &ready6, (void *) cfg); + &ready6, (void *) cfg); } /** @@ -191,9 +190,9 @@ check6 () }; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting v6 service\n"); GNUNET_assert (GNUNET_OK == - GNUNET_SERVICE_run (5, argv, "test_service6", - GNUNET_SERVICE_OPTION_NONE, &runner6, - &ok)); + GNUNET_SERVICE_run (5, argv, "test_service6", + GNUNET_SERVICE_OPTION_NONE, &runner6, + &ok)); GNUNET_assert (0 == ok); return ok; } @@ -202,12 +201,11 @@ check6 () static void start_stop_main (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) + const struct GNUNET_CONFIGURATION_Handle *cfg) { int *ret = cls; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Starting service using start method\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting service using start method\n"); sctx = GNUNET_SERVICE_start ("test_service", cfg); GNUNET_assert (NULL != sctx); runner (cls, GNUNET_SERVICE_get_server (sctx), cfg); @@ -236,9 +234,8 @@ check_start_stop () int ret = 1; GNUNET_assert (GNUNET_OK == - GNUNET_PROGRAM_run (5, argv, "test-service-program", - "no help", options, &start_stop_main, - &ret)); + GNUNET_PROGRAM_run (5, argv, "test-service-program", "no help", + options, &start_stop_main, &ret)); GNUNET_break (0 == ret); return ret; @@ -253,11 +250,11 @@ main (int argc, char *argv[]) GNUNET_log_setup ("test-service", #if VERBOSE - "DEBUG", + "DEBUG", #else - "WARNING", + "WARNING", #endif - NULL); + NULL); ret += check (); ret += check (); @@ -266,22 +263,22 @@ main (int argc, char *argv[]) s = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0); #endif if (NULL == s) + { + if ((errno == ENOBUFS) || (errno == ENOMEM) || (errno == ENFILE) || + (errno == EACCES)) { - if ((errno == ENOBUFS) || (errno == ENOMEM) || (errno == ENFILE) || - (errno == EACCES)) - { - GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); - return 1; - } - fprintf (stderr, - "IPv6 support seems to not be available (%s), not testing it!\n", - strerror (errno)); + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); + return 1; } + fprintf (stderr, + "IPv6 support seems to not be available (%s), not testing it!\n", + strerror (errno)); + } else - { - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); - ret += check6 (); - } + { + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); + ret += check6 (); + } ret += check_start_stop (); return ret; diff --git a/src/util/test_strings.c b/src/util/test_strings.c index bb0e6088f..c6d604144 100644 --- a/src/util/test_strings.c +++ b/src/util/test_strings.c @@ -50,18 +50,18 @@ check () WANT (buf, b); sprintf (buf, "4 %s", _( /* time unit */ "ms")); b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_MILLISECONDS, - 4)); + (GNUNET_TIME_UNIT_MILLISECONDS, + 4)); WANT (buf, b); sprintf (buf, "7 %s", _( /* time unit */ "s")); b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_MILLISECONDS, - 7 * 1000)); + (GNUNET_TIME_UNIT_MILLISECONDS, + 7 * 1000)); WANT (buf, b); sprintf (buf, "7 %s", _( /* time unit */ "h")); b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_MILLISECONDS, - 7 * 60 * 60 * 1000)); + (GNUNET_TIME_UNIT_MILLISECONDS, + 7 * 60 * 60 * 1000)); WANT (buf, b); #ifndef MINGW hdir = getenv ("HOME"); @@ -88,12 +88,12 @@ check () * where the details of the day and hour depend on the timezone; * however, the "0:05 19" should always be there; hence: */ if (NULL == strstr (r, "0:05 19")) - { - fprintf (stderr, "Got %s\n", r); - GNUNET_break (0); - GNUNET_free (r); - return 1; - } + { + fprintf (stderr, "Got %s\n", r); + GNUNET_break (0); + GNUNET_free (r); + return 1; + } GNUNET_free (r); b = GNUNET_STRINGS_to_utf8 ("TEST", 4, "ASCII"); WANT ("TEST", b); diff --git a/src/util/test_time.c b/src/util/test_time.c index 80109615a..c5232ff2a 100644 --- a/src/util/test_time.c +++ b/src/util/test_time.c @@ -63,7 +63,7 @@ check () /*check zero */ rel.rel_value = (UINT64_MAX) - 1024; GNUNET_assert (GNUNET_TIME_relative_get_zero ().rel_value == - GNUNET_TIME_relative_multiply (rel, 0).rel_value); + GNUNET_TIME_relative_multiply (rel, 0).rel_value); /* test infinity-check for relative to absolute */ GNUNET_log_skip (1, GNUNET_NO); @@ -74,11 +74,11 @@ check () /*check relative to absolute */ rel.rel_value = 0; GNUNET_assert (GNUNET_TIME_absolute_get ().abs_value == - GNUNET_TIME_relative_to_absolute (rel).abs_value); + GNUNET_TIME_relative_to_absolute (rel).abs_value); /*check forever */ rel.rel_value = UINT64_MAX; GNUNET_assert (GNUNET_TIME_absolute_get_forever ().abs_value == - GNUNET_TIME_relative_to_absolute (rel).abs_value); + GNUNET_TIME_relative_to_absolute (rel).abs_value); /* check overflow for r2a */ rel.rel_value = (UINT64_MAX) - 1024; GNUNET_log_skip (1, GNUNET_NO); @@ -103,13 +103,13 @@ check () /* check relation check in get_duration */ future.abs_value = now.abs_value + 1000000; - GNUNET_assert (GNUNET_TIME_absolute_get_difference (now, future).rel_value - == 1000000); - GNUNET_assert (GNUNET_TIME_absolute_get_difference (future, now).rel_value - == 0); + GNUNET_assert (GNUNET_TIME_absolute_get_difference (now, future).rel_value == + 1000000); + GNUNET_assert (GNUNET_TIME_absolute_get_difference (future, now).rel_value == + 0); GNUNET_assert (GNUNET_TIME_absolute_get_difference (zero, forever).rel_value - == forever.abs_value); + == forever.abs_value); past.abs_value = now.abs_value - 1000000; rel = GNUNET_TIME_absolute_get_duration (future); @@ -127,7 +127,7 @@ check () GNUNET_assert (rel.rel_value <= 1000000); forever = GNUNET_TIME_absolute_get_forever (); GNUNET_assert (GNUNET_TIME_relative_get_forever ().rel_value == - GNUNET_TIME_absolute_get_remaining (forever).rel_value); + GNUNET_TIME_absolute_get_remaining (forever).rel_value); /* check endianess */ reln = GNUNET_TIME_relative_hton (rel); @@ -152,24 +152,23 @@ check () GNUNET_assert (future.abs_value == now.abs_value); GNUNET_assert (forever.abs_value == - GNUNET_TIME_absolute_subtract (forever, - GNUNET_TIME_UNIT_MINUTES).abs_value); + GNUNET_TIME_absolute_subtract (forever, + GNUNET_TIME_UNIT_MINUTES).abs_value); /*check absolute subtract */ now.abs_value = 50000; rel.rel_value = 100000; GNUNET_assert (GNUNET_TIME_UNIT_ZERO_ABS.abs_value == - (GNUNET_TIME_absolute_subtract (now, rel)).abs_value); + (GNUNET_TIME_absolute_subtract (now, rel)).abs_value); rel.rel_value = 10000; - GNUNET_assert (40000 == - (GNUNET_TIME_absolute_subtract (now, rel)).abs_value); + GNUNET_assert (40000 == (GNUNET_TIME_absolute_subtract (now, rel)).abs_value); /*check relative divide */ GNUNET_assert (GNUNET_TIME_UNIT_FOREVER_REL.rel_value == - (GNUNET_TIME_relative_divide (rel, 0)).rel_value); + (GNUNET_TIME_relative_divide (rel, 0)).rel_value); rel = GNUNET_TIME_UNIT_FOREVER_REL; GNUNET_assert (GNUNET_TIME_UNIT_FOREVER_REL.rel_value == - (GNUNET_TIME_relative_divide (rel, 2)).rel_value); + (GNUNET_TIME_relative_divide (rel, 2)).rel_value); rel = GNUNET_TIME_relative_divide (relUnit, 2); GNUNET_assert (rel.rel_value == relUnit.rel_value / 2); @@ -183,51 +182,50 @@ check () forever = GNUNET_TIME_absolute_get_forever (); forever.abs_value = forever.abs_value - 1024; GNUNET_assert (GNUNET_TIME_absolute_get_zero ().abs_value == - GNUNET_TIME_calculate_eta (forever, 50000, - 100000).rel_value); + GNUNET_TIME_calculate_eta (forever, 50000, 100000).rel_value); /* check zero */ GNUNET_log_skip (1, GNUNET_NO); GNUNET_assert (GNUNET_TIME_UNIT_ZERO.rel_value == - (GNUNET_TIME_calculate_eta (last, 60000, 50000)).rel_value); + (GNUNET_TIME_calculate_eta (last, 60000, 50000)).rel_value); GNUNET_log_skip (0, GNUNET_YES); /*check forever */ GNUNET_assert (GNUNET_TIME_UNIT_FOREVER_REL.rel_value == - (GNUNET_TIME_calculate_eta (last, 0, 50000)).rel_value); + (GNUNET_TIME_calculate_eta (last, 0, 50000)).rel_value); /*check relative subtract */ now = GNUNET_TIME_absolute_get (); rel.rel_value = now.abs_value; relForever.rel_value = rel.rel_value + 1024; GNUNET_assert (1024 == - GNUNET_TIME_relative_subtract (relForever, rel).rel_value); + GNUNET_TIME_relative_subtract (relForever, rel).rel_value); /*check zero */ GNUNET_assert (GNUNET_TIME_relative_get_zero ().rel_value == - GNUNET_TIME_relative_subtract (rel, relForever).rel_value); + GNUNET_TIME_relative_subtract (rel, relForever).rel_value); /*check forever */ rel.rel_value = UINT64_MAX; GNUNET_assert (GNUNET_TIME_relative_get_forever ().rel_value == - GNUNET_TIME_relative_subtract (rel, relForever).rel_value); + GNUNET_TIME_relative_subtract (rel, relForever).rel_value); /*check GNUNET_TIME_relative_min */ now = GNUNET_TIME_absolute_get (); rel.rel_value = now.abs_value; relForever.rel_value = rel.rel_value - 1024; GNUNET_assert (relForever.rel_value == - GNUNET_TIME_relative_min (rel, relForever).rel_value); + GNUNET_TIME_relative_min (rel, relForever).rel_value); /*check GNUNET_TIME_relative_max */ GNUNET_assert (rel.rel_value == - GNUNET_TIME_relative_max (rel, relForever).rel_value); + GNUNET_TIME_relative_max (rel, relForever).rel_value); /*check GNUNET_TIME_absolute_min */ now = GNUNET_TIME_absolute_get (); last.abs_value = now.abs_value - 1024; GNUNET_assert (last.abs_value == - GNUNET_TIME_absolute_min (now, last).abs_value); + GNUNET_TIME_absolute_min (now, last).abs_value); /*check GNUNET_TIME_absolute_max */ GNUNET_assert (now.abs_value == - GNUNET_TIME_absolute_max (now, last).abs_value); + GNUNET_TIME_absolute_max (now, last).abs_value); return 0; } diff --git a/src/util/time.c b/src/util/time.c index e48377fa3..3ee15516a 100644 --- a/src/util/time.c +++ b/src/util/time.c @@ -55,8 +55,8 @@ GNUNET_TIME_absolute_get () GETTIMEOFDAY (&tv, NULL); ret.abs_value = - (uint64_t) (((uint64_t) tv.tv_sec * 1000LL) + - ((uint64_t) tv.tv_usec / 1000LL)) + timestamp_offset; + (uint64_t) (((uint64_t) tv.tv_sec * 1000LL) + + ((uint64_t) tv.tv_usec / 1000LL)) + timestamp_offset; return ret; } @@ -130,10 +130,10 @@ GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel) struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); if (rel.rel_value + now.abs_value < rel.rel_value) - { - GNUNET_break (0); /* overflow... */ - return GNUNET_TIME_absolute_get_forever (); - } + { + GNUNET_break (0); /* overflow... */ + return GNUNET_TIME_absolute_get_forever (); + } ret.abs_value = rel.rel_value + now.abs_value; return ret; } @@ -148,7 +148,7 @@ GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel) */ struct GNUNET_TIME_Relative GNUNET_TIME_relative_min (struct GNUNET_TIME_Relative t1, - struct GNUNET_TIME_Relative t2) + struct GNUNET_TIME_Relative t2) { return (t1.rel_value < t2.rel_value) ? t1 : t2; } @@ -163,7 +163,7 @@ GNUNET_TIME_relative_min (struct GNUNET_TIME_Relative t1, */ struct GNUNET_TIME_Relative GNUNET_TIME_relative_max (struct GNUNET_TIME_Relative t1, - struct GNUNET_TIME_Relative t2) + struct GNUNET_TIME_Relative t2) { return (t1.rel_value > t2.rel_value) ? t1 : t2; } @@ -179,7 +179,7 @@ GNUNET_TIME_relative_max (struct GNUNET_TIME_Relative t1, */ struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_min (struct GNUNET_TIME_Absolute t1, - struct GNUNET_TIME_Absolute t2) + struct GNUNET_TIME_Absolute t2) { return (t1.abs_value < t2.abs_value) ? t1 : t2; } @@ -194,7 +194,7 @@ GNUNET_TIME_absolute_min (struct GNUNET_TIME_Absolute t1, */ struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_max (struct GNUNET_TIME_Absolute t1, - struct GNUNET_TIME_Absolute t2) + struct GNUNET_TIME_Absolute t2) { return (t1.abs_value > t2.abs_value) ? t1 : t2; } @@ -230,7 +230,7 @@ GNUNET_TIME_absolute_get_remaining (struct GNUNET_TIME_Absolute future) */ struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_difference (struct GNUNET_TIME_Absolute start, - struct GNUNET_TIME_Absolute end) + struct GNUNET_TIME_Absolute end) { struct GNUNET_TIME_Relative ret; @@ -271,17 +271,17 @@ GNUNET_TIME_absolute_get_duration (struct GNUNET_TIME_Absolute whence) */ struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add (struct GNUNET_TIME_Absolute start, - struct GNUNET_TIME_Relative duration) + struct GNUNET_TIME_Relative duration) { struct GNUNET_TIME_Absolute ret; if ((start.abs_value == UINT64_MAX) || (duration.rel_value == UINT64_MAX)) return GNUNET_TIME_absolute_get_forever (); if (start.abs_value + duration.rel_value < start.abs_value) - { - GNUNET_break (0); - return GNUNET_TIME_absolute_get_forever (); - } + { + GNUNET_break (0); + return GNUNET_TIME_absolute_get_forever (); + } ret.abs_value = start.abs_value + duration.rel_value; return ret; } @@ -297,7 +297,7 @@ GNUNET_TIME_absolute_add (struct GNUNET_TIME_Absolute start, */ struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_subtract (struct GNUNET_TIME_Absolute start, - struct GNUNET_TIME_Relative duration) + struct GNUNET_TIME_Relative duration) { struct GNUNET_TIME_Absolute ret; @@ -317,7 +317,7 @@ GNUNET_TIME_absolute_subtract (struct GNUNET_TIME_Absolute start, */ struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel, - unsigned int factor) + unsigned int factor) { struct GNUNET_TIME_Relative ret; @@ -325,10 +325,10 @@ GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel, return GNUNET_TIME_relative_get_zero (); ret.rel_value = rel.rel_value * (unsigned long long) factor; if (ret.rel_value / factor != rel.rel_value) - { - GNUNET_break (0); - return GNUNET_TIME_relative_get_forever (); - } + { + GNUNET_break (0); + return GNUNET_TIME_relative_get_forever (); + } return ret; } @@ -342,7 +342,7 @@ GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel, */ struct GNUNET_TIME_Relative GNUNET_TIME_relative_divide (struct GNUNET_TIME_Relative rel, - unsigned int factor) + unsigned int factor) { struct GNUNET_TIME_Relative ret; @@ -365,8 +365,8 @@ GNUNET_TIME_relative_divide (struct GNUNET_TIME_Relative rel, * assuming it continues at the same speed */ struct GNUNET_TIME_Relative -GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start, - uint64_t finished, uint64_t total) +GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start, uint64_t finished, + uint64_t total) { struct GNUNET_TIME_Relative dur; double exp; @@ -393,17 +393,17 @@ GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start, */ struct GNUNET_TIME_Relative GNUNET_TIME_relative_add (struct GNUNET_TIME_Relative a1, - struct GNUNET_TIME_Relative a2) + struct GNUNET_TIME_Relative a2) { struct GNUNET_TIME_Relative ret; if ((a1.rel_value == UINT64_MAX) || (a2.rel_value == UINT64_MAX)) return GNUNET_TIME_relative_get_forever (); if (a1.rel_value + a2.rel_value < a1.rel_value) - { - GNUNET_break (0); - return GNUNET_TIME_relative_get_forever (); - } + { + GNUNET_break (0); + return GNUNET_TIME_relative_get_forever (); + } ret.rel_value = a1.rel_value + a2.rel_value; return ret; } @@ -418,7 +418,7 @@ GNUNET_TIME_relative_add (struct GNUNET_TIME_Relative a1, */ struct GNUNET_TIME_Relative GNUNET_TIME_relative_subtract (struct GNUNET_TIME_Relative a1, - struct GNUNET_TIME_Relative a2) + struct GNUNET_TIME_Relative a2) { struct GNUNET_TIME_Relative ret; diff --git a/src/util/winproc.c b/src/util/winproc.c index aa4757f4a..252cacbfb 100644 --- a/src/util/winproc.c +++ b/src/util/winproc.c @@ -73,8 +73,7 @@ TSetNamedSecurityInfo GNSetNamedSecurityInfo; void plibc_panic (int err, char *msg) { - LOG (((err == - INT_MAX) ? GNUNET_ERROR_TYPE_DEBUG : GNUNET_ERROR_TYPE_ERROR), + LOG (((err == INT_MAX) ? GNUNET_ERROR_TYPE_DEBUG : GNUNET_ERROR_TYPE_ERROR), "%s", msg); } @@ -100,139 +99,137 @@ GNInitWinEnv () /* Function to get CPU usage under Win NT */ if (hNTDLL) - { - GNNtQuerySystemInformation = - (TNtQuerySystemInformation) GetProcAddress (hNTDLL, - "NtQuerySystemInformation"); - } + { + GNNtQuerySystemInformation = + (TNtQuerySystemInformation) GetProcAddress (hNTDLL, + "NtQuerySystemInformation"); + } else - { - GNNtQuerySystemInformation = NULL; - } + { + GNNtQuerySystemInformation = NULL; + } /* Functions to get information about a network adapter */ hIphlpapi = LoadLibrary ("iphlpapi.dll"); if (hIphlpapi) - { - GNGetIfEntry = (TGetIfEntry) GetProcAddress (hIphlpapi, "GetIfEntry"); - GNGetIpAddrTable = - (TGetIpAddrTable) GetProcAddress (hIphlpapi, "GetIpAddrTable"); - GNGetIfTable = (TGetIfTable) GetProcAddress (hIphlpapi, "GetIfTable"); - GNGetBestInterface = - (TGetBestInterface) GetProcAddress (hIphlpapi, "GetBestInterface"); - GGetAdaptersInfo = - (TGetAdaptersInfo) GetProcAddress (hIphlpapi, "GetAdaptersInfo"); - } + { + GNGetIfEntry = (TGetIfEntry) GetProcAddress (hIphlpapi, "GetIfEntry"); + GNGetIpAddrTable = + (TGetIpAddrTable) GetProcAddress (hIphlpapi, "GetIpAddrTable"); + GNGetIfTable = (TGetIfTable) GetProcAddress (hIphlpapi, "GetIfTable"); + GNGetBestInterface = + (TGetBestInterface) GetProcAddress (hIphlpapi, "GetBestInterface"); + GGetAdaptersInfo = + (TGetAdaptersInfo) GetProcAddress (hIphlpapi, "GetAdaptersInfo"); + } else - { - GNGetIfEntry = NULL; - GNGetIpAddrTable = NULL; - GNGetIfTable = NULL; - GNGetBestInterface = NULL; - GGetAdaptersInfo = NULL; - } + { + GNGetIfEntry = NULL; + GNGetIpAddrTable = NULL; + GNGetIfTable = NULL; + GNGetBestInterface = NULL; + GGetAdaptersInfo = NULL; + } /* Service & Account functions */ hAdvapi = LoadLibrary ("advapi32.dll"); if (hAdvapi) - { - GNOpenSCManager = - (TOpenSCManager) GetProcAddress (hAdvapi, "OpenSCManagerA"); - GNCreateService = - (TCreateService) GetProcAddress (hAdvapi, "CreateServiceA"); - GNCloseServiceHandle = - (TCloseServiceHandle) GetProcAddress (hAdvapi, "CloseServiceHandle"); - GNDeleteService = - (TDeleteService) GetProcAddress (hAdvapi, "DeleteService"); - GNRegisterServiceCtrlHandler = - (TRegisterServiceCtrlHandler) GetProcAddress (hAdvapi, - "RegisterServiceCtrlHandlerA"); - GNSetServiceStatus = - (TSetServiceStatus) GetProcAddress (hAdvapi, "SetServiceStatus"); - GNStartServiceCtrlDispatcher = - (TStartServiceCtrlDispatcher) GetProcAddress (hAdvapi, - "StartServiceCtrlDispatcherA"); - GNControlService = - (TControlService) GetProcAddress (hAdvapi, "ControlService"); - GNOpenService = (TOpenService) GetProcAddress (hAdvapi, "OpenServiceA"); + { + GNOpenSCManager = + (TOpenSCManager) GetProcAddress (hAdvapi, "OpenSCManagerA"); + GNCreateService = + (TCreateService) GetProcAddress (hAdvapi, "CreateServiceA"); + GNCloseServiceHandle = + (TCloseServiceHandle) GetProcAddress (hAdvapi, "CloseServiceHandle"); + GNDeleteService = + (TDeleteService) GetProcAddress (hAdvapi, "DeleteService"); + GNRegisterServiceCtrlHandler = + (TRegisterServiceCtrlHandler) GetProcAddress (hAdvapi, + "RegisterServiceCtrlHandlerA"); + GNSetServiceStatus = + (TSetServiceStatus) GetProcAddress (hAdvapi, "SetServiceStatus"); + GNStartServiceCtrlDispatcher = + (TStartServiceCtrlDispatcher) GetProcAddress (hAdvapi, + "StartServiceCtrlDispatcherA"); + GNControlService = + (TControlService) GetProcAddress (hAdvapi, "ControlService"); + GNOpenService = (TOpenService) GetProcAddress (hAdvapi, "OpenServiceA"); - GNLsaOpenPolicy = - (TLsaOpenPolicy) GetProcAddress (hAdvapi, "LsaOpenPolicy"); - GNLsaAddAccountRights = - (TLsaAddAccountRights) GetProcAddress (hAdvapi, - "LsaAddAccountRights"); - GNLsaRemoveAccountRights = - (TLsaRemoveAccountRights) GetProcAddress (hAdvapi, - "LsaRemoveAccountRights"); - GNLsaClose = (TLsaClose) GetProcAddress (hAdvapi, "LsaClose"); - GNLookupAccountName = - (TLookupAccountName) GetProcAddress (hAdvapi, "LookupAccountNameA"); + GNLsaOpenPolicy = + (TLsaOpenPolicy) GetProcAddress (hAdvapi, "LsaOpenPolicy"); + GNLsaAddAccountRights = + (TLsaAddAccountRights) GetProcAddress (hAdvapi, "LsaAddAccountRights"); + GNLsaRemoveAccountRights = + (TLsaRemoveAccountRights) GetProcAddress (hAdvapi, + "LsaRemoveAccountRights"); + GNLsaClose = (TLsaClose) GetProcAddress (hAdvapi, "LsaClose"); + GNLookupAccountName = + (TLookupAccountName) GetProcAddress (hAdvapi, "LookupAccountNameA"); - GNGetFileSecurity = - (TGetFileSecurity) GetProcAddress (hAdvapi, "GetFileSecurityA"); - GNInitializeSecurityDescriptor = - (TInitializeSecurityDescriptor) GetProcAddress (hAdvapi, - "InitializeSecurityDescriptor"); - GNGetSecurityDescriptorDacl = - (TGetSecurityDescriptorDacl) GetProcAddress (hAdvapi, - "GetSecurityDescriptorDacl"); - GNGetAclInformation = - (TGetAclInformation) GetProcAddress (hAdvapi, "GetAclInformation"); - GNInitializeAcl = - (TInitializeAcl) GetProcAddress (hAdvapi, "InitializeAcl"); - GNGetAce = (TGetAce) GetProcAddress (hAdvapi, "GetAce"); - GNEqualSid = (TEqualSid) GetProcAddress (hAdvapi, "EqualSid"); - GNAddAce = (TAddAce) GetProcAddress (hAdvapi, "AddAce"); - GNAddAccessAllowedAce = - (TAddAccessAllowedAce) GetProcAddress (hAdvapi, - "AddAccessAllowedAce"); - GNSetNamedSecurityInfo = - (TSetNamedSecurityInfo) GetProcAddress (hAdvapi, - "SetNamedSecurityInfoA"); - } + GNGetFileSecurity = + (TGetFileSecurity) GetProcAddress (hAdvapi, "GetFileSecurityA"); + GNInitializeSecurityDescriptor = + (TInitializeSecurityDescriptor) GetProcAddress (hAdvapi, + "InitializeSecurityDescriptor"); + GNGetSecurityDescriptorDacl = + (TGetSecurityDescriptorDacl) GetProcAddress (hAdvapi, + "GetSecurityDescriptorDacl"); + GNGetAclInformation = + (TGetAclInformation) GetProcAddress (hAdvapi, "GetAclInformation"); + GNInitializeAcl = + (TInitializeAcl) GetProcAddress (hAdvapi, "InitializeAcl"); + GNGetAce = (TGetAce) GetProcAddress (hAdvapi, "GetAce"); + GNEqualSid = (TEqualSid) GetProcAddress (hAdvapi, "EqualSid"); + GNAddAce = (TAddAce) GetProcAddress (hAdvapi, "AddAce"); + GNAddAccessAllowedAce = + (TAddAccessAllowedAce) GetProcAddress (hAdvapi, "AddAccessAllowedAce"); + GNSetNamedSecurityInfo = + (TSetNamedSecurityInfo) GetProcAddress (hAdvapi, + "SetNamedSecurityInfoA"); + } else - { - GNOpenSCManager = NULL; - GNCreateService = NULL; - GNCloseServiceHandle = NULL; - GNDeleteService = NULL; - GNRegisterServiceCtrlHandler = NULL; - GNSetServiceStatus = NULL; - GNStartServiceCtrlDispatcher = NULL; - GNControlService = NULL; - GNOpenService = NULL; + { + GNOpenSCManager = NULL; + GNCreateService = NULL; + GNCloseServiceHandle = NULL; + GNDeleteService = NULL; + GNRegisterServiceCtrlHandler = NULL; + GNSetServiceStatus = NULL; + GNStartServiceCtrlDispatcher = NULL; + GNControlService = NULL; + GNOpenService = NULL; - GNLsaOpenPolicy = NULL; - GNLsaAddAccountRights = NULL; - GNLsaRemoveAccountRights = NULL; - GNLsaClose = NULL; - GNLookupAccountName = NULL; + GNLsaOpenPolicy = NULL; + GNLsaAddAccountRights = NULL; + GNLsaRemoveAccountRights = NULL; + GNLsaClose = NULL; + GNLookupAccountName = NULL; - GNGetFileSecurity = NULL; - GNInitializeSecurityDescriptor = NULL; - GNGetSecurityDescriptorDacl = NULL; - GNGetAclInformation = NULL; - GNInitializeAcl = NULL; - GNGetAce = NULL; - GNEqualSid = NULL; - GNAddAce = NULL; - GNAddAccessAllowedAce = NULL; - GNSetNamedSecurityInfo = NULL; - } + GNGetFileSecurity = NULL; + GNInitializeSecurityDescriptor = NULL; + GNGetSecurityDescriptorDacl = NULL; + GNGetAclInformation = NULL; + GNInitializeAcl = NULL; + GNGetAce = NULL; + GNEqualSid = NULL; + GNAddAce = NULL; + GNAddAccessAllowedAce = NULL; + GNSetNamedSecurityInfo = NULL; + } /* Account function */ hNetapi = LoadLibrary ("netapi32.dll"); if (hNetapi) - { - GNNetUserAdd = (TNetUserAdd) GetProcAddress (hNetapi, "NetUserAdd"); - GNNetUserSetInfo = - (TNetUserSetInfo) GetProcAddress (hNetapi, "NetUserSetInfo"); - } + { + GNNetUserAdd = (TNetUserAdd) GetProcAddress (hNetapi, "NetUserAdd"); + GNNetUserSetInfo = + (TNetUserSetInfo) GetProcAddress (hNetapi, "NetUserSetInfo"); + } else - { - GNNetUserAdd = NULL; - GNNetUserSetInfo = NULL; - } + { + GNNetUserAdd = NULL; + GNNetUserSetInfo = NULL; + } return ret; } diff --git a/src/vpn/gnunet-daemon-exit.c b/src/vpn/gnunet-daemon-exit.c index 45076250d..838893882 100644 --- a/src/vpn/gnunet-daemon-exit.c +++ b/src/vpn/gnunet-daemon-exit.c @@ -199,24 +199,26 @@ cleanup (void *cls } static void * -new_tunnel (void *cls __attribute__((unused)), - struct GNUNET_MESH_Tunnel *tunnel, - const struct GNUNET_PeerIdentity *initiator __attribute__((unused)), - const struct GNUNET_ATS_Information *ats __attribute__((unused))) +new_tunnel (void *cls + __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel, + const struct GNUNET_PeerIdentity *initiator + __attribute__ ((unused)), const struct GNUNET_ATS_Information *ats + __attribute__ ((unused))) { - struct tunnel_state *s = GNUNET_malloc(sizeof *s); - s->head = NULL; - s->tail = NULL; - s->th = NULL; - return s; + struct tunnel_state *s = GNUNET_malloc (sizeof *s); + + s->head = NULL; + s->tail = NULL; + s->th = NULL; + return s; } static void -clean_tunnel (void *cls __attribute__((unused)), - const struct GNUNET_MESH_Tunnel *tunnel, +clean_tunnel (void *cls + __attribute__ ((unused)), const struct GNUNET_MESH_Tunnel *tunnel, void *tunnel_ctx) { - GNUNET_free(tunnel_ctx); + GNUNET_free (tunnel_ctx); } static void @@ -236,7 +238,8 @@ collect_connections (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) /* FIXME! GNUNET_MESH_close_tunnel(state->tunnel); */ GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_remove (state->hashmap, &state->hash, state)); + GNUNET_CONTAINER_multihashmap_remove (state->hashmap, + &state->hash, state)); GNUNET_free (state); } @@ -275,7 +278,7 @@ send_udp_to_peer_notify_callback (void *cls, size_t size, void *buf) memcpy (buf, hdr, ntohs (hdr->size)); size = ntohs (hdr->size); - struct tunnel_state *s = GNUNET_MESH_tunnel_get_data(*tunnel); + struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (*tunnel); if (NULL != s->head) { @@ -284,9 +287,7 @@ send_udp_to_peer_notify_callback (void *cls, size_t size, void *buf) GNUNET_CONTAINER_DLL_remove (s->head, s->tail, element); s->th = - GNUNET_MESH_notify_transmit_ready (*tunnel, - GNUNET_NO, - 42, + GNUNET_MESH_notify_transmit_ready (*tunnel, GNUNET_NO, 42, GNUNET_TIME_relative_divide (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), (const struct GNUNET_PeerIdentity *) @@ -394,14 +395,13 @@ udp_from_helper (struct udp_pkt *udp, unsigned char *dadr, size_t addrlen) memcpy (_udp, udp, ntohs (udp->len)); - struct tunnel_state *s = GNUNET_MESH_tunnel_get_data(tunnel); + struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (tunnel); + if (NULL == s->th) { /* No notify is pending */ s->th = - GNUNET_MESH_notify_transmit_ready (tunnel, - GNUNET_NO, - 42, + GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO, 42, GNUNET_TIME_relative_divide (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), (const struct GNUNET_PeerIdentity *) @@ -502,18 +502,16 @@ tcp_from_helper (struct tcp_pkt *tcp, unsigned char *dadr, size_t addrlen, memcpy (_tcp, tcp, pktlen); struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (tunnel); + if (NULL == s->th) { /* No notify is pending */ s->th = - GNUNET_MESH_notify_transmit_ready (tunnel, - GNUNET_NO, - 42, + GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO, 42, GNUNET_TIME_relative_divide (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), (const struct GNUNET_PeerIdentity *) - NULL, - len, + NULL, len, send_udp_to_peer_notify_callback, ctunnel); } @@ -684,44 +682,57 @@ read_service_conf (void *cls __attribute__ ((unused)), const char *section) } else { - struct addrinfo* res; + struct addrinfo *res; - int ret = getaddrinfo(hostname, NULL, NULL, &res); + int ret = getaddrinfo (hostname, NULL, NULL, &res); if (ret != 0) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No addresses found for %s!\n", + hostname); + GNUNET_free (serv); + continue; + } + else + { + char buf[256]; + struct addrinfo *c = res; + + if (c) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No addresses found for %s!\n", hostname); - GNUNET_free (serv); - continue; + if (c->ai_family == AF_INET) + { + serv->version = 4; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Found %s as address for %s\n", + inet_ntop (c->ai_family, + &((struct sockaddr_in *) (c-> + ai_addr))->sin_addr, + (char *) &buf, 256), hostname); + memcpy (serv->v4.ip4address, + &((struct sockaddr_in *) (c->ai_addr))->sin_addr, 4); + } + else if (c->ai_family == AF_INET6) + { + serv->version = 6; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Found %s as address for %s\n", + inet_ntop (c->ai_family, + &((struct sockaddr_in6 *) (c-> + ai_addr))->sin6_addr, + (char *) &buf, 256), hostname); + memcpy (serv->v6.ip6address, + &((struct sockaddr_in6 *) (c->ai_addr))->sin6_addr, 16); + } } - else + else { - char buf[256]; - struct addrinfo* c = res; - - if(c) - { - if (c->ai_family == AF_INET) - { - serv->version = 4; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found %s as address for %s\n", inet_ntop(c->ai_family, &((struct sockaddr_in *)(c->ai_addr))->sin_addr, (char*)&buf, 256), hostname); - memcpy(serv->v4.ip4address, &((struct sockaddr_in *)(c->ai_addr))->sin_addr, 4); - } - else if (c->ai_family == AF_INET6) - { - serv->version = 6; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found %s as address for %s\n", inet_ntop(c->ai_family, &((struct sockaddr_in6*)(c->ai_addr))->sin6_addr, (char*)&buf, 256), hostname); - memcpy(serv->v6.ip6address, &((struct sockaddr_in6 *)(c->ai_addr))->sin6_addr, 16); - } - } - else - { - freeaddrinfo(res); - GNUNET_free (serv); - continue; - } - freeaddrinfo(res); + freeaddrinfo (res); + GNUNET_free (serv); + continue; } + freeaddrinfo (res); + } } serv->remote_port = atoi (hostport); if (UDP == proto) @@ -1095,14 +1106,12 @@ receive_tcp_service (void *cls switch (serv->version) { case 4: - prepare_ipv4_packet (len, pkt_len, pkt, IPPROTO_TCP, - &serv->v4.ip4address, tunnel, state, - (struct ip_pkt *) buf); + prepare_ipv4_packet (len, pkt_len, pkt, IPPROTO_TCP, &serv->v4.ip4address, + tunnel, state, (struct ip_pkt *) buf); break; case 6: - prepare_ipv6_packet (len, pkt_len, pkt, IPPROTO_TCP, - &serv->v6.ip6address, tunnel, state, - (struct ip6_pkt *) buf); + prepare_ipv6_packet (len, pkt_len, pkt, IPPROTO_TCP, &serv->v6.ip6address, + tunnel, state, (struct ip6_pkt *) buf); break; default: @@ -1171,12 +1180,12 @@ receive_tcp_remote (void *cls switch (s->addrlen) { case 4: - prepare_ipv4_packet (len, pkt_len, pkt, IPPROTO_TCP, - &s->addr, tunnel, state, (struct ip_pkt *) buf); + prepare_ipv4_packet (len, pkt_len, pkt, IPPROTO_TCP, &s->addr, tunnel, + state, (struct ip_pkt *) buf); break; case 16: - prepare_ipv6_packet (len, pkt_len, pkt, IPPROTO_TCP, - &s->addr, tunnel, state, (struct ip6_pkt *) buf); + prepare_ipv6_packet (len, pkt_len, pkt, IPPROTO_TCP, &s->addr, tunnel, + state, (struct ip6_pkt *) buf); break; default: GNUNET_free (state); @@ -1252,12 +1261,12 @@ receive_udp_remote (void *cls switch (s->addrlen) { case 4: - prepare_ipv4_packet (len, ntohs (pkt->len), pkt, IPPROTO_UDP, - &s->addr, tunnel, state, (struct ip_pkt *) buf); + prepare_ipv4_packet (len, ntohs (pkt->len), pkt, IPPROTO_UDP, &s->addr, + tunnel, state, (struct ip_pkt *) buf); break; case 16: - prepare_ipv6_packet (len, ntohs (pkt->len), pkt, IPPROTO_UDP, - &s->addr, tunnel, state, (struct ip6_pkt *) buf); + prepare_ipv6_packet (len, ntohs (pkt->len), pkt, IPPROTO_UDP, &s->addr, + tunnel, state, (struct ip6_pkt *) buf); break; default: GNUNET_assert (0); @@ -1291,12 +1300,14 @@ receive_udp_remote (void *cls * The messages are one GNUNET_HashCode for the service, followed by a struct udp_pkt */ static int -receive_udp_service (void *cls __attribute__ ((unused)), - struct GNUNET_MESH_Tunnel *tunnel, - void **tunnel_ctx, - const struct GNUNET_PeerIdentity *sender __attribute__ ((unused)), +receive_udp_service (void *cls + __attribute__ ((unused)), + struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx, + const struct GNUNET_PeerIdentity *sender + __attribute__ ((unused)), const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *atsi __attribute__ ((unused))) + const struct GNUNET_ATS_Information *atsi + __attribute__ ((unused))) { GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1); @@ -1437,7 +1448,9 @@ connect_to_mesh () app_idx++; } - mesh_handle = GNUNET_MESH_connect (cfg, 42, NULL, new_tunnel, clean_tunnel, handlers, apptypes); + mesh_handle = + GNUNET_MESH_connect (cfg, 42, NULL, new_tunnel, clean_tunnel, handlers, + apptypes); } @@ -1468,11 +1481,11 @@ run (void *cls, char *const *args __attribute__ ((unused)), const char *cfgfile if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "exit", "MAX_UDP_CONNECTIONS", - &max_udp_connections)) + &max_udp_connections)) max_udp_connections = 1024; if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "exit", "MAX_TCP_CONNECTIONS", - &max_tcp_connections)) + &max_tcp_connections)) max_tcp_connections = 256; GNUNET_CONFIGURATION_iterate_sections (cfg, read_service_conf, NULL); GNUNET_SCHEDULER_add_now (start_helper_and_schedule, NULL); @@ -1481,7 +1494,7 @@ run (void *cls, char *const *args __attribute__ ((unused)), const char *cfgfile /** - * The main function + * The main function * * @param argc number of arguments from the command line * @param argv command line arguments @@ -1495,8 +1508,9 @@ main (int argc, char *const *argv) }; return (GNUNET_OK == - GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-exit", - gettext_noop ("Daemon to run to provide an IP exit node for the VPN"), + GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-exit", + gettext_noop + ("Daemon to run to provide an IP exit node for the VPN"), options, &run, NULL)) ? ret : 1; } diff --git a/src/vpn/gnunet-daemon-vpn-dns.c b/src/vpn/gnunet-daemon-vpn-dns.c index 7f762238c..77d900046 100644 --- a/src/vpn/gnunet-daemon-vpn-dns.c +++ b/src/vpn/gnunet-daemon-vpn-dns.c @@ -57,6 +57,7 @@ size_t send_query (void *cls __attribute__ ((unused)), size_t size, void *buf) { size_t len; + dns_transmit_handle = NULL; /* @@ -100,17 +101,20 @@ send_query (void *cls __attribute__ ((unused)), size_t size, void *buf) */ if (head != NULL) { - dns_transmit_handle = GNUNET_CLIENT_notify_transmit_ready (dns_connection, - ntohs (head->pkt.hdr.size), - GNUNET_TIME_UNIT_FOREVER_REL, - GNUNET_YES, &send_query, NULL); + dns_transmit_handle = + GNUNET_CLIENT_notify_transmit_ready (dns_connection, + ntohs (head->pkt.hdr.size), + GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_YES, &send_query, NULL); } else if (restart_hijack == 1) { - dns_transmit_handle = GNUNET_CLIENT_notify_transmit_ready (dns_connection, - sizeof (struct GNUNET_MessageHeader), - GNUNET_TIME_UNIT_FOREVER_REL, - GNUNET_YES, &send_query, NULL); + dns_transmit_handle = + GNUNET_CLIENT_notify_transmit_ready (dns_connection, + sizeof (struct + GNUNET_MessageHeader), + GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_YES, &send_query, NULL); } return len; @@ -144,16 +148,19 @@ connect_to_service_dns (void *cls /* If a packet is already in the list, schedule to send it */ if (dns_transmit_handle == NULL && head != NULL) - dns_transmit_handle = GNUNET_CLIENT_notify_transmit_ready (dns_connection, - ntohs (head->pkt.hdr.size), - GNUNET_TIME_UNIT_FOREVER_REL, - GNUNET_YES, &send_query, NULL); + dns_transmit_handle = + GNUNET_CLIENT_notify_transmit_ready (dns_connection, + ntohs (head->pkt.hdr.size), + GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_YES, &send_query, NULL); else if (dns_transmit_handle == NULL && restart_hijack == 1) { - dns_transmit_handle = GNUNET_CLIENT_notify_transmit_ready (dns_connection, - sizeof (struct GNUNET_MessageHeader), - GNUNET_TIME_UNIT_FOREVER_REL, - GNUNET_YES, &send_query, NULL); + dns_transmit_handle = + GNUNET_CLIENT_notify_transmit_ready (dns_connection, + sizeof (struct + GNUNET_MessageHeader), + GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_YES, &send_query, NULL); } } @@ -170,7 +177,7 @@ dns_answer_handler (void *cls if (msg == NULL) { if (dns_transmit_handle != NULL) - GNUNET_CLIENT_notify_transmit_ready_cancel(dns_transmit_handle); + GNUNET_CLIENT_notify_transmit_ready_cancel (dns_transmit_handle); dns_transmit_handle = NULL; GNUNET_CLIENT_disconnect (dns_connection, GNUNET_NO); dns_connection = NULL; diff --git a/src/vpn/gnunet-daemon-vpn-helper.c b/src/vpn/gnunet-daemon-vpn-helper.c index 124b53bf1..29227893a 100644 --- a/src/vpn/gnunet-daemon-vpn-helper.c +++ b/src/vpn/gnunet-daemon-vpn-helper.c @@ -45,7 +45,7 @@ struct GNUNET_VPN_HELPER_Handle *helper_handle; -extern struct GNUNET_CLIENT_TransmitHandle* dns_transmit_handle; +extern struct GNUNET_CLIENT_TransmitHandle *dns_transmit_handle; /** * The tunnels that will be used to send tcp- and udp-packets @@ -140,10 +140,12 @@ start_helper_and_schedule (void *cls, */ restart_hijack = 1; if (NULL != dns_connection && dns_transmit_handle == NULL) - dns_transmit_handle = GNUNET_CLIENT_notify_transmit_ready (dns_connection, - sizeof (struct GNUNET_MessageHeader), - GNUNET_TIME_UNIT_FOREVER_REL, - GNUNET_YES, &send_query, NULL); + dns_transmit_handle = + GNUNET_CLIENT_notify_transmit_ready (dns_connection, + sizeof (struct + GNUNET_MessageHeader), + GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_YES, &send_query, NULL); GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, helper_handle->fh_to_helper, &helper_write, @@ -152,10 +154,11 @@ start_helper_and_schedule (void *cls, /*}}}*/ -static void* -initialize_tunnel_state(int addrlen, struct GNUNET_MESH_TransmitHandle* th) +static void * +initialize_tunnel_state (int addrlen, struct GNUNET_MESH_TransmitHandle *th) { - struct tunnel_state* ts = GNUNET_malloc(sizeof *ts); + struct tunnel_state *ts = GNUNET_malloc (sizeof *ts); + ts->addrlen = addrlen; ts->th = th; return ts; @@ -186,111 +189,115 @@ helper_write (void *cls size_t data_len = len - sizeof (struct answer_packet) + 1; - void* buf; + void *buf; size_t pkt_len; if (ans->pkt.addrlen == 16) - { - size_t net_len = sizeof (struct ip6_hdr) + sizeof (struct udp_dns) + data_len; - pkt_len = - sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) + net_len; + { + size_t net_len = + sizeof (struct ip6_hdr) + sizeof (struct udp_dns) + data_len; + pkt_len = + sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) + + net_len; - struct ip6_udp_dns *pkt = alloca (pkt_len); + struct ip6_udp_dns *pkt = alloca (pkt_len); - GNUNET_assert (pkt != NULL); - memset (pkt, 0, pkt_len); + GNUNET_assert (pkt != NULL); + memset (pkt, 0, pkt_len); - /* set the gnunet-header */ - pkt->shdr.size = htons (pkt_len); - pkt->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); + /* set the gnunet-header */ + pkt->shdr.size = htons (pkt_len); + pkt->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); - /* set the tun-header (no flags and ethertype of IPv4) */ - pkt->tun.flags = 0; - pkt->tun.type = htons (0x86dd); + /* set the tun-header (no flags and ethertype of IPv4) */ + pkt->tun.flags = 0; + pkt->tun.type = htons (0x86dd); - memcpy(&pkt->ip6_hdr.sadr, ans->pkt.from, 16); - memcpy(&pkt->ip6_hdr.dadr, ans->pkt.to, 16); + memcpy (&pkt->ip6_hdr.sadr, ans->pkt.from, 16); + memcpy (&pkt->ip6_hdr.dadr, ans->pkt.to, 16); - /* set the udp-header */ - pkt->udp_dns.udp_hdr.spt = htons (53); - pkt->udp_dns.udp_hdr.dpt = ans->pkt.dst_port; - pkt->udp_dns.udp_hdr.len = htons (net_len - sizeof (struct ip6_hdr)); - pkt->udp_dns.udp_hdr.crc = 0; - uint32_t sum = 0; + /* set the udp-header */ + pkt->udp_dns.udp_hdr.spt = htons (53); + pkt->udp_dns.udp_hdr.dpt = ans->pkt.dst_port; + pkt->udp_dns.udp_hdr.len = htons (net_len - sizeof (struct ip6_hdr)); + pkt->udp_dns.udp_hdr.crc = 0; + uint32_t sum = 0; - sum = - calculate_checksum_update (sum, (uint16_t *) & pkt->ip6_hdr.sadr, 16); - sum = - calculate_checksum_update (sum, (uint16_t *) & pkt->ip6_hdr.dadr, 16); - uint32_t tmp = (pkt->udp_dns.udp_hdr.len & 0xffff); + sum = calculate_checksum_update (sum, (uint16_t *) & pkt->ip6_hdr.sadr, 16); + sum = calculate_checksum_update (sum, (uint16_t *) & pkt->ip6_hdr.dadr, 16); + uint32_t tmp = (pkt->udp_dns.udp_hdr.len & 0xffff); - sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); - tmp = htons (((pkt->ip6_hdr.nxthdr & 0x00ff))); - sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); + sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); + tmp = htons (((pkt->ip6_hdr.nxthdr & 0x00ff))); + sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); - sum = + sum = calculate_checksum_update (sum, (uint16_t *) & pkt->udp_dns.udp_hdr, - ntohs (net_len - sizeof(struct ip6_hdr))); - pkt->udp_dns.udp_hdr.crc = calculate_checksum_end (sum); + ntohs (net_len - sizeof (struct ip6_hdr))); + pkt->udp_dns.udp_hdr.crc = calculate_checksum_end (sum); - pkt->ip6_hdr.version = 6; - pkt->ip6_hdr.paylgth = net_len - sizeof (struct ip6_hdr); - pkt->ip6_hdr.nxthdr = IPPROTO_UDP; - pkt->ip6_hdr.hoplmt = 0xff; + pkt->ip6_hdr.version = 6; + pkt->ip6_hdr.paylgth = net_len - sizeof (struct ip6_hdr); + pkt->ip6_hdr.nxthdr = IPPROTO_UDP; + pkt->ip6_hdr.hoplmt = 0xff; - memcpy (&pkt->udp_dns.data, ans->pkt.data, data_len); - buf = pkt; - } + memcpy (&pkt->udp_dns.data, ans->pkt.data, data_len); + buf = pkt; + } else if (ans->pkt.addrlen == 4) - { - size_t net_len = sizeof (struct ip_hdr) + sizeof (struct udp_dns) + data_len; - pkt_len = - sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) + net_len; - - struct ip_udp_dns *pkt = alloca (pkt_len); - - GNUNET_assert (pkt != NULL); - memset (pkt, 0, pkt_len); - - /* set the gnunet-header */ - pkt->shdr.size = htons (pkt_len); - pkt->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); - - /* set the tun-header (no flags and ethertype of IPv4) */ - pkt->tun.flags = 0; - pkt->tun.type = htons (0x0800); - - /* set the ip-header */ - pkt->ip_hdr.version = 4; - pkt->ip_hdr.hdr_lngth = 5; - pkt->ip_hdr.diff_serv = 0; - pkt->ip_hdr.tot_lngth = htons (net_len); - pkt->ip_hdr.ident = 0; - pkt->ip_hdr.flags = 0; - pkt->ip_hdr.frag_off = 0; - pkt->ip_hdr.ttl = 255; - pkt->ip_hdr.proto = IPPROTO_UDP; - pkt->ip_hdr.chks = 0; /* Will be calculated later */ - - memcpy(&pkt->ip_hdr.sadr, ans->pkt.from, 4); - memcpy(&pkt->ip_hdr.dadr, ans->pkt.to, 4); - - pkt->ip_hdr.chks = calculate_ip_checksum ((uint16_t *) & pkt->ip_hdr, 5 * 4); - - /* set the udp-header */ - pkt->udp_dns.udp_hdr.spt = htons (53); - pkt->udp_dns.udp_hdr.dpt = ans->pkt.dst_port; - pkt->udp_dns.udp_hdr.len = htons (net_len - sizeof (struct ip_hdr)); - pkt->udp_dns.udp_hdr.crc = 0; /* Optional for IPv4 */ - - memcpy (&pkt->udp_dns.data, ans->pkt.data, data_len); - buf = pkt; - } + { + size_t net_len = + sizeof (struct ip_hdr) + sizeof (struct udp_dns) + data_len; + pkt_len = + sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) + + net_len; + + struct ip_udp_dns *pkt = alloca (pkt_len); + + GNUNET_assert (pkt != NULL); + memset (pkt, 0, pkt_len); + + /* set the gnunet-header */ + pkt->shdr.size = htons (pkt_len); + pkt->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); + + /* set the tun-header (no flags and ethertype of IPv4) */ + pkt->tun.flags = 0; + pkt->tun.type = htons (0x0800); + + /* set the ip-header */ + pkt->ip_hdr.version = 4; + pkt->ip_hdr.hdr_lngth = 5; + pkt->ip_hdr.diff_serv = 0; + pkt->ip_hdr.tot_lngth = htons (net_len); + pkt->ip_hdr.ident = 0; + pkt->ip_hdr.flags = 0; + pkt->ip_hdr.frag_off = 0; + pkt->ip_hdr.ttl = 255; + pkt->ip_hdr.proto = IPPROTO_UDP; + pkt->ip_hdr.chks = 0; /* Will be calculated later */ + + memcpy (&pkt->ip_hdr.sadr, ans->pkt.from, 4); + memcpy (&pkt->ip_hdr.dadr, ans->pkt.to, 4); + + pkt->ip_hdr.chks = + calculate_ip_checksum ((uint16_t *) & pkt->ip_hdr, 5 * 4); + + /* set the udp-header */ + pkt->udp_dns.udp_hdr.spt = htons (53); + pkt->udp_dns.udp_hdr.dpt = ans->pkt.dst_port; + pkt->udp_dns.udp_hdr.len = htons (net_len - sizeof (struct ip_hdr)); + pkt->udp_dns.udp_hdr.crc = 0; /* Optional for IPv4 */ + + memcpy (&pkt->udp_dns.data, ans->pkt.data, data_len); + buf = pkt; + } else - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Wrong addrlen = %d\n", ans->pkt.addrlen); - GNUNET_assert(0); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Wrong addrlen = %d\n", + ans->pkt.addrlen); + GNUNET_assert (0); + } GNUNET_CONTAINER_DLL_remove (answer_proc_head, answer_proc_tail, ans); GNUNET_free (ans); @@ -332,37 +339,43 @@ message_token (void *cls __attribute__ ((unused)), void *client struct ip6_udp *pkt6_udp; struct ip6_icmp *pkt6_icmp; - pkt6_udp = NULL; /* make compiler happy */ + pkt6_udp = NULL; /* make compiler happy */ switch (pkt6->ip6_hdr.nxthdr) { case IPPROTO_UDP: pkt6_udp = (struct ip6_udp *) pkt6; /* Send dns-packets to the service-dns */ if (ntohs (pkt6_udp->udp_hdr.dpt) == 53) - { - /* 9 = 8 for the udp-header + 1 for the unsigned char data[1]; */ - size_t len = sizeof (struct query_packet) + ntohs (pkt6_udp->udp_hdr.len) - 9; - - struct query_packet_list *query = - GNUNET_malloc (len + sizeof(struct answer_packet_list) - sizeof(struct answer_packet)); - query->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_QUERY_DNS); - query->pkt.hdr.size = htons (len); - memcpy(query->pkt.orig_to, &pkt6->ip6_hdr.dadr, 16); - memcpy(query->pkt.orig_from, &pkt6->ip6_hdr.sadr, 16); - query->pkt.addrlen = 16; - query->pkt.src_port = pkt6_udp->udp_hdr.spt; - memcpy (query->pkt.data, pkt6_udp->data, ntohs (pkt6_udp->udp_hdr.len) - 8); - - GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, query); - - GNUNET_assert (head != NULL); - - if (dns_connection != NULL && dns_transmit_handle == NULL) - dns_transmit_handle = GNUNET_CLIENT_notify_transmit_ready (dns_connection, len, - GNUNET_TIME_UNIT_FOREVER_REL, - GNUNET_YES, &send_query, NULL); - break; - } + { + /* 9 = 8 for the udp-header + 1 for the unsigned char data[1]; */ + size_t len = + sizeof (struct query_packet) + ntohs (pkt6_udp->udp_hdr.len) - 9; + + struct query_packet_list *query = + GNUNET_malloc (len + sizeof (struct answer_packet_list) - + sizeof (struct answer_packet)); + query->pkt.hdr.type = + htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_QUERY_DNS); + query->pkt.hdr.size = htons (len); + memcpy (query->pkt.orig_to, &pkt6->ip6_hdr.dadr, 16); + memcpy (query->pkt.orig_from, &pkt6->ip6_hdr.sadr, 16); + query->pkt.addrlen = 16; + query->pkt.src_port = pkt6_udp->udp_hdr.spt; + memcpy (query->pkt.data, pkt6_udp->data, + ntohs (pkt6_udp->udp_hdr.len) - 8); + + GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, query); + + GNUNET_assert (head != NULL); + + if (dns_connection != NULL && dns_transmit_handle == NULL) + dns_transmit_handle = + GNUNET_CLIENT_notify_transmit_ready (dns_connection, len, + GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_YES, &send_query, + NULL); + break; + } /* fall through */ case IPPROTO_TCP: pkt6_tcp = (struct ip6_tcp *) pkt6; @@ -418,19 +431,20 @@ message_token (void *cls __attribute__ ((unused)), void *client } else { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "pip: %d\n", port_in_ports(me->desc.ports, pkt6_tcp->tcp_hdr.dpt)); - GNUNET_assert(0); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pip: %d\n", + port_in_ports (me->desc.ports, pkt6_tcp->tcp_hdr.dpt)); + GNUNET_assert (0); } if (me->tunnel == NULL && NULL != cls) { *cls = - GNUNET_MESH_tunnel_create(mesh_handle, initialize_tunnel_state(16, NULL), - &send_pkt_to_peer, NULL, cls); + GNUNET_MESH_tunnel_create (mesh_handle, + initialize_tunnel_state (16, NULL), + &send_pkt_to_peer, NULL, cls); GNUNET_MESH_peer_request_connect_add (*cls, - (struct - GNUNET_PeerIdentity *) - &me->desc.peer); + (struct GNUNET_PeerIdentity *) + &me->desc.peer); me->tunnel = *cls; } else if (NULL != cls) @@ -451,7 +465,7 @@ message_token (void *cls __attribute__ ((unused)), void *client memcpy (s->addr, me->addr, me->addrlen); s->proto = pkt6->ip6_hdr.nxthdr; if (s->proto == IPPROTO_UDP) - { + { hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_REMOTE_UDP); memcpy (hc + 1, &pkt6_udp->udp_hdr, ntohs (pkt6_udp->udp_hdr.len)); app_type = GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY; @@ -473,11 +487,11 @@ message_token (void *cls __attribute__ ((unused)), void *client if (me->tunnel == NULL && NULL != cls) { *cls = - GNUNET_MESH_tunnel_create(mesh_handle, initialize_tunnel_state(16, NULL), - &send_pkt_to_peer, NULL, cls); + GNUNET_MESH_tunnel_create (mesh_handle, + initialize_tunnel_state (16, NULL), + &send_pkt_to_peer, NULL, cls); - GNUNET_MESH_peer_request_connect_by_type (*cls, - app_type); + GNUNET_MESH_peer_request_connect_by_type (*cls, app_type); me->tunnel = *cls; if (GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY == app_type) udp_tunnel = *cls; @@ -538,11 +552,12 @@ message_token (void *cls __attribute__ ((unused)), void *client size_t len = sizeof (struct query_packet) + ntohs (udp->udp_hdr.len) - 9; struct query_packet_list *query = - GNUNET_malloc (len + sizeof(struct answer_packet_list) - sizeof(struct answer_packet)); + GNUNET_malloc (len + sizeof (struct answer_packet_list) - + sizeof (struct answer_packet)); query->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_QUERY_DNS); query->pkt.hdr.size = htons (len); - memcpy(query->pkt.orig_to, &pkt->ip_hdr.dadr, 4); - memcpy(query->pkt.orig_from, &pkt->ip_hdr.sadr, 4); + memcpy (query->pkt.orig_to, &pkt->ip_hdr.dadr, 4); + memcpy (query->pkt.orig_from, &pkt->ip_hdr.sadr, 4); query->pkt.addrlen = 4; query->pkt.src_port = udp->udp_hdr.spt; memcpy (query->pkt.data, udp->data, ntohs (udp->udp_hdr.len) - 8); @@ -552,9 +567,10 @@ message_token (void *cls __attribute__ ((unused)), void *client GNUNET_assert (head != NULL); if (dns_connection != NULL && dns_transmit_handle == NULL) - dns_transmit_handle = GNUNET_CLIENT_notify_transmit_ready (dns_connection, len, - GNUNET_TIME_UNIT_FOREVER_REL, - GNUNET_YES, &send_query, NULL); + dns_transmit_handle = + GNUNET_CLIENT_notify_transmit_ready (dns_connection, len, + GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_YES, &send_query, NULL); } else { @@ -625,12 +641,13 @@ message_token (void *cls __attribute__ ((unused)), void *client } if (me->tunnel == NULL && NULL != cls) { - *cls = GNUNET_MESH_tunnel_create(mesh_handle, - initialize_tunnel_state(4, NULL), - send_pkt_to_peer, NULL, cls); + *cls = + GNUNET_MESH_tunnel_create (mesh_handle, + initialize_tunnel_state (4, NULL), + send_pkt_to_peer, NULL, cls); GNUNET_MESH_peer_request_connect_add (*cls, - (struct GNUNET_PeerIdentity *) - &me->desc.peer); + (struct GNUNET_PeerIdentity + *) &me->desc.peer); me->tunnel = *cls; } else if (NULL != cls) @@ -664,13 +681,15 @@ message_token (void *cls __attribute__ ((unused)), void *client ntohs (pkt->ip_hdr.tot_lngth) - 4 * pkt->ip_hdr.hdr_lngth); app_type = GNUNET_APPLICATION_TYPE_INTERNET_TCP_GATEWAY; - } else - GNUNET_assert (0); + } + else + GNUNET_assert (0); if (me->tunnel == NULL && NULL != cls) { *cls = - GNUNET_MESH_tunnel_create(mesh_handle, initialize_tunnel_state(4, NULL), - send_pkt_to_peer, NULL, cls); + GNUNET_MESH_tunnel_create (mesh_handle, + initialize_tunnel_state (4, NULL), + send_pkt_to_peer, NULL, cls); GNUNET_MESH_peer_request_connect_by_type (*cls, app_type); me->tunnel = *cls; diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c index 1191dffe1..cc8001eae 100644 --- a/src/vpn/gnunet-daemon-vpn.c +++ b/src/vpn/gnunet-daemon-vpn.c @@ -183,7 +183,7 @@ collect_mappings (void *cls /* FIXME! GNUNET_MESH_close_tunnel(me->tunnel); */ GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (hashmap, &me->hash, me)); + GNUNET_CONTAINER_multihashmap_remove (hashmap, &me->hash, me)); GNUNET_free (me); } @@ -282,21 +282,22 @@ send_pkt_to_peer_notify_callback (void *cls, size_t size, void *buf) { struct GNUNET_MESH_Tunnel **tunnel = cls; - struct tunnel_state *ts = GNUNET_MESH_tunnel_get_data(*tunnel); + struct tunnel_state *ts = GNUNET_MESH_tunnel_get_data (*tunnel); + ts->th = NULL; if (NULL != buf) - { - struct GNUNET_MessageHeader *hdr = + { + struct GNUNET_MessageHeader *hdr = (struct GNUNET_MessageHeader *) (tunnel + 1); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "send_pkt_to_peer_notify_callback: buf = %x; size = %u;\n", buf, - size); - GNUNET_assert (size >= ntohs (hdr->size)); - memcpy (buf, hdr, ntohs (hdr->size)); - size = ntohs (hdr->size); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent!\n"); - } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "send_pkt_to_peer_notify_callback: buf = %x; size = %u;\n", buf, + size); + GNUNET_assert (size >= ntohs (hdr->size)); + memcpy (buf, hdr, ntohs (hdr->size)); + size = ntohs (hdr->size); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent!\n"); + } else size = 0; @@ -307,9 +308,7 @@ send_pkt_to_peer_notify_callback (void *cls, size_t size, void *buf) GNUNET_CONTAINER_DLL_remove (ts->head, ts->tail, element); ts->th = - GNUNET_MESH_notify_transmit_ready (*tunnel, - GNUNET_NO, - 42, + GNUNET_MESH_notify_transmit_ready (*tunnel, GNUNET_NO, 42, GNUNET_TIME_relative_divide (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), (const struct GNUNET_PeerIdentity *) @@ -330,12 +329,14 @@ port_in_ports (uint64_t ports, uint16_t port) { uint16_t *ps = (uint16_t *) & ports; - return ports == 0 || ps[0] == port || ps[1] == port || ps[2] == port || ps[3] == port; + return ports == 0 || ps[0] == port || ps[1] == port || ps[2] == port || + ps[3] == port; } void send_pkt_to_peer (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Information *atsi __attribute__ ((unused))) + const struct GNUNET_ATS_Information *atsi + __attribute__ ((unused))) { /* peer == NULL means that all peers in this request are connected */ if (peer == NULL) @@ -347,18 +348,16 @@ send_pkt_to_peer (void *cls, const struct GNUNET_PeerIdentity *peer, GNUNET_assert (NULL != tunnel); GNUNET_assert (NULL != *tunnel); - struct tunnel_state *ts = GNUNET_MESH_tunnel_get_data(*tunnel); + struct tunnel_state *ts = GNUNET_MESH_tunnel_get_data (*tunnel); + if (NULL == ts->th) { ts->th = - GNUNET_MESH_notify_transmit_ready (*tunnel, - GNUNET_NO, - 42, + GNUNET_MESH_notify_transmit_ready (*tunnel, GNUNET_NO, 42, GNUNET_TIME_relative_divide (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), (const struct GNUNET_PeerIdentity *) - NULL, - ntohs (hdr->size), + NULL, ntohs (hdr->size), send_pkt_to_peer_notify_callback, cls); } @@ -574,7 +573,8 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) list = GNUNET_malloc (htons (pkt->hdr.size) + - sizeof(struct answer_packet_list) - sizeof(struct answer_packet)); + sizeof (struct answer_packet_list) - + sizeof (struct answer_packet)); memcpy (&list->pkt, pkt, htons (pkt->hdr.size)); @@ -622,8 +622,9 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) char *name = (char *) (map_entry + 1); list = - GNUNET_malloc (sizeof(struct answer_packet_list) - sizeof(struct answer_packet) + offset + 2 + - ntohs (namelen)); + GNUNET_malloc (sizeof (struct answer_packet_list) - + sizeof (struct answer_packet) + offset + 2 + + ntohs (namelen)); struct answer_packet *rpkt = &list->pkt; @@ -641,7 +642,8 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { list = GNUNET_malloc (htons (pkt->hdr.size) + - sizeof(struct answer_packet_list) - sizeof(struct answer_packet)); + sizeof (struct answer_packet_list) - + sizeof (struct answer_packet)); memcpy (&list->pkt, pkt, htons (pkt->hdr.size)); } else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_REMOTE_AAAA) @@ -701,7 +703,8 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) list = GNUNET_malloc (htons (pkt->hdr.size) + - sizeof(struct answer_packet_list) - sizeof(struct answer_packet)); + sizeof (struct answer_packet_list) - + sizeof (struct answer_packet)); memcpy (&list->pkt, pkt, htons (pkt->hdr.size)); } @@ -763,7 +766,8 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) list = GNUNET_malloc (htons (pkt->hdr.size) + - sizeof(struct answer_packet_list) - sizeof(struct answer_packet)); + sizeof (struct answer_packet_list) - + sizeof (struct answer_packet)); memcpy (&list->pkt, pkt, htons (pkt->hdr.size)); } @@ -852,12 +856,12 @@ add_additional_port (struct map_entry *me, uint16_t port) } static int -receive_udp_back (void *cls __attribute__ ((unused)), - struct GNUNET_MESH_Tunnel *tunnel, - void **tunnel_ctx, - const struct GNUNET_PeerIdentity *sender, +receive_udp_back (void *cls + __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel, + void **tunnel_ctx, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *atsi __attribute__ ((unused))) + const struct GNUNET_ATS_Information *atsi + __attribute__ ((unused))) { GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); struct remote_addr *s = (struct remote_addr *) desc; @@ -1029,12 +1033,13 @@ receive_udp_back (void *cls __attribute__ ((unused)), } static int -receive_tcp_back (void *cls __attribute__ ((unused)), - struct GNUNET_MESH_Tunnel *tunnel, - void **tunnel_ctx, - const struct GNUNET_PeerIdentity *sender __attribute__ ((unused)), +receive_tcp_back (void *cls + __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel, + void **tunnel_ctx, const struct GNUNET_PeerIdentity *sender + __attribute__ ((unused)), const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *atsi __attribute__ ((unused))) + const struct GNUNET_ATS_Information *atsi + __attribute__ ((unused))) { GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); struct remote_addr *s = (struct remote_addr *) desc; @@ -1046,9 +1051,10 @@ receive_tcp_back (void *cls __attribute__ ((unused)), ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) - sizeof (GNUNET_HashCode); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received TCP-Packet back, addrlen = %d\n", s->addrlen); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received TCP-Packet back, addrlen = %d\n", s->addrlen); - if (ntohs(message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP_BACK || + if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP_BACK || ts->addrlen == 16) { size_t size = pktlen + sizeof (struct ip6_tcp) - 1; @@ -1195,7 +1201,7 @@ receive_tcp_back (void *cls __attribute__ ((unused)), tmp = pkt4->ip_hdr.dadr; sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); - tmp = (0x06 << 16) | (0xffff & pktlen); // 0x06 for TCP? + tmp = (0x06 << 16) | (0xffff & pktlen); // 0x06 for TCP? tmp = htonl (tmp); @@ -1213,22 +1219,21 @@ receive_tcp_back (void *cls __attribute__ ((unused)), return GNUNET_OK; } -static void* new_tunnel(void* cls, - struct GNUNET_MESH_Tunnel *tunnel, - const struct GNUNET_PeerIdentity *initiator, - const struct GNUNET_ATS_Information *atsi) +static void * +new_tunnel (void *cls, struct GNUNET_MESH_Tunnel *tunnel, + const struct GNUNET_PeerIdentity *initiator, + const struct GNUNET_ATS_Information *atsi) { /* Why should anyone open an inbound tunnel to vpn? */ - GNUNET_break(0); + GNUNET_break (0); return NULL; } -static void cleaner(void *cls, - const struct GNUNET_MESH_Tunnel *tunnel, - void *tunnel_ctx) +static void +cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel, void *tunnel_ctx) { /* Why should anyone open an inbound tunnel to vpn? */ - GNUNET_break(0); + GNUNET_break (0); } /** @@ -1255,7 +1260,9 @@ run (void *cls, char *const *args __attribute__ ((unused)), const char *cfgfilep GNUNET_APPLICATION_TYPE_END }; - mesh_handle = GNUNET_MESH_connect (cfg_, 42, NULL, new_tunnel, cleaner, handlers, types); + mesh_handle = + GNUNET_MESH_connect (cfg_, 42, NULL, new_tunnel, cleaner, handlers, + types); cfg = cfg_; restart_hijack = 0; hashmap = GNUNET_CONTAINER_multihashmap_create (65536); diff --git a/src/vpn/gnunet-dns-parser.c b/src/vpn/gnunet-dns-parser.c index e3b03fefd..e87109e0c 100644 --- a/src/vpn/gnunet-dns-parser.c +++ b/src/vpn/gnunet-dns-parser.c @@ -136,114 +136,126 @@ parse_dns_packet (struct dns_pkt *pkt) } /*}}} */ static void -unparse_dns_name(char* dest, char* src, size_t len) +unparse_dns_name (char *dest, char *src, size_t len) { char *b = dest; char cnt = 0; + dest++; while (*src != 0) + { + while (*src != '.' && *src != 0) { - while (*src != '.' && *src != 0) - { - *dest = *src; - src++; - dest++; - cnt++; - } - *b = cnt; - cnt = 0; - b = dest; - dest++; + *dest = *src; src++; + dest++; + cnt++; } + *b = cnt; + cnt = 0; + b = dest; + dest++; + src++; + } *b = 0; } struct dns_pkt * -unparse_dns_packet (struct dns_pkt_parsed* ppkt) +unparse_dns_packet (struct dns_pkt_parsed *ppkt) { - size_t size = sizeof(struct dns_pkt) - 1; + size_t size = sizeof (struct dns_pkt) - 1; int i; - for (i = 0; i < ntohs(ppkt->s.qdcount); i++) + + for (i = 0; i < ntohs (ppkt->s.qdcount); i++) size += ppkt->queries[i]->namelen + 1; - for (i = 0; i < ntohs(ppkt->s.ancount); i++) - { - size += ppkt->answers[i]->namelen + 1; - size += ppkt->answers[i]->data_len; - } - for (i = 0; i < ntohs(ppkt->s.nscount); i++) - { - size += ppkt->nameservers[i]->namelen + 1; - size += ppkt->nameservers[i]->data_len; - } - for (i = 0; i < ntohs(ppkt->s.arcount); i++) - { - size += ppkt->additional[i]->namelen + 1; - size += ppkt->additional[i]->data_len; - } + for (i = 0; i < ntohs (ppkt->s.ancount); i++) + { + size += ppkt->answers[i]->namelen + 1; + size += ppkt->answers[i]->data_len; + } + for (i = 0; i < ntohs (ppkt->s.nscount); i++) + { + size += ppkt->nameservers[i]->namelen + 1; + size += ppkt->nameservers[i]->data_len; + } + for (i = 0; i < ntohs (ppkt->s.arcount); i++) + { + size += ppkt->additional[i]->namelen + 1; + size += ppkt->additional[i]->data_len; + } + + size += + 4 * ntohs (ppkt->s.qdcount) + 10 * (ntohs (ppkt->s.ancount) + + ntohs (ppkt->s.arcount) + + ntohs (ppkt->s.nscount)); - size += 4*ntohs(ppkt->s.qdcount) + 10*( - ntohs(ppkt->s.ancount)+ - ntohs(ppkt->s.arcount)+ - ntohs(ppkt->s.nscount)); + struct dns_pkt *pkt = GNUNET_malloc (size); + char *pkt_c = (char *) pkt; - struct dns_pkt *pkt = GNUNET_malloc(size); - char *pkt_c = (char*)pkt; - memcpy(&pkt->s, &ppkt->s, sizeof ppkt->s); + memcpy (&pkt->s, &ppkt->s, sizeof ppkt->s); size_t idx = sizeof ppkt->s; - for (i = 0; i < ntohs(ppkt->s.qdcount); i++) - { - unparse_dns_name(&pkt_c[idx], ppkt->queries[i]->name, ppkt->queries[i]->namelen); - idx += ppkt->queries[i]->namelen; - struct dns_query_line *d = (struct dns_query_line*)&pkt_c[idx]; - d->class = ppkt->queries[i]->qclass; - d->type = ppkt->queries[i]->qtype; - idx += sizeof(struct dns_query_line); - } + for (i = 0; i < ntohs (ppkt->s.qdcount); i++) + { + unparse_dns_name (&pkt_c[idx], ppkt->queries[i]->name, + ppkt->queries[i]->namelen); + idx += ppkt->queries[i]->namelen; + struct dns_query_line *d = (struct dns_query_line *) &pkt_c[idx]; + + d->class = ppkt->queries[i]->qclass; + d->type = ppkt->queries[i]->qtype; + idx += sizeof (struct dns_query_line); + } - for (i = 0; i < ntohs(ppkt->s.ancount); i++) - { - unparse_dns_name(&pkt_c[idx], ppkt->answers[i]->name, ppkt->answers[i]->namelen); - idx += ppkt->answers[i]->namelen; - struct dns_record_line *r = (struct dns_record_line*)&pkt_c[idx]; - r->type = ppkt->answers[i]->type; - r->class = ppkt->answers[i]->class; - r->ttl = ppkt->answers[i]->ttl; - r->data_len = ppkt->answers[i]->data_len; - idx += sizeof(struct dns_record_line); - memcpy(&r->data, ppkt->answers[i]->data, ppkt->answers[i]->data_len); - idx += ppkt->answers[i]->data_len; - } + for (i = 0; i < ntohs (ppkt->s.ancount); i++) + { + unparse_dns_name (&pkt_c[idx], ppkt->answers[i]->name, + ppkt->answers[i]->namelen); + idx += ppkt->answers[i]->namelen; + struct dns_record_line *r = (struct dns_record_line *) &pkt_c[idx]; + + r->type = ppkt->answers[i]->type; + r->class = ppkt->answers[i]->class; + r->ttl = ppkt->answers[i]->ttl; + r->data_len = ppkt->answers[i]->data_len; + idx += sizeof (struct dns_record_line); + memcpy (&r->data, ppkt->answers[i]->data, ppkt->answers[i]->data_len); + idx += ppkt->answers[i]->data_len; + } - for (i = 0; i < ntohs(ppkt->s.nscount); i++) - { - unparse_dns_name(&pkt_c[idx], ppkt->nameservers[i]->name, ppkt->nameservers[i]->namelen); - idx += ppkt->nameservers[i]->namelen; - struct dns_record_line *r = (struct dns_record_line*)&pkt_c[idx]; - r->type = ppkt->nameservers[i]->type; - r->class = ppkt->nameservers[i]->class; - r->ttl = ppkt->nameservers[i]->ttl; - r->data_len = ppkt->nameservers[i]->data_len; - idx += sizeof(struct dns_record_line); - memcpy(&r->data, ppkt->nameservers[i]->data, ppkt->nameservers[i]->data_len); - idx += ppkt->nameservers[i]->data_len; - } + for (i = 0; i < ntohs (ppkt->s.nscount); i++) + { + unparse_dns_name (&pkt_c[idx], ppkt->nameservers[i]->name, + ppkt->nameservers[i]->namelen); + idx += ppkt->nameservers[i]->namelen; + struct dns_record_line *r = (struct dns_record_line *) &pkt_c[idx]; + + r->type = ppkt->nameservers[i]->type; + r->class = ppkt->nameservers[i]->class; + r->ttl = ppkt->nameservers[i]->ttl; + r->data_len = ppkt->nameservers[i]->data_len; + idx += sizeof (struct dns_record_line); + memcpy (&r->data, ppkt->nameservers[i]->data, + ppkt->nameservers[i]->data_len); + idx += ppkt->nameservers[i]->data_len; + } - for (i = 0; i < ntohs(ppkt->s.arcount); i++) - { - unparse_dns_name(&pkt_c[idx], ppkt->additional[i]->name, ppkt->additional[i]->namelen); - idx += ppkt->additional[i]->namelen; - struct dns_record_line *r = (struct dns_record_line*)&pkt_c[idx]; - r->type = ppkt->additional[i]->type; - r->class = ppkt->additional[i]->class; - r->ttl = ppkt->additional[i]->ttl; - r->data_len = ppkt->additional[i]->data_len; - idx += sizeof(struct dns_record_line); - memcpy(&r->data, ppkt->additional[i]->data, ppkt->additional[i]->data_len); - idx += ppkt->additional[i]->data_len; - } + for (i = 0; i < ntohs (ppkt->s.arcount); i++) + { + unparse_dns_name (&pkt_c[idx], ppkt->additional[i]->name, + ppkt->additional[i]->namelen); + idx += ppkt->additional[i]->namelen; + struct dns_record_line *r = (struct dns_record_line *) &pkt_c[idx]; + + r->type = ppkt->additional[i]->type; + r->class = ppkt->additional[i]->class; + r->ttl = ppkt->additional[i]->ttl; + r->data_len = ppkt->additional[i]->data_len; + idx += sizeof (struct dns_record_line); + memcpy (&r->data, ppkt->additional[i]->data, ppkt->additional[i]->data_len); + idx += ppkt->additional[i]->data_len; + } return pkt; } diff --git a/src/vpn/gnunet-service-dns-p.h b/src/vpn/gnunet-service-dns-p.h index 13b410e2f..0519b1f84 100644 --- a/src/vpn/gnunet-service-dns-p.h +++ b/src/vpn/gnunet-service-dns-p.h @@ -102,7 +102,8 @@ struct answer_packet unsigned char data[1]; }; -struct answer_packet_list { +struct answer_packet_list +{ struct answer_packet_list *next GNUNET_PACKED; struct answer_packet_list *prev GNUNET_PACKED; struct GNUNET_SERVER_Client *client; diff --git a/src/vpn/gnunet-service-dns.c b/src/vpn/gnunet-service-dns.c index 489235ed4..c8d790b56 100644 --- a/src/vpn/gnunet-service-dns.c +++ b/src/vpn/gnunet-service-dns.c @@ -99,7 +99,7 @@ static struct char *name; uint8_t namelen; uint16_t qtype; -} query_states[UINT16_MAX+1]; +} query_states[UINT16_MAX + 1]; /** * A struct used to give more than one value as @@ -122,39 +122,45 @@ struct tunnel_notify_queue struct tunnel_state { - struct tunnel_notify_queue *head,*tail; + struct tunnel_notify_queue *head, *tail; struct GNUNET_MESH_TransmitHandle *th; }; -static size_t send_answer (void *cls, size_t size, void *buf); +static size_t +send_answer (void *cls, size_t size, void *buf); static void -client_disconnect(void* cls, struct GNUNET_SERVER_Client *client) +client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) { - if (NULL == head) return; + if (NULL == head) + return; if (head->client == client) - { - GNUNET_CONNECTION_notify_transmit_ready_cancel(server_notify); - server_notify = GNUNET_SERVER_notify_transmit_ready (head->next->client, ntohs (head->next->pkt.hdr.size), - GNUNET_TIME_UNIT_FOREVER_REL, - &send_answer, NULL); - } + { + GNUNET_CONNECTION_notify_transmit_ready_cancel (server_notify); + server_notify = + GNUNET_SERVER_notify_transmit_ready (head->next->client, + ntohs (head->next->pkt.hdr.size), + GNUNET_TIME_UNIT_FOREVER_REL, + &send_answer, NULL); + } struct answer_packet_list *element = head; + while (element != NULL) + { + if (element->client == client) { - if (element->client == client) - { - GNUNET_SERVER_client_drop(client); - GNUNET_CONTAINER_DLL_remove(head, tail, element); - struct answer_packet_list* t = element; - element = element->next; - GNUNET_free(t); - } - else - element = element->next; + GNUNET_SERVER_client_drop (client); + GNUNET_CONTAINER_DLL_remove (head, tail, element); + struct answer_packet_list *t = element; + + element = element->next; + GNUNET_free (t); } + else + element = element->next; + } } /** @@ -201,24 +207,26 @@ hijack (void *cls } static void * -new_tunnel (void *cls __attribute__((unused)), - struct GNUNET_MESH_Tunnel *tunnel, - const struct GNUNET_PeerIdentity *initiator __attribute__((unused)), - const struct GNUNET_ATS_Information *ats __attribute__((unused))) +new_tunnel (void *cls + __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel, + const struct GNUNET_PeerIdentity *initiator + __attribute__ ((unused)), const struct GNUNET_ATS_Information *ats + __attribute__ ((unused))) { - struct tunnel_state *s = GNUNET_malloc(sizeof *s); - s->head = NULL; - s->tail = NULL; - s->th = NULL; - return s; + struct tunnel_state *s = GNUNET_malloc (sizeof *s); + + s->head = NULL; + s->tail = NULL; + s->th = NULL; + return s; } static void -clean_tunnel (void *cls __attribute__((unused)), - const struct GNUNET_MESH_Tunnel *tunnel, +clean_tunnel (void *cls + __attribute__ ((unused)), const struct GNUNET_MESH_Tunnel *tunnel, void *tunnel_ctx) { - GNUNET_free(tunnel_ctx); + GNUNET_free (tunnel_ctx); } /** @@ -246,10 +254,10 @@ unhijack (unsigned short port) GNUNET_OS_start_process (NULL, NULL, "gnunet-helper-hijack-dns", "gnunet-hijack-dns", "-d", port_s, virt_dns, NULL))) - { - GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (proc)); - GNUNET_OS_process_close (proc); - } + { + GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (proc)); + GNUNET_OS_process_close (proc); + } GNUNET_free (virt_dns); } @@ -272,11 +280,13 @@ send_answer (void *cls, size_t size, void *buf) /* When more data is to be sent, reschedule */ if (head != NULL) - server_notify = GNUNET_SERVER_notify_transmit_ready (head->client, ntohs (head->pkt.hdr.size), - GNUNET_TIME_UNIT_FOREVER_REL, - &send_answer, NULL); + server_notify = + GNUNET_SERVER_notify_transmit_ready (head->client, + ntohs (head->pkt.hdr.size), + GNUNET_TIME_UNIT_FOREVER_REL, + &send_answer, NULL); - GNUNET_SERVER_client_drop(query->client); + GNUNET_SERVER_client_drop (query->client); GNUNET_free (query); return len; } @@ -311,7 +321,8 @@ mesh_send_response (void *cls, size_t size, void *buf) GNUNET_assert (size >= (*sz + sizeof (struct GNUNET_MessageHeader))); memcpy (hdr + 1, dns, *sz); - struct tunnel_state *s = GNUNET_MESH_tunnel_get_data(*tunnel); + struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (*tunnel); + if (NULL != s->head) { struct tunnel_notify_queue *element = s->head; @@ -321,14 +332,12 @@ mesh_send_response (void *cls, size_t size, void *buf) GNUNET_CONTAINER_DLL_remove (head, tail, element); s->th = - GNUNET_MESH_notify_transmit_ready (*tunnel, - GNUNET_NO, - 42, + GNUNET_MESH_notify_transmit_ready (*tunnel, GNUNET_NO, 42, GNUNET_TIME_relative_divide (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), (const struct GNUNET_PeerIdentity *) - NULL, element->len, - element->cb, element->cls); + NULL, element->len, element->cb, + element->cls); } GNUNET_free (cls); @@ -350,27 +359,23 @@ mesh_send (void *cls, size_t size, void *buf) memcpy (buf, &cls_->hdr, size); - struct tunnel_state *s = GNUNET_MESH_tunnel_get_data(cls_->tunnel); + struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (cls_->tunnel); + if (NULL != s->head) { - struct tunnel_notify_queue *element = - s->head; - struct tunnel_notify_queue *head = - s->head; - struct tunnel_notify_queue *tail = - s->tail;; + struct tunnel_notify_queue *element = s->head; + struct tunnel_notify_queue *head = s->head; + struct tunnel_notify_queue *tail = s->tail;; GNUNET_CONTAINER_DLL_remove (head, tail, element); s->th = - GNUNET_MESH_notify_transmit_ready (cls_->tunnel, - GNUNET_NO, - 42, + GNUNET_MESH_notify_transmit_ready (cls_->tunnel, GNUNET_NO, 42, GNUNET_TIME_relative_divide (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), (const struct GNUNET_PeerIdentity *) - NULL, element->len, - element->cb, element->cls); + NULL, element->len, element->cb, + element->cls); GNUNET_free (element); } @@ -392,26 +397,20 @@ mesh_connect (void *cls, const struct GNUNET_PeerIdentity *peer, "Connected to peer %s, %x, sending query with id %d\n", GNUNET_i2s (peer), peer, ntohs (cls_->dns.s.id)); - struct tunnel_state *s = GNUNET_MESH_tunnel_get_data(cls_->tunnel); + struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (cls_->tunnel); + if (NULL == s->head) { s->th = - GNUNET_MESH_notify_transmit_ready (cls_->tunnel, - GNUNET_YES, - 42, - GNUNET_TIME_UNIT_MINUTES, - NULL, - cls_->hdr.size, - mesh_send, - cls); + GNUNET_MESH_notify_transmit_ready (cls_->tunnel, GNUNET_YES, 42, + GNUNET_TIME_UNIT_MINUTES, NULL, + cls_->hdr.size, mesh_send, cls); } else { - struct tunnel_notify_queue *head = - s->head; - struct tunnel_notify_queue *tail = - s->tail; + struct tunnel_notify_queue *head = s->head; + struct tunnel_notify_queue *tail = s->tail; struct tunnel_notify_queue *element = GNUNET_malloc (sizeof (struct tunnel_notify_queue)); @@ -432,13 +431,14 @@ send_mesh_query (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) struct tunnel_cls *cls_ = (struct tunnel_cls *) cls; - struct tunnel_state *s = GNUNET_malloc(sizeof *s); + struct tunnel_state *s = GNUNET_malloc (sizeof *s); + s->head = NULL; s->tail = NULL; s->th = NULL; cls_->tunnel = - GNUNET_MESH_tunnel_create(mesh_handle, s, mesh_connect, NULL, cls_); + GNUNET_MESH_tunnel_create (mesh_handle, s, mesh_connect, NULL, cls_); GNUNET_MESH_peer_request_connect_by_type (cls_->tunnel, GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER); @@ -461,12 +461,15 @@ receive_mesh_query (void *cls struct sockaddr_in dest; - struct dns_pkt_parsed *pdns = parse_dns_packet(dns); + struct dns_pkt_parsed *pdns = parse_dns_packet (dns); memset (&dest, 0, sizeof dest); dest.sin_port = htons (53); char *dns_resolver; - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, "dns", "EXTERNAL_DNS", &dns_resolver) || + + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (cfg, "dns", "EXTERNAL_DNS", + &dns_resolver) || 1 != inet_pton (AF_INET, dns_resolver, &dest.sin_addr)) inet_pton (AF_INET, "8.8.8.8", &dest.sin_addr); @@ -476,16 +479,17 @@ receive_mesh_query (void *cls query_states[dns->s.id].valid = GNUNET_YES; int i; - for (i= 0; i < ntohs(pdns->s.qdcount); i++) + + for (i = 0; i < ntohs (pdns->s.qdcount); i++) + { + if (pdns->queries[i]->qtype == htons (28) || + pdns->queries[i]->qtype == htons (1)) { - if (pdns->queries[i]->qtype == htons(28) || - pdns->queries[i]->qtype == htons(1)) - { - query_states[dns->s.id].qtype = pdns->queries[i]->qtype; - break; - } + query_states[dns->s.id].qtype = pdns->queries[i]->qtype; + break; } - free_parsed_dns_packet(pdns); + } + free_parsed_dns_packet (pdns); GNUNET_NETWORK_socket_sendto (dnsout, dns, ntohs (message->size) - @@ -528,7 +532,8 @@ receive_mesh_answer (void *cls + sizeof (struct dns_record_line) - 1 + 16; /* To hold the IPv6-Address */ struct answer_packet_list *answer = - GNUNET_malloc (len + sizeof(struct answer_packet_list) - sizeof(struct answer_packet)); + GNUNET_malloc (len + sizeof (struct answer_packet_list) - + sizeof (struct answer_packet)); answer->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS); answer->pkt.hdr.size = htons (len); @@ -546,17 +551,18 @@ receive_mesh_answer (void *cls int i = 0; - while (i < ntohs(pdns->s.ancount) && - ntohs(pdns->answers[i]->type) != 28 && - ntohs(pdns->answers[i]->type) != 1) -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Answer contains %d.\n", ntohs(pdns->answers[i]->type)); + while (i < ntohs (pdns->s.ancount) && ntohs (pdns->answers[i]->type) != 28 && + ntohs (pdns->answers[i]->type) != 1) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Answer contains %d.\n", + ntohs (pdns->answers[i]->type)); i++; -} + } if (i >= ntohs (pdns->s.ancount)) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Answer does not contain any usable answers.\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Answer does not contain any usable answers.\n"); free_parsed_dns_packet (pdns); GNUNET_free (answer); return GNUNET_OK; @@ -568,8 +574,10 @@ receive_mesh_answer (void *cls memcpy (answer->pkt.addr, pdns->answers[i]->data, ntohs (pdns->answers[i]->data_len)); - memcpy(answer->pkt.from, query_states[dns->s.id].remote_ip, query_states[dns->s.id].addrlen); - memcpy(answer->pkt.to, query_states[dns->s.id].local_ip, query_states[dns->s.id].addrlen); + memcpy (answer->pkt.from, query_states[dns->s.id].remote_ip, + query_states[dns->s.id].addrlen); + memcpy (answer->pkt.to, query_states[dns->s.id].local_ip, + query_states[dns->s.id].addrlen); answer->pkt.addrlen = query_states[dns->s.id].addrlen; answer->pkt.dst_port = query_states[dns->s.id].local_port; @@ -595,14 +603,14 @@ receive_mesh_answer (void *cls (struct dns_record_line *) (dpkt->data + (query_states[dns->s.id].namelen) + sizeof (struct dns_query_line) + 2); - if (htons(28) == query_states[dns->s.id].qtype) + if (htons (28) == query_states[dns->s.id].qtype) { answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REMOTE_AAAA; dque->type = htons (28); /* AAAA */ drec_data->type = htons (28); /* AAAA */ drec_data->data_len = htons (16); } - else if (htons(1) == query_states[dns->s.id].qtype) + else if (htons (1) == query_states[dns->s.id].qtype) { answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REMOTE_A; dque->type = htons (1); /* A */ @@ -610,10 +618,11 @@ receive_mesh_answer (void *cls drec_data->data_len = htons (4); } else - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "dns-answer with pending qtype = %d\n", query_states[dns->s.id].qtype); - GNUNET_assert(0); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "dns-answer with pending qtype = %d\n", + query_states[dns->s.id].qtype); + GNUNET_assert (0); + } dque->class = htons (1); /* IN */ char *anname = @@ -634,10 +643,10 @@ receive_mesh_answer (void *cls answer->client = query_states[dns->s.id].client; if (server_notify == NULL) - server_notify = GNUNET_SERVER_notify_transmit_ready (query_states[dns->s.id].client, len, - GNUNET_TIME_UNIT_FOREVER_REL, - &send_answer, - NULL); + server_notify = + GNUNET_SERVER_notify_transmit_ready (query_states[dns->s.id].client, + len, GNUNET_TIME_UNIT_FOREVER_REL, + &send_answer, NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent answer of length %d on to client, addroffset = %d\n", len, @@ -672,14 +681,16 @@ send_rev_query (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 2 /* We do not know the lenght of the answer yet */ ; struct answer_packet_list *answer = - GNUNET_malloc (len + sizeof(struct answer_packet_list) - sizeof(struct answer_packet)); + GNUNET_malloc (len + sizeof (struct answer_packet_list) - + sizeof (struct answer_packet)); answer->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS); answer->pkt.hdr.size = htons (len); answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REV; - memcpy(answer->pkt.from, query_states[id].remote_ip, query_states[id].addrlen); - memcpy(answer->pkt.to, query_states[id].local_ip, query_states[id].addrlen); + memcpy (answer->pkt.from, query_states[id].remote_ip, + query_states[id].addrlen); + memcpy (answer->pkt.to, query_states[id].local_ip, query_states[id].addrlen); answer->pkt.dst_port = query_states[id].local_port; @@ -728,9 +739,10 @@ send_rev_query (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) answer->client = query_states[id].client; if (server_notify == NULL) - server_notify = GNUNET_SERVER_notify_transmit_ready (query_states[id].client, len, - GNUNET_TIME_UNIT_FOREVER_REL, - &send_answer, NULL); + server_notify = + GNUNET_SERVER_notify_transmit_ready (query_states[id].client, len, + GNUNET_TIME_UNIT_FOREVER_REL, + &send_answer, NULL); } /** @@ -740,11 +752,12 @@ static void receive_dht (void *cls, struct GNUNET_TIME_Absolute exp __attribute__ ((unused)), const GNUNET_HashCode * key __attribute__ ((unused)), - const struct GNUNET_PeerIdentity *get_path __attribute__ ((unused)), - unsigned int get_path_length __attribute__ ((unused)), - const struct GNUNET_PeerIdentity *put_path __attribute__ ((unused)), - unsigned int put_path_length __attribute__ ((unused)), - enum GNUNET_BLOCK_Type type, size_t size, + const struct GNUNET_PeerIdentity *get_path + __attribute__ ((unused)), unsigned int get_path_length + __attribute__ ((unused)), + const struct GNUNET_PeerIdentity *put_path + __attribute__ ((unused)), unsigned int put_path_length + __attribute__ ((unused)), enum GNUNET_BLOCK_Type type, size_t size, const void *data) { @@ -773,8 +786,8 @@ receive_dht (void *cls, struct GNUNET_TIME_Absolute exp + sizeof (struct dns_record_line) - 1 + 16; /* To hold the IPv6-Address */ struct answer_packet_list *answer = - GNUNET_malloc (len + - sizeof(struct answer_packet_list) - sizeof(struct answer_packet)); + GNUNET_malloc (len + sizeof (struct answer_packet_list) - + sizeof (struct answer_packet)); answer->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS); answer->pkt.hdr.size = htons (len); @@ -792,8 +805,9 @@ receive_dht (void *cls, struct GNUNET_TIME_Absolute exp memcpy (&answer->pkt.service_descr.ports, &rec->ports, sizeof (answer->pkt.service_descr.ports)); - memcpy(answer->pkt.from, query_states[id].remote_ip, query_states[id].addrlen); - memcpy(answer->pkt.to, query_states[id].local_ip, query_states[id].addrlen); + memcpy (answer->pkt.from, query_states[id].remote_ip, + query_states[id].addrlen); + memcpy (answer->pkt.to, query_states[id].local_ip, query_states[id].addrlen); answer->pkt.addrlen = query_states[id].addrlen; answer->pkt.dst_port = query_states[id].local_port; @@ -844,9 +858,10 @@ receive_dht (void *cls, struct GNUNET_TIME_Absolute exp GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer); if (server_notify == NULL) - server_notify = GNUNET_SERVER_notify_transmit_ready (answer->client, len, - GNUNET_TIME_UNIT_FOREVER_REL, - &send_answer, NULL); + server_notify = + GNUNET_SERVER_notify_transmit_ready (answer->client, len, + GNUNET_TIME_UNIT_FOREVER_REL, + &send_answer, NULL); } /** @@ -877,11 +892,11 @@ receive_query (void *cls query_states[dns->s.id].valid = GNUNET_YES; query_states[dns->s.id].client = client; - GNUNET_SERVER_client_keep(client); - memcpy(query_states[dns->s.id].local_ip, pkt->orig_from, pkt->addrlen); + GNUNET_SERVER_client_keep (client); + memcpy (query_states[dns->s.id].local_ip, pkt->orig_from, pkt->addrlen); query_states[dns->s.id].addrlen = pkt->addrlen; query_states[dns->s.id].local_port = pkt->src_port; - memcpy(query_states[dns->s.id].remote_ip, pkt->orig_to, pkt->addrlen); + memcpy (query_states[dns->s.id].remote_ip, pkt->orig_to, pkt->addrlen); query_states[dns->s.id].namelen = strlen ((char *) dns->data) + 1; if (query_states[dns->s.id].name != NULL) GNUNET_free (query_states[dns->s.id].name); @@ -891,15 +906,16 @@ receive_query (void *cls query_states[dns->s.id].namelen); int i; - for (i= 0; i < ntohs(pdns->s.qdcount); i++) + + for (i = 0; i < ntohs (pdns->s.qdcount); i++) + { + if (pdns->queries[i]->qtype == htons (28) || + pdns->queries[i]->qtype == htons (1)) { - if (pdns->queries[i]->qtype == htons(28) || - pdns->queries[i]->qtype == htons(1)) - { - query_states[dns->s.id].qtype = pdns->queries[i]->qtype; - break; - } + query_states[dns->s.id].qtype = pdns->queries[i]->qtype; + break; } + } /* The query is for a .gnunet-address */ if (pdns->queries[0]->namelen > 9 && @@ -922,8 +938,8 @@ receive_query (void *cls cls->handle = GNUNET_DHT_get_start (dht, GNUNET_TIME_UNIT_MINUTES, GNUNET_BLOCK_TYPE_DNS, &key, - 5 /* DEFAULT_GET_REPLICATION */, GNUNET_DHT_RO_NONE, NULL, - 0, &receive_dht, cls); + 5 /* DEFAULT_GET_REPLICATION */ , + GNUNET_DHT_RO_NONE, NULL, 0, &receive_dht, cls); goto outfree; } @@ -992,53 +1008,55 @@ receive_query (void *cls unsigned char virt_dns_bytes[16]; if (pkt->addrlen == 4) - { - char *virt_dns; - - if (GNUNET_SYSERR == - GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS", &virt_dns)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "No entry 'VIRTDNS' in configuration!\n"); - exit (1); - } - - if (1 != inet_pton (AF_INET, virt_dns, &virt_dns_bytes)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error parsing 'VIRTDNS': %s; %m!\n", - virt_dns); - exit (1); - } + { + char *virt_dns; - GNUNET_free (virt_dns); - } - else if (pkt->addrlen == 16) + if (GNUNET_SYSERR == + GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS", + &virt_dns)) { - char *virt_dns; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "No entry 'VIRTDNS' in configuration!\n"); + exit (1); + } - if (GNUNET_SYSERR == - GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS6", &virt_dns)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "No entry 'VIRTDNS6' in configuration!\n"); - exit (1); - } + if (1 != inet_pton (AF_INET, virt_dns, &virt_dns_bytes)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error parsing 'VIRTDNS': %s; %m!\n", + virt_dns); + exit (1); + } - if (1 != inet_pton (AF_INET6, virt_dns, &virt_dns_bytes)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error parsing 'VIRTDNS6': %s; %m!\n", - virt_dns); - exit (1); - } + GNUNET_free (virt_dns); + } + else if (pkt->addrlen == 16) + { + char *virt_dns; - GNUNET_free (virt_dns); + if (GNUNET_SYSERR == + GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS6", + &virt_dns)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "No entry 'VIRTDNS6' in configuration!\n"); + exit (1); } - else + + if (1 != inet_pton (AF_INET6, virt_dns, &virt_dns_bytes)) { - GNUNET_assert(0); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Error parsing 'VIRTDNS6': %s; %m!\n", virt_dns); + exit (1); } - if (memcmp(virt_dns_bytes,pkt->orig_to, pkt->addrlen) == 0) + GNUNET_free (virt_dns); + } + else + { + GNUNET_assert (0); + } + + if (memcmp (virt_dns_bytes, pkt->orig_to, pkt->addrlen) == 0) { /* This is a packet that was sent directly to the virtual dns-server * @@ -1061,36 +1079,36 @@ receive_query (void *cls cls_->hdr.size - sizeof (struct GNUNET_MessageHeader)); GNUNET_SCHEDULER_add_now (send_mesh_query, cls_); - if (ntohs(pdns->s.qdcount) == 1) + if (ntohs (pdns->s.qdcount) == 1) + { + if (ntohs (pdns->queries[0]->qtype) == 1) + pdns->queries[0]->qtype = htons (28); + else if (ntohs (pdns->queries[0]->qtype) == 28) + pdns->queries[0]->qtype = htons (1); + else { - if (ntohs(pdns->queries[0]->qtype) == 1) - pdns->queries[0]->qtype = htons(28); - else if (ntohs(pdns->queries[0]->qtype) == 28) - pdns->queries[0]->qtype = htons(1); - else -{ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "not sending second packet\n"); - goto outfree; -} - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "sending second packet\n"); - struct dns_pkt *rdns = unparse_dns_packet (pdns); - size_t size = + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "not sending second packet\n"); + goto outfree; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending second packet\n"); + struct dns_pkt *rdns = unparse_dns_packet (pdns); + size_t size = sizeof (struct GNUNET_MESH_Tunnel *) + sizeof (struct GNUNET_MessageHeader) + (ntohs (message->size) - sizeof (struct query_packet) + 1); - struct tunnel_cls *cls_ = GNUNET_malloc (size); + struct tunnel_cls *cls_ = GNUNET_malloc (size); - cls_->hdr.size = size - sizeof (struct GNUNET_MESH_Tunnel *); + cls_->hdr.size = size - sizeof (struct GNUNET_MESH_Tunnel *); - cls_->hdr.type = ntohs (GNUNET_MESSAGE_TYPE_VPN_REMOTE_QUERY_DNS); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "size: %d\n", size); + cls_->hdr.type = ntohs (GNUNET_MESSAGE_TYPE_VPN_REMOTE_QUERY_DNS); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "size: %d\n", size); - memcpy (&cls_->dns, rdns, - cls_->hdr.size - sizeof (struct GNUNET_MessageHeader)); - GNUNET_SCHEDULER_add_now (send_mesh_query, cls_); - GNUNET_free (rdns); - } + memcpy (&cls_->dns, rdns, + cls_->hdr.size - sizeof (struct GNUNET_MessageHeader)); + GNUNET_SCHEDULER_add_now (send_mesh_query, cls_); + GNUNET_free (rdns); + } goto outfree; } @@ -1098,31 +1116,31 @@ receive_query (void *cls /* The query should be sent to the network */ if (pkt->addrlen == 4) - { - struct sockaddr_in dest; + { + struct sockaddr_in dest; - memset (&dest, 0, sizeof dest); - dest.sin_port = htons (53); - memcpy(&dest.sin_addr.s_addr, pkt->orig_to, pkt->addrlen); + memset (&dest, 0, sizeof dest); + dest.sin_port = htons (53); + memcpy (&dest.sin_addr.s_addr, pkt->orig_to, pkt->addrlen); - GNUNET_NETWORK_socket_sendto (dnsout, dns, - ntohs (pkt->hdr.size) - - sizeof (struct query_packet) + 1, - (struct sockaddr *) &dest, sizeof dest); - } + GNUNET_NETWORK_socket_sendto (dnsout, dns, + ntohs (pkt->hdr.size) - + sizeof (struct query_packet) + 1, + (struct sockaddr *) &dest, sizeof dest); + } else if (pkt->addrlen == 16) - { - struct sockaddr_in6 dest; + { + struct sockaddr_in6 dest; - memset (&dest, 0, sizeof dest); - dest.sin6_port = htons (53); - memcpy(&dest.sin6_addr, pkt->orig_to, pkt->addrlen); + memset (&dest, 0, sizeof dest); + dest.sin6_port = htons (53); + memcpy (&dest.sin6_addr, pkt->orig_to, pkt->addrlen); - GNUNET_NETWORK_socket_sendto (dnsout6, dns, - ntohs (pkt->hdr.size) - - sizeof (struct query_packet) + 1, - (struct sockaddr *) &dest, sizeof dest); - } + GNUNET_NETWORK_socket_sendto (dnsout6, dns, + ntohs (pkt->hdr.size) - + sizeof (struct query_packet) + 1, + (struct sockaddr *) &dest, sizeof dest); + } outfree: free_parsed_dns_packet (pdns); @@ -1144,10 +1162,10 @@ open_port6 () dnsout6 = GNUNET_NETWORK_socket_create (AF_INET6, SOCK_DGRAM, 0); if (dnsout6 == NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not create socket: %m\n"); - return GNUNET_SYSERR; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not create socket: %m\n"); + return GNUNET_SYSERR; + } memset (&addr, 0, sizeof (struct sockaddr_in6)); addr.sin6_family = AF_INET6; @@ -1205,7 +1223,9 @@ open_port () return GNUNET_YES; } -void handle_response(struct dns_pkt* dns, struct sockaddr *addr, socklen_t addrlen, int r); +void +handle_response (struct dns_pkt *dns, struct sockaddr *addr, socklen_t addrlen, + int r); /** * Read a response-packet of the UDP-Socket @@ -1228,7 +1248,7 @@ read_response6 (void *cls #ifndef MINGW if (0 != ioctl (GNUNET_NETWORK_get_fd (dnsout6), FIONREAD, &len)) { - (void)open_port6 (); + (void) open_port6 (); return; } #else @@ -1243,14 +1263,15 @@ read_response6 (void *cls (struct sockaddr *) &addr, &addrlen); if (r < 0) - { - (void)open_port6 (); - return; - } + { + (void) open_port6 (); + return; + } + + struct sockaddr *addr_ = GNUNET_malloc (sizeof addr); - struct sockaddr *addr_ = GNUNET_malloc(sizeof addr); memcpy (addr_, &addr, sizeof addr); - handle_response(dns, addr_, 4, r); + handle_response (dns, addr_, 4, r); GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, dnsout6, &read_response6, NULL); @@ -1277,8 +1298,7 @@ read_response (void *cls #ifndef MINGW if (0 != ioctl (GNUNET_NETWORK_get_fd (dnsout), FIONREAD, &len)) { - GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, - "ioctl"); + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "ioctl"); unhijack (dnsoutport); if (GNUNET_YES == open_port ()) GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &hijack, NULL); @@ -1296,114 +1316,118 @@ read_response (void *cls (struct sockaddr *) &addr, &addrlen); if (r < 0) - { - GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, - "recvfrom"); - unhijack (dnsoutport); - if (GNUNET_YES == open_port ()) - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &hijack, NULL); - return; - } + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "recvfrom"); + unhijack (dnsoutport); + if (GNUNET_YES == open_port ()) + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &hijack, NULL); + return; + } + + struct sockaddr *addr_ = GNUNET_malloc (sizeof addr); - struct sockaddr *addr_ = GNUNET_malloc(sizeof addr); memcpy (addr_, &addr, sizeof addr); - handle_response(dns, addr_, 4, r); + handle_response (dns, addr_, 4, r); GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, dnsout, &read_response, NULL); } void -handle_response(struct dns_pkt* dns, struct sockaddr *addr, socklen_t addrlen, int r) +handle_response (struct dns_pkt *dns, struct sockaddr *addr, socklen_t addrlen, + int r) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Answer to query %d\n", ntohs (dns->s.id)); if (query_states[dns->s.id].valid == GNUNET_YES) + { + if (query_states[dns->s.id].tunnel != NULL) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Answer to query %d for a remote peer!\n", ntohs (dns->s.id)); + /* This response should go through a tunnel */ + uint32_t *c = + GNUNET_malloc (4 + sizeof (struct GNUNET_MESH_Tunnel *) + r); + *c = r; + struct GNUNET_MESH_Tunnel **t = (struct GNUNET_MESH_Tunnel **) (c + 1); + + *t = query_states[dns->s.id].tunnel; + memcpy (t + 1, dns, r); + struct tunnel_state *s = + GNUNET_MESH_tunnel_get_data (query_states[dns->s.id].tunnel); + if (NULL == s->th) + { + s->th = + GNUNET_MESH_notify_transmit_ready (query_states[dns->s.id].tunnel, + GNUNET_YES, 32, + GNUNET_TIME_UNIT_MINUTES, NULL, + r + + sizeof (struct + GNUNET_MessageHeader), + mesh_send_response, c); + } + else + { + struct tunnel_notify_queue *element = + GNUNET_malloc (sizeof (struct tunnel_notify_queue)); + element->cls = c; + element->len = r + sizeof (struct GNUNET_MessageHeader); + element->cb = mesh_send_response; + + GNUNET_CONTAINER_DLL_insert_tail (s->head, s->tail, element); + } + } + else { - if (query_states[dns->s.id].tunnel != NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Answer to query %d for a remote peer!\n", - ntohs (dns->s.id)); - /* This response should go through a tunnel */ - uint32_t *c = - GNUNET_malloc (4 + sizeof (struct GNUNET_MESH_Tunnel *) + r); - *c = r; - struct GNUNET_MESH_Tunnel **t = (struct GNUNET_MESH_Tunnel **) (c + 1); - - *t = query_states[dns->s.id].tunnel; - memcpy (t + 1, dns, r); - struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (query_states[dns->s.id].tunnel); - if (NULL == s->th) - { - s->th = - GNUNET_MESH_notify_transmit_ready (query_states[dns->s.id].tunnel, - GNUNET_YES, - 32, - GNUNET_TIME_UNIT_MINUTES, - NULL, - r + - sizeof (struct - GNUNET_MessageHeader), - mesh_send_response, c); - } - else - { - struct tunnel_notify_queue *element = - GNUNET_malloc (sizeof (struct tunnel_notify_queue)); - element->cls = c; - element->len = r + sizeof (struct GNUNET_MessageHeader); - element->cb = mesh_send_response; - - GNUNET_CONTAINER_DLL_insert_tail (s->head, s->tail, element); - } - } + query_states[dns->s.id].valid = GNUNET_NO; + + size_t len = sizeof (struct answer_packet) + r - 1; /* 1 for the unsigned char data[1]; */ + struct answer_packet_list *answer = + GNUNET_malloc (len + sizeof (struct answer_packet_list) - + (sizeof (struct answer_packet))); + answer->pkt.hdr.type = + htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS); + answer->pkt.hdr.size = htons (len); + answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_IP; + answer->pkt.addrlen = addrlen; + if (addrlen == 16) + { + struct sockaddr_in6 *addr_ = (struct sockaddr_in6 *) addr; + + memcpy (answer->pkt.from, &addr_->sin6_addr, addrlen); + memcpy (answer->pkt.to, query_states[dns->s.id].local_ip, addrlen); + } + else if (addrlen == 4) + { + struct sockaddr_in *addr_ = (struct sockaddr_in *) addr; + + memcpy (answer->pkt.from, &addr_->sin_addr.s_addr, addrlen); + memcpy (answer->pkt.to, query_states[dns->s.id].local_ip, addrlen); + } else - { - query_states[dns->s.id].valid = GNUNET_NO; - - size_t len = sizeof (struct answer_packet) + r - 1; /* 1 for the unsigned char data[1]; */ - struct answer_packet_list *answer = - GNUNET_malloc (len + sizeof(struct answer_packet_list) - (sizeof(struct answer_packet))); - answer->pkt.hdr.type = - htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS); - answer->pkt.hdr.size = htons (len); - answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_IP; - answer->pkt.addrlen = addrlen; - if (addrlen == 16) - { - struct sockaddr_in6 *addr_ = (struct sockaddr_in6*)addr; - memcpy(answer->pkt.from, &addr_->sin6_addr, addrlen); - memcpy(answer->pkt.to, query_states[dns->s.id].local_ip, addrlen); - } - else if (addrlen == 4) - { - struct sockaddr_in *addr_ = (struct sockaddr_in*)addr; - memcpy(answer->pkt.from, &addr_->sin_addr.s_addr, addrlen); - memcpy(answer->pkt.to, query_states[dns->s.id].local_ip, addrlen); - } - else - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "addrlen = %d\n", addrlen); - GNUNET_assert(0); - } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "sending answer with addrlen = %d\n", addrlen); - answer->pkt.dst_port = query_states[dns->s.id].local_port; - memcpy (answer->pkt.data, dns, r); - answer->client = query_states[dns->s.id].client; - - GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer); - - if (server_notify == NULL) - server_notify = GNUNET_SERVER_notify_transmit_ready (query_states[dns->s.id].client, - len, GNUNET_TIME_UNIT_FOREVER_REL, - &send_answer, - NULL); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "addrlen = %d\n", addrlen); + GNUNET_assert (0); + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending answer with addrlen = %d\n", + addrlen); + answer->pkt.dst_port = query_states[dns->s.id].local_port; + memcpy (answer->pkt.data, dns, r); + answer->client = query_states[dns->s.id].client; + + GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer); + + if (server_notify == NULL) + server_notify = + GNUNET_SERVER_notify_transmit_ready (query_states[dns->s.id].client, + len, + GNUNET_TIME_UNIT_FOREVER_REL, + &send_answer, NULL); } - GNUNET_free(addr); + } + GNUNET_free (addr); } @@ -1535,8 +1559,9 @@ publish_name (const char *name, uint64_t ports, uint32_t service_type, GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &data.peer); data.expiration_time = - GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_HOURS, 2))); + GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute + (GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_HOURS, 2))); /* Sign the block */ if (GNUNET_OK != @@ -1549,7 +1574,8 @@ publish_name (const char *name, uint64_t ports, uint32_t service_type, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Putting with key %08x, size = %d\n", *((unsigned int *) &data.service_descriptor), size); - GNUNET_DHT_put (dht, &data.service_descriptor, 5 /* DEFAULT_PUT_REPLICATION */, + GNUNET_DHT_put (dht, &data.service_descriptor, + 5 /* DEFAULT_PUT_REPLICATION */ , GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_DNS, size, (char *) &data, GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS), @@ -1694,13 +1720,15 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (cfg_, "dns", "PROVIDE_EXIT")) apptypes[0] = GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER; - mesh_handle = GNUNET_MESH_connect (cfg_, 42, NULL, new_tunnel, clean_tunnel, mesh_handlers, apptypes); + mesh_handle = + GNUNET_MESH_connect (cfg_, 42, NULL, new_tunnel, clean_tunnel, + mesh_handlers, apptypes); cfg = cfg_; dht = GNUNET_DHT_connect (cfg, 1024); GNUNET_SCHEDULER_add_now (publish_names, NULL); GNUNET_SERVER_add_handlers (server, handlers); - GNUNET_SERVER_disconnect_notify(server, &client_disconnect, NULL); + GNUNET_SERVER_disconnect_notify (server, &client_disconnect, NULL); GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task, cls); } -- cgit v1.2.3